aboutsummaryrefslogtreecommitdiff
path: root/node_modules/webpack/lib/wasm/WebAssemblyInInitialChunkError.js
diff options
context:
space:
mode:
authorruki <waruqi@gmail.com>2018-11-08 00:38:48 +0800
committerruki <waruqi@gmail.com>2018-11-07 21:53:09 +0800
commit26105034da4fcce7ac883c899d781f016559310d (patch)
treec459a5dc4e3aa0972d9919033ece511ce76dd129 /node_modules/webpack/lib/wasm/WebAssemblyInInitialChunkError.js
parent2c77f00f1a7ecb6c8192f9c16d3b2001b254a107 (diff)
downloadxmake-docs-26105034da4fcce7ac883c899d781f016559310d.tar.gz
xmake-docs-26105034da4fcce7ac883c899d781f016559310d.zip
switch to vuepress
Diffstat (limited to 'node_modules/webpack/lib/wasm/WebAssemblyInInitialChunkError.js')
-rw-r--r--node_modules/webpack/lib/wasm/WebAssemblyInInitialChunkError.js88
1 files changed, 88 insertions, 0 deletions
diff --git a/node_modules/webpack/lib/wasm/WebAssemblyInInitialChunkError.js b/node_modules/webpack/lib/wasm/WebAssemblyInInitialChunkError.js
new file mode 100644
index 00000000..319e757a
--- /dev/null
+++ b/node_modules/webpack/lib/wasm/WebAssemblyInInitialChunkError.js
@@ -0,0 +1,88 @@
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+*/
+"use strict";
+
+const WebpackError = require("../WebpackError");
+
+/** @typedef {import("../Module")} Module */
+/** @typedef {import("../RequestShortener")} RequestShortener */
+
+/**
+ * @param {Module} module module to get chains from
+ * @param {RequestShortener} requestShortener to make readable identifiers
+ * @returns {string[]} all chains to the module
+ */
+const getInitialModuleChains = (module, requestShortener) => {
+ const queue = [
+ { head: module, message: module.readableIdentifier(requestShortener) }
+ ];
+ /** @type {Set<string>} */
+ const results = new Set();
+ /** @type {Set<string>} */
+ const incompleteResults = new Set();
+ /** @type {Set<Module>} */
+ const visitedModules = new Set();
+
+ for (const chain of queue) {
+ const { head, message } = chain;
+ let final = true;
+ /** @type {Set<Module>} */
+ const alreadyReferencedModules = new Set();
+ for (const reason of head.reasons) {
+ const newHead = reason.module;
+ if (newHead) {
+ if (!newHead.getChunks().some(c => c.canBeInitial())) continue;
+ final = false;
+ if (alreadyReferencedModules.has(newHead)) continue;
+ alreadyReferencedModules.add(newHead);
+ const moduleName = newHead.readableIdentifier(requestShortener);
+ const detail = reason.explanation ? ` (${reason.explanation})` : "";
+ const newMessage = `${moduleName}${detail} --> ${message}`;
+ if (visitedModules.has(newHead)) {
+ incompleteResults.add(`... --> ${newMessage}`);
+ continue;
+ }
+ visitedModules.add(newHead);
+ queue.push({
+ head: newHead,
+ message: newMessage
+ });
+ } else {
+ final = false;
+ const newMessage = reason.explanation
+ ? `(${reason.explanation}) --> ${message}`
+ : message;
+ results.add(newMessage);
+ }
+ }
+ if (final) {
+ results.add(message);
+ }
+ }
+ for (const result of incompleteResults) {
+ results.add(result);
+ }
+ return Array.from(results);
+};
+
+module.exports = class WebAssemblyInInitialChunkError extends WebpackError {
+ /**
+ * @param {Module} module WASM module
+ * @param {RequestShortener} requestShortener request shortener
+ */
+ constructor(module, requestShortener) {
+ const moduleChains = getInitialModuleChains(module, requestShortener);
+ const message = `WebAssembly module is included in initial chunk.
+This is not allowed, because WebAssembly download and compilation must happen asynchronous.
+Add an async splitpoint (i. e. import()) somewhere between your entrypoint and the WebAssembly module:
+${moduleChains.map(s => `* ${s}`).join("\n")}`;
+
+ super(message);
+ this.name = "WebAssemblyInInitialChunkError";
+ this.hideStack = true;
+ this.module = module;
+
+ Error.captureStackTrace(this, this.constructor);
+ }
+};