aboutsummaryrefslogtreecommitdiff
path: root/node_modules/webpack/lib/DynamicEntryPlugin.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
committerFlorian Dold <florian.dold@gmail.com>2018-09-20 02:56:13 +0200
commitbbff7403fbf46f9ad92240ac213df8d30ef31b64 (patch)
treec58400ec5124da1c7d56b01aea83309f80a56c3b /node_modules/webpack/lib/DynamicEntryPlugin.js
parent003fb34971cf63466184351b4db5f7c67df4f444 (diff)
update packages
Diffstat (limited to 'node_modules/webpack/lib/DynamicEntryPlugin.js')
-rw-r--r--node_modules/webpack/lib/DynamicEntryPlugin.js152
1 files changed, 93 insertions, 59 deletions
diff --git a/node_modules/webpack/lib/DynamicEntryPlugin.js b/node_modules/webpack/lib/DynamicEntryPlugin.js
index 2079e1276..99c1be2bf 100644
--- a/node_modules/webpack/lib/DynamicEntryPlugin.js
+++ b/node_modules/webpack/lib/DynamicEntryPlugin.js
@@ -1,59 +1,93 @@
-/*
- MIT License http://www.opensource.org/licenses/mit-license.php
- Author Naoyuki Kanezawa @nkzawa
-*/
-"use strict";
-
-const MultiEntryDependency = require("./dependencies/MultiEntryDependency");
-const SingleEntryDependency = require("./dependencies/SingleEntryDependency");
-const MultiModuleFactory = require("./MultiModuleFactory");
-const MultiEntryPlugin = require("./MultiEntryPlugin");
-const SingleEntryPlugin = require("./SingleEntryPlugin");
-
-class DynamicEntryPlugin {
- constructor(context, entry) {
- this.context = context;
- this.entry = entry;
- }
-
- apply(compiler) {
- compiler.plugin("compilation", (compilation, params) => {
- const multiModuleFactory = new MultiModuleFactory();
- const normalModuleFactory = params.normalModuleFactory;
-
- compilation.dependencyFactories.set(MultiEntryDependency, multiModuleFactory);
- compilation.dependencyFactories.set(SingleEntryDependency, normalModuleFactory);
- });
-
- compiler.plugin("make", (compilation, callback) => {
- const addEntry = (entry, name) => {
- const dep = DynamicEntryPlugin.createDependency(entry, name);
- return new Promise((resolve, reject) => {
- compilation.addEntry(this.context, dep, name, (err) => {
- if(err) return reject(err);
- resolve();
- });
- });
- };
-
- Promise.resolve(this.entry()).then((entry) => {
- if(typeof entry === "string" || Array.isArray(entry)) {
- addEntry(entry, "main").then(() => callback(), callback);
- } else if(typeof entry === "object") {
- Promise.all(Object.keys(entry).map((name) => {
- return addEntry(entry[name], name);
- })).then(() => callback(), callback);
- }
- });
- });
- }
-}
-
-module.exports = DynamicEntryPlugin;
-
-DynamicEntryPlugin.createDependency = function(entry, name) {
- if(Array.isArray(entry))
- return MultiEntryPlugin.createDependency(entry, name);
- else
- return SingleEntryPlugin.createDependency(entry, name);
-};
+/*
+ MIT License http://www.opensource.org/licenses/mit-license.php
+ Author Naoyuki Kanezawa @nkzawa
+*/
+"use strict";
+
+const MultiEntryDependency = require("./dependencies/MultiEntryDependency");
+const SingleEntryDependency = require("./dependencies/SingleEntryDependency");
+const MultiModuleFactory = require("./MultiModuleFactory");
+const MultiEntryPlugin = require("./MultiEntryPlugin");
+const SingleEntryPlugin = require("./SingleEntryPlugin");
+
+/** @typedef {import("./Compiler")} Compiler */
+/** @typedef {import("./Compiler").EntryOptionValuesFunction} EntryOptionValuesFunction */
+
+class DynamicEntryPlugin {
+ /**
+ * @param {string} context the context path
+ * @param {EntryOptionValuesFunction} entry the entry value
+ */
+ constructor(context, entry) {
+ this.context = context;
+ this.entry = entry;
+ }
+
+ /**
+ * @param {Compiler} compiler the compiler instance
+ * @returns {void}
+ */
+ apply(compiler) {
+ compiler.hooks.compilation.tap(
+ "DynamicEntryPlugin",
+ (compilation, { normalModuleFactory }) => {
+ const multiModuleFactory = new MultiModuleFactory();
+
+ compilation.dependencyFactories.set(
+ MultiEntryDependency,
+ multiModuleFactory
+ );
+ compilation.dependencyFactories.set(
+ SingleEntryDependency,
+ normalModuleFactory
+ );
+ }
+ );
+
+ compiler.hooks.make.tapAsync(
+ "DynamicEntryPlugin",
+ (compilation, callback) => {
+ /**
+ * @param {string|string[]} entry entry value or array of entry values
+ * @param {string} name name of entry
+ * @returns {Promise<any>} returns the promise resolving the Compilation#addEntry function
+ */
+ const addEntry = (entry, name) => {
+ const dep = DynamicEntryPlugin.createDependency(entry, name);
+ return new Promise((resolve, reject) => {
+ compilation.addEntry(this.context, dep, name, err => {
+ if (err) return reject(err);
+ resolve();
+ });
+ });
+ };
+
+ Promise.resolve(this.entry()).then(entry => {
+ if (typeof entry === "string" || Array.isArray(entry)) {
+ addEntry(entry, "main").then(() => callback(), callback);
+ } else if (typeof entry === "object") {
+ Promise.all(
+ Object.keys(entry).map(name => {
+ return addEntry(entry[name], name);
+ })
+ ).then(() => callback(), callback);
+ }
+ });
+ }
+ );
+ }
+}
+
+module.exports = DynamicEntryPlugin;
+/**
+ * @param {string|string[]} entry entry value or array of entry paths
+ * @param {string} name name of entry
+ * @returns {SingleEntryDependency|MultiEntryDependency} returns dep
+ */
+DynamicEntryPlugin.createDependency = (entry, name) => {
+ if (Array.isArray(entry)) {
+ return MultiEntryPlugin.createDependency(entry, name);
+ } else {
+ return SingleEntryPlugin.createDependency(entry, name);
+ }
+};