<path> does not support proper glob pattern and relies on shell glob expansion
See original GitHub issueConsider project tree:
app/
sub/sub.js
app.js
transform.js
The command:
jscodeshift app/**/*.js --dry
On macOS with Bash <4 or Bash 4 with globstar
not enabled, this pattern would match only:
sub.js
Expected:
sub.js
app.js
jscodeshift relies on the shell to expand the glob pattern, but without globstar
it doesn’t work as expected.
Of course I can upgrade my bash and enable globstar
(which I did in order to find out why it wasn’t working as expected), but I work with different teams, and intend to run jscodeshift in different environments, which I don’t always have control of (e.g. CI’s).
What’s more, when using an npm script, it’s tricky to tell npm to use the Bash shell installed with brew
, so it ends up using the older Bash version.
I see we’re already using micromatch
for --ignore-pattern
, can we use it for <path>
as well?
Then the user would need to wrap <path>
with double quotes (as we already do with ESLint, Prettier, etc.).
jscodeshift "app/**/*.js" --dry
As noted in Prettier README:
Don’t forget the quotes around the globs! The quotes make sure that Prettier expands the globs rather than your shell, for cross-platform usage. The glob syntax from the glob module is used.
I’m willing to PR with some guidance.
The first thought I had was to run micromatch
on each path provided and normalize paths
in Runner.js
to contain micromatch
ed files.
But I guess there are some considerations to take, like it’s probably a breaking change since it would match more files then t currently does in certain situation like I mentioned above.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:6
Top GitHub Comments
you can solve like this
This drove me crazy. I tried running jscodeshift from a package.json
scripts
but couldn’t get it working on Windows. This has to do something about glob expand as mentioned here. My workaround in the end was adding bash -c to my script pacakge.json script:bash -c 'jscodeshift -t rename.ts ../src/**/*.tsx --parser tsx -d -p'