feat: refactoring project
This commit is contained in:
68
node_modules/webpack/lib/rules/UseEffectRulePlugin.js
generated
vendored
68
node_modules/webpack/lib/rules/UseEffectRulePlugin.js
generated
vendored
@@ -7,6 +7,9 @@
|
||||
|
||||
const util = require("util");
|
||||
|
||||
/** @typedef {import("../../declarations/WebpackOptions").RuleSetLoader} RuleSetLoader */
|
||||
/** @typedef {import("../../declarations/WebpackOptions").RuleSetLoaderOptions} RuleSetLoaderOptions */
|
||||
/** @typedef {import("../../declarations/WebpackOptions").RuleSetRule} RuleSetRule */
|
||||
/** @typedef {import("./RuleSetCompiler")} RuleSetCompiler */
|
||||
/** @typedef {import("./RuleSetCompiler").Effect} Effect */
|
||||
|
||||
@@ -19,6 +22,10 @@ class UseEffectRulePlugin {
|
||||
ruleSetCompiler.hooks.rule.tap(
|
||||
"UseEffectRulePlugin",
|
||||
(path, rule, unhandledProperties, result, references) => {
|
||||
/**
|
||||
* @param {keyof RuleSetRule} property property
|
||||
* @param {string} correctProperty correct property
|
||||
*/
|
||||
const conflictWith = (property, correctProperty) => {
|
||||
if (unhandledProperties.has(property)) {
|
||||
throw ruleSetCompiler.error(
|
||||
@@ -42,7 +49,6 @@ class UseEffectRulePlugin {
|
||||
const type = enforce ? `use-${enforce}` : "use";
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} path options path
|
||||
* @param {string} defaultIdent default ident when none is provided
|
||||
* @param {object} item user provided use value
|
||||
@@ -51,16 +57,14 @@ class UseEffectRulePlugin {
|
||||
const useToEffect = (path, defaultIdent, item) => {
|
||||
if (typeof item === "function") {
|
||||
return data => useToEffectsWithoutIdent(path, item(data));
|
||||
} else {
|
||||
return useToEffectRaw(path, defaultIdent, item);
|
||||
}
|
||||
return useToEffectRaw(path, defaultIdent, item);
|
||||
};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} path options path
|
||||
* @param {string} defaultIdent default ident when none is provided
|
||||
* @param {object} item user provided use value
|
||||
* @param {{ ident?: string, loader?: RuleSetLoader, options?: RuleSetLoaderOptions }} item user provided use value
|
||||
* @returns {Effect} effect
|
||||
*/
|
||||
const useToEffectRaw = (path, defaultIdent, item) => {
|
||||
@@ -73,30 +77,29 @@ class UseEffectRulePlugin {
|
||||
ident: undefined
|
||||
}
|
||||
};
|
||||
} else {
|
||||
const loader = item.loader;
|
||||
const options = item.options;
|
||||
let ident = item.ident;
|
||||
if (options && typeof options === "object") {
|
||||
if (!ident) ident = defaultIdent;
|
||||
references.set(ident, options);
|
||||
}
|
||||
if (typeof options === "string") {
|
||||
util.deprecate(
|
||||
() => {},
|
||||
`Using a string as loader options is deprecated (${path}.options)`,
|
||||
"DEP_WEBPACK_RULE_LOADER_OPTIONS_STRING"
|
||||
)();
|
||||
}
|
||||
return {
|
||||
type: enforce ? `use-${enforce}` : "use",
|
||||
value: {
|
||||
loader,
|
||||
options,
|
||||
ident
|
||||
}
|
||||
};
|
||||
}
|
||||
const loader = item.loader;
|
||||
const options = item.options;
|
||||
let ident = item.ident;
|
||||
if (options && typeof options === "object") {
|
||||
if (!ident) ident = defaultIdent;
|
||||
references.set(ident, options);
|
||||
}
|
||||
if (typeof options === "string") {
|
||||
util.deprecate(
|
||||
() => {},
|
||||
`Using a string as loader options is deprecated (${path}.options)`,
|
||||
"DEP_WEBPACK_RULE_LOADER_OPTIONS_STRING"
|
||||
)();
|
||||
}
|
||||
return {
|
||||
type: enforce ? `use-${enforce}` : "use",
|
||||
value: {
|
||||
loader,
|
||||
options,
|
||||
ident
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -132,7 +135,10 @@ class UseEffectRulePlugin {
|
||||
|
||||
if (typeof use === "function") {
|
||||
result.effects.push(data =>
|
||||
useToEffectsWithoutIdent(`${path}.use`, use(data))
|
||||
useToEffectsWithoutIdent(
|
||||
`${path}.use`,
|
||||
use(/** @type {TODO} */ (data))
|
||||
)
|
||||
);
|
||||
} else {
|
||||
for (const effect of useToEffects(`${path}.use`, use)) {
|
||||
@@ -146,7 +152,7 @@ class UseEffectRulePlugin {
|
||||
unhandledProperties.delete("options");
|
||||
unhandledProperties.delete("enforce");
|
||||
|
||||
const loader = rule.loader;
|
||||
const loader = /** @type {RuleSetLoader} */ (rule.loader);
|
||||
const options = rule.options;
|
||||
const enforce = rule.enforce;
|
||||
|
||||
@@ -189,8 +195,6 @@ class UseEffectRulePlugin {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
useItemToEffects(path, item) {}
|
||||
}
|
||||
|
||||
module.exports = UseEffectRulePlugin;
|
||||
|
||||
Reference in New Issue
Block a user