Importing a script from `node -e` leaves process.argv[1] undefined, and pathToFileURL(undefined) throws on import. The bootstrap installer's signing step imports batch-sign-binaries.mjs this way, and it crashed when that pulled in sanitize-pe-signatures.mjs.
12 lines
438 B
JavaScript
12 lines
438 B
JavaScript
|
|
import path from 'node:path';
|
|
import { pathToFileURL } from 'node:url';
|
|
|
|
// returns true if the passsed file is being invoked from node,
|
|
// not imported. `node -e` / stdin runs have no argv[1]: nothing is main.
|
|
/** @param {string} importMetaUrl @returns {boolean} */
|
|
export function isMain(importMetaUrl) {
|
|
const entry = process.argv[1];
|
|
return entry !== undefined && importMetaUrl === pathToFileURL(path.resolve(entry)).href;
|
|
}
|