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

[Bug] jscodeshift@0.15.1 ignores the files not starting with .js extension by default #582

Closed
trivikr opened this issue Feb 20, 2024 · 5 comments · Fixed by #584
Closed

Comments

@trivikr
Copy link
Contributor

trivikr commented Feb 20, 2024

Describe the bug

The jscodeshift ignores the file if it's extension does not match the default one

Steps to reproduce

$ echo 'export default function transformer(file, api) {
  return api.jscodeshift(file.source).toSource();
}' > transform.js

$ echo '' > example.ts

$ npx jscodeshift@0.15.1 example.ts

Observed behavior

The file example.ts is not processed, even though CLI explicitly asked for it.

$ npx jscodeshift@0.15.1 example.ts

No files selected, nothing to do. 
All done. 
Results: 
0 errors
0 unmodified
0 skipped
0 ok
Time elapsed: 0.001seconds

This happens as extensions is set to js by default, and the fix from #562 caused regression.

Expected behavior

The file example.ts is processed, like it happens in 0.15.0

$ npx jscodeshift@0.15.0 example.ts

Processing 1 files... 
Spawning 1 workers...
Sending 1 files to free worker...
All done. 
Results: 
0 errors
1 unmodified
0 skipped
0 ok
Time elapsed: 0.251seconds

If extensions is not explicitly specified by user, it should default to all extensions.

Additional context

This issue was noticed in downstream utility aws/aws-sdk-js-codemod#766 (comment)

@trivikr
Copy link
Contributor Author

trivikr commented Feb 20, 2024

cc participants from previous discussion for awareness @robcmills @Daniel15 @lg-kialo

@trivikr
Copy link
Contributor Author

trivikr commented Feb 20, 2024

There are two solutions I can think of for updated default value of extensions:

@trivikr
Copy link
Contributor Author

trivikr commented Feb 20, 2024

Example fix which allows all extensions by default #583

Although this fixes the regression, it will send all files for processing by default and will have a performance impact if the folder has lot of files.

@danieldelcore
Copy link

danieldelcore commented Feb 20, 2024

I find folks trip over this quite often. My thinking with @hypermod/cli was to turn on all extensions by default and parse them with the TSX parser since it's a large superset of js/jsx/ts (there are some minor caveats here in the form of generic syntax between ts and TSX, perhaps TS would have been a better way to go 😬).

https://github.com/hypermod-io/hypermod-community/blob/3b4722329bed3f02ac56c23c89925e6b906b9fa7/packages/cli/src/index.ts#L37-L49

@trivikr
Copy link
Contributor Author

trivikr commented Feb 21, 2024

I posted a safer fix at #584, which explicitly passes supported JavaScript and TypeScript files.

@trivikr trivikr changed the title [Bug] jscodeshift@0.15.1 ignores the file if it's extension does not match the default one [Bug] jscodeshift@0.15.1 ignores the files not starting with `.js Feb 21, 2024
@trivikr trivikr changed the title [Bug] jscodeshift@0.15.1 ignores the files not starting with `.js [Bug] jscodeshift@0.15.1 ignores the files not starting with .js extension by default Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants