WXL
4 天以前 2cc85c64f1c64a2dbaeae276a3e2ca8420de76b7
node_modules/webpack/lib/cli.js
@@ -17,6 +17,7 @@
// TODO add originPath to PathItem for better errors
/**
 * Defines the path item type used by this module.
 * @typedef {object} PathItem
 * @property {Schema} schema the part of the schema
 * @property {string} path the path in the config
@@ -27,6 +28,7 @@
/** @typedef {string | number | boolean | RegExp} Value */
/**
 * Defines the problem type used by this module.
 * @typedef {object} Problem
 * @property {ProblemType} type
 * @property {string} path
@@ -37,6 +39,7 @@
 */
/**
 * Defines the local problem type used by this module.
 * @typedef {object} LocalProblem
 * @property {ProblemType} type
 * @property {string} path
@@ -48,6 +51,7 @@
/** @typedef {string | number | boolean | EnumValueObject | EnumValueArray | null} EnumValue */
/**
 * Defines the argument config type used by this module.
 * @typedef {object} ArgumentConfig
 * @property {string=} description
 * @property {string=} negatedDescription
@@ -60,6 +64,7 @@
/** @typedef {"string" | "number" | "boolean"} SimpleType */
/**
 * Defines the argument type used by this module.
 * @typedef {object} Argument
 * @property {string | undefined} description
 * @property {SimpleType} simpleType
@@ -72,6 +77,7 @@
/** @typedef {Record<string, EXPECTED_ANY>} ObjectConfiguration */
/**
 * Returns object of arguments.
 * @param {Schema=} schema a json schema to create arguments for (by default webpack schema is used)
 * @returns {Flags} object of arguments
 */
@@ -80,6 +86,7 @@
   const flags = {};
   /**
    * Path to argument name.
    * @param {string} input input
    * @returns {string} result
    */
@@ -95,6 +102,7 @@
         .toLowerCase();
   /**
    * Returns schema part.
    * @param {string} path path
    * @returns {Schema} schema part
    */
@@ -117,6 +125,7 @@
   };
   /**
    * Returns description.
    * @param {PathItem[]} path path in the schema
    * @returns {string | undefined} description
    */
@@ -131,6 +140,7 @@
   };
   /**
    * Gets negated description.
    * @param {PathItem[]} path path in the schema
    * @returns {string | undefined} negative description
    */
@@ -144,6 +154,7 @@
   };
   /**
    * Gets reset description.
    * @param {PathItem[]} path path in the schema
    * @returns {string | undefined} reset description
    */
@@ -157,6 +168,7 @@
   };
   /**
    * Schema to argument config.
    * @param {Schema} schemaPart schema
    * @returns {Pick<ArgumentConfig, "type" | "values"> | undefined} partial argument config
    */
@@ -190,6 +202,7 @@
   };
   /**
    * Adds the provided path to this object.
    * @param {PathItem[]} path path in the schema
    * @returns {void}
    */
@@ -219,6 +232,7 @@
   };
   /**
    * Adds the provided path to this object.
    * @param {PathItem[]} path full path in schema
    * @param {boolean} multiple inside of an array
    * @returns {number} number of arguments added
@@ -281,6 +295,7 @@
   // TODO support `not` and `if/then/else`
   // TODO support `const`, but we don't use it on our schema
   /**
    * Returns added arguments.
    * @param {Schema} schemaPart the current schema
    * @param {string} schemaPath the current path in the schema
    * @param {PathItem[]} path all previous visited schemaParts
@@ -427,11 +442,13 @@
   return flags;
};
/** @type {WeakMap<EXPECTED_OBJECT, number>} */
const cliAddedItems = new WeakMap();
/** @typedef {string | number} Property */
/**
 * Gets object and property.
 * @param {ObjectConfiguration} config configuration
 * @param {string} schemaPath path in the config
 * @param {number | undefined} index index of value when multiple values are provided, otherwise undefined
@@ -532,6 +549,7 @@
};
/**
 * Updates value using the provided config.
 * @param {ObjectConfiguration} config configuration
 * @param {string} schemaPath path in the config
 * @param {ParsedValue} value parsed value
@@ -551,6 +569,7 @@
};
/**
 * Process argument config.
 * @param {ArgumentConfig} argConfig processing instructions
 * @param {ObjectConfiguration} config configuration
 * @param {Value} value the value
@@ -578,6 +597,7 @@
};
/**
 * Gets expected value.
 * @param {ArgumentConfig} argConfig processing instructions
 * @returns {string | undefined} expected message
 */
@@ -602,7 +622,10 @@
/** @typedef {null | string | number | boolean | RegExp | EnumValue | []} ParsedValue */
const DECIMAL_NUMBER_REGEXP = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
/**
 * Parses value for argument config.
 * @param {ArgumentConfig} argConfig processing instructions
 * @param {Value} value the value
 * @returns {ParsedValue | undefined} parsed value
@@ -621,7 +644,7 @@
         break;
      case "number":
         if (typeof value === "number") return value;
         if (typeof value === "string" && /^[+-]?\d*(\.\d*)[eE]\d+$/) {
         if (typeof value === "string" && DECIMAL_NUMBER_REGEXP.test(value)) {
            const n = Number(value);
            if (!Number.isNaN(n)) return n;
         }
@@ -662,6 +685,7 @@
/** @typedef {Record<string, Value[]>} Values */
/**
 * Processes the provided arg.
 * @param {Flags} args object of arguments
 * @param {ObjectConfiguration} config configuration
 * @param {Values} values object with values
@@ -681,10 +705,12 @@
         continue;
      }
      /**
       * Processes the provided value.
       * @param {Value} value value
       * @param {number | undefined} i index
       */
      const processValue = (value, i) => {
         /** @type {Problem[]} */
         const currentProblems = [];
         for (const argConfig of arg.configs) {
            const problem = processArgumentConfig(argConfig, config, value, i);
@@ -714,6 +740,7 @@
};
/**
 * Checks whether this object is color supported.
 * @returns {boolean} true when colors supported, otherwise false
 */
const isColorSupported = () => {
@@ -737,6 +764,7 @@
};
/**
 * Returns result.
 * @param {number} index index
 * @param {string} string string
 * @param {string} close close
@@ -757,6 +785,7 @@
) => head + (next < 0 ? tail : replaceClose(next, tail, close, replace));
/**
 * Returns result.
 * @param {number} index index to replace
 * @param {string} string string
 * @param {string} open open string
@@ -772,6 +801,7 @@
/** @typedef {(value: EXPECTED_ANY) => string} PrintFunction */
/**
 * Returns function to create color.
 * @param {string} open open string
 * @param {string} close close string
 * @param {string=} replace extra replace
@@ -786,6 +816,7 @@
         : "";
/**
 * Returns result.
 * @param {number} open open code
 * @param {number} close close code
 * @param {string=} replace extra replace
@@ -795,56 +826,18 @@
   filterEmpty(`\u001B[${open}m`, `\u001B[${close}m`, replace);
/**
 * @typedef {{
 * reset: PrintFunction
 * bold: PrintFunction
 * dim: PrintFunction
 * italic: PrintFunction
 * underline: PrintFunction
 * inverse: PrintFunction
 * hidden: PrintFunction
 * strikethrough: PrintFunction
 * black: PrintFunction
 * red: PrintFunction
 * green: PrintFunction
 * yellow: PrintFunction
 * blue: PrintFunction
 * magenta: PrintFunction
 * cyan: PrintFunction
 * white: PrintFunction
 * gray: PrintFunction
 * bgBlack: PrintFunction
 * bgRed: PrintFunction
 * bgGreen: PrintFunction
 * bgYellow: PrintFunction
 * bgBlue: PrintFunction
 * bgMagenta: PrintFunction
 * bgCyan: PrintFunction
 * bgWhite: PrintFunction
 * blackBright: PrintFunction
 * redBright: PrintFunction
 * greenBright: PrintFunction
 * yellowBright: PrintFunction
 * blueBright: PrintFunction
 * magentaBright: PrintFunction
 * cyanBright: PrintFunction
 * whiteBright: PrintFunction
 * bgBlackBright: PrintFunction
 * bgRedBright: PrintFunction
 * bgGreenBright: PrintFunction
 * bgYellowBright: PrintFunction
 * bgBlueBright: PrintFunction
 * bgMagentaBright: PrintFunction
 * bgCyanBright: PrintFunction
 * bgWhiteBright: PrintFunction
 }} Colors */
 * Defines the colors type used by this module.
 * @typedef {{ reset: PrintFunction, bold: PrintFunction, dim: PrintFunction, italic: PrintFunction, underline: PrintFunction, inverse: PrintFunction, hidden: PrintFunction, strikethrough: PrintFunction, black: PrintFunction, red: PrintFunction, green: PrintFunction, yellow: PrintFunction, blue: PrintFunction, magenta: PrintFunction, cyan: PrintFunction, white: PrintFunction, gray: PrintFunction, bgBlack: PrintFunction, bgRed: PrintFunction, bgGreen: PrintFunction, bgYellow: PrintFunction, bgBlue: PrintFunction, bgMagenta: PrintFunction, bgCyan: PrintFunction, bgWhite: PrintFunction, blackBright: PrintFunction, redBright: PrintFunction, greenBright: PrintFunction, yellowBright: PrintFunction, blueBright: PrintFunction, magentaBright: PrintFunction, cyanBright: PrintFunction, whiteBright: PrintFunction, bgBlackBright: PrintFunction, bgRedBright: PrintFunction, bgGreenBright: PrintFunction, bgYellowBright: PrintFunction, bgBlueBright: PrintFunction, bgMagentaBright: PrintFunction, bgCyanBright: PrintFunction, bgWhiteBright: PrintFunction }} Colors
 */
/**
 * Defines the colors options type used by this module.
 * @typedef {object} ColorsOptions
 * @property {boolean=} useColor force use colors
 */
/**
 * Creates a colors from the provided colors option.
 * @param {ColorsOptions=} options options
 * @returns {Colors} colors
 */