@rollup/plugin-babel 6.1.0 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -1
- package/dist/cjs/index.js +157 -199
- package/dist/cjs/transformCode-47UZeDHQ.js +176 -0
- package/dist/cjs/worker.js +19 -0
- package/dist/es/index.js +154 -197
- package/dist/es/transformCode-yk-f524P.js +151 -0
- package/dist/es/worker.js +17 -0
- package/package.json +6 -13
- package/types/index.d.ts +18 -2
package/README.md
CHANGED
|
@@ -94,7 +94,7 @@ A [picomatch pattern](https://github.com/micromatch/picomatch), or array of patt
|
|
|
94
94
|
|
|
95
95
|
### `filter`
|
|
96
96
|
|
|
97
|
-
Type: (id: string) => boolean
|
|
97
|
+
Type: `(id: string, code: string) => Promise<boolean> | boolean`<br>
|
|
98
98
|
|
|
99
99
|
Custom [filter function](https://github.com/rollup/plugins/tree/master/packages/pluginutils#createfilter) can be used to determine whether or not certain modules should be operated upon.
|
|
100
100
|
|
|
@@ -135,6 +135,17 @@ Default: `false`
|
|
|
135
135
|
|
|
136
136
|
Before transpiling your input files this plugin also transpile a short piece of code **for each** input file. This is used to validate some misconfiguration errors, but for sufficiently big projects it can slow your build times so if you are confident about your configuration then you might disable those checks with this option.
|
|
137
137
|
|
|
138
|
+
### `parallel`
|
|
139
|
+
|
|
140
|
+
Type: `Boolean | number`<br>
|
|
141
|
+
Default: `false`
|
|
142
|
+
|
|
143
|
+
Enable parallel processing of files in worker threads. This has a setup cost, so is best suited for larger projects. Pass an integer to set the number of workers. Set `true` for the default number of workers (based on CPU cores, capped at 4).
|
|
144
|
+
|
|
145
|
+
This option is available for both the input plugin (`babel()`) and the output plugin (`getBabelOutputPlugin()`).
|
|
146
|
+
|
|
147
|
+
This option cannot be used alongside custom overrides or non-serializable Babel options.
|
|
148
|
+
|
|
138
149
|
### External dependencies
|
|
139
150
|
|
|
140
151
|
Ideally, you should only be transforming your source code, rather than running all of your external dependencies through Babel (to ignore external dependencies from being handled by this plugin you might use `exclude: 'node_modules/**'` option). If you have a dependency that exposes untranspiled ES6 source code that doesn't run in your target environment, then you may need to break this rule, but it often causes problems with unusual `.babelrc` files or mismatched versions of Babel.
|
package/dist/cjs/index.js
CHANGED
|
@@ -2,10 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
var os = require('os');
|
|
6
|
+
var url = require('url');
|
|
5
7
|
var babel = require('@babel/core');
|
|
6
8
|
var pluginutils = require('@rollup/pluginutils');
|
|
7
|
-
var
|
|
9
|
+
var workerpool = require('workerpool');
|
|
10
|
+
var transformCode = require('./transformCode-47UZeDHQ.js');
|
|
11
|
+
require('@babel/helper-module-imports');
|
|
8
12
|
|
|
13
|
+
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
9
14
|
function _interopNamespaceDefault(e) {
|
|
10
15
|
var n = Object.create(null);
|
|
11
16
|
if (e) {
|
|
@@ -25,153 +30,6 @@ function _interopNamespaceDefault(e) {
|
|
|
25
30
|
|
|
26
31
|
var babel__namespace = /*#__PURE__*/_interopNamespaceDefault(babel);
|
|
27
32
|
|
|
28
|
-
const BUNDLED = 'bundled';
|
|
29
|
-
const INLINE = 'inline';
|
|
30
|
-
const RUNTIME = 'runtime';
|
|
31
|
-
const EXTERNAL = 'external';
|
|
32
|
-
|
|
33
|
-
// NOTE: DO NOT REMOVE the null character `\0` as it may be used by other plugins
|
|
34
|
-
// e.g. https://github.com/rollup/rollup-plugin-node-resolve/blob/313a3e32f432f9eb18cc4c231cc7aac6df317a51/src/index.js#L74
|
|
35
|
-
const HELPERS = '\0rollupPluginBabelHelpers.js';
|
|
36
|
-
|
|
37
|
-
function importHelperPlugin({
|
|
38
|
-
types: t
|
|
39
|
-
}) {
|
|
40
|
-
return {
|
|
41
|
-
pre(file) {
|
|
42
|
-
const cachedHelpers = {};
|
|
43
|
-
file.set('helperGenerator', name => {
|
|
44
|
-
if (!file.availableHelper(name)) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
if (cachedHelpers[name]) {
|
|
48
|
-
return t.cloneNode(cachedHelpers[name]);
|
|
49
|
-
}
|
|
50
|
-
return cachedHelpers[name] = helperModuleImports.addNamed(file.path, name, HELPERS);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const addBabelPlugin = (options, plugin) => {
|
|
57
|
-
return {
|
|
58
|
-
...options,
|
|
59
|
-
plugins: options.plugins.concat(plugin)
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
const warned = {};
|
|
63
|
-
function warnOnce(ctx, msg) {
|
|
64
|
-
if (warned[msg]) return;
|
|
65
|
-
warned[msg] = true;
|
|
66
|
-
ctx.warn(msg);
|
|
67
|
-
}
|
|
68
|
-
const regExpCharactersRegExp = /[\\^$.*+?()[\]{}|]/g;
|
|
69
|
-
const escapeRegExpCharacters = str => str.replace(regExpCharactersRegExp, '\\$&');
|
|
70
|
-
function stripQuery(id) {
|
|
71
|
-
// strip query params from import
|
|
72
|
-
const [bareId, query] = id.split('?');
|
|
73
|
-
const suffix = `${query ? `?${query}` : ''}`;
|
|
74
|
-
return {
|
|
75
|
-
bareId,
|
|
76
|
-
query,
|
|
77
|
-
suffix
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
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/plugins/tree/master/packages/babel#modules ).';
|
|
82
|
-
const UNEXPECTED_ERROR = 'An unexpected situation arose. Please raise an issue at ' + 'https://github.com/rollup/plugins/issues. Thanks!';
|
|
83
|
-
const PREFLIGHT_TEST_STRING = '__ROLLUP__PREFLIGHT_CHECK_DO_NOT_TOUCH__';
|
|
84
|
-
const PREFLIGHT_INPUT = `export default "${PREFLIGHT_TEST_STRING}";`;
|
|
85
|
-
function helpersTestTransform() {
|
|
86
|
-
return {
|
|
87
|
-
visitor: {
|
|
88
|
-
StringLiteral(path, state) {
|
|
89
|
-
if (path.node.value === PREFLIGHT_TEST_STRING) {
|
|
90
|
-
path.replaceWith(state.file.addHelper('inherits'));
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
const mismatchError = (actual, expected, filename) => `You have declared using "${expected}" babelHelpers, but transforming ${filename} resulted in "${actual}". Please check your configuration.`;
|
|
97
|
-
|
|
98
|
-
// Revert to /\/helpers\/(esm\/)?inherits/ when Babel 8 gets released, this was fixed in https://github.com/babel/babel/issues/14185
|
|
99
|
-
const inheritsHelperRe = /[\\/]+helpers[\\/]+(esm[\\/]+)?inherits/;
|
|
100
|
-
async function preflightCheck(ctx, babelHelpers, transformOptions) {
|
|
101
|
-
const finalOptions = addBabelPlugin(transformOptions, helpersTestTransform);
|
|
102
|
-
const check = (await babel__namespace.transformAsync(PREFLIGHT_INPUT, finalOptions)).code;
|
|
103
|
-
|
|
104
|
-
// Babel sometimes splits ExportDefaultDeclaration into 2 statements, so we also check for ExportNamedDeclaration
|
|
105
|
-
if (!/export (d|{)/.test(check)) {
|
|
106
|
-
ctx.error(MODULE_ERROR);
|
|
107
|
-
}
|
|
108
|
-
if (inheritsHelperRe.test(check)) {
|
|
109
|
-
if (babelHelpers === RUNTIME) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
ctx.error(mismatchError(RUNTIME, babelHelpers, transformOptions.filename));
|
|
113
|
-
}
|
|
114
|
-
if (check.includes('babelHelpers.inherits')) {
|
|
115
|
-
if (babelHelpers === EXTERNAL) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
ctx.error(mismatchError(EXTERNAL, babelHelpers, transformOptions.filename));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// test unminifiable string content
|
|
122
|
-
if (check.includes('Super expression must either be null or a function')) {
|
|
123
|
-
if (babelHelpers === INLINE || babelHelpers === BUNDLED) {
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
|
-
if (babelHelpers === RUNTIME && !transformOptions.plugins.length) {
|
|
127
|
-
ctx.error(`You must use the \`@babel/plugin-transform-runtime\` plugin when \`babelHelpers\` is "${RUNTIME}".\n`);
|
|
128
|
-
}
|
|
129
|
-
ctx.error(mismatchError(INLINE, babelHelpers, transformOptions.filename));
|
|
130
|
-
}
|
|
131
|
-
ctx.error(UNEXPECTED_ERROR);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
async function transformCode(inputCode, babelOptions, overrides, customOptions, ctx, finalizeOptions) {
|
|
135
|
-
// loadPartialConfigAsync has become available in @babel/core@7.8.0
|
|
136
|
-
const config = await (babel__namespace.loadPartialConfigAsync || babel__namespace.loadPartialConfig)(babelOptions);
|
|
137
|
-
|
|
138
|
-
// file is ignored by babel
|
|
139
|
-
if (!config) {
|
|
140
|
-
return null;
|
|
141
|
-
}
|
|
142
|
-
let transformOptions = !overrides.config ? config.options : await overrides.config.call(ctx, config, {
|
|
143
|
-
code: inputCode,
|
|
144
|
-
customOptions
|
|
145
|
-
});
|
|
146
|
-
if (finalizeOptions) {
|
|
147
|
-
transformOptions = await finalizeOptions(transformOptions);
|
|
148
|
-
}
|
|
149
|
-
if (!overrides.result) {
|
|
150
|
-
const {
|
|
151
|
-
code,
|
|
152
|
-
map
|
|
153
|
-
} = await babel__namespace.transformAsync(inputCode, transformOptions);
|
|
154
|
-
return {
|
|
155
|
-
code,
|
|
156
|
-
map
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
const result = await babel__namespace.transformAsync(inputCode, transformOptions);
|
|
160
|
-
const {
|
|
161
|
-
code,
|
|
162
|
-
map
|
|
163
|
-
} = await overrides.result.call(ctx, result, {
|
|
164
|
-
code: inputCode,
|
|
165
|
-
customOptions,
|
|
166
|
-
config,
|
|
167
|
-
transformOptions
|
|
168
|
-
});
|
|
169
|
-
return {
|
|
170
|
-
code,
|
|
171
|
-
map
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
33
|
const unpackOptions = ({
|
|
176
34
|
extensions = babel__namespace.DEFAULT_EXTENSIONS,
|
|
177
35
|
// rollup uses sourcemap, babel uses sourceMaps
|
|
@@ -203,7 +61,7 @@ const warnAboutDeprecatedHelpersOption = ({
|
|
|
203
61
|
const unpackInputPluginOptions = ({
|
|
204
62
|
skipPreflightCheck = false,
|
|
205
63
|
...rest
|
|
206
|
-
}
|
|
64
|
+
}) => {
|
|
207
65
|
if ('runtimeHelpers' in rest) {
|
|
208
66
|
warnAboutDeprecatedHelpersOption({
|
|
209
67
|
deprecatedOption: 'runtimeHelpers',
|
|
@@ -221,13 +79,12 @@ const unpackInputPluginOptions = ({
|
|
|
221
79
|
return unpackOptions({
|
|
222
80
|
...rest,
|
|
223
81
|
skipPreflightCheck,
|
|
224
|
-
babelHelpers: rest.babelHelpers || BUNDLED,
|
|
82
|
+
babelHelpers: rest.babelHelpers || transformCode.BUNDLED,
|
|
225
83
|
caller: {
|
|
226
84
|
supportsStaticESM: true,
|
|
227
85
|
supportsDynamicImport: true,
|
|
228
86
|
supportsTopLevelAwait: true,
|
|
229
|
-
|
|
230
|
-
supportsExportNamespaceFrom: !rollupVersion.match(/^1\.2[0-5]\./),
|
|
87
|
+
supportsExportNamespaceFrom: true,
|
|
231
88
|
...rest.caller
|
|
232
89
|
}
|
|
233
90
|
});
|
|
@@ -260,6 +117,54 @@ function getOptionsWithOverrides(pluginOptions = {}, overrides = {}) {
|
|
|
260
117
|
const returnObject = () => {
|
|
261
118
|
return {};
|
|
262
119
|
};
|
|
120
|
+
function findNonSerializableOption(obj) {
|
|
121
|
+
const isSerializable = value => {
|
|
122
|
+
if (value === null) return true;
|
|
123
|
+
if (Array.isArray(value)) return value.every(isSerializable);
|
|
124
|
+
switch (typeof value) {
|
|
125
|
+
case 'undefined':
|
|
126
|
+
case 'string':
|
|
127
|
+
case 'number':
|
|
128
|
+
case 'boolean':
|
|
129
|
+
return true;
|
|
130
|
+
case 'object':
|
|
131
|
+
return Object.values(value).every(isSerializable);
|
|
132
|
+
default:
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
for (const key of Object.keys(obj)) {
|
|
137
|
+
if (!isSerializable(obj[key])) return key;
|
|
138
|
+
}
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
const WORKER_PATH = url.fileURLToPath(new URL('./worker.js', (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('index.js', document.baseURI).href))));
|
|
142
|
+
function createParallelWorkerPool(parallel, overrides) {
|
|
143
|
+
if (typeof parallel === 'number' && (!Number.isInteger(parallel) || parallel < 1)) {
|
|
144
|
+
throw new Error('The "parallel" option must be true or a positive integer specifying the number of workers.');
|
|
145
|
+
}
|
|
146
|
+
if (!parallel) return null;
|
|
147
|
+
if (overrides !== null && overrides !== void 0 && overrides.config) {
|
|
148
|
+
throw new Error('Cannot use "parallel" mode with a custom "config" override.');
|
|
149
|
+
}
|
|
150
|
+
if (overrides !== null && overrides !== void 0 && overrides.result) {
|
|
151
|
+
throw new Error('Cannot use "parallel" mode with a custom "result" override.');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Default limits to 4 workers. Benefits diminish after this point, because of the setup cost.
|
|
155
|
+
const workerCount = typeof parallel === 'number' ? parallel : Math.min(os.cpus().length, 4);
|
|
156
|
+
return workerpool.pool(WORKER_PATH, {
|
|
157
|
+
maxWorkers: workerCount,
|
|
158
|
+
workerType: 'thread'
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
function transformWithWorkerPool(workerPool, context, transformOpts, babelOptions) {
|
|
162
|
+
const nonSerializableKey = findNonSerializableOption(babelOptions);
|
|
163
|
+
if (nonSerializableKey) {
|
|
164
|
+
return Promise.reject(new Error(`Cannot use "parallel" mode because the "${nonSerializableKey}" option is not serializable.`));
|
|
165
|
+
}
|
|
166
|
+
return workerPool.exec('transform', [transformOpts]).catch(err => context.error(err.message));
|
|
167
|
+
}
|
|
263
168
|
function createBabelInputPluginFactory(customCallback = returnObject) {
|
|
264
169
|
const overrides = customCallback(babel__namespace);
|
|
265
170
|
return pluginOptions => {
|
|
@@ -267,59 +172,87 @@ function createBabelInputPluginFactory(customCallback = returnObject) {
|
|
|
267
172
|
customOptions,
|
|
268
173
|
pluginOptionsWithOverrides
|
|
269
174
|
} = getOptionsWithOverrides(pluginOptions, overrides);
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
175
|
+
const {
|
|
176
|
+
exclude,
|
|
177
|
+
extensions,
|
|
178
|
+
babelHelpers,
|
|
179
|
+
include,
|
|
180
|
+
filter: customFilter,
|
|
181
|
+
skipPreflightCheck,
|
|
182
|
+
parallel,
|
|
183
|
+
...babelOptions
|
|
184
|
+
} = unpackInputPluginOptions(pluginOptionsWithOverrides);
|
|
185
|
+
const workerPool = createParallelWorkerPool(parallel, overrides);
|
|
186
|
+
const extensionRegExp = new RegExp(`(${extensions.map(transformCode.escapeRegExpCharacters).join('|')})(\\?.*)?(#.*)?$`);
|
|
187
|
+
if (customFilter && (include || exclude)) {
|
|
188
|
+
throw new Error('Could not handle include or exclude with custom filter together');
|
|
189
|
+
}
|
|
190
|
+
const userDefinedFilter = typeof customFilter === 'function' ? customFilter : pluginutils.createFilter(include, exclude);
|
|
191
|
+
const filter = (id, code) => extensionRegExp.test(id) && userDefinedFilter(id, code);
|
|
192
|
+
const helpersFilter = {
|
|
193
|
+
id: new RegExp(`^${transformCode.escapeRegExpCharacters(transformCode.HELPERS)}$`)
|
|
194
|
+
};
|
|
274
195
|
return {
|
|
275
196
|
name: 'babel',
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
if (customFilter && (include || exclude)) {
|
|
293
|
-
throw new Error('Could not handle include or exclude with custom filter together');
|
|
197
|
+
resolveId: {
|
|
198
|
+
filter: helpersFilter,
|
|
199
|
+
handler(id) {
|
|
200
|
+
if (id !== transformCode.HELPERS) {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
return id;
|
|
204
|
+
}
|
|
205
|
+
},
|
|
206
|
+
load: {
|
|
207
|
+
filter: helpersFilter,
|
|
208
|
+
handler(id) {
|
|
209
|
+
if (id !== transformCode.HELPERS) {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
return babel__namespace.buildExternalHelpers(null, 'module');
|
|
294
213
|
}
|
|
295
|
-
const userDefinedFilter = typeof customFilter === 'function' ? customFilter : pluginutils.createFilter(include, exclude);
|
|
296
|
-
filter = id => extensionRegExp.test(stripQuery(id).bareId) && userDefinedFilter(id);
|
|
297
|
-
return null;
|
|
298
214
|
},
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
215
|
+
transform: {
|
|
216
|
+
filter: {
|
|
217
|
+
id: extensionRegExp
|
|
218
|
+
},
|
|
219
|
+
async handler(code, filename) {
|
|
220
|
+
var _overrides$config, _overrides$result;
|
|
221
|
+
if (!(await filter(filename, code))) return null;
|
|
222
|
+
if (filename === transformCode.HELPERS) return null;
|
|
223
|
+
const resolvedBabelOptions = {
|
|
224
|
+
...babelOptions,
|
|
225
|
+
filename
|
|
226
|
+
};
|
|
227
|
+
if (workerPool) {
|
|
228
|
+
return transformWithWorkerPool(workerPool, this, {
|
|
229
|
+
inputCode: code,
|
|
230
|
+
babelOptions: resolvedBabelOptions,
|
|
231
|
+
skipPreflightCheck,
|
|
232
|
+
babelHelpers
|
|
233
|
+
}, resolvedBabelOptions);
|
|
234
|
+
}
|
|
235
|
+
return transformCode.transformCode({
|
|
236
|
+
inputCode: code,
|
|
237
|
+
babelOptions: resolvedBabelOptions,
|
|
238
|
+
overrides: {
|
|
239
|
+
config: (_overrides$config = overrides.config) === null || _overrides$config === void 0 ? void 0 : _overrides$config.bind(this),
|
|
240
|
+
result: (_overrides$result = overrides.result) === null || _overrides$result === void 0 ? void 0 : _overrides$result.bind(this)
|
|
241
|
+
},
|
|
242
|
+
customOptions,
|
|
243
|
+
error: this.error.bind(this),
|
|
244
|
+
skipPreflightCheck,
|
|
245
|
+
babelHelpers
|
|
246
|
+
});
|
|
302
247
|
}
|
|
303
|
-
return id;
|
|
304
248
|
},
|
|
305
|
-
|
|
306
|
-
if (
|
|
307
|
-
|
|
249
|
+
async closeBundle() {
|
|
250
|
+
if (!this.meta.watchMode) {
|
|
251
|
+
await (workerPool === null || workerPool === void 0 ? void 0 : workerPool.terminate());
|
|
308
252
|
}
|
|
309
|
-
return babel__namespace.buildExternalHelpers(null, 'module');
|
|
310
253
|
},
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
if (filename === HELPERS) return null;
|
|
314
|
-
return transformCode(code, {
|
|
315
|
-
...babelOptions,
|
|
316
|
-
filename
|
|
317
|
-
}, overrides, customOptions, this, async transformOptions => {
|
|
318
|
-
if (!skipPreflightCheck) {
|
|
319
|
-
await preflightCheck(this, babelHelpers, transformOptions);
|
|
320
|
-
}
|
|
321
|
-
return babelHelpers === BUNDLED ? addBabelPlugin(transformOptions, importHelperPlugin) : transformOptions;
|
|
322
|
-
});
|
|
254
|
+
async closeWatcher() {
|
|
255
|
+
await (workerPool === null || workerPool === void 0 ? void 0 : workerPool.terminate());
|
|
323
256
|
}
|
|
324
257
|
};
|
|
325
258
|
};
|
|
@@ -344,6 +277,7 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
|
|
|
344
277
|
customOptions,
|
|
345
278
|
pluginOptionsWithOverrides
|
|
346
279
|
} = getOptionsWithOverrides(pluginOptions, overrides);
|
|
280
|
+
const workerPool = createParallelWorkerPool(pluginOptionsWithOverrides.parallel, overrides);
|
|
347
281
|
|
|
348
282
|
// cache for chunk name filter (includeChunks/excludeChunks)
|
|
349
283
|
let chunkNameFilter;
|
|
@@ -357,13 +291,14 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
|
|
|
357
291
|
allowAllFormats
|
|
358
292
|
} = pluginOptionsWithOverrides;
|
|
359
293
|
if (extensions || include || exclude) {
|
|
360
|
-
warnOnce(this, 'The "include", "exclude" and "extensions" options are ignored when transforming the output.');
|
|
294
|
+
transformCode.warnOnce(this, 'The "include", "exclude" and "extensions" options are ignored when transforming the output.');
|
|
361
295
|
}
|
|
362
296
|
if (!allowAllFormats && outputOptions.format !== 'es' && outputOptions.format !== 'cjs') {
|
|
363
297
|
this.error(`Using Babel on the generated chunks is strongly discouraged for formats other than "esm" or "cjs" as it can easily break wrapper code and lead to accidentally created global variables. Instead, you should set "output.format" to "esm" and use Babel to transform to another format, e.g. by adding "presets: [['@babel/env', { modules: '${getRecommendedFormat(outputOptions.format)}' }]]" to your Babel options. If you still want to proceed, add "allowAllFormats: true" to your plugin options.`);
|
|
364
298
|
}
|
|
365
299
|
},
|
|
366
300
|
renderChunk(code, chunk, outputOptions) {
|
|
301
|
+
var _overrides$config2, _overrides$result2;
|
|
367
302
|
/* eslint-disable no-unused-vars */
|
|
368
303
|
const {
|
|
369
304
|
allowAllFormats,
|
|
@@ -374,6 +309,7 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
|
|
|
374
309
|
externalHelpers,
|
|
375
310
|
externalHelpersWhitelist,
|
|
376
311
|
include,
|
|
312
|
+
parallel,
|
|
377
313
|
runtimeHelpers,
|
|
378
314
|
...babelOptions
|
|
379
315
|
} = unpackOutputPluginOptions(pluginOptionsWithOverrides, outputOptions);
|
|
@@ -390,7 +326,29 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
|
|
|
390
326
|
return null;
|
|
391
327
|
}
|
|
392
328
|
}
|
|
393
|
-
|
|
329
|
+
if (workerPool) {
|
|
330
|
+
return transformWithWorkerPool(workerPool, this, {
|
|
331
|
+
inputCode: code,
|
|
332
|
+
babelOptions,
|
|
333
|
+
skipPreflightCheck: true
|
|
334
|
+
}, babelOptions);
|
|
335
|
+
}
|
|
336
|
+
return transformCode.transformCode({
|
|
337
|
+
inputCode: code,
|
|
338
|
+
babelOptions,
|
|
339
|
+
overrides: {
|
|
340
|
+
config: (_overrides$config2 = overrides.config) === null || _overrides$config2 === void 0 ? void 0 : _overrides$config2.bind(this),
|
|
341
|
+
result: (_overrides$result2 = overrides.result) === null || _overrides$result2 === void 0 ? void 0 : _overrides$result2.bind(this)
|
|
342
|
+
},
|
|
343
|
+
customOptions,
|
|
344
|
+
error: this.error.bind(this),
|
|
345
|
+
skipPreflightCheck: true
|
|
346
|
+
});
|
|
347
|
+
},
|
|
348
|
+
async generateBundle() {
|
|
349
|
+
if (!this.meta.watchMode) {
|
|
350
|
+
await (workerPool === null || workerPool === void 0 ? void 0 : workerPool.terminate());
|
|
351
|
+
}
|
|
394
352
|
}
|
|
395
353
|
};
|
|
396
354
|
};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var babel = require('@babel/core');
|
|
4
|
+
var helperModuleImports = require('@babel/helper-module-imports');
|
|
5
|
+
|
|
6
|
+
function _interopNamespaceDefault(e) {
|
|
7
|
+
var n = Object.create(null);
|
|
8
|
+
if (e) {
|
|
9
|
+
Object.keys(e).forEach(function (k) {
|
|
10
|
+
if (k !== 'default') {
|
|
11
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
12
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return e[k]; }
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
n.default = e;
|
|
20
|
+
return Object.freeze(n);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var babel__namespace = /*#__PURE__*/_interopNamespaceDefault(babel);
|
|
24
|
+
|
|
25
|
+
const BUNDLED = 'bundled';
|
|
26
|
+
const INLINE = 'inline';
|
|
27
|
+
const RUNTIME = 'runtime';
|
|
28
|
+
const EXTERNAL = 'external';
|
|
29
|
+
|
|
30
|
+
// NOTE: DO NOT REMOVE the null character `\0` as it may be used by other plugins
|
|
31
|
+
// e.g. https://github.com/rollup/rollup-plugin-node-resolve/blob/313a3e32f432f9eb18cc4c231cc7aac6df317a51/src/index.js#L74
|
|
32
|
+
const HELPERS = '\0rollupPluginBabelHelpers.js';
|
|
33
|
+
|
|
34
|
+
function importHelperPlugin({
|
|
35
|
+
types: t
|
|
36
|
+
}) {
|
|
37
|
+
return {
|
|
38
|
+
pre(file) {
|
|
39
|
+
const cachedHelpers = {};
|
|
40
|
+
file.set('helperGenerator', name => {
|
|
41
|
+
if (!file.availableHelper(name)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
if (cachedHelpers[name]) {
|
|
45
|
+
return t.cloneNode(cachedHelpers[name]);
|
|
46
|
+
}
|
|
47
|
+
return cachedHelpers[name] = helperModuleImports.addNamed(file.path, name, HELPERS);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const addBabelPlugin = (options, plugin) => {
|
|
54
|
+
return {
|
|
55
|
+
...options,
|
|
56
|
+
plugins: options.plugins.concat(plugin)
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
const warned = {};
|
|
60
|
+
function warnOnce(ctx, msg) {
|
|
61
|
+
if (warned[msg]) return;
|
|
62
|
+
warned[msg] = true;
|
|
63
|
+
ctx.warn(msg);
|
|
64
|
+
}
|
|
65
|
+
const regExpCharactersRegExp = /[\\^$.*+?()[\]{}|]/g;
|
|
66
|
+
const escapeRegExpCharacters = str => str.replace(regExpCharactersRegExp, '\\$&');
|
|
67
|
+
|
|
68
|
+
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/plugins/tree/master/packages/babel#modules ).';
|
|
69
|
+
const UNEXPECTED_ERROR = 'An unexpected situation arose. Please raise an issue at ' + 'https://github.com/rollup/plugins/issues. Thanks!';
|
|
70
|
+
const PREFLIGHT_TEST_STRING = '__ROLLUP__PREFLIGHT_CHECK_DO_NOT_TOUCH__';
|
|
71
|
+
const PREFLIGHT_INPUT = `export default "${PREFLIGHT_TEST_STRING}";`;
|
|
72
|
+
function helpersTestTransform() {
|
|
73
|
+
return {
|
|
74
|
+
visitor: {
|
|
75
|
+
StringLiteral(path, state) {
|
|
76
|
+
if (path.node.value === PREFLIGHT_TEST_STRING) {
|
|
77
|
+
path.replaceWith(state.file.addHelper('inherits'));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
const mismatchError = (actual, expected, filename) => `You have declared using "${expected}" babelHelpers, but transforming ${filename} resulted in "${actual}". Please check your configuration.`;
|
|
84
|
+
|
|
85
|
+
// Revert to /\/helpers\/(esm\/)?inherits/ when Babel 8 gets released, this was fixed in https://github.com/babel/babel/issues/14185
|
|
86
|
+
const inheritsHelperRe = /[\\/]+helpers[\\/]+(esm[\\/]+)?inherits/;
|
|
87
|
+
async function preflightCheck(error, babelHelpers, transformOptions) {
|
|
88
|
+
const finalOptions = addBabelPlugin(transformOptions, helpersTestTransform);
|
|
89
|
+
const check = (await babel__namespace.transformAsync(PREFLIGHT_INPUT, finalOptions)).code;
|
|
90
|
+
|
|
91
|
+
// Babel sometimes splits ExportDefaultDeclaration into 2 statements, so we also check for ExportNamedDeclaration
|
|
92
|
+
if (!/export (d|{)/.test(check)) {
|
|
93
|
+
error(MODULE_ERROR);
|
|
94
|
+
}
|
|
95
|
+
if (inheritsHelperRe.test(check)) {
|
|
96
|
+
if (babelHelpers === RUNTIME) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
error(mismatchError(RUNTIME, babelHelpers, transformOptions.filename));
|
|
100
|
+
}
|
|
101
|
+
if (check.includes('babelHelpers.inherits')) {
|
|
102
|
+
if (babelHelpers === EXTERNAL) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
error(mismatchError(EXTERNAL, babelHelpers, transformOptions.filename));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// test unminifiable string content
|
|
109
|
+
if (check.includes('Super expression must either be null or a function')) {
|
|
110
|
+
if (babelHelpers === INLINE || babelHelpers === BUNDLED) {
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
if (babelHelpers === RUNTIME && !transformOptions.plugins.length) {
|
|
114
|
+
error(`You must use the \`@babel/plugin-transform-runtime\` plugin when \`babelHelpers\` is "${RUNTIME}".\n`);
|
|
115
|
+
}
|
|
116
|
+
error(mismatchError(INLINE, babelHelpers, transformOptions.filename));
|
|
117
|
+
}
|
|
118
|
+
error(UNEXPECTED_ERROR);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function transformCode({
|
|
122
|
+
inputCode,
|
|
123
|
+
babelOptions,
|
|
124
|
+
overrides,
|
|
125
|
+
customOptions,
|
|
126
|
+
error,
|
|
127
|
+
skipPreflightCheck,
|
|
128
|
+
babelHelpers
|
|
129
|
+
}) {
|
|
130
|
+
// loadPartialConfigAsync has become available in @babel/core@7.8.0
|
|
131
|
+
const config = await (babel__namespace.loadPartialConfigAsync || babel__namespace.loadPartialConfig)(babelOptions);
|
|
132
|
+
|
|
133
|
+
// file is ignored by babel
|
|
134
|
+
if (!config) {
|
|
135
|
+
return null;
|
|
136
|
+
}
|
|
137
|
+
let transformOptions = !(overrides !== null && overrides !== void 0 && overrides.config) ? config.options : await overrides.config(config, {
|
|
138
|
+
code: inputCode,
|
|
139
|
+
customOptions
|
|
140
|
+
});
|
|
141
|
+
if (!skipPreflightCheck) {
|
|
142
|
+
await preflightCheck(error, babelHelpers, transformOptions);
|
|
143
|
+
}
|
|
144
|
+
transformOptions = babelHelpers === BUNDLED ? addBabelPlugin(transformOptions, importHelperPlugin) : transformOptions;
|
|
145
|
+
if (!(overrides !== null && overrides !== void 0 && overrides.result)) {
|
|
146
|
+
const {
|
|
147
|
+
code,
|
|
148
|
+
map
|
|
149
|
+
} = await babel__namespace.transformAsync(inputCode, transformOptions);
|
|
150
|
+
return {
|
|
151
|
+
code,
|
|
152
|
+
map
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
const result = await babel__namespace.transformAsync(inputCode, transformOptions);
|
|
156
|
+
const {
|
|
157
|
+
code,
|
|
158
|
+
map
|
|
159
|
+
} = await overrides.result(result, {
|
|
160
|
+
code: inputCode,
|
|
161
|
+
customOptions,
|
|
162
|
+
config,
|
|
163
|
+
transformOptions
|
|
164
|
+
});
|
|
165
|
+
return {
|
|
166
|
+
code,
|
|
167
|
+
map
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
exports.BUNDLED = BUNDLED;
|
|
172
|
+
exports.HELPERS = HELPERS;
|
|
173
|
+
exports.escapeRegExpCharacters = escapeRegExpCharacters;
|
|
174
|
+
exports.transformCode = transformCode;
|
|
175
|
+
exports.warnOnce = warnOnce;
|
|
176
|
+
//# sourceMappingURL=transformCode-47UZeDHQ.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var workerpool = require('workerpool');
|
|
4
|
+
var transformCode = require('./transformCode-47UZeDHQ.js');
|
|
5
|
+
require('@babel/core');
|
|
6
|
+
require('@babel/helper-module-imports');
|
|
7
|
+
|
|
8
|
+
async function transform(opts) {
|
|
9
|
+
return transformCode.transformCode({
|
|
10
|
+
...opts,
|
|
11
|
+
error: msg => {
|
|
12
|
+
throw new Error(msg);
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
workerpool.worker({
|
|
17
|
+
transform
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=worker.js.map
|
package/dist/es/index.js
CHANGED
|
@@ -1,153 +1,10 @@
|
|
|
1
|
+
import { cpus } from 'os';
|
|
2
|
+
import { fileURLToPath } from 'url';
|
|
1
3
|
import * as babel from '@babel/core';
|
|
2
4
|
import { createFilter } from '@rollup/pluginutils';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const INLINE = 'inline';
|
|
7
|
-
const RUNTIME = 'runtime';
|
|
8
|
-
const EXTERNAL = 'external';
|
|
9
|
-
|
|
10
|
-
// NOTE: DO NOT REMOVE the null character `\0` as it may be used by other plugins
|
|
11
|
-
// e.g. https://github.com/rollup/rollup-plugin-node-resolve/blob/313a3e32f432f9eb18cc4c231cc7aac6df317a51/src/index.js#L74
|
|
12
|
-
const HELPERS = '\0rollupPluginBabelHelpers.js';
|
|
13
|
-
|
|
14
|
-
function importHelperPlugin({
|
|
15
|
-
types: t
|
|
16
|
-
}) {
|
|
17
|
-
return {
|
|
18
|
-
pre(file) {
|
|
19
|
-
const cachedHelpers = {};
|
|
20
|
-
file.set('helperGenerator', name => {
|
|
21
|
-
if (!file.availableHelper(name)) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
if (cachedHelpers[name]) {
|
|
25
|
-
return t.cloneNode(cachedHelpers[name]);
|
|
26
|
-
}
|
|
27
|
-
return cachedHelpers[name] = addNamed(file.path, name, HELPERS);
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const addBabelPlugin = (options, plugin) => {
|
|
34
|
-
return {
|
|
35
|
-
...options,
|
|
36
|
-
plugins: options.plugins.concat(plugin)
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
const warned = {};
|
|
40
|
-
function warnOnce(ctx, msg) {
|
|
41
|
-
if (warned[msg]) return;
|
|
42
|
-
warned[msg] = true;
|
|
43
|
-
ctx.warn(msg);
|
|
44
|
-
}
|
|
45
|
-
const regExpCharactersRegExp = /[\\^$.*+?()[\]{}|]/g;
|
|
46
|
-
const escapeRegExpCharacters = str => str.replace(regExpCharactersRegExp, '\\$&');
|
|
47
|
-
function stripQuery(id) {
|
|
48
|
-
// strip query params from import
|
|
49
|
-
const [bareId, query] = id.split('?');
|
|
50
|
-
const suffix = `${query ? `?${query}` : ''}`;
|
|
51
|
-
return {
|
|
52
|
-
bareId,
|
|
53
|
-
query,
|
|
54
|
-
suffix
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
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/plugins/tree/master/packages/babel#modules ).';
|
|
59
|
-
const UNEXPECTED_ERROR = 'An unexpected situation arose. Please raise an issue at ' + 'https://github.com/rollup/plugins/issues. Thanks!';
|
|
60
|
-
const PREFLIGHT_TEST_STRING = '__ROLLUP__PREFLIGHT_CHECK_DO_NOT_TOUCH__';
|
|
61
|
-
const PREFLIGHT_INPUT = `export default "${PREFLIGHT_TEST_STRING}";`;
|
|
62
|
-
function helpersTestTransform() {
|
|
63
|
-
return {
|
|
64
|
-
visitor: {
|
|
65
|
-
StringLiteral(path, state) {
|
|
66
|
-
if (path.node.value === PREFLIGHT_TEST_STRING) {
|
|
67
|
-
path.replaceWith(state.file.addHelper('inherits'));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
const mismatchError = (actual, expected, filename) => `You have declared using "${expected}" babelHelpers, but transforming ${filename} resulted in "${actual}". Please check your configuration.`;
|
|
74
|
-
|
|
75
|
-
// Revert to /\/helpers\/(esm\/)?inherits/ when Babel 8 gets released, this was fixed in https://github.com/babel/babel/issues/14185
|
|
76
|
-
const inheritsHelperRe = /[\\/]+helpers[\\/]+(esm[\\/]+)?inherits/;
|
|
77
|
-
async function preflightCheck(ctx, babelHelpers, transformOptions) {
|
|
78
|
-
const finalOptions = addBabelPlugin(transformOptions, helpersTestTransform);
|
|
79
|
-
const check = (await babel.transformAsync(PREFLIGHT_INPUT, finalOptions)).code;
|
|
80
|
-
|
|
81
|
-
// Babel sometimes splits ExportDefaultDeclaration into 2 statements, so we also check for ExportNamedDeclaration
|
|
82
|
-
if (!/export (d|{)/.test(check)) {
|
|
83
|
-
ctx.error(MODULE_ERROR);
|
|
84
|
-
}
|
|
85
|
-
if (inheritsHelperRe.test(check)) {
|
|
86
|
-
if (babelHelpers === RUNTIME) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
ctx.error(mismatchError(RUNTIME, babelHelpers, transformOptions.filename));
|
|
90
|
-
}
|
|
91
|
-
if (check.includes('babelHelpers.inherits')) {
|
|
92
|
-
if (babelHelpers === EXTERNAL) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
ctx.error(mismatchError(EXTERNAL, babelHelpers, transformOptions.filename));
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// test unminifiable string content
|
|
99
|
-
if (check.includes('Super expression must either be null or a function')) {
|
|
100
|
-
if (babelHelpers === INLINE || babelHelpers === BUNDLED) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
if (babelHelpers === RUNTIME && !transformOptions.plugins.length) {
|
|
104
|
-
ctx.error(`You must use the \`@babel/plugin-transform-runtime\` plugin when \`babelHelpers\` is "${RUNTIME}".\n`);
|
|
105
|
-
}
|
|
106
|
-
ctx.error(mismatchError(INLINE, babelHelpers, transformOptions.filename));
|
|
107
|
-
}
|
|
108
|
-
ctx.error(UNEXPECTED_ERROR);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
async function transformCode(inputCode, babelOptions, overrides, customOptions, ctx, finalizeOptions) {
|
|
112
|
-
// loadPartialConfigAsync has become available in @babel/core@7.8.0
|
|
113
|
-
const config = await (babel.loadPartialConfigAsync || babel.loadPartialConfig)(babelOptions);
|
|
114
|
-
|
|
115
|
-
// file is ignored by babel
|
|
116
|
-
if (!config) {
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
let transformOptions = !overrides.config ? config.options : await overrides.config.call(ctx, config, {
|
|
120
|
-
code: inputCode,
|
|
121
|
-
customOptions
|
|
122
|
-
});
|
|
123
|
-
if (finalizeOptions) {
|
|
124
|
-
transformOptions = await finalizeOptions(transformOptions);
|
|
125
|
-
}
|
|
126
|
-
if (!overrides.result) {
|
|
127
|
-
const {
|
|
128
|
-
code,
|
|
129
|
-
map
|
|
130
|
-
} = await babel.transformAsync(inputCode, transformOptions);
|
|
131
|
-
return {
|
|
132
|
-
code,
|
|
133
|
-
map
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
const result = await babel.transformAsync(inputCode, transformOptions);
|
|
137
|
-
const {
|
|
138
|
-
code,
|
|
139
|
-
map
|
|
140
|
-
} = await overrides.result.call(ctx, result, {
|
|
141
|
-
code: inputCode,
|
|
142
|
-
customOptions,
|
|
143
|
-
config,
|
|
144
|
-
transformOptions
|
|
145
|
-
});
|
|
146
|
-
return {
|
|
147
|
-
code,
|
|
148
|
-
map
|
|
149
|
-
};
|
|
150
|
-
}
|
|
5
|
+
import workerpool from 'workerpool';
|
|
6
|
+
import { e as escapeRegExpCharacters, H as HELPERS, t as transformCode, w as warnOnce, B as BUNDLED } from './transformCode-yk-f524P.js';
|
|
7
|
+
import '@babel/helper-module-imports';
|
|
151
8
|
|
|
152
9
|
const unpackOptions = ({
|
|
153
10
|
extensions = babel.DEFAULT_EXTENSIONS,
|
|
@@ -180,7 +37,7 @@ const warnAboutDeprecatedHelpersOption = ({
|
|
|
180
37
|
const unpackInputPluginOptions = ({
|
|
181
38
|
skipPreflightCheck = false,
|
|
182
39
|
...rest
|
|
183
|
-
}
|
|
40
|
+
}) => {
|
|
184
41
|
if ('runtimeHelpers' in rest) {
|
|
185
42
|
warnAboutDeprecatedHelpersOption({
|
|
186
43
|
deprecatedOption: 'runtimeHelpers',
|
|
@@ -203,8 +60,7 @@ const unpackInputPluginOptions = ({
|
|
|
203
60
|
supportsStaticESM: true,
|
|
204
61
|
supportsDynamicImport: true,
|
|
205
62
|
supportsTopLevelAwait: true,
|
|
206
|
-
|
|
207
|
-
supportsExportNamespaceFrom: !rollupVersion.match(/^1\.2[0-5]\./),
|
|
63
|
+
supportsExportNamespaceFrom: true,
|
|
208
64
|
...rest.caller
|
|
209
65
|
}
|
|
210
66
|
});
|
|
@@ -237,6 +93,54 @@ function getOptionsWithOverrides(pluginOptions = {}, overrides = {}) {
|
|
|
237
93
|
const returnObject = () => {
|
|
238
94
|
return {};
|
|
239
95
|
};
|
|
96
|
+
function findNonSerializableOption(obj) {
|
|
97
|
+
const isSerializable = value => {
|
|
98
|
+
if (value === null) return true;
|
|
99
|
+
if (Array.isArray(value)) return value.every(isSerializable);
|
|
100
|
+
switch (typeof value) {
|
|
101
|
+
case 'undefined':
|
|
102
|
+
case 'string':
|
|
103
|
+
case 'number':
|
|
104
|
+
case 'boolean':
|
|
105
|
+
return true;
|
|
106
|
+
case 'object':
|
|
107
|
+
return Object.values(value).every(isSerializable);
|
|
108
|
+
default:
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
for (const key of Object.keys(obj)) {
|
|
113
|
+
if (!isSerializable(obj[key])) return key;
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
}
|
|
117
|
+
const WORKER_PATH = fileURLToPath(new URL('./worker.js', import.meta.url));
|
|
118
|
+
function createParallelWorkerPool(parallel, overrides) {
|
|
119
|
+
if (typeof parallel === 'number' && (!Number.isInteger(parallel) || parallel < 1)) {
|
|
120
|
+
throw new Error('The "parallel" option must be true or a positive integer specifying the number of workers.');
|
|
121
|
+
}
|
|
122
|
+
if (!parallel) return null;
|
|
123
|
+
if (overrides !== null && overrides !== void 0 && overrides.config) {
|
|
124
|
+
throw new Error('Cannot use "parallel" mode with a custom "config" override.');
|
|
125
|
+
}
|
|
126
|
+
if (overrides !== null && overrides !== void 0 && overrides.result) {
|
|
127
|
+
throw new Error('Cannot use "parallel" mode with a custom "result" override.');
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Default limits to 4 workers. Benefits diminish after this point, because of the setup cost.
|
|
131
|
+
const workerCount = typeof parallel === 'number' ? parallel : Math.min(cpus().length, 4);
|
|
132
|
+
return workerpool.pool(WORKER_PATH, {
|
|
133
|
+
maxWorkers: workerCount,
|
|
134
|
+
workerType: 'thread'
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
function transformWithWorkerPool(workerPool, context, transformOpts, babelOptions) {
|
|
138
|
+
const nonSerializableKey = findNonSerializableOption(babelOptions);
|
|
139
|
+
if (nonSerializableKey) {
|
|
140
|
+
return Promise.reject(new Error(`Cannot use "parallel" mode because the "${nonSerializableKey}" option is not serializable.`));
|
|
141
|
+
}
|
|
142
|
+
return workerPool.exec('transform', [transformOpts]).catch(err => context.error(err.message));
|
|
143
|
+
}
|
|
240
144
|
function createBabelInputPluginFactory(customCallback = returnObject) {
|
|
241
145
|
const overrides = customCallback(babel);
|
|
242
146
|
return pluginOptions => {
|
|
@@ -244,59 +148,87 @@ function createBabelInputPluginFactory(customCallback = returnObject) {
|
|
|
244
148
|
customOptions,
|
|
245
149
|
pluginOptionsWithOverrides
|
|
246
150
|
} = getOptionsWithOverrides(pluginOptions, overrides);
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
151
|
+
const {
|
|
152
|
+
exclude,
|
|
153
|
+
extensions,
|
|
154
|
+
babelHelpers,
|
|
155
|
+
include,
|
|
156
|
+
filter: customFilter,
|
|
157
|
+
skipPreflightCheck,
|
|
158
|
+
parallel,
|
|
159
|
+
...babelOptions
|
|
160
|
+
} = unpackInputPluginOptions(pluginOptionsWithOverrides);
|
|
161
|
+
const workerPool = createParallelWorkerPool(parallel, overrides);
|
|
162
|
+
const extensionRegExp = new RegExp(`(${extensions.map(escapeRegExpCharacters).join('|')})(\\?.*)?(#.*)?$`);
|
|
163
|
+
if (customFilter && (include || exclude)) {
|
|
164
|
+
throw new Error('Could not handle include or exclude with custom filter together');
|
|
165
|
+
}
|
|
166
|
+
const userDefinedFilter = typeof customFilter === 'function' ? customFilter : createFilter(include, exclude);
|
|
167
|
+
const filter = (id, code) => extensionRegExp.test(id) && userDefinedFilter(id, code);
|
|
168
|
+
const helpersFilter = {
|
|
169
|
+
id: new RegExp(`^${escapeRegExpCharacters(HELPERS)}$`)
|
|
170
|
+
};
|
|
251
171
|
return {
|
|
252
172
|
name: 'babel',
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
if (customFilter && (include || exclude)) {
|
|
270
|
-
throw new Error('Could not handle include or exclude with custom filter together');
|
|
173
|
+
resolveId: {
|
|
174
|
+
filter: helpersFilter,
|
|
175
|
+
handler(id) {
|
|
176
|
+
if (id !== HELPERS) {
|
|
177
|
+
return null;
|
|
178
|
+
}
|
|
179
|
+
return id;
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
load: {
|
|
183
|
+
filter: helpersFilter,
|
|
184
|
+
handler(id) {
|
|
185
|
+
if (id !== HELPERS) {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
return babel.buildExternalHelpers(null, 'module');
|
|
271
189
|
}
|
|
272
|
-
const userDefinedFilter = typeof customFilter === 'function' ? customFilter : createFilter(include, exclude);
|
|
273
|
-
filter = id => extensionRegExp.test(stripQuery(id).bareId) && userDefinedFilter(id);
|
|
274
|
-
return null;
|
|
275
190
|
},
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
191
|
+
transform: {
|
|
192
|
+
filter: {
|
|
193
|
+
id: extensionRegExp
|
|
194
|
+
},
|
|
195
|
+
async handler(code, filename) {
|
|
196
|
+
var _overrides$config, _overrides$result;
|
|
197
|
+
if (!(await filter(filename, code))) return null;
|
|
198
|
+
if (filename === HELPERS) return null;
|
|
199
|
+
const resolvedBabelOptions = {
|
|
200
|
+
...babelOptions,
|
|
201
|
+
filename
|
|
202
|
+
};
|
|
203
|
+
if (workerPool) {
|
|
204
|
+
return transformWithWorkerPool(workerPool, this, {
|
|
205
|
+
inputCode: code,
|
|
206
|
+
babelOptions: resolvedBabelOptions,
|
|
207
|
+
skipPreflightCheck,
|
|
208
|
+
babelHelpers
|
|
209
|
+
}, resolvedBabelOptions);
|
|
210
|
+
}
|
|
211
|
+
return transformCode({
|
|
212
|
+
inputCode: code,
|
|
213
|
+
babelOptions: resolvedBabelOptions,
|
|
214
|
+
overrides: {
|
|
215
|
+
config: (_overrides$config = overrides.config) === null || _overrides$config === void 0 ? void 0 : _overrides$config.bind(this),
|
|
216
|
+
result: (_overrides$result = overrides.result) === null || _overrides$result === void 0 ? void 0 : _overrides$result.bind(this)
|
|
217
|
+
},
|
|
218
|
+
customOptions,
|
|
219
|
+
error: this.error.bind(this),
|
|
220
|
+
skipPreflightCheck,
|
|
221
|
+
babelHelpers
|
|
222
|
+
});
|
|
279
223
|
}
|
|
280
|
-
return id;
|
|
281
224
|
},
|
|
282
|
-
|
|
283
|
-
if (
|
|
284
|
-
|
|
225
|
+
async closeBundle() {
|
|
226
|
+
if (!this.meta.watchMode) {
|
|
227
|
+
await (workerPool === null || workerPool === void 0 ? void 0 : workerPool.terminate());
|
|
285
228
|
}
|
|
286
|
-
return babel.buildExternalHelpers(null, 'module');
|
|
287
229
|
},
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
if (filename === HELPERS) return null;
|
|
291
|
-
return transformCode(code, {
|
|
292
|
-
...babelOptions,
|
|
293
|
-
filename
|
|
294
|
-
}, overrides, customOptions, this, async transformOptions => {
|
|
295
|
-
if (!skipPreflightCheck) {
|
|
296
|
-
await preflightCheck(this, babelHelpers, transformOptions);
|
|
297
|
-
}
|
|
298
|
-
return babelHelpers === BUNDLED ? addBabelPlugin(transformOptions, importHelperPlugin) : transformOptions;
|
|
299
|
-
});
|
|
230
|
+
async closeWatcher() {
|
|
231
|
+
await (workerPool === null || workerPool === void 0 ? void 0 : workerPool.terminate());
|
|
300
232
|
}
|
|
301
233
|
};
|
|
302
234
|
};
|
|
@@ -321,6 +253,7 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
|
|
|
321
253
|
customOptions,
|
|
322
254
|
pluginOptionsWithOverrides
|
|
323
255
|
} = getOptionsWithOverrides(pluginOptions, overrides);
|
|
256
|
+
const workerPool = createParallelWorkerPool(pluginOptionsWithOverrides.parallel, overrides);
|
|
324
257
|
|
|
325
258
|
// cache for chunk name filter (includeChunks/excludeChunks)
|
|
326
259
|
let chunkNameFilter;
|
|
@@ -341,6 +274,7 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
|
|
|
341
274
|
}
|
|
342
275
|
},
|
|
343
276
|
renderChunk(code, chunk, outputOptions) {
|
|
277
|
+
var _overrides$config2, _overrides$result2;
|
|
344
278
|
/* eslint-disable no-unused-vars */
|
|
345
279
|
const {
|
|
346
280
|
allowAllFormats,
|
|
@@ -351,6 +285,7 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
|
|
|
351
285
|
externalHelpers,
|
|
352
286
|
externalHelpersWhitelist,
|
|
353
287
|
include,
|
|
288
|
+
parallel,
|
|
354
289
|
runtimeHelpers,
|
|
355
290
|
...babelOptions
|
|
356
291
|
} = unpackOutputPluginOptions(pluginOptionsWithOverrides, outputOptions);
|
|
@@ -367,7 +302,29 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
|
|
|
367
302
|
return null;
|
|
368
303
|
}
|
|
369
304
|
}
|
|
370
|
-
|
|
305
|
+
if (workerPool) {
|
|
306
|
+
return transformWithWorkerPool(workerPool, this, {
|
|
307
|
+
inputCode: code,
|
|
308
|
+
babelOptions,
|
|
309
|
+
skipPreflightCheck: true
|
|
310
|
+
}, babelOptions);
|
|
311
|
+
}
|
|
312
|
+
return transformCode({
|
|
313
|
+
inputCode: code,
|
|
314
|
+
babelOptions,
|
|
315
|
+
overrides: {
|
|
316
|
+
config: (_overrides$config2 = overrides.config) === null || _overrides$config2 === void 0 ? void 0 : _overrides$config2.bind(this),
|
|
317
|
+
result: (_overrides$result2 = overrides.result) === null || _overrides$result2 === void 0 ? void 0 : _overrides$result2.bind(this)
|
|
318
|
+
},
|
|
319
|
+
customOptions,
|
|
320
|
+
error: this.error.bind(this),
|
|
321
|
+
skipPreflightCheck: true
|
|
322
|
+
});
|
|
323
|
+
},
|
|
324
|
+
async generateBundle() {
|
|
325
|
+
if (!this.meta.watchMode) {
|
|
326
|
+
await (workerPool === null || workerPool === void 0 ? void 0 : workerPool.terminate());
|
|
327
|
+
}
|
|
371
328
|
}
|
|
372
329
|
};
|
|
373
330
|
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import * as babel from '@babel/core';
|
|
2
|
+
import { addNamed } from '@babel/helper-module-imports';
|
|
3
|
+
|
|
4
|
+
const BUNDLED = 'bundled';
|
|
5
|
+
const INLINE = 'inline';
|
|
6
|
+
const RUNTIME = 'runtime';
|
|
7
|
+
const EXTERNAL = 'external';
|
|
8
|
+
|
|
9
|
+
// NOTE: DO NOT REMOVE the null character `\0` as it may be used by other plugins
|
|
10
|
+
// e.g. https://github.com/rollup/rollup-plugin-node-resolve/blob/313a3e32f432f9eb18cc4c231cc7aac6df317a51/src/index.js#L74
|
|
11
|
+
const HELPERS = '\0rollupPluginBabelHelpers.js';
|
|
12
|
+
|
|
13
|
+
function importHelperPlugin({
|
|
14
|
+
types: t
|
|
15
|
+
}) {
|
|
16
|
+
return {
|
|
17
|
+
pre(file) {
|
|
18
|
+
const cachedHelpers = {};
|
|
19
|
+
file.set('helperGenerator', name => {
|
|
20
|
+
if (!file.availableHelper(name)) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
if (cachedHelpers[name]) {
|
|
24
|
+
return t.cloneNode(cachedHelpers[name]);
|
|
25
|
+
}
|
|
26
|
+
return cachedHelpers[name] = addNamed(file.path, name, HELPERS);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const addBabelPlugin = (options, plugin) => {
|
|
33
|
+
return {
|
|
34
|
+
...options,
|
|
35
|
+
plugins: options.plugins.concat(plugin)
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const warned = {};
|
|
39
|
+
function warnOnce(ctx, msg) {
|
|
40
|
+
if (warned[msg]) return;
|
|
41
|
+
warned[msg] = true;
|
|
42
|
+
ctx.warn(msg);
|
|
43
|
+
}
|
|
44
|
+
const regExpCharactersRegExp = /[\\^$.*+?()[\]{}|]/g;
|
|
45
|
+
const escapeRegExpCharacters = str => str.replace(regExpCharactersRegExp, '\\$&');
|
|
46
|
+
|
|
47
|
+
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/plugins/tree/master/packages/babel#modules ).';
|
|
48
|
+
const UNEXPECTED_ERROR = 'An unexpected situation arose. Please raise an issue at ' + 'https://github.com/rollup/plugins/issues. Thanks!';
|
|
49
|
+
const PREFLIGHT_TEST_STRING = '__ROLLUP__PREFLIGHT_CHECK_DO_NOT_TOUCH__';
|
|
50
|
+
const PREFLIGHT_INPUT = `export default "${PREFLIGHT_TEST_STRING}";`;
|
|
51
|
+
function helpersTestTransform() {
|
|
52
|
+
return {
|
|
53
|
+
visitor: {
|
|
54
|
+
StringLiteral(path, state) {
|
|
55
|
+
if (path.node.value === PREFLIGHT_TEST_STRING) {
|
|
56
|
+
path.replaceWith(state.file.addHelper('inherits'));
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const mismatchError = (actual, expected, filename) => `You have declared using "${expected}" babelHelpers, but transforming ${filename} resulted in "${actual}". Please check your configuration.`;
|
|
63
|
+
|
|
64
|
+
// Revert to /\/helpers\/(esm\/)?inherits/ when Babel 8 gets released, this was fixed in https://github.com/babel/babel/issues/14185
|
|
65
|
+
const inheritsHelperRe = /[\\/]+helpers[\\/]+(esm[\\/]+)?inherits/;
|
|
66
|
+
async function preflightCheck(error, babelHelpers, transformOptions) {
|
|
67
|
+
const finalOptions = addBabelPlugin(transformOptions, helpersTestTransform);
|
|
68
|
+
const check = (await babel.transformAsync(PREFLIGHT_INPUT, finalOptions)).code;
|
|
69
|
+
|
|
70
|
+
// Babel sometimes splits ExportDefaultDeclaration into 2 statements, so we also check for ExportNamedDeclaration
|
|
71
|
+
if (!/export (d|{)/.test(check)) {
|
|
72
|
+
error(MODULE_ERROR);
|
|
73
|
+
}
|
|
74
|
+
if (inheritsHelperRe.test(check)) {
|
|
75
|
+
if (babelHelpers === RUNTIME) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
error(mismatchError(RUNTIME, babelHelpers, transformOptions.filename));
|
|
79
|
+
}
|
|
80
|
+
if (check.includes('babelHelpers.inherits')) {
|
|
81
|
+
if (babelHelpers === EXTERNAL) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
error(mismatchError(EXTERNAL, babelHelpers, transformOptions.filename));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// test unminifiable string content
|
|
88
|
+
if (check.includes('Super expression must either be null or a function')) {
|
|
89
|
+
if (babelHelpers === INLINE || babelHelpers === BUNDLED) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (babelHelpers === RUNTIME && !transformOptions.plugins.length) {
|
|
93
|
+
error(`You must use the \`@babel/plugin-transform-runtime\` plugin when \`babelHelpers\` is "${RUNTIME}".\n`);
|
|
94
|
+
}
|
|
95
|
+
error(mismatchError(INLINE, babelHelpers, transformOptions.filename));
|
|
96
|
+
}
|
|
97
|
+
error(UNEXPECTED_ERROR);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
async function transformCode({
|
|
101
|
+
inputCode,
|
|
102
|
+
babelOptions,
|
|
103
|
+
overrides,
|
|
104
|
+
customOptions,
|
|
105
|
+
error,
|
|
106
|
+
skipPreflightCheck,
|
|
107
|
+
babelHelpers
|
|
108
|
+
}) {
|
|
109
|
+
// loadPartialConfigAsync has become available in @babel/core@7.8.0
|
|
110
|
+
const config = await (babel.loadPartialConfigAsync || babel.loadPartialConfig)(babelOptions);
|
|
111
|
+
|
|
112
|
+
// file is ignored by babel
|
|
113
|
+
if (!config) {
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
let transformOptions = !(overrides !== null && overrides !== void 0 && overrides.config) ? config.options : await overrides.config(config, {
|
|
117
|
+
code: inputCode,
|
|
118
|
+
customOptions
|
|
119
|
+
});
|
|
120
|
+
if (!skipPreflightCheck) {
|
|
121
|
+
await preflightCheck(error, babelHelpers, transformOptions);
|
|
122
|
+
}
|
|
123
|
+
transformOptions = babelHelpers === BUNDLED ? addBabelPlugin(transformOptions, importHelperPlugin) : transformOptions;
|
|
124
|
+
if (!(overrides !== null && overrides !== void 0 && overrides.result)) {
|
|
125
|
+
const {
|
|
126
|
+
code,
|
|
127
|
+
map
|
|
128
|
+
} = await babel.transformAsync(inputCode, transformOptions);
|
|
129
|
+
return {
|
|
130
|
+
code,
|
|
131
|
+
map
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
const result = await babel.transformAsync(inputCode, transformOptions);
|
|
135
|
+
const {
|
|
136
|
+
code,
|
|
137
|
+
map
|
|
138
|
+
} = await overrides.result(result, {
|
|
139
|
+
code: inputCode,
|
|
140
|
+
customOptions,
|
|
141
|
+
config,
|
|
142
|
+
transformOptions
|
|
143
|
+
});
|
|
144
|
+
return {
|
|
145
|
+
code,
|
|
146
|
+
map
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export { BUNDLED as B, HELPERS as H, escapeRegExpCharacters as e, transformCode as t, warnOnce as w };
|
|
151
|
+
//# sourceMappingURL=transformCode-yk-f524P.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import workerpool from 'workerpool';
|
|
2
|
+
import { t as transformCode } from './transformCode-yk-f524P.js';
|
|
3
|
+
import '@babel/core';
|
|
4
|
+
import '@babel/helper-module-imports';
|
|
5
|
+
|
|
6
|
+
async function transform(opts) {
|
|
7
|
+
return transformCode({
|
|
8
|
+
...opts,
|
|
9
|
+
error: msg => {
|
|
10
|
+
throw new Error(msg);
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
workerpool.worker({
|
|
15
|
+
transform
|
|
16
|
+
});
|
|
17
|
+
//# sourceMappingURL=worker.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rollup/plugin-babel",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@babel/core": "^7.0.0",
|
|
43
43
|
"@types/babel__core": "^7.1.9",
|
|
44
|
-
"rollup": "^
|
|
44
|
+
"rollup": "^2.0.0||^3.0.0||^4.0.0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependenciesMeta": {
|
|
47
47
|
"rollup": {
|
|
@@ -53,7 +53,8 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@babel/helper-module-imports": "^7.18.6",
|
|
56
|
-
"@rollup/pluginutils": "^5.0.1"
|
|
56
|
+
"@rollup/pluginutils": "^5.0.1",
|
|
57
|
+
"workerpool": "^9.0.0"
|
|
57
58
|
},
|
|
58
59
|
"devDependencies": {
|
|
59
60
|
"@babel/core": "^7.19.1",
|
|
@@ -69,14 +70,6 @@
|
|
|
69
70
|
"source-map": "^0.7.4"
|
|
70
71
|
},
|
|
71
72
|
"types": "./types/index.d.ts",
|
|
72
|
-
"ava": {
|
|
73
|
-
"files": [
|
|
74
|
-
"!**/fixtures/**",
|
|
75
|
-
"!**/helpers/**",
|
|
76
|
-
"!**/recipes/**",
|
|
77
|
-
"!**/types.ts"
|
|
78
|
-
]
|
|
79
|
-
},
|
|
80
73
|
"contributors": [
|
|
81
74
|
"Bogdan Chadkin <trysound@yandex.ru>",
|
|
82
75
|
"Mateusz Burzyński <mateuszburzynski@gmail.com> (https://github.com/Andarist)"
|
|
@@ -86,12 +79,12 @@
|
|
|
86
79
|
"ci:coverage": "nyc pnpm test && nyc report --reporter=text-lcov > coverage.lcov",
|
|
87
80
|
"ci:lint": "pnpm build && pnpm lint",
|
|
88
81
|
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}",
|
|
89
|
-
"ci:test": "pnpm test -- --verbose",
|
|
82
|
+
"ci:test": "pnpm test -- --reporter=verbose",
|
|
90
83
|
"prebuild": "del-cli dist",
|
|
91
84
|
"prerelease": "pnpm build",
|
|
92
85
|
"pretest": "pnpm build",
|
|
93
86
|
"release": "pnpm --workspace-root package:release $(pwd)",
|
|
94
|
-
"test": "
|
|
87
|
+
"test": "vitest --config ../../.config/vitest.config.mts run",
|
|
95
88
|
"test:ts": "tsc types/index.d.ts test/types.ts --noEmit"
|
|
96
89
|
}
|
|
97
90
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Plugin, PluginContext, TransformPluginContext } from 'rollup';
|
|
2
|
-
import type { FilterPattern
|
|
2
|
+
import type { FilterPattern } from '@rollup/pluginutils';
|
|
3
3
|
import type * as babelCore from '@babel/core';
|
|
4
4
|
|
|
5
5
|
export interface RollupBabelInputPluginOptions
|
|
@@ -23,7 +23,7 @@ export interface RollupBabelInputPluginOptions
|
|
|
23
23
|
* const filter = createFilter(include, exclude, {});
|
|
24
24
|
* @default undefined;
|
|
25
25
|
*/
|
|
26
|
-
filter?:
|
|
26
|
+
filter?: (id: string, code: string) => Promise<boolean> | boolean;
|
|
27
27
|
/**
|
|
28
28
|
* An array of file extensions that Babel should transpile. If you want to transpile TypeScript files with this plugin it's essential to include .ts and .tsx in this option.
|
|
29
29
|
* @default ['.js', '.jsx', '.es6', '.es', '.mjs']
|
|
@@ -39,6 +39,14 @@ export interface RollupBabelInputPluginOptions
|
|
|
39
39
|
* @default false
|
|
40
40
|
*/
|
|
41
41
|
skipPreflightCheck?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Enable parallel processing of files in worker threads. This has a setup cost, so is best suited for larger projects.
|
|
44
|
+
* Pass an integer to set the number of workers. Set `true` for the default number of workers (based on CPU cores, capped at 4).
|
|
45
|
+
*
|
|
46
|
+
* This option cannot be used alongside custom overrides or non-serializable Babel options.
|
|
47
|
+
* @default false
|
|
48
|
+
*/
|
|
49
|
+
parallel?: boolean | number;
|
|
42
50
|
}
|
|
43
51
|
|
|
44
52
|
export interface RollupBabelOutputPluginOptions
|
|
@@ -58,6 +66,14 @@ export interface RollupBabelOutputPluginOptions
|
|
|
58
66
|
* These patterns are matched against the `chunk.name` value in Rollup's `renderChunk` hook.
|
|
59
67
|
*/
|
|
60
68
|
excludeChunks?: FilterPattern;
|
|
69
|
+
/**
|
|
70
|
+
* Enable parallel processing of chunks in worker threads. This has a setup cost, so is best suited for larger projects.
|
|
71
|
+
* Pass an integer to set the number of workers. Set `true` for the default number of workers (based on CPU cores, capped at 4).
|
|
72
|
+
*
|
|
73
|
+
* This option cannot be used alongside custom overrides or non-serializable Babel options.
|
|
74
|
+
* @default false
|
|
75
|
+
*/
|
|
76
|
+
parallel?: boolean | number;
|
|
61
77
|
}
|
|
62
78
|
|
|
63
79
|
export type RollupBabelCustomInputPluginOptions = (
|