Skip to content

Commit

Permalink
Address review
Browse files Browse the repository at this point in the history
  • Loading branch information
jgerigmeyer committed Jan 25, 2024
1 parent abd2a71 commit f05aa50
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/src/importer-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ export class NodePackageImporter {
[entryPointPathKey]?: string;

constructor(entryPointPath?: string) {
entryPointPath = entryPointPath
? p.resolve(process.cwd(), entryPointPath)
: require.main?.filename;
if (!entryPointPath) {
throw new Error(
'The Node package importer cannot determine an entry point ' +
'because `require.main.filename` is not defined. ' +
'Please provide an `entryPointPath` to the `NodePackageImporter`.'
);
}
this[entryPointPathKey] = entryPointPath;
}
}
Expand Down Expand Up @@ -58,18 +68,7 @@ export class ImporterRegistry<sync extends 'sync' | 'async'> {
const message = new proto.InboundMessage_CompileRequest_Importer();
if (importer instanceof NodePackageImporter) {
const importerMessage = new proto.NodePackageImporter();
const entryPointPath = importer[entryPointPathKey]
? p.resolve(process.cwd(), importer[entryPointPathKey])
: require.main?.filename;

if (!entryPointPath) {
throw new Error(
'The Node package importer cannot determine an entry point ' +
'because `require.main.filename` is not defined. ' +
'Please provide an `entryPointPath` to the `NodePackageImporter`.'
);
}
importerMessage.entryPointPath = entryPointPath;
importerMessage.entryPointPath = importer[entryPointPathKey]!;
message.importer = {
case: 'nodePackageImporter',
value: importerMessage,
Expand Down

0 comments on commit f05aa50

Please sign in to comment.