-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
create babel-preset and babel-register modules #13973
Changes from 1 commit
b538428
cea0b97
02bcba8
716e547
1d81afb
6e9a141
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
require('../src/optimize/babel/register'); | ||
require('../src/babel-register'); | ||
require('../src/docs/cli'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
require('../src/optimize/babel/register'); | ||
require('../src/babel-register'); | ||
require('../src/es_archiver/cli'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
require('../src/optimize/babel/register'); | ||
require('../src/babel-register'); | ||
require('../src/functional_test_runner/cli'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
require('../src/optimize/babel/register'); | ||
require('../src/babel-register'); | ||
require('../test/scripts/run_mocha'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
presets: [ | ||
require.resolve('babel-preset-react'), | ||
], | ||
plugins: [ | ||
require.resolve('babel-plugin-add-module-exports'), | ||
// stage 3 | ||
require.resolve('babel-plugin-transform-async-generator-functions'), | ||
require.resolve('babel-plugin-transform-object-rest-spread'), | ||
// stage 2 | ||
require.resolve('babel-plugin-transform-class-properties'), | ||
], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module.exports = { | ||
presets: [ | ||
[ | ||
require.resolve('babel-preset-env'), | ||
{ | ||
targets: { | ||
node: 'current', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe add a comment above this line about what
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any thoughts on pulling this from package.json instead? I mention that only as a single-source-of-truth thing, as I honestly can't think of a situation where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I request that we keep "current" because I take advantage of the fact that I can run Kibana server in node v8 and babel-preset-env doesn't transpile async/await and makes debugging so much easier |
||
}, | ||
useBuiltIns: true, | ||
}, | ||
], | ||
require('./common'), | ||
], | ||
plugins: [ | ||
[ | ||
require.resolve('babel-plugin-transform-define'), | ||
{ | ||
'typeof BUILT_WITH_BABEL': 'true' | ||
} | ||
] | ||
] | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module.exports = { | ||
presets: [ | ||
[ | ||
require.resolve('babel-preset-env'), | ||
{ | ||
targets: { | ||
browsers: [ | ||
'last 2 versions', | ||
'> 5%', | ||
'Safari 7', // for PhantomJS support | ||
], | ||
}, | ||
useBuiltIns: true, | ||
}, | ||
], | ||
require('./common'), | ||
] | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// register and polyfill need to happen in this | ||
// order and in separate files. Checkout each file | ||
// for a much more detailed explaination | ||
require('./register'); | ||
require('./polyfill'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// `babel-preset-env` looks for and rewrites the following import | ||
// statement into a list of import statements based on the polyfills | ||
// necessary for our target environment (the current version of node) | ||
// but since it does that during compilation, `import 'babel-polyfill'` | ||
// must be in a file that is loaded with `require()` AFTER `babel-register` | ||
// is configured. | ||
// | ||
// This is why we have this single statement in it's own file and require | ||
// it from ./index.js | ||
import 'babel-polyfill'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const { resolve } = require('path'); | ||
|
||
// this must happen before `require('babel-register')` and can't be changed | ||
// once the module has been loaded | ||
if (!process.env.BABEL_CACHE_PATH) { | ||
process.env.BABEL_CACHE_PATH = resolve(__dirname, '../../optimize/.babelcache.json'); | ||
} | ||
|
||
// paths that babel-register should ignore | ||
const ignore = [ | ||
/[\\\/](node_modules|bower_components)[\\\/]/, | ||
]; | ||
|
||
if (typeof BUILT_WITH_BABEL !== 'undefined') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick: Could this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Haha, yeah, fair 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, now that I think about it, I kind of like that it looks unnatural, since it totally is. But I'll switch over to process.env.BUILT_WITH_BABEL and leave a comment that the environment variable should never be set... idk... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I can just replace There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good idea with the |
||
// in "production" builds we define `typeof BUILT_WITH_BABEL` as `true` | ||
// which indicates that all of the code in the `src` directory is already | ||
// built and can be ignored by `babel-register` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, not sure I follow the logic and struggled with the build, so I'll ask here instead: Why do we still run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We pre-transpile the server code but plugins are still transpiled in prod. |
||
ignore.push(resolve(__dirname, '../../src')); | ||
} | ||
|
||
// modifies all future calls to require() to automatically | ||
// compile the required source with babel | ||
require('babel-register')({ | ||
ignore, | ||
babelrc: false, | ||
presets: [ | ||
require.resolve('../babel-preset/node') | ||
], | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
require('../optimize/babel/register'); | ||
require('../babel-register'); | ||
require('./cli'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
require('../optimize/babel/register'); | ||
require('../babel-register'); | ||
require('./cli'); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
const babelJest = require('babel-jest'); | ||
const options = require('../optimize/babel/options'); | ||
|
||
const babelOptions = options.node; | ||
|
||
module.exports = babelJest.createTransformer(babelOptions); | ||
module.exports = babelJest.createTransformer({ | ||
presets: [ | ||
require.resolve('../babel-preset/node') | ||
] | ||
}); |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
require('../src/optimize/babel/register'); | ||
require('../src/babel-register'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is copy-pasted, just thought I'd make sure we add a comment here: the class properties proposal was merged with the private fields proposal into the "class fields" proposal, which is currently stage 3. I don't see a specific Babel transform for that proposal yet, though, but there is babel/proposals#12 which tracks this proposal. Maybe add a link to that Babel proposal?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that's a good point. I imagine once there is a solid class fields proposal it will go into babel-preset-env and collide with this transform, but I shall leave a comment nonetheless