feat: refactoring project
This commit is contained in:
45
node_modules/webpack/lib/DllReferencePlugin.js
generated
vendored
45
node_modules/webpack/lib/DllReferencePlugin.js
generated
vendored
@@ -15,6 +15,7 @@ const makePathsRelative = require("./util/identifier").makePathsRelative;
|
||||
|
||||
/** @typedef {import("../declarations/WebpackOptions").Externals} Externals */
|
||||
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptions} DllReferencePluginOptions */
|
||||
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptionsContent} DllReferencePluginOptionsContent */
|
||||
/** @typedef {import("../declarations/plugins/DllReferencePlugin").DllReferencePluginOptionsManifest} DllReferencePluginOptionsManifest */
|
||||
/** @typedef {import("./Compiler")} Compiler */
|
||||
/** @typedef {import("./util/fs").InputFileSystem} InputFileSystem */
|
||||
@@ -28,6 +29,8 @@ const validate = createSchemaValidation(
|
||||
}
|
||||
);
|
||||
|
||||
/** @typedef {{ path: string, data: DllReferencePluginOptionsManifest | undefined, error: Error | undefined }} CompilationDataItem */
|
||||
|
||||
class DllReferencePlugin {
|
||||
/**
|
||||
* @param {DllReferencePluginOptions} options options object
|
||||
@@ -35,7 +38,7 @@ class DllReferencePlugin {
|
||||
constructor(options) {
|
||||
validate(options);
|
||||
this.options = options;
|
||||
/** @type {WeakMap<object, {path: string, data: DllReferencePluginOptionsManifest?, error: Error?}>} */
|
||||
/** @type {WeakMap<object, CompilationDataItem>} */
|
||||
this._compilationData = new WeakMap();
|
||||
}
|
||||
|
||||
@@ -64,6 +67,7 @@ class DllReferencePlugin {
|
||||
/** @type {InputFileSystem} */
|
||||
(compiler.inputFileSystem).readFile(manifest, (err, result) => {
|
||||
if (err) return callback(err);
|
||||
/** @type {CompilationDataItem} */
|
||||
const data = {
|
||||
path: manifest,
|
||||
data: undefined,
|
||||
@@ -75,15 +79,18 @@ class DllReferencePlugin {
|
||||
data.data = parseJson(
|
||||
/** @type {Buffer} */ (result).toString("utf-8")
|
||||
);
|
||||
} catch (e) {
|
||||
} catch (parseErr) {
|
||||
// Store the error in the params so that it can
|
||||
// be added as a compilation error later on.
|
||||
const manifestPath = makePathsRelative(
|
||||
compiler.options.context,
|
||||
/** @type {string} */ (compiler.options.context),
|
||||
manifest,
|
||||
compiler.root
|
||||
);
|
||||
data.error = new DllManifestError(manifestPath, e.message);
|
||||
data.error = new DllManifestError(
|
||||
manifestPath,
|
||||
/** @type {Error} */ (parseErr).message
|
||||
);
|
||||
}
|
||||
this._compilationData.set(params, data);
|
||||
return callback();
|
||||
@@ -98,13 +105,15 @@ class DllReferencePlugin {
|
||||
compiler.hooks.compile.tap("DllReferencePlugin", params => {
|
||||
let name = this.options.name;
|
||||
let sourceType = this.options.sourceType;
|
||||
let content =
|
||||
let resolvedContent =
|
||||
"content" in this.options ? this.options.content : undefined;
|
||||
if ("manifest" in this.options) {
|
||||
let manifestParameter = this.options.manifest;
|
||||
const manifestParameter = this.options.manifest;
|
||||
let manifest;
|
||||
if (typeof manifestParameter === "string") {
|
||||
const data = this._compilationData.get(params);
|
||||
const data =
|
||||
/** @type {CompilationDataItem} */
|
||||
(this._compilationData.get(params));
|
||||
// If there was an error parsing the manifest
|
||||
// file, exit now because the error will be added
|
||||
// as a compilation error in the "compilation" hook.
|
||||
@@ -118,23 +127,27 @@ class DllReferencePlugin {
|
||||
if (manifest) {
|
||||
if (!name) name = manifest.name;
|
||||
if (!sourceType) sourceType = manifest.type;
|
||||
if (!content) content = manifest.content;
|
||||
if (!resolvedContent) resolvedContent = manifest.content;
|
||||
}
|
||||
}
|
||||
/** @type {Externals} */
|
||||
const externals = {};
|
||||
const source = "dll-reference " + name;
|
||||
externals[source] = name;
|
||||
const source = `dll-reference ${name}`;
|
||||
externals[source] = /** @type {string} */ (name);
|
||||
const normalModuleFactory = params.normalModuleFactory;
|
||||
new ExternalModuleFactoryPlugin(sourceType || "var", externals).apply(
|
||||
normalModuleFactory
|
||||
);
|
||||
new DelegatedModuleFactoryPlugin({
|
||||
source: source,
|
||||
source,
|
||||
type: this.options.type,
|
||||
scope: this.options.scope,
|
||||
context: this.options.context || compiler.options.context,
|
||||
content,
|
||||
context:
|
||||
/** @type {string} */
|
||||
(this.options.context || compiler.options.context),
|
||||
content:
|
||||
/** @type {DllReferencePluginOptionsContent} */
|
||||
(resolvedContent),
|
||||
extensions: this.options.extensions,
|
||||
associatedObjectForCache: compiler.root
|
||||
}).apply(normalModuleFactory);
|
||||
@@ -144,9 +157,11 @@ class DllReferencePlugin {
|
||||
"DllReferencePlugin",
|
||||
(compilation, params) => {
|
||||
if ("manifest" in this.options) {
|
||||
let manifest = this.options.manifest;
|
||||
const manifest = this.options.manifest;
|
||||
if (typeof manifest === "string") {
|
||||
const data = this._compilationData.get(params);
|
||||
const data = /** @type {CompilationDataItem} */ (
|
||||
this._compilationData.get(params)
|
||||
);
|
||||
// If there was an error parsing the manifest file, add the
|
||||
// error as a compilation error to make the compilation fail.
|
||||
if (data.error) {
|
||||
|
||||
Reference in New Issue
Block a user