Skip to content

Commit

Permalink
use new version scheme for bundled esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
edewit committed Jan 31, 2024
1 parent b19a83f commit c482cae
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 22 deletions.
18 changes: 9 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.release>17</maven.compiler.release>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<esbuild.version>0.19.9</esbuild.version>
<esbuild.version>0.19.9-mvnpm-0.0.5</esbuild.version>
<quarkus.version>3.6.0</quarkus.version>
<esbuild.scss.version>v0.0.4</esbuild.scss.version>
<esbuild.scss.version>v0.0.5</esbuild.scss.version>
<formatter.plugin.version>2.23.0</formatter.plugin.version>
<impsort.plugin.version>1.9.0</impsort.plugin.version>
<quarkus.ide-config.version>3.5.0</quarkus.ide-config.version>
Expand Down Expand Up @@ -122,13 +122,13 @@
<configuration>
<target>
<get dest="src/main/resources" skipexisting="true">
<url url="https://github.com/mvnpm/esbuild/releases/download/${esbuild.scss.version}/mvnpm-esbuild-darwin-arm64-${esbuild.version}.tgz"/>
<url url="https://github.com/mvnpm/esbuild/releases/download/${esbuild.scss.version}/mvnpm-esbuild-darwin-x64-${esbuild.version}.tgz"/>
<url url="https://github.com/mvnpm/esbuild/releases/download/${esbuild.scss.version}/mvnpm-esbuild-win32-x64-${esbuild.version}.tgz"/>
<url url="https://github.com/mvnpm/esbuild/releases/download/${esbuild.scss.version}/mvnpm-esbuild-win32-ia32-${esbuild.version}.tgz"/>
<url url="https://github.com/mvnpm/esbuild/releases/download/${esbuild.scss.version}/mvnpm-esbuild-linux-arm64-${esbuild.version}.tgz"/>
<url url="https://github.com/mvnpm/esbuild/releases/download/${esbuild.scss.version}/mvnpm-esbuild-linux-x64-${esbuild.version}.tgz"/>
<url url="https://github.com/mvnpm/esbuild/releases/download/${esbuild.scss.version}/mvnpm-esbuild-linux-ia32-${esbuild.version}.tgz"/>
<url url="https://github.com/mvnpm/esbuild/releases/download/${esbuild.scss.version}/esbuild-darwin-arm64-${esbuild.version}.tgz"/>
<url url="https://github.com/mvnpm/esbuild/releases/download/${esbuild.scss.version}/esbuild-darwin-x64-${esbuild.version}.tgz"/>
<url url="https://github.com/mvnpm/esbuild/releases/download/${esbuild.scss.version}/esbuild-win32-x64-${esbuild.version}.tgz"/>
<url url="https://github.com/mvnpm/esbuild/releases/download/${esbuild.scss.version}/esbuild-win32-ia32-${esbuild.version}.tgz"/>
<url url="https://github.com/mvnpm/esbuild/releases/download/${esbuild.scss.version}/esbuild-linux-arm64-${esbuild.version}.tgz"/>
<url url="https://github.com/mvnpm/esbuild/releases/download/${esbuild.scss.version}/esbuild-linux-x64-${esbuild.version}.tgz"/>
<url url="https://github.com/mvnpm/esbuild/releases/download/${esbuild.scss.version}/esbuild-linux-ia32-${esbuild.version}.tgz"/>
</get>
</target>
</configuration>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/mvnpm/esbuild/resolve/BaseResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ private static String determineClassifier() {
return classifier;
}

static Path extract(InputStream archive, String version) throws IOException {
final File destination = createDestination(version).toFile();
return extract(archive, destination);
static Path extract(InputStream archive, String destination) throws IOException {
final File destinationFile = createDestination(destination).toFile();
return extract(archive, destinationFile);
}

static Path extract(InputStream archive, File destination) throws IOException {
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/io/mvnpm/esbuild/resolve/BundleCacheResolver.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.mvnpm.esbuild.resolve;

import static io.mvnpm.esbuild.Bundler.ESBUILD_EMBEDDED_VERSION;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class BundleCacheResolver extends CacheResolver {
public BundleCacheResolver(Resolver resolver) {
super(resolver);
}

@Override
public Path resolve(String version) throws IOException {
final Path path = super.resolve(ESBUILD_EMBEDDED_VERSION);
if (Files.isExecutable(path)) {
return path;
}
return resolver.resolve(version);
}
}
6 changes: 4 additions & 2 deletions src/main/java/io/mvnpm/esbuild/resolve/BundledResolver.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.mvnpm.esbuild.resolve;

import static io.mvnpm.esbuild.Bundler.ESBUILD_EMBEDDED_VERSION;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
Expand All @@ -12,10 +14,10 @@ public BundledResolver(Resolver resolver) {

@Override
public Path resolve(String version) throws IOException {
final InputStream resource = getClass().getResourceAsStream("/mvnpm-esbuild-%s-%s.tgz".formatted(CLASSIFIER, version));
final InputStream resource = getClass().getResourceAsStream("/esbuild-%s-%s.tgz".formatted(CLASSIFIER, version));

if (resource != null) {
return extract(resource, version);
return extract(resource, ESBUILD_EMBEDDED_VERSION);
}

return resolver.resolve(version);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ public ExecutableResolver() {
throw new RuntimeException("could not resolve esbuild with version " + version);
});
final BundledResolver bundledResolver = new BundledResolver(downloadResolver);
this.resolver = new CacheResolver(bundledResolver);
final CacheResolver bundleCacheResolver = new BundleCacheResolver(bundledResolver);
this.resolver = new BundleCacheResolver(bundleCacheResolver);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/io/mvnpm/esbuild/ExecuteTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.mvnpm.esbuild;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;
import java.nio.file.Path;
Expand All @@ -23,6 +23,6 @@ public void shouldExecuteEsBuild() throws IOException {
String workingDirectory = System.getProperty("user.dir");
final ExecuteResult executeResult = new Execute(Paths.get(workingDirectory), path.toFile(), esBuildConfig)
.executeAndWait();
assertTrue(executeResult.output().startsWith(defaultVersion));
assertEquals(defaultVersion + "\n", executeResult.output());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void resolve() throws IOException {
assertTrue(location.toFile().list().length > 0);
}

private Path createEsBuildBinary(String version) throws IOException {
protected static Path createEsBuildBinary(String version) throws IOException {
final Path destination = BaseResolver.createDestination(version);
final Path exec = destination.resolve(EXECUTABLE_PATH);
Files.createDirectories(exec.getParent());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import io.mvnpm.esbuild.Bundler;

public class DownloadResolverTest extends BundleTester {
private static final String TEST_VERSION = "0.19.9";

@BeforeAll
public static void cleanUp() throws IOException {
cleanUpDefault();
cleanUp(TEST_VERSION);
}

@Test
public void download() throws IOException {
// when
final Path path = new DownloadResolver(THROWING_RESOLVER).resolve(Bundler.ESBUILD_EMBEDDED_VERSION);
final Path path = new DownloadResolver(THROWING_RESOLVER).resolve(TEST_VERSION);

// then
assertTrue(path.toFile().exists());
Expand Down

0 comments on commit c482cae

Please sign in to comment.