@statoscope/webpack-model
Advanced tools
Comparing version 5.14.1 to 5.17.0
import { NormalizationData, Webpack } from '../webpack'; | ||
import Compilation = Webpack.Compilation; | ||
import Module = Webpack.Module; | ||
export declare type ModulesMap = Map<number, Module>; | ||
import RawModule = Webpack.RawModule; | ||
export declare type ModulesMap = Map<number, RawModule>; | ||
export declare type CompilationData = { | ||
@@ -6,0 +6,0 @@ id: string; |
import { Options } from '@statoscope/helpers/dist/jora'; | ||
import { NormalizedCompilation, NormalizedFile, RawStatsFileDescriptor } from '../types'; | ||
import joraHelpers from './jora-helpers'; | ||
import normalize, { NormalizedCompilation, NormalizedFile, RawStatsFileDescriptor } from './normalize'; | ||
import normalize from './handleFile'; | ||
export { default as validate } from './validate'; | ||
@@ -5,0 +6,0 @@ export * as module from './module'; |
@@ -29,4 +29,4 @@ "use strict"; | ||
exports.joraHelpers = jora_helpers_1.default; | ||
const normalize_1 = __importDefault(require("./normalize")); | ||
exports.normalize = normalize_1.default; | ||
const handleFile_1 = __importDefault(require("./handleFile")); | ||
exports.normalize = handleFile_1.default; | ||
var validate_1 = require("./validate"); | ||
@@ -36,3 +36,3 @@ Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return __importDefault(validate_1).default; } }); | ||
function prepareWithJora(stats, options = {}) { | ||
const normalizeResult = (0, normalize_1.default)(stats); | ||
const normalizeResult = (0, handleFile_1.default)(stats); | ||
const { files, compilations } = normalizeResult; | ||
@@ -39,0 +39,0 @@ const prepared = (0, jora_1.prepareWithJora)(files, { |
@@ -9,4 +9,4 @@ import type { Size } from '@statoscope/stats-extension-compressed/dist/generator'; | ||
import { Webpack } from '../webpack'; | ||
import { ModuleGraphNodeData, NodeModuleInstance, NormalizedAsset, NormalizedChunk, NormalizedCompilation, NormalizedEntrypointItem, NormalizedExtension, NormalizedModule, NormalizedPackage, NormalizeResult, NormalizedFile } from '../types'; | ||
import { moduleNameResource, moduleReasonResource, moduleResource, nodeModule } from './module'; | ||
import { ModuleGraphNodeData, NodeModuleInstance, NormalizedAsset, NormalizedChunk, NormalizedCompilation, NormalizedEntrypointItem, NormalizedExtension, NormalizedFile, NormalizedModule, NormalizedPackage, NormalizeResult } from './normalize'; | ||
import { Node as FoamTreeNode } from './modules-to-foam-tree'; | ||
@@ -43,2 +43,3 @@ import ChunkID = Webpack.ChunkID; | ||
chunkName(chunk: NormalizedChunk): string; | ||
assetChunkName(asset: NormalizedAsset): string | null; | ||
getTotalFilesSize: (asset: NormalizedAsset, hash?: string | undefined, compressed?: boolean | undefined) => number; | ||
@@ -69,8 +70,8 @@ resolveChunk(id: ChunkID, compilationHash: string): NormalizedChunk | null; | ||
modulesToFoamTree(modules: NormalizedModule[], hash?: string | undefined, compressed?: boolean | undefined): FoamTreeNode; | ||
validation_getItems(hash?: string | undefined, relatedType?: "module" | "entry" | "package" | "package-instance" | "resource" | "compilation" | "chunk" | null | undefined, relatedId?: string | number | undefined): Item[]; | ||
validation_getItems(hash?: string | undefined, relatedType?: "module" | "package" | "package-instance" | "resource" | "entry" | "compilation" | "chunk" | null | undefined, relatedId?: string | number | undefined): Item[]; | ||
validation_getItem(id?: number | undefined, hash?: string | undefined): Item | null; | ||
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_getItems(file: string, hash?: string | null | undefined, relatedType?: "module" | "package" | "package-instance" | "resource" | "entry" | "compilation" | "chunk" | null | undefined, relatedId?: string | number | undefined): Report<unknown, unknown>[]; | ||
customReports_getItem(id: string, file: string): Report<unknown, unknown> | null; | ||
}; |
@@ -16,3 +16,3 @@ "use strict"; | ||
var _a, _b; | ||
return (_b = (_a = normalizeResult.fileResolvers.get(fileName)) === null || _a === void 0 ? void 0 : _a.resolveExtension(id)) !== null && _b !== void 0 ? _b : null; | ||
return (_b = (_a = normalizeResult.resolvers.get(fileName)) === null || _a === void 0 ? void 0 : _a.resolveExtension(id)) !== null && _b !== void 0 ? _b : null; | ||
}; | ||
@@ -33,4 +33,11 @@ const resolveExtensionByCompilation = (hash, id) => { | ||
chunkName(chunk) { | ||
return `${chunk.names[0] ? chunk.names.join(', ') : chunk.name || chunk.id}${chunk.reason ? ' [' + chunk.reason + ']' : ''}`; | ||
var _a, _b; | ||
const chunkNames = [...chunk.names, ...((_a = chunk.idHints) !== null && _a !== void 0 ? _a : [])]; | ||
return `${(_b = chunkNames[0]) !== null && _b !== void 0 ? _b : (chunk.name || chunk.id)}${chunk.reason ? ' [' + chunk.reason + ']' : ''}`; | ||
}, | ||
assetChunkName(asset) { | ||
var _a, _b, _c; | ||
const chunkNames = [...((_a = asset.chunkNames) !== null && _a !== void 0 ? _a : []), ...((_b = asset.chunkIdHints) !== null && _b !== void 0 ? _b : [])]; | ||
return (_c = chunkNames[0]) !== null && _c !== void 0 ? _c : null; | ||
}, | ||
getTotalFilesSize: (asset, hash, compressed) => { | ||
@@ -296,3 +303,3 @@ const files = asset.files.length | ||
} | ||
const ext = (_a = normalizeResult.fileResolvers | ||
const ext = (_a = normalizeResult.resolvers | ||
.get(file)) === null || _a === void 0 ? void 0 : _a.resolveExtension('@statoscope/stats-extension-custom-reports'); | ||
@@ -313,3 +320,3 @@ const api = ext === null || ext === void 0 ? void 0 : ext.api; | ||
} | ||
const ext = (_a = normalizeResult.fileResolvers | ||
const ext = (_a = normalizeResult.resolvers | ||
.get(file)) === null || _a === void 0 ? void 0 : _a.resolveExtension('@statoscope/stats-extension-custom-reports'); | ||
@@ -316,0 +323,0 @@ const api = ext === null || ext === void 0 ? void 0 : ext.api; |
@@ -1,9 +0,11 @@ | ||
import { NormalizedModule, NormalizedReason } from './normalize'; | ||
import { Webpack } from '../webpack'; | ||
import { NormalizedModule, NormalizedReason } from '../types'; | ||
import RawModule = Webpack.RawModule; | ||
import RawReason = Webpack.RawReason; | ||
export declare const extractFileRx: RegExp; | ||
export declare const concatenatedIdRx: RegExp; | ||
export declare const contextIdRx: RegExp; | ||
export declare function matchRxValue(rx: RegExp, string: string): string | null; | ||
export declare function moduleNameResource(name: string | null): string | null; | ||
export declare function moduleResource(module: NormalizedModule | null): string | null; | ||
export declare function moduleReasonResource(reason: NormalizedReason | null): string | null; | ||
export declare function moduleResource(module: RawModule | NormalizedModule | null): string | null; | ||
export declare function moduleReasonResource(reason: RawReason | NormalizedReason | null): string | null; | ||
export declare type NodeModule = { | ||
@@ -10,0 +12,0 @@ path: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.nodeModule = exports.moduleReasonResource = exports.moduleResource = exports.moduleNameResource = exports.matchRxValue = exports.contextIdRx = exports.concatenatedIdRx = exports.extractFileRx = void 0; | ||
exports.extractFileRx = /.*(?:^|!|\s+)(\.?\.?[\\/].+)/; | ||
exports.nodeModule = exports.moduleReasonResource = exports.moduleResource = exports.moduleNameResource = exports.matchRxValue = exports.concatenatedIdRx = exports.extractFileRx = void 0; | ||
exports.extractFileRx = /!?([^!]+)$/; | ||
exports.concatenatedIdRx = /(.+) \+ \d+ modules$/; | ||
exports.contextIdRx = /(.+) (?:sync|eager|weak|async-weak|lazy|lazy-once)(?:\s|$)/; | ||
function matchRxValue(rx, string) { | ||
@@ -18,5 +17,3 @@ const [, match] = string.match(rx) || []; | ||
} | ||
const nameResource = matchRxValue(exports.concatenatedIdRx, normalized) || | ||
matchRxValue(exports.contextIdRx, normalized) || | ||
normalized; | ||
const nameResource = matchRxValue(exports.concatenatedIdRx, normalized) || normalized; | ||
if (nameResource.startsWith('./') || nameResource.startsWith('.\\')) { | ||
@@ -23,0 +20,0 @@ return nameResource.slice(2); |
import { Compressor, Size } from '@statoscope/stats-extension-compressed/dist/generator'; | ||
import { NormalizedModule } from './normalize'; | ||
import { NormalizedModule } from '../types'; | ||
export declare type NodeLink = { | ||
@@ -4,0 +4,0 @@ page: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const collector_1 = require("./collector"); | ||
function handleModule(module, modulesData) { | ||
@@ -16,6 +17,5 @@ var _a, _b, _c, _d; | ||
]; | ||
resolvedModule.reasons = [ | ||
...((_c = resolvedModule.reasons) !== null && _c !== void 0 ? _c : []), | ||
...((_d = module.reasons) !== null && _d !== void 0 ? _d : []), | ||
].reduce((all, current) => { | ||
const toReasons = (0, collector_1.collectRawReasonsFromArray)((_c = resolvedModule.reasons) !== null && _c !== void 0 ? _c : []); | ||
const fromReasons = (0, collector_1.collectRawReasonsFromArray)((_d = module.reasons) !== null && _d !== void 0 ? _d : []); | ||
resolvedModule.reasons = [...toReasons.values(), ...fromReasons.values()].reduce((all, current) => { | ||
if (!all.find((r) => r.moduleIdentifier === current.moduleIdentifier && | ||
@@ -32,3 +32,6 @@ r.type === current.type && | ||
function handleChunk(chunk, modulesData) { | ||
for (const [id, module] of (chunk.modules || []).entries()) { | ||
var _a; | ||
const modules = (0, collector_1.collectRawModulesFromArray)((_a = chunk.modules) !== null && _a !== void 0 ? _a : []); | ||
chunk.modules = [...modules.values()]; | ||
for (const [id, module] of chunk.modules.entries()) { | ||
// @ts-ignore | ||
@@ -39,2 +42,3 @@ chunk.modules[id] = handleModule(module, modulesData); | ||
function handleCompilation(compilation, compilationMap) { | ||
var _a; | ||
const modulesData = { | ||
@@ -48,3 +52,5 @@ ixToModuleMap: new Map(), | ||
}); | ||
for (const [id, module] of (compilation.modules || []).entries()) { | ||
const modules = (0, collector_1.collectRawModulesFromArray)((_a = compilation.modules) !== null && _a !== void 0 ? _a : []); | ||
compilation.modules = [...modules.values()]; | ||
for (const [id, module] of compilation.modules.entries()) { | ||
// @ts-ignore | ||
@@ -51,0 +57,0 @@ compilation.modules[id] = handleModule(module, modulesData); |
{ | ||
"name": "@statoscope/webpack-model", | ||
"version": "5.14.1", | ||
"version": "5.17.0", | ||
"description": "This package contains helpers to process webpack stats", | ||
@@ -37,3 +37,3 @@ "main": "./dist/index.js", | ||
}, | ||
"gitHead": "cd4f79745932c1a951517cc117f78afb3717f1a3" | ||
"gitHead": "c9d0c148c1e38a87696d79485f37e598110db80c" | ||
} |
@@ -13,3 +13,7 @@ import { StatsDescriptor } from '@statoscope/stats'; | ||
type Module = { | ||
type ModuleGroup = { type: 'group name here'; children: Module[] }; | ||
type ReasonGroup = { type: 'group name here'; children: Reason[] }; | ||
type RawModule = { | ||
type: string; | ||
id: ModuleID; | ||
@@ -20,11 +24,11 @@ identifier: string; | ||
issuerPath?: IssuerPathItem[] | null; | ||
chunks?: Array<Chunk | ChunkID>; | ||
chunks?: Array<ChunkID | Chunk>; | ||
reasons?: Reason[]; | ||
modules?: InnerModule[]; | ||
modules?: Module[]; | ||
optimizationBailout?: string[]; | ||
}; | ||
type Module = ModuleGroup | RawModule; | ||
type Reason = ReasonGroup | RawReason; | ||
type InnerModule = Omit<Module, 'id' | 'modules'> & { id: null }; | ||
type Reason = { | ||
type RawReason = { | ||
type?: string; | ||
@@ -57,2 +61,3 @@ moduleIdentifier: string | null; | ||
files: Array<string | File>; | ||
idHints?: string[]; | ||
}; | ||
@@ -70,2 +75,4 @@ | ||
files?: File[]; | ||
chunkNames?: string[]; | ||
chunkIdHints?: string[]; | ||
}; | ||
@@ -97,3 +104,3 @@ | ||
idToIxMap: Map<string, number>; | ||
ixToModuleMap: Map<number, Webpack.Module>; | ||
ixToModuleMap: Map<number, Webpack.RawModule>; | ||
lastId: number; | ||
@@ -114,3 +121,3 @@ }; | ||
data: { | ||
modules: Array<[number, Webpack.Module]>; | ||
modules: Array<[number, Webpack.RawModule]>; | ||
}; | ||
@@ -117,0 +124,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
81748
28
1951