Skip to content

Commit

Permalink
Merge pull request #80 from edewit/scss-esbuild-plugin
Browse files Browse the repository at this point in the history
esbuild that has scss plugin installed
  • Loading branch information
ia3andy authored Jan 31, 2024
2 parents ba1ddbb + c482cae commit 676113f
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 20 deletions.
17 changes: 9 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +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.2</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.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 @@ -121,13 +122,13 @@
<configuration>
<target>
<get dest="src/main/resources" skipexisting="true">
<url url="https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-${esbuild.version}.tgz" />
<url url="https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-${esbuild.version}.tgz" />
<url url="https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-${esbuild.version}.tgz" />
<url url="https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-${esbuild.version}.tgz" />
<url url="https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-${esbuild.version}.tgz" />
<url url="https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-${esbuild.version}.tgz" />
<url url="https://registry.npmjs.org/@esbuild/linux-ia32/-/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
8 changes: 4 additions & 4 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 All @@ -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;
}
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("/%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
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 676113f

Please sign in to comment.