diff --git a/packages/google-closure-compiler-java/package.json b/packages/google-closure-compiler-java/package.json index 966b3861..60628681 100644 --- a/packages/google-closure-compiler-java/package.json +++ b/packages/google-closure-compiler-java/package.json @@ -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 ", "license": "Apache-2.0", diff --git a/packages/google-closure-compiler/lib/utils.js b/packages/google-closure-compiler/lib/utils.js index 66f736d9..8230c1ac 100644 --- a/packages/google-closure-compiler/lib/utils.js +++ b/packages/google-closure-compiler/lib/utils.js @@ -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} */ +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} platforms + * @return {string} + */ export const getFirstSupportedPlatform = (platforms) => { const platform = platforms.find((platform, index) => { switch (platform.toLowerCase()) {