From 7505fcbbef697ed05d33a0cd67901d3f15a17cee Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Tue, 12 Dec 2023 09:40:39 +0100 Subject: [PATCH 1/8] esbuild that has scss plugin installed --- pom.xml | 17 +++++++++-------- .../io/mvnpm/esbuild/resolve/BaseResolver.java | 2 +- src/test/java/io/mvnpm/esbuild/ExecuteTest.java | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 82ea8a1..dee5027 100644 --- a/pom.xml +++ b/pom.xml @@ -36,8 +36,9 @@ 17 17 UTF-8 - 0.19.2 + 0.19.5 3.6.0 + v0.0.2 2.23.0 1.9.0 3.5.0 @@ -121,13 +122,13 @@ - - - - - - - + + + + + + + diff --git a/src/main/java/io/mvnpm/esbuild/resolve/BaseResolver.java b/src/main/java/io/mvnpm/esbuild/resolve/BaseResolver.java index a508a6b..039d079 100644 --- a/src/main/java/io/mvnpm/esbuild/resolve/BaseResolver.java +++ b/src/main/java/io/mvnpm/esbuild/resolve/BaseResolver.java @@ -84,7 +84,7 @@ static Path extract(InputStream archive, File destination) throws IOException { ArchiveEntry entry; while ((entry = tarIn.getNextEntry()) != null) { - if (!tarIn.canReadEntryData(entry)) { + if (!tarIn.canReadEntryData(entry) || entry.isDirectory()) { // Entry is a directory or symbolic link, skip it continue; } diff --git a/src/test/java/io/mvnpm/esbuild/ExecuteTest.java b/src/test/java/io/mvnpm/esbuild/ExecuteTest.java index e2dcc70..f35106f 100644 --- a/src/test/java/io/mvnpm/esbuild/ExecuteTest.java +++ b/src/test/java/io/mvnpm/esbuild/ExecuteTest.java @@ -1,6 +1,6 @@ package io.mvnpm.esbuild; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.nio.file.Path; @@ -20,6 +20,6 @@ public void shouldExecuteEsBuild() throws IOException { final String defaultVersion = Bundler.ESBUILD_EMBEDDED_VERSION; final Path path = new ExecutableResolver().resolve(defaultVersion); final ExecuteResult executeResult = new Execute(path.toFile(), esBuildConfig).executeAndWait(); - assertEquals(defaultVersion + "\n", executeResult.output()); + assertTrue(executeResult.output().startsWith(defaultVersion)); } } From 783e49f6dcd2bcea4dc0aed42b90398aca07985c Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Thu, 14 Dec 2023 11:53:23 +0100 Subject: [PATCH 2/8] moved to mvnpm/esbuild Signed-off-by: Erik Jan de Wit --- pom.xml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index dee5027..a45a356 100644 --- a/pom.xml +++ b/pom.xml @@ -122,13 +122,13 @@ - - - - - - - + + + + + + + From c7e86658f311f4722aa12e2d038a19cd1e2cc228 Mon Sep 17 00:00:00 2001 From: Andy Damevin Date: Thu, 21 Dec 2023 11:10:38 +0100 Subject: [PATCH 3/8] Use workdir for process --- src/main/java/io/mvnpm/esbuild/Bundler.java | 13 +++++++------ src/main/java/io/mvnpm/esbuild/Execute.java | 10 +++++++--- src/main/java/io/mvnpm/esbuild/Main.java | 5 ++++- src/test/java/io/mvnpm/esbuild/ExecuteTest.java | 5 ++++- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/mvnpm/esbuild/Bundler.java b/src/main/java/io/mvnpm/esbuild/Bundler.java index d518cb1..3e2e495 100644 --- a/src/main/java/io/mvnpm/esbuild/Bundler.java +++ b/src/main/java/io/mvnpm/esbuild/Bundler.java @@ -54,7 +54,7 @@ public static BundleResult bundle(BundleOptions bundleOptions, boolean install) final Path dist = workDir.resolve(DIST); final EsBuildConfig esBuildConfig = createBundle(bundleOptions, workDir, dist); - final ExecuteResult executeResult = esBuild(esBuildConfig); + final ExecuteResult executeResult = esBuild(workDir, esBuildConfig); if (!Files.isDirectory(dist)) { throw new BundleException("Unexpected Error during bundling", executeResult.output()); @@ -81,7 +81,7 @@ public static Watch watch(BundleOptions bundleOptions, BuildEventListener eventL final EsBuildConfig esBuildConfig = createBundle(bundleOptions, workDir, dist); bundleOptions.getEsBuildConfig().setWatch(true); - final Process process = esBuild(esBuildConfig, eventListener); + final Process process = esBuild(workDir, esBuildConfig, eventListener); return new Watch(process, workDir); } @@ -101,15 +101,16 @@ public static void clearDependencies(Path nodeModulesDir) throws IOException { deleteRecursive(nodeModulesDir); } - protected static Process esBuild(EsBuildConfig esBuildConfig, BuildEventListener listener) throws IOException { + protected static Process esBuild(Path workDir, EsBuildConfig esBuildConfig, BuildEventListener listener) + throws IOException { final Path esBuildExec = new ExecutableResolver().resolve(Bundler.ESBUILD_EMBEDDED_VERSION); - final Execute execute = new Execute(esBuildExec.toFile(), esBuildConfig); + final Execute execute = new Execute(workDir, esBuildExec.toFile(), esBuildConfig); return execute.execute(listener); } - protected static ExecuteResult esBuild(EsBuildConfig esBuildConfig) throws IOException { + protected static ExecuteResult esBuild(Path workDir, EsBuildConfig esBuildConfig) throws IOException { final Path esBuildExec = new ExecutableResolver().resolve(Bundler.ESBUILD_EMBEDDED_VERSION); - final Execute execute = new Execute(esBuildExec.toFile(), esBuildConfig); + final Execute execute = new Execute(workDir, esBuildExec.toFile(), esBuildConfig); return execute.executeAndWait(); } diff --git a/src/main/java/io/mvnpm/esbuild/Execute.java b/src/main/java/io/mvnpm/esbuild/Execute.java index 9d9199e..c24f905 100644 --- a/src/main/java/io/mvnpm/esbuild/Execute.java +++ b/src/main/java/io/mvnpm/esbuild/Execute.java @@ -6,6 +6,7 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -29,16 +30,19 @@ public class Execute { }); private static final Logger logger = Logger.getLogger(Execute.class.getName()); + private final Path workDir; private final File esBuildExec; private EsBuildConfig esBuildConfig; private String[] args; - public Execute(File esBuildExec, EsBuildConfig esBuildConfig) { + public Execute(Path workDir, File esBuildExec, EsBuildConfig esBuildConfig) { + this.workDir = workDir; this.esBuildExec = esBuildExec; this.esBuildConfig = esBuildConfig; } - public Execute(File esBuildExec, String[] args) { + public Execute(Path workDir, File esBuildExec, String[] args) { + this.workDir = workDir; this.esBuildExec = esBuildExec; this.args = args; } @@ -85,7 +89,7 @@ private String[] getCommand(String[] args) { } public Process createProcess(final String[] command, final Optional listener) throws IOException { - Process process = new ProcessBuilder().command(command).start(); + Process process = new ProcessBuilder().directory(workDir.toFile()).command(command).start(); final InputStream s = process.getErrorStream(); if (listener.isPresent()) { EXECUTOR.execute(new Streamer(process::isAlive, s, listener.get())); diff --git a/src/main/java/io/mvnpm/esbuild/Main.java b/src/main/java/io/mvnpm/esbuild/Main.java index 7db2ae5..bb4dd6e 100644 --- a/src/main/java/io/mvnpm/esbuild/Main.java +++ b/src/main/java/io/mvnpm/esbuild/Main.java @@ -2,6 +2,7 @@ import java.io.IOException; import java.nio.file.Path; +import java.nio.file.Paths; import io.mvnpm.esbuild.model.ExecuteResult; import io.mvnpm.esbuild.resolve.ExecutableResolver; @@ -9,8 +10,10 @@ public class Main { public static void main(String[] args) throws IOException { + String workingDirectory = System.getProperty("user.dir"); final Path esBuildExec = new ExecutableResolver().resolve(Bundler.ESBUILD_EMBEDDED_VERSION); - final ExecuteResult executeResult = new Execute(esBuildExec.toFile(), args).executeAndWait(); + final ExecuteResult executeResult = new Execute(Paths.get(workingDirectory), esBuildExec.toFile(), args) + .executeAndWait(); System.out.println(executeResult.output()); } } diff --git a/src/test/java/io/mvnpm/esbuild/ExecuteTest.java b/src/test/java/io/mvnpm/esbuild/ExecuteTest.java index f35106f..e680fe3 100644 --- a/src/test/java/io/mvnpm/esbuild/ExecuteTest.java +++ b/src/test/java/io/mvnpm/esbuild/ExecuteTest.java @@ -4,6 +4,7 @@ import java.io.IOException; import java.nio.file.Path; +import java.nio.file.Paths; import org.junit.jupiter.api.Test; @@ -19,7 +20,9 @@ public void shouldExecuteEsBuild() throws IOException { esBuildConfig.setVersion(true); final String defaultVersion = Bundler.ESBUILD_EMBEDDED_VERSION; final Path path = new ExecutableResolver().resolve(defaultVersion); - final ExecuteResult executeResult = new Execute(path.toFile(), esBuildConfig).executeAndWait(); + String workingDirectory = System.getProperty("user.dir"); + final ExecuteResult executeResult = new Execute(Paths.get(workingDirectory), path.toFile(), esBuildConfig) + .executeAndWait(); assertTrue(executeResult.output().startsWith(defaultVersion)); } } From 024ac6ebd43b8bcc510e201c0cc3f241dd785f53 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Tue, 12 Dec 2023 09:40:39 +0100 Subject: [PATCH 4/8] esbuild that has scss plugin installed --- pom.xml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index a45a356..9503b4d 100644 --- a/pom.xml +++ b/pom.xml @@ -122,13 +122,13 @@ - - - - - - - + + + + + + + From f4dae59282c02b811c0840414e7cfa46e3fadf97 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Wed, 10 Jan 2024 12:38:12 +0100 Subject: [PATCH 5/8] use the version which includes sass --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9503b4d..2258366 100644 --- a/pom.xml +++ b/pom.xml @@ -38,7 +38,7 @@ UTF-8 0.19.5 3.6.0 - v0.0.2 + v0.0.3 2.23.0 1.9.0 3.5.0 From 3ab93d62206e7a28532bf961f4435baa2ca08876 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Mon, 15 Jan 2024 10:41:18 +0100 Subject: [PATCH 6/8] use the version which includes sass --- pom.xml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 2258366..e0bea56 100644 --- a/pom.xml +++ b/pom.xml @@ -36,9 +36,9 @@ 17 17 UTF-8 - 0.19.5 + 0.19.9 3.6.0 - v0.0.3 + v0.0.4 2.23.0 1.9.0 3.5.0 @@ -122,13 +122,13 @@ - - - - - - - + + + + + + + From b19a83f3127e9ee639b06ac54e4b5db205130f36 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Mon, 29 Jan 2024 13:57:44 +0100 Subject: [PATCH 7/8] changed release filename Signed-off-by: Erik Jan de Wit --- pom.xml | 14 +++++++------- .../io/mvnpm/esbuild/resolve/BundledResolver.java | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index e0bea56..3a23984 100644 --- a/pom.xml +++ b/pom.xml @@ -122,13 +122,13 @@ - - - - - - - + + + + + + + diff --git a/src/main/java/io/mvnpm/esbuild/resolve/BundledResolver.java b/src/main/java/io/mvnpm/esbuild/resolve/BundledResolver.java index 3eb2120..04b41f5 100644 --- a/src/main/java/io/mvnpm/esbuild/resolve/BundledResolver.java +++ b/src/main/java/io/mvnpm/esbuild/resolve/BundledResolver.java @@ -12,7 +12,7 @@ public BundledResolver(Resolver resolver) { @Override public Path resolve(String version) throws IOException { - final InputStream resource = getClass().getResourceAsStream("/%s-%s.tgz".formatted(CLASSIFIER, version)); + final InputStream resource = getClass().getResourceAsStream("/mvnpm-esbuild-%s-%s.tgz".formatted(CLASSIFIER, version)); if (resource != null) { return extract(resource, version); From c482cae3f044c56bf571e9fffd5392a4f617a440 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Wed, 31 Jan 2024 09:52:09 +0100 Subject: [PATCH 8/8] use new version scheme for bundled esbuild --- pom.xml | 18 +++++++-------- .../mvnpm/esbuild/resolve/BaseResolver.java | 6 ++--- .../esbuild/resolve/BundleCacheResolver.java | 22 +++++++++++++++++++ .../esbuild/resolve/BundledResolver.java | 6 +++-- .../esbuild/resolve/ExecutableResolver.java | 3 ++- .../java/io/mvnpm/esbuild/ExecuteTest.java | 4 ++-- .../esbuild/resolve/CacheResolverTest.java | 2 +- .../esbuild/resolve/DownloadResolverTest.java | 7 +++--- 8 files changed, 46 insertions(+), 22 deletions(-) create mode 100644 src/main/java/io/mvnpm/esbuild/resolve/BundleCacheResolver.java diff --git a/pom.xml b/pom.xml index 3a23984..1b9dd72 100644 --- a/pom.xml +++ b/pom.xml @@ -36,9 +36,9 @@ 17 17 UTF-8 - 0.19.9 + 0.19.9-mvnpm-0.0.5 3.6.0 - v0.0.4 + v0.0.5 2.23.0 1.9.0 3.5.0 @@ -122,13 +122,13 @@ - - - - - - - + + + + + + + diff --git a/src/main/java/io/mvnpm/esbuild/resolve/BaseResolver.java b/src/main/java/io/mvnpm/esbuild/resolve/BaseResolver.java index 039d079..e9bb56c 100644 --- a/src/main/java/io/mvnpm/esbuild/resolve/BaseResolver.java +++ b/src/main/java/io/mvnpm/esbuild/resolve/BaseResolver.java @@ -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 { diff --git a/src/main/java/io/mvnpm/esbuild/resolve/BundleCacheResolver.java b/src/main/java/io/mvnpm/esbuild/resolve/BundleCacheResolver.java new file mode 100644 index 0000000..da3626e --- /dev/null +++ b/src/main/java/io/mvnpm/esbuild/resolve/BundleCacheResolver.java @@ -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); + } +} diff --git a/src/main/java/io/mvnpm/esbuild/resolve/BundledResolver.java b/src/main/java/io/mvnpm/esbuild/resolve/BundledResolver.java index 04b41f5..034865b 100644 --- a/src/main/java/io/mvnpm/esbuild/resolve/BundledResolver.java +++ b/src/main/java/io/mvnpm/esbuild/resolve/BundledResolver.java @@ -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; @@ -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); diff --git a/src/main/java/io/mvnpm/esbuild/resolve/ExecutableResolver.java b/src/main/java/io/mvnpm/esbuild/resolve/ExecutableResolver.java index a44cb4b..21bafcc 100644 --- a/src/main/java/io/mvnpm/esbuild/resolve/ExecutableResolver.java +++ b/src/main/java/io/mvnpm/esbuild/resolve/ExecutableResolver.java @@ -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 diff --git a/src/test/java/io/mvnpm/esbuild/ExecuteTest.java b/src/test/java/io/mvnpm/esbuild/ExecuteTest.java index e680fe3..7b85af3 100644 --- a/src/test/java/io/mvnpm/esbuild/ExecuteTest.java +++ b/src/test/java/io/mvnpm/esbuild/ExecuteTest.java @@ -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; @@ -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()); } } diff --git a/src/test/java/io/mvnpm/esbuild/resolve/CacheResolverTest.java b/src/test/java/io/mvnpm/esbuild/resolve/CacheResolverTest.java index 82b1ce8..608fa5e 100644 --- a/src/test/java/io/mvnpm/esbuild/resolve/CacheResolverTest.java +++ b/src/test/java/io/mvnpm/esbuild/resolve/CacheResolverTest.java @@ -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()); diff --git a/src/test/java/io/mvnpm/esbuild/resolve/DownloadResolverTest.java b/src/test/java/io/mvnpm/esbuild/resolve/DownloadResolverTest.java index 043af7d..553e1de 100644 --- a/src/test/java/io/mvnpm/esbuild/resolve/DownloadResolverTest.java +++ b/src/test/java/io/mvnpm/esbuild/resolve/DownloadResolverTest.java @@ -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());