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

extensions cli option not respected when passing individual file paths #561

Closed
robcmills opened this issue Jun 28, 2023 · 0 comments · Fixed by #562
Closed

extensions cli option not respected when passing individual file paths #561

robcmills opened this issue Jun 28, 2023 · 0 comments · Fixed by #562

Comments

@robcmills
Copy link
Contributor

robcmills commented Jun 28, 2023

Description

If you run jscodeshift on the cli, with --extensions=ts provided, and you pass individual file paths (not a directory) like this:

jscodeshift -t transform.ts --extensions=ts readme.md

Then the extensions are not respected and files that do not match those extensions are sent to the workers and processed through your transform file. Clearly, if the file is not the expected extension, then when your transform function tries to parse it, you will get an error:

Screenshot 2023-06-28 at 10 45 40 AM

I think this is because of this code right here in jscodeshift/src/Runner.js:

Screenshot 2023-06-28 at 10 50 02 AM

In this function, filter is passed in from this methods only usage:

Screenshot 2023-06-28 at 10 55 43 AM

and you can see that it takes into account the extensions, filtering out any files that do not match. And in getAllFiles, you can see that if the file is a directory, then it filters the files, but the else if condition does not. The else if clause only accounts for ignore patterns.

To Reproduce

  1. Run jscodeshift from the cli with --extensions=ts and pass it a filepath with a different extension

Note that it will not ignore that file and try to process it

Processing 1 files...

Expected Behavior

--extensions option should filter which files are processed, ignoring non-matching files

System Information:

  • OS: Apple M1 Pro Ventura 13.4
  • Terminal: Warp v0.2023.06.20.08.04.stable_03
  • jscodeshift version: 0.15.0

Additional Context

My use case, which I believe is quite common, is running jscodeshift as a part of a Github workflow automation, where we run a git command to get a list of files that are changed in a PR as compared to a development (or main) branch, and then pass those files to the codemod. This results in many individual filepaths (instead of a directory) that can include non-typescript files.

Our current workaround is to just filter that list ourselves before passing it to jscodeshift, but it would be nice to not have that restriction and for jscodeshift to work as expected, so we can be confident in the stability of our generic codemod script.

Also, I opened a PR to fix: #562

Error Logs

npx jscodeshift -t transform.ts --extensions=ts readme.md
Processing 1 files...
Spawning 1 workers...
Sending 1 files to free worker...
 ERR readme.md Transformation error (Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option. (1:0))
SyntaxError: Topic reference is used, but the pipelineOperator plugin was not passed a "proposal": "hack" or "smart" option. (1:0)
    at instantiate (/Users/robcmills/src/jscodeshift-fix-extensions/node_modules/@babel/parser/src/parse-error/credentials.ts:62:21)
    at toParseError (/Users/robcmills/src/jscodeshift-fix-extensions/node_modules/@babel/parser/src/parse-error.ts:60:12)
    at TypeScriptParserMixin.raise (/Users/robcmills/src/jscodeshift-fix-extensions/node_modules/@babel/parser/src/tokenizer/index.ts:1487:19)
    at TypeScriptParserMixin.testTopicReferenceConfiguration (/Users/robcmills/src/jscodeshift-fix-extensions/node_modules/@babel/parser/src/parser/expression.ts:1505:20)
    at TypeScriptParserMixin.finishTopicReference (/Users/robcmills/src/jscodeshift-fix-extensions/node_modules/@babel/parser/src/parser/expression.ts:1437:12)
    at TypeScriptParserMixin.parseTopicReference (/Users/robcmills/src/jscodeshift-fix-extensions/node_modules/@babel/parser/src/parser/expression.ts:1414:17)
    at TypeScriptParserMixin.parseExprAtom (/Users/robcmills/src/jscodeshift-fix-extensions/node_modules/@babel/parser/src/parser/expression.ts:1275:23)
    at TypeScriptParserMixin.parseExprAtom (/Users/robcmills/src/jscodeshift-fix-extensions/node_modules/@babel/parser/src/plugins/jsx/index.ts:574:22)
    at TypeScriptParserMixin.parseExprSubscripts (/Users/robcmills/src/jscodeshift-fix-extensions/node_modules/@babel/parser/src/parser/expression.ts:718:23)
    at TypeScriptParserMixin.parseUpdate (/Users/robcmills/src/jscodeshift-fix-extensions/node_modules/@babel/parser/src/parser/expression.ts:695:21)
All done.
Results:
1 errors
0 unmodified
0 skipped
0 ok
Time elapsed: 0.369seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant