Skip to content

Commit 7b342af

Browse files
authoredSep 3, 2019
feat: enable the parallel option by default (#131)
BREAKING CHANGE: the `parallel` option is `true` by default
1 parent 41a9fff commit 7b342af

10 files changed

+54
-15
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ module.exports = {
226226
### `parallel`
227227

228228
Type: `Boolean|Number`
229-
Default: `false`
229+
Default: `true`
230230

231231
Use multi-process parallel running to improve the build speed.
232232
Default number of concurrent runs: `os.cpus().length - 1`.

‎jest.config.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
testEnvironment: 'node',
3+
};

‎src/index.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/* eslint-disable
2-
no-param-reassign
3-
*/
41
import crypto from 'crypto';
52
import path from 'path';
63

@@ -34,7 +31,7 @@ class TerserPlugin {
3431
sourceMap = false,
3532
cache = false,
3633
cacheKeys = (defaultCacheKeys) => defaultCacheKeys,
37-
parallel = false,
34+
parallel = true,
3835
include,
3936
exclude,
4037
} = options;
@@ -160,6 +157,7 @@ class TerserPlugin {
160157
apply(compiler) {
161158
const buildModuleFn = (moduleArg) => {
162159
// to get detailed location info about errors
160+
// eslint-disable-next-line no-param-reassign
163161
moduleArg.useSourceMap = true;
164162
};
165163

@@ -356,19 +354,22 @@ class TerserPlugin {
356354
compilation.assets[commentsFile].add('\n');
357355
compilation.assets[commentsFile].add(commentsSource);
358356
} else {
357+
// eslint-disable-next-line no-param-reassign
359358
compilation.assets[commentsFile] = new ConcatSource(
360359
compilation.assets[commentsFile],
361360
'\n',
362361
commentsSource
363362
);
364363
}
365364
} else {
365+
// eslint-disable-next-line no-param-reassign
366366
compilation.assets[commentsFile] = commentsSource;
367367
}
368368
}
369369
}
370370

371371
// Updating assets
372+
// eslint-disable-next-line no-param-reassign
372373
processedAssets.add((compilation.assets[file] = outputSource));
373374

374375
// Handling warnings

‎src/minify.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
/* eslint-disable
2-
arrow-body-style
3-
*/
4-
import { minify as terserMinify } from 'terser';
1+
const { minify: terserMinify } = require('terser');
52

63
const buildTerserOptions = ({
74
ecma,
@@ -187,4 +184,4 @@ const minify = (options) => {
187184
return { error, map, code, warnings, extractedComments };
188185
};
189186

190-
export default minify;
187+
module.exports = minify;

‎src/worker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import minify from './minify';
1+
const minify = require('./minify');
22

33
module.exports = (options, callback) => {
44
try {

‎test/TerserPlugin.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ describe('TerserPlugin', () => {
2222
mappings: '',
2323
};
2424

25-
it('should works (without options)', async () => {
25+
it('should work (without options)', async () => {
2626
const compiler = createCompiler();
2727

2828
new TerserPlugin().apply(compiler);

‎test/__snapshots__/TerserPlugin.test.js.snap

+3-3
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ exports[`TerserPlugin should regenerate hash: errors 1`] = `Array []`;
8282

8383
exports[`TerserPlugin should regenerate hash: warnings 1`] = `Array []`;
8484

85-
exports[`TerserPlugin should works (without options): assets 1`] = `
85+
exports[`TerserPlugin should work (without options): assets 1`] = `
8686
Object {
8787
"main.js": "!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){\\"undefined\\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:\\"Module\\"}),Object.defineProperty(e,\\"__esModule\\",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&\\"object\\"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,\\"default\\",{enumerable:!0,value:e}),2&t&&\\"string\\"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,\\"a\\",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p=\\"\\",n(n.s=0)}([function(e,t){e.exports=function(){console.log(7)}}]);",
8888
}
8989
`;
9090

91-
exports[`TerserPlugin should works (without options): errors 1`] = `Array []`;
91+
exports[`TerserPlugin should work (without options): errors 1`] = `Array []`;
9292

93-
exports[`TerserPlugin should works (without options): warnings 1`] = `Array []`;
93+
exports[`TerserPlugin should work (without options): warnings 1`] = `Array []`;

‎test/__snapshots__/parallel-option.test.js.snap

+13
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,16 @@ Object {
3838
exports[`parallel option should match snapshot for the "true" value: errors 1`] = `Array []`;
3939

4040
exports[`parallel option should match snapshot for the "true" value: warnings 1`] = `Array []`;
41+
42+
exports[`parallel option should match snapshot when a value is not specify: assets 1`] = `
43+
Object {
44+
"four.js": "!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){\\"undefined\\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:\\"Module\\"}),Object.defineProperty(e,\\"__esModule\\",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&\\"object\\"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,\\"default\\",{enumerable:!0,value:e}),2&t&&\\"string\\"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,\\"a\\",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p=\\"\\",n(n.s=0)}([function(e,t){e.exports=function(){console.log(7)}}]);",
45+
"one.js": "!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){\\"undefined\\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:\\"Module\\"}),Object.defineProperty(e,\\"__esModule\\",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&\\"object\\"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,\\"default\\",{enumerable:!0,value:e}),2&t&&\\"string\\"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,\\"a\\",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p=\\"\\",n(n.s=0)}([function(e,t){e.exports=function(){console.log(7)}}]);",
46+
"three.js": "!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){\\"undefined\\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:\\"Module\\"}),Object.defineProperty(e,\\"__esModule\\",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&\\"object\\"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,\\"default\\",{enumerable:!0,value:e}),2&t&&\\"string\\"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,\\"a\\",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p=\\"\\",n(n.s=0)}([function(e,t){e.exports=function(){console.log(7)}}]);",
47+
"two.js": "!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){\\"undefined\\"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:\\"Module\\"}),Object.defineProperty(e,\\"__esModule\\",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&\\"object\\"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,\\"default\\",{enumerable:!0,value:e}),2&t&&\\"string\\"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,\\"a\\",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p=\\"\\",n(n.s=0)}([function(e,t){e.exports=function(){console.log(7)}}]);",
48+
}
49+
`;
50+
51+
exports[`parallel option should match snapshot when a value is not specify: errors 1`] = `Array []`;
52+
53+
exports[`parallel option should match snapshot when a value is not specify: warnings 1`] = `Array []`;

‎test/parallel-option.test.js

+24
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@ jest.mock('worker-farm', () => {
2727
require(worker)(data, callback)
2828
))
2929
);
30+
3031
mock.end = jest.fn();
32+
3133
return mock;
3234
});
3335

@@ -49,6 +51,28 @@ describe('parallel option', () => {
4951
});
5052
});
5153

54+
it('should match snapshot when a value is not specify', async () => {
55+
new TerserPlugin().apply(compiler);
56+
57+
const stats = await compile(compiler);
58+
59+
const errors = stats.compilation.errors.map(cleanErrorStack);
60+
const warnings = stats.compilation.warnings.map(cleanErrorStack);
61+
62+
expect(workerFarm.mock.calls.length).toBe(1);
63+
expect(workerFarm.mock.calls[0][0].maxConcurrentWorkers).toBe(
64+
os.cpus().length - 1
65+
);
66+
expect(workerFarmMock.mock.calls.length).toBe(
67+
Object.keys(stats.compilation.assets).length
68+
);
69+
expect(workerFarm.end.mock.calls.length).toBe(1);
70+
71+
expect(errors).toMatchSnapshot('errors');
72+
expect(warnings).toMatchSnapshot('warnings');
73+
expect(getAssets(stats, compiler)).toMatchSnapshot('assets');
74+
});
75+
5276
it('should match snapshot for the "false" value', async () => {
5377
new TerserPlugin({ parallel: false }).apply(compiler);
5478

‎test/terserOptions-option.test.js

+1
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,7 @@ describe('terserOptions option', () => {
581581
const compiler = createCompiler();
582582

583583
new TerserPlugin({
584+
parallel: false,
584585
terserOptions: {
585586
output: {
586587
unknown: true,

0 commit comments

Comments
 (0)
Failed to load comments.