first commit
This commit is contained in:
2687
app_vue/node_modules/webpack/lib/stats/DefaultStatsFactoryPlugin.js
generated
vendored
Normal file
2687
app_vue/node_modules/webpack/lib/stats/DefaultStatsFactoryPlugin.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
411
app_vue/node_modules/webpack/lib/stats/DefaultStatsPresetPlugin.js
generated
vendored
Normal file
411
app_vue/node_modules/webpack/lib/stats/DefaultStatsPresetPlugin.js
generated
vendored
Normal file
@ -0,0 +1,411 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const RequestShortener = require("../RequestShortener");
|
||||
|
||||
/** @typedef {import("../../declarations/WebpackOptions").StatsOptions} StatsOptions */
|
||||
/** @typedef {import("../../declarations/WebpackOptions").StatsValue} StatsValue */
|
||||
/** @typedef {import("../Compilation")} Compilation */
|
||||
/** @typedef {import("../Compilation").CreateStatsOptionsContext} CreateStatsOptionsContext */
|
||||
/** @typedef {import("../Compilation").KnownNormalizedStatsOptions} KnownNormalizedStatsOptions */
|
||||
/** @typedef {import("../Compilation").NormalizedStatsOptions} NormalizedStatsOptions */
|
||||
/** @typedef {import("../Compiler")} Compiler */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsError} StatsError */
|
||||
|
||||
/**
|
||||
* @param {Partial<NormalizedStatsOptions>} options options
|
||||
* @param {StatsOptions} defaults default options
|
||||
*/
|
||||
const applyDefaults = (options, defaults) => {
|
||||
for (const _k of Object.keys(defaults)) {
|
||||
const key = /** @type {keyof StatsOptions} */ (_k);
|
||||
if (typeof options[key] === "undefined") {
|
||||
options[/** @type {keyof NormalizedStatsOptions} */ (key)] =
|
||||
defaults[key];
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** @typedef {{ [Key in Exclude<StatsValue, boolean | object | "normal">]: StatsOptions }} NamedPresets */
|
||||
|
||||
/** @type {NamedPresets} */
|
||||
const NAMED_PRESETS = {
|
||||
verbose: {
|
||||
hash: true,
|
||||
builtAt: true,
|
||||
relatedAssets: true,
|
||||
entrypoints: true,
|
||||
chunkGroups: true,
|
||||
ids: true,
|
||||
modules: false,
|
||||
chunks: true,
|
||||
chunkRelations: true,
|
||||
chunkModules: true,
|
||||
dependentModules: true,
|
||||
chunkOrigins: true,
|
||||
depth: true,
|
||||
env: true,
|
||||
reasons: true,
|
||||
usedExports: true,
|
||||
providedExports: true,
|
||||
optimizationBailout: true,
|
||||
errorDetails: true,
|
||||
errorStack: true,
|
||||
errorCause: true,
|
||||
errorErrors: true,
|
||||
publicPath: true,
|
||||
logging: "verbose",
|
||||
orphanModules: true,
|
||||
runtimeModules: true,
|
||||
exclude: false,
|
||||
errorsSpace: Infinity,
|
||||
warningsSpace: Infinity,
|
||||
modulesSpace: Infinity,
|
||||
chunkModulesSpace: Infinity,
|
||||
assetsSpace: Infinity,
|
||||
reasonsSpace: Infinity,
|
||||
children: true
|
||||
},
|
||||
detailed: {
|
||||
hash: true,
|
||||
builtAt: true,
|
||||
relatedAssets: true,
|
||||
entrypoints: true,
|
||||
chunkGroups: true,
|
||||
ids: true,
|
||||
chunks: true,
|
||||
chunkRelations: true,
|
||||
chunkModules: false,
|
||||
chunkOrigins: true,
|
||||
depth: true,
|
||||
usedExports: true,
|
||||
providedExports: true,
|
||||
optimizationBailout: true,
|
||||
errorDetails: true,
|
||||
errorCause: true,
|
||||
errorErrors: true,
|
||||
publicPath: true,
|
||||
logging: true,
|
||||
runtimeModules: true,
|
||||
exclude: false,
|
||||
errorsSpace: 1000,
|
||||
warningsSpace: 1000,
|
||||
modulesSpace: 1000,
|
||||
assetsSpace: 1000,
|
||||
reasonsSpace: 1000
|
||||
},
|
||||
minimal: {
|
||||
all: false,
|
||||
version: true,
|
||||
timings: true,
|
||||
modules: true,
|
||||
errorsSpace: 0,
|
||||
warningsSpace: 0,
|
||||
modulesSpace: 0,
|
||||
assets: true,
|
||||
assetsSpace: 0,
|
||||
errors: true,
|
||||
errorsCount: true,
|
||||
warnings: true,
|
||||
warningsCount: true,
|
||||
logging: "warn"
|
||||
},
|
||||
"errors-only": {
|
||||
all: false,
|
||||
errors: true,
|
||||
errorsCount: true,
|
||||
errorsSpace: Infinity,
|
||||
moduleTrace: true,
|
||||
logging: "error"
|
||||
},
|
||||
"errors-warnings": {
|
||||
all: false,
|
||||
errors: true,
|
||||
errorsCount: true,
|
||||
errorsSpace: Infinity,
|
||||
warnings: true,
|
||||
warningsCount: true,
|
||||
warningsSpace: Infinity,
|
||||
logging: "warn"
|
||||
},
|
||||
summary: {
|
||||
all: false,
|
||||
version: true,
|
||||
errorsCount: true,
|
||||
warningsCount: true
|
||||
},
|
||||
none: {
|
||||
all: false
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {Partial<NormalizedStatsOptions>} all stats option
|
||||
* @returns {boolean} true when enabled, otherwise false
|
||||
*/
|
||||
const NORMAL_ON = ({ all }) => all !== false;
|
||||
/**
|
||||
* @param {Partial<NormalizedStatsOptions>} all stats option
|
||||
* @returns {boolean} true when enabled, otherwise false
|
||||
*/
|
||||
const NORMAL_OFF = ({ all }) => all === true;
|
||||
/**
|
||||
* @param {Partial<NormalizedStatsOptions>} all stats option
|
||||
* @param {CreateStatsOptionsContext} forToString stats options context
|
||||
* @returns {boolean} true when enabled, otherwise false
|
||||
*/
|
||||
const ON_FOR_TO_STRING = ({ all }, { forToString }) =>
|
||||
forToString ? all !== false : all === true;
|
||||
/**
|
||||
* @param {Partial<NormalizedStatsOptions>} all stats option
|
||||
* @param {CreateStatsOptionsContext} forToString stats options context
|
||||
* @returns {boolean} true when enabled, otherwise false
|
||||
*/
|
||||
const OFF_FOR_TO_STRING = ({ all }, { forToString }) =>
|
||||
forToString ? all === true : all !== false;
|
||||
/**
|
||||
* @param {Partial<NormalizedStatsOptions>} all stats option
|
||||
* @param {CreateStatsOptionsContext} forToString stats options context
|
||||
* @returns {boolean | "auto"} true when enabled, otherwise false
|
||||
*/
|
||||
const AUTO_FOR_TO_STRING = ({ all }, { forToString }) => {
|
||||
if (all === false) return false;
|
||||
if (all === true) return true;
|
||||
if (forToString) return "auto";
|
||||
return true;
|
||||
};
|
||||
|
||||
/** @typedef {keyof NormalizedStatsOptions} DefaultsKeys */
|
||||
/** @typedef {{ [Key in DefaultsKeys]: (options: Partial<NormalizedStatsOptions>, context: CreateStatsOptionsContext, compilation: Compilation) => NormalizedStatsOptions[Key] | RequestShortener }} Defaults */
|
||||
|
||||
/** @type {Partial<Defaults>} */
|
||||
const DEFAULTS = {
|
||||
context: (options, context, compilation) => compilation.compiler.context,
|
||||
requestShortener: (options, context, compilation) =>
|
||||
compilation.compiler.context === options.context
|
||||
? compilation.requestShortener
|
||||
: new RequestShortener(
|
||||
/** @type {string} */
|
||||
(options.context),
|
||||
compilation.compiler.root
|
||||
),
|
||||
performance: NORMAL_ON,
|
||||
hash: OFF_FOR_TO_STRING,
|
||||
env: NORMAL_OFF,
|
||||
version: NORMAL_ON,
|
||||
timings: NORMAL_ON,
|
||||
builtAt: OFF_FOR_TO_STRING,
|
||||
assets: NORMAL_ON,
|
||||
entrypoints: AUTO_FOR_TO_STRING,
|
||||
chunkGroups: OFF_FOR_TO_STRING,
|
||||
chunkGroupAuxiliary: OFF_FOR_TO_STRING,
|
||||
chunkGroupChildren: OFF_FOR_TO_STRING,
|
||||
chunkGroupMaxAssets: (o, { forToString }) => (forToString ? 5 : Infinity),
|
||||
chunks: OFF_FOR_TO_STRING,
|
||||
chunkRelations: OFF_FOR_TO_STRING,
|
||||
chunkModules: ({ all, modules }) => {
|
||||
if (all === false) return false;
|
||||
if (all === true) return true;
|
||||
if (modules) return false;
|
||||
return true;
|
||||
},
|
||||
dependentModules: OFF_FOR_TO_STRING,
|
||||
chunkOrigins: OFF_FOR_TO_STRING,
|
||||
ids: OFF_FOR_TO_STRING,
|
||||
modules: ({ all, chunks, chunkModules }, { forToString }) => {
|
||||
if (all === false) return false;
|
||||
if (all === true) return true;
|
||||
if (forToString && chunks && chunkModules) return false;
|
||||
return true;
|
||||
},
|
||||
nestedModules: OFF_FOR_TO_STRING,
|
||||
groupModulesByType: ON_FOR_TO_STRING,
|
||||
groupModulesByCacheStatus: ON_FOR_TO_STRING,
|
||||
groupModulesByLayer: ON_FOR_TO_STRING,
|
||||
groupModulesByAttributes: ON_FOR_TO_STRING,
|
||||
groupModulesByPath: ON_FOR_TO_STRING,
|
||||
groupModulesByExtension: ON_FOR_TO_STRING,
|
||||
modulesSpace: (o, { forToString }) => (forToString ? 15 : Infinity),
|
||||
chunkModulesSpace: (o, { forToString }) => (forToString ? 10 : Infinity),
|
||||
nestedModulesSpace: (o, { forToString }) => (forToString ? 10 : Infinity),
|
||||
relatedAssets: OFF_FOR_TO_STRING,
|
||||
groupAssetsByEmitStatus: ON_FOR_TO_STRING,
|
||||
groupAssetsByInfo: ON_FOR_TO_STRING,
|
||||
groupAssetsByPath: ON_FOR_TO_STRING,
|
||||
groupAssetsByExtension: ON_FOR_TO_STRING,
|
||||
groupAssetsByChunk: ON_FOR_TO_STRING,
|
||||
assetsSpace: (o, { forToString }) => (forToString ? 15 : Infinity),
|
||||
orphanModules: OFF_FOR_TO_STRING,
|
||||
runtimeModules: ({ all, runtime }, { forToString }) =>
|
||||
runtime !== undefined
|
||||
? runtime
|
||||
: forToString
|
||||
? all === true
|
||||
: all !== false,
|
||||
cachedModules: ({ all, cached }, { forToString }) =>
|
||||
cached !== undefined ? cached : forToString ? all === true : all !== false,
|
||||
moduleAssets: OFF_FOR_TO_STRING,
|
||||
depth: OFF_FOR_TO_STRING,
|
||||
cachedAssets: OFF_FOR_TO_STRING,
|
||||
reasons: OFF_FOR_TO_STRING,
|
||||
reasonsSpace: (o, { forToString }) => (forToString ? 15 : Infinity),
|
||||
groupReasonsByOrigin: ON_FOR_TO_STRING,
|
||||
usedExports: OFF_FOR_TO_STRING,
|
||||
providedExports: OFF_FOR_TO_STRING,
|
||||
optimizationBailout: OFF_FOR_TO_STRING,
|
||||
children: OFF_FOR_TO_STRING,
|
||||
source: NORMAL_OFF,
|
||||
moduleTrace: NORMAL_ON,
|
||||
errors: NORMAL_ON,
|
||||
errorsCount: NORMAL_ON,
|
||||
errorDetails: AUTO_FOR_TO_STRING,
|
||||
errorStack: OFF_FOR_TO_STRING,
|
||||
errorCause: AUTO_FOR_TO_STRING,
|
||||
errorErrors: AUTO_FOR_TO_STRING,
|
||||
warnings: NORMAL_ON,
|
||||
warningsCount: NORMAL_ON,
|
||||
publicPath: OFF_FOR_TO_STRING,
|
||||
logging: ({ all }, { forToString }) =>
|
||||
forToString && all !== false ? "info" : false,
|
||||
loggingDebug: () => [],
|
||||
loggingTrace: OFF_FOR_TO_STRING,
|
||||
excludeModules: () => [],
|
||||
excludeAssets: () => [],
|
||||
modulesSort: () => "depth",
|
||||
chunkModulesSort: () => "name",
|
||||
nestedModulesSort: () => false,
|
||||
chunksSort: () => false,
|
||||
assetsSort: () => "!size",
|
||||
outputPath: OFF_FOR_TO_STRING,
|
||||
colors: () => false
|
||||
};
|
||||
|
||||
/**
|
||||
* @template {string} T
|
||||
* @param {string | ({ test: (value: T) => boolean }) | ((value: T, ...args: EXPECTED_ANY[]) => boolean) | boolean} item item to normalize
|
||||
* @returns {(value: T, ...args: EXPECTED_ANY[]) => boolean} normalize fn
|
||||
*/
|
||||
const normalizeFilter = item => {
|
||||
if (typeof item === "string") {
|
||||
const regExp = new RegExp(
|
||||
`[\\\\/]${item.replace(/[-[\]{}()*+?.\\^$|]/g, "\\$&")}([\\\\/]|$|!|\\?)`
|
||||
);
|
||||
return ident => regExp.test(/** @type {T} */ (ident));
|
||||
}
|
||||
if (item && typeof item === "object" && typeof item.test === "function") {
|
||||
return ident => item.test(ident);
|
||||
}
|
||||
if (typeof item === "boolean") {
|
||||
return () => item;
|
||||
}
|
||||
|
||||
return /** @type {(value: T, ...args: EXPECTED_ANY[]) => boolean} */ (item);
|
||||
};
|
||||
|
||||
/** @typedef {keyof (KnownNormalizedStatsOptions | StatsOptions)} NormalizerKeys */
|
||||
/** @typedef {{ [Key in NormalizerKeys]: (value: StatsOptions[Key]) => KnownNormalizedStatsOptions[Key] }} Normalizers */
|
||||
|
||||
/** @type {Partial<Normalizers>} */
|
||||
const NORMALIZER = {
|
||||
excludeModules: value => {
|
||||
if (!Array.isArray(value)) {
|
||||
value = value
|
||||
? /** @type {KnownNormalizedStatsOptions["excludeModules"]} */ ([value])
|
||||
: [];
|
||||
}
|
||||
return value.map(normalizeFilter);
|
||||
},
|
||||
excludeAssets: value => {
|
||||
if (!Array.isArray(value)) {
|
||||
value = value ? [value] : [];
|
||||
}
|
||||
return value.map(normalizeFilter);
|
||||
},
|
||||
warningsFilter: value => {
|
||||
if (!Array.isArray(value)) {
|
||||
value = value ? [value] : [];
|
||||
}
|
||||
/**
|
||||
* @callback WarningFilterFn
|
||||
* @param {StatsError} warning warning
|
||||
* @param {string} warningString warning string
|
||||
* @returns {boolean} result
|
||||
*/
|
||||
return value.map(
|
||||
/**
|
||||
* @param {StatsOptions["warningsFilter"]} filter a warning filter
|
||||
* @returns {WarningFilterFn} result
|
||||
*/
|
||||
filter => {
|
||||
if (typeof filter === "string") {
|
||||
return (warning, warningString) => warningString.includes(filter);
|
||||
}
|
||||
if (filter instanceof RegExp) {
|
||||
return (warning, warningString) => filter.test(warningString);
|
||||
}
|
||||
if (typeof filter === "function") {
|
||||
return filter;
|
||||
}
|
||||
throw new Error(
|
||||
`Can only filter warnings with Strings or RegExps. (Given: ${filter})`
|
||||
);
|
||||
}
|
||||
);
|
||||
},
|
||||
logging: value => {
|
||||
if (value === true) value = "log";
|
||||
return /** @type {KnownNormalizedStatsOptions["logging"]} */ (value);
|
||||
},
|
||||
loggingDebug: value => {
|
||||
if (!Array.isArray(value)) {
|
||||
value = value
|
||||
? /** @type {KnownNormalizedStatsOptions["loggingDebug"]} */ ([value])
|
||||
: [];
|
||||
}
|
||||
return value.map(normalizeFilter);
|
||||
}
|
||||
};
|
||||
|
||||
const PLUGIN_NAME = "DefaultStatsPresetPlugin";
|
||||
|
||||
class DefaultStatsPresetPlugin {
|
||||
/**
|
||||
* Apply the plugin
|
||||
* @param {Compiler} compiler the compiler instance
|
||||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
compiler.hooks.compilation.tap(PLUGIN_NAME, compilation => {
|
||||
for (const key of Object.keys(NAMED_PRESETS)) {
|
||||
const defaults = NAMED_PRESETS[/** @type {keyof NamedPresets} */ (key)];
|
||||
compilation.hooks.statsPreset
|
||||
.for(key)
|
||||
.tap(PLUGIN_NAME, (options, context) => {
|
||||
applyDefaults(options, defaults);
|
||||
});
|
||||
}
|
||||
compilation.hooks.statsNormalize.tap(PLUGIN_NAME, (options, context) => {
|
||||
for (const key of Object.keys(DEFAULTS)) {
|
||||
if (options[key] === undefined)
|
||||
options[key] =
|
||||
/** @type {Defaults[DefaultsKeys]} */
|
||||
(DEFAULTS[/** @type {DefaultsKeys} */ (key)])(
|
||||
options,
|
||||
context,
|
||||
compilation
|
||||
);
|
||||
}
|
||||
for (const key of Object.keys(NORMALIZER)) {
|
||||
options[key] =
|
||||
/** @type {TODO} */
|
||||
(NORMALIZER[/** @type {NormalizerKeys} */ (key)])(options[key]);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
module.exports = DefaultStatsPresetPlugin;
|
1889
app_vue/node_modules/webpack/lib/stats/DefaultStatsPrinterPlugin.js
generated
vendored
Normal file
1889
app_vue/node_modules/webpack/lib/stats/DefaultStatsPrinterPlugin.js
generated
vendored
Normal file
File diff suppressed because it is too large
Load Diff
400
app_vue/node_modules/webpack/lib/stats/StatsFactory.js
generated
vendored
Normal file
400
app_vue/node_modules/webpack/lib/stats/StatsFactory.js
generated
vendored
Normal file
@ -0,0 +1,400 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const { HookMap, SyncBailHook, SyncWaterfallHook } = require("tapable");
|
||||
const { concatComparators, keepOriginalOrder } = require("../util/comparators");
|
||||
const smartGrouping = require("../util/smartGrouping");
|
||||
|
||||
/** @typedef {import("../Chunk")} Chunk */
|
||||
/** @typedef {import("../ChunkGroup").OriginRecord} OriginRecord */
|
||||
/** @typedef {import("../Compilation")} Compilation */
|
||||
/** @typedef {import("../Compilation").Asset} Asset */
|
||||
/** @typedef {import("../Compilation").NormalizedStatsOptions} NormalizedStatsOptions */
|
||||
/** @typedef {import("../Dependency")} Dependency */
|
||||
/** @typedef {import("../Module")} Module */
|
||||
/** @typedef {import("../ModuleGraph").ModuleProfile} ModuleProfile */
|
||||
/** @typedef {import("../ModuleGraphConnection")} ModuleGraphConnection */
|
||||
/** @typedef {import("../WebpackError")} WebpackError */
|
||||
/** @typedef {import("../util/comparators").Comparator<EXPECTED_ANY>} Comparator */
|
||||
/** @typedef {import("../util/runtime").RuntimeSpec} RuntimeSpec */
|
||||
/** @typedef {import("../util/smartGrouping").GroupConfig<EXPECTED_ANY, EXPECTED_OBJECT>} GroupConfig */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").ChunkGroupInfoWithName} ChunkGroupInfoWithName */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").ModuleIssuerPath} ModuleIssuerPath */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").ModuleTrace} ModuleTrace */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsAsset} StatsAsset */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsChunk} StatsChunk */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsChunkGroup} StatsChunkGroup */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsChunkOrigin} StatsChunkOrigin */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsCompilation} StatsCompilation */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsError} StatsError */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsModule} StatsModule */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsModuleIssuer} StatsModuleIssuer */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsModuleReason} StatsModuleReason */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsModuleTraceDependency} StatsModuleTraceDependency */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsModuleTraceItem} StatsModuleTraceItem */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsProfile} StatsProfile */
|
||||
|
||||
/**
|
||||
* @typedef {object} KnownStatsFactoryContext
|
||||
* @property {string} type
|
||||
* @property {(path: string) => string} makePathsRelative
|
||||
* @property {Compilation} compilation
|
||||
* @property {Set<Module>} rootModules
|
||||
* @property {Map<string, Chunk[]>} compilationFileToChunks
|
||||
* @property {Map<string, Chunk[]>} compilationAuxiliaryFileToChunks
|
||||
* @property {RuntimeSpec} runtime
|
||||
* @property {(compilation: Compilation) => WebpackError[]} cachedGetErrors
|
||||
* @property {(compilation: Compilation) => WebpackError[]} cachedGetWarnings
|
||||
*/
|
||||
|
||||
/** @typedef {KnownStatsFactoryContext & Record<string, EXPECTED_ANY>} StatsFactoryContext */
|
||||
|
||||
// StatsLogging StatsLoggingEntry
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @template F
|
||||
* @typedef {T extends Compilation ? StatsCompilation : T extends ChunkGroupInfoWithName ? StatsChunkGroup : T extends Chunk ? StatsChunk : T extends OriginRecord ? StatsChunkOrigin : T extends Module ? StatsModule : T extends ModuleGraphConnection ? StatsModuleReason : T extends Asset ? StatsAsset : T extends ModuleTrace ? StatsModuleTraceItem : T extends Dependency ? StatsModuleTraceDependency : T extends Error ? StatsError : T extends ModuleProfile ? StatsProfile : F} StatsObject
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @template F
|
||||
* @typedef {T extends ChunkGroupInfoWithName[] ? Record<string, StatsObject<ChunkGroupInfoWithName, F>> : T extends (infer V)[] ? StatsObject<V, F>[] : StatsObject<T, F>} CreatedObject
|
||||
*/
|
||||
|
||||
/** @typedef {TODO} FactoryData */
|
||||
/** @typedef {TODO} FactoryDataItem */
|
||||
/** @typedef {TODO} Result */
|
||||
/** @typedef {Record<string, TODO>} ObjectForExtract */
|
||||
|
||||
/**
|
||||
* @typedef {object} StatsFactoryHooks
|
||||
* @property {HookMap<SyncBailHook<[ObjectForExtract, FactoryData, StatsFactoryContext], void>>} extract
|
||||
* @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext, number, number], boolean | void>>} filter
|
||||
* @property {HookMap<SyncBailHook<[Comparator[], StatsFactoryContext], void>>} sort
|
||||
* @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext, number, number], boolean | void>>} filterSorted
|
||||
* @property {HookMap<SyncBailHook<[GroupConfig[], StatsFactoryContext], void>>} groupResults
|
||||
* @property {HookMap<SyncBailHook<[Comparator[], StatsFactoryContext], void>>} sortResults
|
||||
* @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext, number, number], boolean | void>>} filterResults
|
||||
* @property {HookMap<SyncBailHook<[FactoryDataItem[], StatsFactoryContext], Result | void>>} merge
|
||||
* @property {HookMap<SyncBailHook<[Result, StatsFactoryContext], Result>>} result
|
||||
* @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext], string | void>>} getItemName
|
||||
* @property {HookMap<SyncBailHook<[FactoryDataItem, StatsFactoryContext], StatsFactory | void>>} getItemFactory
|
||||
*/
|
||||
|
||||
/**
|
||||
* @template T
|
||||
* @typedef {Map<string, T[]>} Caches
|
||||
*/
|
||||
|
||||
class StatsFactory {
|
||||
constructor() {
|
||||
/** @type {StatsFactoryHooks} */
|
||||
this.hooks = Object.freeze({
|
||||
extract: new HookMap(
|
||||
() => new SyncBailHook(["object", "data", "context"])
|
||||
),
|
||||
filter: new HookMap(
|
||||
() => new SyncBailHook(["item", "context", "index", "unfilteredIndex"])
|
||||
),
|
||||
sort: new HookMap(() => new SyncBailHook(["comparators", "context"])),
|
||||
filterSorted: new HookMap(
|
||||
() => new SyncBailHook(["item", "context", "index", "unfilteredIndex"])
|
||||
),
|
||||
groupResults: new HookMap(
|
||||
() => new SyncBailHook(["groupConfigs", "context"])
|
||||
),
|
||||
sortResults: new HookMap(
|
||||
() => new SyncBailHook(["comparators", "context"])
|
||||
),
|
||||
filterResults: new HookMap(
|
||||
() => new SyncBailHook(["item", "context", "index", "unfilteredIndex"])
|
||||
),
|
||||
merge: new HookMap(() => new SyncBailHook(["items", "context"])),
|
||||
result: new HookMap(() => new SyncWaterfallHook(["result", "context"])),
|
||||
getItemName: new HookMap(() => new SyncBailHook(["item", "context"])),
|
||||
getItemFactory: new HookMap(() => new SyncBailHook(["item", "context"]))
|
||||
});
|
||||
const hooks = this.hooks;
|
||||
this._caches = /** @type {TODO} */ ({});
|
||||
for (const key of Object.keys(hooks)) {
|
||||
this._caches[/** @type {keyof StatsFactoryHooks} */ (key)] = new Map();
|
||||
}
|
||||
this._inCreate = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {StatsFactoryHooks[keyof StatsFactoryHooks]} HM
|
||||
* @template {HM extends HookMap<infer H> ? H : never} H
|
||||
* @param {HM} hookMap hook map
|
||||
* @param {Caches<H>} cache cache
|
||||
* @param {string} type type
|
||||
* @returns {H[]} hooks
|
||||
* @private
|
||||
*/
|
||||
_getAllLevelHooks(hookMap, cache, type) {
|
||||
const cacheEntry = cache.get(type);
|
||||
if (cacheEntry !== undefined) {
|
||||
return cacheEntry;
|
||||
}
|
||||
const hooks = /** @type {H[]} */ ([]);
|
||||
const typeParts = type.split(".");
|
||||
for (let i = 0; i < typeParts.length; i++) {
|
||||
const hook = /** @type {H} */ (hookMap.get(typeParts.slice(i).join(".")));
|
||||
if (hook) {
|
||||
hooks.push(hook);
|
||||
}
|
||||
}
|
||||
cache.set(type, hooks);
|
||||
return hooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {StatsFactoryHooks[keyof StatsFactoryHooks]} HM
|
||||
* @template {HM extends HookMap<infer H> ? H : never} H
|
||||
* @template {H extends import("tapable").Hook<any, infer R> ? R : never} R
|
||||
* @param {HM} hookMap hook map
|
||||
* @param {Caches<H>} cache cache
|
||||
* @param {string} type type
|
||||
* @param {(hook: H) => R | void} fn fn
|
||||
* @returns {R | void} hook
|
||||
* @private
|
||||
*/
|
||||
_forEachLevel(hookMap, cache, type, fn) {
|
||||
for (const hook of this._getAllLevelHooks(hookMap, cache, type)) {
|
||||
const result = fn(/** @type {H} */ (hook));
|
||||
if (result !== undefined) return result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {StatsFactoryHooks[keyof StatsFactoryHooks]} HM
|
||||
* @template {HM extends HookMap<infer H> ? H : never} H
|
||||
* @param {HM} hookMap hook map
|
||||
* @param {Caches<H>} cache cache
|
||||
* @param {string} type type
|
||||
* @param {FactoryData} data data
|
||||
* @param {(hook: H, factoryData: FactoryData) => FactoryData} fn fn
|
||||
* @returns {FactoryData} data
|
||||
* @private
|
||||
*/
|
||||
_forEachLevelWaterfall(hookMap, cache, type, data, fn) {
|
||||
for (const hook of this._getAllLevelHooks(hookMap, cache, type)) {
|
||||
data = fn(/** @type {H} */ (hook), data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @template {StatsFactoryHooks[keyof StatsFactoryHooks]} T
|
||||
* @template {T extends HookMap<infer H> ? H : never} H
|
||||
* @template {H extends import("tapable").Hook<any, infer R> ? R : never} R
|
||||
* @param {T} hookMap hook map
|
||||
* @param {Caches<H>} cache cache
|
||||
* @param {string} type type
|
||||
* @param {Array<FactoryData>} items items
|
||||
* @param {(hook: H, item: R, idx: number, i: number) => R | undefined} fn fn
|
||||
* @param {boolean} forceClone force clone
|
||||
* @returns {R[]} result for each level
|
||||
* @private
|
||||
*/
|
||||
_forEachLevelFilter(hookMap, cache, type, items, fn, forceClone) {
|
||||
const hooks = this._getAllLevelHooks(hookMap, cache, type);
|
||||
if (hooks.length === 0) return forceClone ? items.slice() : items;
|
||||
let i = 0;
|
||||
return items.filter((item, idx) => {
|
||||
for (const hook of hooks) {
|
||||
const r = fn(/** @type {H} */ (hook), item, idx, i);
|
||||
if (r !== undefined) {
|
||||
if (r) i++;
|
||||
return r;
|
||||
}
|
||||
}
|
||||
i++;
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @template FactoryData
|
||||
* @template FallbackCreatedObject
|
||||
* @param {string} type type
|
||||
* @param {FactoryData} data factory data
|
||||
* @param {Omit<StatsFactoryContext, "type">} baseContext context used as base
|
||||
* @returns {CreatedObject<FactoryData, FallbackCreatedObject>} created object
|
||||
*/
|
||||
create(type, data, baseContext) {
|
||||
if (this._inCreate) {
|
||||
return this._create(type, data, baseContext);
|
||||
}
|
||||
try {
|
||||
this._inCreate = true;
|
||||
return this._create(type, data, baseContext);
|
||||
} finally {
|
||||
for (const key of Object.keys(this._caches))
|
||||
this._caches[/** @type {keyof StatsFactoryHooks} */ (key)].clear();
|
||||
this._inCreate = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @template FactoryData
|
||||
* @template FallbackCreatedObject
|
||||
* @param {string} type type
|
||||
* @param {FactoryData} data factory data
|
||||
* @param {Omit<StatsFactoryContext, "type">} baseContext context used as base
|
||||
* @returns {CreatedObject<FactoryData, FallbackCreatedObject>} created object
|
||||
*/
|
||||
_create(type, data, baseContext) {
|
||||
const context = /** @type {StatsFactoryContext} */ ({
|
||||
...baseContext,
|
||||
type,
|
||||
[type]: data
|
||||
});
|
||||
if (Array.isArray(data)) {
|
||||
// run filter on unsorted items
|
||||
const items = this._forEachLevelFilter(
|
||||
this.hooks.filter,
|
||||
this._caches.filter,
|
||||
type,
|
||||
data,
|
||||
(h, r, idx, i) => h.call(r, context, idx, i),
|
||||
true
|
||||
);
|
||||
|
||||
// sort items
|
||||
/** @type {Comparator[]} */
|
||||
const comparators = [];
|
||||
this._forEachLevel(this.hooks.sort, this._caches.sort, type, h =>
|
||||
h.call(comparators, context)
|
||||
);
|
||||
if (comparators.length > 0) {
|
||||
items.sort(
|
||||
// @ts-expect-error number of arguments is correct
|
||||
concatComparators(...comparators, keepOriginalOrder(items))
|
||||
);
|
||||
}
|
||||
|
||||
// run filter on sorted items
|
||||
const items2 = this._forEachLevelFilter(
|
||||
this.hooks.filterSorted,
|
||||
this._caches.filterSorted,
|
||||
type,
|
||||
items,
|
||||
(h, r, idx, i) => h.call(r, context, idx, i),
|
||||
false
|
||||
);
|
||||
|
||||
// for each item
|
||||
let resultItems = items2.map((item, i) => {
|
||||
/** @type {StatsFactoryContext} */
|
||||
const itemContext = {
|
||||
...context,
|
||||
_index: i
|
||||
};
|
||||
|
||||
// run getItemName
|
||||
const itemName = this._forEachLevel(
|
||||
this.hooks.getItemName,
|
||||
this._caches.getItemName,
|
||||
`${type}[]`,
|
||||
h => h.call(item, itemContext)
|
||||
);
|
||||
if (itemName) itemContext[itemName] = item;
|
||||
const innerType = itemName ? `${type}[].${itemName}` : `${type}[]`;
|
||||
|
||||
// run getItemFactory
|
||||
const itemFactory =
|
||||
this._forEachLevel(
|
||||
this.hooks.getItemFactory,
|
||||
this._caches.getItemFactory,
|
||||
innerType,
|
||||
h => h.call(item, itemContext)
|
||||
) || this;
|
||||
|
||||
// run item factory
|
||||
return itemFactory.create(innerType, item, itemContext);
|
||||
});
|
||||
|
||||
// sort result items
|
||||
/** @type {Comparator[]} */
|
||||
const comparators2 = [];
|
||||
this._forEachLevel(
|
||||
this.hooks.sortResults,
|
||||
this._caches.sortResults,
|
||||
type,
|
||||
h => h.call(comparators2, context)
|
||||
);
|
||||
if (comparators2.length > 0) {
|
||||
resultItems.sort(
|
||||
// @ts-expect-error number of arguments is correct
|
||||
concatComparators(...comparators2, keepOriginalOrder(resultItems))
|
||||
);
|
||||
}
|
||||
|
||||
// group result items
|
||||
/** @type {GroupConfig[]} */
|
||||
const groupConfigs = [];
|
||||
this._forEachLevel(
|
||||
this.hooks.groupResults,
|
||||
this._caches.groupResults,
|
||||
type,
|
||||
h => h.call(groupConfigs, context)
|
||||
);
|
||||
if (groupConfigs.length > 0) {
|
||||
resultItems = smartGrouping(resultItems, groupConfigs);
|
||||
}
|
||||
|
||||
// run filter on sorted result items
|
||||
const finalResultItems = this._forEachLevelFilter(
|
||||
this.hooks.filterResults,
|
||||
this._caches.filterResults,
|
||||
type,
|
||||
resultItems,
|
||||
(h, r, idx, i) => h.call(r, context, idx, i),
|
||||
false
|
||||
);
|
||||
|
||||
// run merge on mapped items
|
||||
let result = this._forEachLevel(
|
||||
this.hooks.merge,
|
||||
this._caches.merge,
|
||||
type,
|
||||
h => h.call(finalResultItems, context)
|
||||
);
|
||||
if (result === undefined) result = finalResultItems;
|
||||
|
||||
// run result on merged items
|
||||
return this._forEachLevelWaterfall(
|
||||
this.hooks.result,
|
||||
this._caches.result,
|
||||
type,
|
||||
result,
|
||||
(h, r) => h.call(r, context)
|
||||
);
|
||||
}
|
||||
/** @type {ObjectForExtract} */
|
||||
const object = {};
|
||||
|
||||
// run extract on value
|
||||
this._forEachLevel(this.hooks.extract, this._caches.extract, type, h =>
|
||||
h.call(object, data, context)
|
||||
);
|
||||
|
||||
// run result on extracted object
|
||||
return this._forEachLevelWaterfall(
|
||||
this.hooks.result,
|
||||
this._caches.result,
|
||||
type,
|
||||
object,
|
||||
(h, r) => h.call(r, context)
|
||||
);
|
||||
}
|
||||
}
|
||||
module.exports = StatsFactory;
|
301
app_vue/node_modules/webpack/lib/stats/StatsPrinter.js
generated
vendored
Normal file
301
app_vue/node_modules/webpack/lib/stats/StatsPrinter.js
generated
vendored
Normal file
@ -0,0 +1,301 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Tobias Koppers @sokra
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
const { HookMap, SyncWaterfallHook, SyncBailHook } = require("tapable");
|
||||
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsAsset} StatsAsset */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsChunk} StatsChunk */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsChunkGroup} StatsChunkGroup */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsCompilation} StatsCompilation */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsError} StatsError */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsLogging} StatsLogging */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsModule} StatsModule */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsModuleIssuer} StatsModuleIssuer */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsModuleReason} StatsModuleReason */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsModuleTraceDependency} StatsModuleTraceDependency */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsModuleTraceItem} StatsModuleTraceItem */
|
||||
/** @typedef {import("./DefaultStatsFactoryPlugin").StatsProfile} StatsProfile */
|
||||
|
||||
/**
|
||||
* @typedef {object} PrintedElement
|
||||
* @property {string} element
|
||||
* @property {string | undefined} content
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} KnownStatsPrinterContext
|
||||
* @property {string=} type
|
||||
* @property {StatsCompilation=} compilation
|
||||
* @property {StatsChunkGroup=} chunkGroup
|
||||
* @property {string=} chunkGroupKind
|
||||
* @property {StatsAsset=} asset
|
||||
* @property {StatsModule=} module
|
||||
* @property {StatsChunk=} chunk
|
||||
* @property {StatsModuleReason=} moduleReason
|
||||
* @property {StatsModuleIssuer=} moduleIssuer
|
||||
* @property {StatsError=} error
|
||||
* @property {StatsProfile=} profile
|
||||
* @property {StatsLogging=} logging
|
||||
* @property {StatsModuleTraceItem=} moduleTraceItem
|
||||
* @property {StatsModuleTraceDependency=} moduleTraceDependency
|
||||
*/
|
||||
|
||||
/** @typedef {(value: string | number) => string} ColorFunction */
|
||||
|
||||
/**
|
||||
* @typedef {object} KnownStatsPrinterColorFunctions
|
||||
* @property {ColorFunction=} bold
|
||||
* @property {ColorFunction=} yellow
|
||||
* @property {ColorFunction=} red
|
||||
* @property {ColorFunction=} green
|
||||
* @property {ColorFunction=} magenta
|
||||
* @property {ColorFunction=} cyan
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {object} KnownStatsPrinterFormatters
|
||||
* @property {(file: string, oversize?: boolean) => string=} formatFilename
|
||||
* @property {(id: string | number) => string=} formatModuleId
|
||||
* @property {(id: string | number, direction?: "parent" | "child" | "sibling") => string=} formatChunkId
|
||||
* @property {(size: number) => string=} formatSize
|
||||
* @property {(size: string) => string=} formatLayer
|
||||
* @property {(dateTime: number) => string=} formatDateTime
|
||||
* @property {(flag: string) => string=} formatFlag
|
||||
* @property {(time: number, boldQuantity?: boolean) => string=} formatTime
|
||||
* @property {(message: string) => string=} formatError
|
||||
*/
|
||||
|
||||
/** @typedef {KnownStatsPrinterColorFunctions & KnownStatsPrinterFormatters & KnownStatsPrinterContext & Record<string, EXPECTED_ANY>} StatsPrinterContext */
|
||||
/** @typedef {StatsPrinterContext & Required<KnownStatsPrinterColorFunctions> & Required<KnownStatsPrinterFormatters> & { type: string }} StatsPrinterContextWithExtra */
|
||||
/** @typedef {EXPECTED_ANY} PrintObject */
|
||||
|
||||
/**
|
||||
* @typedef {object} StatsPrintHooks
|
||||
* @property {HookMap<SyncBailHook<[string[], StatsPrinterContext], void>>} sortElements
|
||||
* @property {HookMap<SyncBailHook<[PrintedElement[], StatsPrinterContext], string | undefined | void>>} printElements
|
||||
* @property {HookMap<SyncBailHook<[PrintObject[], StatsPrinterContext], boolean | void>>} sortItems
|
||||
* @property {HookMap<SyncBailHook<[PrintObject, StatsPrinterContext], string | void>>} getItemName
|
||||
* @property {HookMap<SyncBailHook<[string[], StatsPrinterContext], string | undefined>>} printItems
|
||||
* @property {HookMap<SyncBailHook<[PrintObject, StatsPrinterContext], string | undefined | void>>} print
|
||||
* @property {HookMap<SyncWaterfallHook<[string, StatsPrinterContext]>>} result
|
||||
*/
|
||||
|
||||
class StatsPrinter {
|
||||
constructor() {
|
||||
/** @type {StatsPrintHooks} */
|
||||
this.hooks = Object.freeze({
|
||||
sortElements: new HookMap(
|
||||
() => new SyncBailHook(["elements", "context"])
|
||||
),
|
||||
printElements: new HookMap(
|
||||
() => new SyncBailHook(["printedElements", "context"])
|
||||
),
|
||||
sortItems: new HookMap(() => new SyncBailHook(["items", "context"])),
|
||||
getItemName: new HookMap(() => new SyncBailHook(["item", "context"])),
|
||||
printItems: new HookMap(
|
||||
() => new SyncBailHook(["printedItems", "context"])
|
||||
),
|
||||
print: new HookMap(() => new SyncBailHook(["object", "context"])),
|
||||
result: new HookMap(() => new SyncWaterfallHook(["result", "context"]))
|
||||
});
|
||||
/**
|
||||
* @type {TODO}
|
||||
*/
|
||||
this._levelHookCache = new Map();
|
||||
this._inPrint = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* get all level hooks
|
||||
* @private
|
||||
* @template {StatsPrintHooks[keyof StatsPrintHooks]} HM
|
||||
* @template {HM extends HookMap<infer H> ? H : never} H
|
||||
* @param {HM} hookMap hook map
|
||||
* @param {string} type type
|
||||
* @returns {H[]} hooks
|
||||
*/
|
||||
_getAllLevelHooks(hookMap, type) {
|
||||
let cache = this._levelHookCache.get(hookMap);
|
||||
if (cache === undefined) {
|
||||
cache = new Map();
|
||||
this._levelHookCache.set(hookMap, cache);
|
||||
}
|
||||
const cacheEntry = cache.get(type);
|
||||
if (cacheEntry !== undefined) {
|
||||
return cacheEntry;
|
||||
}
|
||||
/** @type {H[]} */
|
||||
const hooks = [];
|
||||
const typeParts = type.split(".");
|
||||
for (let i = 0; i < typeParts.length; i++) {
|
||||
const hook = /** @type {H} */ (hookMap.get(typeParts.slice(i).join(".")));
|
||||
if (hook) {
|
||||
hooks.push(hook);
|
||||
}
|
||||
}
|
||||
cache.set(type, hooks);
|
||||
return hooks;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run `fn` for each level
|
||||
* @private
|
||||
* @template {StatsPrintHooks[keyof StatsPrintHooks]} HM
|
||||
* @template {HM extends HookMap<infer H> ? H : never} H
|
||||
* @template {H extends import("tapable").Hook<any, infer R> ? R : never} R
|
||||
* @param {HM} hookMap hook map
|
||||
* @param {string} type type
|
||||
* @param {(hooK: H) => R | undefined | void} fn fn
|
||||
* @returns {R | undefined} hook
|
||||
*/
|
||||
_forEachLevel(hookMap, type, fn) {
|
||||
for (const hook of this._getAllLevelHooks(hookMap, type)) {
|
||||
const result = fn(/** @type {H} */ (hook));
|
||||
if (result !== undefined) return /** @type {R} */ (result);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Run `fn` for each level
|
||||
* @private
|
||||
* @template {StatsPrintHooks[keyof StatsPrintHooks]} HM
|
||||
* @template {HM extends HookMap<infer H> ? H : never} H
|
||||
* @param {HM} hookMap hook map
|
||||
* @param {string} type type
|
||||
* @param {string} data data
|
||||
* @param {(hook: H, data: string) => string} fn fn
|
||||
* @returns {string | undefined} result of `fn`
|
||||
*/
|
||||
_forEachLevelWaterfall(hookMap, type, data, fn) {
|
||||
for (const hook of this._getAllLevelHooks(hookMap, type)) {
|
||||
data = fn(/** @type {H} */ (hook), data);
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} type The type
|
||||
* @param {PrintObject} object Object to print
|
||||
* @param {StatsPrinterContext=} baseContext The base context
|
||||
* @returns {string | undefined} printed result
|
||||
*/
|
||||
print(type, object, baseContext) {
|
||||
if (this._inPrint) {
|
||||
return this._print(type, object, baseContext);
|
||||
}
|
||||
try {
|
||||
this._inPrint = true;
|
||||
return this._print(type, object, baseContext);
|
||||
} finally {
|
||||
this._levelHookCache.clear();
|
||||
this._inPrint = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @private
|
||||
* @param {string} type type
|
||||
* @param {PrintObject} object object
|
||||
* @param {StatsPrinterContext=} baseContext context
|
||||
* @returns {string | undefined} printed result
|
||||
*/
|
||||
_print(type, object, baseContext) {
|
||||
/** @type {StatsPrinterContext} */
|
||||
const context = {
|
||||
...baseContext,
|
||||
type,
|
||||
[type]: object
|
||||
};
|
||||
|
||||
/** @type {string | undefined} */
|
||||
let printResult = this._forEachLevel(this.hooks.print, type, hook =>
|
||||
hook.call(object, context)
|
||||
);
|
||||
if (printResult === undefined) {
|
||||
if (Array.isArray(object)) {
|
||||
const sortedItems = object.slice();
|
||||
this._forEachLevel(this.hooks.sortItems, type, h =>
|
||||
h.call(
|
||||
sortedItems,
|
||||
/** @type {StatsPrinterContextWithExtra} */
|
||||
(context)
|
||||
)
|
||||
);
|
||||
const printedItems = sortedItems.map((item, i) => {
|
||||
const itemContext =
|
||||
/** @type {StatsPrinterContextWithExtra} */
|
||||
({
|
||||
...context,
|
||||
_index: i
|
||||
});
|
||||
const itemName = this._forEachLevel(
|
||||
this.hooks.getItemName,
|
||||
`${type}[]`,
|
||||
h => h.call(item, itemContext)
|
||||
);
|
||||
if (itemName) itemContext[itemName] = item;
|
||||
return this.print(
|
||||
itemName ? `${type}[].${itemName}` : `${type}[]`,
|
||||
item,
|
||||
itemContext
|
||||
);
|
||||
});
|
||||
printResult = this._forEachLevel(this.hooks.printItems, type, h =>
|
||||
h.call(
|
||||
/** @type {string[]} */ (printedItems),
|
||||
/** @type {StatsPrinterContextWithExtra} */
|
||||
(context)
|
||||
)
|
||||
);
|
||||
if (printResult === undefined) {
|
||||
const result = printedItems.filter(Boolean);
|
||||
if (result.length > 0) printResult = result.join("\n");
|
||||
}
|
||||
} else if (object !== null && typeof object === "object") {
|
||||
const elements = Object.keys(object).filter(
|
||||
key => object[key] !== undefined
|
||||
);
|
||||
this._forEachLevel(this.hooks.sortElements, type, h =>
|
||||
h.call(
|
||||
elements,
|
||||
/** @type {StatsPrinterContextWithExtra} */
|
||||
(context)
|
||||
)
|
||||
);
|
||||
const printedElements = elements.map(element => {
|
||||
const content = this.print(`${type}.${element}`, object[element], {
|
||||
...context,
|
||||
_parent: object,
|
||||
_element: element,
|
||||
[element]: object[element]
|
||||
});
|
||||
return { element, content };
|
||||
});
|
||||
printResult = this._forEachLevel(this.hooks.printElements, type, h =>
|
||||
h.call(
|
||||
printedElements,
|
||||
/** @type {StatsPrinterContextWithExtra} */
|
||||
(context)
|
||||
)
|
||||
);
|
||||
if (printResult === undefined) {
|
||||
const result = printedElements.map(e => e.content).filter(Boolean);
|
||||
if (result.length > 0) printResult = result.join("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this._forEachLevelWaterfall(
|
||||
this.hooks.result,
|
||||
type,
|
||||
/** @type {string} */
|
||||
(printResult),
|
||||
(h, r) => h.call(r, /** @type {StatsPrinterContextWithExtra} */ (context))
|
||||
);
|
||||
}
|
||||
}
|
||||
module.exports = StatsPrinter;
|
Reference in New Issue
Block a user