From 46631cba3660c82881082f2cb02f4ba9ce992729 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 9 Jun 2022 18:29:36 -0400 Subject: [PATCH] feat: allow all file extension inputs (including `.jsx`) (#294) This fixes an issue where a file input ending with `.jsx` was not traced properly. Since we already fail gracefully for files that cannot be parsed, this PR removes the guard on all input file extensions. - Also fixes #249 --- src/node-file-trace.ts | 5 +---- test/unit.test.js | 3 +++ test/unit/jsx-input/dep.jsx | 1 + test/unit/jsx-input/input.jsx | 3 +++ test/unit/jsx-input/output.js | 4 ++++ 5 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 test/unit/jsx-input/dep.jsx create mode 100644 test/unit/jsx-input/input.jsx create mode 100644 test/unit/jsx-input/output.js diff --git a/src/node-file-trace.ts b/src/node-file-trace.ts index 17f819ff..7300e918 100644 --- a/src/node-file-trace.ts +++ b/src/node-file-trace.ts @@ -33,10 +33,7 @@ export async function nodeFileTrace(files: string[], opts: NodeFileTraceOptions await Promise.all(files.map(async file => { const path = resolve(file); await job.emitFile(path, 'initial'); - if (path.endsWith('.js') || path.endsWith('.cjs') || path.endsWith('.mjs') || path.endsWith('.node') || job.ts && (path.endsWith('.ts') || path.endsWith('.tsx'))) { - return job.emitDependency(path); - } - return undefined; + return job.emitDependency(path); })); const result: NodeFileTraceResult = { diff --git a/test/unit.test.js b/test/unit.test.js index 6792ed98..92dcb4be 100644 --- a/test/unit.test.js +++ b/test/unit.test.js @@ -50,6 +50,9 @@ for (const { testName, isRoot } of unitTests) { let inputFileNames = ["input.js"]; let outputFileName = "output.js"; + if (testName === "jsx-input") { + inputFileNames = ["input.jsx"]; + } if (testName === "tsx-input") { inputFileNames = ["input.tsx"]; } diff --git a/test/unit/jsx-input/dep.jsx b/test/unit/jsx-input/dep.jsx new file mode 100644 index 00000000..0ec1bcae --- /dev/null +++ b/test/unit/jsx-input/dep.jsx @@ -0,0 +1 @@ +export const dep =

dep

\ No newline at end of file diff --git a/test/unit/jsx-input/input.jsx b/test/unit/jsx-input/input.jsx new file mode 100644 index 00000000..76f0078e --- /dev/null +++ b/test/unit/jsx-input/input.jsx @@ -0,0 +1,3 @@ +import { readFileSync } from 'fs'; + +readFileSync(__dirname + '/dep.jsx'); diff --git a/test/unit/jsx-input/output.js b/test/unit/jsx-input/output.js new file mode 100644 index 00000000..f28d4788 --- /dev/null +++ b/test/unit/jsx-input/output.js @@ -0,0 +1,4 @@ +[ + "test/unit/jsx-input/dep.jsx", + "test/unit/jsx-input/input.jsx" +] \ No newline at end of file