Skip to content
This repository was archived by the owner on Nov 19, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/google-closure-compiler-java/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"description": "Check, compile, optimize and compress Javascript with Closure-Compiler using Java",
"type": "module",
"main": "index.js",
"repository": "https://github.com/google/closure-compiler-npm/tree/master/packages/google-closure-compiler-java",
"repository": {
"type": "git",
"url": "git+https://github.com/google/closure-compiler-npm.git#master"
},
"homepage": "https://developers.google.com/closure/compiler/",
"author": "Chad Killingsworth <[email protected]>",
"license": "Apache-2.0",
Expand Down
50 changes: 25 additions & 25 deletions packages/google-closure-compiler/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,38 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import fs from 'node:fs';
import {createRequire} from 'node:module';
const require = createRequire(import.meta.url);

/** @type {!Map<string, string>} */
const platformLookup = new Map([
['darwin', 'macos'],
['win32', 'windows'],
['linux', 'linux'],
]);

/** @return {string|undefined} */
export const getNativeImagePath = () => {
if (process.platform === 'darwin') {
try {
return require('google-closure-compiler-macos').default;
} catch (e) {
return;
}
}
if (process.platform === 'win32') {
try {
return require('google-closure-compiler-windows').default;
} catch (e) {
return;
}
}
if (process.platform === 'linux' && ['x64','x32'].includes(process.arch)) {
try {
return require('google-closure-compiler-linux').default;
} catch (e) {
}
}
if (process.platform === 'linux' && ['arm64'].includes(process.arch)) {
try {
return require('google-closure-compiler-linux-arm64').default;
} catch (e) {
}
let platform = platformLookup.get(process.platform);
let binarySuffix = '';
if (!platform) {
return;
} else if (platform === 'linux' && process.arch === 'arm64') {
platform += '-arm64';
} else if (platform === 'windows') {
binarySuffix = '.exe';
}
const compilerPath = `google-closure-compiler-${platform}/compiler${binarySuffix}`;
try {
return require.resolve(compilerPath);
} catch {}
};

/**
* @param {!Array<string>} platforms
* @return {string}
*/
export const getFirstSupportedPlatform = (platforms) => {
const platform = platforms.find((platform, index) => {
switch (platform.toLowerCase()) {
Expand Down
Loading