From daef55a3f5f503001164f16c9d8a5c302fde0607 Mon Sep 17 00:00:00 2001 From: Julien Huang Date: Wed, 27 Mar 2024 11:40:22 +0100 Subject: [PATCH] feat(isValidNodeImport): support `stripComments` option (#236) --- src/syntax.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/syntax.ts b/src/syntax.ts index fe78deb..d08c3d5 100644 --- a/src/syntax.ts +++ b/src/syntax.ts @@ -63,6 +63,12 @@ export interface ValidNodeImportOptions extends ResolveOptions { * Default: ['node', 'file', 'data'] */ allowedProtocols?: Array; + /** + * Whether to strip comments from the code before checking for ESM syntax. + * + * Default: false + */ + stripComments?: boolean; } const validNodeImportDefaults: ValidNodeImportOptions = { @@ -115,5 +121,5 @@ export async function isValidNodeImport( (await fsp.readFile(resolvedPath, "utf8").catch(() => {})) || ""; - return !hasESMSyntax(code); + return !hasESMSyntax(code, { stripComments: options.stripComments }); }