chore: mutualize Babel 7 config
This commit is contained in:
parent
38d6130e89
commit
ded1127d64
47
@xen-orchestra/babel-config/index.js
Normal file
47
@xen-orchestra/babel-config/index.js
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
'use strict'
|
||||||
|
|
||||||
|
const PLUGINS_RE = /^(?:@babel\/plugin-.+|babel-plugin-lodash)$/
|
||||||
|
const PRESETS_RE = /^@babel\/preset-.+$/
|
||||||
|
|
||||||
|
const NODE_ENV = process.env.NODE_ENV || 'development'
|
||||||
|
const __PROD__ = NODE_ENV === 'production'
|
||||||
|
const __TEST__ = NODE_ENV === 'test'
|
||||||
|
|
||||||
|
module.exports = function (pkg, plugins, presets) {
|
||||||
|
plugins === undefined && (plugins = {})
|
||||||
|
|
||||||
|
presets === undefined && (presets = {})
|
||||||
|
presets['@babel/preset-env'] = {
|
||||||
|
debug: !__TEST__,
|
||||||
|
loose: true,
|
||||||
|
shippedProposals: true,
|
||||||
|
targets: __PROD__
|
||||||
|
? (() => {
|
||||||
|
let node = (pkg.engines || {}).node
|
||||||
|
if (node !== undefined) {
|
||||||
|
const trimChars = '^=>~'
|
||||||
|
while (trimChars.includes(node[0])) {
|
||||||
|
node = node.slice(1)
|
||||||
|
}
|
||||||
|
return { node: node }
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
: { browsers: '', node: 'current' },
|
||||||
|
useBuiltIns: '@babel/polyfill' in (pkg.dependencies || {}) && 'usage',
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.keys(pkg.devDependencies || {}).forEach(name => {
|
||||||
|
if (!(name in presets) && PLUGINS_RE.test(name)) {
|
||||||
|
plugins[name] = {}
|
||||||
|
} else if (!(name in presets) && PRESETS_RE.test(name)) {
|
||||||
|
presets[name] = {}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
comments: !__PROD__,
|
||||||
|
ignore: __TEST__ ? undefined : [/\.spec\.js$/],
|
||||||
|
plugins: Object.keys(plugins).map(plugin => [plugin, plugins[plugin]]),
|
||||||
|
presets: Object.keys(presets).map(preset => [preset, presets[preset]]),
|
||||||
|
}
|
||||||
|
}
|
11
@xen-orchestra/babel-config/package.json
Normal file
11
@xen-orchestra/babel-config/package.json
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"private": true,
|
||||||
|
"name": "@xen-orchestra/babel-config",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"homepage": "https://github.com/vatesfr/xen-orchestra/tree/master/packages/@xen-orchestra/babel-config",
|
||||||
|
"bugs": "https://github.com/vatesfr/xen-orchestra/issues",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/vatesfr/xen-orchestra.git"
|
||||||
|
}
|
||||||
|
}
|
@ -1,47 +1,3 @@
|
|||||||
'use strict'
|
module.exports = require('../../@xen-orchestra/babel-config')(
|
||||||
|
require('./package.json')
|
||||||
const NODE_ENV = process.env.NODE_ENV || 'development'
|
)
|
||||||
const __PROD__ = NODE_ENV === 'production'
|
|
||||||
const __TEST__ = NODE_ENV === 'test'
|
|
||||||
|
|
||||||
const pkg = require('./package')
|
|
||||||
|
|
||||||
const plugins = {
|
|
||||||
lodash: {},
|
|
||||||
}
|
|
||||||
|
|
||||||
const presets = {
|
|
||||||
'@babel/preset-env': {
|
|
||||||
debug: !__TEST__,
|
|
||||||
loose: true,
|
|
||||||
shippedProposals: true,
|
|
||||||
targets: __PROD__
|
|
||||||
? (() => {
|
|
||||||
let node = (pkg.engines || {}).node
|
|
||||||
if (node !== undefined) {
|
|
||||||
const trimChars = '^=>~'
|
|
||||||
while (trimChars.includes(node[0])) {
|
|
||||||
node = node.slice(1)
|
|
||||||
}
|
|
||||||
return { node: node }
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
: { browsers: '', node: 'current' },
|
|
||||||
useBuiltIns: '@babel/polyfill' in (pkg.dependencies || {}) && 'usage',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.keys(pkg.devDependencies || {}).forEach(name => {
|
|
||||||
if (!(name in presets) && /@babel\/plugin-.+/.test(name)) {
|
|
||||||
plugins[name] = {}
|
|
||||||
} else if (!(name in presets) && /@babel\/preset-.+/.test(name)) {
|
|
||||||
presets[name] = {}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
comments: !__PROD__,
|
|
||||||
ignore: __TEST__ ? undefined : [/\.spec\.js$/],
|
|
||||||
plugins: Object.keys(plugins).map(plugin => [plugin, plugins[plugin]]),
|
|
||||||
presets: Object.keys(presets).map(preset => [preset, presets[preset]]),
|
|
||||||
}
|
|
||||||
|
@ -1,47 +1,3 @@
|
|||||||
'use strict'
|
module.exports = require('../../@xen-orchestra/babel-config')(
|
||||||
|
require('./package.json')
|
||||||
const NODE_ENV = process.env.NODE_ENV || 'development'
|
)
|
||||||
const __PROD__ = NODE_ENV === 'production'
|
|
||||||
const __TEST__ = NODE_ENV === 'test'
|
|
||||||
|
|
||||||
const pkg = require('./package')
|
|
||||||
|
|
||||||
const plugins = {
|
|
||||||
lodash: {},
|
|
||||||
}
|
|
||||||
|
|
||||||
const presets = {
|
|
||||||
'@babel/preset-env': {
|
|
||||||
debug: !__TEST__,
|
|
||||||
loose: true,
|
|
||||||
shippedProposals: true,
|
|
||||||
targets: __PROD__
|
|
||||||
? (() => {
|
|
||||||
let node = (pkg.engines || {}).node
|
|
||||||
if (node !== undefined) {
|
|
||||||
const trimChars = '^=>~'
|
|
||||||
while (trimChars.includes(node[0])) {
|
|
||||||
node = node.slice(1)
|
|
||||||
}
|
|
||||||
return { node: node }
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
: { browsers: '', node: 'current' },
|
|
||||||
useBuiltIns: '@babel/polyfill' in (pkg.dependencies || {}) && 'usage',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.keys(pkg.devDependencies || {}).forEach(name => {
|
|
||||||
if (!(name in presets) && /@babel\/plugin-.+/.test(name)) {
|
|
||||||
plugins[name] = {}
|
|
||||||
} else if (!(name in presets) && /@babel\/preset-.+/.test(name)) {
|
|
||||||
presets[name] = {}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
comments: !__PROD__,
|
|
||||||
ignore: __TEST__ ? undefined : [/\.spec\.js$/],
|
|
||||||
plugins: Object.keys(plugins).map(plugin => [plugin, plugins[plugin]]),
|
|
||||||
presets: Object.keys(presets).map(preset => [preset, presets[preset]]),
|
|
||||||
}
|
|
||||||
|
@ -1,47 +1,3 @@
|
|||||||
'use strict'
|
module.exports = require('../../@xen-orchestra/babel-config')(
|
||||||
|
require('./package.json')
|
||||||
const NODE_ENV = process.env.NODE_ENV || 'development'
|
)
|
||||||
const __PROD__ = NODE_ENV === 'production'
|
|
||||||
const __TEST__ = NODE_ENV === 'test'
|
|
||||||
|
|
||||||
const pkg = require('./package')
|
|
||||||
|
|
||||||
const plugins = {
|
|
||||||
lodash: {},
|
|
||||||
}
|
|
||||||
|
|
||||||
const presets = {
|
|
||||||
'@babel/preset-env': {
|
|
||||||
debug: !__TEST__,
|
|
||||||
loose: true,
|
|
||||||
shippedProposals: true,
|
|
||||||
targets: __PROD__
|
|
||||||
? (() => {
|
|
||||||
let node = (pkg.engines || {}).node
|
|
||||||
if (node !== undefined) {
|
|
||||||
const trimChars = '^=>~'
|
|
||||||
while (trimChars.includes(node[0])) {
|
|
||||||
node = node.slice(1)
|
|
||||||
}
|
|
||||||
return { node: node }
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
: { browsers: '', node: 'current' },
|
|
||||||
useBuiltIns: '@babel/polyfill' in (pkg.dependencies || {}) && 'usage',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.keys(pkg.devDependencies || {}).forEach(name => {
|
|
||||||
if (!(name in presets) && /@babel\/plugin-.+/.test(name)) {
|
|
||||||
plugins[name] = {}
|
|
||||||
} else if (!(name in presets) && /@babel\/preset-.+/.test(name)) {
|
|
||||||
presets[name] = {}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
comments: !__PROD__,
|
|
||||||
ignore: __TEST__ ? undefined : [/\.spec\.js$/],
|
|
||||||
plugins: Object.keys(plugins).map(plugin => [plugin, plugins[plugin]]),
|
|
||||||
presets: Object.keys(presets).map(preset => [preset, presets[preset]]),
|
|
||||||
}
|
|
||||||
|
@ -1,47 +1,3 @@
|
|||||||
'use strict'
|
module.exports = require('../../@xen-orchestra/babel-config')(
|
||||||
|
require('./package.json')
|
||||||
const NODE_ENV = process.env.NODE_ENV || 'development'
|
)
|
||||||
const __PROD__ = NODE_ENV === 'production'
|
|
||||||
const __TEST__ = NODE_ENV === 'test'
|
|
||||||
|
|
||||||
const pkg = require('./package')
|
|
||||||
|
|
||||||
const plugins = {
|
|
||||||
lodash: {},
|
|
||||||
}
|
|
||||||
|
|
||||||
const presets = {
|
|
||||||
'@babel/preset-env': {
|
|
||||||
debug: !__TEST__,
|
|
||||||
loose: true,
|
|
||||||
shippedProposals: true,
|
|
||||||
targets: __PROD__
|
|
||||||
? (() => {
|
|
||||||
let node = (pkg.engines || {}).node
|
|
||||||
if (node !== undefined) {
|
|
||||||
const trimChars = '^=>~'
|
|
||||||
while (trimChars.includes(node[0])) {
|
|
||||||
node = node.slice(1)
|
|
||||||
}
|
|
||||||
return { node: node }
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
: { browsers: '', node: 'current' },
|
|
||||||
useBuiltIns: '@babel/polyfill' in (pkg.dependencies || {}) && 'usage',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.keys(pkg.devDependencies || {}).forEach(name => {
|
|
||||||
if (!(name in presets) && /@babel\/plugin-.+/.test(name)) {
|
|
||||||
plugins[name] = {}
|
|
||||||
} else if (!(name in presets) && /@babel\/preset-.+/.test(name)) {
|
|
||||||
presets[name] = {}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
comments: !__PROD__,
|
|
||||||
ignore: __TEST__ ? undefined : [/\.spec\.js$/],
|
|
||||||
plugins: Object.keys(plugins).map(plugin => [plugin, plugins[plugin]]),
|
|
||||||
presets: Object.keys(presets).map(preset => [preset, presets[preset]]),
|
|
||||||
}
|
|
||||||
|
@ -1,47 +1,3 @@
|
|||||||
'use strict'
|
module.exports = require('../../@xen-orchestra/babel-config')(
|
||||||
|
require('./package.json')
|
||||||
const NODE_ENV = process.env.NODE_ENV || 'development'
|
)
|
||||||
const __PROD__ = NODE_ENV === 'production'
|
|
||||||
const __TEST__ = NODE_ENV === 'test'
|
|
||||||
|
|
||||||
const pkg = require('./package')
|
|
||||||
|
|
||||||
const plugins = {
|
|
||||||
lodash: {},
|
|
||||||
}
|
|
||||||
|
|
||||||
const presets = {
|
|
||||||
'@babel/preset-env': {
|
|
||||||
debug: !__TEST__,
|
|
||||||
loose: true,
|
|
||||||
shippedProposals: true,
|
|
||||||
targets: __PROD__
|
|
||||||
? (() => {
|
|
||||||
let node = (pkg.engines || {}).node
|
|
||||||
if (node !== undefined) {
|
|
||||||
const trimChars = '^=>~'
|
|
||||||
while (trimChars.includes(node[0])) {
|
|
||||||
node = node.slice(1)
|
|
||||||
}
|
|
||||||
return { node: node }
|
|
||||||
}
|
|
||||||
})()
|
|
||||||
: { browsers: '', node: 'current' },
|
|
||||||
useBuiltIns: '@babel/polyfill' in (pkg.dependencies || {}) && 'usage',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
Object.keys(pkg.devDependencies || {}).forEach(name => {
|
|
||||||
if (!(name in presets) && /@babel\/plugin-.+/.test(name)) {
|
|
||||||
plugins[name] = {}
|
|
||||||
} else if (!(name in presets) && /@babel\/preset-.+/.test(name)) {
|
|
||||||
presets[name] = {}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
comments: !__PROD__,
|
|
||||||
ignore: __TEST__ ? undefined : [/\.spec\.js$/],
|
|
||||||
plugins: Object.keys(plugins).map(plugin => [plugin, plugins[plugin]]),
|
|
||||||
presets: Object.keys(presets).map(preset => [preset, presets[preset]]),
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user