From de98e0b232509d5f40c135d540a70e415272ff85 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 3 May 2017 15:35:00 +0200 Subject: node_modules --- .../lib/webworker/WebWorkerChunkTemplatePlugin.js | 29 ++++++ .../WebWorkerHotUpdateChunkTemplatePlugin.js | 28 ++++++ .../lib/webworker/WebWorkerMainTemplate.runtime.js | 57 +++++++++++ .../lib/webworker/WebWorkerMainTemplatePlugin.js | 108 +++++++++++++++++++++ .../lib/webworker/WebWorkerTemplatePlugin.js | 20 ++++ 5 files changed, 242 insertions(+) create mode 100644 node_modules/webpack/lib/webworker/WebWorkerChunkTemplatePlugin.js create mode 100644 node_modules/webpack/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js create mode 100644 node_modules/webpack/lib/webworker/WebWorkerMainTemplate.runtime.js create mode 100644 node_modules/webpack/lib/webworker/WebWorkerMainTemplatePlugin.js create mode 100644 node_modules/webpack/lib/webworker/WebWorkerTemplatePlugin.js (limited to 'node_modules/webpack/lib/webworker') diff --git a/node_modules/webpack/lib/webworker/WebWorkerChunkTemplatePlugin.js b/node_modules/webpack/lib/webworker/WebWorkerChunkTemplatePlugin.js new file mode 100644 index 000000000..0b7fa525b --- /dev/null +++ b/node_modules/webpack/lib/webworker/WebWorkerChunkTemplatePlugin.js @@ -0,0 +1,29 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +"use strict"; + +var ConcatSource = require("webpack-sources").ConcatSource; +var Template = require("../Template"); + +class WebWorkerChunkTemplatePlugin { + + apply(chunkTemplate) { + chunkTemplate.plugin("render", function(modules, chunk) { + const chunkCallbackName = this.outputOptions.chunkCallbackName || Template.toIdentifier("webpackChunk" + (this.outputOptions.library || "")); + const source = new ConcatSource(); + source.add(`${chunkCallbackName}(${JSON.stringify(chunk.ids)},`); + source.add(modules); + source.add(")"); + return source; + }); + chunkTemplate.plugin("hash", function(hash) { + hash.update("webworker"); + hash.update("3"); + hash.update(`${this.outputOptions.chunkCallbackName}`); + hash.update(`${this.outputOptions.library}`); + }); + } +} +module.exports = WebWorkerChunkTemplatePlugin; diff --git a/node_modules/webpack/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js b/node_modules/webpack/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js new file mode 100644 index 000000000..c128be7c7 --- /dev/null +++ b/node_modules/webpack/lib/webworker/WebWorkerHotUpdateChunkTemplatePlugin.js @@ -0,0 +1,28 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +"use strict"; +const ConcatSource = require("webpack-sources").ConcatSource; +const Template = require("../Template"); + +class WebWorkerHotUpdateChunkTemplatePlugin { + + apply(hotUpdateChunkTemplate) { + hotUpdateChunkTemplate.plugin("render", function(modulesSource, modules, removedModules, hash, id) { + const chunkCallbackName = this.outputOptions.hotUpdateFunction || Template.toIdentifier("webpackHotUpdate" + (this.outputOptions.library || "")); + const source = new ConcatSource(); + source.add(chunkCallbackName + "(" + JSON.stringify(id) + ","); + source.add(modulesSource); + source.add(")"); + return source; + }); + hotUpdateChunkTemplate.plugin("hash", function(hash) { + hash.update("WebWorkerHotUpdateChunkTemplatePlugin"); + hash.update("3"); + hash.update(this.outputOptions.hotUpdateFunction + ""); + hash.update(this.outputOptions.library + ""); + }); + } +} +module.exports = WebWorkerHotUpdateChunkTemplatePlugin; diff --git a/node_modules/webpack/lib/webworker/WebWorkerMainTemplate.runtime.js b/node_modules/webpack/lib/webworker/WebWorkerMainTemplate.runtime.js new file mode 100644 index 000000000..bcead37e4 --- /dev/null +++ b/node_modules/webpack/lib/webworker/WebWorkerMainTemplate.runtime.js @@ -0,0 +1,57 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +/*globals installedChunks hotAddUpdateChunk parentHotUpdateCallback importScripts XMLHttpRequest $require$ $hotChunkFilename$ $hotMainFilename$ */ +module.exports = function() { + function webpackHotUpdateCallback(chunkId, moreModules) { // eslint-disable-line no-unused-vars + hotAddUpdateChunk(chunkId, moreModules); + if(parentHotUpdateCallback) parentHotUpdateCallback(chunkId, moreModules); + } //$semicolon + + function hotDownloadUpdateChunk(chunkId) { // eslint-disable-line no-unused-vars + importScripts($require$.p + $hotChunkFilename$); + } + + function hotDownloadManifest(callback) { // eslint-disable-line no-unused-vars + return new Promise(function(resolve, reject) { + if(typeof XMLHttpRequest === "undefined") + return reject(new Error("No browser support")); + try { + var request = new XMLHttpRequest(); + var requestPath = $require$.p + $hotMainFilename$; + request.open("GET", requestPath, true); + request.timeout = 10000; + request.send(null); + } catch(err) { + return reject(err); + } + request.onreadystatechange = function() { + if(request.readyState !== 4) return; + if(request.status === 0) { + // timeout + reject(new Error("Manifest request to " + requestPath + " timed out.")); + } else if(request.status === 404) { + // no update available + resolve(); + } else if(request.status !== 200 && request.status !== 304) { + // other failure + reject(new Error("Manifest request to " + requestPath + " failed.")); + } else { + // success + try { + var update = JSON.parse(request.responseText); + } catch(e) { + reject(e); + return; + } + resolve(update); + } + }; + }); + } + + function hotDisposeChunk(chunkId) { //eslint-disable-line no-unused-vars + delete installedChunks[chunkId]; + } +}; diff --git a/node_modules/webpack/lib/webworker/WebWorkerMainTemplatePlugin.js b/node_modules/webpack/lib/webworker/WebWorkerMainTemplatePlugin.js new file mode 100644 index 000000000..a0e6cc2f3 --- /dev/null +++ b/node_modules/webpack/lib/webworker/WebWorkerMainTemplatePlugin.js @@ -0,0 +1,108 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +"use strict"; + +const Template = require("../Template"); + +class WebWorkerMainTemplatePlugin { + apply(mainTemplate) { + mainTemplate.plugin("local-vars", function(source, chunk) { + if(chunk.chunks.length > 0) { + return this.asString([ + source, + "", + "// object to store loaded chunks", + "// \"1\" means \"already loaded\"", + "var installedChunks = {", + this.indent( + chunk.ids.map(function(id) { + return id + ": 1"; + }).join(",\n") + ), + "};" + ]); + } + return source; + }); + mainTemplate.plugin("require-ensure", function(_, chunk, hash) { + const chunkFilename = this.outputOptions.chunkFilename; + return this.asString([ + "// \"1\" is the signal for \"already loaded\"", + "if(!installedChunks[chunkId]) {", + this.indent([ + "importScripts(" + + this.applyPluginsWaterfall("asset-path", JSON.stringify(chunkFilename), { + hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"", + hashWithLength: function(length) { + return "\" + " + this.renderCurrentHashCode(hash, length) + " + \""; + }.bind(this), + chunk: { + id: "\" + chunkId + \"" + } + }) + ");" + ]), + "}", + "return Promise.resolve();" + ]); + }); + mainTemplate.plugin("bootstrap", function(source, chunk, hash) { + if(chunk.chunks.length > 0) { + const chunkCallbackName = this.outputOptions.chunkCallbackName || Template.toIdentifier("webpackChunk" + (this.outputOptions.library || "")); + return this.asString([ + source, + "this[" + JSON.stringify(chunkCallbackName) + "] = function webpackChunkCallback(chunkIds, moreModules) {", + this.indent([ + "for(var moduleId in moreModules) {", + this.indent(this.renderAddModule(hash, chunk, "moduleId", "moreModules[moduleId]")), + "}", + "while(chunkIds.length)", + this.indent("installedChunks[chunkIds.pop()] = 1;") + ]), + "};" + ]); + } + return source; + }); + mainTemplate.plugin("hot-bootstrap", function(source, chunk, hash) { + const hotUpdateChunkFilename = this.outputOptions.hotUpdateChunkFilename; + const hotUpdateMainFilename = this.outputOptions.hotUpdateMainFilename; + const hotUpdateFunction = this.outputOptions.hotUpdateFunction || Template.toIdentifier("webpackHotUpdate" + (this.outputOptions.library || "")); + const currentHotUpdateChunkFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateChunkFilename), { + hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"", + hashWithLength: function(length) { + return "\" + " + this.renderCurrentHashCode(hash, length) + " + \""; + }.bind(this), + chunk: { + id: "\" + chunkId + \"" + } + }); + const currentHotUpdateMainFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateMainFilename), { + hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"", + hashWithLength: function(length) { + return "\" + " + this.renderCurrentHashCode(hash, length) + " + \""; + }.bind(this) + }); + + return source + "\n" + + "var parentHotUpdateCallback = this[" + JSON.stringify(hotUpdateFunction) + "];\n" + + "this[" + JSON.stringify(hotUpdateFunction) + "] = " + Template.getFunctionContent(require("./WebWorkerMainTemplate.runtime.js")) + .replace(/\/\/\$semicolon/g, ";") + .replace(/\$require\$/g, this.requireFn) + .replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename) + .replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename) + .replace(/\$hash\$/g, JSON.stringify(hash)); + }); + mainTemplate.plugin("hash", function(hash) { + hash.update("webworker"); + hash.update("3"); + hash.update(`${this.outputOptions.publicPath}`); + hash.update(`${this.outputOptions.filename}`); + hash.update(`${this.outputOptions.chunkFilename}`); + hash.update(`${this.outputOptions.chunkCallbackName}`); + hash.update(`${this.outputOptions.library}`); + }); + } +} +module.exports = WebWorkerMainTemplatePlugin; diff --git a/node_modules/webpack/lib/webworker/WebWorkerTemplatePlugin.js b/node_modules/webpack/lib/webworker/WebWorkerTemplatePlugin.js new file mode 100644 index 000000000..64f1e00f5 --- /dev/null +++ b/node_modules/webpack/lib/webworker/WebWorkerTemplatePlugin.js @@ -0,0 +1,20 @@ +/* + MIT License http://www.opensource.org/licenses/mit-license.php + Author Tobias Koppers @sokra +*/ +"use strict"; + +const WebWorkerMainTemplatePlugin = require("./WebWorkerMainTemplatePlugin"); +const WebWorkerChunkTemplatePlugin = require("./WebWorkerChunkTemplatePlugin"); +const WebWorkerHotUpdateChunkTemplatePlugin = require("./WebWorkerHotUpdateChunkTemplatePlugin"); + +class WebWorkerTemplatePlugin { + apply(compiler) { + compiler.plugin("this-compilation", compilation => { + compilation.mainTemplate.apply(new WebWorkerMainTemplatePlugin()); + compilation.chunkTemplate.apply(new WebWorkerChunkTemplatePlugin()); + compilation.hotUpdateChunkTemplate.apply(new WebWorkerHotUpdateChunkTemplatePlugin()); + }); + } +} +module.exports = WebWorkerTemplatePlugin; -- cgit v1.2.3