From 5efa77a64d8fbce123b289461234ac3a8812fb54 Mon Sep 17 00:00:00 2001 From: Evilebot Tnawi Date: Wed, 5 Aug 2020 17:41:18 +0300 Subject: [PATCH 1/4] fix: interpolation `[name]` for the `filename` option (#277) * fix: interpolation `[name]` for the `filename` option --- src/index.js | 10 ++++++--- .../chunkFilename-option.test.js.snap | 4 ++-- .../filename-options.test.js.snap | 10 ++++----- test/__snapshots__/loader.test.js.snap | 13 +++++++++++ test/fixtures/name/TypeDetection.js | 7 ++++++ test/fixtures/name/entry.js | 22 +++++++++++++++++++ test/fixtures/name/index.html | 13 +++++++++++ test/helpers/getCompiler.js | 4 +--- test/loader.test.js | 15 +++++++++++++ 9 files changed, 85 insertions(+), 13 deletions(-) create mode 100644 test/fixtures/name/TypeDetection.js create mode 100644 test/fixtures/name/entry.js create mode 100644 test/fixtures/name/index.html diff --git a/src/index.js b/src/index.js index 0429fc3..d7cb59a 100644 --- a/src/index.js +++ b/src/index.js @@ -1,3 +1,5 @@ +import path from 'path'; + import { getOptions } from 'loader-utils'; import validateOptions from 'schema-utils'; @@ -99,9 +101,11 @@ export function pitch(request) { ).apply(workerContext.compiler); } - new SingleEntryPlugin(this.context, `!!${request}`, 'main').apply( - workerContext.compiler - ); + new SingleEntryPlugin( + this.context, + `!!${request}`, + path.parse(this.resourcePath).name + ).apply(workerContext.compiler); workerContext.request = request; diff --git a/test/__snapshots__/chunkFilename-option.test.js.snap b/test/__snapshots__/chunkFilename-option.test.js.snap index fdbdf0c..577fecc 100644 --- a/test/__snapshots__/chunkFilename-option.test.js.snap +++ b/test/__snapshots__/chunkFilename-option.test.js.snap @@ -17,7 +17,7 @@ exports[`"name" option should work and respect the "output.chunkFilename" defaul exports[`"name" option should work and respect the "output.chunkFilename" default value option: module 1`] = ` "export default function() { - return new Worker(__webpack_public_path__ + \\"main.worker.js\\"); + return new Worker(__webpack_public_path__ + \\"worker.worker.js\\"); } " `; @@ -30,7 +30,7 @@ exports[`"name" option should work and respect the "output.chunkFilename" option exports[`"name" option should work and respect the "output.chunkFilename" option ("string"): module 1`] = ` "export default function() { - return new Worker(__webpack_public_path__ + \\"main.worker.js\\"); + return new Worker(__webpack_public_path__ + \\"worker.worker.js\\"); } " `; diff --git a/test/__snapshots__/filename-options.test.js.snap b/test/__snapshots__/filename-options.test.js.snap index cc533c1..beb0124 100644 --- a/test/__snapshots__/filename-options.test.js.snap +++ b/test/__snapshots__/filename-options.test.js.snap @@ -4,7 +4,7 @@ exports[`"filename" option should work ("function"): errors 1`] = `Array []`; exports[`"filename" option should work ("function"): module 1`] = ` "export default function() { - return new Worker(__webpack_public_path__ + \\"main.custom.worker.js\\"); + return new Worker(__webpack_public_path__ + \\"worker.custom.worker.js\\"); } " `; @@ -17,7 +17,7 @@ exports[`"filename" option should work ("string"): errors 1`] = `Array []`; exports[`"filename" option should work ("string"): module 1`] = ` "export default function() { - return new Worker(__webpack_public_path__ + \\"main.custom.worker.js\\"); + return new Worker(__webpack_public_path__ + \\"worker.custom.worker.js\\"); } " `; @@ -30,7 +30,7 @@ exports[`"filename" option should work and respect the "output.filename" default exports[`"filename" option should work and respect the "output.filename" default value option: module 1`] = ` "export default function() { - return new Worker(__webpack_public_path__ + \\"main.worker.js\\"); + return new Worker(__webpack_public_path__ + \\"worker.worker.js\\"); } " `; @@ -43,7 +43,7 @@ exports[`"filename" option should work and respect the "output.filename" option exports[`"filename" option should work and respect the "output.filename" option ("function"): module 1`] = ` "export default function() { - return new Worker(__webpack_public_path__ + \\"main.custom.worker.js\\"); + return new Worker(__webpack_public_path__ + \\"worker.custom.worker.js\\"); } " `; @@ -56,7 +56,7 @@ exports[`"filename" option should work and respect the "output.filename" option exports[`"filename" option should work and respect the "output.filename" option ("string"): module 1`] = ` "export default function() { - return new Worker(__webpack_public_path__ + \\"main.custom.worker.js\\"); + return new Worker(__webpack_public_path__ + \\"worker.custom.worker.js\\"); } " `; diff --git a/test/__snapshots__/loader.test.js.snap b/test/__snapshots__/loader.test.js.snap index 044d170..a0338ad 100644 --- a/test/__snapshots__/loader.test.js.snap +++ b/test/__snapshots__/loader.test.js.snap @@ -1,5 +1,18 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`worker-loader should work and have the same base file name as the source files: errors 1`] = `Array []`; + +exports[`worker-loader should work and have the same base file name as the source files: module 1`] = ` +"export default function() { + return new Worker(__webpack_public_path__ + \\"TypeDetection.worker.js\\"); +} +" +`; + +exports[`worker-loader should work and have the same base file name as the source files: result 1`] = `"{\\"postMessage\\":true,\\"onmessage\\":true}"`; + +exports[`worker-loader should work and have the same base file name as the source files: warnings 1`] = `Array []`; + exports[`worker-loader should work and respect the "devtool" option ("false" value): errors 1`] = `Array []`; exports[`worker-loader should work and respect the "devtool" option ("false" value): module 1`] = ` diff --git a/test/fixtures/name/TypeDetection.js b/test/fixtures/name/TypeDetection.js new file mode 100644 index 0000000..8d67d1d --- /dev/null +++ b/test/fixtures/name/TypeDetection.js @@ -0,0 +1,7 @@ +onmessage = function(event) { + const workerResult = event.data; + + workerResult.onmessage = true; + + postMessage(workerResult); +}; diff --git a/test/fixtures/name/entry.js b/test/fixtures/name/entry.js new file mode 100644 index 0000000..aad9b1a --- /dev/null +++ b/test/fixtures/name/entry.js @@ -0,0 +1,22 @@ +import Worker from './TypeDetection.js'; + +const worker = new Worker(); + +let result; + +worker.onmessage = function (event) { + if (!result) { + result = document.createElement("div"); + result.setAttribute('id', 'result'); + + document.body.append(result); + } + + result.innerText = JSON.stringify(event.data) +}; + +const button = document.getElementById('button'); + +button.addEventListener('click', () => { + worker.postMessage({ postMessage: true }) +}); diff --git a/test/fixtures/name/index.html b/test/fixtures/name/index.html new file mode 100644 index 0000000..786cafc --- /dev/null +++ b/test/fixtures/name/index.html @@ -0,0 +1,13 @@ + + + + + Webpack App + + + + + + + + diff --git a/test/helpers/getCompiler.js b/test/helpers/getCompiler.js index d4dde22..8810b19 100644 --- a/test/helpers/getCompiler.js +++ b/test/helpers/getCompiler.js @@ -20,7 +20,7 @@ export default (fixture, loaderOptions = {}, config = {}) => { module: { rules: [ { - test: /worker\.js$/i, + test: /(worker|TypeDetection)\.js$/i, rules: [ { loader: path.resolve(__dirname, '../../src'), @@ -48,8 +48,6 @@ export default (fixture, loaderOptions = {}, config = {}) => { fullConfig.experiments = {}; } - fullConfig.experiments.importAsync = true; - fullConfig.experiments.importAwait = true; fullConfig.experiments.asyncWebAssembly = true; } diff --git a/test/loader.test.js b/test/loader.test.js index 9636ea2..6e4cc70 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -113,4 +113,19 @@ describe('worker-loader', () => { expect(getWarnings(stats)).toMatchSnapshot('warnings'); expect(getErrors(stats)).toMatchSnapshot('errors'); }); + + it('should work and have the same base file name as the source files', async () => { + const compiler = getCompiler('./name/entry.js', { + filename: '[name].worker.js', + }); + const stats = await compile(compiler); + const result = await getResultFromBrowser(stats); + + expect(getModuleSource('./name/TypeDetection.js', stats)).toMatchSnapshot( + 'module' + ); + expect(result).toMatchSnapshot('result'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); }); From 9ed9e421fc84a2594b60cc1cf22da41cf66ca2f3 Mon Sep 17 00:00:00 2001 From: Evilebot Tnawi Date: Wed, 5 Aug 2020 18:02:42 +0300 Subject: [PATCH 2/4] test: resolve todo (#278) --- test/__snapshots__/inline-option.test.js.snap | 6 + test/__snapshots__/loader.test.js.snap | 13 +++ test/__snapshots__/publicPath.test.js.snap | 26 +++++ test/inline-option.test.js | 41 ++++--- test/loader.test.js | 35 +++--- test/publicPath.test.js | 108 +++++++++--------- 6 files changed, 135 insertions(+), 94 deletions(-) diff --git a/test/__snapshots__/inline-option.test.js.snap b/test/__snapshots__/inline-option.test.js.snap index 7aeb673..9af5142 100644 --- a/test/__snapshots__/inline-option.test.js.snap +++ b/test/__snapshots__/inline-option.test.js.snap @@ -27,10 +27,16 @@ exports[`"inline" option should work with "fallback" value and "esModule" with " exports[`"inline" option should work with "fallback" value and the "devtool" option ("source-map" value): errors 1`] = `Array []`; +exports[`"inline" option should work with "fallback" value and the "devtool" option ("source-map" value): errors 2`] = `Array []`; + exports[`"inline" option should work with "fallback" value and the "devtool" option ("source-map" value): result 1`] = `"{\\"postMessage\\":true,\\"onmessage\\":true}"`; +exports[`"inline" option should work with "fallback" value and the "devtool" option ("source-map" value): result 2`] = `"{\\"postMessage\\":true,\\"onmessage\\":true}"`; + exports[`"inline" option should work with "fallback" value and the "devtool" option ("source-map" value): warnings 1`] = `Array []`; +exports[`"inline" option should work with "fallback" value and the "devtool" option ("source-map" value): warnings 2`] = `Array []`; + exports[`"inline" option should work with "fallback" value: errors 1`] = `Array []`; exports[`"inline" option should work with "fallback" value: result 1`] = `"{\\"postMessage\\":true,\\"onmessage\\":true}"`; diff --git a/test/__snapshots__/loader.test.js.snap b/test/__snapshots__/loader.test.js.snap index a0338ad..0a7eea0 100644 --- a/test/__snapshots__/loader.test.js.snap +++ b/test/__snapshots__/loader.test.js.snap @@ -26,6 +26,19 @@ exports[`worker-loader should work and respect the "devtool" option ("false" val exports[`worker-loader should work and respect the "devtool" option ("false" value): warnings 1`] = `Array []`; +exports[`worker-loader should work and respect the "devtool" option ("source-map" value): errors 1`] = `Array []`; + +exports[`worker-loader should work and respect the "devtool" option ("source-map" value): module 1`] = ` +"export default function() { + return new Worker(__webpack_public_path__ + \\"test.worker.js\\"); +} +" +`; + +exports[`worker-loader should work and respect the "devtool" option ("source-map" value): result 1`] = `"{\\"postMessage\\":true,\\"onmessage\\":true}"`; + +exports[`worker-loader should work and respect the "devtool" option ("source-map" value): warnings 1`] = `Array []`; + exports[`worker-loader should work with "externals": errors 1`] = `Array []`; exports[`worker-loader should work with "externals": module 1`] = ` diff --git a/test/__snapshots__/publicPath.test.js.snap b/test/__snapshots__/publicPath.test.js.snap index 3011711..c17f4ab 100644 --- a/test/__snapshots__/publicPath.test.js.snap +++ b/test/__snapshots__/publicPath.test.js.snap @@ -1,5 +1,31 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`"publicPath" option should work and respect "filename" and "chunkFilename" option values: errors 1`] = `Array []`; + +exports[`"publicPath" option should work and respect "filename" and "chunkFilename" option values: errors 2`] = `Array []`; + +exports[`"publicPath" option should work and respect "filename" and "chunkFilename" option values: module 1`] = ` +"export default function() { + return new Worker(__webpack_public_path__ + \\"other-static/js/worker.bundle.worker.js\\"); +} +" +`; + +exports[`"publicPath" option should work and respect "filename" and "chunkFilename" option values: module 2`] = ` +"export default function() { + return new Worker(__webpack_public_path__ + \\"other-static/js/worker.worker.js\\"); +} +" +`; + +exports[`"publicPath" option should work and respect "filename" and "chunkFilename" option values: result 1`] = `"{\\"postMessage\\":true,\\"onmessage\\":true}"`; + +exports[`"publicPath" option should work and respect "filename" and "chunkFilename" option values: result 2`] = `"{\\"postMessage\\":true,\\"onmessage\\":true}"`; + +exports[`"publicPath" option should work and respect "filename" and "chunkFilename" option values: warnings 1`] = `Array []`; + +exports[`"publicPath" option should work and respect "filename" and "chunkFilename" option values: warnings 2`] = `Array []`; + exports[`"publicPath" option should work and respect the "output.publicPath" option default value: errors 1`] = `Array []`; exports[`"publicPath" option should work and respect the "output.publicPath" option default value: module 1`] = ` diff --git a/test/inline-option.test.js b/test/inline-option.test.js index ecaeb16..763303a 100644 --- a/test/inline-option.test.js +++ b/test/inline-option.test.js @@ -99,27 +99,26 @@ describe('"inline" option', () => { expect(getErrors(stats)).toMatchSnapshot('errors'); }); - // TODO broken on webpack@5 - // it.skip('should work with "fallback" value and the "devtool" option ("source-map" value)', async () => { - // const compiler = getCompiler( - // './basic/entry.js', - // { inline: 'fallback' }, - // { devtool: 'source-map' } - // ); - // const stats = await compile(compiler); - // const result = await getResultFromBrowser(stats); - // const moduleSource = getModuleSource('./basic/worker.js', stats); - // - // expect(moduleSource.indexOf('inline.js') > 0).toBe(true); - // expect( - // moduleSource.indexOf('__webpack_public_path__ + "test.worker.js"') > 0 - // ).toBe(true); - // expect(stats.compilation.assets['test.worker.js']).toBeDefined(); - // expect(stats.compilation.assets['test.worker.js.map']).toBeDefined(); - // expect(result).toMatchSnapshot('result'); - // expect(getWarnings(stats)).toMatchSnapshot('warnings'); - // expect(getErrors(stats)).toMatchSnapshot('errors'); - // }); + it('should work with "fallback" value and the "devtool" option ("source-map" value)', async () => { + const compiler = getCompiler( + './basic/entry.js', + { inline: 'fallback' }, + { devtool: 'source-map' } + ); + const stats = await compile(compiler); + const result = await getResultFromBrowser(stats); + const moduleSource = getModuleSource('./basic/worker.js', stats); + + expect(moduleSource.indexOf('inline.js') > 0).toBe(true); + expect( + moduleSource.indexOf('__webpack_public_path__ + "test.worker.js"') > 0 + ).toBe(true); + expect(stats.compilation.assets['test.worker.js']).toBeDefined(); + expect(stats.compilation.assets['test.worker.js.map']).toBeDefined(); + expect(result).toMatchSnapshot('result'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); it('should work with "fallback" value and the "devtool" option ("source-map" value)', async () => { const compiler = getCompiler( diff --git a/test/loader.test.js b/test/loader.test.js index 6e4cc70..b9efb8b 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -81,24 +81,23 @@ describe('worker-loader', () => { expect(getErrors(stats)).toMatchSnapshot('errors'); }); - // TODO broken on webpack@5 - // it.skip('should work and respect the "devtool" option ("source-map" value)', async () => { - // const compiler = getCompiler( - // './basic/entry.js', - // {}, - // { devtool: 'source-map' } - // ); - // const stats = await compile(compiler); - // const result = await getResultFromBrowser(stats); - // - // expect(getModuleSource('./basic/worker.js', stats)).toMatchSnapshot( - // 'module' - // ); - // expect(stats.compilation.assets['test.worker.js.map']).toBeDefined(); - // expect(result).toMatchSnapshot('result'); - // expect(getWarnings(stats)).toMatchSnapshot('warnings'); - // expect(getErrors(stats)).toMatchSnapshot('errors'); - // }); + it('should work and respect the "devtool" option ("source-map" value)', async () => { + const compiler = getCompiler( + './basic/entry.js', + {}, + { devtool: 'source-map' } + ); + const stats = await compile(compiler); + const result = await getResultFromBrowser(stats); + + expect(getModuleSource('./basic/worker.js', stats)).toMatchSnapshot( + 'module' + ); + expect(stats.compilation.assets['test.worker.js.map']).toBeDefined(); + expect(result).toMatchSnapshot('result'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); it('should work and respect the "devtool" option ("false" value)', async () => { const compiler = getCompiler('./basic/entry.js', {}, { devtool: false }); diff --git a/test/publicPath.test.js b/test/publicPath.test.js index 2e52c9e..b8e78a3 100644 --- a/test/publicPath.test.js +++ b/test/publicPath.test.js @@ -131,59 +131,57 @@ describe('"publicPath" option', () => { expect(getErrors(stats)).toMatchSnapshot('errors'); }); - // TODO broken on webpack@5 - // it('should work and respect "filename" and "chunkFilename" option values', async () => { - // const nanoid = customAlphabet('1234567890abcdef', 10); - // const compiler = getCompiler( - // './chunks/entry.js', - // {}, - // { - // module: { - // rules: [ - // { - // test: /worker\.js$/i, - // rules: [ - // { - // loader: path.resolve(__dirname, './../src'), - // }, - // ], - // }, - // ], - // }, - // output: { - // publicPath: '/public-path-static-other/', - // path: path.resolve(__dirname, './outputs', `test_${nanoid()}`), - // filename: 'other-static/js/[name].bundle.js', - // chunkFilename: 'other-static/js/[name].chunk.js', - // }, - // } - // ); - // const stats = await compile(compiler); - // const result = await getResultFromBrowser(stats); - // - // expect(getModuleSource('./chunks/worker.js', stats)).toMatchSnapshot( - // 'module' - // ); - // expect(result).toMatchSnapshot('result'); - // expect(getWarnings(stats)).toMatchSnapshot('warnings'); - // expect(getErrors(stats)).toMatchSnapshot('errors'); - // }); - - // TODO broken on webpack@5 - // it('should work and respect "filename" and "chunkFilename" option values', async () => { - // const compiler = getCompiler('./chunks/entry.js', { - // publicPath: '/public-path-static-other/', - // filename: 'other-static/js/[name].worker.js', - // chunkFilename: 'other-static/js/[name].chunk.worker.js', - // }); - // const stats = await compile(compiler); - // const result = await getResultFromBrowser(stats); - // - // expect(getModuleSource('./chunks/worker.js', stats)).toMatchSnapshot( - // 'module' - // ); - // expect(result).toMatchSnapshot('result'); - // expect(getWarnings(stats)).toMatchSnapshot('warnings'); - // expect(getErrors(stats)).toMatchSnapshot('errors'); - // }); + it('should work and respect "filename" and "chunkFilename" option values', async () => { + const nanoid = customAlphabet('1234567890abcdef', 10); + const compiler = getCompiler( + './chunks/entry.js', + {}, + { + module: { + rules: [ + { + test: /worker\.js$/i, + rules: [ + { + loader: path.resolve(__dirname, './../src'), + }, + ], + }, + ], + }, + output: { + publicPath: '/public-path-static-other/', + path: path.resolve(__dirname, './outputs', `test_${nanoid()}`), + filename: 'other-static/js/[name].bundle.js', + chunkFilename: 'other-static/js/[name].chunk.js', + }, + } + ); + const stats = await compile(compiler); + const result = await getResultFromBrowser(stats); + + expect(getModuleSource('./chunks/worker.js', stats)).toMatchSnapshot( + 'module' + ); + expect(result).toMatchSnapshot('result'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should work and respect "filename" and "chunkFilename" option values', async () => { + const compiler = getCompiler('./chunks/entry.js', { + publicPath: '/public-path-static-other/', + filename: 'other-static/js/[name].worker.js', + chunkFilename: 'other-static/js/[name].chunk.worker.js', + }); + const stats = await compile(compiler); + const result = await getResultFromBrowser(stats); + + expect(getModuleSource('./chunks/worker.js', stats)).toMatchSnapshot( + 'module' + ); + expect(result).toMatchSnapshot('result'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); }); From ee519b1d283dbb599385fe2932c99c929b09db36 Mon Sep 17 00:00:00 2001 From: Evilebot Tnawi Date: Wed, 5 Aug 2020 19:12:36 +0300 Subject: [PATCH 3/4] fix: compatibility with webpack@5 cache (#279) --- src/supportWebpack4.js | 6 ++- src/supportWebpack5.js | 103 +++++++++++++++++++---------------------- 2 files changed, 53 insertions(+), 56 deletions(-) diff --git a/src/supportWebpack4.js b/src/supportWebpack4.js index cbdd762..fec90d4 100644 --- a/src/supportWebpack4.js +++ b/src/supportWebpack4.js @@ -42,6 +42,10 @@ export default function runAsChild( return callback(null, workerCode); } - return callback(null, null); + return callback( + new Error( + `Failed to compile web worker "${workerContext.request}" request` + ) + ); }); } diff --git a/src/supportWebpack5.js b/src/supportWebpack5.js index 9d9164a..6c6f910 100644 --- a/src/supportWebpack5.js +++ b/src/supportWebpack5.js @@ -1,5 +1,3 @@ -import { stringifyRequest } from 'loader-utils'; - import { workerGenerator, sourceMappingURLRegex } from './utils'; export default function runAsChild( @@ -8,9 +6,6 @@ export default function runAsChild( options, callback ) { - // eslint-disable-next-line import/no-unresolved, global-require - const getLazyHashedEtag = require('webpack/lib/cache/getLazyHashedEtag'); - workerContext.compiler.runAsChild((error, entries, compilation) => { if (error) { return callback(error); @@ -18,68 +13,66 @@ export default function runAsChild( if (entries[0]) { const [workerFilename] = [...entries[0].files]; - const requestIdent = stringifyRequest( - { context: loaderContext.rootContext }, - workerContext.request + const cache = workerContext.compiler.getCache('worker-loader'); + const cacheIdent = workerFilename; + const cacheETag = cache.getLazyHashedEtag( + compilation.assets[workerFilename] ); - const cacheIdent = `${workerContext.compiler.compilerPath}/worker-loader|${requestIdent}`; - const cacheETag = getLazyHashedEtag(compilation.assets[workerFilename]); - // TODO not working, need fix on webpack@5 side - return workerContext.compiler.cache.get( - cacheIdent, - cacheETag, - (getCacheError, content) => { - if (getCacheError) { - return callback(getCacheError); - } - - if (options.inline === 'no-fallback') { - // eslint-disable-next-line no-underscore-dangle, no-param-reassign - delete loaderContext._compilation.assets[workerFilename]; + return cache.get(cacheIdent, cacheETag, (getCacheError, content) => { + if (getCacheError) { + return callback(getCacheError); + } - // TODO improve this, we should store generated source maps files for file in `assetInfo` - // eslint-disable-next-line no-underscore-dangle - if (loaderContext._compilation.assets[`${workerFilename}.map`]) { - // eslint-disable-next-line no-underscore-dangle, no-param-reassign - delete loaderContext._compilation.assets[`${workerFilename}.map`]; - } - } + if (options.inline === 'no-fallback') { + // eslint-disable-next-line no-underscore-dangle, no-param-reassign + delete loaderContext._compilation.assets[workerFilename]; - if (content) { - return callback(null, content); + // TODO improve this, we should store generated source maps files for file in `assetInfo` + // eslint-disable-next-line no-underscore-dangle + if (loaderContext._compilation.assets[`${workerFilename}.map`]) { + // eslint-disable-next-line no-underscore-dangle, no-param-reassign + delete loaderContext._compilation.assets[`${workerFilename}.map`]; } + } - let workerSource = compilation.assets[workerFilename].source(); + if (content) { + return callback(null, content); + } - if (options.inline === 'no-fallback') { - // Remove `/* sourceMappingURL=url */` comment - workerSource = workerSource.replace(sourceMappingURLRegex, ''); - } + let workerSource = compilation.assets[workerFilename].source(); - const workerCode = workerGenerator( - loaderContext, - workerFilename, - workerSource, - options - ); + if (options.inline === 'no-fallback') { + // Remove `/* sourceMappingURL=url */` comment + workerSource = workerSource.replace(sourceMappingURLRegex, ''); + } - return workerContext.compiler.cache.store( - cacheIdent, - cacheETag, - workerCode, - (storeCacheError) => { - if (storeCacheError) { - return callback(storeCacheError); - } + const workerCode = workerGenerator( + loaderContext, + workerFilename, + workerSource, + options + ); - return callback(null, workerCode); + return cache.store( + cacheIdent, + cacheETag, + workerCode, + (storeCacheError) => { + if (storeCacheError) { + return callback(storeCacheError); } - ); - } - ); + + return callback(null, workerCode); + } + ); + }); } - return callback(null, null); + return callback( + new Error( + `Failed to compile web worker "${workerContext.request}" request` + ) + ); }); } From ec8cb5f8f553f54b916677789141e95218841200 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Wed, 5 Aug 2020 19:38:25 +0300 Subject: [PATCH 4/4] chore(release): 3.0.1 --- CHANGELOG.md | 8 ++++++++ package-lock.json | 2 +- package.json | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b54811..dbd3e52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. +### [3.0.1](https://github.com/webpack-contrib/worker-loader/compare/v3.0.0...v3.0.1) (2020-08-05) + + +### Bug Fixes + +* compatibility with webpack@5 cache ([#279](https://github.com/webpack-contrib/worker-loader/issues/279)) ([ee519b1](https://github.com/webpack-contrib/worker-loader/commit/ee519b1d283dbb599385fe2932c99c929b09db36)) +* interpolation `[name]` for the `filename` option ([#277](https://github.com/webpack-contrib/worker-loader/issues/277)) ([5efa77a](https://github.com/webpack-contrib/worker-loader/commit/5efa77a64d8fbce123b289461234ac3a8812fb54)) + ## [3.0.0](https://github.com/webpack-contrib/worker-loader/compare/v2.0.0...v3.0.0) (2020-08-01) diff --git a/package-lock.json b/package-lock.json index 23af9d8..7845c57 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "worker-loader", - "version": "3.0.0", + "version": "3.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 4b20dde..1666d9f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "worker-loader", - "version": "3.0.0", + "version": "3.0.1", "description": "worker loader module for webpack", "license": "MIT", "repository": "webpack-contrib/worker-loader", pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy