rollup-plugin-babel
Advanced tools
Comparing version 4.0.0-beta.5 to 4.0.0-beta.6
@@ -5,4 +5,4 @@ 'use strict'; | ||
var core = require('@babel/core'); | ||
var helperModuleImports = require('@babel/helper-module-imports'); | ||
var rollupPluginutils = require('rollup-pluginutils'); | ||
var helperModuleImports = require('@babel/helper-module-imports'); | ||
@@ -17,2 +17,15 @@ var INLINE = {}; | ||
var MODULE_ERROR = | ||
'Rollup requires that your Babel configuration keeps ES6 module syntax intact. ' + | ||
'Unfortunately it looks like your configuration specifies a module transformer ' + | ||
'to replace ES6 modules with another module format. To continue you have to disable it.' + | ||
'\n\n' + | ||
'Most commonly it\'s a CommonJS transform added by @babel/preset-env - ' + | ||
'in such case you should disable it by adding `modules: false` option to that preset ' + | ||
'(described in more detail here - https://github.com/rollup/rollup-plugin-babel#modules ).'; | ||
var UNEXPECTED_ERROR = | ||
'An unexpected situation arose. Please raise an issue at ' + | ||
'https://github.com/rollup/rollup-plugin-babel/issues. Thanks!'; | ||
function fallbackClassTransform () { | ||
@@ -28,39 +41,43 @@ return { | ||
var preflightCheckResults = {}; | ||
function createPreflightCheck () { | ||
var preflightCheckResults = {}; | ||
function preflightCheck ( options, dir ) { | ||
if ( !preflightCheckResults[ dir ] ) { | ||
var helpers; | ||
return function ( ctx, options, dir ) { | ||
if ( !preflightCheckResults[ dir ] ) { | ||
var helpers; | ||
options = Object.assign( {}, options ); | ||
delete options.only; | ||
delete options.ignore; | ||
options = Object.assign( {}, options ); | ||
delete options.only; | ||
delete options.ignore; | ||
options.filename = path.join( dir, 'x.js' ); | ||
options.filename = path.join( dir, 'x.js' ); | ||
var inputCode = 'class Foo extends Bar {};\nexport default Foo;'; | ||
var check = core.transform( inputCode, options ).code; | ||
var inputCode = 'class Foo extends Bar {};\nexport default Foo;'; | ||
var check = core.transform( inputCode, options ).code; | ||
if ( ~check.indexOf('class ') ) { | ||
options.plugins = (options.plugins || []).concat( fallbackClassTransform ); | ||
check = core.transform( inputCode, options ).code; | ||
} | ||
if ( ~check.indexOf('class ') ) { | ||
options.plugins = (options.plugins || []).concat( fallbackClassTransform ); | ||
check = core.transform( inputCode, options ).code; | ||
} | ||
if ( ~check.indexOf( 'import _inherits' ) ) { helpers = RUNTIME; } | ||
else if ( ~check.indexOf( 'function _inherits' ) ) { helpers = INLINE; } | ||
else if ( ~check.indexOf( 'babelHelpers' ) ) { helpers = EXTERNAL; } | ||
else { | ||
throw new Error( 'An unexpected situation arose. Please raise an issue at https://github.com/rollup/rollup-plugin-babel/issues. Thanks!' ); | ||
} | ||
if ( | ||
!~check.indexOf( 'export default' ) && | ||
!~check.indexOf( 'export default Foo' ) && | ||
!~check.indexOf( 'export { Foo as default }' ) | ||
) { | ||
ctx.error( MODULE_ERROR ); | ||
} | ||
if ( | ||
!~check.indexOf( 'export default' ) && | ||
!~check.indexOf( 'export default Foo' ) && | ||
!~check.indexOf( 'export { Foo as default }' ) | ||
) { throw new Error( 'It looks like your Babel configuration specifies a module transformer. Please disable it. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information' ); } | ||
if ( ~check.indexOf( '/helpers/inherits' ) ) { helpers = RUNTIME; } | ||
else if ( ~check.indexOf( 'function _inherits' ) ) { helpers = INLINE; } | ||
else if ( ~check.indexOf( 'babelHelpers' ) ) { helpers = EXTERNAL; } | ||
else { | ||
ctx.error( UNEXPECTED_ERROR ); | ||
} | ||
preflightCheckResults[ dir ] = helpers; | ||
} | ||
preflightCheckResults[ dir ] = helpers; | ||
} | ||
return preflightCheckResults[ dir ]; | ||
return preflightCheckResults[ dir ]; | ||
}; | ||
} | ||
@@ -83,39 +100,39 @@ | ||
var warned = {}; | ||
function warnOnce ( warn, msg ) { | ||
function warnOnce ( ctx, msg ) { | ||
if ( warned[ msg ] ) { return; } | ||
warned[ msg ] = true; | ||
warn( msg ); | ||
ctx.warn( msg ); | ||
} | ||
function babel ( options ) { | ||
options = Object.assign( {}, options || {} ); | ||
function objectWithoutProperties (obj, exclude) { var target = {}; for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) target[k] = obj[k]; return target; } | ||
var filter = rollupPluginutils.createFilter( options.include, options.exclude ); | ||
delete options.include; | ||
delete options.exclude; | ||
var unpackOptions = function (ref) { | ||
if ( ref === void 0 ) ref = {}; | ||
var sourcemap = ref.sourcemap; if ( sourcemap === void 0 ) sourcemap = true; | ||
var sourcemaps = ref.sourcemaps; if ( sourcemaps === void 0 ) sourcemaps = true; | ||
var sourceMap = ref.sourceMap; if ( sourceMap === void 0 ) sourceMap = true; | ||
var sourceMaps = ref.sourceMaps; if ( sourceMaps === void 0 ) sourceMaps = true; | ||
var rest$1 = objectWithoutProperties( ref, ["sourcemap", "sourcemaps", "sourceMap", "sourceMaps"] ); | ||
var rest = rest$1; | ||
if ( options.sourceMap !== false ) { options.sourceMaps = true; } | ||
if ( options.sourceMaps !== false ) { options.sourceMaps = true; } | ||
delete options.sourceMap; | ||
return (Object.assign({}, {sourceMaps: sourcemap && sourcemaps && sourceMap && sourceMaps}, | ||
rest)); | ||
}; | ||
var runtimeHelpers = options.runtimeHelpers; | ||
delete options.runtimeHelpers; | ||
function babel ( options ) { | ||
var ref = unpackOptions(options); | ||
var exclude = ref.exclude; | ||
var externalHelpers = ref.externalHelpers; | ||
var externalHelpersWhitelist = ref.externalHelpersWhitelist; | ||
var include = ref.include; | ||
var runtimeHelpers = ref.runtimeHelpers; | ||
var rest = objectWithoutProperties( ref, ["exclude", "externalHelpers", "externalHelpersWhitelist", "include", "runtimeHelpers"] ); | ||
var babelOptions = rest; | ||
var externalHelpers; | ||
if ( options.externalHelpers ) { externalHelpers = true; } | ||
delete options.externalHelpers; | ||
var filter = rollupPluginutils.createFilter( include, exclude ); | ||
var preflightCheck = createPreflightCheck(); | ||
var externalHelpersWhitelist = null; | ||
if ( options.externalHelpersWhitelist ) { externalHelpersWhitelist = options.externalHelpersWhitelist; } | ||
delete options.externalHelpersWhitelist; | ||
var warn = function (msg) { return console.warn(msg); }; // eslint-disable-line no-console | ||
return { | ||
name: 'babel', | ||
options: function options ( options$1 ) { | ||
warn = options$1.onwarn || warn; | ||
}, | ||
resolveId: function resolveId ( id ) { | ||
@@ -137,11 +154,11 @@ if ( id === HELPERS ) { return id; } | ||
var helpers = preflightCheck( options, path.dirname( id ) ); | ||
var helpers = preflightCheck( this, babelOptions, path.dirname( id ) ); | ||
if ( helpers === EXTERNAL && !externalHelpers ) { | ||
warnOnce( warn, 'Using "external-helpers" plugin with rollup-plugin-babel is deprecated, as it now automatically deduplicates your Babel helpers.' ); | ||
warnOnce( this, 'Using "external-helpers" plugin with rollup-plugin-babel is deprecated, as it now automatically deduplicates your Babel helpers.' ); | ||
} else if ( helpers === RUNTIME && !runtimeHelpers ) { | ||
throw new Error( 'Runtime helpers are not enabled. Either exclude the transform-runtime Babel plugin or pass the `runtimeHelpers: true` option. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information' ); | ||
this.error( 'Runtime helpers are not enabled. Either exclude the transform-runtime Babel plugin or pass the `runtimeHelpers: true` option. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information' ); | ||
} | ||
var localOpts = Object.assign({ filename: id }, options); | ||
var localOpts = Object.assign({ filename: id }, babelOptions); | ||
@@ -148,0 +165,0 @@ if ( helpers !== RUNTIME ) { |
@@ -1,5 +0,5 @@ | ||
import { dirname, join } from 'path'; | ||
import { buildExternalHelpers, transform } from '@babel/core'; | ||
import { join, dirname } from 'path'; | ||
import { transform, buildExternalHelpers } from '@babel/core'; | ||
import { addNamed } from '@babel/helper-module-imports'; | ||
import { createFilter } from 'rollup-pluginutils'; | ||
import { addNamed } from '@babel/helper-module-imports'; | ||
@@ -14,7 +14,20 @@ var INLINE = {}; | ||
var MODULE_ERROR = | ||
'Rollup requires that your Babel configuration keeps ES6 module syntax intact. ' + | ||
'Unfortunately it looks like your configuration specifies a module transformer ' + | ||
'to replace ES6 modules with another module format. To continue you have to disable it.' + | ||
'\n\n' + | ||
'Most commonly it\'s a CommonJS transform added by @babel/preset-env - ' + | ||
'in such case you should disable it by adding `modules: false` option to that preset ' + | ||
'(described in more detail here - https://github.com/rollup/rollup-plugin-babel#modules ).'; | ||
var UNEXPECTED_ERROR = | ||
'An unexpected situation arose. Please raise an issue at ' + | ||
'https://github.com/rollup/rollup-plugin-babel/issues. Thanks!'; | ||
function fallbackClassTransform () { | ||
return { | ||
visitor: { | ||
ClassDeclaration: function ClassDeclaration (path$$1, state) { | ||
path$$1.replaceWith(path$$1, state.file.addHelper('inherits')); | ||
ClassDeclaration: function ClassDeclaration (path, state) { | ||
path.replaceWith(path, state.file.addHelper('inherits')); | ||
} | ||
@@ -25,39 +38,43 @@ } | ||
var preflightCheckResults = {}; | ||
function createPreflightCheck () { | ||
var preflightCheckResults = {}; | ||
function preflightCheck ( options, dir ) { | ||
if ( !preflightCheckResults[ dir ] ) { | ||
var helpers; | ||
return function ( ctx, options, dir ) { | ||
if ( !preflightCheckResults[ dir ] ) { | ||
var helpers; | ||
options = Object.assign( {}, options ); | ||
delete options.only; | ||
delete options.ignore; | ||
options = Object.assign( {}, options ); | ||
delete options.only; | ||
delete options.ignore; | ||
options.filename = join( dir, 'x.js' ); | ||
options.filename = join( dir, 'x.js' ); | ||
var inputCode = 'class Foo extends Bar {};\nexport default Foo;'; | ||
var check = transform( inputCode, options ).code; | ||
var inputCode = 'class Foo extends Bar {};\nexport default Foo;'; | ||
var check = transform( inputCode, options ).code; | ||
if ( ~check.indexOf('class ') ) { | ||
options.plugins = (options.plugins || []).concat( fallbackClassTransform ); | ||
check = transform( inputCode, options ).code; | ||
} | ||
if ( ~check.indexOf('class ') ) { | ||
options.plugins = (options.plugins || []).concat( fallbackClassTransform ); | ||
check = transform( inputCode, options ).code; | ||
} | ||
if ( ~check.indexOf( 'import _inherits' ) ) { helpers = RUNTIME; } | ||
else if ( ~check.indexOf( 'function _inherits' ) ) { helpers = INLINE; } | ||
else if ( ~check.indexOf( 'babelHelpers' ) ) { helpers = EXTERNAL; } | ||
else { | ||
throw new Error( 'An unexpected situation arose. Please raise an issue at https://github.com/rollup/rollup-plugin-babel/issues. Thanks!' ); | ||
} | ||
if ( | ||
!~check.indexOf( 'export default' ) && | ||
!~check.indexOf( 'export default Foo' ) && | ||
!~check.indexOf( 'export { Foo as default }' ) | ||
) { | ||
ctx.error( MODULE_ERROR ); | ||
} | ||
if ( | ||
!~check.indexOf( 'export default' ) && | ||
!~check.indexOf( 'export default Foo' ) && | ||
!~check.indexOf( 'export { Foo as default }' ) | ||
) { throw new Error( 'It looks like your Babel configuration specifies a module transformer. Please disable it. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information' ); } | ||
if ( ~check.indexOf( '/helpers/inherits' ) ) { helpers = RUNTIME; } | ||
else if ( ~check.indexOf( 'function _inherits' ) ) { helpers = INLINE; } | ||
else if ( ~check.indexOf( 'babelHelpers' ) ) { helpers = EXTERNAL; } | ||
else { | ||
ctx.error( UNEXPECTED_ERROR ); | ||
} | ||
preflightCheckResults[ dir ] = helpers; | ||
} | ||
preflightCheckResults[ dir ] = helpers; | ||
} | ||
return preflightCheckResults[ dir ]; | ||
return preflightCheckResults[ dir ]; | ||
}; | ||
} | ||
@@ -80,39 +97,39 @@ | ||
var warned = {}; | ||
function warnOnce ( warn, msg ) { | ||
function warnOnce ( ctx, msg ) { | ||
if ( warned[ msg ] ) { return; } | ||
warned[ msg ] = true; | ||
warn( msg ); | ||
ctx.warn( msg ); | ||
} | ||
function babel ( options ) { | ||
options = Object.assign( {}, options || {} ); | ||
function objectWithoutProperties (obj, exclude) { var target = {}; for (var k in obj) if (Object.prototype.hasOwnProperty.call(obj, k) && exclude.indexOf(k) === -1) target[k] = obj[k]; return target; } | ||
var filter = createFilter( options.include, options.exclude ); | ||
delete options.include; | ||
delete options.exclude; | ||
var unpackOptions = function (ref) { | ||
if ( ref === void 0 ) ref = {}; | ||
var sourcemap = ref.sourcemap; if ( sourcemap === void 0 ) sourcemap = true; | ||
var sourcemaps = ref.sourcemaps; if ( sourcemaps === void 0 ) sourcemaps = true; | ||
var sourceMap = ref.sourceMap; if ( sourceMap === void 0 ) sourceMap = true; | ||
var sourceMaps = ref.sourceMaps; if ( sourceMaps === void 0 ) sourceMaps = true; | ||
var rest$1 = objectWithoutProperties( ref, ["sourcemap", "sourcemaps", "sourceMap", "sourceMaps"] ); | ||
var rest = rest$1; | ||
if ( options.sourceMap !== false ) { options.sourceMaps = true; } | ||
if ( options.sourceMaps !== false ) { options.sourceMaps = true; } | ||
delete options.sourceMap; | ||
return (Object.assign({}, {sourceMaps: sourcemap && sourcemaps && sourceMap && sourceMaps}, | ||
rest)); | ||
}; | ||
var runtimeHelpers = options.runtimeHelpers; | ||
delete options.runtimeHelpers; | ||
function babel ( options ) { | ||
var ref = unpackOptions(options); | ||
var exclude = ref.exclude; | ||
var externalHelpers = ref.externalHelpers; | ||
var externalHelpersWhitelist = ref.externalHelpersWhitelist; | ||
var include = ref.include; | ||
var runtimeHelpers = ref.runtimeHelpers; | ||
var rest = objectWithoutProperties( ref, ["exclude", "externalHelpers", "externalHelpersWhitelist", "include", "runtimeHelpers"] ); | ||
var babelOptions = rest; | ||
var externalHelpers; | ||
if ( options.externalHelpers ) { externalHelpers = true; } | ||
delete options.externalHelpers; | ||
var filter = createFilter( include, exclude ); | ||
var preflightCheck = createPreflightCheck(); | ||
var externalHelpersWhitelist = null; | ||
if ( options.externalHelpersWhitelist ) { externalHelpersWhitelist = options.externalHelpersWhitelist; } | ||
delete options.externalHelpersWhitelist; | ||
var warn = function (msg) { return console.warn(msg); }; // eslint-disable-line no-console | ||
return { | ||
name: 'babel', | ||
options: function options ( options$1 ) { | ||
warn = options$1.onwarn || warn; | ||
}, | ||
resolveId: function resolveId ( id ) { | ||
@@ -134,11 +151,11 @@ if ( id === HELPERS ) { return id; } | ||
var helpers = preflightCheck( options, dirname( id ) ); | ||
var helpers = preflightCheck( this, babelOptions, dirname( id ) ); | ||
if ( helpers === EXTERNAL && !externalHelpers ) { | ||
warnOnce( warn, 'Using "external-helpers" plugin with rollup-plugin-babel is deprecated, as it now automatically deduplicates your Babel helpers.' ); | ||
warnOnce( this, 'Using "external-helpers" plugin with rollup-plugin-babel is deprecated, as it now automatically deduplicates your Babel helpers.' ); | ||
} else if ( helpers === RUNTIME && !runtimeHelpers ) { | ||
throw new Error( 'Runtime helpers are not enabled. Either exclude the transform-runtime Babel plugin or pass the `runtimeHelpers: true` option. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information' ); | ||
this.error( 'Runtime helpers are not enabled. Either exclude the transform-runtime Babel plugin or pass the `runtimeHelpers: true` option. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information' ); | ||
} | ||
var localOpts = Object.assign({ filename: id }, options); | ||
var localOpts = Object.assign({ filename: id }, babelOptions); | ||
@@ -145,0 +162,0 @@ if ( helpers !== RUNTIME ) { |
{ | ||
"name": "rollup-plugin-babel", | ||
"version": "4.0.0-beta.5", | ||
"version": "4.0.0-beta.6", | ||
"description": "Seamless integration between Rollup and Babel.", | ||
@@ -36,4 +36,4 @@ "main": "dist/rollup-plugin-babel.cjs.js", | ||
"dependencies": { | ||
"@babel/helper-module-imports": "7.0.0-beta.49", | ||
"rollup-pluginutils": "^2.0.1" | ||
"@babel/helper-module-imports": "7.0.0-beta.51", | ||
"rollup-pluginutils": "^2.3.0" | ||
}, | ||
@@ -44,14 +44,14 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@babel/core": "7.0.0-beta.49", | ||
"@babel/plugin-external-helpers": "7.0.0-beta.49", | ||
"@babel/plugin-proposal-decorators": "7.0.0-beta.49", | ||
"@babel/plugin-transform-runtime": "7.0.0-beta.49", | ||
"@babel/preset-env": "7.0.0-beta.49", | ||
"buble": "^0.18.0", | ||
"eslint": "^3.12.0", | ||
"mocha": "^3.2.0", | ||
"rollup": "^0.52.2", | ||
"rollup-plugin-buble": "^0.18.0", | ||
"source-map": "^0.5.6", | ||
"source-map-support": "^0.4.6" | ||
"@babel/core": "7.0.0-beta.51", | ||
"@babel/plugin-external-helpers": "7.0.0-beta.51", | ||
"@babel/plugin-proposal-decorators": "7.0.0-beta.51", | ||
"@babel/plugin-transform-runtime": "7.0.0-beta.51", | ||
"@babel/preset-env": "7.0.0-beta.51", | ||
"buble": "^0.19.3", | ||
"eslint": "^5.0.1", | ||
"mocha": "^5.2.0", | ||
"rollup": "^0.62.0", | ||
"rollup-plugin-buble": "^0.19.2", | ||
"source-map": "^0.6.1", | ||
"source-map-support": "^0.5.6" | ||
}, | ||
@@ -58,0 +58,0 @@ "repository": "rollup/rollup-plugin-babel", |
@@ -95,2 +95,11 @@ # rollup-plugin-babel | ||
However, setting `modules: false` in your `.babelrc` may conflict if you are using `babel-register`. To work around this, specify `babelrc: false` in your rollup config. This allows Rollup to bypass your `.babelrc` file. In order to use the `env` preset, you will also need to specify it with `modules: false` option: | ||
```js | ||
plugins: [ | ||
babel({ | ||
babelrc: false, | ||
presets: [['env', { modules: false }]] | ||
}) | ||
] | ||
``` | ||
### Helpers | ||
@@ -100,3 +109,3 @@ | ||
By default, those helpers will be inserted at the top of the file being transformed, which can lead to duplication. It's therefore recommended that you use the `external-helpers` plugin, which is automatically included in the `es2015-rollup` preset. Rollup will combine the helpers in a single block at the top of your bundle. | ||
By default, those helpers will be inserted at the top of the file being transformed, which can lead to duplication. It's therefore recommended that you use the `external-helpers` plugin. Rollup will combine the helpers in a single block at the top of your bundle. | ||
@@ -103,0 +112,0 @@ Alternatively, if you know what you're doing, you can use the `transform-runtime` plugin. If you do this, use `runtimeHelpers: true`: |
import { dirname } from 'path'; | ||
import { buildExternalHelpers, transform } from '@babel/core'; | ||
import { createFilter } from 'rollup-pluginutils'; | ||
import preflightCheck from './preflightCheck.js'; | ||
import createPreflightCheck from './preflightCheck.js'; | ||
import helperPlugin from './helperPlugin.js'; | ||
@@ -9,33 +9,31 @@ import { warnOnce } from './utils.js'; | ||
const unpackOptions = ({ | ||
// rollup uses sourcemap, babel uses sourceMaps | ||
// just normalize them here so people don't have to worry about it | ||
sourcemap = true, | ||
sourcemaps = true, | ||
sourceMap = true, | ||
sourceMaps = true, | ||
...rest | ||
} = {}) => ({ | ||
sourceMaps: sourcemap && sourcemaps && sourceMap && sourceMaps, | ||
...rest | ||
}); | ||
export default function babel ( options ) { | ||
options = Object.assign( {}, options || {} ); | ||
const { | ||
exclude, | ||
externalHelpers, | ||
externalHelpersWhitelist, | ||
include, | ||
runtimeHelpers, | ||
...babelOptions | ||
} = unpackOptions(options); | ||
const filter = createFilter( options.include, options.exclude ); | ||
delete options.include; | ||
delete options.exclude; | ||
const filter = createFilter( include, exclude ); | ||
const preflightCheck = createPreflightCheck(); | ||
if ( options.sourceMap !== false ) options.sourceMaps = true; | ||
if ( options.sourceMaps !== false ) options.sourceMaps = true; | ||
delete options.sourceMap; | ||
const runtimeHelpers = options.runtimeHelpers; | ||
delete options.runtimeHelpers; | ||
let externalHelpers; | ||
if ( options.externalHelpers ) externalHelpers = true; | ||
delete options.externalHelpers; | ||
let externalHelpersWhitelist = null; | ||
if ( options.externalHelpersWhitelist ) externalHelpersWhitelist = options.externalHelpersWhitelist; | ||
delete options.externalHelpersWhitelist; | ||
let warn = msg => console.warn(msg); // eslint-disable-line no-console | ||
return { | ||
name: 'babel', | ||
options ( options ) { | ||
warn = options.onwarn || warn; | ||
}, | ||
resolveId ( id ) { | ||
@@ -57,11 +55,11 @@ if ( id === HELPERS ) return id; | ||
const helpers = preflightCheck( options, dirname( id ) ); | ||
const helpers = preflightCheck( this, babelOptions, dirname( id ) ); | ||
if ( helpers === EXTERNAL && !externalHelpers ) { | ||
warnOnce( warn, 'Using "external-helpers" plugin with rollup-plugin-babel is deprecated, as it now automatically deduplicates your Babel helpers.' ); | ||
warnOnce( this, 'Using "external-helpers" plugin with rollup-plugin-babel is deprecated, as it now automatically deduplicates your Babel helpers.' ); | ||
} else if ( helpers === RUNTIME && !runtimeHelpers ) { | ||
throw new Error( 'Runtime helpers are not enabled. Either exclude the transform-runtime Babel plugin or pass the `runtimeHelpers: true` option. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information' ); | ||
this.error( 'Runtime helpers are not enabled. Either exclude the transform-runtime Babel plugin or pass the `runtimeHelpers: true` option. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information' ); | ||
} | ||
let localOpts = Object.assign({ filename: id }, options); | ||
let localOpts = Object.assign({ filename: id }, babelOptions); | ||
@@ -68,0 +66,0 @@ if ( helpers !== RUNTIME ) { |
@@ -5,2 +5,15 @@ import { join } from 'path'; | ||
const MODULE_ERROR = | ||
'Rollup requires that your Babel configuration keeps ES6 module syntax intact. ' + | ||
'Unfortunately it looks like your configuration specifies a module transformer ' + | ||
'to replace ES6 modules with another module format. To continue you have to disable it.' + | ||
'\n\n' + | ||
'Most commonly it\'s a CommonJS transform added by @babel/preset-env - ' + | ||
'in such case you should disable it by adding `modules: false` option to that preset ' + | ||
'(described in more detail here - https://github.com/rollup/rollup-plugin-babel#modules ).'; | ||
const UNEXPECTED_ERROR = | ||
'An unexpected situation arose. Please raise an issue at ' + | ||
'https://github.com/rollup/rollup-plugin-babel/issues. Thanks!'; | ||
function fallbackClassTransform () { | ||
@@ -16,39 +29,43 @@ return { | ||
let preflightCheckResults = {}; | ||
export default function createPreflightCheck () { | ||
let preflightCheckResults = {}; | ||
export default function preflightCheck ( options, dir ) { | ||
if ( !preflightCheckResults[ dir ] ) { | ||
let helpers; | ||
return ( ctx, options, dir ) => { | ||
if ( !preflightCheckResults[ dir ] ) { | ||
let helpers; | ||
options = Object.assign( {}, options ); | ||
delete options.only; | ||
delete options.ignore; | ||
options = Object.assign( {}, options ); | ||
delete options.only; | ||
delete options.ignore; | ||
options.filename = join( dir, 'x.js' ); | ||
options.filename = join( dir, 'x.js' ); | ||
const inputCode = 'class Foo extends Bar {};\nexport default Foo;'; | ||
let check = transform( inputCode, options ).code; | ||
const inputCode = 'class Foo extends Bar {};\nexport default Foo;'; | ||
let check = transform( inputCode, options ).code; | ||
if ( ~check.indexOf('class ') ) { | ||
options.plugins = (options.plugins || []).concat( fallbackClassTransform ); | ||
check = transform( inputCode, options ).code; | ||
} | ||
if ( ~check.indexOf('class ') ) { | ||
options.plugins = (options.plugins || []).concat( fallbackClassTransform ); | ||
check = transform( inputCode, options ).code; | ||
} | ||
if ( ~check.indexOf( 'import _inherits' ) ) helpers = RUNTIME; | ||
else if ( ~check.indexOf( 'function _inherits' ) ) helpers = INLINE; | ||
else if ( ~check.indexOf( 'babelHelpers' ) ) helpers = EXTERNAL; | ||
else { | ||
throw new Error( 'An unexpected situation arose. Please raise an issue at https://github.com/rollup/rollup-plugin-babel/issues. Thanks!' ); | ||
} | ||
if ( | ||
!~check.indexOf( 'export default' ) && | ||
!~check.indexOf( 'export default Foo' ) && | ||
!~check.indexOf( 'export { Foo as default }' ) | ||
) { | ||
ctx.error( MODULE_ERROR ); | ||
} | ||
if ( | ||
!~check.indexOf( 'export default' ) && | ||
!~check.indexOf( 'export default Foo' ) && | ||
!~check.indexOf( 'export { Foo as default }' ) | ||
) throw new Error( 'It looks like your Babel configuration specifies a module transformer. Please disable it. See https://github.com/rollup/rollup-plugin-babel#configuring-babel for more information' ); | ||
if ( ~check.indexOf( '/helpers/inherits' ) ) helpers = RUNTIME; | ||
else if ( ~check.indexOf( 'function _inherits' ) ) helpers = INLINE; | ||
else if ( ~check.indexOf( 'babelHelpers' ) ) helpers = EXTERNAL; | ||
else { | ||
ctx.error( UNEXPECTED_ERROR ); | ||
} | ||
preflightCheckResults[ dir ] = helpers; | ||
} | ||
preflightCheckResults[ dir ] = helpers; | ||
} | ||
return preflightCheckResults[ dir ]; | ||
return preflightCheckResults[ dir ]; | ||
}; | ||
} |
let warned = {}; | ||
export function warnOnce ( warn, msg ) { | ||
export function warnOnce ( ctx, msg ) { | ||
if ( warned[ msg ] ) return; | ||
warned[ msg ] = true; | ||
warn( msg ); | ||
ctx.warn( msg ); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28765
433
140
+ Added@babel/helper-module-imports@7.0.0-beta.51(transitive)
+ Added@babel/types@7.0.0-beta.51(transitive)
- Removed@babel/helper-module-imports@7.0.0-beta.49(transitive)
- Removed@babel/types@7.0.0-beta.49(transitive)
Updatedrollup-pluginutils@^2.3.0