Skip to content

Commit

Permalink
Reduce transpilation on Node.js >=4 (#1068)
Browse files Browse the repository at this point in the history
Better startup performance and improved stack traces.
  • Loading branch information
sindresorhus committed Oct 9, 2016
1 parent 16b7e53 commit 4025d81
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/babel-config.js
Expand Up @@ -4,6 +4,7 @@ var chalk = require('chalk');
var figures = require('figures');
var convertSourceMap = require('convert-source-map');
var objectAssign = require('object-assign');
var semver = require('semver');
var colors = require('./colors');

function validate(conf) {
Expand Down Expand Up @@ -40,9 +41,13 @@ function lazy(initFn) {
}

var defaultPresets = lazy(function () {
var esPreset = semver.satisfies(process.version, '>=4') ?
'babel-preset-es2015-node4' :
'babel-preset-es2015';

return [
require('babel-preset-stage-2'),
require('babel-preset-es2015')
require(esPreset)
];
});

Expand Down
3 changes: 2 additions & 1 deletion lib/caching-precompiler.js
Expand Up @@ -76,7 +76,8 @@ CachingPrecompiler.prototype._transform = function (code, filePath, hash) {
CachingPrecompiler.prototype._createTransform = function () {
var salt = packageHash.sync(
[require.resolve('../package.json')].concat(babelConfigHelper.pluginPackages),
JSON.stringify(this.babelConfig)
JSON.stringify(this.babelConfig),
process.version.split('.')[0]
);

return cachingTransform({
Expand Down
2 changes: 2 additions & 0 deletions package.json
Expand Up @@ -100,6 +100,7 @@
"babel-plugin-espower": "^2.3.1",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-preset-es2015": "^6.16.0",
"babel-preset-es2015-node4": "^2.1.0",
"babel-preset-stage-2": "^6.17.0",
"babel-runtime": "^6.11.6",
"bluebird": "^3.0.0",
Expand Down Expand Up @@ -151,6 +152,7 @@
"repeating": "^2.0.0",
"require-precompiled": "^0.1.0",
"resolve-cwd": "^1.0.0",
"semver": "^5.3.0",
"set-immediate-shim": "^1.0.1",
"source-map-support": "^0.4.0",
"stack-utils": "^0.4.0",
Expand Down

2 comments on commit 4025d81

@sheerun
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sindresorhus
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explained in the PR #1068:

Long-term we'll want to use babel-preset-env, but it's too immature at the moment. I didn't include a specific preset for Node.js 6 as it didn't improve performance and will be solved with the eventual use of babel-preset-env.

This is just a temp improvement.

Please sign in to comment.