@statoscope/webpack-model
Advanced tools
Comparing version 5.8.0 to 5.9.0
@@ -35,5 +35,6 @@ "use strict"; | ||
function prepareWithJora(stats, options = {}) { | ||
const { files, compilations } = normalize_1.default(stats); | ||
const prepared = jora_1.prepareWithJora(files, { | ||
helpers: { ...jora_helpers_1.default(compilations), ...options.helpers }, | ||
const normalizeResult = (0, normalize_1.default)(stats); | ||
const { files, compilations } = normalizeResult; | ||
const prepared = (0, jora_1.prepareWithJora)(files, { | ||
helpers: { ...(0, jora_helpers_1.default)(normalizeResult), ...options.helpers }, | ||
}); | ||
@@ -40,0 +41,0 @@ return { |
@@ -5,7 +5,8 @@ import type { Size } from '@statoscope/stats-extension-compressed/dist/generator'; | ||
import type { Item } from '@statoscope/stats-extension-stats-validation-result/dist/generator'; | ||
import { RelatedItem } from '@statoscope/types/types/validation/test-entry'; | ||
import { RelationItem } from '@statoscope/types/types'; | ||
import { RuleDescriptor } from '@statoscope/types/types/validation/api'; | ||
import { Report } from '@statoscope/types/types/custom-report'; | ||
import { Webpack } from '../webpack'; | ||
import { moduleNameResource, moduleReasonResource, moduleResource, nodeModule } from './module'; | ||
import { HandledCompilation, ModuleGraphNodeData, NodeModuleInstance, NormalizedAsset, NormalizedChunk, NormalizedCompilation, NormalizedEntrypointItem, NormalizedFile, NormalizedModule, NormalizedPackage } from './normalize'; | ||
import { ModuleGraphNodeData, NodeModuleInstance, NormalizedAsset, NormalizedChunk, NormalizedCompilation, NormalizedEntrypointItem, NormalizedExtension, NormalizedFile, NormalizedModule, NormalizedPackage, NormalizeResult } from './normalize'; | ||
import { Node as FoamTreeNode } from './modules-to-foam-tree'; | ||
@@ -39,3 +40,3 @@ import ChunkID = Webpack.ChunkID; | ||
}; | ||
export default function (compilations: HandledCompilation[]): { | ||
export default function (normalizeResult: NormalizeResult): { | ||
moduleSize(module: NormalizedModule): number; | ||
@@ -54,3 +55,3 @@ chunkName(chunk: NormalizedChunk): string; | ||
resolveCompilation(id: string): NormalizedCompilation | null; | ||
resolveExtension(id: string, hash: string): unknown; | ||
resolveExtension(id: string, hash: string): NormalizedExtension<unknown, unknown> | null; | ||
getModuleSize(module: NormalizedModule, hash?: string | undefined, compressed?: boolean | undefined): Size; | ||
@@ -68,6 +69,8 @@ getAssetSize(asset: NormalizedAsset, hash?: string | undefined, compressed?: boolean | undefined): Size; | ||
modulesToFoamTree(modules: NormalizedModule[], hash?: string | undefined, compressed?: boolean | undefined): FoamTreeNode; | ||
validation_getItems(hash?: string | undefined, relatedType?: "module" | "package" | "package-instance" | "resource" | "entry" | "compilation" | "chunk" | null | undefined, relatedId?: string | number | undefined): Item[]; | ||
validation_getItems(hash?: string | undefined, relatedType?: "module" | "entry" | "package" | "package-instance" | "resource" | "compilation" | "chunk" | null | undefined, relatedId?: string | number | undefined): Item[]; | ||
validation_getItem(id?: number | undefined, hash?: string | undefined): Item | null; | ||
validation_resolveRelatedItem(item?: RelatedItem | undefined, hash?: string | undefined): ResolvedRelatedItem; | ||
validation_resolveRelatedItem(item?: RelationItem | undefined, hash?: string | undefined): ResolvedRelatedItem; | ||
validation_resolveRule(name?: string | undefined, hash?: string | undefined): RuleDescriptor | null; | ||
customReports_getItems(file: string, hash?: string | null | undefined, relatedType?: "module" | "entry" | "package" | "package-instance" | "resource" | "compilation" | "chunk" | null | undefined, relatedId?: string | number | undefined): Report<unknown, unknown>[]; | ||
customReports_getItem(id: string, file: string): Report<unknown, unknown> | null; | ||
}; |
@@ -10,5 +10,14 @@ "use strict"; | ||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/explicit-function-return-type | ||
function default_1(compilations) { | ||
const resolveCompilation = entity_resolver_1.default(compilations, (item) => { var _a; return (_a = item === null || item === void 0 ? void 0 : item.data) === null || _a === void 0 ? void 0 : _a.hash; }); | ||
const resolveFile = entity_resolver_1.default(compilations.map((c) => c.file), (item) => item.name); | ||
function default_1(normalizeResult) { | ||
const compilations = normalizeResult.compilations; | ||
const resolveCompilation = (0, entity_resolver_1.default)(compilations, (item) => { var _a; return (_a = item === null || item === void 0 ? void 0 : item.data) === null || _a === void 0 ? void 0 : _a.hash; }); | ||
const resolveFile = (0, entity_resolver_1.default)(compilations.map((c) => c.file), (item) => item.name); | ||
const resolveExtension = (hash, id) => { | ||
var _a, _b, _c; | ||
const fileName = (_a = resolveCompilation(hash)) === null || _a === void 0 ? void 0 : _a.file.name; | ||
if (!fileName) { | ||
return null; | ||
} | ||
return (_c = (_b = normalizeResult.fileResolvers.get(fileName)) === null || _b === void 0 ? void 0 : _b.resolveExtension(id)) !== null && _c !== void 0 ? _c : null; | ||
}; | ||
return { | ||
@@ -23,3 +32,2 @@ moduleSize(module) { | ||
getTotalFilesSize: (asset, hash, compressed) => { | ||
var _a; | ||
const files = asset.files.length | ||
@@ -34,3 +42,3 @@ ? asset.files | ||
} | ||
const ext = (_a = resolveCompilation(hash)) === null || _a === void 0 ? void 0 : _a.resolvers.resolveExtension('@statoscope/stats-extension-compressed'); | ||
const ext = resolveExtension(hash, '@statoscope/stats-extension-compressed'); | ||
const resolverSize = ext === null || ext === void 0 ? void 0 : ext.api; | ||
@@ -79,7 +87,6 @@ return files | ||
resolveExtension(id, hash) { | ||
var _a; | ||
return (_a = resolveCompilation(hash)) === null || _a === void 0 ? void 0 : _a.resolvers.resolveExtension(id); | ||
return resolveExtension(hash, id); | ||
}, | ||
getModuleSize(module, hash, compressed) { | ||
var _a, _b; | ||
var _a; | ||
if (!compressed) { | ||
@@ -91,5 +98,5 @@ return { size: module.size }; | ||
} | ||
const ext = (_a = resolveCompilation(hash)) === null || _a === void 0 ? void 0 : _a.resolvers.resolveExtension('@statoscope/stats-extension-compressed'); | ||
const ext = resolveExtension(hash, '@statoscope/stats-extension-compressed'); | ||
const resolverSize = ext === null || ext === void 0 ? void 0 : ext.api; | ||
return ((_b = resolverSize === null || resolverSize === void 0 ? void 0 : resolverSize(hash, module.name)) !== null && _b !== void 0 ? _b : { | ||
return ((_a = resolverSize === null || resolverSize === void 0 ? void 0 : resolverSize(hash, module.identifier)) !== null && _a !== void 0 ? _a : { | ||
size: module.size, | ||
@@ -99,3 +106,3 @@ }); | ||
getAssetSize(asset, hash, compressed) { | ||
var _a, _b; | ||
var _a; | ||
if (!compressed) { | ||
@@ -107,5 +114,5 @@ return { size: asset.size }; | ||
} | ||
const ext = (_a = resolveCompilation(hash)) === null || _a === void 0 ? void 0 : _a.resolvers.resolveExtension('@statoscope/stats-extension-compressed'); | ||
const ext = resolveExtension(hash, '@statoscope/stats-extension-compressed'); | ||
const resolverSize = ext === null || ext === void 0 ? void 0 : ext.api; | ||
return ((_b = resolverSize === null || resolverSize === void 0 ? void 0 : resolverSize(hash, asset.name)) !== null && _b !== void 0 ? _b : { | ||
return ((_a = resolverSize === null || resolverSize === void 0 ? void 0 : resolverSize(hash, asset.name)) !== null && _a !== void 0 ? _a : { | ||
size: asset.size, | ||
@@ -115,9 +122,9 @@ }); | ||
getPackageInstanceInfo(packageName, instancePath, hash) { | ||
var _a, _b; | ||
var _a; | ||
if (!hash) { | ||
throw new Error('[getPackageInstanceInfo]: hash-parameter is required'); | ||
} | ||
const ext = (_a = resolveCompilation(hash)) === null || _a === void 0 ? void 0 : _a.resolvers.resolveExtension('@statoscope/stats-extension-package-info'); | ||
const ext = resolveExtension(hash, '@statoscope/stats-extension-package-info'); | ||
const api = ext === null || ext === void 0 ? void 0 : ext.api; | ||
return (_b = api === null || api === void 0 ? void 0 : api.getInstance(hash, packageName, instancePath)) !== null && _b !== void 0 ? _b : null; | ||
return (_a = api === null || api === void 0 ? void 0 : api.getInstance(hash, packageName, instancePath)) !== null && _a !== void 0 ? _a : null; | ||
}, | ||
@@ -133,3 +140,3 @@ moduleResource: module_1.moduleResource, | ||
const hash = stat.compilation.hash.slice(0, 7); | ||
const compilationName = stat.compilation.name && module_1.moduleNameResource(stat.compilation.name); | ||
const compilationName = stat.compilation.name && (0, module_1.moduleNameResource)(stat.compilation.name); | ||
if (stat.file.name) { | ||
@@ -151,3 +158,3 @@ return `${stat.file.name} (${compilationName || hash})`; | ||
} | ||
const moduleNode = graph.getNode(module.name); | ||
const moduleNode = graph.getNode(module.identifier); | ||
if (!moduleNode) { | ||
@@ -164,4 +171,4 @@ return []; | ||
} | ||
const entryModuleName = (_a = entry.data.dep) === null || _a === void 0 ? void 0 : _a.module.name; | ||
const entryModule = graph.getNode(entryModuleName); | ||
const entryModuleId = (_a = entry.data.dep) === null || _a === void 0 ? void 0 : _a.module.identifier; | ||
const entryModule = graph.getNode(entryModuleId); | ||
if (entryModule) { | ||
@@ -185,4 +192,4 @@ if (moduleNode === entryModule) { | ||
} | ||
const fromNode = graph.getNode(from.name); | ||
const toNode = graph.getNode(to.name); | ||
const fromNode = graph.getNode(from.identifier); | ||
const toNode = graph.getNode(to.identifier); | ||
if (!fromNode || !toNode) { | ||
@@ -197,3 +204,3 @@ return null; | ||
} | ||
return modules_to_foam_tree_1.default(modules, (module) => { | ||
return (0, modules_to_foam_tree_1.default)(modules, (module) => { | ||
if (compressed && hash) { | ||
@@ -206,15 +213,15 @@ return this.getModuleSize(module, hash, compressed); | ||
validation_getItems(hash, relatedType, relatedId) { | ||
var _a, _b, _c; | ||
var _a, _b; | ||
if (!hash) { | ||
throw new Error('[validation_getItems]: hash-parameter is required'); | ||
} | ||
const ext = (_a = resolveCompilation(hash)) === null || _a === void 0 ? void 0 : _a.resolvers.resolveExtension('@statoscope/stats-extension-stats-validation-result'); | ||
const ext = resolveExtension(hash, '@statoscope/stats-extension-stats-validation-result'); | ||
const api = ext === null || ext === void 0 ? void 0 : ext.api; | ||
return [ | ||
...((_b = api === null || api === void 0 ? void 0 : api.getItems(null, relatedType, relatedId)) !== null && _b !== void 0 ? _b : []), | ||
...((_c = api === null || api === void 0 ? void 0 : api.getItems(hash, relatedType, relatedId)) !== null && _c !== void 0 ? _c : []), | ||
...((_a = api === null || api === void 0 ? void 0 : api.getItems(null, relatedType, relatedId)) !== null && _a !== void 0 ? _a : []), | ||
...((_b = api === null || api === void 0 ? void 0 : api.getItems(hash, relatedType, relatedId)) !== null && _b !== void 0 ? _b : []), | ||
]; | ||
}, | ||
validation_getItem(id, hash) { | ||
var _a, _b; | ||
var _a; | ||
if (!hash) { | ||
@@ -226,5 +233,5 @@ throw new Error('[validation_getItem]: hash-parameter is required'); | ||
} | ||
const ext = (_a = resolveCompilation(hash)) === null || _a === void 0 ? void 0 : _a.resolvers.resolveExtension('@statoscope/stats-extension-stats-validation-result'); | ||
const ext = resolveExtension(hash, '@statoscope/stats-extension-stats-validation-result'); | ||
const api = ext === null || ext === void 0 ? void 0 : ext.api; | ||
return (_b = api === null || api === void 0 ? void 0 : api.getItemById(id)) !== null && _b !== void 0 ? _b : null; | ||
return (_a = api === null || api === void 0 ? void 0 : api.getItemById(id)) !== null && _a !== void 0 ? _a : null; | ||
}, | ||
@@ -247,3 +254,3 @@ validation_resolveRelatedItem(item, hash) { | ||
if (item.type === 'package-instance') { | ||
const instance = module_1.nodeModule(item.id); | ||
const instance = (0, module_1.nodeModule)(item.id); | ||
const thePackage = compilation.resolvers.resolvePackage(instance.name); | ||
@@ -280,3 +287,3 @@ const theInstance = (_a = thePackage === null || thePackage === void 0 ? void 0 : thePackage.instances.find((item) => item.path === instance.path)) !== null && _a !== void 0 ? _a : null; | ||
validation_resolveRule(name, hash) { | ||
var _a, _b; | ||
var _a; | ||
if (!hash) { | ||
@@ -288,6 +295,32 @@ throw new Error('[validation_resolveRule]: hash-parameter is required'); | ||
} | ||
const ext = (_a = resolveCompilation(hash)) === null || _a === void 0 ? void 0 : _a.resolvers.resolveExtension('@statoscope/stats-extension-stats-validation-result'); | ||
const ext = resolveExtension(hash, '@statoscope/stats-extension-stats-validation-result'); | ||
const api = ext === null || ext === void 0 ? void 0 : ext.api; | ||
return (_b = api === null || api === void 0 ? void 0 : api.getRule(name)) !== null && _b !== void 0 ? _b : null; | ||
return (_a = api === null || api === void 0 ? void 0 : api.getRule(name)) !== null && _a !== void 0 ? _a : null; | ||
}, | ||
customReports_getItems(file, hash, relatedType, relatedId) { | ||
var _a, _b, _c; | ||
if (!file) { | ||
throw new Error('[customReports_getItems]: file-parameter is required'); | ||
} | ||
const ext = (_a = normalizeResult.fileResolvers | ||
.get(file)) === null || _a === void 0 ? void 0 : _a.resolveExtension('@statoscope/stats-extension-custom-reports'); | ||
const api = ext === null || ext === void 0 ? void 0 : ext.api; | ||
return [ | ||
...((_b = api === null || api === void 0 ? void 0 : api.getReports(null, relatedType, relatedId)) !== null && _b !== void 0 ? _b : []), | ||
...((_c = api === null || api === void 0 ? void 0 : api.getReports(hash, relatedType, relatedId)) !== null && _c !== void 0 ? _c : []), | ||
]; | ||
}, | ||
customReports_getItem(id, file) { | ||
var _a, _b; | ||
if (!file) { | ||
throw new Error('[customReports_getItem]: file-parameter is required'); | ||
} | ||
if (id == null) { | ||
throw new Error('[customReports_getItem]: id-parameter is required'); | ||
} | ||
const ext = (_a = normalizeResult.fileResolvers | ||
.get(file)) === null || _a === void 0 ? void 0 : _a.resolveExtension('@statoscope/stats-extension-custom-reports'); | ||
const api = ext === null || ext === void 0 ? void 0 : ext.api; | ||
return (_b = api === null || api === void 0 ? void 0 : api.getById(id)) !== null && _b !== void 0 ? _b : null; | ||
}, | ||
}; | ||
@@ -294,0 +327,0 @@ } |
@@ -15,3 +15,3 @@ "use strict"; | ||
function handleModule(root, module, getModuleSize) { | ||
const resource = module_1.moduleResource(module); | ||
const resource = (0, module_1.moduleResource)(module); | ||
if (!resource) { | ||
@@ -32,3 +32,3 @@ return; | ||
currentPackage.name += (currentPackage.name ? '/' : '') + part.label; | ||
const instance = module_1.nodeModule(module_1.moduleResource(module)); | ||
const instance = (0, module_1.nodeModule)((0, module_1.moduleResource)(module)); | ||
part.link = { | ||
@@ -60,3 +60,3 @@ page: 'package', | ||
page: 'module', | ||
id: String(module.id || module.name), | ||
id: String(module.id || module.identifier), | ||
}; | ||
@@ -63,0 +63,0 @@ } |
@@ -102,2 +102,5 @@ import { StatsDescriptor } from '@statoscope/stats'; | ||
compilations: HandledCompilation[]; | ||
resolvers: { | ||
resolveExtension: Resolver<string, NormalizedExtension<unknown, unknown>>; | ||
}; | ||
}; | ||
@@ -110,3 +113,3 @@ export declare type CompilationResolvers = { | ||
resolveEntrypoint: Resolver<string, NormalizedEntrypointItem>; | ||
resolveExtension: Resolver<string, NormalizedExtension<unknown, unknown> | null>; | ||
resolveExtension: Resolver<string, NormalizedExtension<unknown, unknown>>; | ||
}; | ||
@@ -124,2 +127,3 @@ export declare type HandledCompilation = { | ||
compilations: HandledCompilation[]; | ||
fileResolvers: Map<string, HandledStats['resolvers']>; | ||
}; | ||
@@ -126,0 +130,0 @@ export default function normalize(rawData: RawStatsFileDescriptor | RawStatsFileDescriptor[]): NormalizeResult; |
@@ -16,2 +16,4 @@ "use strict"; | ||
const api_3 = __importDefault(require("@statoscope/stats-extension-stats-validation-result/dist/api")); | ||
const package_json_4 = __importDefault(require("@statoscope/stats-extension-custom-reports/package.json")); | ||
const api_4 = __importDefault(require("@statoscope/stats-extension-custom-reports/dist/api")); | ||
const graph_1 = __importDefault(require("@statoscope/helpers/dist/graph")); | ||
@@ -27,2 +29,3 @@ const validate_1 = __importDefault(require("./validate")); | ||
extensionContainer.register(package_json_3.default.name, package_json_3.default.version, api_3.default); | ||
extensionContainer.register(package_json_4.default.name, package_json_4.default.version, api_4.default); | ||
function getHash(compilation, parent) { | ||
@@ -33,5 +36,5 @@ if (compilation.hash) { | ||
if (parent) { | ||
return md5_1.default(parent.hash + String(compilation.name)); | ||
return (0, md5_1.default)(parent.hash + String(compilation.name)); | ||
} | ||
return md5_1.default(compilation.name || 'unknown'); | ||
return (0, md5_1.default)(compilation.name || 'unknown'); | ||
} | ||
@@ -41,2 +44,3 @@ function normalize(rawData) { | ||
const compilations = []; | ||
const fileResolvers = new Map(); | ||
if (!Array.isArray(rawData)) { | ||
@@ -49,15 +53,32 @@ rawData = [rawData]; | ||
compilations.push(...handledFile.compilations); | ||
fileResolvers.set(rawFile.name, handledFile.resolvers); | ||
} | ||
return { files, compilations }; | ||
return { files, compilations, fileResolvers }; | ||
} | ||
exports.default = normalize; | ||
function handleRawFile(rawStatsFileDescriptor) { | ||
denormalizeCompilation_1.default(rawStatsFileDescriptor.data); | ||
var _a, _b, _c; | ||
(0, denormalizeCompilation_1.default)(rawStatsFileDescriptor.data); | ||
const file = { | ||
name: rawStatsFileDescriptor.name, | ||
version: rawStatsFileDescriptor.data.version || 'unknown', | ||
validation: validate_1.default(rawStatsFileDescriptor.data), | ||
validation: (0, validate_1.default)(rawStatsFileDescriptor.data), | ||
compilations: [], | ||
__statoscope: rawStatsFileDescriptor.data.__statoscope, | ||
}; | ||
const extensions = (_c = (_b = (_a = file.__statoscope) === null || _a === void 0 ? void 0 : _a.extensions) === null || _b === void 0 ? void 0 : _b.map((ext) => { | ||
const item = extensionContainer.resolve(ext.descriptor.name); | ||
if (!item) { | ||
console.warn(`Unknown extension ${ext.descriptor.name}:`, ext); | ||
return null; | ||
} | ||
return { | ||
data: ext, | ||
api: item.apiFactory(ext), | ||
}; | ||
})) !== null && _c !== void 0 ? _c : []; | ||
const resolveExtension = (0, entity_resolver_1.default)(extensions, (ext) => ext.data.descriptor.name); | ||
const resolvers = { | ||
resolveExtension, | ||
}; | ||
const compilations = []; | ||
@@ -72,3 +93,3 @@ const stack = [ | ||
while ((cursor = stack.pop())) { | ||
const handled = handleCompilation(cursor.compilation, file, cursor.parent); | ||
const handled = handleCompilation(cursor.compilation, file, cursor.parent, resolvers); | ||
if (cursor.parent) { | ||
@@ -83,3 +104,7 @@ cursor.parent.children.push(handled.data); | ||
} | ||
return { file, compilations }; | ||
return { | ||
file, | ||
compilations, | ||
resolvers, | ||
}; | ||
} | ||
@@ -102,3 +127,3 @@ exports.handleRawFile = handleRawFile; | ||
if (globalHandled.has(module)) { | ||
return graph.getNode(module.name); | ||
return graph.getNode(module.identifier); | ||
} | ||
@@ -109,3 +134,3 @@ globalHandled.add(module); | ||
.map((r) => r.resolvedEntry); | ||
const node = (_a = graph.getNode(module.name)) !== null && _a !== void 0 ? _a : graph.makeNode(module.name, { module, entries }); | ||
const node = (_a = graph.getNode(module.identifier)) !== null && _a !== void 0 ? _a : graph.makeNode(module.identifier, { module, entries }); | ||
const handled = new WeakSet(); | ||
@@ -126,4 +151,3 @@ for (const innerModule of module.modules) { | ||
} | ||
function handleCompilation(compilation, file, parent) { | ||
var _a, _b, _c; | ||
function handleCompilation(compilation, file, parent, fileResolvers) { | ||
const normalized = { | ||
@@ -143,20 +167,8 @@ time: compilation.time, | ||
}; | ||
const extensions = (_c = (_b = (_a = file.__statoscope) === null || _a === void 0 ? void 0 : _a.extensions) === null || _b === void 0 ? void 0 : _b.map((ext) => { | ||
const item = extensionContainer.resolve(ext.descriptor.name); | ||
if (!item) { | ||
console.warn(`Unknown extension ${ext.descriptor.name}:`, ext); | ||
return null; | ||
} | ||
return { | ||
data: ext, | ||
api: item.apiFactory(ext), | ||
}; | ||
})) !== null && _c !== void 0 ? _c : []; | ||
const resolveModule = makeModuleResolver(normalized); | ||
const resolveChunk = entity_resolver_1.default(normalized.chunks, ({ id }) => id); | ||
const resolveAsset = entity_resolver_1.default(normalized.assets || [], ({ name }) => name); | ||
const resolvePackage = entity_resolver_1.default(normalized.nodeModules, ({ name }) => name); | ||
const resolveExtension = entity_resolver_1.default(extensions, (ext) => ext === null || ext === void 0 ? void 0 : ext.data.descriptor.name); | ||
const resolveChunk = (0, entity_resolver_1.default)(normalized.chunks, ({ id }) => id); | ||
const resolveAsset = (0, entity_resolver_1.default)(normalized.assets || [], ({ name }) => name); | ||
const resolvePackage = (0, entity_resolver_1.default)(normalized.nodeModules, ({ name }) => name, null, false); | ||
normalized.entrypoints = prepareEntries(compilation, resolveChunk, resolveAsset); | ||
const resolveEntrypoint = entity_resolver_1.default(normalized.entrypoints, ({ name }) => name); | ||
const resolveEntrypoint = (0, entity_resolver_1.default)(normalized.entrypoints, ({ name }) => name); | ||
const resolvers = { | ||
@@ -168,3 +180,3 @@ resolveModule, | ||
resolveEntrypoint, | ||
resolveExtension, | ||
resolveExtension: fileResolvers.resolveExtension, | ||
}; | ||
@@ -176,2 +188,3 @@ prepareModules(compilation, resolvers); | ||
const graph = buildGraph(normalized); | ||
resolvePackage.lock(); | ||
return { | ||
@@ -188,6 +201,6 @@ data: normalized, | ||
const modules = [...compilation.modules]; | ||
const resolve = entity_resolver_1.default(modules, ({ name }) => name); | ||
const resolve = (0, entity_resolver_1.default)(modules, ({ identifier }) => identifier, null, false); | ||
for (const chunk of compilation.chunks) { | ||
for (const [ix, module] of Object.entries(chunk.modules || [])) { | ||
const resolved = resolve(module.name); | ||
const resolved = resolve(module.identifier); | ||
if (!resolved) { | ||
@@ -204,16 +217,14 @@ modules.push(module); | ||
compilation.modules.length = 0; | ||
const resolveFromCompilation = entity_resolver_1.default(compilation.modules, ({ name }) => name); | ||
const resolveFromCompilation = (0, entity_resolver_1.default)(compilation.modules, ({ identifier }) => identifier, null, false); | ||
for (const module of [...modules]) { | ||
if (!resolveFromCompilation(module.name)) { | ||
if (!resolveFromCompilation(module.identifier)) { | ||
compilation.modules.push(module); | ||
} | ||
for (const innerModule of module.modules || []) { | ||
if (!resolve(innerModule.name)) { | ||
if (!resolve(innerModule.identifier)) { | ||
modules.push(innerModule); | ||
} | ||
if (!resolveFromCompilation(innerModule.name)) { | ||
compilation.modules.push(innerModule); | ||
} | ||
} | ||
} | ||
resolve.lock(); | ||
return resolve; | ||
@@ -230,5 +241,5 @@ } | ||
const { resolveChunk, resolveModule } = resolvers; | ||
module.resolvedResource = module_1.moduleResource(module); | ||
module.resolvedResource = (0, module_1.moduleResource)(module); | ||
if (module.issuerPath) { | ||
module.issuerPath.map((i) => (i.resolvedModule = resolveModule(i.name))); | ||
module.issuerPath.map((i) => (i.resolvedModule = resolveModule(i.identifier))); | ||
} | ||
@@ -244,3 +255,3 @@ if (module.chunks) { | ||
if (module.reasons) { | ||
module.reasons = module.reasons.filter((r) => r.moduleName !== module.name); | ||
module.reasons = module.reasons.filter((r) => r.moduleIdentifier !== module.identifier); | ||
for (const reason of module.reasons) { | ||
@@ -275,4 +286,4 @@ normalizeReason(reason, resolvers); | ||
var _a; | ||
reason.resolvedModule = reason.moduleName | ||
? resolveModule(reason.moduleName) | ||
reason.resolvedModule = reason.moduleIdentifier | ||
? resolveModule(reason.moduleIdentifier) | ||
: null; | ||
@@ -297,3 +308,3 @@ if (/(?:.+ )?entry$/.test((_a = reason.type) !== null && _a !== void 0 ? _a : '')) { | ||
for (const [i, module] of Object.entries(compilation.modules || [])) { | ||
const resolved = resolvers.resolveModule(module.name); | ||
const resolved = resolvers.resolveModule(module.identifier); | ||
if (resolved) { | ||
@@ -305,3 +316,3 @@ compilation.modules[+i] = resolved; | ||
for (const [i, innerModule] of Object.entries(module.modules)) { | ||
const resolved = resolvers.resolveModule(innerModule.name); | ||
const resolved = resolvers.resolveModule(innerModule.identifier); | ||
if (resolved) { | ||
@@ -319,2 +330,3 @@ module.modules[+i] = resolved; | ||
function prepareChunk(chunk, resolvers) { | ||
var _a; | ||
const { resolveModule, resolveAsset, resolveChunk } = resolvers; | ||
@@ -329,8 +341,8 @@ // @ts-ignore | ||
chunk.modules = chunk.modules | ||
.map((m) => resolveModule(m.name)) | ||
.map((m) => resolveModule(m.identifier)) | ||
.filter(Boolean); | ||
for (const [i, module] of Object.entries(chunk.modules)) { | ||
const resolved = resolvers.resolveModule(module.name); | ||
const resolved = resolvers.resolveModule(module.identifier); | ||
if (resolved) { | ||
const chunks = new Set([...resolved.chunks, ...chunk.modules[+i].chunks]); | ||
const chunks = new Set([...resolved.chunks, ...((_a = chunk.modules[+i].chunks) !== null && _a !== void 0 ? _a : [])]); | ||
resolved.chunks = [...chunks].map((chunk) => typeof chunk === 'string' || typeof chunk === 'number' | ||
@@ -344,3 +356,3 @@ ? resolveChunk(chunk) | ||
for (const [i, innerModule] of Object.entries(module.modules)) { | ||
const resolved = resolvers.resolveModule(innerModule.name); | ||
const resolved = resolvers.resolveModule(innerModule.identifier); | ||
if (resolved) { | ||
@@ -397,4 +409,4 @@ module.modules[+i] = resolved; | ||
chunk.origins | ||
.map((o) => (o.resolvedModule = o.moduleName | ||
? resolveModule(o.moduleName) | ||
.map((o) => (o.resolvedModule = o.moduleIdentifier | ||
? resolveModule(o.moduleIdentifier) | ||
: null)) | ||
@@ -444,12 +456,12 @@ .filter(Boolean); | ||
function extractPackages(compilation, { resolvePackage, resolveExtension }) { | ||
const buildReasonKey = (type, moduleName, loc) => { | ||
return [type, moduleName, loc].join(';'); | ||
const buildReasonKey = (type, moduleIdentifier, loc) => { | ||
return [type, moduleIdentifier, loc].join(';'); | ||
}; | ||
const extractModulePackages = (module) => { | ||
var _a, _b, _c; | ||
const resource = module_1.moduleResource(module); | ||
const resource = (0, module_1.moduleResource)(module); | ||
if (!resource) { | ||
return; | ||
} | ||
const modulePackage = module_1.nodeModule(resource); | ||
const modulePackage = (0, module_1.nodeModule)(resource); | ||
if (modulePackage) { | ||
@@ -482,6 +494,6 @@ let resolvedPackage = resolvePackage(modulePackage.name); | ||
var _a, _b; | ||
return buildReasonKey(reason.type, (_a = reason.data.moduleName) !== null && _a !== void 0 ? _a : 'unknown', (_b = reason.data.loc) !== null && _b !== void 0 ? _b : 'unknown'); | ||
return buildReasonKey(reason.type, (_a = reason.data.moduleIdentifier) !== null && _a !== void 0 ? _a : 'unknown', (_b = reason.data.loc) !== null && _b !== void 0 ? _b : 'unknown'); | ||
})); | ||
for (const reason of module.reasons) { | ||
const reasonPackage = module_1.nodeModule(module_1.moduleReasonResource(reason)); | ||
const reasonPackage = (0, module_1.nodeModule)((0, module_1.moduleReasonResource)(reason)); | ||
if (reasonPackage && reasonPackage.path === instance.path) { | ||
@@ -491,3 +503,3 @@ continue; | ||
const reasonType = 'module'; | ||
const reasonKey = buildReasonKey(reasonType, (_b = reason.moduleName) !== null && _b !== void 0 ? _b : 'unknown', (_c = reason.loc) !== null && _c !== void 0 ? _c : 'unknown'); | ||
const reasonKey = buildReasonKey(reasonType, (_b = reason.moduleIdentifier) !== null && _b !== void 0 ? _b : 'unknown', (_c = reason.loc) !== null && _c !== void 0 ? _c : 'unknown'); | ||
if (!instanceReasonsKeys.has(reasonKey)) { | ||
@@ -494,0 +506,0 @@ instance.reasons.push({ type: reasonType, data: reason }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function handleModule(module, modulesData) { | ||
let resolvedId = modulesData.nameToIdMap.get(module.name); | ||
var _a, _b; | ||
let resolvedId = modulesData.idToIxMap.get(module.identifier); | ||
if (!resolvedId) { | ||
resolvedId = modulesData.lastId++; | ||
modulesData.nameToIdMap.set(module.name, resolvedId); | ||
modulesData.idToModuleMap.set(resolvedId, module); | ||
modulesData.idToIxMap.set(module.identifier, resolvedId); | ||
modulesData.ixToModuleMap.set(resolvedId, module); | ||
} | ||
else { | ||
const resolvedModule = modulesData.idToModuleMap.get(resolvedId); | ||
resolvedModule.chunks = [...new Set([...resolvedModule.chunks, ...module.chunks])]; | ||
const resolvedModule = modulesData.ixToModuleMap.get(resolvedId); | ||
resolvedModule.chunks = [ | ||
...new Set([...((_a = resolvedModule.chunks) !== null && _a !== void 0 ? _a : []), ...((_b = module.chunks) !== null && _b !== void 0 ? _b : [])]), | ||
]; | ||
} | ||
@@ -24,4 +27,4 @@ return resolvedId; | ||
const modulesData = { | ||
idToModuleMap: new Map(), | ||
nameToIdMap: new Map(), | ||
ixToModuleMap: new Map(), | ||
idToIxMap: new Map(), | ||
lastId: 1, | ||
@@ -57,3 +60,3 @@ }; | ||
data: { | ||
modules: [...compilation.modules.idToModuleMap.entries()], | ||
modules: [...compilation.modules.ixToModuleMap.entries()], | ||
}, | ||
@@ -60,0 +63,0 @@ }; |
{ | ||
"name": "@statoscope/webpack-model", | ||
"version": "5.8.0", | ||
"version": "5.9.0", | ||
"description": "This package contains helpers to process webpack stats", | ||
@@ -22,9 +22,10 @@ "main": "./dist/index.js", | ||
"@statoscope/extensions": "5.7.1", | ||
"@statoscope/helpers": "5.7.1", | ||
"@statoscope/helpers": "5.9.0", | ||
"@statoscope/stats": "5.7.0", | ||
"@statoscope/stats-extension-compressed": "5.7.1", | ||
"@statoscope/stats-extension-package-info": "5.7.1", | ||
"@statoscope/stats-extension-stats-validation-result": "5.7.1", | ||
"@statoscope/types": "5.7.1", | ||
"ajv": "^8.5.0", | ||
"@statoscope/stats-extension-compressed": "5.9.0", | ||
"@statoscope/stats-extension-custom-reports": "5.9.0", | ||
"@statoscope/stats-extension-package-info": "5.9.0", | ||
"@statoscope/stats-extension-stats-validation-result": "5.9.0", | ||
"@statoscope/types": "5.9.0", | ||
"ajv": "^8.6.3", | ||
"md5": "^2.3.0" | ||
@@ -36,3 +37,3 @@ }, | ||
}, | ||
"gitHead": "d7b10e373e8352a955271fd8923778b68f23dfca" | ||
"gitHead": "f8e8a9cd721828a4bc53a2f808441d81e5fdbf84" | ||
} |
@@ -15,6 +15,7 @@ import { StatsDescriptor } from '@statoscope/stats'; | ||
id: ModuleID; | ||
identifier: string; | ||
name: string; | ||
size: number; | ||
issuerPath?: IssuerPathItem[] | null; | ||
chunks: Array<Chunk | ChunkID>; | ||
chunks?: Array<Chunk | ChunkID>; | ||
reasons?: Reason[]; | ||
@@ -29,2 +30,3 @@ modules?: InnerModule[]; | ||
type?: string; | ||
moduleIdentifier: string | null; | ||
moduleName: string | null; | ||
@@ -80,13 +82,16 @@ loc?: string; | ||
children?: Compilation[]; | ||
__statoscope?: { | ||
descriptor?: StatsDescriptor; | ||
extensions?: Extension<unknown>[]; | ||
normalization?: NormalizationData; | ||
}; | ||
__statoscope?: StatoscopeMeta; | ||
}; | ||
} | ||
export type StatoscopeMeta = { | ||
descriptor?: StatsDescriptor; | ||
extensions?: Extension<unknown>[]; | ||
normalization?: NormalizationData; | ||
context?: string; | ||
}; | ||
export type ModuleData = { | ||
nameToIdMap: Map<string, number>; | ||
idToModuleMap: Map<number, Webpack.Module>; | ||
idToIxMap: Map<string, number>; | ||
ixToModuleMap: Map<number, Webpack.Module>; | ||
lastId: number; | ||
@@ -93,0 +98,0 @@ }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
72189
1748
10
+ Added@statoscope/helpers@5.9.0(transitive)
+ Added@statoscope/stats-extension-compressed@5.9.0(transitive)
+ Added@statoscope/stats-extension-custom-reports@5.9.0(transitive)
+ Added@statoscope/stats-extension-package-info@5.9.0(transitive)
+ Added@statoscope/stats-extension-stats-validation-result@5.9.0(transitive)
+ Added@statoscope/types@5.9.0(transitive)
- Removed@statoscope/helpers@5.7.1(transitive)
- Removed@statoscope/stats-extension-compressed@5.7.1(transitive)
- Removed@statoscope/stats-extension-package-info@5.7.1(transitive)
- Removed@statoscope/stats-extension-stats-validation-result@5.7.1(transitive)
- Removed@statoscope/types@5.7.1(transitive)
Updated@statoscope/helpers@5.9.0
Updated@statoscope/stats-extension-stats-validation-result@5.9.0
Updated@statoscope/types@5.9.0
Updatedajv@^8.6.3