@rollup/plugin-babel 7.0.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 CHANGED
@@ -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 helperModuleImports = require('@babel/helper-module-imports');
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,143 +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
-
71
- 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 ).';
72
- const UNEXPECTED_ERROR = 'An unexpected situation arose. Please raise an issue at ' + 'https://github.com/rollup/plugins/issues. Thanks!';
73
- const PREFLIGHT_TEST_STRING = '__ROLLUP__PREFLIGHT_CHECK_DO_NOT_TOUCH__';
74
- const PREFLIGHT_INPUT = `export default "${PREFLIGHT_TEST_STRING}";`;
75
- function helpersTestTransform() {
76
- return {
77
- visitor: {
78
- StringLiteral(path, state) {
79
- if (path.node.value === PREFLIGHT_TEST_STRING) {
80
- path.replaceWith(state.file.addHelper('inherits'));
81
- }
82
- }
83
- }
84
- };
85
- }
86
- const mismatchError = (actual, expected, filename) => `You have declared using "${expected}" babelHelpers, but transforming ${filename} resulted in "${actual}". Please check your configuration.`;
87
-
88
- // Revert to /\/helpers\/(esm\/)?inherits/ when Babel 8 gets released, this was fixed in https://github.com/babel/babel/issues/14185
89
- const inheritsHelperRe = /[\\/]+helpers[\\/]+(esm[\\/]+)?inherits/;
90
- async function preflightCheck(ctx, babelHelpers, transformOptions) {
91
- const finalOptions = addBabelPlugin(transformOptions, helpersTestTransform);
92
- const check = (await babel__namespace.transformAsync(PREFLIGHT_INPUT, finalOptions)).code;
93
-
94
- // Babel sometimes splits ExportDefaultDeclaration into 2 statements, so we also check for ExportNamedDeclaration
95
- if (!/export (d|{)/.test(check)) {
96
- ctx.error(MODULE_ERROR);
97
- }
98
- if (inheritsHelperRe.test(check)) {
99
- if (babelHelpers === RUNTIME) {
100
- return;
101
- }
102
- ctx.error(mismatchError(RUNTIME, babelHelpers, transformOptions.filename));
103
- }
104
- if (check.includes('babelHelpers.inherits')) {
105
- if (babelHelpers === EXTERNAL) {
106
- return;
107
- }
108
- ctx.error(mismatchError(EXTERNAL, babelHelpers, transformOptions.filename));
109
- }
110
-
111
- // test unminifiable string content
112
- if (check.includes('Super expression must either be null or a function')) {
113
- if (babelHelpers === INLINE || babelHelpers === BUNDLED) {
114
- return;
115
- }
116
- if (babelHelpers === RUNTIME && !transformOptions.plugins.length) {
117
- ctx.error(`You must use the \`@babel/plugin-transform-runtime\` plugin when \`babelHelpers\` is "${RUNTIME}".\n`);
118
- }
119
- ctx.error(mismatchError(INLINE, babelHelpers, transformOptions.filename));
120
- }
121
- ctx.error(UNEXPECTED_ERROR);
122
- }
123
-
124
- async function transformCode(inputCode, babelOptions, overrides, customOptions, ctx, finalizeOptions) {
125
- // loadPartialConfigAsync has become available in @babel/core@7.8.0
126
- const config = await (babel__namespace.loadPartialConfigAsync || babel__namespace.loadPartialConfig)(babelOptions);
127
-
128
- // file is ignored by babel
129
- if (!config) {
130
- return null;
131
- }
132
- let transformOptions = !overrides.config ? config.options : await overrides.config.call(ctx, config, {
133
- code: inputCode,
134
- customOptions
135
- });
136
- if (finalizeOptions) {
137
- transformOptions = await finalizeOptions(transformOptions);
138
- }
139
- if (!overrides.result) {
140
- const {
141
- code,
142
- map
143
- } = await babel__namespace.transformAsync(inputCode, transformOptions);
144
- return {
145
- code,
146
- map
147
- };
148
- }
149
- const result = await babel__namespace.transformAsync(inputCode, transformOptions);
150
- const {
151
- code,
152
- map
153
- } = await overrides.result.call(ctx, result, {
154
- code: inputCode,
155
- customOptions,
156
- config,
157
- transformOptions
158
- });
159
- return {
160
- code,
161
- map
162
- };
163
- }
164
-
165
33
  const unpackOptions = ({
166
34
  extensions = babel__namespace.DEFAULT_EXTENSIONS,
167
35
  // rollup uses sourcemap, babel uses sourceMaps
@@ -211,7 +79,7 @@ const unpackInputPluginOptions = ({
211
79
  return unpackOptions({
212
80
  ...rest,
213
81
  skipPreflightCheck,
214
- babelHelpers: rest.babelHelpers || BUNDLED,
82
+ babelHelpers: rest.babelHelpers || transformCode.BUNDLED,
215
83
  caller: {
216
84
  supportsStaticESM: true,
217
85
  supportsDynamicImport: true,
@@ -249,6 +117,54 @@ function getOptionsWithOverrides(pluginOptions = {}, overrides = {}) {
249
117
  const returnObject = () => {
250
118
  return {};
251
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
+ }
252
168
  function createBabelInputPluginFactory(customCallback = returnObject) {
253
169
  const overrides = customCallback(babel__namespace);
254
170
  return pluginOptions => {
@@ -263,23 +179,25 @@ function createBabelInputPluginFactory(customCallback = returnObject) {
263
179
  include,
264
180
  filter: customFilter,
265
181
  skipPreflightCheck,
182
+ parallel,
266
183
  ...babelOptions
267
184
  } = unpackInputPluginOptions(pluginOptionsWithOverrides);
268
- const extensionRegExp = new RegExp(`(${extensions.map(escapeRegExpCharacters).join('|')})(\\?.*)?(#.*)?$`);
185
+ const workerPool = createParallelWorkerPool(parallel, overrides);
186
+ const extensionRegExp = new RegExp(`(${extensions.map(transformCode.escapeRegExpCharacters).join('|')})(\\?.*)?(#.*)?$`);
269
187
  if (customFilter && (include || exclude)) {
270
188
  throw new Error('Could not handle include or exclude with custom filter together');
271
189
  }
272
190
  const userDefinedFilter = typeof customFilter === 'function' ? customFilter : pluginutils.createFilter(include, exclude);
273
191
  const filter = (id, code) => extensionRegExp.test(id) && userDefinedFilter(id, code);
274
192
  const helpersFilter = {
275
- id: new RegExp(`^${escapeRegExpCharacters(HELPERS)}$`)
193
+ id: new RegExp(`^${transformCode.escapeRegExpCharacters(transformCode.HELPERS)}$`)
276
194
  };
277
195
  return {
278
196
  name: 'babel',
279
197
  resolveId: {
280
198
  filter: helpersFilter,
281
199
  handler(id) {
282
- if (id !== HELPERS) {
200
+ if (id !== transformCode.HELPERS) {
283
201
  return null;
284
202
  }
285
203
  return id;
@@ -288,7 +206,7 @@ function createBabelInputPluginFactory(customCallback = returnObject) {
288
206
  load: {
289
207
  filter: helpersFilter,
290
208
  handler(id) {
291
- if (id !== HELPERS) {
209
+ if (id !== transformCode.HELPERS) {
292
210
  return null;
293
211
  }
294
212
  return babel__namespace.buildExternalHelpers(null, 'module');
@@ -299,18 +217,42 @@ function createBabelInputPluginFactory(customCallback = returnObject) {
299
217
  id: extensionRegExp
300
218
  },
301
219
  async handler(code, filename) {
220
+ var _overrides$config, _overrides$result;
302
221
  if (!(await filter(filename, code))) return null;
303
- if (filename === HELPERS) return null;
304
- return transformCode(code, {
222
+ if (filename === transformCode.HELPERS) return null;
223
+ const resolvedBabelOptions = {
305
224
  ...babelOptions,
306
225
  filename
307
- }, overrides, customOptions, this, async transformOptions => {
308
- if (!skipPreflightCheck) {
309
- await preflightCheck(this, babelHelpers, transformOptions);
310
- }
311
- return babelHelpers === BUNDLED ? addBabelPlugin(transformOptions, importHelperPlugin) : transformOptions;
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
312
246
  });
313
247
  }
248
+ },
249
+ async closeBundle() {
250
+ if (!this.meta.watchMode) {
251
+ await (workerPool === null || workerPool === void 0 ? void 0 : workerPool.terminate());
252
+ }
253
+ },
254
+ async closeWatcher() {
255
+ await (workerPool === null || workerPool === void 0 ? void 0 : workerPool.terminate());
314
256
  }
315
257
  };
316
258
  };
@@ -335,6 +277,7 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
335
277
  customOptions,
336
278
  pluginOptionsWithOverrides
337
279
  } = getOptionsWithOverrides(pluginOptions, overrides);
280
+ const workerPool = createParallelWorkerPool(pluginOptionsWithOverrides.parallel, overrides);
338
281
 
339
282
  // cache for chunk name filter (includeChunks/excludeChunks)
340
283
  let chunkNameFilter;
@@ -348,13 +291,14 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
348
291
  allowAllFormats
349
292
  } = pluginOptionsWithOverrides;
350
293
  if (extensions || include || exclude) {
351
- 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.');
352
295
  }
353
296
  if (!allowAllFormats && outputOptions.format !== 'es' && outputOptions.format !== 'cjs') {
354
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.`);
355
298
  }
356
299
  },
357
300
  renderChunk(code, chunk, outputOptions) {
301
+ var _overrides$config2, _overrides$result2;
358
302
  /* eslint-disable no-unused-vars */
359
303
  const {
360
304
  allowAllFormats,
@@ -365,6 +309,7 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
365
309
  externalHelpers,
366
310
  externalHelpersWhitelist,
367
311
  include,
312
+ parallel,
368
313
  runtimeHelpers,
369
314
  ...babelOptions
370
315
  } = unpackOutputPluginOptions(pluginOptionsWithOverrides, outputOptions);
@@ -381,7 +326,29 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
381
326
  return null;
382
327
  }
383
328
  }
384
- return transformCode(code, babelOptions, overrides, customOptions, this);
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
+ }
385
352
  }
386
353
  };
387
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,143 +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 { addNamed } from '@babel/helper-module-imports';
4
-
5
- const BUNDLED = 'bundled';
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
-
48
- 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 ).';
49
- const UNEXPECTED_ERROR = 'An unexpected situation arose. Please raise an issue at ' + 'https://github.com/rollup/plugins/issues. Thanks!';
50
- const PREFLIGHT_TEST_STRING = '__ROLLUP__PREFLIGHT_CHECK_DO_NOT_TOUCH__';
51
- const PREFLIGHT_INPUT = `export default "${PREFLIGHT_TEST_STRING}";`;
52
- function helpersTestTransform() {
53
- return {
54
- visitor: {
55
- StringLiteral(path, state) {
56
- if (path.node.value === PREFLIGHT_TEST_STRING) {
57
- path.replaceWith(state.file.addHelper('inherits'));
58
- }
59
- }
60
- }
61
- };
62
- }
63
- const mismatchError = (actual, expected, filename) => `You have declared using "${expected}" babelHelpers, but transforming ${filename} resulted in "${actual}". Please check your configuration.`;
64
-
65
- // Revert to /\/helpers\/(esm\/)?inherits/ when Babel 8 gets released, this was fixed in https://github.com/babel/babel/issues/14185
66
- const inheritsHelperRe = /[\\/]+helpers[\\/]+(esm[\\/]+)?inherits/;
67
- async function preflightCheck(ctx, babelHelpers, transformOptions) {
68
- const finalOptions = addBabelPlugin(transformOptions, helpersTestTransform);
69
- const check = (await babel.transformAsync(PREFLIGHT_INPUT, finalOptions)).code;
70
-
71
- // Babel sometimes splits ExportDefaultDeclaration into 2 statements, so we also check for ExportNamedDeclaration
72
- if (!/export (d|{)/.test(check)) {
73
- ctx.error(MODULE_ERROR);
74
- }
75
- if (inheritsHelperRe.test(check)) {
76
- if (babelHelpers === RUNTIME) {
77
- return;
78
- }
79
- ctx.error(mismatchError(RUNTIME, babelHelpers, transformOptions.filename));
80
- }
81
- if (check.includes('babelHelpers.inherits')) {
82
- if (babelHelpers === EXTERNAL) {
83
- return;
84
- }
85
- ctx.error(mismatchError(EXTERNAL, babelHelpers, transformOptions.filename));
86
- }
87
-
88
- // test unminifiable string content
89
- if (check.includes('Super expression must either be null or a function')) {
90
- if (babelHelpers === INLINE || babelHelpers === BUNDLED) {
91
- return;
92
- }
93
- if (babelHelpers === RUNTIME && !transformOptions.plugins.length) {
94
- ctx.error(`You must use the \`@babel/plugin-transform-runtime\` plugin when \`babelHelpers\` is "${RUNTIME}".\n`);
95
- }
96
- ctx.error(mismatchError(INLINE, babelHelpers, transformOptions.filename));
97
- }
98
- ctx.error(UNEXPECTED_ERROR);
99
- }
100
-
101
- async function transformCode(inputCode, babelOptions, overrides, customOptions, ctx, finalizeOptions) {
102
- // loadPartialConfigAsync has become available in @babel/core@7.8.0
103
- const config = await (babel.loadPartialConfigAsync || babel.loadPartialConfig)(babelOptions);
104
-
105
- // file is ignored by babel
106
- if (!config) {
107
- return null;
108
- }
109
- let transformOptions = !overrides.config ? config.options : await overrides.config.call(ctx, config, {
110
- code: inputCode,
111
- customOptions
112
- });
113
- if (finalizeOptions) {
114
- transformOptions = await finalizeOptions(transformOptions);
115
- }
116
- if (!overrides.result) {
117
- const {
118
- code,
119
- map
120
- } = await babel.transformAsync(inputCode, transformOptions);
121
- return {
122
- code,
123
- map
124
- };
125
- }
126
- const result = await babel.transformAsync(inputCode, transformOptions);
127
- const {
128
- code,
129
- map
130
- } = await overrides.result.call(ctx, result, {
131
- code: inputCode,
132
- customOptions,
133
- config,
134
- transformOptions
135
- });
136
- return {
137
- code,
138
- map
139
- };
140
- }
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';
141
8
 
142
9
  const unpackOptions = ({
143
10
  extensions = babel.DEFAULT_EXTENSIONS,
@@ -226,6 +93,54 @@ function getOptionsWithOverrides(pluginOptions = {}, overrides = {}) {
226
93
  const returnObject = () => {
227
94
  return {};
228
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
+ }
229
144
  function createBabelInputPluginFactory(customCallback = returnObject) {
230
145
  const overrides = customCallback(babel);
231
146
  return pluginOptions => {
@@ -240,8 +155,10 @@ function createBabelInputPluginFactory(customCallback = returnObject) {
240
155
  include,
241
156
  filter: customFilter,
242
157
  skipPreflightCheck,
158
+ parallel,
243
159
  ...babelOptions
244
160
  } = unpackInputPluginOptions(pluginOptionsWithOverrides);
161
+ const workerPool = createParallelWorkerPool(parallel, overrides);
245
162
  const extensionRegExp = new RegExp(`(${extensions.map(escapeRegExpCharacters).join('|')})(\\?.*)?(#.*)?$`);
246
163
  if (customFilter && (include || exclude)) {
247
164
  throw new Error('Could not handle include or exclude with custom filter together');
@@ -276,18 +193,42 @@ function createBabelInputPluginFactory(customCallback = returnObject) {
276
193
  id: extensionRegExp
277
194
  },
278
195
  async handler(code, filename) {
196
+ var _overrides$config, _overrides$result;
279
197
  if (!(await filter(filename, code))) return null;
280
198
  if (filename === HELPERS) return null;
281
- return transformCode(code, {
199
+ const resolvedBabelOptions = {
282
200
  ...babelOptions,
283
201
  filename
284
- }, overrides, customOptions, this, async transformOptions => {
285
- if (!skipPreflightCheck) {
286
- await preflightCheck(this, babelHelpers, transformOptions);
287
- }
288
- return babelHelpers === BUNDLED ? addBabelPlugin(transformOptions, importHelperPlugin) : transformOptions;
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
289
222
  });
290
223
  }
224
+ },
225
+ async closeBundle() {
226
+ if (!this.meta.watchMode) {
227
+ await (workerPool === null || workerPool === void 0 ? void 0 : workerPool.terminate());
228
+ }
229
+ },
230
+ async closeWatcher() {
231
+ await (workerPool === null || workerPool === void 0 ? void 0 : workerPool.terminate());
291
232
  }
292
233
  };
293
234
  };
@@ -312,6 +253,7 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
312
253
  customOptions,
313
254
  pluginOptionsWithOverrides
314
255
  } = getOptionsWithOverrides(pluginOptions, overrides);
256
+ const workerPool = createParallelWorkerPool(pluginOptionsWithOverrides.parallel, overrides);
315
257
 
316
258
  // cache for chunk name filter (includeChunks/excludeChunks)
317
259
  let chunkNameFilter;
@@ -332,6 +274,7 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
332
274
  }
333
275
  },
334
276
  renderChunk(code, chunk, outputOptions) {
277
+ var _overrides$config2, _overrides$result2;
335
278
  /* eslint-disable no-unused-vars */
336
279
  const {
337
280
  allowAllFormats,
@@ -342,6 +285,7 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
342
285
  externalHelpers,
343
286
  externalHelpersWhitelist,
344
287
  include,
288
+ parallel,
345
289
  runtimeHelpers,
346
290
  ...babelOptions
347
291
  } = unpackOutputPluginOptions(pluginOptionsWithOverrides, outputOptions);
@@ -358,7 +302,29 @@ function createBabelOutputPluginFactory(customCallback = returnObject) {
358
302
  return null;
359
303
  }
360
304
  }
361
- return transformCode(code, babelOptions, overrides, customOptions, this);
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
+ }
362
328
  }
363
329
  };
364
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": "7.0.0",
3
+ "version": "7.1.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -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": "ava",
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
@@ -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 = (