@umijs/bundler-webpack 4.0.42 → 4.0.43

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.
Files changed (84) hide show
  1. package/client/utils/formatWebpackMessages.js +27 -8
  2. package/compiled/babel-loader/index.js +8 -2
  3. package/compiled/babel-loader/package.json +1 -1
  4. package/compiled/less-loader/index.js +1 -1
  5. package/compiled/less-loader/package.json +1 -1
  6. package/compiled/mini-css-extract-plugin/hmr/hotModuleReplacement.js +22 -60
  7. package/compiled/mini-css-extract-plugin/hmr/normalize-url.js +2 -10
  8. package/compiled/mini-css-extract-plugin/index.js +492 -696
  9. package/compiled/mini-css-extract-plugin/loader.js +54 -120
  10. package/compiled/mini-css-extract-plugin/package.json +1 -1
  11. package/compiled/mini-css-extract-plugin/utils.js +27 -44
  12. package/compiled/postcss-loader/index.js +1 -1
  13. package/compiled/postcss-loader/package.json +1 -1
  14. package/compiled/sass-loader/index.js +1 -1
  15. package/compiled/sass-loader/package.json +1 -1
  16. package/compiled/sass-loader/sass.default.dart.js +4 -0
  17. package/compiled/terser/@jridgewell/gen-mapping/dist/types/gen-mapping.d.ts +90 -0
  18. package/compiled/terser/@jridgewell/gen-mapping/dist/types/sourcemap-segment.d.ts +12 -0
  19. package/compiled/terser/@jridgewell/gen-mapping/dist/types/types.d.ts +35 -0
  20. package/compiled/terser/@jridgewell/source-map/dist/types/source-map.d.ts +25 -0
  21. package/compiled/terser/@jridgewell/trace-mapping/dist/types/sourcemap-segment.d.ts +16 -0
  22. package/compiled/terser/@jridgewell/trace-mapping/dist/types/trace-mapping.d.ts +74 -0
  23. package/compiled/terser/@jridgewell/trace-mapping/dist/types/types.d.ts +92 -0
  24. package/compiled/terser/index.js +1 -1
  25. package/compiled/terser/package.json +1 -1
  26. package/compiled/terser/tools/terser.d.ts +6 -3
  27. package/compiled/terser-webpack-plugin/@jridgewell/trace-mapping/dist/types/sourcemap-segment.d.ts +16 -0
  28. package/compiled/terser-webpack-plugin/@jridgewell/trace-mapping/dist/types/trace-mapping.d.ts +74 -0
  29. package/compiled/terser-webpack-plugin/@jridgewell/trace-mapping/dist/types/types.d.ts +92 -0
  30. package/compiled/terser-webpack-plugin/index.js +1211 -3390
  31. package/compiled/terser-webpack-plugin/package.json +1 -1
  32. package/compiled/terser-webpack-plugin/types/index.d.ts +10 -10
  33. package/compiled/terser-webpack-plugin/types/utils.d.ts +10 -9
  34. package/compiled/terser-webpack-plugin/utils.js +36 -10
  35. package/compiled/webpack/package.json +1 -1
  36. package/compiled/webpack/types.d.ts +137 -126
  37. package/compiled/webpack-5-chain/index.js +1 -1
  38. package/compiled/webpack-5-chain/package.json +1 -1
  39. package/compiled/webpack-5-chain/types/index.d.ts +76 -20
  40. package/compiled/webpack-bundle-analyzer/index.js +7 -6
  41. package/compiled/webpack-bundle-analyzer/package.json +1 -1
  42. package/compiled/webpack-bundle-analyzer/public/viewer.js +2 -2
  43. package/compiled/webpack-bundle-analyzer/public/viewer.js.map +1 -1
  44. package/compiled/webpack-dev-middleware/index.js +5 -5
  45. package/compiled/webpack-dev-middleware/package.json +1 -1
  46. package/compiled/ws/LICENSE +13 -12
  47. package/compiled/ws/index.d.ts +73 -33
  48. package/compiled/ws/index.js +1 -1
  49. package/compiled/ws/package.json +1 -1
  50. package/dist/build.js +8 -2
  51. package/dist/cli.js +4 -1
  52. package/dist/config/compressPlugin.js +4 -1
  53. package/dist/config/config.js +41 -11
  54. package/dist/config/cssRules.js +17 -5
  55. package/dist/config/detectDeadCode.js +38 -8
  56. package/dist/config/detectDeadCodePlugin.js +8 -2
  57. package/dist/config/fastRefreshPlugin.js +4 -1
  58. package/dist/config/forkTSCheckerPlugin.js +4 -1
  59. package/dist/config/harmonyLinkingErrorPlugin.js +14 -11
  60. package/dist/config/javaScriptRules.js +10 -5
  61. package/dist/config/miniCSSExtractPlugin.js +4 -1
  62. package/dist/config/progressPlugin.js +9 -2
  63. package/dist/config/speedMeasureWebpackPlugin.js +7 -2
  64. package/dist/config/ssrPlugin.js +20 -6
  65. package/dist/config/svgRules.js +4 -1
  66. package/dist/dev.js +29 -10
  67. package/dist/loader/svgr.js +16 -11
  68. package/dist/loader/swc.js +26 -8
  69. package/dist/parcelCSS.js +4 -1
  70. package/dist/plugins/ProgressPlugin.js +6 -2
  71. package/dist/plugins/RuntimePublicPathPlugin.js +9 -6
  72. package/dist/plugins/_SamplePlugin.d.ts +1 -1
  73. package/dist/plugins/_SamplePlugin.js +1 -1
  74. package/dist/requireHook.js +4 -1
  75. package/dist/schema.js +58 -23
  76. package/dist/server/server.d.ts +1 -4
  77. package/dist/server/server.js +37 -23
  78. package/dist/server/ws.js +8 -3
  79. package/dist/swcPlugins/autoCSSModules.js +4 -1
  80. package/dist/swcPlugins/lockCoreJS.js +8 -2
  81. package/dist/types.d.ts +2 -1
  82. package/dist/utils/formatWebpackMessages.js +31 -9
  83. package/dist/utils/getEsBuildTarget.js +7 -1
  84. package/package.json +25 -24
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  const path = require("path");
4
-
5
4
  const {
6
5
  findModuleById,
7
6
  evalModuleCode,
@@ -9,29 +8,22 @@ const {
9
8
  ABSOLUTE_PUBLIC_PATH,
10
9
  BASE_URI,
11
10
  SINGLE_DOT_PATH_SEGMENT,
12
- stringifyRequest
11
+ stringifyRequest,
12
+ stringifyLocal
13
13
  } = require("./utils");
14
-
15
14
  const schema = require("./loader-options.json");
16
-
17
15
  const MiniCssExtractPlugin = require("./index");
18
- /** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
19
16
 
17
+ /** @typedef {import("schema-utils/declarations/validate").Schema} Schema */
20
18
  /** @typedef {import("webpack").Compiler} Compiler */
21
-
22
19
  /** @typedef {import("webpack").Compilation} Compilation */
23
-
24
20
  /** @typedef {import("webpack").Chunk} Chunk */
25
-
26
21
  /** @typedef {import("webpack").Module} Module */
27
-
28
22
  /** @typedef {import("webpack").sources.Source} Source */
29
-
30
23
  /** @typedef {import("webpack").AssetInfo} AssetInfo */
31
-
32
24
  /** @typedef {import("webpack").NormalModule} NormalModule */
33
-
34
25
  /** @typedef {import("./index.js").LoaderOptions} LoaderOptions */
26
+ /** @typedef {{ [key: string]: string | function }} Locals */
35
27
 
36
28
  /** @typedef {any} TODO */
37
29
 
@@ -48,17 +40,16 @@ const MiniCssExtractPlugin = require("./index");
48
40
 
49
41
  /**
50
42
  * @param {string} content
51
- * @param {{ loaderContext: import("webpack").LoaderContext<LoaderOptions>, options: LoaderOptions, locals: {[key: string]: string } | undefined }} context
43
+ * @param {{ loaderContext: import("webpack").LoaderContext<LoaderOptions>, options: LoaderOptions, locals: Locals | undefined }} context
52
44
  * @returns {string}
53
45
  */
54
-
55
-
56
46
  function hotLoader(content, context) {
57
47
  const accept = context.locals ? "" : "module.hot.accept(undefined, cssReload);";
58
48
  return `${content}
59
49
  if(module.hot) {
60
50
  // ${Date.now()}
61
- var cssReload = require(${stringifyRequest(context.loaderContext, path.join(__dirname, "hmr/hotModuleReplacement.js"))})(module.id, ${JSON.stringify({ ...context.options,
51
+ var cssReload = require(${stringifyRequest(context.loaderContext, path.join(__dirname, "hmr/hotModuleReplacement.js"))})(module.id, ${JSON.stringify({
52
+ ...context.options,
62
53
  locals: !!context.locals
63
54
  })});
64
55
  module.hot.dispose(cssReload);
@@ -66,32 +57,25 @@ function hotLoader(content, context) {
66
57
  }
67
58
  `;
68
59
  }
60
+
69
61
  /**
70
62
  * @this {import("webpack").LoaderContext<LoaderOptions>}
71
63
  * @param {string} request
72
64
  */
73
-
74
-
75
65
  function pitch(request) {
76
66
  // @ts-ignore
77
- const options = this.getOptions(
78
- /** @type {Schema} */
79
- schema);
67
+ const options = this.getOptions( /** @type {Schema} */schema);
68
+ const emit = typeof options.emit !== "undefined" ? options.emit : true;
80
69
  const callback = this.async();
81
- const optionsFromPlugin =
82
- /** @type {TODO} */
83
- this[MiniCssExtractPlugin.pluginSymbol];
84
-
70
+ const optionsFromPlugin = /** @type {TODO} */this[MiniCssExtractPlugin.pluginSymbol];
85
71
  if (!optionsFromPlugin) {
86
72
  callback(new Error("You forgot to add 'mini-css-extract-plugin' plugin (i.e. `{ plugins: [new MiniCssExtractPlugin()] }`), please read https://github.com/webpack-contrib/mini-css-extract-plugin#getting-started"));
87
73
  return;
88
74
  }
89
-
90
75
  const {
91
76
  webpack
92
- } =
93
- /** @type {Compiler} */
94
- this._compiler;
77
+ } = /** @type {Compiler} */this._compiler;
78
+
95
79
  /**
96
80
  * @param {TODO} originalExports
97
81
  * @param {Compilation} [compilation]
@@ -99,62 +83,47 @@ function pitch(request) {
99
83
  * @param {Map<string, AssetInfo>} [assetsInfo]
100
84
  * @returns {void}
101
85
  */
102
-
103
86
  const handleExports = (originalExports, compilation, assets, assetsInfo) => {
104
- /** @type {{[key: string]: string } | undefined} */
87
+ /** @type {Locals | undefined} */
105
88
  let locals;
106
89
  let namedExport;
107
90
  const esModule = typeof options.esModule !== "undefined" ? options.esModule : true;
91
+
108
92
  /**
109
93
  * @param {Dependency[] | [null, object][]} dependencies
110
94
  */
111
-
112
95
  const addDependencies = dependencies => {
113
96
  if (!Array.isArray(dependencies) && dependencies != null) {
114
97
  throw new Error(`Exported value was not extracted as an array: ${JSON.stringify(dependencies)}`);
115
98
  }
116
-
117
99
  const identifierCountMap = new Map();
118
- const emit = typeof options.emit !== "undefined" ? options.emit : true;
119
100
  let lastDep;
120
-
121
101
  for (const dependency of dependencies) {
122
- if (!
123
- /** @type {Dependency} */
124
- dependency.identifier || !emit) {
102
+ if (! /** @type {Dependency} */dependency.identifier || !emit) {
125
103
  // eslint-disable-next-line no-continue
126
104
  continue;
127
105
  }
128
-
129
- const count = identifierCountMap.get(
130
- /** @type {Dependency} */
131
- dependency.identifier) || 0;
106
+ const count = identifierCountMap.get( /** @type {Dependency} */dependency.identifier) || 0;
132
107
  const CssDependency = MiniCssExtractPlugin.getCssDependency(webpack);
133
- /** @type {NormalModule} */
134
108
 
135
- this._module.addDependency(lastDep = new CssDependency(
136
- /** @type {Dependency} */
137
- dependency,
138
- /** @type {Dependency} */
109
+ /** @type {NormalModule} */
110
+ this._module.addDependency(lastDep = new CssDependency( /** @type {Dependency} */
111
+ dependency, /** @type {Dependency} */
139
112
  dependency.context, count));
140
-
141
- identifierCountMap.set(
142
- /** @type {Dependency} */
113
+ identifierCountMap.set( /** @type {Dependency} */
143
114
  dependency.identifier, count + 1);
144
115
  }
145
-
146
116
  if (lastDep && assets) {
147
117
  lastDep.assets = assets;
148
118
  lastDep.assetsInfo = assetsInfo;
149
119
  }
150
120
  };
151
-
152
121
  try {
153
122
  // eslint-disable-next-line no-underscore-dangle
154
123
  const exports = originalExports.__esModule ? originalExports.default : originalExports;
155
- namedExport = // eslint-disable-next-line no-underscore-dangle
124
+ namedExport =
125
+ // eslint-disable-next-line no-underscore-dangle
156
126
  originalExports.__esModule && (!originalExports.default || !("locals" in originalExports.default));
157
-
158
127
  if (namedExport) {
159
128
  Object.keys(originalExports).forEach(key => {
160
129
  if (key !== "default") {
@@ -162,27 +131,24 @@ function pitch(request) {
162
131
  locals = {};
163
132
  }
164
133
 
134
+ /** @type {Locals} */
165
135
  locals[key] = originalExports[key];
166
136
  }
167
137
  });
168
138
  } else {
169
139
  locals = exports && exports.locals;
170
140
  }
171
- /** @type {Dependency[] | [null, object][]} */
172
-
173
141
 
142
+ /** @type {Dependency[] | [null, object][]} */
174
143
  let dependencies;
175
-
176
144
  if (!Array.isArray(exports)) {
177
145
  dependencies = [[null, exports]];
178
146
  } else {
179
147
  dependencies = exports.map(([id, content, media, sourceMap, supports, layer]) => {
180
148
  let identifier = id;
181
149
  let context;
182
-
183
150
  if (compilation) {
184
- const module =
185
- /** @type {Module} */
151
+ const module = /** @type {Module} */
186
152
  findModuleById(compilation, id);
187
153
  identifier = module.identifier();
188
154
  ({
@@ -192,7 +158,6 @@ function pitch(request) {
192
158
  // TODO check if this context is used somewhere
193
159
  context = this.rootContext;
194
160
  }
195
-
196
161
  return {
197
162
  identifier,
198
163
  context,
@@ -200,69 +165,56 @@ function pitch(request) {
200
165
  media,
201
166
  supports,
202
167
  layer,
203
- sourceMap: sourceMap ? Buffer.from(JSON.stringify(sourceMap)) : // eslint-disable-next-line no-undefined
168
+ sourceMap: sourceMap ? Buffer.from(JSON.stringify(sourceMap)) :
169
+ // eslint-disable-next-line no-undefined
204
170
  undefined
205
171
  };
206
172
  });
207
173
  }
208
-
209
174
  addDependencies(dependencies);
210
175
  } catch (e) {
211
- callback(
212
- /** @type {Error} */
213
- e);
176
+ callback( /** @type {Error} */e);
214
177
  return;
215
178
  }
216
-
217
- const result = locals ? namedExport ? Object.keys(locals).map(key => `\nexport var ${key} = ${JSON.stringify(
218
- /** @type {{[key: string]: string }} */
219
- locals[key])};`).join("") : `\n${esModule ? "export default" : "module.exports ="} ${JSON.stringify(locals)};` : esModule ? `\nexport {};` : "";
179
+ const result = locals ? namedExport ? Object.keys(locals).map(key => `\nexport var ${key} = ${stringifyLocal( /** @type {Locals} */locals[key])};`).join("") : `\n${esModule ? "export default" : "module.exports ="} ${JSON.stringify(locals)};` : esModule ? `\nexport {};` : "";
220
180
  let resultSource = `// extracted by ${MiniCssExtractPlugin.pluginName}`;
221
- resultSource += this.hot ? hotLoader(result, {
181
+
182
+ // only attempt hotreloading if the css is actually used for something other than hash values
183
+ resultSource += this.hot && emit ? hotLoader(result, {
222
184
  loaderContext: this,
223
185
  options,
224
186
  locals
225
187
  }) : result;
226
188
  callback(null, resultSource);
227
189
  };
228
-
229
190
  let {
230
191
  publicPath
231
- } =
232
- /** @type {Compilation} */
192
+ } = /** @type {Compilation} */
233
193
  this._compilation.outputOptions;
234
-
235
194
  if (typeof options.publicPath === "string") {
236
195
  // eslint-disable-next-line prefer-destructuring
237
196
  publicPath = options.publicPath;
238
197
  } else if (typeof options.publicPath === "function") {
239
198
  publicPath = options.publicPath(this.resourcePath, this.rootContext);
240
199
  }
241
-
242
200
  if (publicPath === "auto") {
243
201
  publicPath = AUTO_PUBLIC_PATH;
244
202
  }
245
-
246
203
  if (typeof optionsFromPlugin.experimentalUseImportModule === "undefined" && typeof this.importModule === "function" || optionsFromPlugin.experimentalUseImportModule) {
247
204
  if (!this.importModule) {
248
205
  callback(new Error("You are using 'experimentalUseImportModule' but 'this.importModule' is not available in loader context. You need to have at least webpack 5.33.2."));
249
206
  return;
250
207
  }
251
-
252
208
  let publicPathForExtract;
253
-
254
209
  if (typeof publicPath === "string") {
255
210
  const isAbsolutePublicPath = /^[a-zA-Z][a-zA-Z\d+\-.]*?:/.test(publicPath);
256
211
  publicPathForExtract = isAbsolutePublicPath ? publicPath : `${ABSOLUTE_PUBLIC_PATH}${publicPath.replace(/\./g, SINGLE_DOT_PATH_SEGMENT)}`;
257
212
  } else {
258
213
  publicPathForExtract = publicPath;
259
214
  }
260
-
261
215
  this.importModule(`${this.resourcePath}.webpack[javascript/auto]!=!!!${request}`, {
262
216
  layer: options.layer,
263
- publicPath:
264
- /** @type {string} */
265
- publicPathForExtract,
217
+ publicPath: /** @type {string} */publicPathForExtract,
266
218
  baseUri: `${BASE_URI}/`
267
219
  },
268
220
  /**
@@ -274,12 +226,10 @@ function pitch(request) {
274
226
  callback(error);
275
227
  return;
276
228
  }
277
-
278
229
  handleExports(exports);
279
230
  });
280
231
  return;
281
232
  }
282
-
283
233
  const loaders = this.loaders.slice(this.loaderIndex + 1);
284
234
  this.addDependency(this.resourcePath);
285
235
  const childFilename = "*";
@@ -287,19 +237,20 @@ function pitch(request) {
287
237
  filename: childFilename,
288
238
  publicPath
289
239
  };
240
+ const childCompiler = /** @type {Compilation} */
241
+ this._compilation.createChildCompiler(`${MiniCssExtractPlugin.pluginName} ${request}`, outputOptions);
290
242
 
291
- const childCompiler =
292
- /** @type {Compilation} */
293
- this._compilation.createChildCompiler(`${MiniCssExtractPlugin.pluginName} ${request}`, outputOptions); // The templates are compiled and executed by NodeJS - similar to server side rendering
243
+ // The templates are compiled and executed by NodeJS - similar to server side rendering
294
244
  // Unfortunately this causes issues as some loaders require an absolute URL to support ES Modules
295
245
  // The following config enables relative URL support for the child compiler
296
-
297
-
298
- childCompiler.options.module = { ...childCompiler.options.module
246
+ childCompiler.options.module = {
247
+ ...childCompiler.options.module
299
248
  };
300
- childCompiler.options.module.parser = { ...childCompiler.options.module.parser
249
+ childCompiler.options.module.parser = {
250
+ ...childCompiler.options.module.parser
301
251
  };
302
- childCompiler.options.module.parser.javascript = { ...childCompiler.options.module.parser.javascript,
252
+ childCompiler.options.module.parser.javascript = {
253
+ ...childCompiler.options.module.parser.javascript,
303
254
  url: "relative"
304
255
  };
305
256
  const {
@@ -356,8 +307,8 @@ function pitch(request) {
356
307
  }
357
308
  });
358
309
  });
359
- /** @type {string | Buffer} */
360
310
 
311
+ /** @type {string | Buffer} */
361
312
  let source;
362
313
  childCompiler.hooks.compilation.tap(MiniCssExtractPlugin.pluginName,
363
314
  /**
@@ -365,8 +316,9 @@ function pitch(request) {
365
316
  */
366
317
  compilation => {
367
318
  compilation.hooks.processAssets.tap(MiniCssExtractPlugin.pluginName, () => {
368
- source = compilation.assets[childFilename] && compilation.assets[childFilename].source(); // Remove all chunk assets
319
+ source = compilation.assets[childFilename] && compilation.assets[childFilename].source();
369
320
 
321
+ // Remove all chunk assets
370
322
  compilation.chunks.forEach(chunk => {
371
323
  chunk.files.forEach(file => {
372
324
  compilation.deleteAsset(file);
@@ -379,61 +331,43 @@ function pitch(request) {
379
331
  callback(error);
380
332
  return;
381
333
  }
382
-
383
- if (
384
- /** @type {Compilation} */
385
- compilation.errors.length > 0) {
386
- callback(
387
- /** @type {Compilation} */
388
- compilation.errors[0]);
334
+ if ( /** @type {Compilation} */compilation.errors.length > 0) {
335
+ callback( /** @type {Compilation} */compilation.errors[0]);
389
336
  return;
390
337
  }
391
- /** @type {{ [name: string]: Source }} */
392
-
393
338
 
339
+ /** @type {{ [name: string]: Source }} */
394
340
  const assets = Object.create(null);
395
341
  /** @type {Map<string, AssetInfo>} */
396
-
397
342
  const assetsInfo = new Map();
398
-
399
- for (const asset of
400
- /** @type {Compilation} */
401
- compilation.getAssets()) {
343
+ for (const asset of /** @type {Compilation} */compilation.getAssets()) {
402
344
  assets[asset.name] = asset.source;
403
345
  assetsInfo.set(asset.name, asset.info);
404
346
  }
405
- /** @type {Compilation} */
406
-
407
347
 
348
+ /** @type {Compilation} */
408
349
  compilation.fileDependencies.forEach(dep => {
409
350
  this.addDependency(dep);
410
351
  }, this);
411
- /** @type {Compilation} */
412
352
 
353
+ /** @type {Compilation} */
413
354
  compilation.contextDependencies.forEach(dep => {
414
355
  this.addContextDependency(dep);
415
356
  }, this);
416
-
417
357
  if (!source) {
418
358
  callback(new Error("Didn't get a result from child compiler"));
419
359
  return;
420
360
  }
421
-
422
361
  let originalExports;
423
-
424
362
  try {
425
363
  originalExports = evalModuleCode(this, source, request);
426
364
  } catch (e) {
427
- callback(
428
- /** @type {Error} */
429
- e);
365
+ callback( /** @type {Error} */e);
430
366
  return;
431
367
  }
432
-
433
368
  handleExports(originalExports, compilation, assets, assetsInfo);
434
369
  });
435
370
  }
436
-
437
371
  module.exports = {
438
372
  default: function loader() {},
439
373
  pitch
@@ -1 +1 @@
1
- {"name":"mini-css-extract-plugin","author":"Tobias Koppers @sokra","license":"MIT","types":"types/index.d.ts"}
1
+ {"name":"mini-css-extract-plugin","version":"2.7.2","author":"Tobias Koppers @sokra","license":"MIT","types":"types/index.d.ts"}
@@ -1,135 +1,116 @@
1
1
  "use strict";
2
2
 
3
3
  const NativeModule = require("module");
4
-
5
4
  const path = require("path");
6
- /** @typedef {import("webpack").Compilation} Compilation */
7
5
 
6
+ /** @typedef {import("webpack").Compilation} Compilation */
8
7
  /** @typedef {import("webpack").Module} Module */
9
-
10
8
  /** @typedef {import("webpack").LoaderContext<any>} LoaderContext */
11
9
 
12
10
  /**
13
11
  * @returns {boolean}
14
12
  */
15
-
16
-
17
13
  function trueFn() {
18
14
  return true;
19
15
  }
16
+
20
17
  /**
21
18
  * @param {Compilation} compilation
22
19
  * @param {string | number} id
23
20
  * @returns {null | Module}
24
21
  */
25
-
26
-
27
22
  function findModuleById(compilation, id) {
28
23
  const {
29
24
  modules,
30
25
  chunkGraph
31
26
  } = compilation;
32
-
33
27
  for (const module of modules) {
34
28
  const moduleId = typeof chunkGraph !== "undefined" ? chunkGraph.getModuleId(module) : module.id;
35
-
36
29
  if (moduleId === id) {
37
30
  return module;
38
31
  }
39
32
  }
40
-
41
33
  return null;
42
34
  }
35
+
43
36
  /**
44
37
  * @param {LoaderContext} loaderContext
45
38
  * @param {string | Buffer} code
46
39
  * @param {string} filename
47
40
  * @returns {object}
48
41
  */
49
-
50
-
51
42
  function evalModuleCode(loaderContext, code, filename) {
52
43
  // @ts-ignore
53
- const module = new NativeModule(filename, loaderContext); // @ts-ignore
44
+ const module = new NativeModule(filename, loaderContext);
54
45
 
46
+ // @ts-ignore
55
47
  module.paths = NativeModule._nodeModulePaths(loaderContext.context); // eslint-disable-line no-underscore-dangle
56
-
57
- module.filename = filename; // @ts-ignore
58
-
48
+ module.filename = filename;
49
+ // @ts-ignore
59
50
  module._compile(code, filename); // eslint-disable-line no-underscore-dangle
60
51
 
61
-
62
52
  return module.exports;
63
53
  }
54
+
64
55
  /**
65
56
  * @param {string} a
66
57
  * @param {string} b
67
58
  * @returns {0 | 1 | -1}
68
59
  */
69
-
70
-
71
60
  function compareIds(a, b) {
72
61
  if (typeof a !== typeof b) {
73
62
  return typeof a < typeof b ? -1 : 1;
74
63
  }
75
-
76
64
  if (a < b) {
77
65
  return -1;
78
66
  }
79
-
80
67
  if (a > b) {
81
68
  return 1;
82
69
  }
83
-
84
70
  return 0;
85
71
  }
72
+
86
73
  /**
87
74
  * @param {Module} a
88
75
  * @param {Module} b
89
76
  * @returns {0 | 1 | -1}
90
77
  */
91
-
92
-
93
78
  function compareModulesByIdentifier(a, b) {
94
79
  return compareIds(a.identifier(), b.identifier());
95
80
  }
96
-
97
81
  const MODULE_TYPE = "css/mini-extract";
98
82
  const AUTO_PUBLIC_PATH = "__mini_css_extract_plugin_public_path_auto__";
99
83
  const ABSOLUTE_PUBLIC_PATH = "webpack:///mini-css-extract-plugin/";
100
84
  const BASE_URI = "webpack://";
101
85
  const SINGLE_DOT_PATH_SEGMENT = "__mini_css_extract_plugin_single_dot_path_segment__";
86
+
102
87
  /**
103
88
  * @param {string} str
104
89
  * @returns {boolean}
105
90
  */
106
-
107
91
  function isAbsolutePath(str) {
108
92
  return path.posix.isAbsolute(str) || path.win32.isAbsolute(str);
109
93
  }
110
-
111
94
  const RELATIVE_PATH_REGEXP = /^\.\.?[/\\]/;
95
+
112
96
  /**
113
97
  * @param {string} str
114
98
  * @returns {boolean}
115
99
  */
116
-
117
100
  function isRelativePath(str) {
118
101
  return RELATIVE_PATH_REGEXP.test(str);
119
- } // TODO simplify for the next major release
102
+ }
120
103
 
104
+ // TODO simplify for the next major release
121
105
  /**
122
106
  * @param {LoaderContext} loaderContext
123
107
  * @param {string} request
124
108
  * @returns {string}
125
109
  */
126
-
127
-
128
110
  function stringifyRequest(loaderContext, request) {
129
111
  if (typeof loaderContext.utils !== "undefined" && typeof loaderContext.utils.contextify === "function") {
130
112
  return JSON.stringify(loaderContext.utils.contextify(loaderContext.context || loaderContext.rootContext, request));
131
113
  }
132
-
133
114
  const splitted = request.split("!");
134
115
  const {
135
116
  context
@@ -139,40 +120,35 @@ function stringifyRequest(loaderContext, request) {
139
120
  const splittedPart = part.match(/^(.*?)(\?.*)/);
140
121
  const query = splittedPart ? splittedPart[2] : "";
141
122
  let singlePath = splittedPart ? splittedPart[1] : part;
142
-
143
123
  if (isAbsolutePath(singlePath) && context) {
144
124
  singlePath = path.relative(context, singlePath);
145
-
146
125
  if (isAbsolutePath(singlePath)) {
147
126
  // If singlePath still matches an absolute path, singlePath was on a different drive than context.
148
127
  // In this case, we leave the path platform-specific without replacing any separators.
149
128
  // @see https://github.com/webpack/loader-utils/pull/14
150
129
  return singlePath + query;
151
130
  }
152
-
153
131
  if (isRelativePath(singlePath) === false) {
154
132
  // Ensure that the relative path starts at least with ./ otherwise it would be a request into the modules directory (like node_modules).
155
133
  singlePath = `./${singlePath}`;
156
134
  }
157
135
  }
158
-
159
136
  return singlePath.replace(/\\/g, "/") + query;
160
137
  }).join("!"));
161
138
  }
139
+
162
140
  /**
163
141
  * @param {string} filename
164
142
  * @param {string} outputPath
165
143
  * @param {boolean} enforceRelative
166
144
  * @returns {string}
167
145
  */
168
-
169
-
170
146
  function getUndoPath(filename, outputPath, enforceRelative) {
171
147
  let depth = -1;
172
- let append = ""; // eslint-disable-next-line no-param-reassign
148
+ let append = "";
173
149
 
150
+ // eslint-disable-next-line no-param-reassign
174
151
  outputPath = outputPath.replace(/[\\/]$/, "");
175
-
176
152
  for (const part of filename.split(/[/\\]+/)) {
177
153
  if (part === "..") {
178
154
  if (depth > -1) {
@@ -182,13 +158,12 @@ function getUndoPath(filename, outputPath, enforceRelative) {
182
158
  const i = outputPath.lastIndexOf("/");
183
159
  const j = outputPath.lastIndexOf("\\");
184
160
  const pos = i < 0 ? j : j < 0 ? i : Math.max(i, j);
185
-
186
161
  if (pos < 0) {
187
162
  return `${outputPath}/`;
188
163
  }
164
+ append = `${outputPath.slice(pos + 1)}/${append}`;
189
165
 
190
- append = `${outputPath.slice(pos + 1)}/${append}`; // eslint-disable-next-line no-param-reassign
191
-
166
+ // eslint-disable-next-line no-param-reassign
192
167
  outputPath = outputPath.slice(0, pos);
193
168
  }
194
169
  } else if (part !== ".") {
@@ -196,10 +171,17 @@ function getUndoPath(filename, outputPath, enforceRelative) {
196
171
  depth++;
197
172
  }
198
173
  }
199
-
200
174
  return depth > 0 ? `${"../".repeat(depth)}${append}` : enforceRelative ? `./${append}` : append;
201
175
  }
202
176
 
177
+ /**
178
+ *
179
+ * @param {string | function} value
180
+ * @returns {string}
181
+ */
182
+ function stringifyLocal(value) {
183
+ return typeof value === "function" ? value.toString() : JSON.stringify(value);
184
+ }
203
185
  module.exports = {
204
186
  trueFn,
205
187
  findModuleById,
@@ -211,5 +193,6 @@ module.exports = {
211
193
  BASE_URI,
212
194
  SINGLE_DOT_PATH_SEGMENT,
213
195
  stringifyRequest,
196
+ stringifyLocal,
214
197
  getUndoPath
215
198
  };