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

babel-register: Fast path without transpilation/source-map-support when no plugins are enabled? #6163

Open
papandreou opened this issue Aug 26, 2017 · 6 comments
Labels
PR: New Feature 🚀 A type of pull request used for our changelog categories

Comments

@papandreou
Copy link

Choose one: is this a bug report or feature request?

Feature request

I'm introducing babel and babel-preset-env in a project (unexpectedjs/unexpected#416) where the main development takes place in bleeding edge node, but the code has to be transpiled to work in older node.js versions (including on CI) and in older browsers.

Since node.js 8.3.0+ has a fairly complete ES201[567] implementation I thought I'd use that as the baseline so I wouldn't need to transpile anything in my main edit->save->test cycle. I expected babel-preset-env to just bypass the transpilation pipeline when none of the configured plugins are required in the running environment. It could simply unhook itself from require.extensions and not bother installing source-map-support.

The reasons why I'd like it to work like that are:

  1. Performance. I want my dev cycle to be fast. In this particular project I measured a difference of half a second between babel-register being active with no active plugins (warm cache) vs. not being required at all.
  2. Fewer layers of complexity wrt. the code being executed. Sometimes the transpilation is a leaky abstraction, has bugs of its own, and causes weird or mangled entries in stack traces. It'd be nice if those things didn't affect me while developing.

My .babelrc looks like this:

{
  "presets": [
    ["env", {
      "modules": false,
      "targets": {
        "node": "current"
      }
    }]
  ]
}

babel-preset-env's debug mode displays an empty list of plugins when I run it in node.js 8. However, I can tell that despite this fact, babel is still burning cycles processing and reserializing all my code. This results in a performance degradation of about half a second compared to removing --require babel-register from the mocha command line.

Since the premise of babel-preset-env is to dynamically adjust the amount of work that has be done, I expected it to disable babel's require hook altogether when the platform has all the required capabilities. The alternative would be for me to wrap babel-register in a module of my own and only execute the require when using node.js < 8.3.0, then use that instead of babel-register. However, that's hard to get to work with tools that include native babel support (such as jest), and the exact cutoff point is subject to change. To me it feels like something that babel itself should take care of.

I brought up the issue/idea in the slack channel here: https://babeljs.slack.com/archives/C0DFJT81H/p1503758913000063

There was a productive discussion, some potential caveats were brought up, but the idea of a fast path when no plugins are configured was not flat out rejected, so I'm taking the liberty of raising it here :)

Thanks in advance for considering it!

Your Environment

software version(s)
Babel 6.26.0 and the 7 betas
node 8.4.0
npm 5.3.0
Operating System
@babel-bot
Copy link
Collaborator

Hey @papandreou! 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.

@ljharb
Copy link
Member

ljharb commented Aug 26, 2017

Wouldn't you want the dev experience to mirror the CI/prod experience, "bugs of its own" and all?

@papandreou
Copy link
Author

@ljharb, that would be nice, of course, but since it's still a relatively rare occurrence, I can live with CI catching those cases.

@papandreou
Copy link
Author

I made a module called maybabel that helps me achieve what I want. It's inferior to having babel-preset-env determine the capabilities at runtime, so I still hope you'll consider this feature request.

@hzoo hzoo added the PR: New Feature 🚀 A type of pull request used for our changelog categories label Aug 31, 2017
@hzoo
Copy link
Member

hzoo commented Aug 31, 2017

Also similar to #5890. If we can determine nothing is run we should just return the file sure, would appreciate a pr if you want this earlier since we are trying to release v7

@loganfsmyth
Copy link
Member

Revisiting this, I'd be open to this as a Babel option like requirePlugins: boolean that would just return null; like we do when something matches ignore or fails to match only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: New Feature 🚀 A type of pull request used for our changelog categories
Projects
None yet
Development

No branches or pull requests

5 participants