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 does not work with a quote delimited string. #2436

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ryanpcmcquen
Copy link

As I discovered in my own project. When using .ts files alongside .js files, passing a quote delimited string to --extensions, causes Babel to ignore plain .js files:

extensions_string_issue

Commands are as follows:

"build": "babel src/ -s --extensions .js,.jsx,.ts,.tsx -d lib/",
"build-broken": "babel src/ -s --extensions '.js,.jsx,.ts,.tsx' -d lib/",

There may be other areas that need to be updated ... or perhaps this is just a bug?

@netlify
Copy link

netlify bot commented Jan 3, 2021

✔️ Deploy preview for babel ready!
Built without sensitive environment variables

🔨 Explore the source changes: 46b65b0

🔍 Inspect the deploy logs: https://app.netlify.com/sites/babel/deploys/5ff18b73d474df00076cae31

😎 Browse the preview: https://deploy-preview-2436--babel.netlify.app

@ryanpcmcquen
Copy link
Author

Here is an exact commit where this can be repro'd:
ryanpcmcquen/inkdrop_wiki_links@1428c56

@JLHwung
Copy link
Contributor

JLHwung commented Jan 14, 2021

I don't think we have to change --extensions ".ts" to --extensions .ts

@babel/cli does not support comma-separated --extensions string, if you want to provide variadic options

--extensions .ts .js

or

--extensions .ts --extensions .js

See also https://github.com/tj/commander.js/#variadic-option

@ryanpcmcquen
Copy link
Author

Well, this works:

--extensions .js,.jsx,.ts,.tsx

This does not:

--extensions '.js,.jsx,.ts,.tsx'

And this does not:

--extensions ".js,.jsx,.ts,.tsx"

Despite comma separated strings not being supported, they have propagated well across the internet, even landing in an official Microsoft project promoting Babel with TypeScript:

https://github.com/microsoft/TypeScript-Babel-Starter/blob/d7f039380418fcd4d59e6bd4ab3fd8e405d07196/package.json#L10

    "build:js": "babel src --out-dir lib --extensions \".ts,.tsx\" --source-maps inline"

They are on Microsoft's site as well:

https://devblogs.microsoft.com/typescript/typescript-and-babel-7/

Other various sites have picked up on this syntax now for it to become somewhat idiomatic ... since the quote delimiting is superfluous, is there any reason to keep it in the documentation?

@nicolo-ribaudo
Copy link
Member

We'll then need a new tests to make sure that comma separated extensions don't accidentally stop working.

@JLHwung
Copy link
Contributor

JLHwung commented Jul 30, 2021

Here is an exact commit where this can be repro'd:

Thanks for the reproduction repo. However, I can not reproduce this issue: yarn build-broken works for me. It seems that there are inconsistent behaviours between macOS and Windows.

yarn run v1.22.10
warning [email protected]: The engine "inkdrop" appears to be invalid.
$ babel src/ -s --extensions '.js,.jsx,.ts,.tsx' -d lib/
Successfully compiled 4 files with Babel (654ms).
✨  Done in 0.95s.

In your case, the '.js,.jsx,.ts,.tsx' might be passed down to process.argv as "'.js,.jsx,.ts,.tsx'". After it is split by ,, it becomes an array of '.js, .jsx, .ts and .tsx'. So from your side, adding quotes to comma-separated string does not work.

@babel/cli does not support comma-separated --extensions string

I was wrong. Babel does support comma separated extensions: https://github.com/babel/babel/blob/d3a7cd5e8d5f99fb0b465a5c1d7209d5e1e6ab03/packages/babel-cli/src/babel/options.ts#L354

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 this pull request may close these issues.

3 participants