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

Commit 263db91

Browse files
Avoid using require to import an ES module
1 parent d691e7a commit 263db91

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

packages/google-closure-compiler-java/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"description": "Check, compile, optimize and compress Javascript with Closure-Compiler using Java",
55
"type": "module",
66
"main": "index.js",
7-
"repository": "https://github.com/google/closure-compiler-npm/tree/master/packages/google-closure-compiler-java",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/google/closure-compiler-npm.git#master"
10+
},
811
"homepage": "https://developers.google.com/closure/compiler/",
912
"author": "Chad Killingsworth <[email protected]>",
1013
"license": "Apache-2.0",

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

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,35 +13,27 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
import fs from 'node:fs';
1617
import {createRequire} from 'node:module';
1718
const require = createRequire(import.meta.url);
1819

1920
export const getNativeImagePath = () => {
20-
if (process.platform === 'darwin') {
21-
try {
22-
return require('google-closure-compiler-macos').default;
23-
} catch (e) {
24-
return;
25-
}
26-
}
27-
if (process.platform === 'win32') {
28-
try {
29-
return require('google-closure-compiler-windows').default;
30-
} catch (e) {
31-
return;
32-
}
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;
3332
}
34-
if (process.platform === 'linux' && ['x64','x32'].includes(process.arch)) {
33+
if (compilerPath) {
3534
try {
36-
return require('google-closure-compiler-linux').default;
37-
} catch (e) {
38-
}
39-
}
40-
if (process.platform === 'linux' && ['arm64'].includes(process.arch)) {
41-
try {
42-
return require('google-closure-compiler-linux-arm64').default;
43-
} catch (e) {
44-
}
35+
return require.resolve(compilerPath);
36+
} catch {}
4537
}
4638
};
4739

0 commit comments

Comments
 (0)