webpack 4.1.0 → 4.4.0
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 +719 -721
- package/bin/webpack.js +69 -10
- package/lib/APIPlugin.js +84 -84
- package/lib/AmdMainTemplatePlugin.js +75 -77
- package/lib/AsyncDependencyToInitialChunkError.js +21 -23
- package/lib/BannerPlugin.js +101 -101
- package/lib/Chunk.js +477 -469
- package/lib/ChunkTemplate.js +51 -53
- package/lib/Compilation.js +1858 -1851
- package/lib/Compiler.js +493 -478
- package/lib/ConcurrentCompilationError.js +19 -0
- package/lib/ContextModule.js +696 -685
- package/lib/ContextModuleFactory.js +245 -243
- package/lib/DefinePlugin.js +197 -197
- package/lib/DelegatedModule.js +101 -101
- package/lib/DependenciesBlockVariable.js +51 -52
- package/lib/Dependency.js +53 -52
- package/lib/DllModule.js +54 -54
- package/lib/DllModuleFactory.js +29 -29
- package/lib/EnvironmentPlugin.js +65 -67
- package/lib/EvalDevToolModuleTemplatePlugin.js +60 -60
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +105 -105
- package/lib/ExportPropertyMainTemplatePlugin.js +40 -40
- package/lib/ExternalModule.js +159 -159
- package/lib/FunctionModuleTemplatePlugin.js +98 -98
- package/lib/HotModuleReplacement.runtime.js +631 -631
- package/lib/HotModuleReplacementPlugin.js +407 -406
- package/lib/HotUpdateChunkTemplate.js +78 -80
- package/lib/JavascriptGenerator.js +228 -229
- package/lib/JavascriptModulesPlugin.js +184 -158
- package/lib/JsonGenerator.js +42 -42
- package/lib/MainTemplate.js +406 -402
- package/lib/Module.js +343 -340
- package/lib/ModuleBuildError.js +42 -42
- package/lib/ModuleError.js +28 -28
- package/lib/ModuleFilenameHelpers.js +166 -166
- package/lib/ModuleTemplate.js +77 -79
- package/lib/ModuleWarning.js +30 -30
- package/lib/MultiCompiler.js +271 -259
- package/lib/MultiModule.js +78 -75
- package/lib/MultiModuleFactory.js +23 -23
- package/lib/MultiWatching.js +38 -37
- package/lib/NoModeWarning.js +23 -21
- package/lib/NormalModule.js +478 -470
- package/lib/NormalModuleFactory.js +483 -481
- package/lib/OptionsDefaulter.js +80 -86
- package/lib/Parser.js +2074 -2071
- package/lib/ProgressPlugin.js +231 -231
- package/lib/RawModule.js +54 -55
- package/lib/RecordIdsPlugin.js +160 -160
- package/lib/RemovedPluginError.js +13 -13
- package/lib/ResolverFactory.js +64 -67
- package/lib/RuntimeTemplate.js +267 -297
- package/lib/SetVarMainTemplatePlugin.js +57 -57
- package/lib/SourceMapDevToolPlugin.js +302 -308
- package/lib/Stats.js +1234 -1212
- package/lib/Template.js +205 -205
- package/lib/TemplatedPathPlugin.js +170 -143
- package/lib/UmdMainTemplatePlugin.js +264 -269
- package/lib/Watching.js +193 -193
- package/lib/WebAssemblyParser.js +50 -54
- package/lib/WebpackOptionsApply.js +401 -401
- package/lib/WebpackOptionsDefaulter.js +337 -317
- package/lib/WebpackOptionsValidationError.js +316 -319
- package/lib/debug/ProfilingPlugin.js +409 -405
- package/lib/dependencies/AMDDefineDependencyParserPlugin.js +328 -311
- package/lib/dependencies/AMDRequireContextDependency.js +20 -20
- package/lib/dependencies/AMDRequireDependenciesBlockParserPlugin.js +270 -241
- package/lib/dependencies/HarmonyAcceptImportDependency.js +23 -23
- package/lib/dependencies/HarmonyExportImportedSpecifierDependency.js +620 -606
- package/lib/dependencies/HarmonyExportSpecifierDependency.js +53 -53
- package/lib/dependencies/HarmonyImportDependencyParserPlugin.js +214 -214
- package/lib/dependencies/HarmonyImportSpecifierDependency.js +154 -156
- package/lib/dependencies/ImportDependenciesBlock.js +17 -17
- package/lib/dependencies/ImportDependency.js +34 -34
- package/lib/dependencies/ImportEagerDependency.js +32 -32
- package/lib/dependencies/ImportParserPlugin.js +175 -179
- package/lib/dependencies/ImportWeakDependency.js +34 -34
- package/lib/dependencies/JsonExportsDependency.js +25 -25
- package/lib/dependencies/ModuleDependency.js +20 -20
- package/lib/dependencies/NullDependency.js +20 -20
- package/lib/dependencies/RequireContextDependency.js +22 -22
- package/lib/dependencies/RequireIncludeDependency.js +40 -40
- package/lib/dependencies/WebpackMissingModule.js +20 -22
- package/lib/node/NodeChunkTemplatePlugin.js +31 -31
- package/lib/node/NodeHotUpdateChunkTemplatePlugin.js +36 -36
- package/lib/node/NodeMainTemplatePlugin.js +320 -273
- package/lib/node/ReadFileCompileWasmMainTemplatePlugin.js +113 -115
- package/lib/optimize/AggressiveSplittingPlugin.js +281 -281
- package/lib/optimize/ConcatenatedModule.js +1364 -1366
- package/lib/optimize/RemoveParentModulesPlugin.js +114 -114
- package/lib/optimize/SplitChunksPlugin.js +519 -491
- package/lib/performance/SizeLimitsPlugin.js +105 -105
- package/lib/util/TrackingSet.js +35 -35
- package/lib/util/objectToMap.js +10 -10
- package/lib/wasm/WasmModuleTemplatePlugin.js +106 -106
- package/lib/web/JsonpChunkTemplatePlugin.js +47 -47
- package/lib/web/JsonpExportMainTemplatePlugin.js +47 -47
- package/lib/web/JsonpHotUpdateChunkTemplatePlugin.js +39 -39
- package/lib/web/JsonpMainTemplatePlugin.js +425 -403
- package/lib/webpack.js +182 -179
- package/lib/webworker/WebWorkerChunkTemplatePlugin.js +35 -35
- package/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js +40 -40
- package/lib/webworker/WebWorkerMainTemplatePlugin.js +177 -154
- package/package.json +9 -8
- package/schemas/WebpackOptions.json +1973 -1951
- package/schemas/ajv.absolutePath.js +55 -29
- package/schemas/plugins/BannerPlugin.json +85 -85
- package/schemas/plugins/DllPlugin.json +28 -28
- 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/lib/Watching.js
CHANGED
@@ -1,193 +1,193 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
"use strict";
|
6
|
-
|
7
|
-
const Stats = require("./Stats");
|
8
|
-
|
9
|
-
class Watching {
|
10
|
-
constructor(compiler, watchOptions, handler) {
|
11
|
-
this.startTime = null;
|
12
|
-
this.invalid = false;
|
13
|
-
this.handler = handler;
|
14
|
-
this.callbacks = [];
|
15
|
-
this.closed = false;
|
16
|
-
if (typeof watchOptions === "number") {
|
17
|
-
this.watchOptions = {
|
18
|
-
aggregateTimeout: watchOptions
|
19
|
-
};
|
20
|
-
} else if (watchOptions && typeof watchOptions === "object") {
|
21
|
-
this.watchOptions = Object.assign({}, watchOptions);
|
22
|
-
} else {
|
23
|
-
this.watchOptions = {};
|
24
|
-
}
|
25
|
-
this.watchOptions.aggregateTimeout =
|
26
|
-
this.watchOptions.aggregateTimeout || 200;
|
27
|
-
this.compiler = compiler;
|
28
|
-
this.running = true;
|
29
|
-
this.compiler.readRecords(err => {
|
30
|
-
if (err) return this._done(err);
|
31
|
-
|
32
|
-
this._go();
|
33
|
-
});
|
34
|
-
}
|
35
|
-
|
36
|
-
_go() {
|
37
|
-
this.startTime = Date.now();
|
38
|
-
this.running = true;
|
39
|
-
this.invalid = false;
|
40
|
-
this.compiler.hooks.watchRun.callAsync(this.compiler, err => {
|
41
|
-
if (err) return this._done(err);
|
42
|
-
const onCompiled = (err, compilation) => {
|
43
|
-
if (err) return this._done(err);
|
44
|
-
if (this.invalid) return this._done();
|
45
|
-
|
46
|
-
if (this.compiler.hooks.shouldEmit.call(compilation) === false) {
|
47
|
-
return this._done(null, compilation);
|
48
|
-
}
|
49
|
-
|
50
|
-
this.compiler.emitAssets(compilation, err => {
|
51
|
-
if (err) return this._done(err);
|
52
|
-
if (this.invalid) return this._done();
|
53
|
-
|
54
|
-
this.compiler.emitRecords(err => {
|
55
|
-
if (err) return this._done(err);
|
56
|
-
|
57
|
-
if (compilation.hooks.needAdditionalPass.call()) {
|
58
|
-
compilation.needAdditionalPass = true;
|
59
|
-
|
60
|
-
const stats = new Stats(compilation);
|
61
|
-
stats.startTime = this.startTime;
|
62
|
-
stats.endTime = Date.now();
|
63
|
-
this.compiler.hooks.done.callAsync(stats, err => {
|
64
|
-
if (err) return this._done(err);
|
65
|
-
|
66
|
-
this.compiler.hooks.additionalPass.callAsync(err => {
|
67
|
-
if (err) return this._done(err);
|
68
|
-
this.compiler.compile(onCompiled);
|
69
|
-
});
|
70
|
-
});
|
71
|
-
return;
|
72
|
-
}
|
73
|
-
return this._done(null, compilation);
|
74
|
-
});
|
75
|
-
});
|
76
|
-
};
|
77
|
-
this.compiler.compile(onCompiled);
|
78
|
-
});
|
79
|
-
}
|
80
|
-
|
81
|
-
_getStats(compilation) {
|
82
|
-
const stats = new Stats(compilation);
|
83
|
-
stats.startTime = this.startTime;
|
84
|
-
stats.endTime = Date.now();
|
85
|
-
return stats;
|
86
|
-
}
|
87
|
-
|
88
|
-
_done(err, compilation) {
|
89
|
-
this.running = false;
|
90
|
-
if (this.invalid) return this._go();
|
91
|
-
|
92
|
-
const stats = compilation ? this._getStats(compilation) : null;
|
93
|
-
if (err) {
|
94
|
-
this.compiler.hooks.failed.call(err);
|
95
|
-
this.handler(err, stats);
|
96
|
-
return;
|
97
|
-
}
|
98
|
-
|
99
|
-
this.compiler.hooks.done.callAsync(stats, () => {
|
100
|
-
this.handler(null, stats);
|
101
|
-
if (!this.closed) {
|
102
|
-
this.watch(
|
103
|
-
Array.from(compilation.fileDependencies),
|
104
|
-
Array.from(compilation.contextDependencies),
|
105
|
-
Array.from(compilation.missingDependencies)
|
106
|
-
);
|
107
|
-
}
|
108
|
-
for (const cb of this.callbacks) cb();
|
109
|
-
this.callbacks.length = 0;
|
110
|
-
});
|
111
|
-
}
|
112
|
-
|
113
|
-
watch(files, dirs, missing) {
|
114
|
-
this.pausedWatcher = null;
|
115
|
-
this.watcher = this.compiler.watchFileSystem.watch(
|
116
|
-
files,
|
117
|
-
dirs,
|
118
|
-
missing,
|
119
|
-
this.startTime,
|
120
|
-
this.watchOptions,
|
121
|
-
(
|
122
|
-
err,
|
123
|
-
filesModified,
|
124
|
-
contextModified,
|
125
|
-
missingModified,
|
126
|
-
fileTimestamps,
|
127
|
-
contextTimestamps
|
128
|
-
) => {
|
129
|
-
this.pausedWatcher = this.watcher;
|
130
|
-
this.watcher = null;
|
131
|
-
if (err) return this.handler(err);
|
132
|
-
|
133
|
-
this.compiler.fileTimestamps = fileTimestamps;
|
134
|
-
this.compiler.contextTimestamps = contextTimestamps;
|
135
|
-
this._invalidate();
|
136
|
-
},
|
137
|
-
(fileName, changeTime) => {
|
138
|
-
this.compiler.hooks.invalid.call(fileName, changeTime);
|
139
|
-
}
|
140
|
-
);
|
141
|
-
}
|
142
|
-
|
143
|
-
invalidate(callback) {
|
144
|
-
if (callback) {
|
145
|
-
this.callbacks.push(callback);
|
146
|
-
}
|
147
|
-
if (this.watcher) {
|
148
|
-
this.compiler.fileTimestamps = this.watcher.getFileTimestamps();
|
149
|
-
this.compiler.contextTimestamps = this.watcher.getContextTimestamps();
|
150
|
-
}
|
151
|
-
return this._invalidate();
|
152
|
-
}
|
153
|
-
|
154
|
-
_invalidate() {
|
155
|
-
if (this.watcher) {
|
156
|
-
this.pausedWatcher = this.watcher;
|
157
|
-
this.watcher.pause();
|
158
|
-
this.watcher = null;
|
159
|
-
}
|
160
|
-
if (this.running) {
|
161
|
-
this.invalid = true;
|
162
|
-
return false;
|
163
|
-
} else {
|
164
|
-
this._go();
|
165
|
-
}
|
166
|
-
}
|
167
|
-
|
168
|
-
close(callback) {
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
if (this.
|
177
|
-
this.
|
178
|
-
this.
|
179
|
-
}
|
180
|
-
if (this.
|
181
|
-
this.
|
182
|
-
this.
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
}
|
190
|
-
}
|
191
|
-
}
|
192
|
-
|
193
|
-
module.exports = Watching;
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const Stats = require("./Stats");
|
8
|
+
|
9
|
+
class Watching {
|
10
|
+
constructor(compiler, watchOptions, handler) {
|
11
|
+
this.startTime = null;
|
12
|
+
this.invalid = false;
|
13
|
+
this.handler = handler;
|
14
|
+
this.callbacks = [];
|
15
|
+
this.closed = false;
|
16
|
+
if (typeof watchOptions === "number") {
|
17
|
+
this.watchOptions = {
|
18
|
+
aggregateTimeout: watchOptions
|
19
|
+
};
|
20
|
+
} else if (watchOptions && typeof watchOptions === "object") {
|
21
|
+
this.watchOptions = Object.assign({}, watchOptions);
|
22
|
+
} else {
|
23
|
+
this.watchOptions = {};
|
24
|
+
}
|
25
|
+
this.watchOptions.aggregateTimeout =
|
26
|
+
this.watchOptions.aggregateTimeout || 200;
|
27
|
+
this.compiler = compiler;
|
28
|
+
this.running = true;
|
29
|
+
this.compiler.readRecords(err => {
|
30
|
+
if (err) return this._done(err);
|
31
|
+
|
32
|
+
this._go();
|
33
|
+
});
|
34
|
+
}
|
35
|
+
|
36
|
+
_go() {
|
37
|
+
this.startTime = Date.now();
|
38
|
+
this.running = true;
|
39
|
+
this.invalid = false;
|
40
|
+
this.compiler.hooks.watchRun.callAsync(this.compiler, err => {
|
41
|
+
if (err) return this._done(err);
|
42
|
+
const onCompiled = (err, compilation) => {
|
43
|
+
if (err) return this._done(err);
|
44
|
+
if (this.invalid) return this._done();
|
45
|
+
|
46
|
+
if (this.compiler.hooks.shouldEmit.call(compilation) === false) {
|
47
|
+
return this._done(null, compilation);
|
48
|
+
}
|
49
|
+
|
50
|
+
this.compiler.emitAssets(compilation, err => {
|
51
|
+
if (err) return this._done(err);
|
52
|
+
if (this.invalid) return this._done();
|
53
|
+
|
54
|
+
this.compiler.emitRecords(err => {
|
55
|
+
if (err) return this._done(err);
|
56
|
+
|
57
|
+
if (compilation.hooks.needAdditionalPass.call()) {
|
58
|
+
compilation.needAdditionalPass = true;
|
59
|
+
|
60
|
+
const stats = new Stats(compilation);
|
61
|
+
stats.startTime = this.startTime;
|
62
|
+
stats.endTime = Date.now();
|
63
|
+
this.compiler.hooks.done.callAsync(stats, err => {
|
64
|
+
if (err) return this._done(err);
|
65
|
+
|
66
|
+
this.compiler.hooks.additionalPass.callAsync(err => {
|
67
|
+
if (err) return this._done(err);
|
68
|
+
this.compiler.compile(onCompiled);
|
69
|
+
});
|
70
|
+
});
|
71
|
+
return;
|
72
|
+
}
|
73
|
+
return this._done(null, compilation);
|
74
|
+
});
|
75
|
+
});
|
76
|
+
};
|
77
|
+
this.compiler.compile(onCompiled);
|
78
|
+
});
|
79
|
+
}
|
80
|
+
|
81
|
+
_getStats(compilation) {
|
82
|
+
const stats = new Stats(compilation);
|
83
|
+
stats.startTime = this.startTime;
|
84
|
+
stats.endTime = Date.now();
|
85
|
+
return stats;
|
86
|
+
}
|
87
|
+
|
88
|
+
_done(err, compilation) {
|
89
|
+
this.running = false;
|
90
|
+
if (this.invalid) return this._go();
|
91
|
+
|
92
|
+
const stats = compilation ? this._getStats(compilation) : null;
|
93
|
+
if (err) {
|
94
|
+
this.compiler.hooks.failed.call(err);
|
95
|
+
this.handler(err, stats);
|
96
|
+
return;
|
97
|
+
}
|
98
|
+
|
99
|
+
this.compiler.hooks.done.callAsync(stats, () => {
|
100
|
+
this.handler(null, stats);
|
101
|
+
if (!this.closed) {
|
102
|
+
this.watch(
|
103
|
+
Array.from(compilation.fileDependencies),
|
104
|
+
Array.from(compilation.contextDependencies),
|
105
|
+
Array.from(compilation.missingDependencies)
|
106
|
+
);
|
107
|
+
}
|
108
|
+
for (const cb of this.callbacks) cb();
|
109
|
+
this.callbacks.length = 0;
|
110
|
+
});
|
111
|
+
}
|
112
|
+
|
113
|
+
watch(files, dirs, missing) {
|
114
|
+
this.pausedWatcher = null;
|
115
|
+
this.watcher = this.compiler.watchFileSystem.watch(
|
116
|
+
files,
|
117
|
+
dirs,
|
118
|
+
missing,
|
119
|
+
this.startTime,
|
120
|
+
this.watchOptions,
|
121
|
+
(
|
122
|
+
err,
|
123
|
+
filesModified,
|
124
|
+
contextModified,
|
125
|
+
missingModified,
|
126
|
+
fileTimestamps,
|
127
|
+
contextTimestamps
|
128
|
+
) => {
|
129
|
+
this.pausedWatcher = this.watcher;
|
130
|
+
this.watcher = null;
|
131
|
+
if (err) return this.handler(err);
|
132
|
+
|
133
|
+
this.compiler.fileTimestamps = fileTimestamps;
|
134
|
+
this.compiler.contextTimestamps = contextTimestamps;
|
135
|
+
this._invalidate();
|
136
|
+
},
|
137
|
+
(fileName, changeTime) => {
|
138
|
+
this.compiler.hooks.invalid.call(fileName, changeTime);
|
139
|
+
}
|
140
|
+
);
|
141
|
+
}
|
142
|
+
|
143
|
+
invalidate(callback) {
|
144
|
+
if (callback) {
|
145
|
+
this.callbacks.push(callback);
|
146
|
+
}
|
147
|
+
if (this.watcher) {
|
148
|
+
this.compiler.fileTimestamps = this.watcher.getFileTimestamps();
|
149
|
+
this.compiler.contextTimestamps = this.watcher.getContextTimestamps();
|
150
|
+
}
|
151
|
+
return this._invalidate();
|
152
|
+
}
|
153
|
+
|
154
|
+
_invalidate() {
|
155
|
+
if (this.watcher) {
|
156
|
+
this.pausedWatcher = this.watcher;
|
157
|
+
this.watcher.pause();
|
158
|
+
this.watcher = null;
|
159
|
+
}
|
160
|
+
if (this.running) {
|
161
|
+
this.invalid = true;
|
162
|
+
return false;
|
163
|
+
} else {
|
164
|
+
this._go();
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
close(callback) {
|
169
|
+
const finalCallback = () => {
|
170
|
+
this.compiler.hooks.watchClose.call();
|
171
|
+
this.compiler.running = false;
|
172
|
+
if (callback !== undefined) callback();
|
173
|
+
};
|
174
|
+
|
175
|
+
this.closed = true;
|
176
|
+
if (this.watcher) {
|
177
|
+
this.watcher.close();
|
178
|
+
this.watcher = null;
|
179
|
+
}
|
180
|
+
if (this.pausedWatcher) {
|
181
|
+
this.pausedWatcher.close();
|
182
|
+
this.pausedWatcher = null;
|
183
|
+
}
|
184
|
+
if (this.running) {
|
185
|
+
this.invalid = true;
|
186
|
+
this._done = finalCallback;
|
187
|
+
} else {
|
188
|
+
finalCallback();
|
189
|
+
}
|
190
|
+
}
|
191
|
+
}
|
192
|
+
|
193
|
+
module.exports = Watching;
|
package/lib/WebAssemblyParser.js
CHANGED
@@ -1,54 +1,50 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
/* globals WebAssembly */
|
6
|
-
"use strict";
|
7
|
-
|
8
|
-
// Syntax: https://developer.mozilla.org/en/SpiderMonkey/Parser_API
|
9
|
-
|
10
|
-
const Tapable = require("tapable")
|
11
|
-
const WebAssemblyImportDependency = require("./dependencies/WebAssemblyImportDependency");
|
12
|
-
|
13
|
-
class WebAssemblyParser extends Tapable {
|
14
|
-
constructor(options) {
|
15
|
-
super();
|
16
|
-
this.hooks = {};
|
17
|
-
this.options = options;
|
18
|
-
}
|
19
|
-
|
20
|
-
parse(source, state, callback) {
|
21
|
-
// TODO parse WASM AST and walk it
|
22
|
-
// TODO extract imports
|
23
|
-
|
24
|
-
// flag it as ESM
|
25
|
-
state.module.buildMeta.exportsType = "namespace";
|
26
|
-
|
27
|
-
// extract exports
|
28
|
-
// TODO find more efficient way doing it
|
29
|
-
// TODO use Promises
|
30
|
-
if (typeof WebAssembly !== "undefined") {
|
31
|
-
WebAssembly.compile(source)
|
32
|
-
.then(module => {
|
33
|
-
state.module.buildMeta.providedExports = WebAssembly.Module.exports(
|
34
|
-
module
|
35
|
-
).map(exp => exp.name);
|
36
|
-
for (const imp of WebAssembly.Module.imports(module)) {
|
37
|
-
const dep = new WebAssemblyImportDependency(
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
}
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
}
|
52
|
-
}
|
53
|
-
|
54
|
-
module.exports = WebAssemblyParser;
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
/* globals WebAssembly */
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
// Syntax: https://developer.mozilla.org/en/SpiderMonkey/Parser_API
|
9
|
+
|
10
|
+
const { Tapable } = require("tapable");
|
11
|
+
const WebAssemblyImportDependency = require("./dependencies/WebAssemblyImportDependency");
|
12
|
+
|
13
|
+
class WebAssemblyParser extends Tapable {
|
14
|
+
constructor(options) {
|
15
|
+
super();
|
16
|
+
this.hooks = {};
|
17
|
+
this.options = options;
|
18
|
+
}
|
19
|
+
|
20
|
+
parse(source, state, callback) {
|
21
|
+
// TODO parse WASM AST and walk it
|
22
|
+
// TODO extract imports
|
23
|
+
|
24
|
+
// flag it as ESM
|
25
|
+
state.module.buildMeta.exportsType = "namespace";
|
26
|
+
|
27
|
+
// extract exports
|
28
|
+
// TODO find more efficient way doing it
|
29
|
+
// TODO use Promises
|
30
|
+
if (typeof WebAssembly !== "undefined") {
|
31
|
+
WebAssembly.compile(source)
|
32
|
+
.then(module => {
|
33
|
+
state.module.buildMeta.providedExports = WebAssembly.Module.exports(
|
34
|
+
module
|
35
|
+
).map(exp => exp.name);
|
36
|
+
for (const imp of WebAssembly.Module.imports(module)) {
|
37
|
+
const dep = new WebAssemblyImportDependency(imp.module, imp.name);
|
38
|
+
state.module.addDependency(dep);
|
39
|
+
}
|
40
|
+
})
|
41
|
+
.then(() => callback(null, state), err => callback(err));
|
42
|
+
} else {
|
43
|
+
throw new Error(
|
44
|
+
"Can't compile WebAssembly modules without WebAssembly support in current node.js version (Update to latest node.js version)"
|
45
|
+
);
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
module.exports = WebAssemblyParser;
|