Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

Commit

Permalink
fix: hash is not idempotent with different os or webpack or node vers…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
ramasilveyra committed Nov 16, 2020
1 parent 6a64b56 commit 9d8ad01
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 38 deletions.
8 changes: 2 additions & 6 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { stringifyRequest, interpolateName } from 'loader-utils';
import { stringifyRequest } from 'loader-utils';
import camelcase from 'lodash.camelcase';

function getDefaultFilename(filename) {
Expand Down Expand Up @@ -49,11 +49,7 @@ function workerGenerator(loaderContext, workerFilename, workerSource, options) {

const esModule =
typeof options.esModule !== 'undefined' ? options.esModule : true;
const fnName = interpolateName(
loaderContext,
`${camelcase(workerFilename)}Worker[hash:7]`,
{ content: workerSource }
);
const fnName = `${camelcase(workerFilename)}Worker`;

if (options.inline) {
const InlineWorkerPath = stringifyRequest(
Expand Down
8 changes: 4 additions & 4 deletions test/__snapshots__/chunkFilename-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`"name" option should chunkFilename suffix be inserted before query parameters: errors 1`] = `Array []`;

exports[`"name" option should chunkFilename suffix be inserted before query parameters: module 1`] = `
"export default function workerWorkerJsWorkere97b0d2() {
"export default function workerWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"worker.worker.js\\");
}
"
Expand All @@ -18,7 +18,7 @@ exports[`"name" option should chunkFilename suffix be inserted before query para
exports[`"name" option should work ("string"): errors 1`] = `Array []`;

exports[`"name" option should work ("string"): module 1`] = `
"export default function testWorkerJsWorker5182e60() {
"export default function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
}
"
Expand All @@ -31,7 +31,7 @@ exports[`"name" option should work ("string"): warnings 1`] = `Array []`;
exports[`"name" option should work and respect the "output.chunkFilename" default value option: errors 1`] = `Array []`;

exports[`"name" option should work and respect the "output.chunkFilename" default value option: module 1`] = `
"export default function workerWorkerJsWorker8de1ef2() {
"export default function workerWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"worker.worker.js\\");
}
"
Expand All @@ -44,7 +44,7 @@ exports[`"name" option should work and respect the "output.chunkFilename" defaul
exports[`"name" option should work and respect the "output.chunkFilename" option ("string"): errors 1`] = `Array []`;

exports[`"name" option should work and respect the "output.chunkFilename" option ("string"): module 1`] = `
"export default function workerWorkerJsWorker8250cd8() {
"export default function workerWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"worker.worker.js\\");
}
"
Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/esModule-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`"esModule" option should work and generate ES module syntax by default: errors 1`] = `Array []`;

exports[`"esModule" option should work and generate ES module syntax by default: module 1`] = `
"export default function testWorkerJsWorker78b84b4() {
"export default function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
}
"
Expand All @@ -14,7 +14,7 @@ exports[`"esModule" option should work and generate ES module syntax by default:
exports[`"esModule" option should work with "false" value: errors 1`] = `Array []`;

exports[`"esModule" option should work with "false" value: module 1`] = `
"module.exports = function testWorkerJsWorker78b84b4() {
"module.exports = function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
}
"
Expand All @@ -27,7 +27,7 @@ exports[`"esModule" option should work with "false" value: warnings 1`] = `Array
exports[`"esModule" option should work with "true" value: errors 1`] = `Array []`;

exports[`"esModule" option should work with "true" value: module 1`] = `
"export default function testWorkerJsWorker78b84b4() {
"export default function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
}
"
Expand Down
10 changes: 5 additions & 5 deletions test/__snapshots__/filename-options.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`"filename" option should work ("function"): errors 1`] = `Array []`;

exports[`"filename" option should work ("function"): module 1`] = `
"export default function workerCustomWorkerJsWorker8250cd8() {
"export default function workerCustomWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"worker.custom.worker.js\\");
}
"
Expand All @@ -16,7 +16,7 @@ exports[`"filename" option should work ("function"): warnings 1`] = `Array []`;
exports[`"filename" option should work ("string"): errors 1`] = `Array []`;

exports[`"filename" option should work ("string"): module 1`] = `
"export default function workerCustomWorkerJsWorker8250cd8() {
"export default function workerCustomWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"worker.custom.worker.js\\");
}
"
Expand All @@ -29,7 +29,7 @@ exports[`"filename" option should work ("string"): warnings 1`] = `Array []`;
exports[`"filename" option should work and respect the "output.filename" default value option: errors 1`] = `Array []`;

exports[`"filename" option should work and respect the "output.filename" default value option: module 1`] = `
"export default function workerWorkerJsWorker8250cd8() {
"export default function workerWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"worker.worker.js\\");
}
"
Expand All @@ -42,7 +42,7 @@ exports[`"filename" option should work and respect the "output.filename" default
exports[`"filename" option should work and respect the "output.filename" option ("function"): errors 1`] = `Array []`;

exports[`"filename" option should work and respect the "output.filename" option ("function"): module 1`] = `
"export default function workerCustomWorkerJsWorker225d46c() {
"export default function workerCustomWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"worker.custom.worker.js\\");
}
"
Expand All @@ -55,7 +55,7 @@ exports[`"filename" option should work and respect the "output.filename" option
exports[`"filename" option should work and respect the "output.filename" option ("string"): errors 1`] = `Array []`;

exports[`"filename" option should work and respect the "output.filename" option ("string"): module 1`] = `
"export default function workerCustomWorkerJsWorker8250cd8() {
"export default function workerCustomWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"worker.custom.worker.js\\");
}
"
Expand Down
2 changes: 1 addition & 1 deletion test/__snapshots__/inline-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`"inline" option should not work by default: errors 1`] = `Array []`;

exports[`"inline" option should not work by default: module 1`] = `
"export default function testWorkerJsWorker78b84b4() {
"export default function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
}
"
Expand Down
16 changes: 8 additions & 8 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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 typeDetectionWorkerJsWorker3d6ec69() {
"export default function typeDetectionWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"TypeDetection.worker.js\\");
}
"
Expand All @@ -16,7 +16,7 @@ exports[`worker-loader should work and have the same base file name as the sourc
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`] = `
"export default function testWorkerJsWorker78b84b4() {
"export default function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
}
"
Expand All @@ -29,7 +29,7 @@ exports[`worker-loader should work and respect the "devtool" option ("false" val
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 testWorkerJsWorker409f1ae() {
"export default function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
}
"
Expand All @@ -42,7 +42,7 @@ exports[`worker-loader should work and respect the "devtool" option ("source-map
exports[`worker-loader should work with "externals": errors 1`] = `Array []`;

exports[`worker-loader should work with "externals": module 1`] = `
"export default function testWorkerJsWorker0ad18cc() {
"export default function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
}
"
Expand All @@ -55,7 +55,7 @@ exports[`worker-loader should work with "externals": warnings 1`] = `Array []`;
exports[`worker-loader should work with WASM: errors 1`] = `Array []`;

exports[`worker-loader should work with WASM: module 1`] = `
"export default function testWorkerJsWorker9b7b307() {
"export default function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
}
"
Expand All @@ -68,7 +68,7 @@ exports[`worker-loader should work with WASM: warnings 1`] = `Array []`;
exports[`worker-loader should work with async chunks: errors 1`] = `Array []`;

exports[`worker-loader should work with async chunks: module 1`] = `
"export default function testWorkerJsWorker8250cd8() {
"export default function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
}
"
Expand All @@ -81,7 +81,7 @@ exports[`worker-loader should work with async chunks: warnings 1`] = `Array []`;
exports[`worker-loader should work with inline syntax: errors 1`] = `Array []`;

exports[`worker-loader should work with inline syntax: module 1`] = `
"export default function testWorkerJsWorker348cb02() {
"export default function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
}
"
Expand All @@ -94,7 +94,7 @@ exports[`worker-loader should work with inline syntax: warnings 1`] = `Array []`
exports[`worker-loader should work: errors 1`] = `Array []`;

exports[`worker-loader should work: module 1`] = `
"export default function testWorkerJsWorker78b84b4() {
"export default function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
}
"
Expand Down
16 changes: 8 additions & 8 deletions test/__snapshots__/publicPath.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ exports[`"publicPath" option should work and respect "filename" and "chunkFilena
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 otherStaticJsWorkerBundleWorkerJsWorker57f1fc8() {
"export default function otherStaticJsWorkerBundleWorkerJsWorker() {
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 otherStaticJsWorkerWorkerJsWorker57f1fc8() {
"export default function otherStaticJsWorkerWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"other-static/js/worker.worker.js\\");
}
"
Expand All @@ -29,7 +29,7 @@ exports[`"publicPath" option should work and respect "filename" and "chunkFilena
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`] = `
"export default function testWorkerJsWorker8250cd8() {
"export default function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
}
"
Expand All @@ -42,7 +42,7 @@ exports[`"publicPath" option should work and respect the "output.publicPath" opt
exports[`"publicPath" option should work and respect the "output.publicPath" option value ("function"): errors 1`] = `Array []`;

exports[`"publicPath" option should work and respect the "output.publicPath" option value ("function"): module 1`] = `
"export default function testWorkerJsWorkerb7c903a() {
"export default function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
}
"
Expand All @@ -55,7 +55,7 @@ exports[`"publicPath" option should work and respect the "output.publicPath" opt
exports[`"publicPath" option should work and respect the "output.publicPath" option value ("string"): errors 1`] = `Array []`;

exports[`"publicPath" option should work and respect the "output.publicPath" option value ("string"): module 1`] = `
"export default function testWorkerJsWorkerb7c903a() {
"export default function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
}
"
Expand All @@ -68,7 +68,7 @@ exports[`"publicPath" option should work and respect the "output.publicPath" opt
exports[`"publicPath" option should work and respect the "publicPath" option ("function"): errors 1`] = `Array []`;

exports[`"publicPath" option should work and respect the "publicPath" option ("function"): module 1`] = `
"export default function testWorkerJsWorkerb7c903a() {
"export default function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
}
"
Expand All @@ -81,7 +81,7 @@ exports[`"publicPath" option should work and respect the "publicPath" option ("f
exports[`"publicPath" option should work and respect the "publicPath" option ("string"): errors 1`] = `Array []`;

exports[`"publicPath" option should work and respect the "publicPath" option ("string"): module 1`] = `
"export default function testWorkerJsWorkerb7c903a() {
"export default function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
}
"
Expand All @@ -94,7 +94,7 @@ exports[`"publicPath" option should work and respect the "publicPath" option ("s
exports[`"publicPath" option should work and use "__webpack_public_path__" by default: errors 1`] = `Array []`;

exports[`"publicPath" option should work and use "__webpack_public_path__" by default: module 1`] = `
"export default function testWorkerJsWorker8250cd8() {
"export default function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
}
"
Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/worker-option.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ exports[`"workerType" option should support the "Worker" object value for inline
exports[`"workerType" option should support the "Worker" object value: errors 1`] = `Array []`;

exports[`"workerType" option should support the "Worker" object value: module 1`] = `
"export default function testWorkerJsWorker78b84b4() {
"export default function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\", {\\"type\\":\\"classic\\",\\"name\\":\\"worker-name\\"});
}
"
Expand All @@ -28,7 +28,7 @@ exports[`"workerType" option should support the "Worker" object value: warnings
exports[`"workerType" option should support the "Worker" string value: errors 1`] = `Array []`;

exports[`"workerType" option should support the "Worker" string value: module 1`] = `
"export default function testWorkerJsWorker78b84b4() {
"export default function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
}
"
Expand All @@ -41,7 +41,7 @@ exports[`"workerType" option should support the "Worker" string value: warnings
exports[`"workerType" option should use "Worker" by default: errors 1`] = `Array []`;

exports[`"workerType" option should use "Worker" by default: module 1`] = `
"export default function testWorkerJsWorker78b84b4() {
"export default function testWorkerJsWorker() {
return new Worker(__webpack_public_path__ + \\"test.worker.js\\");
}
"
Expand Down

0 comments on commit 9d8ad01

Please sign in to comment.