mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Upgrade to Babel 7 stable (#5042) (major)
🎉 https://twitter.com/left_pad/status/1034204330352500736
This commit is contained in:
parent
66ec2061c1
commit
4c891a7e8a
35
package.json
35
package.json
|
@ -42,6 +42,11 @@
|
||||||
"prepublish": "npm run release",
|
"prepublish": "npm run release",
|
||||||
"precommit": "lint-staged"
|
"precommit": "lint-staged"
|
||||||
},
|
},
|
||||||
|
"taskr": {
|
||||||
|
"requires": [
|
||||||
|
"./taskfile-babel.js"
|
||||||
|
]
|
||||||
|
},
|
||||||
"standard": {
|
"standard": {
|
||||||
"parser": "babel-eslint",
|
"parser": "babel-eslint",
|
||||||
"ignore": [
|
"ignore": [
|
||||||
|
@ -57,17 +62,17 @@
|
||||||
"bin/*": "standard"
|
"bin/*": "standard"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/core": "7.0.0-rc.1",
|
"@babel/core": "7.0.0",
|
||||||
"@babel/plugin-proposal-class-properties": "7.0.0-rc.1",
|
"@babel/plugin-proposal-class-properties": "7.0.0",
|
||||||
"@babel/plugin-proposal-object-rest-spread": "7.0.0-rc.1",
|
"@babel/plugin-proposal-object-rest-spread": "7.0.0",
|
||||||
"@babel/plugin-syntax-dynamic-import": "7.0.0-rc.1",
|
"@babel/plugin-syntax-dynamic-import": "7.0.0",
|
||||||
"@babel/plugin-transform-react-jsx-source": "7.0.0-rc.1",
|
"@babel/plugin-transform-react-jsx-source": "7.0.0",
|
||||||
"@babel/plugin-transform-runtime": "7.0.0-rc.1",
|
"@babel/plugin-transform-runtime": "7.0.0",
|
||||||
"@babel/preset-env": "7.0.0-rc.1",
|
"@babel/preset-env": "7.0.0",
|
||||||
"@babel/preset-react": "7.0.0-rc.1",
|
"@babel/preset-react": "7.0.0",
|
||||||
"@babel/runtime": "7.0.0-rc.1",
|
"@babel/runtime": "7.0.0",
|
||||||
"@babel/runtime-corejs2": "7.0.0-rc.1",
|
"@babel/runtime-corejs2": "7.0.0",
|
||||||
"@babel/template": "7.0.0-rc.1",
|
"@babel/template": "7.0.0",
|
||||||
"ansi-html": "0.0.7",
|
"ansi-html": "0.0.7",
|
||||||
"autodll-webpack-plugin": "0.4.2",
|
"autodll-webpack-plugin": "0.4.2",
|
||||||
"babel-core": "7.0.0-bridge.0",
|
"babel-core": "7.0.0-bridge.0",
|
||||||
|
@ -113,16 +118,15 @@
|
||||||
"write-file-webpack-plugin": "4.3.2"
|
"write-file-webpack-plugin": "4.3.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/preset-flow": "7.0.0-rc.1",
|
"@babel/preset-flow": "7.0.0",
|
||||||
"@taskr/babel": "1.1.0-next.1",
|
|
||||||
"@taskr/clear": "1.1.0",
|
"@taskr/clear": "1.1.0",
|
||||||
"@taskr/esnext": "1.1.0",
|
"@taskr/esnext": "1.1.0",
|
||||||
"@taskr/watch": "1.1.0",
|
"@taskr/watch": "1.1.0",
|
||||||
"@zeit/next-css": "0.2.1-canary.1",
|
"@zeit/next-css": "0.2.1-canary.1",
|
||||||
"@zeit/next-sass": "0.2.1-canary.1",
|
"@zeit/next-sass": "0.2.1-canary.1",
|
||||||
"@zeit/next-typescript": "1.1.0",
|
"@zeit/next-typescript": "1.1.0",
|
||||||
"babel-eslint": "8.2.2",
|
"babel-eslint": "9.0.0",
|
||||||
"babel-jest": "21.2.0",
|
"babel-jest": "23.4.2",
|
||||||
"benchmark": "2.1.4",
|
"benchmark": "2.1.4",
|
||||||
"cheerio": "0.22.0",
|
"cheerio": "0.22.0",
|
||||||
"chromedriver": "2.32.3",
|
"chromedriver": "2.32.3",
|
||||||
|
@ -131,6 +135,7 @@
|
||||||
"cross-env": "5.0.5",
|
"cross-env": "5.0.5",
|
||||||
"express": "4.15.5",
|
"express": "4.15.5",
|
||||||
"fkill": "5.1.0",
|
"fkill": "5.1.0",
|
||||||
|
"flatten": "1.0.2",
|
||||||
"flow-bin": "0.73.0",
|
"flow-bin": "0.73.0",
|
||||||
"get-port": "3.2.0",
|
"get-port": "3.2.0",
|
||||||
"husky": "0.14.3",
|
"husky": "0.14.3",
|
||||||
|
|
65
taskfile-babel.js
Normal file
65
taskfile-babel.js
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
// taskr babel plugin with Babel 7 support
|
||||||
|
// https://github.com/lukeed/taskr/pull/305
|
||||||
|
'use strict'
|
||||||
|
|
||||||
|
const transform = require('@babel/core').transform
|
||||||
|
const flatten = require('flatten')
|
||||||
|
|
||||||
|
const BABEL_REGEX = /(^@babel\/)(preset|plugin)-(.*)/i
|
||||||
|
|
||||||
|
function getBabels () {
|
||||||
|
const pkg = require('./package.json')
|
||||||
|
return flatten(
|
||||||
|
['devDependencies', 'dependencies'].map(s => Object.keys(pkg[s] || {}))
|
||||||
|
).filter(s => BABEL_REGEX.test(s))
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = function (task) {
|
||||||
|
let cache
|
||||||
|
|
||||||
|
task.plugin('babel', {}, function * (file, opts) {
|
||||||
|
if (opts.preload) {
|
||||||
|
delete opts.preload
|
||||||
|
// get dependencies
|
||||||
|
cache = cache || getBabels()
|
||||||
|
|
||||||
|
// attach any deps to babel's `opts`
|
||||||
|
cache.forEach(dep => {
|
||||||
|
const segs = BABEL_REGEX.exec(dep)
|
||||||
|
const type = `${segs[2]}s`
|
||||||
|
const name = `@babel/${segs[2]}-${segs[3]}`
|
||||||
|
|
||||||
|
opts[type] = opts[type] || []
|
||||||
|
|
||||||
|
// flatten all (advanced entries are arrays)
|
||||||
|
if (flatten(opts[type]).indexOf(name) === -1) {
|
||||||
|
opts[type] = opts[type].concat(name)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// attach file's name
|
||||||
|
opts.filename = file.base
|
||||||
|
|
||||||
|
const output = transform(file.data, opts)
|
||||||
|
|
||||||
|
if (output.map) {
|
||||||
|
const map = `${file.base}.map`
|
||||||
|
|
||||||
|
// append `sourceMappingURL` to original file
|
||||||
|
if (opts.sourceMaps !== 'both') {
|
||||||
|
output.code += Buffer.from(`\n//# sourceMappingURL=${map}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
// add sourcemap to `files` array
|
||||||
|
this._.files.push({
|
||||||
|
base: map,
|
||||||
|
dir: file.dir,
|
||||||
|
data: Buffer.from(JSON.stringify(output.map))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// update file's data
|
||||||
|
file.data = Buffer.from(output.code)
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in a new issue