Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trace entry files without extension #249

Closed
remorses opened this issue Nov 20, 2021 · 3 comments · Fixed by #294
Closed

Trace entry files without extension #249

remorses opened this issue Nov 20, 2021 · 3 comments · Fixed by #294
Labels
bug Something isn't working

Comments

@remorses
Copy link

Currently files passed to nodeFileTrace without extension are not traced beacuse of this line

if (path.endsWith('.js') || path.endsWith('.cjs') || path.endsWith('.mjs') || path.endsWith('.node') || job.ts && (path.endsWith('.ts') || path.endsWith('.tsx'))) {

However it is common for files that end up in .bin directory to not have an extension (and also to have #!/usr/bin/env node on top, which already works), these files are still js code but they don't have the 'js' extension

The following will not trace the files dependencies because next/dist/bin/next does not have an extension

await nodeFileTrace([require.resolve('next/dist/bin/next')])
@styfle styfle added the bug Something isn't working label Nov 21, 2021
@styfle
Copy link
Member

styfle commented Nov 21, 2021

We might need to peek in the file contents to check if the first line contains a hash bang.

@guybedford Could we remove this if statement since it seems like the caller should avoid calling nodeFileTrace() for non-JS files, right?

@guybedford
Copy link
Contributor

The reason for this is that Node.js in ESM mode doesn't execute files without an extension, although it does in CJS mode.

We could perhaps add an exception for the initial entry point specifically (isMain kind of thing, which is fairly common).

@styfle
Copy link
Member

styfle commented Jun 9, 2022

I think this guard can be removed for input files and we can fail gracefully during parse failures: #294

styfle added a commit that referenced this issue Jun 9, 2022
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants