From 387e7fe91d27a3c409f63af74d524b96cb54e173 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Tue, 20 Feb 2024 15:50:17 -0800 Subject: [PATCH 1/2] Use `process.argv[1]` as a fallback for `new NodePackageImporter()` Closes #274 --- lib/src/importer-registry.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/src/importer-registry.ts b/lib/src/importer-registry.ts index be9c0dd1..b388076e 100644 --- a/lib/src/importer-registry.ts +++ b/lib/src/importer-registry.ts @@ -2,6 +2,7 @@ // MIT-style license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. +import {createRequire} from 'module'; import * as p from 'path'; import {URL} from 'url'; import {inspect} from 'util'; @@ -21,6 +22,10 @@ export class NodePackageImporter { ? p.resolve(entryPointDirectory) : require.main?.filename ? p.dirname(require.main.filename) + // TODO: Find a way to use `import.meta.main` once + // https://github.com/nodejs/node/issues/49440 is done. + : process.argv[1] + ? createRequire(process.argv[1]).resolve(process.argv[1]) : undefined; if (!entryPointDirectory) { throw new Error( From 9b4d939dbddbdac942b6a1466fbcc95f4997a300 Mon Sep 17 00:00:00 2001 From: Natalie Weizenbaum Date: Tue, 20 Feb 2024 16:49:35 -0800 Subject: [PATCH 2/2] Reformat, bafflingly --- lib/src/importer-registry.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/src/importer-registry.ts b/lib/src/importer-registry.ts index b388076e..7208950a 100644 --- a/lib/src/importer-registry.ts +++ b/lib/src/importer-registry.ts @@ -22,9 +22,9 @@ export class NodePackageImporter { ? p.resolve(entryPointDirectory) : require.main?.filename ? p.dirname(require.main.filename) - // TODO: Find a way to use `import.meta.main` once + : // TODO: Find a way to use `import.meta.main` once // https://github.com/nodejs/node/issues/49440 is done. - : process.argv[1] + process.argv[1] ? createRequire(process.argv[1]).resolve(process.argv[1]) : undefined; if (!entryPointDirectory) {