You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
I think this is because of this code right here in jscodeshift/src/Runner.js:
In this function, filter is passed in from this methods only usage:
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
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.
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
The text was updated successfully, but these errors were encountered:
Description
If you run
jscodeshift
on the cli, with--extensions=ts
provided, and you pass individual file paths (not a directory) like this: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:
I think this is because of this code right here in
jscodeshift/src/Runner.js
:In this function,
filter
is passed in from this methods only usage: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
--extensions=ts
and pass it a filepath with a different extensionNote that it will not ignore that file and try to process it
Expected Behavior
--extensions
option should filter which files are processed, ignoring non-matching filesSystem Information:
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
The text was updated successfully, but these errors were encountered: