This repository was archived by the owner on Sep 19, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +24
-16
lines changed
packages/google-closure-compiler/lib Expand file tree Collapse file tree 1 file changed +24
-16
lines changed Original file line number Diff line number Diff line change @@ -17,26 +17,34 @@ import fs from 'node:fs';
17
17
import { createRequire } from 'node:module' ;
18
18
const require = createRequire ( import . meta. url ) ;
19
19
20
+ /** @type {!Map<string, string> } */
21
+ const platformLookup = new Map ( [
22
+ [ 'darwin' , 'macos' ] ,
23
+ [ 'win32' , 'windows' ] ,
24
+ [ 'linux' , 'linux' ] ,
25
+ ] ) ;
26
+
27
+ /** @return {string|undefined } */
20
28
export const getNativeImagePath = ( ) => {
21
- let compilerPath ;
22
- switch ( process . platform ) {
23
- case 'darwin' :
24
- compilerPath = 'google-closure-compiler-macos/compiler' ;
25
- break ;
26
- case 'win32' :
27
- compilerPath = 'google-closure-compiler-windows/compiler.exe' ;
28
- break ;
29
- case 'linux' :
30
- compilerPath = `google-closure-compiler-linux${ process . arch === 'arm64' ? '-arm64' : '' } /compiler` ;
31
- break ;
32
- }
33
- if ( compilerPath ) {
34
- try {
35
- return require . resolve ( compilerPath ) ;
36
- } catch { }
29
+ let platform = platformLookup . get ( process . platform ) ;
30
+ let binarySuffix = '' ;
31
+ if ( ! platform ) {
32
+ return ;
33
+ } else if ( platform === 'linux' && process . arch === 'arm64' ) {
34
+ platform += '-arm64' ;
35
+ } else if ( platform === 'windows' ) {
36
+ binarySuffix = '.exe' ;
37
37
}
38
+ const compilerPath = `google-closure-compiler-${ platform } /compiler${ binarySuffix } ` ;
39
+ try {
40
+ return require . resolve ( compilerPath ) ;
41
+ } catch { }
38
42
} ;
39
43
44
+ /**
45
+ * @param {!Array<string> } platforms
46
+ * @return {string }
47
+ */
40
48
export const getFirstSupportedPlatform = ( platforms ) => {
41
49
const platform = platforms . find ( ( platform , index ) => {
42
50
switch ( platform . toLowerCase ( ) ) {
You can’t perform that action at this time.
0 commit comments