Skip to content

Commit

Permalink
feat(isValidNodeImport): support stripComments option (#236)
Browse files Browse the repository at this point in the history
  • Loading branch information
huang-julien committed Mar 27, 2024
1 parent 659e351 commit daef55a
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/syntax.ts
Expand Up @@ -63,6 +63,12 @@ export interface ValidNodeImportOptions extends ResolveOptions {
* Default: ['node', 'file', 'data']
*/
allowedProtocols?: Array<string>;
/**
* Whether to strip comments from the code before checking for ESM syntax.
*
* Default: false
*/
stripComments?: boolean;
}

const validNodeImportDefaults: ValidNodeImportOptions = {
Expand Down Expand Up @@ -115,5 +121,5 @@ export async function isValidNodeImport(
(await fsp.readFile(resolvedPath, "utf8").catch(() => {})) ||
"";

return !hasESMSyntax(code);
return !hasESMSyntax(code, { stripComments: options.stripComments });
}

0 comments on commit daef55a

Please sign in to comment.