codingclip-worker-loader 3.0.9 → 3.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright JS Foundation and other contributors
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- 'Software'), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright JS Foundation and other contributors
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ 'Software'), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/dist/cjs.js CHANGED
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
 
3
3
  const loader = require("./index");
4
-
5
4
  module.exports = loader.default;
6
5
  module.exports.pitch = loader.pitch;
package/dist/index.js CHANGED
@@ -5,49 +5,65 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = loader;
7
7
  exports.pitch = pitch;
8
-
9
8
  var _path = _interopRequireDefault(require("path"));
10
-
11
9
  var _loaderUtils = require("loader-utils");
12
-
13
10
  var _schemaUtils = require("schema-utils");
14
-
15
- var _NodeTargetPlugin = _interopRequireDefault(require("webpack/lib/node/NodeTargetPlugin"));
16
-
17
- var _SingleEntryPlugin = _interopRequireDefault(require("webpack/lib/SingleEntryPlugin"));
18
-
19
- var _WebWorkerTemplatePlugin = _interopRequireDefault(require("webpack/lib/webworker/WebWorkerTemplatePlugin"));
20
-
21
- var _ExternalsPlugin = _interopRequireDefault(require("webpack/lib/ExternalsPlugin"));
22
-
23
11
  var _options = _interopRequireDefault(require("./options.json"));
24
-
25
12
  var _supportWebpack = _interopRequireDefault(require("./supportWebpack5"));
26
-
27
13
  var _supportWebpack2 = _interopRequireDefault(require("./supportWebpack4"));
28
-
29
14
  var _utils = require("./utils");
30
-
31
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
32
-
33
- let FetchCompileWasmPlugin;
34
- let FetchCompileAsyncWasmPlugin; // determine the version of webpack peer dependency
35
- // eslint-disable-next-line global-require, import/no-unresolved
36
-
37
- const useWebpack5 = require("webpack/package.json").version.startsWith("5.");
38
-
39
- if (useWebpack5) {
40
- // eslint-disable-next-line global-require, import/no-unresolved
41
- FetchCompileWasmPlugin = require("webpack/lib/web/FetchCompileWasmPlugin"); // eslint-disable-next-line global-require, import/no-unresolved
42
-
43
- FetchCompileAsyncWasmPlugin = require("webpack/lib/web/FetchCompileAsyncWasmPlugin");
44
- } else {
45
- // eslint-disable-next-line global-require, import/no-unresolved, import/extensions
46
- FetchCompileWasmPlugin = require("webpack/lib/web/FetchCompileWasmTemplatePlugin");
15
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
16
+ // Cache for webpack plugins resolved from the compiler's webpack instance
17
+ const webpackPluginsCache = new WeakMap();
18
+
19
+ /**
20
+ * Get webpack plugins from the compiler's webpack instance.
21
+ * This ensures we use the same webpack version as the parent compiler,
22
+ * avoiding "compilation argument must be an instance of Compilation" errors
23
+ * when multiple webpack versions are installed.
24
+ */
25
+ function getWebpackPlugins(compiler) {
26
+ if (webpackPluginsCache.has(compiler)) {
27
+ return webpackPluginsCache.get(compiler);
28
+ }
29
+ const {
30
+ webpack
31
+ } = compiler;
32
+ const isWebpack5 = webpack && webpack.version && webpack.version.startsWith("5.");
33
+ let plugins;
34
+ if (isWebpack5) {
35
+ // Webpack 5: use compiler.webpack to access modules
36
+ plugins = {
37
+ NodeTargetPlugin: webpack.node.NodeTargetPlugin,
38
+ EntryPlugin: webpack.EntryPlugin,
39
+ WebWorkerTemplatePlugin: webpack.webworker.WebWorkerTemplatePlugin,
40
+ ExternalsPlugin: webpack.ExternalsPlugin,
41
+ FetchCompileWasmPlugin: webpack.web.FetchCompileWasmPlugin,
42
+ FetchCompileAsyncWasmPlugin: webpack.web.FetchCompileAsyncWasmPlugin,
43
+ isWebpack5: true
44
+ };
45
+ } else {
46
+ // Webpack 4: require from webpack (fallback for older versions without compiler.webpack)
47
+ // eslint-disable-next-line global-require, import/no-unresolved
48
+ plugins = {
49
+ // eslint-disable-next-line global-require, import/no-unresolved
50
+ NodeTargetPlugin: require("webpack/lib/node/NodeTargetPlugin"),
51
+ // eslint-disable-next-line global-require, import/no-unresolved
52
+ SingleEntryPlugin: require("webpack/lib/SingleEntryPlugin"),
53
+ // eslint-disable-next-line global-require, import/no-unresolved
54
+ WebWorkerTemplatePlugin: require("webpack/lib/webworker/WebWorkerTemplatePlugin"),
55
+ // eslint-disable-next-line global-require, import/no-unresolved
56
+ ExternalsPlugin: require("webpack/lib/ExternalsPlugin"),
57
+ // eslint-disable-next-line global-require, import/no-unresolved, import/extensions
58
+ FetchCompileWasmPlugin: require("webpack/lib/web/FetchCompileWasmTemplatePlugin"),
59
+ FetchCompileAsyncWasmPlugin: null,
60
+ isWebpack5: false
61
+ };
62
+ }
63
+ webpackPluginsCache.set(compiler, plugins);
64
+ return plugins;
47
65
  }
48
-
49
66
  function loader() {}
50
-
51
67
  function pitch(request) {
52
68
  this.cacheable(false);
53
69
  const options = (0, _loaderUtils.getOptions)(this);
@@ -55,6 +71,20 @@ function pitch(request) {
55
71
  name: "Worker Loader",
56
72
  baseDataPath: "options"
57
73
  });
74
+
75
+ // Get webpack plugins from the compiler's webpack instance
76
+ // This ensures compatibility when multiple webpack versions are installed
77
+ const plugins = getWebpackPlugins(this._compiler);
78
+ const {
79
+ NodeTargetPlugin,
80
+ EntryPlugin,
81
+ SingleEntryPlugin,
82
+ WebWorkerTemplatePlugin,
83
+ ExternalsPlugin,
84
+ FetchCompileWasmPlugin,
85
+ FetchCompileAsyncWasmPlugin,
86
+ isWebpack5
87
+ } = plugins;
58
88
  const workerContext = {};
59
89
  const compilerOptions = this._compiler.options || {};
60
90
  const filename = options.filename ? options.filename : (0, _utils.getDefaultFilename)(compilerOptions.output.filename);
@@ -67,30 +97,27 @@ function pitch(request) {
67
97
  globalObject: "self"
68
98
  };
69
99
  workerContext.compiler = this._compilation.createChildCompiler(`worker-loader ${request}`, workerContext.options);
70
- new _WebWorkerTemplatePlugin.default().apply(workerContext.compiler);
71
-
100
+ new WebWorkerTemplatePlugin().apply(workerContext.compiler);
72
101
  if (this.target !== "webworker" && this.target !== "web") {
73
- new _NodeTargetPlugin.default().apply(workerContext.compiler);
102
+ new NodeTargetPlugin().apply(workerContext.compiler);
74
103
  }
75
-
76
104
  if (FetchCompileWasmPlugin) {
77
105
  new FetchCompileWasmPlugin({
78
106
  mangleImports: compilerOptions.optimization.mangleWasmImports
79
107
  }).apply(workerContext.compiler);
80
108
  }
81
-
82
109
  if (FetchCompileAsyncWasmPlugin) {
83
110
  new FetchCompileAsyncWasmPlugin().apply(workerContext.compiler);
84
111
  }
85
-
86
112
  if (compilerOptions.externals) {
87
- new _ExternalsPlugin.default((0, _utils.getExternalsType)(compilerOptions), compilerOptions.externals).apply(workerContext.compiler);
113
+ new ExternalsPlugin((0, _utils.getExternalsType)(compilerOptions), compilerOptions.externals).apply(workerContext.compiler);
88
114
  }
89
115
 
90
- new _SingleEntryPlugin.default(this.context, `!!${request}`, _path.default.parse(this.resourcePath).name).apply(workerContext.compiler);
116
+ // Use EntryPlugin for webpack 5, SingleEntryPlugin for webpack 4
117
+ const EntryPluginClass = isWebpack5 ? EntryPlugin : SingleEntryPlugin;
118
+ new EntryPluginClass(this.context, `!!${request}`, _path.default.parse(this.resourcePath).name).apply(workerContext.compiler);
91
119
  workerContext.request = request;
92
120
  const cb = this.async();
93
-
94
121
  if (workerContext.compiler.cache && typeof workerContext.compiler.cache.get === "function") {
95
122
  (0, _supportWebpack.default)(this, workerContext, options, cb);
96
123
  } else {
package/dist/options.json CHANGED
@@ -1,72 +1,72 @@
1
- {
2
- "type": "object",
3
- "properties": {
4
- "worker": {
5
- "anyOf": [
6
- {
7
- "type": "string",
8
- "minLength": 1
9
- },
10
- {
11
- "type": "object",
12
- "additionalProperties": false,
13
- "properties": {
14
- "type": {
15
- "type": "string",
16
- "minLength": 1
17
- },
18
- "options": {
19
- "additionalProperties": true,
20
- "type": "object"
21
- }
22
- },
23
- "required": ["type"]
24
- }
25
- ],
26
- "description": "Set the worker type.",
27
- "link": "https://github.com/webpack-contrib/worker-loader#worker"
28
- },
29
- "publicPath": {
30
- "anyOf": [
31
- {
32
- "type": "string"
33
- },
34
- {
35
- "instanceof": "Function"
36
- }
37
- ],
38
- "description": "Specifies the public URL address of the output files when referenced in a browser.",
39
- "link": "https://github.com/webpack-contrib/worker-loader#publicpath"
40
- },
41
- "filename": {
42
- "anyOf": [
43
- {
44
- "type": "string",
45
- "minLength": 1
46
- },
47
- {
48
- "instanceof": "Function"
49
- }
50
- ],
51
- "description": "The filename of entry chunks for web workers.",
52
- "link": "https://github.com/webpack-contrib/worker-loader#filename"
53
- },
54
- "chunkFilename": {
55
- "type": "string",
56
- "description": "The filename of non-entry chunks for web workers.",
57
- "link": "https://github.com/webpack-contrib/worker-loader#chunkfilename",
58
- "minLength": 1
59
- },
60
- "inline": {
61
- "enum": ["no-fallback", "fallback"],
62
- "description": "Allow to inline the worker as a BLOB.",
63
- "link": "https://github.com/webpack-contrib/worker-loader#inline"
64
- },
65
- "esModule": {
66
- "type": "boolean",
67
- "description": "Enable or disable ES module syntax.",
68
- "link": "https://github.com/webpack-contrib/worker-loader#esmodule"
69
- }
70
- },
71
- "additionalProperties": false
72
- }
1
+ {
2
+ "type": "object",
3
+ "properties": {
4
+ "worker": {
5
+ "anyOf": [
6
+ {
7
+ "type": "string",
8
+ "minLength": 1
9
+ },
10
+ {
11
+ "type": "object",
12
+ "additionalProperties": false,
13
+ "properties": {
14
+ "type": {
15
+ "type": "string",
16
+ "minLength": 1
17
+ },
18
+ "options": {
19
+ "additionalProperties": true,
20
+ "type": "object"
21
+ }
22
+ },
23
+ "required": ["type"]
24
+ }
25
+ ],
26
+ "description": "Set the worker type.",
27
+ "link": "https://github.com/webpack-contrib/worker-loader#worker"
28
+ },
29
+ "publicPath": {
30
+ "anyOf": [
31
+ {
32
+ "type": "string"
33
+ },
34
+ {
35
+ "instanceof": "Function"
36
+ }
37
+ ],
38
+ "description": "Specifies the public URL address of the output files when referenced in a browser.",
39
+ "link": "https://github.com/webpack-contrib/worker-loader#publicpath"
40
+ },
41
+ "filename": {
42
+ "anyOf": [
43
+ {
44
+ "type": "string",
45
+ "minLength": 1
46
+ },
47
+ {
48
+ "instanceof": "Function"
49
+ }
50
+ ],
51
+ "description": "The filename of entry chunks for web workers.",
52
+ "link": "https://github.com/webpack-contrib/worker-loader#filename"
53
+ },
54
+ "chunkFilename": {
55
+ "type": "string",
56
+ "description": "The filename of non-entry chunks for web workers.",
57
+ "link": "https://github.com/webpack-contrib/worker-loader#chunkfilename",
58
+ "minLength": 1
59
+ },
60
+ "inline": {
61
+ "enum": ["no-fallback", "fallback"],
62
+ "description": "Allow to inline the worker as a BLOB.",
63
+ "link": "https://github.com/webpack-contrib/worker-loader#inline"
64
+ },
65
+ "esModule": {
66
+ "type": "boolean",
67
+ "description": "Enable or disable ES module syntax.",
68
+ "link": "https://github.com/webpack-contrib/worker-loader#esmodule"
69
+ }
70
+ },
71
+ "additionalProperties": false
72
+ }
@@ -1,15 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  /* eslint-env browser */
4
-
5
4
  /* eslint-disable no-undef, no-use-before-define, new-cap */
5
+
6
6
  module.exports = function (content, workerConstructor, workerOptions, url) {
7
7
  var globalScope = self || window;
8
-
9
8
  try {
10
9
  try {
11
10
  var blob;
12
-
13
11
  try {
14
12
  // New API
15
13
  blob = new globalScope.Blob([content]);
@@ -20,7 +18,6 @@ module.exports = function (content, workerConstructor, workerOptions, url) {
20
18
  blob.append(content);
21
19
  blob = blob.getBlob();
22
20
  }
23
-
24
21
  var URL = globalScope.URL || globalScope.webkitURL;
25
22
  var objectURL = URL.createObjectURL(blob);
26
23
  var worker = new globalScope[workerConstructor](objectURL, workerOptions);
@@ -33,7 +30,6 @@ module.exports = function (content, workerConstructor, workerOptions, url) {
33
30
  if (!url) {
34
31
  throw Error("Inline worker is not supported");
35
32
  }
36
-
37
33
  return new globalScope[workerConstructor](url, workerOptions);
38
34
  }
39
35
  };
@@ -4,40 +4,36 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = runAsChild;
7
-
8
7
  var _utils = require("./utils");
9
-
10
8
  function runAsChild(loaderContext, workerContext, options, callback) {
11
9
  workerContext.compiler.runAsChild((error, entries, compilation) => {
12
10
  if (error) {
13
11
  return callback(error);
14
12
  }
15
-
16
13
  if (entries[0]) {
17
14
  // eslint-disable-next-line no-param-reassign, prefer-destructuring
18
15
  const workerFilename = entries[0].files[0];
19
16
  let workerSource = compilation.assets[workerFilename].source();
20
-
21
17
  if (options.inline === "no-fallback") {
22
18
  // eslint-disable-next-line no-underscore-dangle, no-param-reassign
23
- delete loaderContext._compilation.assets[workerFilename]; // TODO improve it, we should store generated source maps files for file in `assetInfo`
24
- // eslint-disable-next-line no-underscore-dangle
19
+ delete loaderContext._compilation.assets[workerFilename];
25
20
 
21
+ // TODO improve it, we should store generated source maps files for file in `assetInfo`
22
+ // eslint-disable-next-line no-underscore-dangle
26
23
  if (loaderContext._compilation.assets[`${workerFilename}.map`]) {
27
24
  // eslint-disable-next-line no-underscore-dangle, no-param-reassign
28
25
  delete loaderContext._compilation.assets[`${workerFilename}.map`];
29
- } // Remove `/* sourceMappingURL=url */` comment
30
-
26
+ }
31
27
 
32
- workerSource = workerSource.replace(_utils.sourceMappingURLRegex, ""); // Remove `//# sourceURL=webpack-internal` comment
28
+ // Remove `/* sourceMappingURL=url */` comment
29
+ workerSource = workerSource.replace(_utils.sourceMappingURLRegex, "");
33
30
 
31
+ // Remove `//# sourceURL=webpack-internal` comment
34
32
  workerSource = workerSource.replace(_utils.sourceURLWebpackRegex, "");
35
33
  }
36
-
37
34
  const workerCode = (0, _utils.workerGenerator)(loaderContext, workerFilename, workerSource, options);
38
35
  return callback(null, workerCode);
39
36
  }
40
-
41
37
  return callback(new Error(`Failed to compile web worker "${workerContext.request}" request`));
42
38
  });
43
39
  }
@@ -4,15 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = runAsChild;
7
-
8
7
  var _utils = require("./utils");
9
-
10
8
  function runAsChild(loaderContext, workerContext, options, callback) {
11
9
  workerContext.compiler.runAsChild((error, entries, compilation) => {
12
10
  if (error) {
13
11
  return callback(error);
14
12
  }
15
-
16
13
  if (entries[0]) {
17
14
  const [workerFilename] = [...entries[0].files];
18
15
  const cache = workerContext.compiler.getCache("worker-loader");
@@ -22,43 +19,38 @@ function runAsChild(loaderContext, workerContext, options, callback) {
22
19
  if (getCacheError) {
23
20
  return callback(getCacheError);
24
21
  }
25
-
26
22
  if (options.inline === "no-fallback") {
27
23
  // eslint-disable-next-line no-underscore-dangle, no-param-reassign
28
- delete loaderContext._compilation.assets[workerFilename]; // TODO improve this, we should store generated source maps files for file in `assetInfo`
29
- // eslint-disable-next-line no-underscore-dangle
24
+ delete loaderContext._compilation.assets[workerFilename];
30
25
 
26
+ // TODO improve this, we should store generated source maps files for file in `assetInfo`
27
+ // eslint-disable-next-line no-underscore-dangle
31
28
  if (loaderContext._compilation.assets[`${workerFilename}.map`]) {
32
29
  // eslint-disable-next-line no-underscore-dangle, no-param-reassign
33
30
  delete loaderContext._compilation.assets[`${workerFilename}.map`];
34
31
  }
35
32
  }
36
-
37
33
  if (content) {
38
34
  return callback(null, content);
39
35
  }
40
-
41
36
  let workerSource = compilation.assets[workerFilename].source();
42
-
43
37
  if (options.inline === "no-fallback") {
44
38
  // Remove `/* sourceMappingURL=url */` comment
45
- workerSource = workerSource.replace(_utils.sourceMappingURLRegex, ""); // Remove `//# sourceURL=webpack-internal` comment
39
+ workerSource = workerSource.replace(_utils.sourceMappingURLRegex, "");
46
40
 
41
+ // Remove `//# sourceURL=webpack-internal` comment
47
42
  workerSource = workerSource.replace(_utils.sourceURLWebpackRegex, "");
48
43
  }
49
-
50
44
  const workerCode = (0, _utils.workerGenerator)(loaderContext, workerFilename, workerSource, options);
51
45
  const workerCodeBuffer = Buffer.from(workerCode);
52
46
  return cache.store(cacheIdent, cacheETag, workerCodeBuffer, storeCacheError => {
53
47
  if (storeCacheError) {
54
48
  return callback(storeCacheError);
55
49
  }
56
-
57
50
  return callback(null, workerCodeBuffer);
58
51
  });
59
52
  });
60
53
  }
61
-
62
54
  return callback(new Error(`Failed to compile web worker "${workerContext.request}" request`));
63
55
  });
64
56
  }
package/dist/utils.js CHANGED
@@ -3,52 +3,42 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.getDefaultFilename = getDefaultFilename;
7
6
  exports.getDefaultChunkFilename = getDefaultChunkFilename;
7
+ exports.getDefaultFilename = getDefaultFilename;
8
8
  exports.getExternalsType = getExternalsType;
9
- exports.workerGenerator = workerGenerator;
10
9
  exports.sourceURLWebpackRegex = exports.sourceMappingURLRegex = void 0;
11
-
10
+ exports.workerGenerator = workerGenerator;
12
11
  var _loaderUtils = require("loader-utils");
13
-
14
12
  function getDefaultFilename(filename) {
15
13
  if (typeof filename === "function") {
16
14
  return filename;
17
15
  }
18
-
19
16
  return filename.replace(/\.([a-z]+)(\?.+)?$/i, ".worker.$1$2");
20
17
  }
21
-
22
18
  function getDefaultChunkFilename(chunkFilename) {
23
19
  return chunkFilename.replace(/\.([a-z]+)(\?.+)?$/i, ".worker.$1$2");
24
20
  }
25
-
26
21
  function getExternalsType(compilerOptions) {
27
22
  // For webpack@4
28
23
  if (compilerOptions.output.libraryTarget) {
29
24
  return compilerOptions.output.libraryTarget;
30
- } // For webpack@5
31
-
25
+ }
32
26
 
27
+ // For webpack@5
33
28
  if (compilerOptions.externalsType) {
34
29
  return compilerOptions.externalsType;
35
30
  }
36
-
37
31
  if (compilerOptions.output.library) {
38
32
  return compilerOptions.output.library.type;
39
33
  }
40
-
41
34
  if (compilerOptions.output.module) {
42
35
  return "module";
43
36
  }
44
-
45
37
  return "var";
46
38
  }
47
-
48
39
  function workerGenerator(loaderContext, workerFilename, workerSource, options) {
49
40
  let workerConstructor;
50
41
  let workerOptions;
51
-
52
42
  if (typeof options.worker === "undefined") {
53
43
  workerConstructor = "Worker";
54
44
  } else if (typeof options.worker === "string") {
@@ -59,35 +49,27 @@ function workerGenerator(loaderContext, workerFilename, workerSource, options) {
59
49
  options: workerOptions
60
50
  } = options.worker);
61
51
  }
62
-
63
52
  const esModule = typeof options.esModule !== "undefined" ? options.esModule : true;
64
53
  const fnName = `${workerConstructor}_fn`;
65
54
  const publicPath = options.publicPath ? `"${options.publicPath}"` : "__webpack_public_path__";
66
-
67
55
  if (options.inline) {
68
56
  const InlineWorkerPath = (0, _loaderUtils.stringifyRequest)(loaderContext, `!!${require.resolve("./runtime/inline.js")}`);
69
57
  let fallbackWorkerPath;
70
-
71
58
  if (options.inline === "fallback") {
72
59
  fallbackWorkerPath = `${publicPath} + ${JSON.stringify(workerFilename)}`;
73
60
  }
74
-
75
61
  return `
76
62
  ${esModule ? `import worker from ${InlineWorkerPath};` : `var worker = require(${InlineWorkerPath});`}
77
63
 
78
64
  ${esModule ? "export default" : "module.exports ="} function ${fnName}() {\n return worker(${JSON.stringify(workerSource)}, ${JSON.stringify(workerConstructor)}, ${JSON.stringify(workerOptions)}, ${fallbackWorkerPath});\n}\n`;
79
65
  }
80
-
81
66
  return `${esModule ? "export default" : "module.exports ="} function ${fnName}() {\n return new ${workerConstructor}(${publicPath} + ${JSON.stringify(workerFilename)}${workerOptions ? `, ${JSON.stringify(workerOptions)}` : ""});\n}\n`;
82
- } // Matches only the last occurrence of sourceMappingURL
83
-
67
+ }
84
68
 
69
+ // Matches only the last occurrence of sourceMappingURL
85
70
  const innerRegex = /\s*[#@]\s*sourceMappingURL\s*=\s*(.*?(?=[\s'"]|\\n|\*\/|$)(?:\\n)?)\s*/;
86
- /* eslint-disable prefer-template */
87
-
88
- const sourceMappingURLRegex = RegExp("(?:" + "/\\*" + "(?:\\s*\r?\n(?://)?)?" + "(?:" + innerRegex.source + ")" + "\\s*" + "\\*/" + "|" + "//(?:" + innerRegex.source + ")" + ")" + "\\s*");
89
- exports.sourceMappingURLRegex = sourceMappingURLRegex;
90
- const sourceURLWebpackRegex = RegExp("\\/\\/#\\ssourceURL=webpack-internal:\\/\\/\\/(.*?)\\\\n");
91
- /* eslint-enable prefer-template */
92
71
 
93
- exports.sourceURLWebpackRegex = sourceURLWebpackRegex;
72
+ /* eslint-disable prefer-template */
73
+ const sourceMappingURLRegex = exports.sourceMappingURLRegex = RegExp("(?:" + "/\\*" + "(?:\\s*\r?\n(?://)?)?" + "(?:" + innerRegex.source + ")" + "\\s*" + "\\*/" + "|" + "//(?:" + innerRegex.source + ")" + ")" + "\\s*");
74
+ const sourceURLWebpackRegex = exports.sourceURLWebpackRegex = RegExp("\\/\\/#\\ssourceURL=webpack-internal:\\/\\/\\/(.*?)\\\\n");
75
+ /* eslint-enable prefer-template */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codingclip-worker-loader",
3
- "version": "3.0.9",
3
+ "version": "3.0.10",
4
4
  "description": "worker loader module for webpack",
5
5
  "license": "MIT",
6
6
  "repository": "webpack-contrib/worker-loader",
@@ -47,10 +47,10 @@
47
47
  "@babel/cli": "^7.14.5",
48
48
  "@babel/core": "^7.14.6",
49
49
  "@babel/preset-env": "^7.14.7",
50
- "@commitlint/cli": "^12.1.4",
50
+ "@commitlint/cli": "^20.2.0",
51
51
  "@commitlint/config-conventional": "^12.1.4",
52
52
  "@webpack-contrib/eslint-config-webpack": "^3.0.0",
53
- "babel-jest": "^26.6.3",
53
+ "babel-jest": "^30.2.0",
54
54
  "cross-env": "^7.0.3",
55
55
  "del": "^6.0.0",
56
56
  "del-cli": "^3.0.1",
@@ -61,7 +61,7 @@
61
61
  "get-port": "^5.1.1",
62
62
  "html-webpack-plugin": "^4.5.0",
63
63
  "husky": "^4.3.0",
64
- "jest": "^26.6.3",
64
+ "jest": "^30.2.0",
65
65
  "lint-staged": "^10.5.4",
66
66
  "memfs": "^3.2.0",
67
67
  "nanoid": "^3.1.20",
@@ -69,7 +69,7 @@
69
69
  "prettier": "^2.3.2",
70
70
  "puppeteer": "^7.0.4",
71
71
  "standard-version": "^9.3.1",
72
- "webpack": "^5.45.1"
72
+ "webpack": "^5.104.1"
73
73
  },
74
74
  "keywords": [
75
75
  "webpack"
package/CHANGELOG.md DELETED
@@ -1,145 +0,0 @@
1
- # Changelog
2
-
3
- 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.
4
-
5
- ### [3.0.8](https://github.com/webpack-contrib/worker-loader/compare/v3.0.7...v3.0.8) (2021-02-11)
6
-
7
-
8
- ### Bug Fixes
9
-
10
- * make inline workers work from inside workers ([#307](https://github.com/webpack-contrib/worker-loader/issues/307)) ([2abd129](https://github.com/webpack-contrib/worker-loader/commit/2abd129a322d631caf619622cd65825699bb183a))
11
-
12
- ### [3.0.7](https://github.com/webpack-contrib/worker-loader/compare/v3.0.6...v3.0.7) (2020-12-23)
13
-
14
-
15
- ### Bug Fixes
16
-
17
- * serializing big strings ([#304](https://github.com/webpack-contrib/worker-loader/issues/304)) ([a0de29b](https://github.com/webpack-contrib/worker-loader/commit/a0de29b497876eb462271ca5ebbeb3ffe1c1d1c4))
18
-
19
- ### [3.0.6](https://github.com/webpack-contrib/worker-loader/compare/v3.0.5...v3.0.6) (2020-12-02)
20
-
21
-
22
- ### Bug Fixes
23
-
24
- * set a name to exported function ([#299](https://github.com/webpack-contrib/worker-loader/issues/299)) ([15cf407](https://github.com/webpack-contrib/worker-loader/commit/15cf407ad6baeb09e2cbb5d7b4b869cc63bfac7f))
25
-
26
- ### [3.0.5](https://github.com/webpack-contrib/worker-loader/compare/v3.0.4...v3.0.5) (2020-10-16)
27
-
28
-
29
- ### Bug Fixes
30
-
31
- * determine webpack peer dependency version ([#296](https://github.com/webpack-contrib/worker-loader/issues/296)) ([8c63449](https://github.com/webpack-contrib/worker-loader/commit/8c634495419b4becc32b83e24c21e36ff720a2cd))
32
-
33
- ### [3.0.4](https://github.com/webpack-contrib/worker-loader/compare/v3.0.3...v3.0.4) (2020-10-09)
34
-
35
- ### Chore
36
-
37
- * update `schema-utils`
38
-
39
- ### [3.0.3](https://github.com/webpack-contrib/worker-loader/compare/v3.0.2...v3.0.3) (2020-09-22)
40
-
41
-
42
- ### Bug Fixes
43
-
44
- * remove unnecessary webpack sourceURL ([#289](https://github.com/webpack-contrib/worker-loader/issues/289)) ([eef2757](https://github.com/webpack-contrib/worker-loader/commit/eef27574160f519c344dfa5fd981b7ac561a8939))
45
- * compatibility with eval source maps ([#286](https://github.com/webpack-contrib/worker-loader/issues/286)) ([0d4624c](https://github.com/webpack-contrib/worker-loader/commit/0d4624c178c426aa97e5175a5f321e43de482c2b))
46
-
47
- ### [3.0.2](https://github.com/webpack-contrib/worker-loader/compare/v3.0.1...v3.0.2) (2020-08-22)
48
-
49
-
50
- ### Bug Fixes
51
-
52
- * SSR compatibility ([#284](https://github.com/webpack-contrib/worker-loader/issues/284)) ([ca4a963](https://github.com/webpack-contrib/worker-loader/commit/ca4a963e93fe5efcdf84cda0dbe571d293f079a5))
53
-
54
- ### [3.0.1](https://github.com/webpack-contrib/worker-loader/compare/v3.0.0...v3.0.1) (2020-08-05)
55
-
56
-
57
- ### Bug Fixes
58
-
59
- * 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))
60
- * 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))
61
-
62
- ## [3.0.0](https://github.com/webpack-contrib/worker-loader/compare/v2.0.0...v3.0.0) (2020-08-01)
63
-
64
-
65
- ### ⚠ BREAKING CHANGES
66
-
67
- * minimum supported Node.js version is `10.13`
68
- * minimum supported webpack version is `4`
69
- * the `name` option was renamed to the `filename` option
70
- * switch on ES module syntax by default, use the `esModule` option if you need backward compatibility with Common JS modules
71
- * the `fallback` option was removed in favor the `inline` option, the `inline` option accepts only `fallback` and `no-fallback` values
72
- * the `publicPath` option default value based on `output.publicPath`
73
- * the `filename` option default value based on `output.filename`
74
-
75
-
76
- ### Features
77
-
78
- * added the `worker` option (replaces [#178](https://github.com/webpack-contrib/worker-loader/issues/178)) ([#247](https://github.com/webpack-contrib/worker-loader/issues/247)) ([f03498d](https://github.com/webpack-contrib/worker-loader/commit/f03498d22c6a3737b724c51bdfb56627e33b57b2))
79
- * added the `chunkFilename` option, default value based on `output.chunkFilename` ([905ed7b](https://github.com/webpack-contrib/worker-loader/commit/905ed7b028bbcb646050a1d09096dbe2fc1feb42))
80
- * added the `esModule` option
81
- * allow to use any web worker constructor and options for constructor
82
- * the `publicPath` option can be `Function`
83
- * the `filename` (previously `name`) option can be `Function`
84
-
85
-
86
- ### Bug Fixes
87
-
88
- * support `WASM` ([152634c](https://github.com/webpack-contrib/worker-loader/commit/152634c0d8866d248ced3b6e5ac02761c978ae1a))
89
- * respect `externals` ([#264](https://github.com/webpack-contrib/worker-loader/issues/264)) ([1e761ed](https://github.com/webpack-contrib/worker-loader/commit/1e761edcbfc8b214ae3a19f44f401f20ab07b718))
90
- * memory leak for inline web workers ([#252](https://github.com/webpack-contrib/worker-loader/issues/252)) ([f729e34](https://github.com/webpack-contrib/worker-loader/commit/f729e342922180bf3b375a8d2ea6e1b72ca95d74))
91
- * source maps when `inline` using without fallback ([#269](https://github.com/webpack-contrib/worker-loader/issues/269)) ([5047abb](https://github.com/webpack-contrib/worker-loader/commit/5047abb2f9b97ff4706069716df8e718bee9de43))
92
- * the `publicPath` options works fine with async web workers chunks
93
- * compatibility with webpack@5 ([#259](https://github.com/webpack-contrib/worker-loader/issues/259)) ([e0d9887](https://github.com/webpack-contrib/worker-loader/commit/e0d98876c6ee83bc48ea9589b38437590878e9d9))
94
- * always use `self` as global object
95
- * compatibility with `webpack-dev-server`
96
- * increase performance
97
-
98
-
99
- ## [2.0.0](https://github.com/webpack-contrib/worker-loader/compare/v1.1.1...v2.0.0) (2018-05-27)
100
-
101
- ## Updates
102
-
103
- - refactor(index): remove `Tapable.apply` calls (#121)
104
- - docs: use ES6 import in TypeScript README example (#140) …
105
- - docs(README): add note about omitted hashes (`options.name`) (#131)
106
- - fix(package): homepage URL typo (#130)
107
-
108
- ## Breaking Changes
109
-
110
- Drops support for Webpack versions < 3.0.0
111
-
112
- <a name="1.1.1"></a>
113
- ## [1.1.1](https://github.com/webpack-contrib/worker-loader/compare/v1.1.0...v1.1.1) (2018-02-25)
114
-
115
-
116
- ### Bug Fixes
117
-
118
- * **index:** add `webpack >= v4.0.0` support ([#128](https://github.com/webpack-contrib/worker-loader/issues/128)) ([d1a7a94](https://github.com/webpack-contrib/worker-loader/commit/d1a7a94))
119
-
120
-
121
-
122
- <a name="1.1.0"></a>
123
- # [1.1.0](https://github.com/webpack-contrib/worker-loader/compare/v1.0.0...v1.1.0) (2017-10-24)
124
-
125
-
126
- ### Features
127
-
128
- * add `publicPath` support (`options.publicPath`) ([#31](https://github.com/webpack-contrib/worker-loader/issues/31)) ([96c6144](https://github.com/webpack-contrib/worker-loader/commit/96c6144))
129
-
130
-
131
-
132
- <a name="1.0.0"></a>
133
- ## [1.0.0](https://github.com/webpack-contrib/worker-loader/compare/v0.8.0...v1.0.0) (2017-09-25)
134
-
135
-
136
- ### Features
137
-
138
- * add `options` validation (`schema-utils`) ([#78](https://github.com/webpack-contrib/worker-loader/issues/78)) ([5e2f5e6](https://github.com/webpack-contrib/worker-loader/commit/5e2f5e6))
139
- * support loading node core modules ([#76](https://github.com/webpack-contrib/worker-loader/issues/76)) ([edcda35](https://github.com/webpack-contrib/worker-loader/commit/edcda35))
140
-
141
-
142
- ### BREAKING CHANGES
143
-
144
- * loader-utils upgrade to > 1.0 is not backwards
145
- compatible with previous versions