Skip to content
This repository was archived by the owner on Sep 19, 2025. It is now read-only.

Commit a4d7581

Browse files
Refactor code to be simpler
1 parent 263db91 commit a4d7581

File tree

1 file changed

+24
-16
lines changed
  • packages/google-closure-compiler/lib

1 file changed

+24
-16
lines changed

packages/google-closure-compiler/lib/utils.js

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,34 @@ import fs from 'node:fs';
1717
import {createRequire} from 'node:module';
1818
const require = createRequire(import.meta.url);
1919

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} */
2028
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';
3737
}
38+
const compilerPath = `google-closure-compiler-${platform}/compiler${binarySuffix}`;
39+
try {
40+
return require.resolve(compilerPath);
41+
} catch {}
3842
};
3943

44+
/**
45+
* @param {!Array<string>} platforms
46+
* @return {string}
47+
*/
4048
export const getFirstSupportedPlatform = (platforms) => {
4149
const platform = platforms.find((platform, index) => {
4250
switch (platform.toLowerCase()) {

0 commit comments

Comments
 (0)