webpack 4.15.0 → 4.16.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -20
- package/README.md +761 -758
- package/SECURITY.md +9 -9
- package/buildin/amd-define.js +3 -3
- package/buildin/amd-options.js +2 -2
- package/buildin/global.js +20 -20
- package/buildin/harmony-module.js +24 -24
- package/buildin/module.js +22 -22
- package/buildin/system.js +7 -7
- package/hot/dev-server.js +61 -61
- package/hot/emitter.js +2 -2
- package/hot/log-apply-result.js +44 -44
- package/hot/log.js +45 -45
- package/hot/only-dev-server.js +105 -105
- package/hot/poll.js +40 -37
- package/hot/signal.js +62 -62
- package/lib/APIPlugin.js +84 -84
- package/lib/AmdMainTemplatePlugin.js +87 -87
- package/lib/AsyncDependencyToInitialChunkError.js +31 -31
- package/lib/AutomaticPrefetchPlugin.js +1 -1
- package/lib/BannerPlugin.js +117 -117
- package/lib/BasicEvaluatedExpression.js +211 -211
- package/lib/CachePlugin.js +102 -102
- package/lib/CaseSensitiveModulesWarning.js +67 -67
- package/lib/Chunk.js +833 -811
- package/lib/ChunkGroup.js +4 -4
- package/lib/ChunkRenderError.js +32 -32
- package/lib/CommentCompilationWarning.js +2 -2
- package/lib/CompatibilityPlugin.js +70 -70
- package/lib/Compilation.js +46 -15
- package/lib/ConcurrentCompilationError.js +19 -19
- package/lib/ConstPlugin.js +258 -258
- package/lib/ContextExclusionPlugin.js +28 -17
- package/lib/ContextModule.js +844 -739
- package/lib/ContextModuleFactory.js +262 -256
- package/lib/ContextReplacementPlugin.js +133 -133
- package/lib/DefinePlugin.js +49 -0
- package/lib/DelegatedModule.js +5 -0
- package/lib/DelegatedModuleFactoryPlugin.js +95 -89
- package/lib/DelegatedPlugin.js +39 -39
- package/lib/DependenciesBlock.js +1 -1
- package/lib/Dependency.js +10 -4
- package/lib/DllModule.js +60 -54
- package/lib/DllModuleFactory.js +29 -29
- package/lib/DllPlugin.js +44 -44
- package/lib/DllReferencePlugin.js +132 -84
- package/lib/EntryModuleNotFoundError.js +21 -21
- package/lib/Entrypoint.js +54 -54
- package/lib/EnvironmentPlugin.js +72 -65
- package/lib/ErrorHelpers.js +60 -60
- package/lib/EvalDevToolModulePlugin.js +27 -27
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +115 -115
- package/lib/EvalSourceMapDevToolPlugin.js +41 -41
- package/lib/ExportPropertyMainTemplatePlugin.js +53 -53
- package/lib/ExternalModule.js +165 -159
- package/lib/ExternalsPlugin.js +23 -23
- package/lib/FlagDependencyExportsPlugin.js +146 -146
- package/lib/FlagInitialModulesAsUsedPlugin.js +36 -36
- package/lib/FunctionModuleTemplatePlugin.js +100 -100
- package/lib/Generator.js +60 -52
- package/lib/HarmonyLinkingError.js +17 -17
- package/lib/HashedModuleIdsPlugin.js +53 -53
- package/lib/HotModuleReplacementPlugin.js +411 -413
- package/lib/IgnorePlugin.js +90 -90
- package/lib/JavascriptGenerator.js +229 -229
- package/lib/JavascriptModulesPlugin.js +179 -179
- package/lib/JsonGenerator.js +55 -55
- package/lib/JsonModulesPlugin.js +30 -30
- package/lib/JsonParser.js +27 -27
- package/lib/LibManifestPlugin.js +86 -86
- package/lib/LibraryTemplatePlugin.js +153 -153
- package/lib/LoaderOptionsPlugin.js +53 -53
- package/lib/LoaderTargetPlugin.js +24 -24
- package/lib/MemoryOutputFileSystem.js +5 -5
- package/lib/Module.js +431 -391
- package/lib/ModuleBuildError.js +52 -52
- package/lib/ModuleDependencyError.js +35 -35
- package/lib/ModuleDependencyWarning.js +25 -25
- package/lib/ModuleError.js +36 -36
- package/lib/ModuleFilenameHelpers.js +178 -178
- package/lib/ModuleNotFoundError.js +23 -23
- package/lib/ModuleParseError.js +57 -57
- package/lib/ModuleTemplate.js +93 -93
- package/lib/ModuleWarning.js +36 -36
- package/lib/MultiCompiler.js +283 -283
- package/lib/MultiModule.js +87 -81
- package/lib/MultiModuleFactory.js +23 -23
- package/lib/MultiStats.js +92 -92
- package/lib/MultiWatching.js +38 -38
- package/lib/NamedChunksPlugin.js +29 -29
- package/lib/NamedModulesPlugin.js +57 -57
- package/lib/NoEmitOnErrorsPlugin.js +20 -20
- package/lib/NoModeWarning.js +23 -23
- package/lib/NodeStuffPlugin.js +197 -179
- package/lib/NormalModule.js +542 -536
- package/lib/NormalModuleFactory.js +526 -526
- package/lib/NormalModuleReplacementPlugin.js +51 -51
- package/lib/NullFactory.js +12 -12
- package/lib/OptionsApply.js +10 -10
- package/lib/OptionsDefaulter.js +84 -84
- package/lib/Parser.js +2202 -2193
- package/lib/ParserHelpers.js +103 -103
- package/lib/PrefetchPlugin.js +37 -37
- package/lib/ProgressPlugin.js +246 -246
- package/lib/ProvidePlugin.js +86 -86
- package/lib/RawModule.js +56 -56
- package/lib/RecordIdsPlugin.js +230 -230
- package/lib/RemovedPluginError.js +11 -11
- package/lib/RequestShortener.js +83 -83
- package/lib/RequireJsStuffPlugin.js +69 -69
- package/lib/ResolverFactory.js +64 -64
- package/lib/RuntimeTemplate.js +12 -0
- package/lib/SetVarMainTemplatePlugin.js +69 -69
- package/lib/SingleEntryPlugin.js +6 -1
- package/lib/SizeFormatHelpers.js +24 -24
- package/lib/SourceMapDevToolModuleOptionsPlugin.js +49 -49
- package/lib/SourceMapDevToolPlugin.js +301 -301
- package/lib/Stats.js +28 -5
- package/lib/TemplatedPathPlugin.js +173 -173
- package/lib/UnsupportedFeatureWarning.js +22 -22
- package/lib/UseStrictPlugin.js +54 -54
- package/lib/WarnCaseSensitiveModulesPlugin.js +37 -37
- package/lib/WarnNoModeSetPlugin.js +17 -17
- package/lib/WatchIgnorePlugin.js +100 -100
- package/lib/Watching.js +194 -194
- package/lib/WebpackOptionsApply.js +92 -10
- package/lib/WebpackOptionsDefaulter.js +368 -354
- package/lib/debug/ProfilingPlugin.js +430 -430
- package/lib/dependencies/AMDPlugin.js +250 -250
- package/lib/dependencies/AMDRequireArrayDependency.js +49 -49
- package/lib/dependencies/AMDRequireContextDependency.js +20 -20
- package/lib/dependencies/AMDRequireDependency.js +135 -135
- package/lib/dependencies/AMDRequireItemDependency.js +22 -22
- package/lib/dependencies/CommonJsPlugin.js +161 -161
- package/lib/dependencies/CommonJsRequireContextDependency.js +23 -23
- package/lib/dependencies/CommonJsRequireDependency.js +22 -22
- package/lib/dependencies/CommonJsRequireDependencyParserPlugin.js +6 -0
- package/lib/dependencies/ConstDependency.js +33 -33
- package/lib/dependencies/ContextDependency.js +68 -68
- package/lib/dependencies/ContextDependencyHelpers.js +142 -142
- package/lib/dependencies/ContextDependencyTemplateAsId.js +42 -42
- package/lib/dependencies/ContextDependencyTemplateAsRequireCall.js +38 -38
- package/lib/dependencies/ContextElementDependency.js +21 -21
- package/lib/dependencies/CriticalDependencyWarning.js +20 -20
- package/lib/dependencies/DelegatedSourceDependency.js +18 -18
- package/lib/dependencies/DllEntryDependency.js +20 -20
- package/lib/dependencies/HarmonyAcceptDependency.js +45 -45
- package/lib/dependencies/HarmonyCompatibilityDependency.js +31 -31
- package/lib/dependencies/HarmonyDetectionParserPlugin.js +92 -92
- package/lib/dependencies/HarmonyExportDependencyParserPlugin.js +139 -139
- package/lib/dependencies/HarmonyExportHeaderDependency.js +30 -30
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +2 -1
- package/lib/dependencies/HarmonyImportDependency.js +109 -109
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +222 -222
- package/lib/dependencies/HarmonyImportSideEffectDependency.js +31 -31
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +167 -167
- package/lib/dependencies/HarmonyInitDependency.js +60 -60
- package/lib/dependencies/HarmonyModulesPlugin.js +146 -146
- package/lib/dependencies/HarmonyTopLevelThisParserPlugin.js +26 -26
- package/lib/dependencies/ImportContextDependency.js +23 -23
- package/lib/dependencies/ImportDependenciesBlock.js +18 -18
- package/lib/dependencies/ImportDependency.js +34 -34
- package/lib/dependencies/ImportEagerDependency.js +32 -32
- package/lib/dependencies/ImportParserPlugin.js +263 -263
- package/lib/dependencies/ImportPlugin.js +82 -82
- package/lib/dependencies/ImportWeakDependency.js +34 -34
- package/lib/dependencies/LoaderPlugin.js +18 -1
- package/lib/dependencies/LocalModule.js +23 -23
- package/lib/dependencies/LocalModulesHelpers.js +52 -52
- package/lib/dependencies/ModuleDependencyTemplateAsId.js +17 -17
- package/lib/dependencies/ModuleDependencyTemplateAsRequireId.js +17 -17
- package/lib/dependencies/ModuleHotAcceptDependency.js +23 -23
- package/lib/dependencies/ModuleHotDeclineDependency.js +23 -23
- package/lib/dependencies/NullDependency.js +20 -20
- package/lib/dependencies/PrefetchDependency.js +18 -18
- package/lib/dependencies/RequireContextDependency.js +22 -22
- package/lib/dependencies/RequireContextDependencyParserPlugin.js +56 -56
- package/lib/dependencies/RequireContextPlugin.js +143 -143
- package/lib/dependencies/RequireEnsureDependenciesBlock.js +33 -33
- package/lib/dependencies/RequireEnsureDependenciesBlockParserPlugin.js +116 -116
- package/lib/dependencies/RequireEnsureDependency.js +58 -58
- package/lib/dependencies/RequireEnsureItemDependency.js +21 -21
- package/lib/dependencies/RequireEnsurePlugin.js +74 -74
- package/lib/dependencies/RequireHeaderDependency.js +26 -26
- package/lib/dependencies/RequireIncludeDependencyParserPlugin.js +23 -23
- package/lib/dependencies/RequireIncludePlugin.js +61 -61
- package/lib/dependencies/RequireResolveContextDependency.js +23 -23
- package/lib/dependencies/RequireResolveDependency.js +22 -22
- package/lib/dependencies/RequireResolveDependencyParserPlugin.js +85 -85
- package/lib/dependencies/RequireResolveHeaderDependency.js +26 -26
- package/lib/dependencies/SystemPlugin.js +125 -125
- package/lib/dependencies/UnsupportedDependency.js +27 -27
- package/lib/dependencies/WebAssemblyExportImportedDependency.js +29 -29
- package/lib/dependencies/WebAssemblyImportDependency.js +48 -48
- package/lib/dependencies/WebpackMissingModule.js +20 -20
- package/lib/formatLocation.js +75 -61
- package/lib/node/NodeChunkTemplatePlugin.js +31 -31
- package/lib/node/NodeEnvironmentPlugin.js +28 -28
- package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
- package/lib/node/NodeMainTemplate.runtime.js +27 -27
- package/lib/node/NodeMainTemplatePlugin.js +323 -323
- package/lib/node/NodeOutputFileSystem.js +22 -22
- package/lib/node/NodeSourcePlugin.js +144 -144
- package/lib/node/NodeTargetPlugin.js +18 -18
- package/lib/node/NodeTemplatePlugin.js +31 -31
- package/lib/node/NodeWatchFileSystem.js +99 -99
- package/lib/node/ReadFileCompileWasmTemplatePlugin.js +61 -61
- package/lib/optimize/AggressiveMergingPlugin.js +87 -87
- package/lib/optimize/AggressiveSplittingPlugin.js +287 -287
- package/lib/optimize/ConcatenatedModule.js +5 -0
- package/lib/optimize/EnsureChunkConditionsPlugin.js +70 -70
- package/lib/optimize/FlagIncludedChunksPlugin.js +99 -99
- package/lib/optimize/LimitChunkCountPlugin.js +66 -66
- package/lib/optimize/MergeDuplicateChunksPlugin.js +78 -78
- package/lib/optimize/MinChunkSizePlugin.js +77 -77
- package/lib/optimize/NaturalChunkOrderPlugin.js +41 -0
- package/lib/optimize/OccurrenceChunkOrderPlugin.js +61 -0
- package/lib/optimize/OccurrenceModuleOrderPlugin.js +103 -0
- package/lib/optimize/OccurrenceOrderPlugin.js +135 -133
- package/lib/optimize/RemoveEmptyChunksPlugin.js +42 -42
- package/lib/optimize/RemoveParentModulesPlugin.js +127 -127
- package/lib/optimize/RuntimeChunkPlugin.js +41 -41
- package/lib/optimize/SideEffectsFlagPlugin.js +168 -168
- package/lib/optimize/SplitChunksPlugin.js +866 -850
- package/lib/performance/AssetsOverSizeLimitWarning.js +30 -30
- package/lib/performance/EntrypointsOverSizeLimitWarning.js +30 -30
- package/lib/performance/NoAsyncChunksWarning.js +21 -21
- package/lib/performance/SizeLimitsPlugin.js +105 -105
- package/lib/util/SortableSet.js +1 -0
- package/lib/util/StackedSetMap.js +144 -135
- package/lib/util/TrackingSet.js +35 -35
- package/lib/util/cachedMerge.js +35 -35
- package/lib/util/deterministicGrouping.js +251 -251
- package/lib/util/identifier.js +103 -103
- package/lib/util/objectToMap.js +16 -16
- package/lib/validateSchema.js +67 -67
- package/lib/wasm/UnsupportedWebAssemblyFeatureError.js +17 -17
- package/lib/wasm/WasmFinalizeExportsPlugin.js +1 -1
- package/lib/wasm/WebAssemblyGenerator.js +16 -2
- package/lib/wasm/WebAssemblyJavascriptGenerator.js +147 -133
- package/lib/wasm/WebAssemblyParser.js +174 -174
- package/lib/wasm/WebAssemblyUtils.js +59 -59
- package/lib/web/FetchCompileWasmTemplatePlugin.js +37 -37
- package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
- package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
- package/lib/web/JsonpMainTemplate.runtime.js +65 -65
- package/lib/web/JsonpMainTemplatePlugin.js +1 -1
- package/lib/web/JsonpTemplatePlugin.js +23 -23
- package/lib/web/WebEnvironmentPlugin.js +18 -18
- package/lib/webpack.js +5 -0
- package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
- package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
- package/lib/webworker/WebWorkerMainTemplate.runtime.js +65 -65
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +196 -196
- package/lib/webworker/WebWorkerTemplatePlugin.js +25 -25
- package/package.json +22 -13
- package/schemas/WebpackOptions.json +2062 -2036
- package/schemas/ajv.absolutePath.js +55 -55
- package/schemas/plugins/BannerPlugin.json +96 -96
- package/schemas/plugins/DllPlugin.json +32 -32
- package/schemas/plugins/DllReferencePlugin.json +99 -99
- package/schemas/plugins/HashedModuleIdsPlugin.json +24 -24
- package/schemas/plugins/LoaderOptionsPlugin.json +26 -26
- package/schemas/plugins/SourceMapDevToolPlugin.json +187 -187
- package/schemas/plugins/WatchIgnorePlugin.json +16 -16
- package/schemas/plugins/debug/ProfilingPlugin.json +12 -12
- package/schemas/plugins/optimize/AggressiveSplittingPlugin.json +22 -22
- package/schemas/plugins/optimize/LimitChunkCountPlugin.json +15 -15
- package/schemas/plugins/optimize/MinChunkSizePlugin.json +13 -13
- package/schemas/plugins/optimize/OccurrenceOrderChunkIdsPlugin.json +10 -0
- package/schemas/plugins/optimize/OccurrenceOrderModuleIdsPlugin.json +10 -0
package/lib/NormalModule.js
CHANGED
|
@@ -1,536 +1,542 @@
|
|
|
1
|
-
/*
|
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
-
Author Tobias Koppers @sokra
|
|
4
|
-
*/
|
|
5
|
-
"use strict";
|
|
6
|
-
|
|
7
|
-
const NativeModule = require("module");
|
|
8
|
-
|
|
9
|
-
const {
|
|
10
|
-
CachedSource,
|
|
11
|
-
LineToLineMappedSource,
|
|
12
|
-
OriginalSource,
|
|
13
|
-
RawSource,
|
|
14
|
-
SourceMapSource
|
|
15
|
-
} = require("webpack-sources");
|
|
16
|
-
const { getContext, runLoaders } = require("loader-runner");
|
|
17
|
-
|
|
18
|
-
const WebpackError = require("./WebpackError");
|
|
19
|
-
const Module = require("./Module");
|
|
20
|
-
const ModuleParseError = require("./ModuleParseError");
|
|
21
|
-
const ModuleBuildError = require("./ModuleBuildError");
|
|
22
|
-
const ModuleError = require("./ModuleError");
|
|
23
|
-
const ModuleWarning = require("./ModuleWarning");
|
|
24
|
-
const createHash = require("./util/createHash");
|
|
25
|
-
const contextify = require("./util/identifier").contextify;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
* @
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
this.
|
|
77
|
-
this.
|
|
78
|
-
this.
|
|
79
|
-
this.
|
|
80
|
-
this.
|
|
81
|
-
this.
|
|
82
|
-
this.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
this.
|
|
89
|
-
this.
|
|
90
|
-
|
|
91
|
-
this.
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
this
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
this.
|
|
125
|
-
this.
|
|
126
|
-
this.
|
|
127
|
-
this.
|
|
128
|
-
this.
|
|
129
|
-
this.
|
|
130
|
-
this.
|
|
131
|
-
this.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
// @ts-ignore
|
|
177
|
-
module
|
|
178
|
-
|
|
179
|
-
module.
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
this.loaders
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
this.buildInfo.
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const
|
|
297
|
-
const
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
extraInfo
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
this.
|
|
335
|
-
|
|
336
|
-
this.
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
//
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
if
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
this.
|
|
398
|
-
this.
|
|
399
|
-
this.
|
|
400
|
-
this.
|
|
401
|
-
this.
|
|
402
|
-
this.
|
|
403
|
-
this.
|
|
404
|
-
this.
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
if
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
this.
|
|
432
|
-
this
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
}
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
//
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
const NativeModule = require("module");
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
CachedSource,
|
|
11
|
+
LineToLineMappedSource,
|
|
12
|
+
OriginalSource,
|
|
13
|
+
RawSource,
|
|
14
|
+
SourceMapSource
|
|
15
|
+
} = require("webpack-sources");
|
|
16
|
+
const { getContext, runLoaders } = require("loader-runner");
|
|
17
|
+
|
|
18
|
+
const WebpackError = require("./WebpackError");
|
|
19
|
+
const Module = require("./Module");
|
|
20
|
+
const ModuleParseError = require("./ModuleParseError");
|
|
21
|
+
const ModuleBuildError = require("./ModuleBuildError");
|
|
22
|
+
const ModuleError = require("./ModuleError");
|
|
23
|
+
const ModuleWarning = require("./ModuleWarning");
|
|
24
|
+
const createHash = require("./util/createHash");
|
|
25
|
+
const contextify = require("./util/identifier").contextify;
|
|
26
|
+
|
|
27
|
+
/** @typedef {import("./util/createHash").Hash} Hash */
|
|
28
|
+
|
|
29
|
+
const asString = buf => {
|
|
30
|
+
if (Buffer.isBuffer(buf)) {
|
|
31
|
+
return buf.toString("utf-8");
|
|
32
|
+
}
|
|
33
|
+
return buf;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const asBuffer = str => {
|
|
37
|
+
if (!Buffer.isBuffer(str)) {
|
|
38
|
+
return Buffer.from(str, "utf-8");
|
|
39
|
+
}
|
|
40
|
+
return str;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
class NonErrorEmittedError extends WebpackError {
|
|
44
|
+
constructor(error) {
|
|
45
|
+
super();
|
|
46
|
+
|
|
47
|
+
this.name = "NonErrorEmittedError";
|
|
48
|
+
this.message = "(Emitted value instead of an instance of Error) " + error;
|
|
49
|
+
|
|
50
|
+
Error.captureStackTrace(this, this.constructor);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @typedef {Object} CachedSourceEntry
|
|
56
|
+
* @property {TODO} source the generated source
|
|
57
|
+
* @property {string} hash the hash value
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
class NormalModule extends Module {
|
|
61
|
+
constructor({
|
|
62
|
+
type,
|
|
63
|
+
request,
|
|
64
|
+
userRequest,
|
|
65
|
+
rawRequest,
|
|
66
|
+
loaders,
|
|
67
|
+
resource,
|
|
68
|
+
matchResource,
|
|
69
|
+
parser,
|
|
70
|
+
generator,
|
|
71
|
+
resolveOptions
|
|
72
|
+
}) {
|
|
73
|
+
super(type, getContext(resource));
|
|
74
|
+
|
|
75
|
+
// Info from Factory
|
|
76
|
+
this.request = request;
|
|
77
|
+
this.userRequest = userRequest;
|
|
78
|
+
this.rawRequest = rawRequest;
|
|
79
|
+
this.binary = type.startsWith("webassembly");
|
|
80
|
+
this.parser = parser;
|
|
81
|
+
this.generator = generator;
|
|
82
|
+
this.resource = resource;
|
|
83
|
+
this.matchResource = matchResource;
|
|
84
|
+
this.loaders = loaders;
|
|
85
|
+
if (resolveOptions !== undefined) this.resolveOptions = resolveOptions;
|
|
86
|
+
|
|
87
|
+
// Info from Build
|
|
88
|
+
this.error = null;
|
|
89
|
+
this._source = null;
|
|
90
|
+
this._buildHash = "";
|
|
91
|
+
this.buildTimestamp = undefined;
|
|
92
|
+
/** @private @type {Map<string, CachedSourceEntry>} */
|
|
93
|
+
this._cachedSources = new Map();
|
|
94
|
+
|
|
95
|
+
// Options for the NormalModule set by plugins
|
|
96
|
+
// TODO refactor this -> options object filled from Factory
|
|
97
|
+
this.useSourceMap = false;
|
|
98
|
+
this.lineToLine = false;
|
|
99
|
+
|
|
100
|
+
// Cache
|
|
101
|
+
this._lastSuccessfulBuildMeta = {};
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
identifier() {
|
|
105
|
+
return this.request;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
readableIdentifier(requestShortener) {
|
|
109
|
+
return requestShortener.shorten(this.userRequest);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
libIdent(options) {
|
|
113
|
+
return contextify(options.context, this.userRequest);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
nameForCondition() {
|
|
117
|
+
const resource = this.matchResource || this.resource;
|
|
118
|
+
const idx = resource.indexOf("?");
|
|
119
|
+
if (idx >= 0) return resource.substr(0, idx);
|
|
120
|
+
return resource;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
updateCacheModule(module) {
|
|
124
|
+
this.type = module.type;
|
|
125
|
+
this.request = module.request;
|
|
126
|
+
this.userRequest = module.userRequest;
|
|
127
|
+
this.rawRequest = module.rawRequest;
|
|
128
|
+
this.parser = module.parser;
|
|
129
|
+
this.generator = module.generator;
|
|
130
|
+
this.resource = module.resource;
|
|
131
|
+
this.matchResource = module.matchResource;
|
|
132
|
+
this.loaders = module.loaders;
|
|
133
|
+
this.resolveOptions = module.resolveOptions;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
createSourceForAsset(name, content, sourceMap) {
|
|
137
|
+
if (!sourceMap) {
|
|
138
|
+
return new RawSource(content);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (typeof sourceMap === "string") {
|
|
142
|
+
return new OriginalSource(content, sourceMap);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return new SourceMapSource(content, name, sourceMap);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
createLoaderContext(resolver, options, compilation, fs) {
|
|
149
|
+
const requestShortener = compilation.runtimeTemplate.requestShortener;
|
|
150
|
+
const loaderContext = {
|
|
151
|
+
version: 2,
|
|
152
|
+
emitWarning: warning => {
|
|
153
|
+
if (!(warning instanceof Error)) {
|
|
154
|
+
warning = new NonErrorEmittedError(warning);
|
|
155
|
+
}
|
|
156
|
+
const currentLoader = this.getCurrentLoader(loaderContext);
|
|
157
|
+
this.warnings.push(
|
|
158
|
+
new ModuleWarning(this, warning, {
|
|
159
|
+
from: requestShortener.shorten(currentLoader.loader)
|
|
160
|
+
})
|
|
161
|
+
);
|
|
162
|
+
},
|
|
163
|
+
emitError: error => {
|
|
164
|
+
if (!(error instanceof Error)) {
|
|
165
|
+
error = new NonErrorEmittedError(error);
|
|
166
|
+
}
|
|
167
|
+
const currentLoader = this.getCurrentLoader(loaderContext);
|
|
168
|
+
this.errors.push(
|
|
169
|
+
new ModuleError(this, error, {
|
|
170
|
+
from: requestShortener.shorten(currentLoader.loader)
|
|
171
|
+
})
|
|
172
|
+
);
|
|
173
|
+
},
|
|
174
|
+
// TODO remove in webpack 5
|
|
175
|
+
exec: (code, filename) => {
|
|
176
|
+
// @ts-ignore Argument of type 'this' is not assignable to parameter of type 'Module'.
|
|
177
|
+
const module = new NativeModule(filename, this);
|
|
178
|
+
// @ts-ignore _nodeModulePaths is deprecated and undocumented Node.js API
|
|
179
|
+
module.paths = NativeModule._nodeModulePaths(this.context);
|
|
180
|
+
module.filename = filename;
|
|
181
|
+
module._compile(code, filename);
|
|
182
|
+
return module.exports;
|
|
183
|
+
},
|
|
184
|
+
resolve(context, request, callback) {
|
|
185
|
+
resolver.resolve({}, context, request, {}, callback);
|
|
186
|
+
},
|
|
187
|
+
emitFile: (name, content, sourceMap) => {
|
|
188
|
+
if (!this.buildInfo.assets) {
|
|
189
|
+
this.buildInfo.assets = Object.create(null);
|
|
190
|
+
}
|
|
191
|
+
this.buildInfo.assets[name] = this.createSourceForAsset(
|
|
192
|
+
name,
|
|
193
|
+
content,
|
|
194
|
+
sourceMap
|
|
195
|
+
);
|
|
196
|
+
},
|
|
197
|
+
rootContext: options.context,
|
|
198
|
+
webpack: true,
|
|
199
|
+
sourceMap: !!this.useSourceMap,
|
|
200
|
+
_module: this,
|
|
201
|
+
_compilation: compilation,
|
|
202
|
+
_compiler: compilation.compiler,
|
|
203
|
+
fs: fs
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
compilation.hooks.normalModuleLoader.call(loaderContext, this);
|
|
207
|
+
if (options.loader) {
|
|
208
|
+
Object.assign(loaderContext, options.loader);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return loaderContext;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
getCurrentLoader(loaderContext, index = loaderContext.loaderIndex) {
|
|
215
|
+
if (
|
|
216
|
+
this.loaders &&
|
|
217
|
+
this.loaders.length &&
|
|
218
|
+
index < this.loaders.length &&
|
|
219
|
+
index >= 0 &&
|
|
220
|
+
this.loaders[index]
|
|
221
|
+
) {
|
|
222
|
+
return this.loaders[index];
|
|
223
|
+
}
|
|
224
|
+
return null;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
createSource(source, resourceBuffer, sourceMap) {
|
|
228
|
+
// if there is no identifier return raw source
|
|
229
|
+
if (!this.identifier) {
|
|
230
|
+
return new RawSource(source);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// from here on we assume we have an identifier
|
|
234
|
+
const identifier = this.identifier();
|
|
235
|
+
|
|
236
|
+
if (this.lineToLine && resourceBuffer) {
|
|
237
|
+
return new LineToLineMappedSource(
|
|
238
|
+
source,
|
|
239
|
+
identifier,
|
|
240
|
+
asString(resourceBuffer)
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (this.useSourceMap && sourceMap) {
|
|
245
|
+
return new SourceMapSource(source, identifier, sourceMap);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (Buffer.isBuffer(source)) {
|
|
249
|
+
// @ts-ignore
|
|
250
|
+
// TODO We need to fix @types/webpack-sources to allow RawSource to take a Buffer | string
|
|
251
|
+
return new RawSource(source);
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return new OriginalSource(source, identifier);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
doBuild(options, compilation, resolver, fs, callback) {
|
|
258
|
+
const loaderContext = this.createLoaderContext(
|
|
259
|
+
resolver,
|
|
260
|
+
options,
|
|
261
|
+
compilation,
|
|
262
|
+
fs
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
runLoaders(
|
|
266
|
+
{
|
|
267
|
+
resource: this.resource,
|
|
268
|
+
loaders: this.loaders,
|
|
269
|
+
context: loaderContext,
|
|
270
|
+
readResource: fs.readFile.bind(fs)
|
|
271
|
+
},
|
|
272
|
+
(err, result) => {
|
|
273
|
+
if (result) {
|
|
274
|
+
this.buildInfo.cacheable = result.cacheable;
|
|
275
|
+
this.buildInfo.fileDependencies = new Set(result.fileDependencies);
|
|
276
|
+
this.buildInfo.contextDependencies = new Set(
|
|
277
|
+
result.contextDependencies
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
if (err) {
|
|
282
|
+
if (!(err instanceof Error)) {
|
|
283
|
+
err = new NonErrorEmittedError(err);
|
|
284
|
+
}
|
|
285
|
+
const currentLoader = this.getCurrentLoader(loaderContext);
|
|
286
|
+
const error = new ModuleBuildError(this, err, {
|
|
287
|
+
from:
|
|
288
|
+
currentLoader &&
|
|
289
|
+
compilation.runtimeTemplate.requestShortener.shorten(
|
|
290
|
+
currentLoader.loader
|
|
291
|
+
)
|
|
292
|
+
});
|
|
293
|
+
return callback(error);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
const resourceBuffer = result.resourceBuffer;
|
|
297
|
+
const source = result.result[0];
|
|
298
|
+
const sourceMap = result.result.length >= 1 ? result.result[1] : null;
|
|
299
|
+
const extraInfo = result.result.length >= 2 ? result.result[2] : null;
|
|
300
|
+
|
|
301
|
+
if (!Buffer.isBuffer(source) && typeof source !== "string") {
|
|
302
|
+
const currentLoader = this.getCurrentLoader(loaderContext, 0);
|
|
303
|
+
const err = new Error(
|
|
304
|
+
`Final loader (${
|
|
305
|
+
currentLoader
|
|
306
|
+
? compilation.runtimeTemplate.requestShortener.shorten(
|
|
307
|
+
currentLoader.loader
|
|
308
|
+
)
|
|
309
|
+
: "unknown"
|
|
310
|
+
}) didn't return a Buffer or String`
|
|
311
|
+
);
|
|
312
|
+
const error = new ModuleBuildError(this, err);
|
|
313
|
+
return callback(error);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
this._source = this.createSource(
|
|
317
|
+
this.binary ? asBuffer(source) : asString(source),
|
|
318
|
+
resourceBuffer,
|
|
319
|
+
sourceMap
|
|
320
|
+
);
|
|
321
|
+
this._ast =
|
|
322
|
+
typeof extraInfo === "object" &&
|
|
323
|
+
extraInfo !== null &&
|
|
324
|
+
extraInfo.webpackAST !== undefined
|
|
325
|
+
? extraInfo.webpackAST
|
|
326
|
+
: null;
|
|
327
|
+
return callback();
|
|
328
|
+
}
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
markModuleAsErrored(error) {
|
|
333
|
+
// Restore build meta from successful build to keep importing state
|
|
334
|
+
this.buildMeta = Object.assign({}, this._lastSuccessfulBuildMeta);
|
|
335
|
+
|
|
336
|
+
this.error = error;
|
|
337
|
+
this.errors.push(this.error);
|
|
338
|
+
this._source = new RawSource(
|
|
339
|
+
"throw new Error(" + JSON.stringify(this.error.message) + ");"
|
|
340
|
+
);
|
|
341
|
+
this._ast = null;
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
applyNoParseRule(rule, content) {
|
|
345
|
+
// must start with "rule" if rule is a string
|
|
346
|
+
if (typeof rule === "string") {
|
|
347
|
+
return content.indexOf(rule) === 0;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
if (typeof rule === "function") {
|
|
351
|
+
return rule(content);
|
|
352
|
+
}
|
|
353
|
+
// we assume rule is a regexp
|
|
354
|
+
return rule.test(content);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// check if module should not be parsed
|
|
358
|
+
// returns "true" if the module should !not! be parsed
|
|
359
|
+
// returns "false" if the module !must! be parsed
|
|
360
|
+
shouldPreventParsing(noParseRule, request) {
|
|
361
|
+
// if no noParseRule exists, return false
|
|
362
|
+
// the module !must! be parsed.
|
|
363
|
+
if (!noParseRule) {
|
|
364
|
+
return false;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// we only have one rule to check
|
|
368
|
+
if (!Array.isArray(noParseRule)) {
|
|
369
|
+
// returns "true" if the module is !not! to be parsed
|
|
370
|
+
return this.applyNoParseRule(noParseRule, request);
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
for (let i = 0; i < noParseRule.length; i++) {
|
|
374
|
+
const rule = noParseRule[i];
|
|
375
|
+
// early exit on first truthy match
|
|
376
|
+
// this module is !not! to be parsed
|
|
377
|
+
if (this.applyNoParseRule(rule, request)) {
|
|
378
|
+
return true;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
// no match found, so this module !should! be parsed
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
_initBuildHash(compilation) {
|
|
386
|
+
const hash = createHash(compilation.outputOptions.hashFunction);
|
|
387
|
+
if (this._source) {
|
|
388
|
+
hash.update("source");
|
|
389
|
+
this._source.updateHash(hash);
|
|
390
|
+
}
|
|
391
|
+
hash.update("meta");
|
|
392
|
+
hash.update(JSON.stringify(this.buildMeta));
|
|
393
|
+
this._buildHash = hash.digest("hex");
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
build(options, compilation, resolver, fs, callback) {
|
|
397
|
+
this.buildTimestamp = Date.now();
|
|
398
|
+
this.built = true;
|
|
399
|
+
this._source = null;
|
|
400
|
+
this._ast = null;
|
|
401
|
+
this._buildHash = "";
|
|
402
|
+
this.error = null;
|
|
403
|
+
this.errors.length = 0;
|
|
404
|
+
this.warnings.length = 0;
|
|
405
|
+
this.buildMeta = {};
|
|
406
|
+
this.buildInfo = {
|
|
407
|
+
cacheable: false,
|
|
408
|
+
fileDependencies: new Set(),
|
|
409
|
+
contextDependencies: new Set()
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
return this.doBuild(options, compilation, resolver, fs, err => {
|
|
413
|
+
this._cachedSources.clear();
|
|
414
|
+
|
|
415
|
+
// if we have an error mark module as failed and exit
|
|
416
|
+
if (err) {
|
|
417
|
+
this.markModuleAsErrored(err);
|
|
418
|
+
this._initBuildHash(compilation);
|
|
419
|
+
return callback();
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// check if this module should !not! be parsed.
|
|
423
|
+
// if so, exit here;
|
|
424
|
+
const noParseRule = options.module && options.module.noParse;
|
|
425
|
+
if (this.shouldPreventParsing(noParseRule, this.request)) {
|
|
426
|
+
this._initBuildHash(compilation);
|
|
427
|
+
return callback();
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
const handleParseError = e => {
|
|
431
|
+
const source = this._source.source();
|
|
432
|
+
const error = new ModuleParseError(this, source, e);
|
|
433
|
+
this.markModuleAsErrored(error);
|
|
434
|
+
this._initBuildHash(compilation);
|
|
435
|
+
return callback();
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
const handleParseResult = result => {
|
|
439
|
+
this._lastSuccessfulBuildMeta = this.buildMeta;
|
|
440
|
+
this._initBuildHash(compilation);
|
|
441
|
+
return callback();
|
|
442
|
+
};
|
|
443
|
+
|
|
444
|
+
try {
|
|
445
|
+
const result = this.parser.parse(
|
|
446
|
+
this._ast || this._source.source(),
|
|
447
|
+
{
|
|
448
|
+
current: this,
|
|
449
|
+
module: this,
|
|
450
|
+
compilation: compilation,
|
|
451
|
+
options: options
|
|
452
|
+
},
|
|
453
|
+
(err, result) => {
|
|
454
|
+
if (err) {
|
|
455
|
+
handleParseError(err);
|
|
456
|
+
} else {
|
|
457
|
+
handleParseResult(result);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
);
|
|
461
|
+
if (result !== undefined) {
|
|
462
|
+
// parse is sync
|
|
463
|
+
handleParseResult(result);
|
|
464
|
+
}
|
|
465
|
+
} catch (e) {
|
|
466
|
+
handleParseError(e);
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
getHashDigest(dependencyTemplates) {
|
|
472
|
+
// TODO webpack 5 refactor
|
|
473
|
+
let dtHash = dependencyTemplates.get("hash");
|
|
474
|
+
return `${this.hash}-${dtHash}`;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
source(dependencyTemplates, runtimeTemplate, type = "javascript") {
|
|
478
|
+
const hashDigest = this.getHashDigest(dependencyTemplates);
|
|
479
|
+
const cacheEntry = this._cachedSources.get(type);
|
|
480
|
+
if (cacheEntry !== undefined && cacheEntry.hash === hashDigest) {
|
|
481
|
+
// We can reuse the cached source
|
|
482
|
+
return cacheEntry.source;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
const source = this.generator.generate(
|
|
486
|
+
this,
|
|
487
|
+
dependencyTemplates,
|
|
488
|
+
runtimeTemplate,
|
|
489
|
+
type
|
|
490
|
+
);
|
|
491
|
+
|
|
492
|
+
const cachedSource = new CachedSource(source);
|
|
493
|
+
this._cachedSources.set(type, {
|
|
494
|
+
source: cachedSource,
|
|
495
|
+
hash: hashDigest
|
|
496
|
+
});
|
|
497
|
+
return cachedSource;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
originalSource() {
|
|
501
|
+
return this._source;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
needRebuild(fileTimestamps, contextTimestamps) {
|
|
505
|
+
// always try to rebuild in case of an error
|
|
506
|
+
if (this.error) return true;
|
|
507
|
+
|
|
508
|
+
// always rebuild when module is not cacheable
|
|
509
|
+
if (!this.buildInfo.cacheable) return true;
|
|
510
|
+
|
|
511
|
+
// Check timestamps of all dependencies
|
|
512
|
+
// Missing timestamp -> need rebuild
|
|
513
|
+
// Timestamp bigger than buildTimestamp -> need rebuild
|
|
514
|
+
for (const file of this.buildInfo.fileDependencies) {
|
|
515
|
+
const timestamp = fileTimestamps.get(file);
|
|
516
|
+
if (!timestamp) return true;
|
|
517
|
+
if (timestamp >= this.buildTimestamp) return true;
|
|
518
|
+
}
|
|
519
|
+
for (const file of this.buildInfo.contextDependencies) {
|
|
520
|
+
const timestamp = contextTimestamps.get(file);
|
|
521
|
+
if (!timestamp) return true;
|
|
522
|
+
if (timestamp >= this.buildTimestamp) return true;
|
|
523
|
+
}
|
|
524
|
+
// elsewise -> no rebuild needed
|
|
525
|
+
return false;
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
size() {
|
|
529
|
+
return this._source ? this._source.size() : -1;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
533
|
+
* @param {Hash} hash the hash used to track dependencies
|
|
534
|
+
* @returns {void}
|
|
535
|
+
*/
|
|
536
|
+
updateHash(hash) {
|
|
537
|
+
hash.update(this._buildHash);
|
|
538
|
+
super.updateHash(hash);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
module.exports = NormalModule;
|