webpack 5.36.0 → 5.37.1
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.
Potentially problematic release.
This version of webpack might be problematic. Click here for more details.
- package/README.md +5 -8
- package/bin/webpack.js +0 -0
- package/lib/CacheFacade.js +3 -3
- package/lib/Chunk.js +10 -5
- package/lib/ChunkGraph.js +58 -35
- package/lib/Compilation.js +116 -98
- package/lib/Compiler.js +31 -17
- package/lib/ConcatenationScope.js +2 -1
- package/lib/ContextModule.js +3 -3
- package/lib/ContextReplacementPlugin.js +4 -3
- package/lib/DefinePlugin.js +16 -12
- package/lib/EntryPlugin.js +1 -1
- package/lib/EvalSourceMapDevToolPlugin.js +3 -1
- package/lib/FileSystemInfo.js +25 -31
- package/lib/FlagDependencyExportsPlugin.js +8 -7
- package/lib/FlagDependencyUsagePlugin.js +2 -4
- package/lib/HotModuleReplacementPlugin.js +20 -30
- package/lib/InitFragment.js +21 -6
- package/lib/JavascriptMetaInfoPlugin.js +2 -1
- package/lib/MainTemplate.js +2 -3
- package/lib/ModuleFilenameHelpers.js +4 -2
- package/lib/ModuleGraph.js +2 -2
- package/lib/ModuleGraphConnection.js +6 -2
- package/lib/ModuleInfoHeaderPlugin.js +2 -3
- package/lib/MultiCompiler.js +31 -27
- package/lib/NormalModule.js +38 -7
- package/lib/NormalModuleFactory.js +27 -23
- package/lib/RecordIdsPlugin.js +5 -4
- package/lib/ResolverFactory.js +10 -7
- package/lib/RuntimeGlobals.js +7 -0
- package/lib/RuntimePlugin.js +19 -1
- package/lib/SourceMapDevToolPlugin.js +14 -15
- package/lib/Template.js +4 -2
- package/lib/Watching.js +83 -46
- package/lib/WebpackOptionsApply.js +1 -0
- package/lib/asset/AssetGenerator.js +19 -23
- package/lib/buildChunkGraph.js +28 -23
- package/lib/cache/PackFileCacheStrategy.js +77 -13
- package/lib/config/defaults.js +24 -10
- package/lib/config/normalization.js +17 -7
- package/lib/debug/ProfilingPlugin.js +4 -3
- package/lib/dependencies/AMDRequireDependency.js +3 -3
- package/lib/dependencies/CommonJsExportRequireDependency.js +2 -3
- package/lib/dependencies/CommonJsExportsParserPlugin.js +3 -1
- package/lib/dependencies/CommonJsImportsParserPlugin.js +2 -4
- package/lib/dependencies/CommonJsPlugin.js +8 -7
- package/lib/dependencies/CommonJsRequireContextDependency.js +2 -1
- package/lib/dependencies/ContextDependencyHelpers.js +10 -8
- package/lib/dependencies/CreateScriptUrlDependency.js +54 -0
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +11 -13
- package/lib/dependencies/HarmonyExportInitFragment.js +47 -0
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +2 -4
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +4 -11
- package/lib/dependencies/ImportDependency.js +3 -3
- package/lib/dependencies/ImportParserPlugin.js +2 -4
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +2 -3
- package/lib/dependencies/RequireEnsureDependency.js +3 -3
- package/lib/dependencies/WorkerDependency.js +6 -6
- package/lib/dependencies/WorkerPlugin.js +47 -20
- package/lib/hmr/LazyCompilationPlugin.js +6 -4
- package/lib/ids/HashedModuleIdsPlugin.js +3 -3
- package/lib/ids/OccurrenceModuleIdsPlugin.js +2 -3
- package/lib/index.js +5 -3
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +4 -6
- package/lib/javascript/CommonJsChunkFormatPlugin.js +2 -3
- package/lib/javascript/JavascriptGenerator.js +3 -1
- package/lib/javascript/JavascriptModulesPlugin.js +15 -23
- package/lib/javascript/JavascriptParser.js +10 -8
- package/lib/library/AssignLibraryPlugin.js +4 -2
- package/lib/node/NodeWatchFileSystem.js +19 -4
- package/lib/optimize/AggressiveSplittingPlugin.js +5 -4
- package/lib/optimize/ConcatenatedModule.js +22 -27
- package/lib/optimize/FlagIncludedChunksPlugin.js +4 -6
- package/lib/optimize/InnerGraph.js +9 -11
- package/lib/optimize/InnerGraphPlugin.js +3 -1
- package/lib/optimize/ModuleConcatenationPlugin.js +7 -10
- package/lib/optimize/RealContentHashPlugin.js +14 -16
- package/lib/optimize/SideEffectsFlagPlugin.js +6 -5
- package/lib/optimize/SplitChunksPlugin.js +13 -15
- package/lib/runtime/CreateScriptUrlRuntimeModule.js +61 -0
- package/lib/runtime/EnsureChunkRuntimeModule.js +9 -8
- package/lib/runtime/LoadScriptRuntimeModule.js +12 -5
- package/lib/runtime/OnChunksLoadedRuntimeModule.js +38 -37
- package/lib/serialization/BinaryMiddleware.js +2 -3
- package/lib/serialization/FileMiddleware.js +3 -1
- package/lib/serialization/ObjectMiddleware.js +11 -7
- package/lib/stats/DefaultStatsFactoryPlugin.js +2 -3
- package/lib/stats/DefaultStatsPrinterPlugin.js +11 -9
- package/lib/stats/StatsFactory.js +2 -1
- package/lib/stats/StatsPrinter.js +3 -3
- package/lib/util/LazyBucketSortedSet.js +3 -3
- package/lib/util/cleverMerge.js +3 -1
- package/lib/util/comparators.js +13 -13
- package/lib/util/fs.js +8 -8
- package/lib/util/identifier.js +2 -1
- package/lib/util/internalSerializables.js +2 -0
- package/lib/validateSchema.js +5 -3
- package/lib/wasm-async/AsyncWebAssemblyModulesPlugin.js +4 -4
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +5 -4
- package/lib/wasm-sync/WebAssemblyGenerator.js +89 -83
- package/lib/wasm-sync/WebAssemblyModulesPlugin.js +2 -1
- package/lib/wasm-sync/WebAssemblyParser.js +6 -5
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +2 -4
- package/lib/webpack.js +11 -7
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +13 -1
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +14 -4
- package/package.json +9 -6
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +103 -60
- package/types.d.ts +463 -280
package/lib/NormalModule.js
CHANGED
@@ -41,10 +41,12 @@ const { contextify, absolutify } = require("./util/identifier");
|
|
41
41
|
const makeSerializable = require("./util/makeSerializable");
|
42
42
|
const memoize = require("./util/memoize");
|
43
43
|
|
44
|
-
/** @typedef {import("source-map").RawSourceMap} SourceMap */
|
45
44
|
/** @typedef {import("webpack-sources").Source} Source */
|
45
|
+
/** @typedef {import("../declarations/LoaderContext").NormalModuleLoaderContext} NormalModuleLoaderContext */
|
46
|
+
/** @typedef {import("../declarations/WebpackOptions").Mode} Mode */
|
46
47
|
/** @typedef {import("../declarations/WebpackOptions").WebpackOptionsNormalized} WebpackOptions */
|
47
48
|
/** @typedef {import("./ChunkGraph")} ChunkGraph */
|
49
|
+
/** @typedef {import("./Compiler")} Compiler */
|
48
50
|
/** @typedef {import("./Dependency").UpdateHashContext} UpdateHashContext */
|
49
51
|
/** @typedef {import("./DependencyTemplates")} DependencyTemplates */
|
50
52
|
/** @typedef {import("./Generator")} Generator */
|
@@ -60,10 +62,22 @@ const memoize = require("./util/memoize");
|
|
60
62
|
/** @typedef {import("./RequestShortener")} RequestShortener */
|
61
63
|
/** @typedef {import("./ResolverFactory").ResolverWithOptions} ResolverWithOptions */
|
62
64
|
/** @typedef {import("./RuntimeTemplate")} RuntimeTemplate */
|
65
|
+
/** @typedef {import("./logging/Logger").Logger} WebpackLogger */
|
63
66
|
/** @typedef {import("./util/Hash")} Hash */
|
64
67
|
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
65
68
|
/** @typedef {import("./util/runtime").RuntimeSpec} RuntimeSpec */
|
66
69
|
|
70
|
+
/**
|
71
|
+
* @typedef {Object} SourceMap
|
72
|
+
* @property {number} version
|
73
|
+
* @property {string[]} sources
|
74
|
+
* @property {string} mappings
|
75
|
+
* @property {string=} file
|
76
|
+
* @property {string=} sourceRoot
|
77
|
+
* @property {string[]=} sourcesContent
|
78
|
+
* @property {string[]=} names
|
79
|
+
*/
|
80
|
+
|
67
81
|
const getInvalidDependenciesModuleWarning = memoize(() =>
|
68
82
|
require("./InvalidDependenciesModuleWarning")
|
69
83
|
);
|
@@ -262,6 +276,8 @@ class NormalModule extends Module {
|
|
262
276
|
this._source = null;
|
263
277
|
/** @private @type {Map<string, number> | undefined} **/
|
264
278
|
this._sourceSizes = undefined;
|
279
|
+
/** @private @type {Set<string>} */
|
280
|
+
this._sourceTypes = undefined;
|
265
281
|
|
266
282
|
// Cache
|
267
283
|
this._lastSuccessfulBuildMeta = {};
|
@@ -333,12 +349,19 @@ class NormalModule extends Module {
|
|
333
349
|
this.resource = m.resource;
|
334
350
|
this.matchResource = m.matchResource;
|
335
351
|
this.loaders = m.loaders;
|
352
|
+
this._sourceTypes = m._sourceTypes;
|
353
|
+
this._sourceSizes = m._sourceSizes;
|
336
354
|
}
|
337
355
|
|
338
356
|
/**
|
339
357
|
* Assuming this module is in the cache. Remove internal references to allow freeing some memory.
|
340
358
|
*/
|
341
359
|
cleanupForCache() {
|
360
|
+
// Make sure to cache types and sizes before cleanup
|
361
|
+
if (this._sourceTypes === undefined) this.getSourceTypes();
|
362
|
+
for (const type of this._sourceTypes) {
|
363
|
+
this.size(type);
|
364
|
+
}
|
342
365
|
super.cleanupForCache();
|
343
366
|
this.parser = undefined;
|
344
367
|
this.parserOptions = undefined;
|
@@ -376,6 +399,7 @@ class NormalModule extends Module {
|
|
376
399
|
this.type,
|
377
400
|
this.generatorOptions
|
378
401
|
);
|
402
|
+
// we assume the generator behaves identically and keep cached sourceTypes/Sizes
|
379
403
|
}
|
380
404
|
|
381
405
|
/**
|
@@ -421,7 +445,7 @@ class NormalModule extends Module {
|
|
421
445
|
* @param {WebpackOptions} options webpack options
|
422
446
|
* @param {Compilation} compilation the compilation
|
423
447
|
* @param {InputFileSystem} fs file system from reading
|
424
|
-
* @returns {
|
448
|
+
* @returns {NormalModuleLoaderContext} loader context
|
425
449
|
*/
|
426
450
|
createLoaderContext(resolver, options, compilation, fs) {
|
427
451
|
const { requestShortener } = compilation.runtimeTemplate;
|
@@ -751,7 +775,11 @@ class NormalModule extends Module {
|
|
751
775
|
},
|
752
776
|
(err, result) => {
|
753
777
|
// Cleanup loaderContext to avoid leaking memory in ICs
|
754
|
-
loaderContext._compilation =
|
778
|
+
loaderContext._compilation =
|
779
|
+
loaderContext._compiler =
|
780
|
+
loaderContext._module =
|
781
|
+
loaderContext.fs =
|
782
|
+
undefined;
|
755
783
|
|
756
784
|
if (!result) {
|
757
785
|
return processResult(
|
@@ -855,6 +883,7 @@ class NormalModule extends Module {
|
|
855
883
|
this._forceBuild = false;
|
856
884
|
this._source = null;
|
857
885
|
if (this._sourceSizes !== undefined) this._sourceSizes.clear();
|
886
|
+
this._sourceTypes = undefined;
|
858
887
|
this._ast = null;
|
859
888
|
this.error = null;
|
860
889
|
this.clearWarningsAndErrors();
|
@@ -944,7 +973,8 @@ class NormalModule extends Module {
|
|
944
973
|
checkDependencies(this.buildInfo.missingDependencies);
|
945
974
|
checkDependencies(this.buildInfo.contextDependencies);
|
946
975
|
if (nonAbsoluteDependencies !== undefined) {
|
947
|
-
const InvalidDependenciesModuleWarning =
|
976
|
+
const InvalidDependenciesModuleWarning =
|
977
|
+
getInvalidDependenciesModuleWarning();
|
948
978
|
this.addWarning(
|
949
979
|
new InvalidDependenciesModuleWarning(this, nonAbsoluteDependencies)
|
950
980
|
);
|
@@ -1056,7 +1086,10 @@ class NormalModule extends Module {
|
|
1056
1086
|
* @returns {Set<string>} types available (do not mutate)
|
1057
1087
|
*/
|
1058
1088
|
getSourceTypes() {
|
1059
|
-
|
1089
|
+
if (this._sourceTypes === undefined) {
|
1090
|
+
this._sourceTypes = this.generator.getTypes(this);
|
1091
|
+
}
|
1092
|
+
return this._sourceTypes;
|
1060
1093
|
}
|
1061
1094
|
|
1062
1095
|
/**
|
@@ -1245,7 +1278,6 @@ class NormalModule extends Module {
|
|
1245
1278
|
const { write } = context;
|
1246
1279
|
// deserialize
|
1247
1280
|
write(this._source);
|
1248
|
-
write(this._sourceSizes);
|
1249
1281
|
write(this.error);
|
1250
1282
|
write(this._lastSuccessfulBuildMeta);
|
1251
1283
|
write(this._forceBuild);
|
@@ -1277,7 +1309,6 @@ class NormalModule extends Module {
|
|
1277
1309
|
deserialize(context) {
|
1278
1310
|
const { read } = context;
|
1279
1311
|
this._source = read();
|
1280
|
-
this._sourceSizes = read();
|
1281
1312
|
this.error = read();
|
1282
1313
|
this._lastSuccessfulBuildMeta = read();
|
1283
1314
|
this._forceBuild = read();
|
@@ -520,29 +520,33 @@ class NormalModuleFactory extends ModuleFactory {
|
|
520
520
|
)
|
521
521
|
);
|
522
522
|
}
|
523
|
-
|
524
|
-
|
525
|
-
layer
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
523
|
+
try {
|
524
|
+
Object.assign(data.createData, {
|
525
|
+
layer:
|
526
|
+
layer === undefined ? contextInfo.issuerLayer || null : layer,
|
527
|
+
request: stringifyLoadersAndResource(
|
528
|
+
allLoaders,
|
529
|
+
resourceData.resource
|
530
|
+
),
|
531
|
+
userRequest,
|
532
|
+
rawRequest: request,
|
533
|
+
loaders: allLoaders,
|
534
|
+
resource: resourceData.resource,
|
535
|
+
matchResource: matchResourceData
|
536
|
+
? matchResourceData.resource
|
537
|
+
: undefined,
|
538
|
+
resourceResolveData: resourceData.data,
|
539
|
+
settings,
|
540
|
+
type,
|
541
|
+
parser: this.getParser(type, settings.parser),
|
542
|
+
parserOptions: settings.parser,
|
543
|
+
generator: this.getGenerator(type, settings.generator),
|
544
|
+
generatorOptions: settings.generator,
|
545
|
+
resolveOptions
|
546
|
+
});
|
547
|
+
} catch (e) {
|
548
|
+
return callback(e);
|
549
|
+
}
|
546
550
|
callback();
|
547
551
|
});
|
548
552
|
this.resolveRequestArray(
|
package/lib/RecordIdsPlugin.js
CHANGED
@@ -48,10 +48,11 @@ class RecordIdsPlugin {
|
|
48
48
|
apply(compiler) {
|
49
49
|
const portableIds = this.options.portableIds;
|
50
50
|
|
51
|
-
const makePathsRelative =
|
52
|
-
|
53
|
-
|
54
|
-
|
51
|
+
const makePathsRelative =
|
52
|
+
identifierUtils.makePathsRelative.bindContextCache(
|
53
|
+
compiler.context,
|
54
|
+
compiler.root
|
55
|
+
);
|
55
56
|
|
56
57
|
/**
|
57
58
|
* @param {Module} module the module
|
package/lib/ResolverFactory.js
CHANGED
@@ -42,9 +42,9 @@ const convertToResolveOptions = resolveOptionsWithDepType => {
|
|
42
42
|
...remaining,
|
43
43
|
plugins:
|
44
44
|
plugins &&
|
45
|
-
/** @type {ResolvePluginInstance[]} */ (
|
46
|
-
item => item !== "..."
|
47
|
-
)
|
45
|
+
/** @type {ResolvePluginInstance[]} */ (
|
46
|
+
plugins.filter(item => item !== "...")
|
47
|
+
)
|
48
48
|
};
|
49
49
|
|
50
50
|
if (!partialOptions.fileSystem) {
|
@@ -53,7 +53,10 @@ const convertToResolveOptions = resolveOptionsWithDepType => {
|
|
53
53
|
);
|
54
54
|
}
|
55
55
|
// These weird types validate that we checked all non-optional properties
|
56
|
-
const options =
|
56
|
+
const options =
|
57
|
+
/** @type {Partial<ResolveOptions> & Pick<ResolveOptions, "fileSystem">} */ (
|
58
|
+
partialOptions
|
59
|
+
);
|
57
60
|
|
58
61
|
return removeOperations(
|
59
62
|
resolveByProperty(options, "byDependency", dependencyType)
|
@@ -124,9 +127,9 @@ module.exports = class ResolverFactory {
|
|
124
127
|
const resolveOptions = convertToResolveOptions(
|
125
128
|
this.hooks.resolveOptions.for(type).call(resolveOptionsWithDepType)
|
126
129
|
);
|
127
|
-
const resolver = /** @type {ResolverWithOptions} */ (
|
128
|
-
resolveOptions
|
129
|
-
)
|
130
|
+
const resolver = /** @type {ResolverWithOptions} */ (
|
131
|
+
Factory.createResolver(resolveOptions)
|
132
|
+
);
|
130
133
|
if (!resolver) {
|
131
134
|
throw new Error("No resolver created");
|
132
135
|
}
|
package/lib/RuntimeGlobals.js
CHANGED
@@ -168,6 +168,13 @@ exports.scriptNonce = "__webpack_require__.nc";
|
|
168
168
|
*/
|
169
169
|
exports.loadScript = "__webpack_require__.l";
|
170
170
|
|
171
|
+
/**
|
172
|
+
* function to promote a string to a TrustedScriptURL using webpack's Trusted
|
173
|
+
* Types policy
|
174
|
+
* Arguments: (url: string) => TrustedScriptURL
|
175
|
+
*/
|
176
|
+
exports.createScriptUrl = "__webpack_require__.tu";
|
177
|
+
|
171
178
|
/**
|
172
179
|
* the chunk name of the chunk with the runtime
|
173
180
|
*/
|
package/lib/RuntimePlugin.js
CHANGED
@@ -13,6 +13,7 @@ const AutoPublicPathRuntimeModule = require("./runtime/AutoPublicPathRuntimeModu
|
|
13
13
|
const CompatGetDefaultExportRuntimeModule = require("./runtime/CompatGetDefaultExportRuntimeModule");
|
14
14
|
const CompatRuntimeModule = require("./runtime/CompatRuntimeModule");
|
15
15
|
const CreateFakeNamespaceObjectRuntimeModule = require("./runtime/CreateFakeNamespaceObjectRuntimeModule");
|
16
|
+
const CreateScriptUrlRuntimeModule = require("./runtime/CreateScriptUrlRuntimeModule");
|
16
17
|
const DefinePropertyGettersRuntimeModule = require("./runtime/DefinePropertyGettersRuntimeModule");
|
17
18
|
const EnsureChunkRuntimeModule = require("./runtime/EnsureChunkRuntimeModule");
|
18
19
|
const GetChunkFilenameRuntimeModule = require("./runtime/GetChunkFilenameRuntimeModule");
|
@@ -38,6 +39,7 @@ const GLOBALS_ON_REQUIRE = [
|
|
38
39
|
RuntimeGlobals.runtimeId,
|
39
40
|
RuntimeGlobals.compatGetDefaultExport,
|
40
41
|
RuntimeGlobals.createFakeNamespaceObject,
|
42
|
+
RuntimeGlobals.createScriptUrl,
|
41
43
|
RuntimeGlobals.definePropertyGetters,
|
42
44
|
RuntimeGlobals.ensureChunk,
|
43
45
|
RuntimeGlobals.entryModuleId,
|
@@ -319,7 +321,23 @@ class RuntimePlugin {
|
|
319
321
|
compilation.hooks.runtimeRequirementInTree
|
320
322
|
.for(RuntimeGlobals.loadScript)
|
321
323
|
.tap("RuntimePlugin", (chunk, set) => {
|
322
|
-
compilation.
|
324
|
+
const withCreateScriptUrl = !!compilation.outputOptions.trustedTypes;
|
325
|
+
if (withCreateScriptUrl) {
|
326
|
+
set.add(RuntimeGlobals.createScriptUrl);
|
327
|
+
}
|
328
|
+
compilation.addRuntimeModule(
|
329
|
+
chunk,
|
330
|
+
new LoadScriptRuntimeModule(withCreateScriptUrl)
|
331
|
+
);
|
332
|
+
return true;
|
333
|
+
});
|
334
|
+
compilation.hooks.runtimeRequirementInTree
|
335
|
+
.for(RuntimeGlobals.createScriptUrl)
|
336
|
+
.tap("RuntimePlugin", (chunk, set) => {
|
337
|
+
compilation.addRuntimeModule(
|
338
|
+
chunk,
|
339
|
+
new CreateScriptUrlRuntimeModule()
|
340
|
+
);
|
323
341
|
return true;
|
324
342
|
});
|
325
343
|
compilation.hooks.runtimeRequirementInTree
|
@@ -16,7 +16,6 @@ const createHash = require("./util/createHash");
|
|
16
16
|
const { relative, dirname } = require("./util/fs");
|
17
17
|
const { absolutify } = require("./util/identifier");
|
18
18
|
|
19
|
-
/** @typedef {import("source-map").RawSourceMap} SourceMap */
|
20
19
|
/** @typedef {import("webpack-sources").MapOptions} MapOptions */
|
21
20
|
/** @typedef {import("webpack-sources").Source} Source */
|
22
21
|
/** @typedef {import("../declarations/plugins/SourceMapDevToolPlugin").SourceMapDevToolPluginOptions} SourceMapDevToolPluginOptions */
|
@@ -26,6 +25,7 @@ const { absolutify } = require("./util/identifier");
|
|
26
25
|
/** @typedef {import("./Compilation").AssetInfo} AssetInfo */
|
27
26
|
/** @typedef {import("./Compiler")} Compiler */
|
28
27
|
/** @typedef {import("./Module")} Module */
|
28
|
+
/** @typedef {import("./NormalModule").SourceMap} SourceMap */
|
29
29
|
/** @typedef {import("./util/Hash")} Hash */
|
30
30
|
|
31
31
|
const validate = createSchemaValidation(
|
@@ -430,19 +430,20 @@ class SourceMapDevToolPlugin {
|
|
430
430
|
currentSourceMappingURLComment !== false &&
|
431
431
|
/\.css($|\?)/i.test(file)
|
432
432
|
) {
|
433
|
-
currentSourceMappingURLComment =
|
434
|
-
|
435
|
-
|
436
|
-
|
433
|
+
currentSourceMappingURLComment =
|
434
|
+
currentSourceMappingURLComment.replace(
|
435
|
+
/^\n\/\/(.*)$/,
|
436
|
+
"\n/*$1*/"
|
437
|
+
);
|
437
438
|
}
|
438
439
|
const sourceMapString = JSON.stringify(sourceMap);
|
439
440
|
if (sourceMapFilename) {
|
440
441
|
let filename = file;
|
441
442
|
const sourceMapContentHash =
|
442
443
|
usesContentHash &&
|
443
|
-
/** @type {string} */ (
|
444
|
-
.update(sourceMapString)
|
445
|
-
|
444
|
+
/** @type {string} */ (
|
445
|
+
createHash("md4").update(sourceMapString).digest("hex")
|
446
|
+
);
|
446
447
|
const pathParams = {
|
447
448
|
chunk,
|
448
449
|
filename: options.fileContext
|
@@ -454,13 +455,11 @@ class SourceMapDevToolPlugin {
|
|
454
455
|
: filename,
|
455
456
|
contentHash: sourceMapContentHash
|
456
457
|
};
|
457
|
-
const {
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
pathParams
|
463
|
-
);
|
458
|
+
const { path: sourceMapFile, info: sourceMapInfo } =
|
459
|
+
compilation.getPathWithInfo(
|
460
|
+
sourceMapFilename,
|
461
|
+
pathParams
|
462
|
+
);
|
464
463
|
const sourceMapUrl = options.publicPath
|
465
464
|
? options.publicPath + sourceMapFile
|
466
465
|
: relative(
|
package/lib/Template.js
CHANGED
@@ -413,5 +413,7 @@ class Template {
|
|
413
413
|
}
|
414
414
|
|
415
415
|
module.exports = Template;
|
416
|
-
module.exports.NUMBER_OF_IDENTIFIER_START_CHARS =
|
417
|
-
|
416
|
+
module.exports.NUMBER_OF_IDENTIFIER_START_CHARS =
|
417
|
+
NUMBER_OF_IDENTIFIER_START_CHARS;
|
418
|
+
module.exports.NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS =
|
419
|
+
NUMBER_OF_IDENTIFIER_CONTINUATION_CHARS;
|
package/lib/Watching.js
CHANGED
@@ -57,16 +57,53 @@ class Watching {
|
|
57
57
|
this._needRecords = true;
|
58
58
|
this.watcher = undefined;
|
59
59
|
this.pausedWatcher = undefined;
|
60
|
+
/** @type {Set<string>} */
|
61
|
+
this._collectedChangedFiles = undefined;
|
62
|
+
/** @type {Set<string>} */
|
63
|
+
this._collectedRemovedFiles = undefined;
|
60
64
|
this._done = this._done.bind(this);
|
61
65
|
process.nextTick(() => {
|
62
66
|
if (this._initial) this._invalidate();
|
63
67
|
});
|
64
68
|
}
|
65
69
|
|
66
|
-
|
70
|
+
_mergeWithCollected(changedFiles, removedFiles) {
|
71
|
+
if (!changedFiles) return;
|
72
|
+
if (!this._collectedChangedFiles) {
|
73
|
+
this._collectedChangedFiles = new Set(changedFiles);
|
74
|
+
this._collectedRemovedFiles = new Set(removedFiles);
|
75
|
+
} else {
|
76
|
+
for (const file of changedFiles) {
|
77
|
+
this._collectedChangedFiles.add(file);
|
78
|
+
this._collectedRemovedFiles.delete(file);
|
79
|
+
}
|
80
|
+
for (const file of removedFiles) {
|
81
|
+
this._collectedChangedFiles.delete(file);
|
82
|
+
this._collectedRemovedFiles.add(file);
|
83
|
+
}
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
_go(fileTimeInfoEntries, contextTimeInfoEntries, changedFiles, removedFiles) {
|
67
88
|
this._initial = false;
|
68
89
|
this.startTime = Date.now();
|
69
90
|
this.running = true;
|
91
|
+
if (this.watcher) {
|
92
|
+
this.pausedWatcher = this.watcher;
|
93
|
+
this.watcher.pause();
|
94
|
+
this.watcher = null;
|
95
|
+
}
|
96
|
+
this._mergeWithCollected(
|
97
|
+
changedFiles ||
|
98
|
+
(this.pausedWatcher &&
|
99
|
+
this.pausedWatcher.getAggregatedChanges &&
|
100
|
+
this.pausedWatcher.getAggregatedChanges()),
|
101
|
+
(this.compiler.removedFiles =
|
102
|
+
removedFiles ||
|
103
|
+
(this.pausedWatcher &&
|
104
|
+
this.pausedWatcher.getAggregatedRemovals &&
|
105
|
+
this.pausedWatcher.getAggregatedRemovals()))
|
106
|
+
);
|
70
107
|
const run = () => {
|
71
108
|
if (this.compiler.idle) {
|
72
109
|
return this.compiler.cache.endIdle(err => {
|
@@ -83,6 +120,19 @@ class Watching {
|
|
83
120
|
run();
|
84
121
|
});
|
85
122
|
}
|
123
|
+
|
124
|
+
this.compiler.modifiedFiles = this._collectedChangedFiles;
|
125
|
+
this._collectedChangedFiles = undefined;
|
126
|
+
this.compiler.removedFiles = this._collectedRemovedFiles;
|
127
|
+
this._collectedRemovedFiles = undefined;
|
128
|
+
|
129
|
+
this.compiler.fileTimestamps =
|
130
|
+
fileTimeInfoEntries ||
|
131
|
+
(this.pausedWatcher && this.pausedWatcher.getFileTimeInfoEntries());
|
132
|
+
this.compiler.contextTimestamps =
|
133
|
+
contextTimeInfoEntries ||
|
134
|
+
(this.pausedWatcher && this.pausedWatcher.getContextTimeInfoEntries());
|
135
|
+
|
86
136
|
this.invalid = false;
|
87
137
|
this._invalidReported = false;
|
88
138
|
this.compiler.hooks.watchRun.callAsync(this.compiler, err => {
|
@@ -159,13 +209,16 @@ class Watching {
|
|
159
209
|
|
160
210
|
let stats = null;
|
161
211
|
|
162
|
-
const handleError = err => {
|
212
|
+
const handleError = (err, cbs) => {
|
163
213
|
this.compiler.hooks.failed.call(err);
|
164
214
|
this.compiler.cache.beginIdle();
|
165
215
|
this.compiler.idle = true;
|
166
216
|
this.handler(err, stats);
|
167
|
-
|
168
|
-
|
217
|
+
if (!cbs) {
|
218
|
+
cbs = this.callbacks;
|
219
|
+
this.callbacks = [];
|
220
|
+
}
|
221
|
+
for (const cb of cbs) cb(err);
|
169
222
|
};
|
170
223
|
|
171
224
|
if (
|
@@ -197,17 +250,19 @@ class Watching {
|
|
197
250
|
}
|
198
251
|
if (err) return handleError(err);
|
199
252
|
|
253
|
+
const cbs = this.callbacks;
|
254
|
+
this.callbacks = [];
|
200
255
|
logger.time("done hook");
|
201
256
|
this.compiler.hooks.done.callAsync(stats, err => {
|
202
257
|
logger.timeEnd("done hook");
|
203
|
-
if (err) return handleError(err);
|
258
|
+
if (err) return handleError(err, cbs);
|
204
259
|
this.handler(null, stats);
|
205
260
|
logger.time("storeBuildDependencies");
|
206
261
|
this.compiler.cache.storeBuildDependencies(
|
207
262
|
compilation.buildDependencies,
|
208
263
|
err => {
|
209
264
|
logger.timeEnd("storeBuildDependencies");
|
210
|
-
if (err) return handleError(err);
|
265
|
+
if (err) return handleError(err, cbs);
|
211
266
|
logger.time("beginIdle");
|
212
267
|
this.compiler.cache.beginIdle();
|
213
268
|
this.compiler.idle = true;
|
@@ -221,8 +276,7 @@ class Watching {
|
|
221
276
|
);
|
222
277
|
}
|
223
278
|
});
|
224
|
-
for (const cb of
|
225
|
-
this.callbacks.length = 0;
|
279
|
+
for (const cb of cbs) cb(null);
|
226
280
|
this.compiler.hooks.afterDone.call(stats);
|
227
281
|
}
|
228
282
|
);
|
@@ -250,8 +304,6 @@ class Watching {
|
|
250
304
|
changedFiles,
|
251
305
|
removedFiles
|
252
306
|
) => {
|
253
|
-
this.pausedWatcher = this.watcher;
|
254
|
-
this.watcher = null;
|
255
307
|
if (err) {
|
256
308
|
this.compiler.modifiedFiles = undefined;
|
257
309
|
this.compiler.removedFiles = undefined;
|
@@ -259,16 +311,12 @@ class Watching {
|
|
259
311
|
this.compiler.contextTimestamps = undefined;
|
260
312
|
return this.handler(err);
|
261
313
|
}
|
262
|
-
this.
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
this.watcher.pause();
|
269
|
-
this.watcher = null;
|
270
|
-
}
|
271
|
-
this._invalidate();
|
314
|
+
this._invalidate(
|
315
|
+
fileTimeInfoEntries,
|
316
|
+
contextTimeInfoEntries,
|
317
|
+
changedFiles,
|
318
|
+
removedFiles
|
319
|
+
);
|
272
320
|
this._onChange();
|
273
321
|
},
|
274
322
|
(fileName, changeTime) => {
|
@@ -293,33 +341,30 @@ class Watching {
|
|
293
341
|
this._invalidReported = true;
|
294
342
|
this.compiler.hooks.invalid.call(null, Date.now());
|
295
343
|
}
|
344
|
+
this._onChange();
|
296
345
|
this._invalidate();
|
297
346
|
}
|
298
347
|
|
299
|
-
_invalidate(
|
300
|
-
|
301
|
-
|
302
|
-
|
348
|
+
_invalidate(
|
349
|
+
fileTimeInfoEntries,
|
350
|
+
contextTimeInfoEntries,
|
351
|
+
changedFiles,
|
352
|
+
removedFiles
|
353
|
+
) {
|
354
|
+
if (this.suspended || (this._isBlocked() && (this.blocked = true))) {
|
355
|
+
this._mergeWithCollected(changedFiles, removedFiles);
|
303
356
|
return;
|
304
357
|
}
|
305
|
-
if (this.watcher) {
|
306
|
-
this.compiler.modifiedFiles =
|
307
|
-
this.watcher.getAggregatedChanges &&
|
308
|
-
this.watcher.getAggregatedChanges();
|
309
|
-
this.compiler.removedFiles =
|
310
|
-
this.watcher.getAggregatedRemovals &&
|
311
|
-
this.watcher.getAggregatedRemovals();
|
312
|
-
this.compiler.fileTimestamps = this.watcher.getFileTimeInfoEntries();
|
313
|
-
this.compiler.contextTimestamps = this.watcher.getContextTimeInfoEntries();
|
314
|
-
this.pausedWatcher = this.watcher;
|
315
|
-
this.watcher.pause();
|
316
|
-
this.watcher = null;
|
317
|
-
}
|
318
358
|
|
319
359
|
if (this.running) {
|
320
360
|
this.invalid = true;
|
321
361
|
} else {
|
322
|
-
this._go(
|
362
|
+
this._go(
|
363
|
+
fileTimeInfoEntries,
|
364
|
+
contextTimeInfoEntries,
|
365
|
+
changedFiles,
|
366
|
+
removedFiles
|
367
|
+
);
|
323
368
|
}
|
324
369
|
}
|
325
370
|
|
@@ -334,14 +379,6 @@ class Watching {
|
|
334
379
|
}
|
335
380
|
}
|
336
381
|
|
337
|
-
_checkUnblocked() {
|
338
|
-
if (this.blocked && !this._isBlocked()) {
|
339
|
-
this.blocked = false;
|
340
|
-
this._needWatcherInfo = true;
|
341
|
-
this._invalidate();
|
342
|
-
}
|
343
|
-
}
|
344
|
-
|
345
382
|
/**
|
346
383
|
* @param {Callback<void>} callback signals when the watcher is closed
|
347
384
|
* @returns {void}
|
@@ -569,6 +569,7 @@ class WebpackOptionsApply extends OptionsApply {
|
|
569
569
|
),
|
570
570
|
snapshot: options.snapshot,
|
571
571
|
maxAge: cacheOptions.maxAge,
|
572
|
+
profile: cacheOptions.profile,
|
572
573
|
allowCollectingMemory: cacheOptions.allowCollectingMemory
|
573
574
|
}),
|
574
575
|
cacheOptions.idleTimeout,
|
@@ -170,9 +170,9 @@ class AssetGenerator extends Generator {
|
|
170
170
|
hash.update(runtimeTemplate.outputOptions.hashSalt);
|
171
171
|
}
|
172
172
|
hash.update(originalSource.buffer());
|
173
|
-
const fullHash = /** @type {string} */ (
|
174
|
-
runtimeTemplate.outputOptions.hashDigest
|
175
|
-
)
|
173
|
+
const fullHash = /** @type {string} */ (
|
174
|
+
hash.digest(runtimeTemplate.outputOptions.hashDigest)
|
175
|
+
);
|
176
176
|
const contentHash = fullHash.slice(
|
177
177
|
0,
|
178
178
|
runtimeTemplate.outputOptions.hashDigestLength
|
@@ -183,26 +183,9 @@ class AssetGenerator extends Generator {
|
|
183
183
|
module.matchResource || module.resource,
|
184
184
|
runtimeTemplate.compilation.compiler.root
|
185
185
|
).replace(/^\.\//, "");
|
186
|
-
let {
|
187
|
-
|
188
|
-
|
189
|
-
} = runtimeTemplate.compilation.getAssetPathWithInfo(
|
190
|
-
assetModuleFilename,
|
191
|
-
{
|
192
|
-
module,
|
193
|
-
runtime,
|
194
|
-
filename: sourceFilename,
|
195
|
-
chunkGraph,
|
196
|
-
contentHash
|
197
|
-
}
|
198
|
-
);
|
199
|
-
let publicPath;
|
200
|
-
if (this.publicPath) {
|
201
|
-
const {
|
202
|
-
path,
|
203
|
-
info
|
204
|
-
} = runtimeTemplate.compilation.getAssetPathWithInfo(
|
205
|
-
this.publicPath,
|
186
|
+
let { path: filename, info: assetInfo } =
|
187
|
+
runtimeTemplate.compilation.getAssetPathWithInfo(
|
188
|
+
assetModuleFilename,
|
206
189
|
{
|
207
190
|
module,
|
208
191
|
runtime,
|
@@ -211,6 +194,19 @@ class AssetGenerator extends Generator {
|
|
211
194
|
contentHash
|
212
195
|
}
|
213
196
|
);
|
197
|
+
let publicPath;
|
198
|
+
if (this.publicPath) {
|
199
|
+
const { path, info } =
|
200
|
+
runtimeTemplate.compilation.getAssetPathWithInfo(
|
201
|
+
this.publicPath,
|
202
|
+
{
|
203
|
+
module,
|
204
|
+
runtime,
|
205
|
+
filename: sourceFilename,
|
206
|
+
chunkGraph,
|
207
|
+
contentHash
|
208
|
+
}
|
209
|
+
);
|
214
210
|
publicPath = JSON.stringify(path);
|
215
211
|
assetInfo = mergeAssetInfo(assetInfo, info);
|
216
212
|
} else {
|