question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

<path> does not support proper glob pattern and relies on shell glob expansion

See original GitHub issue

Consider 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 micromatched 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:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:6

github_iconTop GitHub Comments

2reactions
sibeliuscommented, Jun 25, 2020

you can solve like this

find /src -iname '*.ts' -print | xargs jscodeshift -t path/to/transform.ts
1reaction
johotcommented, Feb 3, 2021

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'

Read more comments on GitHub >

github_iconTop Results From Across the Web

bash - The best way to expand glob pattern?
Just let it expand inside an array declaration's right side: list=(../smth*/) # grab the list echo "${#list[@]}" # print array length echo "${list[@]}" ......
Read more >
Shell GLOB patterns (wildcard pathname matching) - Teaching
GLOB patterns do not only match file names. The names being matched by a GLOB pattern can be anything: files, directories, symbolic links,...
Read more >
Using a glob expression passed as a bash script argument
I don't fully understand when/why some arguments must be passed in quotes, but I assume it has to do with the wildcard expansion...
Read more >
glob (programming)
In computer programming, glob patterns specify sets of filenames with wildcard characters. For example, the Unix Bash shell command mv *.txt textfiles/ ...
Read more >
File Name Glob Patterns
A glob pattern matches a given file name if it successfully consumes and matches the entire name. Partial matches are failed matches. Most...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found