Skip to content
This repository was archived by the owner on Apr 19, 2026. It is now read-only.

Commit 5021ef6

Browse files
committed
5.0.0
1 parent f6b1b4f commit 5021ef6

3 files changed

Lines changed: 24 additions & 14 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "worker-plugin",
3-
"version": "4.0.3",
3+
"version": "5.0.0",
44
"description": "Webpack plugin to bundle Workers automagically.",
55
"main": "dist/worker-plugin.js",
66
"repository": "GoogleChromeLabs/worker-plugin",

test/_util.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export function sleep (ms) {
2323
return new Promise(resolve => setTimeout(resolve, ms));
2424
}
2525

26+
/**
27+
* @param {string} fixture
28+
* @param {{ terserOptions?: import('terser').MinifyOptions } & Partial<import('webpack').Configuration>} [options]
29+
*/
2630
export function runWebpack (fixture, { output, plugins, terserOptions, ...config } = {}) {
2731
return run(callback => webpack({
2832
mode: 'production',
@@ -50,14 +54,20 @@ export function runWebpack (fixture, { output, plugins, terserOptions, ...config
5054
plugins: [
5155
new CleanPlugin([
5256
path.resolve(__dirname, 'fixtures', fixture, 'dist', '**')
53-
])
54-
].concat(plugins || []),
57+
], {}),
58+
...(Array.isArray(plugins) ? plugins : [])
59+
],
5560
...config
5661
}, callback));
5762
}
5863

64+
/**
65+
* @param {string} fixture
66+
* @param {Partial<import('webpack').Configuration & { terserOptions?: import('terser').MinifyOptions }>} [options]
67+
*/
5968
export function watchWebpack (fixture, { output, plugins, context, terserOptions, ...config } = {}) {
6069
context = context || path.resolve(__dirname, 'fixtures', fixture);
70+
/** @type {Partial<import('webpack').Compiler & { doRun(): Promise<import('webpack').Stats> }>} */
6171
const compiler = webpack({
6272
mode: 'production',
6373
context,

test/index.test.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ describe('worker-plugin', () => {
276276
const stats = await runWebpack('no-trailing-comma', {
277277
plugins: [
278278
new WorkerPlugin()
279-
],
279+
]
280280
});
281281

282282
const assetNames = Object.keys(stats.assets);
@@ -294,7 +294,7 @@ describe('worker-plugin', () => {
294294
expect(main).toMatch(/new Worker\s*\(__webpack__worker__\d, void 0\)/);
295295

296296
// Match `new Worker(__webpack__worker__0, { type: void 0, name: "foo" })`
297-
expect(main).toMatch(/new Worker\s*\(__webpack__worker__\d, {\s*type\: void 0,\s*name\: "foo"\s*}\)/);
297+
expect(main).toMatch(/new Worker\s*\(__webpack__worker__\d, {\s*type: void 0,\s*name: "foo"\s*}\)/);
298298
});
299299

300300
describe('worker-plugin/loader', () => {
@@ -335,17 +335,17 @@ describe('worker-plugin', () => {
335335
]
336336
});
337337

338+
/** @returns {Partial<Promise & { resolve(v): void, reject(e): void }>} */
338339
function Deferred () {
339-
let controller;
340-
const p = new Promise((resolve, reject) => {
341-
controller = { resolve, reject };
342-
});
343-
Object.assign(p, controller);
344-
return p;
340+
const controller = {};
341+
return Object.assign(new Promise((resolve, reject) => {
342+
controller.resolve = resolve;
343+
controller.reject = reject;
344+
}), controller);
345345
}
346346

347347
let stats;
348-
let ready = new Deferred();
348+
let ready = Deferred();
349349

350350
const watcher = compiler.watch({
351351
aggregateTimeout: 1,
@@ -358,7 +358,7 @@ describe('worker-plugin', () => {
358358

359359
try {
360360
for (let i = 1; i < 5; i++) {
361-
ready = new Deferred();
361+
ready = Deferred();
362362
writeFileSync(workerFile, workerCode.replace(/console\.log\('hello from worker( \d+)?'\)/, `console.log('hello from worker ${i}')`));
363363
await sleep(1000);
364364
stats = await ready;
@@ -367,7 +367,7 @@ describe('worker-plugin', () => {
367367
expect(stats.assets['0.worker.js']).toContain(`hello from worker ${i}`);
368368
}
369369
} finally {
370-
watcher.close();
370+
watcher.close(() => {});
371371
}
372372

373373
await sleep(1000);

0 commit comments

Comments
 (0)