1313import org .apache .commons .compress .archivers .tar .TarArchiveEntry ;
1414import org .apache .commons .compress .archivers .tar .TarArchiveInputStream ;
1515import org .apache .commons .compress .compressors .gzip .GzipCompressorInputStream ;
16+ import org .apache .commons .io .FileUtils ;
1617
1718final class Resolvers {
1819 private static final Logger logger = Logger .getLogger (Resolvers .class .getName ());
@@ -39,10 +40,29 @@ static Path resolveExecutablePath(Path bundleDir) {
3940 return bundleDir .resolve (isWindows () ? path + ".exe" : path );
4041 }
4142
42- static Path requireExecutablePath (Path bundleDir ) throws IOException {
43+ static Path resolveSassExecutablePath (Path bundleDir ) {
44+ String path = "dart-sass/sass" ;
45+ return bundleDir .resolve (isWindows () ? path + ".bat" : path );
46+ }
47+
48+ static Path getExecutablePath (Path bundleDir ) throws IOException {
4349 final Path path = resolveExecutablePath (bundleDir );
4450 if (!Files .isExecutable (path )) {
45- throw new IOException ("Invalid esbuild executable: " + path );
51+ return null ;
52+ }
53+ if (bundleDir .toString ().contains ("-mvnpm-" )) {
54+ // check for scss
55+ if (!Files .isExecutable (resolveSassExecutablePath (bundleDir ))) {
56+ return null ;
57+ }
58+ }
59+ return path ;
60+ }
61+
62+ static Path requireExecutablePath (Path bundleDir ) throws IOException {
63+ final Path path = getExecutablePath (bundleDir );
64+ if (path == null ) {
65+ throw new IOException ("Invalid esbuild executable in: " + bundleDir );
4666 }
4767 return path ;
4868 }
@@ -63,27 +83,29 @@ private static boolean isWindows() {
6383 private static String determineClassifier () {
6484 final String osName = System .getProperty ("os.name" ).toLowerCase ();
6585 final String osArch = System .getProperty ("os.arch" ).toLowerCase ();
66- String classifier ;
67-
86+ String classifier = null ;
6887 if (osName .contains ("mac" )) {
6988 if (osArch .equals ("aarch64" ) || osArch .contains ("arm" )) {
70- classifier = "darwin -arm64" ;
89+ classifier = "macos -arm64" ;
7190 } else {
72- classifier = "darwin -x64" ;
91+ classifier = "macos -x64" ;
7392 }
7493 } else if (osName .contains ("win" )) {
75- classifier = osArch .contains ("64" ) ? "win32-x64" : "win32-ia32" ;
94+ if (osArch .equals ("aarch64" ) || osArch .equals ("arm64" )) {
95+ classifier = "windows-arm64" ;
96+ } else if (osArch .contains ("64" )) {
97+ classifier = "windows-x64" ;
98+ }
7699 } else {
77100 if (osArch .equals ("aarch64" ) || osArch .equals ("arm64" )) {
78101 classifier = "linux-arm64" ;
79- } else if (osArch .contains ("arm" )) {
80- classifier = "linux-arm" ;
81102 } else if (osArch .contains ("64" )) {
82103 classifier = "linux-x64" ;
83- } else {
84- classifier = "linux-ia32" ;
85104 }
86105 }
106+ if (classifier == null ) {
107+ throw new EsbuildResolutionException ("Incompatible os: '%s' and arch: '%s' for esbuild" .formatted (osName , osArch ));
108+ }
87109 return classifier ;
88110 }
89111
@@ -93,9 +115,10 @@ static Path extract(InputStream archive, String destination) throws IOException
93115 }
94116
95117 static Path extract (InputStream archive , File destination ) throws IOException {
96- if (! destination .exists ()) {
97- destination . mkdirs ( );
118+ if (destination . isDirectory () && destination .exists ()) {
119+ FileUtils . deleteDirectory ( destination );
98120 }
121+ destination .mkdirs ();
99122
100123 try (GzipCompressorInputStream gzipIn = new GzipCompressorInputStream (archive );
101124 TarArchiveInputStream tarIn = new TarArchiveInputStream (gzipIn )) {
0 commit comments