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

[preset-env] target.node=true should use package.engines.node #7277

Open
julien-f opened this issue Jan 26, 2018 · 18 comments
Open

[preset-env] target.node=true should use package.engines.node #7277

julien-f opened this issue Jan 26, 2018 · 18 comments

Comments

@julien-f
Copy link

@julien-f julien-f commented Jan 26, 2018

Is this a bug report or feature request?

Feature request

Input Code

var your => (code) => here;

Babel/Babylon Configuration (.babelrc, package.json, cli command)

{
  presets: ['env', { targets: { node: true } }]
}

package.json:

{
  "engines": {
    "node": ">=6"
  }
}

Expected Behavior

It should target the Node version specified in package.engines.node.

Current Behavior

It targets the current Node version.

Possible Solution

current should still use the current version, but true could use package.engines.node.

Context

I currently have to maintain in sync the targeted Node version both in package.json and in the Babel config.

Your Environment

software version(s)
Babel
Babylon
node
npm
Operating System
@babel-bot
Copy link
Collaborator

@babel-bot babel-bot commented Jan 26, 2018

Hey @julien-f! We really appreciate you taking the time to report an issue. The collaborators
on this project attempt to help as many people as possible, but we're a limited number of volunteers,
so it's possible this won't be addressed swiftly.

If you need any help, or just have general Babel or JavaScript questions, we have a vibrant Slack
community that typically always has someone willing to help. You can sign-up here
for an invite.

@Andarist
Copy link
Member

@Andarist Andarist commented Jan 27, 2018

Wouldnt node: "engines" be more explicit and readable? Although it's also worth discussing if engines could support also some format for browsers - and if yes then this should be a top-level option and not only for node.

@julien-f
Copy link
Author

@julien-f julien-f commented Jan 27, 2018

engines is already a standard field in package.json, see the documentation.

Concerning the browsers, preset-env uses browserslist which does expose a pseudo-standard browserslist field (doc).

@Andarist
Copy link
Member

@Andarist Andarist commented Jan 27, 2018

I know its a standard field, but as it is an object with "node" key and it could easily support browsers too - but i guess it could have been more useful for other things (i.e. when consuming packages with specified engines.browsers) and is not tightly related to your request

@julien-f
Copy link
Author

@julien-f julien-f commented Jan 27, 2018

Yes, it could support browsers as well, but this probably an issue that should be created in the browserslist repo :)

@existentialism
Copy link
Member

@existentialism existentialism commented Jan 27, 2018

For history/reference: babel/babel-preset-env#114

@jaydenseric
Copy link

@jaydenseric jaydenseric commented Jan 29, 2018

It should just read from engines by default, like it reads from browserslist by default. Zero configuration FTW!

That you have to set this up manually is my single biggest frustration with present-env. In .babelrc.js I require package.json and pull in engines.node.

It is shocking how many published packages don't follow best practice to define engines.node; making it the default way to configure preset-env could really help this situation.

@julien-f
Copy link
Author

@julien-f julien-f commented Jan 29, 2018

Agreed, but this should be overridable (maybe with node: false).

@grantlouisherman
Copy link

@grantlouisherman grantlouisherman commented Apr 25, 2018

Is this ticket still open?

@xtuc
Copy link
Member

@xtuc xtuc commented May 4, 2018

@grantlouisherman
Copy link

@grantlouisherman grantlouisherman commented May 7, 2018

@xtuc I would like to take it if possible.

@DZuz14
Copy link

@DZuz14 DZuz14 commented Jun 26, 2018

@existentialism
Copy link
Member

@existentialism existentialism commented Jun 26, 2018

You can reference a previous PR for this over at the old repo: babel/babel-preset-env#114.

Keep in mind, there were some unresolved questions in that thread that we might want to nail down :)

@DZuz14
Copy link

@DZuz14 DZuz14 commented Jun 26, 2018

Excuse my naivety on this issue(and the Babel project in general), but why cant the node field in targets just have a simple true or false value, and require that people set their node version in package.engines.node in their package.json?

In the package.json, you'd have to explicitly specify "current", ">=6" etc.

@renatoagds
Copy link

@renatoagds renatoagds commented Jul 23, 2018

Is this issue still open? Can I claim it? :)

@dhruvdutt
Copy link

@dhruvdutt dhruvdutt commented Aug 16, 2018

Is this still available to work on?

@julien-f
Copy link
Author

@julien-f julien-f commented Sep 13, 2018

I believe so.

@existentialism do you confirm?

@niftylettuce
Copy link

@niftylettuce niftylettuce commented Sep 24, 2018

What would be really nice is to be able to specify the node targets in package.json, e.g. nodeTargets, and also make use of browserlist key in package.json as well. Right now if you specify a targets option in .babelrc and also have .browserlistrc file, the .browserlistrc file will not be read. In some cases such as using eslint with plugins like eslint-plugin-compat (to check for browser compatibility using caniuse database) - you always need to specify the same browserlist string... It's quite ugly.

niftylettuce added a commit to cabinjs/axe that referenced this issue Sep 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
You can’t perform that action at this time.