facebook / jscodeshift

A JavaScript codemod toolkit.
https://jscodeshift.com
MIT License
9.11k stars 468 forks source link

Process all extensions by default #583

Closed trivikr closed 4 months ago

trivikr commented 5 months ago

Description

Fixes: https://github.com/facebook/jscodeshift/issues/582

Testing

Before

The ts files are not processed by default

$ ../jscodeshift/bin/jscodeshift.js example.ts 2>&1 | head -n 1
No files selected, nothing to do.

The extensions had to be explicitly passed

$ ../jscodeshift/bin/jscodeshift.js --extensions=ts example.ts 2>&1 | head -n 1
Processing 1 files...

By default, the extensions is set to js

$ ../jscodeshift/bin/jscodeshift.js --help | grep -A 1 extensions
      --extensions=EXT          transform files with these file extensions (comma separated list)
                                (default: js)

After

The ts files are processed without requiring to pass extensions

$ ../jscodeshift/bin/jscodeshift.js example.ts 2>&1 | head -n 1                
Processing 1 files...

The ts files are skipped if extensions do not allow it

$ ../jscodeshift/bin/jscodeshift.js --extensions=js example.ts 2>&1 | head -n 1
No files selected, nothing to do.

The ts files are process if extensions request for it

$ ../jscodeshift/bin/jscodeshift.js --extensions=ts example.ts 2>&1 | head -n 1
Processing 1 files...

By default, the extensions is not set

$ ../jscodeshift/bin/jscodeshift.js --help | grep -A 1 extensions
      --extensions=EXT          transform files with these file extensions (comma separated list)
      --(no-)fail-on-error      Return a non-zero code when there are errors
Daniel15 commented 5 months ago

This seems reasonable to me. What did old versions of jscodeshift do? Could this break anyone's workflow if they upgrade from jscodeshift < 0.15.1?

trivikr commented 5 months ago

What did old versions of jscodeshift do?

As per this bug report, the extensions were not respected https://github.com/facebook/jscodeshift/issues/561 I don't know how many versions the bug was present though.

Could this break anyone's workflow if they upgrade from jscodeshift < 0.15.1?

The only breaking change I can think of is that jscodeshift will start processing other files by default. It might surface parser failures - depending on how parser behaves.

Should we limit the default to only supported extensions, i.e. cjs,es,es6,js,jsx,mjs,ts,tsx, like it's done downstream in https://github.com/aws/aws-sdk-js-codemod/pull/770?

trivikr commented 5 months ago

Should we limit the default to only supported extensions, i.e. cjs,es,es6,js,jsx,mjs,ts,tsx, like it's done downstream in aws/aws-sdk-js-codemod#770?

I think https://github.com/facebook/jscodeshift/pull/584 is a safer fix, as it's more explicit.

I changed this PR to draft, and it can be closed without merge.

Daniel15 commented 4 months ago

Thanks!