Skip to content

Commit

Permalink
feat: allow all file extension inputs (including .jsx) (#294)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
styfle authored Jun 9, 2022
1 parent 0aefe4d commit 46631cb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/node-file-trace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
3 changes: 3 additions & 0 deletions test/unit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
}
Expand Down
1 change: 1 addition & 0 deletions test/unit/jsx-input/dep.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const dep = <h1>dep</h1>
3 changes: 3 additions & 0 deletions test/unit/jsx-input/input.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { readFileSync } from 'fs';

readFileSync(__dirname + '/dep.jsx');
4 changes: 4 additions & 0 deletions test/unit/jsx-input/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"test/unit/jsx-input/dep.jsx",
"test/unit/jsx-input/input.jsx"
]

0 comments on commit 46631cb

Please sign in to comment.