Skip to content

Commit d3c6857

Browse files
committed
validate parallel config
1 parent 20cb23a commit d3c6857

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

packages/babel/src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ function createBabelInputPluginFactory(customCallback = returnObject) {
151151
typeof customFilter === 'function' ? customFilter : createFilter(include, exclude);
152152
const filter = (id, code) => extensionRegExp.test(id) && userDefinedFilter(id, code);
153153

154+
if (typeof parallel === 'number' && (!Number.isInteger(parallel) || parallel < 1)) {
155+
throw new Error(
156+
'The "parallel" option must be true or a positive integer specifying the number of workers.'
157+
);
158+
}
159+
154160
if (parallel) {
155161
const parallelAllowed =
156162
isSerializable(babelOptions) && !overrides?.config && !overrides?.result;

packages/babel/test/as-input-plugin.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,21 @@ test('works in parallel with specified worker count', async () => {
611611
expect(code.includes('var answer = 42')).toBe(true);
612612
});
613613

614+
test('throws when parallel option is not a positive integer', () => {
615+
expect(() => babelPlugin({ babelHelpers: 'bundled', parallel: 0 })).toThrow(
616+
/must be true or a positive integer/
617+
);
618+
expect(() => babelPlugin({ babelHelpers: 'bundled', parallel: -1 })).toThrow(
619+
/must be true or a positive integer/
620+
);
621+
expect(() => babelPlugin({ babelHelpers: 'bundled', parallel: 2.5 })).toThrow(
622+
/must be true or a positive integer/
623+
);
624+
expect(() => babelPlugin({ babelHelpers: 'bundled', parallel: NaN })).toThrow(
625+
/must be true or a positive integer/
626+
);
627+
});
628+
614629
test('throws when using parallel with non-serializable babel options', async () => {
615630
await expect(() =>
616631
generate('basic/main.js', {

0 commit comments

Comments
 (0)