webpack 5.100.2 → 5.101.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.
- package/README.md +12 -10
- package/bin/webpack.js +7 -7
- package/lib/APIPlugin.js +12 -14
- package/lib/AutomaticPrefetchPlugin.js +2 -2
- package/lib/BannerPlugin.js +4 -4
- package/lib/Cache.js +1 -1
- package/lib/CacheFacade.js +7 -7
- package/lib/CaseSensitiveModulesWarning.js +2 -2
- package/lib/Chunk.js +3 -3
- package/lib/ChunkGraph.js +63 -18
- package/lib/ChunkGroup.js +4 -4
- package/lib/CleanPlugin.js +19 -53
- package/lib/CodeGenerationResults.js +3 -3
- package/lib/CompatibilityPlugin.js +6 -6
- package/lib/Compilation.js +168 -116
- package/lib/Compiler.js +37 -37
- package/lib/ConcatenationScope.js +39 -1
- package/lib/ConstPlugin.js +11 -11
- package/lib/ContextExclusionPlugin.js +3 -3
- package/lib/ContextModule.js +12 -11
- package/lib/ContextModuleFactory.js +11 -11
- package/lib/ContextReplacementPlugin.js +5 -5
- package/lib/DefinePlugin.js +24 -22
- package/lib/DelegatedModuleFactoryPlugin.js +1 -1
- package/lib/Dependency.js +2 -1
- package/lib/DllEntryPlugin.js +1 -1
- package/lib/DllReferencePlugin.js +1 -1
- package/lib/DynamicEntryPlugin.js +3 -3
- package/lib/EntryPlugin.js +1 -1
- package/lib/EnvironmentPlugin.js +1 -1
- package/lib/ErrorHelpers.js +2 -2
- package/lib/EvalDevToolModulePlugin.js +2 -2
- package/lib/EvalSourceMapDevToolPlugin.js +5 -5
- package/lib/ExportsInfo.js +9 -9
- package/lib/ExportsInfoApiPlugin.js +2 -2
- package/lib/ExternalModule.js +163 -48
- package/lib/ExternalModuleFactoryPlugin.js +2 -2
- package/lib/ExternalsPlugin.js +45 -0
- package/lib/FileSystemInfo.js +64 -61
- package/lib/FlagAllModulesAsUsedPlugin.js +2 -2
- package/lib/FlagDependencyExportsPlugin.js +7 -7
- package/lib/FlagDependencyUsagePlugin.js +4 -4
- package/lib/FlagEntryExportAsUsedPlugin.js +1 -1
- package/lib/HotModuleReplacementPlugin.js +27 -27
- package/lib/IgnorePlugin.js +3 -3
- package/lib/IgnoreWarningsPlugin.js +4 -4
- package/lib/InitFragment.js +6 -0
- package/lib/InvalidDependenciesModuleWarning.js +1 -1
- package/lib/JavascriptMetaInfoPlugin.js +1 -1
- package/lib/LibManifestPlugin.js +2 -2
- package/lib/LoaderOptionsPlugin.js +1 -1
- package/lib/LoaderTargetPlugin.js +2 -2
- package/lib/MainTemplate.js +1 -1
- package/lib/Module.js +3 -2
- package/lib/ModuleFilenameHelpers.js +3 -3
- package/lib/ModuleGraph.js +23 -38
- package/lib/ModuleInfoHeaderPlugin.js +3 -3
- package/lib/ModuleParseError.js +5 -3
- package/lib/ModuleTemplate.js +3 -2
- package/lib/MultiCompiler.js +29 -24
- package/lib/MultiStats.js +18 -13
- package/lib/MultiWatching.js +1 -1
- package/lib/NoEmitOnErrorsPlugin.js +2 -2
- package/lib/NodeStuffPlugin.js +27 -15
- package/lib/NormalModule.js +23 -23
- package/lib/NormalModuleFactory.js +23 -21
- package/lib/NormalModuleReplacementPlugin.js +3 -3
- package/lib/PrefetchPlugin.js +1 -1
- package/lib/ProgressPlugin.js +11 -11
- package/lib/ProvidePlugin.js +2 -2
- package/lib/RecordIdsPlugin.js +3 -3
- package/lib/ResolverFactory.js +3 -3
- package/lib/RuntimeGlobals.js +20 -0
- package/lib/RuntimePlugin.js +16 -16
- package/lib/RuntimeTemplate.js +35 -26
- package/lib/SizeFormatHelpers.js +1 -1
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +4 -4
- package/lib/SourceMapDevToolPlugin.js +9 -9
- package/lib/Stats.js +2 -2
- package/lib/Template.js +1 -1
- package/lib/TemplatedPathPlugin.js +2 -2
- package/lib/UseStrictPlugin.js +1 -1
- package/lib/WarnCaseSensitiveModulesPlugin.js +1 -1
- package/lib/WarnDeprecatedOptionPlugin.js +1 -1
- package/lib/WarnNoModeSetPlugin.js +1 -1
- package/lib/WatchIgnorePlugin.js +2 -2
- package/lib/Watching.js +12 -14
- package/lib/WebpackIsIncludedPlugin.js +2 -2
- package/lib/WebpackOptionsApply.js +3 -3
- package/lib/asset/AssetGenerator.js +1 -1
- package/lib/asset/AssetModulesPlugin.js +6 -6
- package/lib/async-modules/AsyncModuleHelpers.js +1 -1
- package/lib/async-modules/AwaitDependenciesInitFragment.js +36 -24
- package/lib/async-modules/InferAsyncModulesPlugin.js +3 -3
- package/lib/buildChunkGraph.js +5 -5
- package/lib/cache/AddBuildDependenciesPlugin.js +1 -1
- package/lib/cache/IdleFileCachePlugin.js +5 -5
- package/lib/cache/PackFileCacheStrategy.js +20 -20
- package/lib/cache/ResolverCachePlugin.js +4 -4
- package/lib/cli.js +196 -14
- package/lib/config/browserslistTargetHandler.js +6 -6
- package/lib/config/defaults.js +23 -14
- package/lib/config/normalization.js +41 -38
- package/lib/config/target.js +4 -4
- package/lib/container/ContainerEntryModule.js +3 -3
- package/lib/container/ContainerPlugin.js +3 -3
- package/lib/container/ContainerReferencePlugin.js +3 -3
- package/lib/container/FallbackModule.js +1 -1
- package/lib/container/HoistContainerReferencesPlugin.js +7 -7
- package/lib/container/options.js +4 -4
- package/lib/css/CssGenerator.js +5 -3
- package/lib/css/CssLoadingRuntimeModule.js +1 -1
- package/lib/css/CssModulesPlugin.js +25 -22
- package/lib/css/CssParser.js +5 -5
- package/lib/css/walkCssTokens.js +9 -9
- package/lib/debug/ProfilingPlugin.js +5 -5
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +4 -4
- package/lib/dependencies/AMDPlugin.js +3 -3
- package/lib/dependencies/AMDRequireArrayDependency.js +1 -1
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +3 -3
- package/lib/dependencies/CommonJsExportRequireDependency.js +2 -2
- package/lib/dependencies/CommonJsExportsParserPlugin.js +12 -10
- package/lib/dependencies/CommonJsImportsParserPlugin.js +21 -19
- package/lib/dependencies/CommonJsPlugin.js +2 -2
- package/lib/dependencies/ContextDependency.js +1 -1
- package/lib/dependencies/ContextDependencyHelpers.js +3 -3
- package/lib/dependencies/CssIcssExportDependency.js +2 -2
- package/lib/dependencies/CssLocalIdentifierDependency.js +2 -2
- package/lib/dependencies/CssUrlDependency.js +4 -4
- package/lib/dependencies/DynamicExports.js +5 -5
- package/lib/dependencies/HarmonyAcceptDependency.js +91 -5
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +2 -2
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +17 -13
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +7 -8
- package/lib/dependencies/HarmonyExportInitFragment.js +1 -1
- package/lib/dependencies/HarmonyExports.js +1 -1
- package/lib/dependencies/HarmonyImportDependency.js +28 -9
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +56 -48
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +4 -5
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +3 -4
- package/lib/dependencies/HarmonyModulesPlugin.js +2 -8
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +1 -1
- package/lib/dependencies/ImportMetaContextDependencyParserPlugin.js +4 -4
- package/lib/dependencies/ImportMetaPlugin.js +7 -7
- package/lib/dependencies/ImportParserPlugin.js +4 -4
- package/lib/dependencies/JsonExportsDependency.js +7 -2
- package/lib/dependencies/LoaderPlugin.js +4 -4
- package/lib/dependencies/ModuleDependency.js +2 -1
- package/lib/dependencies/ProvidedDependency.js +2 -2
- package/lib/dependencies/PureExpressionDependency.js +1 -1
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +1 -1
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +1 -1
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +3 -3
- package/lib/dependencies/SystemPlugin.js +3 -3
- package/lib/dependencies/WorkerPlugin.js +5 -5
- package/lib/dependencies/getFunctionExpression.js +1 -1
- package/lib/esm/ExportWebpackRequireRuntimeModule.js +8 -1
- package/lib/esm/ModuleChunkFormatPlugin.js +35 -69
- package/lib/esm/ModuleChunkLoadingPlugin.js +3 -6
- package/lib/esm/ModuleChunkLoadingRuntimeModule.js +15 -11
- package/lib/formatLocation.js +2 -2
- package/lib/hmr/HotModuleReplacement.runtime.js +39 -27
- package/lib/hmr/JavascriptHotModuleReplacement.runtime.js +43 -32
- package/lib/hmr/JavascriptHotModuleReplacementHelper.js +1 -1
- package/lib/hmr/LazyCompilationPlugin.js +6 -6
- package/lib/hmr/lazyCompilationBackend.js +6 -6
- package/lib/ids/ChunkModuleIdRangePlugin.js +4 -4
- package/lib/ids/DeterministicChunkIdsPlugin.js +5 -4
- package/lib/ids/DeterministicModuleIdsPlugin.js +2 -2
- package/lib/ids/HashedModuleIdsPlugin.js +1 -1
- package/lib/ids/IdHelpers.js +9 -9
- package/lib/ids/NamedChunkIdsPlugin.js +5 -5
- package/lib/ids/NamedModuleIdsPlugin.js +2 -2
- package/lib/ids/NaturalChunkIdsPlugin.js +2 -2
- package/lib/ids/NaturalModuleIdsPlugin.js +1 -1
- package/lib/ids/OccurrenceChunkIdsPlugin.js +2 -2
- package/lib/ids/OccurrenceModuleIdsPlugin.js +4 -4
- package/lib/ids/SyncModuleIdsPlugin.js +4 -4
- package/lib/index.js +18 -6
- package/lib/javascript/ArrayPushCallbackChunkFormatPlugin.js +1 -1
- package/lib/javascript/BasicEvaluatedExpression.js +3 -3
- package/lib/javascript/ChunkFormatHelpers.js +70 -0
- package/lib/javascript/CommonJsChunkFormatPlugin.js +10 -21
- package/lib/javascript/EnableChunkLoadingPlugin.js +1 -1
- package/lib/javascript/JavascriptGenerator.js +1 -1
- package/lib/javascript/JavascriptModulesPlugin.js +108 -54
- package/lib/javascript/JavascriptParser.js +80 -78
- package/lib/javascript/JavascriptParserHelpers.js +3 -3
- package/lib/javascript/StartupHelpers.js +2 -2
- package/lib/json/JsonGenerator.js +2 -2
- package/lib/json/JsonModulesPlugin.js +2 -2
- package/lib/library/AbstractLibraryPlugin.js +30 -3
- package/lib/library/AmdLibraryPlugin.js +3 -3
- package/lib/library/AssignLibraryPlugin.js +2 -2
- package/lib/library/EnableLibraryPlugin.js +2 -2
- package/lib/library/ModuleLibraryPlugin.js +49 -31
- package/lib/library/SystemLibraryPlugin.js +6 -4
- package/lib/library/UmdLibraryPlugin.js +14 -14
- package/lib/logging/createConsoleLogger.js +4 -4
- package/lib/logging/runtime.js +3 -3
- package/lib/logging/truncateArgs.js +4 -4
- package/lib/node/CommonJsChunkLoadingPlugin.js +2 -2
- package/lib/node/NodeEnvironmentPlugin.js +1 -1
- package/lib/node/ReadFileChunkLoadingRuntimeModule.js +16 -14
- package/lib/node/ReadFileCompileAsyncWasmPlugin.js +7 -7
- package/lib/node/ReadFileCompileWasmPlugin.js +7 -7
- package/lib/node/RequireChunkLoadingRuntimeModule.js +13 -6
- package/lib/node/nodeConsole.js +2 -2
- package/lib/optimize/AggressiveMergingPlugin.js +2 -2
- package/lib/optimize/AggressiveSplittingPlugin.js +10 -10
- package/lib/optimize/ConcatenatedModule.js +186 -77
- package/lib/optimize/EnsureChunkConditionsPlugin.js +2 -2
- package/lib/optimize/FlagIncludedChunksPlugin.js +2 -2
- package/lib/optimize/InnerGraph.js +5 -5
- package/lib/optimize/InnerGraphPlugin.js +14 -12
- package/lib/optimize/LimitChunkCountPlugin.js +5 -5
- package/lib/optimize/MangleExportsPlugin.js +5 -5
- package/lib/optimize/MergeDuplicateChunksPlugin.js +2 -2
- package/lib/optimize/MinChunkSizePlugin.js +3 -3
- package/lib/optimize/ModuleConcatenationPlugin.js +45 -38
- package/lib/optimize/RealContentHashPlugin.js +23 -23
- package/lib/optimize/RemoveEmptyChunksPlugin.js +2 -2
- package/lib/optimize/RemoveParentModulesPlugin.js +3 -3
- package/lib/optimize/RuntimeChunkPlugin.js +2 -2
- package/lib/optimize/SideEffectsFlagPlugin.js +5 -5
- package/lib/optimize/SplitChunksPlugin.js +20 -20
- package/lib/performance/AssetsOverSizeLimitWarning.js +1 -1
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +2 -2
- package/lib/performance/SizeLimitsPlugin.js +4 -4
- package/lib/prefetch/ChunkPrefetchPreloadPlugin.js +1 -1
- package/lib/prefetch/ChunkPrefetchStartupRuntimeModule.js +3 -3
- package/lib/rules/BasicMatcherRulePlugin.js +1 -1
- package/lib/rules/RuleSetCompiler.js +10 -10
- package/lib/rules/UseEffectRulePlugin.js +2 -2
- package/lib/runtime/GetChunkFilenameRuntimeModule.js +19 -15
- package/lib/runtime/GetMainFilenameRuntimeModule.js +1 -1
- package/lib/runtime/GetTrustedTypesPolicyRuntimeModule.js +1 -1
- package/lib/runtime/MakeDeferredNamespaceObjectRuntime.js +1 -1
- package/lib/runtime/StartupChunkDependenciesPlugin.js +2 -2
- package/lib/runtime/StartupChunkDependenciesRuntimeModule.js +3 -3
- package/lib/schemes/DataUriPlugin.js +3 -3
- package/lib/schemes/FileUriPlugin.js +1 -1
- package/lib/schemes/HttpUriPlugin.js +40 -36
- package/lib/schemes/VirtualUrlPlugin.js +1 -1
- package/lib/serialization/BinaryMiddleware.js +11 -11
- package/lib/serialization/FileMiddleware.js +18 -17
- package/lib/serialization/ObjectMiddleware.js +8 -8
- package/lib/serialization/Serializer.js +2 -2
- package/lib/serialization/SerializerMiddleware.js +2 -2
- package/lib/sharing/ConsumeSharedPlugin.js +4 -4
- package/lib/sharing/ProvideSharedPlugin.js +4 -4
- package/lib/sharing/SharePlugin.js +1 -1
- package/lib/sharing/resolveMatchedConfigs.js +1 -1
- package/lib/stats/DefaultStatsFactoryPlugin.js +85 -80
- package/lib/stats/DefaultStatsPresetPlugin.js +15 -15
- package/lib/stats/DefaultStatsPrinterPlugin.js +87 -87
- package/lib/stats/StatsFactory.js +7 -7
- package/lib/stats/StatsPrinter.js +9 -9
- package/lib/url/URLParserPlugin.js +5 -5
- package/lib/util/AsyncQueue.js +4 -4
- package/lib/util/IterableHelpers.js +2 -2
- package/lib/util/LazyBucketSortedSet.js +3 -3
- package/lib/util/SetHelpers.js +2 -2
- package/lib/util/StackedCacheMap.js +1 -1
- package/lib/util/StackedMap.js +1 -1
- package/lib/util/TupleSet.js +1 -1
- package/lib/util/WeakTupleMap.js +1 -1
- package/lib/util/cleverMerge.js +8 -8
- package/lib/util/comparators.js +10 -10
- package/lib/util/compileBooleanMatcher.js +20 -20
- package/lib/util/concatenate.js +3 -3
- package/lib/util/conventions.js +4 -4
- package/lib/util/create-schema-validation.js +1 -1
- package/lib/util/createHash.js +1 -1
- package/lib/util/deprecation.js +4 -4
- package/lib/util/deterministicGrouping.js +7 -7
- package/lib/util/findGraphRoots.js +1 -1
- package/lib/util/fs.js +4 -4
- package/lib/util/identifier.js +14 -14
- package/lib/util/magicComment.js +5 -1
- package/lib/util/memoize.js +1 -1
- package/lib/util/processAsyncTree.js +2 -2
- package/lib/util/propertyName.js +1 -1
- package/lib/util/removeBOM.js +1 -1
- package/lib/util/runtime.js +6 -6
- package/lib/util/semver.js +16 -16
- package/lib/util/serialization.js +5 -5
- package/lib/util/smartGrouping.js +1 -1
- package/lib/validateSchema.js +2 -2
- package/lib/wasm/EnableWasmLoadingPlugin.js +1 -1
- package/lib/wasm-async/AsyncWasmLoadingRuntimeModule.js +1 -1
- package/lib/wasm-async/AsyncWebAssemblyJavascriptGenerator.js +1 -1
- package/lib/wasm-async/UniversalCompileAsyncWasmPlugin.js +4 -4
- package/lib/wasm-sync/WasmChunkLoadingRuntimeModule.js +13 -9
- package/lib/wasm-sync/WasmFinalizeExportsPlugin.js +2 -2
- package/lib/wasm-sync/WebAssemblyGenerator.js +16 -17
- package/lib/wasm-sync/WebAssemblyInInitialChunkError.js +4 -2
- package/lib/wasm-sync/WebAssemblyParser.js +2 -2
- package/lib/web/FetchCompileAsyncWasmPlugin.js +4 -4
- package/lib/web/FetchCompileWasmPlugin.js +4 -4
- package/lib/web/JsonpChunkLoadingPlugin.js +2 -2
- package/lib/web/JsonpChunkLoadingRuntimeModule.js +1 -1
- package/lib/webpack.js +17 -12
- package/lib/webworker/ImportScriptsChunkLoadingPlugin.js +2 -2
- package/lib/webworker/ImportScriptsChunkLoadingRuntimeModule.js +1 -1
- package/package.json +16 -16
- package/schemas/WebpackOptions.check.js +1 -1
- package/schemas/WebpackOptions.json +4 -0
- package/types.d.ts +275 -64
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
const { ConcatSource } = require("webpack-sources");
|
|
9
9
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
|
10
10
|
const Template = require("../Template");
|
|
11
|
+
const CommonJsSelfReferenceDependency = require("../dependencies/CommonJsSelfReferenceDependency");
|
|
11
12
|
const ConcatenatedModule = require("../optimize/ConcatenatedModule");
|
|
12
13
|
const propertyAccess = require("../util/propertyAccess");
|
|
13
14
|
const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
@@ -21,6 +22,7 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
|
21
22
|
/** @typedef {import("../Module")} Module */
|
|
22
23
|
/** @typedef {import("../Module").BuildMeta} BuildMeta */
|
|
23
24
|
/** @typedef {import("../javascript/JavascriptModulesPlugin").StartupRenderContext} StartupRenderContext */
|
|
25
|
+
/** @typedef {import("../javascript/JavascriptModulesPlugin").ModuleRenderContext} ModuleRenderContext */
|
|
24
26
|
/** @typedef {import("../util/Hash")} Hash */
|
|
25
27
|
|
|
26
28
|
/**
|
|
@@ -64,34 +66,10 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
64
66
|
apply(compiler) {
|
|
65
67
|
super.apply(compiler);
|
|
66
68
|
|
|
67
|
-
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
|
|
68
|
-
const {
|
|
69
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
70
|
+
const { onDemandExportsGeneration } =
|
|
69
71
|
ConcatenatedModule.getCompilationHooks(compilation);
|
|
70
|
-
|
|
71
|
-
// If we have connections not all modules were concatenated, so we need the wrapper
|
|
72
|
-
const connections =
|
|
73
|
-
compilation.moduleGraph.getIncomingConnections(module);
|
|
74
|
-
|
|
75
|
-
for (const connection of connections) {
|
|
76
|
-
if (connection.originModule) {
|
|
77
|
-
return false;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Runtime and splitting chunks now requires the wrapper too
|
|
82
|
-
for (const chunk of compilation.chunkGraph.getModuleChunksIterable(
|
|
83
|
-
module
|
|
84
|
-
)) {
|
|
85
|
-
if (
|
|
86
|
-
!chunk.hasRuntime() ||
|
|
87
|
-
compilation.chunkGraph.getNumberOfEntryModules(chunk) > 1
|
|
88
|
-
) {
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
return true;
|
|
94
|
-
});
|
|
72
|
+
onDemandExportsGeneration.tap(PLUGIN_NAME, (_module) => true);
|
|
95
73
|
});
|
|
96
74
|
}
|
|
97
75
|
|
|
@@ -123,10 +101,21 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
123
101
|
renderStartup(
|
|
124
102
|
source,
|
|
125
103
|
module,
|
|
126
|
-
{ moduleGraph, chunk, codeGenerationResults },
|
|
104
|
+
{ moduleGraph, chunk, codeGenerationResults, inlined, inlinedInIIFE },
|
|
127
105
|
{ options, compilation }
|
|
128
106
|
) {
|
|
129
107
|
const result = new ConcatSource(source);
|
|
108
|
+
|
|
109
|
+
if (!module.buildMeta || !module.buildMeta.exportsType) {
|
|
110
|
+
for (const dependency of module.dependencies) {
|
|
111
|
+
if (dependency instanceof CommonJsSelfReferenceDependency) {
|
|
112
|
+
result.add(`export { ${RuntimeGlobals.exports} as default }`);
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
|
|
130
119
|
const exportsInfo = options.export
|
|
131
120
|
? [
|
|
132
121
|
moduleGraph.getExportInfo(
|
|
@@ -136,8 +125,11 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
136
125
|
]
|
|
137
126
|
: moduleGraph.getExportsInfo(module).orderedExports;
|
|
138
127
|
const definitions =
|
|
139
|
-
|
|
140
|
-
|
|
128
|
+
inlined && !inlinedInIIFE
|
|
129
|
+
? (module.buildMeta &&
|
|
130
|
+
/** @type {GenerationMeta} */ module.buildMeta.exportsFinalName) ||
|
|
131
|
+
{}
|
|
132
|
+
: {};
|
|
141
133
|
/** @type {string[]} */
|
|
142
134
|
const shortHandedExports = [];
|
|
143
135
|
/** @type {[string, string][]} */
|
|
@@ -159,7 +151,7 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
159
151
|
|
|
160
152
|
let shouldContinue = false;
|
|
161
153
|
|
|
162
|
-
const reexport = exportInfo.findTarget(moduleGraph, _m => true);
|
|
154
|
+
const reexport = exportInfo.findTarget(moduleGraph, (_m) => true);
|
|
163
155
|
|
|
164
156
|
if (reexport) {
|
|
165
157
|
const exp = moduleGraph.getExportsInfo(reexport.module);
|
|
@@ -236,6 +228,32 @@ class ModuleLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
236
228
|
|
|
237
229
|
return result;
|
|
238
230
|
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* @param {Source} source source
|
|
234
|
+
* @param {Module} module module
|
|
235
|
+
* @param {ModuleRenderContext} renderContext render context
|
|
236
|
+
* @param {Omit<LibraryContext<T>, 'options'>} libraryContext context
|
|
237
|
+
* @returns {Source} source with library export
|
|
238
|
+
*/
|
|
239
|
+
renderModuleContent(
|
|
240
|
+
source,
|
|
241
|
+
module,
|
|
242
|
+
{ factory, inlinedInIIFE },
|
|
243
|
+
libraryContext
|
|
244
|
+
) {
|
|
245
|
+
const result = new ConcatSource(source);
|
|
246
|
+
// Re-add `factoryExportsBinding` to the source
|
|
247
|
+
// when the module is rendered as a factory or treated as an inlined (startup) module but wrapped in an IIFE
|
|
248
|
+
if (
|
|
249
|
+
(inlinedInIIFE || factory) &&
|
|
250
|
+
module.buildMeta &&
|
|
251
|
+
module.buildMeta.factoryExportsBinding
|
|
252
|
+
) {
|
|
253
|
+
result.add(module.buildMeta.factoryExportsBinding);
|
|
254
|
+
}
|
|
255
|
+
return result;
|
|
256
|
+
}
|
|
239
257
|
}
|
|
240
258
|
|
|
241
259
|
module.exports = ModuleLibraryPlugin;
|
|
@@ -73,7 +73,9 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
73
73
|
render(source, { chunkGraph, moduleGraph, chunk }, { options, compilation }) {
|
|
74
74
|
const modules = chunkGraph
|
|
75
75
|
.getChunkModules(chunk)
|
|
76
|
-
.filter(
|
|
76
|
+
.filter(
|
|
77
|
+
(m) => m instanceof ExternalModule && m.externalType === "system"
|
|
78
|
+
);
|
|
77
79
|
const externals = /** @type {ExternalModule[]} */ (modules);
|
|
78
80
|
|
|
79
81
|
// The name this bundle should be registered as with System
|
|
@@ -83,7 +85,7 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
83
85
|
|
|
84
86
|
// The array of dependencies that are external to webpack and will be provided by System
|
|
85
87
|
const systemDependencies = JSON.stringify(
|
|
86
|
-
externals.map(m =>
|
|
88
|
+
externals.map((m) =>
|
|
87
89
|
typeof m.request === "object" && !Array.isArray(m.request)
|
|
88
90
|
? m.request.amd
|
|
89
91
|
: m.request
|
|
@@ -95,7 +97,7 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
95
97
|
|
|
96
98
|
// An array of the internal variable names for the webpack externals
|
|
97
99
|
const externalWebpackNames = externals.map(
|
|
98
|
-
m =>
|
|
100
|
+
(m) =>
|
|
99
101
|
`__WEBPACK_EXTERNAL_MODULE_${Template.toIdentifier(
|
|
100
102
|
`${chunkGraph.getModuleId(m)}`
|
|
101
103
|
)}__`
|
|
@@ -103,7 +105,7 @@ class SystemLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
103
105
|
|
|
104
106
|
// Declaring variables for the internal variable names for the webpack externals
|
|
105
107
|
const externalVarDeclarations = externalWebpackNames
|
|
106
|
-
.map(name => `var ${name} = {};`)
|
|
108
|
+
.map((name) => `var ${name} = {};`)
|
|
107
109
|
.join("\n");
|
|
108
110
|
|
|
109
111
|
// Define __esModule flag on all internal variables and helpers
|
|
@@ -30,8 +30,8 @@ const AbstractLibraryPlugin = require("./AbstractLibraryPlugin");
|
|
|
30
30
|
* @param {string[]} accessor the accessor to convert to path
|
|
31
31
|
* @returns {string} the path
|
|
32
32
|
*/
|
|
33
|
-
const accessorToObjectAccess = accessor =>
|
|
34
|
-
accessor.map(a => `[${JSON.stringify(a)}]`).join("");
|
|
33
|
+
const accessorToObjectAccess = (accessor) =>
|
|
34
|
+
accessor.map((a) => `[${JSON.stringify(a)}]`).join("");
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* @param {string|undefined} base the path prefix
|
|
@@ -131,7 +131,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
131
131
|
const modules = chunkGraph
|
|
132
132
|
.getChunkModules(chunk)
|
|
133
133
|
.filter(
|
|
134
|
-
m =>
|
|
134
|
+
(m) =>
|
|
135
135
|
m instanceof ExternalModule &&
|
|
136
136
|
(m.externalType === "umd" || m.externalType === "umd2")
|
|
137
137
|
);
|
|
@@ -157,7 +157,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
157
157
|
* @param {string} str the string to replace
|
|
158
158
|
* @returns {string} the replaced keys
|
|
159
159
|
*/
|
|
160
|
-
const replaceKeys = str =>
|
|
160
|
+
const replaceKeys = (str) =>
|
|
161
161
|
compilation.getPath(str, {
|
|
162
162
|
chunk
|
|
163
163
|
});
|
|
@@ -166,10 +166,10 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
166
166
|
* @param {ExternalModule[]} modules external modules
|
|
167
167
|
* @returns {string} result
|
|
168
168
|
*/
|
|
169
|
-
const externalsDepsArray = modules =>
|
|
169
|
+
const externalsDepsArray = (modules) =>
|
|
170
170
|
`[${replaceKeys(
|
|
171
171
|
modules
|
|
172
|
-
.map(m =>
|
|
172
|
+
.map((m) =>
|
|
173
173
|
JSON.stringify(
|
|
174
174
|
typeof m.request === "object"
|
|
175
175
|
? /** @type {RequestRecord} */
|
|
@@ -184,10 +184,10 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
184
184
|
* @param {ExternalModule[]} modules external modules
|
|
185
185
|
* @returns {string} result
|
|
186
186
|
*/
|
|
187
|
-
const externalsRootArray = modules =>
|
|
187
|
+
const externalsRootArray = (modules) =>
|
|
188
188
|
replaceKeys(
|
|
189
189
|
modules
|
|
190
|
-
.map(m => {
|
|
190
|
+
.map((m) => {
|
|
191
191
|
let request = m.request;
|
|
192
192
|
if (typeof request === "object") {
|
|
193
193
|
request =
|
|
@@ -206,10 +206,10 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
206
206
|
* @param {string} type the type
|
|
207
207
|
* @returns {string} external require array
|
|
208
208
|
*/
|
|
209
|
-
const externalsRequireArray = type =>
|
|
209
|
+
const externalsRequireArray = (type) =>
|
|
210
210
|
replaceKeys(
|
|
211
211
|
externals
|
|
212
|
-
.map(m => {
|
|
212
|
+
.map((m) => {
|
|
213
213
|
let expr;
|
|
214
214
|
let request = m.request;
|
|
215
215
|
if (typeof request === "object") {
|
|
@@ -239,10 +239,10 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
239
239
|
* @param {ExternalModule[]} modules external modules
|
|
240
240
|
* @returns {string} arguments
|
|
241
241
|
*/
|
|
242
|
-
const externalsArguments = modules =>
|
|
242
|
+
const externalsArguments = (modules) =>
|
|
243
243
|
modules
|
|
244
244
|
.map(
|
|
245
|
-
m =>
|
|
245
|
+
(m) =>
|
|
246
246
|
`__WEBPACK_EXTERNAL_MODULE_${Template.toIdentifier(
|
|
247
247
|
`${chunkGraph.getModuleId(m)}`
|
|
248
248
|
)}__`
|
|
@@ -253,7 +253,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
253
253
|
* @param {string| string[]} library library name
|
|
254
254
|
* @returns {string} stringified library name
|
|
255
255
|
*/
|
|
256
|
-
const libraryName = library =>
|
|
256
|
+
const libraryName = (library) =>
|
|
257
257
|
JSON.stringify(
|
|
258
258
|
replaceKeys(
|
|
259
259
|
/** @type {string} */
|
|
@@ -287,7 +287,7 @@ class UmdLibraryPlugin extends AbstractLibraryPlugin {
|
|
|
287
287
|
* @param {keyof LibraryCustomUmdCommentObject} type type
|
|
288
288
|
* @returns {string} comment
|
|
289
289
|
*/
|
|
290
|
-
const getAuxiliaryComment = type => {
|
|
290
|
+
const getAuxiliaryComment = (type) => {
|
|
291
291
|
if (auxiliaryComment) {
|
|
292
292
|
if (typeof auxiliaryComment === "string") {
|
|
293
293
|
return `\t//${auxiliaryComment}\n`;
|
|
@@ -43,15 +43,15 @@ const { LogType } = require("./Logger");
|
|
|
43
43
|
* @param {FilterItemTypes} item an input item
|
|
44
44
|
* @returns {FilterFunction | undefined} filter function
|
|
45
45
|
*/
|
|
46
|
-
const filterToFunction = item => {
|
|
46
|
+
const filterToFunction = (item) => {
|
|
47
47
|
if (typeof item === "string") {
|
|
48
48
|
const regExp = new RegExp(
|
|
49
49
|
`[\\\\/]${item.replace(/[-[\]{}()*+?.\\^$|]/g, "\\$&")}([\\\\/]|$|!|\\?)`
|
|
50
50
|
);
|
|
51
|
-
return ident => regExp.test(ident);
|
|
51
|
+
return (ident) => regExp.test(ident);
|
|
52
52
|
}
|
|
53
53
|
if (item && typeof item === "object" && typeof item.test === "function") {
|
|
54
|
-
return ident => item.test(ident);
|
|
54
|
+
return (ident) => item.test(ident);
|
|
55
55
|
}
|
|
56
56
|
if (typeof item === "function") {
|
|
57
57
|
return item;
|
|
@@ -107,7 +107,7 @@ module.exports = ({ level = "info", debug = false, console }) => {
|
|
|
107
107
|
}
|
|
108
108
|
return [];
|
|
109
109
|
};
|
|
110
|
-
const debug = debugFilters.some(f => f(name));
|
|
110
|
+
const debug = debugFilters.some((f) => f(name));
|
|
111
111
|
switch (type) {
|
|
112
112
|
case LogType.debug:
|
|
113
113
|
if (!debug) return;
|
package/lib/logging/runtime.js
CHANGED
|
@@ -21,7 +21,7 @@ let currentDefaultLogger = createConsoleLogger(currentDefaultLoggerOptions);
|
|
|
21
21
|
* @param {createConsoleLogger.LoggerOptions} options new options, merge with old options
|
|
22
22
|
* @returns {void}
|
|
23
23
|
*/
|
|
24
|
-
module.exports.configureDefaultLogger = options => {
|
|
24
|
+
module.exports.configureDefaultLogger = (options) => {
|
|
25
25
|
Object.assign(currentDefaultLoggerOptions, options);
|
|
26
26
|
currentDefaultLogger = createConsoleLogger(currentDefaultLoggerOptions);
|
|
27
27
|
};
|
|
@@ -30,14 +30,14 @@ module.exports.configureDefaultLogger = options => {
|
|
|
30
30
|
* @param {string} name name of the logger
|
|
31
31
|
* @returns {Logger} a logger
|
|
32
32
|
*/
|
|
33
|
-
module.exports.getLogger = name =>
|
|
33
|
+
module.exports.getLogger = (name) =>
|
|
34
34
|
new Logger(
|
|
35
35
|
(type, args) => {
|
|
36
36
|
if (module.exports.hooks.log.call(name, type, args) === undefined) {
|
|
37
37
|
currentDefaultLogger(name, type, args);
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
|
-
childName => module.exports.getLogger(`${name}/${childName}`)
|
|
40
|
+
(childName) => module.exports.getLogger(`${name}/${childName}`)
|
|
41
41
|
);
|
|
42
42
|
|
|
43
43
|
module.exports.hooks = {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @param {Array<number>} array array of numbers
|
|
10
10
|
* @returns {number} sum of all numbers in array
|
|
11
11
|
*/
|
|
12
|
-
const arraySum = array => {
|
|
12
|
+
const arraySum = (array) => {
|
|
13
13
|
let sum = 0;
|
|
14
14
|
for (const item of array) sum += item;
|
|
15
15
|
return sum;
|
|
@@ -21,7 +21,7 @@ const arraySum = array => {
|
|
|
21
21
|
* @returns {string[]} truncated args
|
|
22
22
|
*/
|
|
23
23
|
const truncateArgs = (args, maxLength) => {
|
|
24
|
-
const lengths = args.map(a => `${a}`.length);
|
|
24
|
+
const lengths = args.map((a) => `${a}`.length);
|
|
25
25
|
const availableLength = maxLength - lengths.length + 1;
|
|
26
26
|
|
|
27
27
|
if (availableLength > 0 && args.length === 1) {
|
|
@@ -34,7 +34,7 @@ const truncateArgs = (args, maxLength) => {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
// Check if there is space for at least 4 chars per arg
|
|
37
|
-
if (availableLength < arraySum(lengths.map(i => Math.min(i, 6)))) {
|
|
37
|
+
if (availableLength < arraySum(lengths.map((i) => Math.min(i, 6)))) {
|
|
38
38
|
// remove args
|
|
39
39
|
if (args.length > 1) return truncateArgs(args.slice(0, -1), maxLength);
|
|
40
40
|
return [];
|
|
@@ -48,7 +48,7 @@ const truncateArgs = (args, maxLength) => {
|
|
|
48
48
|
// Try to remove chars from the longest items until it fits
|
|
49
49
|
while (currentLength > availableLength) {
|
|
50
50
|
const maxLength = Math.max(...lengths);
|
|
51
|
-
const shorterItems = lengths.filter(l => l !== maxLength);
|
|
51
|
+
const shorterItems = lengths.filter((l) => l !== maxLength);
|
|
52
52
|
const nextToMaxLength =
|
|
53
53
|
shorterItems.length > 0 ? Math.max(...shorterItems) : 0;
|
|
54
54
|
const maxReduce = maxLength - nextToMaxLength;
|
|
@@ -42,13 +42,13 @@ class CommonJsChunkLoadingPlugin {
|
|
|
42
42
|
chunkLoading: chunkLoadingValue,
|
|
43
43
|
asyncChunkLoading: this._asyncChunkLoading
|
|
44
44
|
}).apply(compiler);
|
|
45
|
-
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
|
|
45
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
46
46
|
const globalChunkLoading = compilation.outputOptions.chunkLoading;
|
|
47
47
|
/**
|
|
48
48
|
* @param {Chunk} chunk chunk
|
|
49
49
|
* @returns {boolean} true, if wasm loading is enabled for the chunk
|
|
50
50
|
*/
|
|
51
|
-
const isEnabledForChunk = chunk => {
|
|
51
|
+
const isEnabledForChunk = (chunk) => {
|
|
52
52
|
const options = chunk.getEntryOptions();
|
|
53
53
|
const chunkLoading =
|
|
54
54
|
options && options.chunkLoading !== undefined
|
|
@@ -57,7 +57,7 @@ class NodeEnvironmentPlugin {
|
|
|
57
57
|
compiler.outputFileSystem = fs;
|
|
58
58
|
compiler.intermediateFileSystem = fs;
|
|
59
59
|
compiler.watchFileSystem = new NodeWatchFileSystem(inputFileSystem);
|
|
60
|
-
compiler.hooks.beforeRun.tap(PLUGIN_NAME, compiler => {
|
|
60
|
+
compiler.hooks.beforeRun.tap(PLUGIN_NAME, (compiler) => {
|
|
61
61
|
if (
|
|
62
62
|
compiler.inputFileSystem === inputFileSystem &&
|
|
63
63
|
inputFileSystem.purge
|
|
@@ -21,6 +21,7 @@ const { getUndoPath } = require("../util/identifier");
|
|
|
21
21
|
/** @typedef {import("../Chunk")} Chunk */
|
|
22
22
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
|
23
23
|
/** @typedef {import("../Compilation")} Compilation */
|
|
24
|
+
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
|
24
25
|
/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
|
25
26
|
|
|
26
27
|
class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|
@@ -36,15 +37,16 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
36
37
|
* @private
|
|
37
38
|
* @param {Chunk} chunk chunk
|
|
38
39
|
* @param {string} rootOutputDir root output directory
|
|
40
|
+
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
|
39
41
|
* @returns {string} generated code
|
|
40
42
|
*/
|
|
41
|
-
_generateBaseUri(chunk, rootOutputDir) {
|
|
43
|
+
_generateBaseUri(chunk, rootOutputDir, runtimeTemplate) {
|
|
42
44
|
const options = chunk.getEntryOptions();
|
|
43
45
|
if (options && options.baseUri) {
|
|
44
46
|
return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
return `${RuntimeGlobals.baseURI} = require("url").pathToFileURL(${
|
|
49
|
+
return `${RuntimeGlobals.baseURI} = require(${runtimeTemplate.renderNodePrefixForCoreModule("url")}).pathToFileURL(${
|
|
48
50
|
rootOutputDir
|
|
49
51
|
? `__dirname + ${JSON.stringify(`/${rootOutputDir}`)}`
|
|
50
52
|
: "__filename"
|
|
@@ -99,7 +101,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
99
101
|
|
|
100
102
|
return Template.asString([
|
|
101
103
|
withBaseURI
|
|
102
|
-
? this._generateBaseUri(chunk, rootOutputDir)
|
|
104
|
+
? this._generateBaseUri(chunk, rootOutputDir, runtimeTemplate)
|
|
103
105
|
: "// no baseURI",
|
|
104
106
|
"",
|
|
105
107
|
"// object to store loaded chunks",
|
|
@@ -108,7 +110,7 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
108
110
|
stateExpression ? `${stateExpression} = ${stateExpression} || ` : ""
|
|
109
111
|
}{`,
|
|
110
112
|
Template.indent(
|
|
111
|
-
Array.from(initialChunkIds, id => `${JSON.stringify(id)}: 0`).join(
|
|
113
|
+
Array.from(initialChunkIds, (id) => `${JSON.stringify(id)}: 0`).join(
|
|
112
114
|
",\n"
|
|
113
115
|
)
|
|
114
116
|
),
|
|
@@ -171,17 +173,17 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
171
173
|
"var promise = new Promise(function(resolve, reject) {",
|
|
172
174
|
Template.indent([
|
|
173
175
|
"installedChunkData = installedChunks[chunkId] = [resolve, reject];",
|
|
174
|
-
`var filename = require(
|
|
176
|
+
`var filename = require(${runtimeTemplate.renderNodePrefixForCoreModule("path")}).join(__dirname, ${JSON.stringify(
|
|
175
177
|
rootOutputDir
|
|
176
178
|
)} + ${
|
|
177
179
|
RuntimeGlobals.getChunkScriptFilename
|
|
178
180
|
}(chunkId));`,
|
|
179
|
-
|
|
181
|
+
`require(${runtimeTemplate.renderNodePrefixForCoreModule("fs")}).readFile(filename, 'utf-8', function(err, content) {`,
|
|
180
182
|
Template.indent([
|
|
181
183
|
"if(err) return reject(err);",
|
|
182
184
|
"var chunk = {};",
|
|
183
|
-
|
|
184
|
-
|
|
185
|
+
`require(${runtimeTemplate.renderNodePrefixForCoreModule("vm")}).runInThisContext('(function(exports, require, __dirname, __filename) {' + content + '\\n})', filename)` +
|
|
186
|
+
`(chunk, require, require(${runtimeTemplate.renderNodePrefixForCoreModule("path")}).dirname(filename), filename);`,
|
|
185
187
|
"installChunk(chunk);"
|
|
186
188
|
]),
|
|
187
189
|
"});"
|
|
@@ -215,15 +217,15 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
215
217
|
Template.indent([
|
|
216
218
|
"return new Promise(function(resolve, reject) {",
|
|
217
219
|
Template.indent([
|
|
218
|
-
`var filename = require(
|
|
220
|
+
`var filename = require(${runtimeTemplate.renderNodePrefixForCoreModule("path")}).join(__dirname, ${JSON.stringify(
|
|
219
221
|
rootOutputDir
|
|
220
222
|
)} + ${RuntimeGlobals.getChunkUpdateScriptFilename}(chunkId));`,
|
|
221
|
-
|
|
223
|
+
`require(${runtimeTemplate.renderNodePrefixForCoreModule("fs")}).readFile(filename, 'utf-8', function(err, content) {`,
|
|
222
224
|
Template.indent([
|
|
223
225
|
"if(err) return reject(err);",
|
|
224
226
|
"var update = {};",
|
|
225
|
-
|
|
226
|
-
|
|
227
|
+
`require(${runtimeTemplate.renderNodePrefixForCoreModule("vm")}).runInThisContext('(function(exports, require, __dirname, __filename) {' + content + '\\n})', filename)` +
|
|
228
|
+
`(update, require, require(${runtimeTemplate.renderNodePrefixForCoreModule("path")}).dirname(filename), filename);`,
|
|
227
229
|
"var updatedModules = update.modules;",
|
|
228
230
|
"var runtime = update.runtime;",
|
|
229
231
|
"for(var moduleId in updatedModules) {",
|
|
@@ -255,10 +257,10 @@ class ReadFileChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
255
257
|
Template.indent([
|
|
256
258
|
"return new Promise(function(resolve, reject) {",
|
|
257
259
|
Template.indent([
|
|
258
|
-
`var filename = require(
|
|
260
|
+
`var filename = require(${runtimeTemplate.renderNodePrefixForCoreModule("path")}).join(__dirname, ${JSON.stringify(
|
|
259
261
|
rootOutputDir
|
|
260
262
|
)} + ${RuntimeGlobals.getUpdateManifestFilename}());`,
|
|
261
|
-
|
|
263
|
+
`require(${runtimeTemplate.renderNodePrefixForCoreModule("fs")}).readFile(filename, 'utf-8', function(err, content) {`,
|
|
262
264
|
Template.indent([
|
|
263
265
|
"if(err) {",
|
|
264
266
|
Template.indent([
|
|
@@ -34,13 +34,13 @@ class ReadFileCompileAsyncWasmPlugin {
|
|
|
34
34
|
* @returns {void}
|
|
35
35
|
*/
|
|
36
36
|
apply(compiler) {
|
|
37
|
-
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
|
|
37
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
38
38
|
const globalWasmLoading = compilation.outputOptions.wasmLoading;
|
|
39
39
|
/**
|
|
40
40
|
* @param {Chunk} chunk chunk
|
|
41
41
|
* @returns {boolean} true, if wasm loading is enabled for the chunk
|
|
42
42
|
*/
|
|
43
|
-
const isEnabledForChunk = chunk => {
|
|
43
|
+
const isEnabledForChunk = (chunk) => {
|
|
44
44
|
const options = chunk.getEntryOptions();
|
|
45
45
|
const wasmLoading =
|
|
46
46
|
options && options.wasmLoading !== undefined
|
|
@@ -53,7 +53,7 @@ class ReadFileCompileAsyncWasmPlugin {
|
|
|
53
53
|
* @type {(path: string) => string} callback to generate code to load the wasm file
|
|
54
54
|
*/
|
|
55
55
|
const generateLoadBinaryCode = this._import
|
|
56
|
-
? path =>
|
|
56
|
+
? (path) =>
|
|
57
57
|
Template.asString([
|
|
58
58
|
"Promise.all([import('fs'), import('url')]).then(([{ readFile }, { URL }]) => new Promise((resolve, reject) => {",
|
|
59
59
|
Template.indent([
|
|
@@ -70,14 +70,14 @@ class ReadFileCompileAsyncWasmPlugin {
|
|
|
70
70
|
]),
|
|
71
71
|
"}))"
|
|
72
72
|
])
|
|
73
|
-
: path =>
|
|
73
|
+
: (path) =>
|
|
74
74
|
Template.asString([
|
|
75
75
|
"new Promise(function (resolve, reject) {",
|
|
76
76
|
Template.indent([
|
|
77
77
|
"try {",
|
|
78
78
|
Template.indent([
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
`var { readFile } = require(${compilation.runtimeTemplate.renderNodePrefixForCoreModule("fs")});`,
|
|
80
|
+
`var { join } = require(${compilation.runtimeTemplate.renderNodePrefixForCoreModule("path")});`,
|
|
81
81
|
"",
|
|
82
82
|
`readFile(join(__dirname, ${path}), function(err, buffer){`,
|
|
83
83
|
Template.indent([
|
|
@@ -102,7 +102,7 @@ class ReadFileCompileAsyncWasmPlugin {
|
|
|
102
102
|
if (
|
|
103
103
|
!chunkGraph.hasModuleInGraph(
|
|
104
104
|
chunk,
|
|
105
|
-
m => m.type === WEBASSEMBLY_MODULE_TYPE_ASYNC
|
|
105
|
+
(m) => m.type === WEBASSEMBLY_MODULE_TYPE_ASYNC
|
|
106
106
|
)
|
|
107
107
|
) {
|
|
108
108
|
return;
|
|
@@ -37,13 +37,13 @@ class ReadFileCompileWasmPlugin {
|
|
|
37
37
|
* @returns {void}
|
|
38
38
|
*/
|
|
39
39
|
apply(compiler) {
|
|
40
|
-
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
|
|
40
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
|
|
41
41
|
const globalWasmLoading = compilation.outputOptions.wasmLoading;
|
|
42
42
|
/**
|
|
43
43
|
* @param {Chunk} chunk chunk
|
|
44
44
|
* @returns {boolean} true, when wasm loading is enabled for the chunk
|
|
45
45
|
*/
|
|
46
|
-
const isEnabledForChunk = chunk => {
|
|
46
|
+
const isEnabledForChunk = (chunk) => {
|
|
47
47
|
const options = chunk.getEntryOptions();
|
|
48
48
|
const wasmLoading =
|
|
49
49
|
options && options.wasmLoading !== undefined
|
|
@@ -56,7 +56,7 @@ class ReadFileCompileWasmPlugin {
|
|
|
56
56
|
* @type {(path: string) => string} callback to generate code to load the wasm file
|
|
57
57
|
*/
|
|
58
58
|
const generateLoadBinaryCode = this.options.import
|
|
59
|
-
? path =>
|
|
59
|
+
? (path) =>
|
|
60
60
|
Template.asString([
|
|
61
61
|
"Promise.all([import('fs'), import('url')]).then(([{ readFile }, { URL }]) => new Promise((resolve, reject) => {",
|
|
62
62
|
Template.indent([
|
|
@@ -73,12 +73,12 @@ class ReadFileCompileWasmPlugin {
|
|
|
73
73
|
]),
|
|
74
74
|
"}))"
|
|
75
75
|
])
|
|
76
|
-
: path =>
|
|
76
|
+
: (path) =>
|
|
77
77
|
Template.asString([
|
|
78
78
|
"new Promise(function (resolve, reject) {",
|
|
79
79
|
Template.indent([
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
`var { readFile } = require(${compilation.runtimeTemplate.renderNodePrefixForCoreModule("fs")});`,
|
|
81
|
+
`var { join } = require(${compilation.runtimeTemplate.renderNodePrefixForCoreModule("path")});`,
|
|
82
82
|
"",
|
|
83
83
|
"try {",
|
|
84
84
|
Template.indent([
|
|
@@ -105,7 +105,7 @@ class ReadFileCompileWasmPlugin {
|
|
|
105
105
|
if (
|
|
106
106
|
!chunkGraph.hasModuleInGraph(
|
|
107
107
|
chunk,
|
|
108
|
-
m => m.type === WEBASSEMBLY_MODULE_TYPE_SYNC
|
|
108
|
+
(m) => m.type === WEBASSEMBLY_MODULE_TYPE_SYNC
|
|
109
109
|
)
|
|
110
110
|
) {
|
|
111
111
|
return;
|
|
@@ -21,6 +21,7 @@ const { getUndoPath } = require("../util/identifier");
|
|
|
21
21
|
/** @typedef {import("../Chunk")} Chunk */
|
|
22
22
|
/** @typedef {import("../ChunkGraph")} ChunkGraph */
|
|
23
23
|
/** @typedef {import("../Compilation")} Compilation */
|
|
24
|
+
/** @typedef {import("../RuntimeTemplate")} RuntimeTemplate */
|
|
24
25
|
/** @typedef {import("../Module").ReadOnlyRuntimeRequirements} ReadOnlyRuntimeRequirements */
|
|
25
26
|
|
|
26
27
|
class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
|
@@ -36,15 +37,16 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
36
37
|
* @private
|
|
37
38
|
* @param {Chunk} chunk chunk
|
|
38
39
|
* @param {string} rootOutputDir root output directory
|
|
40
|
+
* @param {RuntimeTemplate} runtimeTemplate the runtime template
|
|
39
41
|
* @returns {string} generated code
|
|
40
42
|
*/
|
|
41
|
-
_generateBaseUri(chunk, rootOutputDir) {
|
|
43
|
+
_generateBaseUri(chunk, rootOutputDir, runtimeTemplate) {
|
|
42
44
|
const options = chunk.getEntryOptions();
|
|
43
45
|
if (options && options.baseUri) {
|
|
44
46
|
return `${RuntimeGlobals.baseURI} = ${JSON.stringify(options.baseUri)};`;
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
return `${RuntimeGlobals.baseURI} = require("url").pathToFileURL(${
|
|
49
|
+
return `${RuntimeGlobals.baseURI} = require(${runtimeTemplate.renderNodePrefixForCoreModule("url")}).pathToFileURL(${
|
|
48
50
|
rootOutputDir !== "./"
|
|
49
51
|
? `__dirname + ${JSON.stringify(`/${rootOutputDir}`)}`
|
|
50
52
|
: "__filename"
|
|
@@ -99,7 +101,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
99
101
|
|
|
100
102
|
return Template.asString([
|
|
101
103
|
withBaseURI
|
|
102
|
-
? this._generateBaseUri(chunk, rootOutputDir)
|
|
104
|
+
? this._generateBaseUri(chunk, rootOutputDir, runtimeTemplate)
|
|
103
105
|
: "// no baseURI",
|
|
104
106
|
"",
|
|
105
107
|
"// object to store loaded chunks",
|
|
@@ -108,7 +110,7 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
108
110
|
stateExpression ? `${stateExpression} = ${stateExpression} || ` : ""
|
|
109
111
|
}{`,
|
|
110
112
|
Template.indent(
|
|
111
|
-
Array.from(initialChunkIds, id => `${JSON.stringify(id)}: 1`).join(
|
|
113
|
+
Array.from(initialChunkIds, (id) => `${JSON.stringify(id)}: 1`).join(
|
|
112
114
|
",\n"
|
|
113
115
|
)
|
|
114
116
|
),
|
|
@@ -156,11 +158,16 @@ class RequireChunkLoadingRuntimeModule extends RuntimeModule {
|
|
|
156
158
|
? "if(true) { // all chunks have JS"
|
|
157
159
|
: `if(${hasJsMatcher("chunkId")}) {`,
|
|
158
160
|
Template.indent([
|
|
159
|
-
|
|
161
|
+
// The require function loads and runs a chunk. When the chunk is being run,
|
|
162
|
+
// it can call __webpack_require__.C to directly complete installed.
|
|
163
|
+
`var installedChunk = require(${JSON.stringify(
|
|
160
164
|
rootOutputDir
|
|
161
165
|
)} + ${
|
|
162
166
|
RuntimeGlobals.getChunkScriptFilename
|
|
163
|
-
}(chunkId))
|
|
167
|
+
}(chunkId));`,
|
|
168
|
+
"if (!installedChunks[chunkId]) {",
|
|
169
|
+
Template.indent(["installChunk(installedChunk);"]),
|
|
170
|
+
"}"
|
|
164
171
|
]),
|
|
165
172
|
"} else installedChunks[chunkId] = 1;",
|
|
166
173
|
""
|
package/lib/node/nodeConsole.js
CHANGED
|
@@ -130,8 +130,8 @@ module.exports = ({ colors, appendOnly, stream }) => {
|
|
|
130
130
|
currentIndent = currentIndent.slice(0, -2);
|
|
131
131
|
}
|
|
132
132
|
},
|
|
133
|
-
profile: console.profile && (name => console.profile(name)),
|
|
134
|
-
profileEnd: console.profileEnd && (name => console.profileEnd(name)),
|
|
133
|
+
profile: console.profile && ((name) => console.profile(name)),
|
|
134
|
+
profileEnd: console.profileEnd && ((name) => console.profileEnd(name)),
|
|
135
135
|
clear:
|
|
136
136
|
/** @type {() => void} */
|
|
137
137
|
(
|