@statoscope/webpack-model
Advanced tools
Comparing version 5.6.2 to 5.7.0-alpha.0
@@ -0,1 +1,2 @@ | ||
import { Options } from '@statoscope/helpers/dist/jora'; | ||
import joraHelpers from './jora-helpers'; | ||
@@ -6,5 +7,2 @@ import normalize, { NormalizedCompilation, NormalizedFile, RawStatsFileDescriptor } from './normalize'; | ||
export { joraHelpers, normalize }; | ||
export declare type Options = { | ||
helpers?: Record<string, unknown>; | ||
}; | ||
export declare type Prepared = { | ||
@@ -11,0 +9,0 @@ files: NormalizedFile[]; |
@@ -26,4 +26,3 @@ "use strict"; | ||
exports.prepareWithJora = exports.normalize = exports.joraHelpers = exports.module = exports.validate = void 0; | ||
// @ts-ignore | ||
const jora_1 = __importDefault(require("jora")); | ||
const jora_1 = require("@statoscope/helpers/dist/jora"); | ||
const jora_helpers_1 = __importDefault(require("./jora-helpers")); | ||
@@ -38,11 +37,9 @@ exports.joraHelpers = jora_helpers_1.default; | ||
const { files, compilations } = normalize_1.default(stats); | ||
const j = jora_1.default.setup({ | ||
...options.helpers, | ||
...jora_helpers_1.default(compilations), | ||
const prepared = jora_1.prepareWithJora(files, { | ||
helpers: { ...jora_helpers_1.default(compilations), ...options.helpers }, | ||
}); | ||
const rootContext = {}; | ||
return { | ||
files, | ||
compilations: compilations.map((c) => c.data), | ||
query: (query, data, context = rootContext) => j(query)(data || files, context), | ||
query: (query, data, context) => prepared.query(query, data, context), | ||
}; | ||
@@ -49,0 +46,0 @@ } |
import type { Size } from '@statoscope/stats-extension-compressed/dist/generator'; | ||
import type { Instance } from '@statoscope/stats-extension-package-info/dist/generator'; | ||
import Graph, { PathSolution } from '@statoscope/helpers/dist/graph'; | ||
import type { Item } from '@statoscope/stats-extension-stats-validation-result/dist/generator'; | ||
import { RelatedItem } from '@statoscope/types/types/validation/test-entry'; | ||
import { RuleDescriptor } from '@statoscope/types/types/validation/api'; | ||
import { Webpack } from '../webpack'; | ||
import { moduleNameResource, moduleReasonResource, moduleResource, nodeModule } from './module'; | ||
import { HandledCompilation, ModuleGraphNodeData, NormalizedAsset, NormalizedChunk, NormalizedCompilation, NormalizedEntrypointItem, NormalizedFile, NormalizedModule, NormalizedPackage } from './normalize'; | ||
import { HandledCompilation, ModuleGraphNodeData, NodeModuleInstance, NormalizedAsset, NormalizedChunk, NormalizedCompilation, NormalizedEntrypointItem, NormalizedFile, NormalizedModule, NormalizedPackage } from './normalize'; | ||
import { Node as FoamTreeNode } from './modules-to-foam-tree'; | ||
@@ -13,6 +16,25 @@ import ChunkID = Webpack.ChunkID; | ||
}; | ||
export declare type ResolvedRelatedItem = { | ||
type: 'module'; | ||
item: NormalizedModule | null; | ||
} | { | ||
type: 'chunk'; | ||
item: NormalizedChunk | null; | ||
} | { | ||
type: 'resource'; | ||
item: NormalizedAsset | null; | ||
} | { | ||
type: 'entry'; | ||
item: NormalizedEntrypointItem | null; | ||
} | { | ||
type: 'package'; | ||
item: NormalizedPackage | null; | ||
} | { | ||
type: 'package-instance'; | ||
item: NodeModuleInstance | null; | ||
}; | ||
export default function (compilations: HandledCompilation[]): { | ||
moduleSize(module: NormalizedModule): number; | ||
chunkName(chunk: NormalizedChunk): string; | ||
getTotalFilesSize: (asset: NormalizedAsset, compressed?: boolean | undefined, hash?: string | undefined) => number; | ||
getTotalFilesSize: (asset: NormalizedAsset, hash?: string | undefined, compressed?: boolean | undefined) => number; | ||
resolveChunk(id: ChunkID, compilationHash: string): NormalizedChunk | null; | ||
@@ -22,7 +44,11 @@ resolveAsset(id: string, compilationHash: string): NormalizedAsset | null; | ||
resolvePackage(id: string, compilationHash: string): NormalizedPackage | null; | ||
resolveEntrypoint(id: string, compilationHash: string): NormalizedEntrypointItem | null; | ||
resolveFile(id: string): NormalizedFile | null; | ||
resolveInputFile(): NormalizedFile | null; | ||
resolveReferenceFile(): NormalizedFile | null; | ||
resolveStat(id: string): ResolvedStats | null; | ||
resolveCompilation(id: string): NormalizedCompilation | null; | ||
resolveExtension(id: string, hash: string): unknown; | ||
getModuleSize(module: NormalizedModule, compressed?: boolean | undefined, hash?: string | undefined): Size; | ||
getAssetSize(asset: NormalizedAsset, compressed?: boolean | undefined, hash?: string | undefined): Size; | ||
getModuleSize(module: NormalizedModule, hash?: string | undefined, compressed?: boolean | undefined): Size; | ||
getAssetSize(asset: NormalizedAsset, hash?: string | undefined, compressed?: boolean | undefined): Size; | ||
getPackageInstanceInfo(packageName: string, instancePath: string, hash: string): Instance | null; | ||
@@ -37,3 +63,7 @@ moduleResource: typeof moduleResource; | ||
moduleGraph_getPaths(from?: NormalizedModule | undefined, graph?: Graph<ModuleGraphNodeData> | undefined, to?: NormalizedModule | undefined, max?: number): PathSolution<ModuleGraphNodeData> | null; | ||
modulesToFoamTree(modules: NormalizedModule[], compressed?: boolean | undefined, hash?: string | undefined): FoamTreeNode; | ||
modulesToFoamTree(modules: NormalizedModule[], hash?: string | undefined, compressed?: boolean | undefined): FoamTreeNode; | ||
validation_getItems(hash?: string | undefined, relatedType?: "module" | "package" | "package-instance" | "resource" | "entry" | "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_resolveRule(name?: string | undefined, hash?: string | undefined): RuleDescriptor | null; | ||
}; |
@@ -12,2 +12,3 @@ "use strict"; | ||
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); | ||
return { | ||
@@ -21,13 +22,16 @@ moduleSize(module) { | ||
}, | ||
getTotalFilesSize: (asset, compressed, hash) => { | ||
getTotalFilesSize: (asset, hash, compressed) => { | ||
var _a; | ||
const files = asset.files.length | ||
? asset.files | ||
: [{ name: asset.name, size: asset.size }]; | ||
if (!compressed) { | ||
return asset.files.reduce((sum, file) => sum + file.size, 0); | ||
return files.reduce((sum, file) => sum + file.size, 0); | ||
} | ||
if (!hash) { | ||
throw new Error('[getTotalFilesSize-helper]: hash-parameter is required'); | ||
throw new Error('[getTotalFilesSize]: hash-parameter is required'); | ||
} | ||
const ext = (_a = resolveCompilation(hash)) === null || _a === void 0 ? void 0 : _a.resolvers.resolveExtension('@statoscope/stats-extension-compressed'); | ||
const resolverSize = ext === null || ext === void 0 ? void 0 : ext.api; | ||
return asset.files | ||
return files | ||
.map((f) => { var _a; return (_a = resolverSize === null || resolverSize === void 0 ? void 0 : resolverSize(hash, f.name)) !== null && _a !== void 0 ? _a : null; }) | ||
@@ -52,2 +56,15 @@ .reduce((sum, file) => { var _a; return sum + ((_a = file === null || file === void 0 ? void 0 : file.size) !== null && _a !== void 0 ? _a : 0); }, 0); | ||
}, | ||
resolveEntrypoint(id, compilationHash) { | ||
var _a; | ||
return ((_a = resolveCompilation(compilationHash)) === null || _a === void 0 ? void 0 : _a.resolvers.resolveEntrypoint(id)) || null; | ||
}, | ||
resolveFile(id) { | ||
return resolveFile(id); | ||
}, | ||
resolveInputFile() { | ||
return this.resolveFile('input.json'); | ||
}, | ||
resolveReferenceFile() { | ||
return this.resolveFile('reference.json'); | ||
}, | ||
resolveStat(id) { | ||
@@ -65,3 +82,3 @@ const resolved = resolveCompilation(id); | ||
}, | ||
getModuleSize(module, compressed, hash) { | ||
getModuleSize(module, hash, compressed) { | ||
var _a, _b; | ||
@@ -72,3 +89,3 @@ if (!compressed) { | ||
if (!hash) { | ||
throw new Error('[getModuleSize-helper]: hash-parameter is required'); | ||
throw new Error('[getModuleSize]: hash-parameter is required'); | ||
} | ||
@@ -81,3 +98,3 @@ const ext = (_a = resolveCompilation(hash)) === null || _a === void 0 ? void 0 : _a.resolvers.resolveExtension('@statoscope/stats-extension-compressed'); | ||
}, | ||
getAssetSize(asset, compressed, hash) { | ||
getAssetSize(asset, hash, compressed) { | ||
var _a, _b; | ||
@@ -88,3 +105,3 @@ if (!compressed) { | ||
if (!hash) { | ||
throw new Error('[getAssetSize-helper]: hash-parameter is required'); | ||
throw new Error('[getAssetSize]: hash-parameter is required'); | ||
} | ||
@@ -100,3 +117,3 @@ const ext = (_a = resolveCompilation(hash)) === null || _a === void 0 ? void 0 : _a.resolvers.resolveExtension('@statoscope/stats-extension-compressed'); | ||
if (!hash) { | ||
throw new Error('[getPackageInstanceInfo-helper]: hash-parameter is required'); | ||
throw new Error('[getPackageInstanceInfo]: hash-parameter is required'); | ||
} | ||
@@ -172,9 +189,9 @@ const ext = (_a = resolveCompilation(hash)) === null || _a === void 0 ? void 0 : _a.resolvers.resolveExtension('@statoscope/stats-extension-package-info'); | ||
}, | ||
modulesToFoamTree(modules, compressed, hash) { | ||
modulesToFoamTree(modules, hash, compressed) { | ||
if (compressed && !hash) { | ||
throw new Error('[modulesToFoamTree-helper]: hash-parameter is required'); | ||
throw new Error('[modulesToFoamTree]: hash-parameter is required'); | ||
} | ||
return modules_to_foam_tree_1.default(modules, (module) => { | ||
if (compressed && hash) { | ||
return this.getModuleSize(module, compressed, hash); | ||
return this.getModuleSize(module, hash, compressed); | ||
} | ||
@@ -184,2 +201,79 @@ return { size: module.size }; | ||
}, | ||
validation_getItems(hash, relatedType, relatedId) { | ||
var _a, _b, _c; | ||
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 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 : []), | ||
]; | ||
}, | ||
validation_getItem(id, hash) { | ||
var _a, _b; | ||
if (!hash) { | ||
throw new Error('[validation_getItem]: hash-parameter is required'); | ||
} | ||
if (id == null) { | ||
throw new Error('[validation_getItem]: id-parameter is required'); | ||
} | ||
const ext = (_a = resolveCompilation(hash)) === null || _a === void 0 ? void 0 : _a.resolvers.resolveExtension('@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; | ||
}, | ||
validation_resolveRelatedItem(item, hash) { | ||
var _a; | ||
if (!item) { | ||
throw new Error('[validation_resolveRelatedItem]: item-parameter is required'); | ||
} | ||
if (!hash) { | ||
throw new Error('[validation_resolveRelatedItem]: hash-parameter is required'); | ||
} | ||
const compilation = resolveCompilation(hash); | ||
if (!compilation) { | ||
throw new Error("[validation_resolveRelatedItem]: can't resolve compilation"); | ||
} | ||
if (item.type === 'package') { | ||
return { type: item.type, item: compilation.resolvers.resolvePackage(item.id) }; | ||
} | ||
if (item.type === 'package-instance') { | ||
const instance = module_1.nodeModule(item.id); | ||
const thePackage = compilation.resolvers.resolvePackage(instance.name); | ||
const theInstance = (_a = thePackage === null || thePackage === void 0 ? void 0 : thePackage.instances.find((item) => item.path === instance.path)) !== null && _a !== void 0 ? _a : null; | ||
return { type: item.type, item: theInstance }; | ||
} | ||
if (item.type === 'module') { | ||
return { type: item.type, item: compilation.resolvers.resolveModule(item.id) }; | ||
} | ||
if (item.type === 'entry') { | ||
return { | ||
type: item.type, | ||
item: compilation.resolvers.resolveEntrypoint(item.id), | ||
}; | ||
} | ||
if (item.type === 'chunk') { | ||
return { | ||
type: item.type, | ||
item: compilation.resolvers.resolveChunk(item.id), | ||
}; | ||
} | ||
return { | ||
type: item.type, | ||
item: compilation.resolvers.resolveAsset(item.id), | ||
}; | ||
}, | ||
validation_resolveRule(name, hash) { | ||
var _a, _b; | ||
if (!hash) { | ||
throw new Error('[validation_resolveRule]: hash-parameter is required'); | ||
} | ||
if (name == null) { | ||
throw new Error('[validation_resolveRule]: name-parameter is required'); | ||
} | ||
const ext = (_a = resolveCompilation(hash)) === null || _a === void 0 ? void 0 : _a.resolvers.resolveExtension('@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; | ||
}, | ||
}; | ||
@@ -186,0 +280,0 @@ } |
@@ -14,2 +14,4 @@ "use strict"; | ||
const package_json_2 = __importDefault(require("@statoscope/stats-extension-package-info/package.json")); | ||
const package_json_3 = __importDefault(require("@statoscope/stats-extension-stats-validation-result/package.json")); | ||
const api_3 = __importDefault(require("@statoscope/stats-extension-stats-validation-result/dist/api")); | ||
const graph_1 = __importDefault(require("@statoscope/helpers/dist/graph")); | ||
@@ -23,2 +25,3 @@ const validate_1 = __importDefault(require("./validate")); | ||
extensionContainer.register(package_json_2.default.name, package_json_2.default.version, api_2.default); | ||
extensionContainer.register(package_json_3.default.name, package_json_3.default.version, api_3.default); | ||
function getHash(compilation, parent) { | ||
@@ -265,6 +268,14 @@ if (compilation.hash) { | ||
function prepareModules(compilation, resolvers) { | ||
for (const module of compilation.modules || []) { | ||
for (const [i, module] of Object.entries(compilation.modules || [])) { | ||
const resolved = resolvers.resolveModule(module.name); | ||
if (resolved) { | ||
compilation.modules[+i] = resolved; | ||
} | ||
prepareModule(module, resolvers); | ||
if (module.modules) { | ||
for (const innerModule of module.modules) { | ||
for (const [i, innerModule] of Object.entries(module.modules)) { | ||
const resolved = resolvers.resolveModule(innerModule.name); | ||
if (resolved) { | ||
module.modules[+i] = resolved; | ||
} | ||
prepareModule(innerModule, resolvers); | ||
@@ -290,6 +301,14 @@ } | ||
.filter(Boolean); | ||
for (const module of chunk.modules) { | ||
for (const [i, module] of Object.entries(chunk.modules)) { | ||
const resolved = resolvers.resolveModule(module.name); | ||
if (resolved) { | ||
chunk.modules[+i] = resolved; | ||
} | ||
prepareModule(module, resolvers); | ||
if (module.modules) { | ||
for (const innerModule of module.modules) { | ||
for (const [i, innerModule] of Object.entries(module.modules)) { | ||
const resolved = resolvers.resolveModule(innerModule.name); | ||
if (resolved) { | ||
module.modules[+i] = resolved; | ||
} | ||
prepareModule(innerModule, resolvers); | ||
@@ -442,13 +461,20 @@ } | ||
}; | ||
function handleModule(module) { | ||
var _a; | ||
extractModulePackages(module); | ||
if (module.modules) { | ||
for (const innerModule of module.modules) { | ||
handleModule(innerModule); | ||
} | ||
} | ||
else { | ||
(_a = module.modules) !== null && _a !== void 0 ? _a : (module.modules = []); | ||
} | ||
} | ||
for (const module of compilation.modules) { | ||
handleModule(module); | ||
} | ||
for (const chunk of compilation.chunks) { | ||
for (const module of chunk.modules) { | ||
extractModulePackages(module); | ||
if (module.modules) { | ||
for (const innerModule of module.modules) { | ||
extractModulePackages(innerModule); | ||
} | ||
} | ||
else { | ||
module.modules = []; | ||
} | ||
handleModule(module); | ||
} | ||
@@ -455,0 +481,0 @@ } |
{ | ||
"name": "@statoscope/webpack-model", | ||
"version": "5.6.2", | ||
"version": "5.7.0-alpha.0", | ||
"description": "This package contains helpers to process webpack stats", | ||
@@ -25,9 +25,10 @@ "main": "./dist/index.js", | ||
"dependencies": { | ||
"@statoscope/extensions": "^5.5.1", | ||
"@statoscope/helpers": "^5.6.1", | ||
"@statoscope/stats": "^5.3.0", | ||
"@statoscope/stats-extension-compressed": "^5.6.1", | ||
"@statoscope/stats-extension-package-info": "^5.6.1", | ||
"@statoscope/extensions": "5.7.0-alpha.0", | ||
"@statoscope/helpers": "5.7.0-alpha.0", | ||
"@statoscope/stats": "5.7.0-alpha.0", | ||
"@statoscope/stats-extension-compressed": "5.7.0-alpha.0", | ||
"@statoscope/stats-extension-package-info": "5.7.0-alpha.0", | ||
"@statoscope/stats-extension-stats-validation-result": "5.7.0-alpha.0", | ||
"@statoscope/types": "5.7.0-alpha.0", | ||
"ajv": "^8.5.0", | ||
"jora": "^1.0.0-beta.5", | ||
"md5": "^2.3.0" | ||
@@ -39,3 +40,3 @@ }, | ||
}, | ||
"gitHead": "d0ac649118f394b2dd8a22f2fb980a1e0483fc93" | ||
"gitHead": "d87b4b850ad9ff1f94110fb017bb915a77ed4c62" | ||
} |
@@ -21,2 +21,3 @@ import { StatsDescriptor } from '@statoscope/stats'; | ||
modules?: InnerModule[]; | ||
optimizationBailout?: string[]; | ||
}; | ||
@@ -23,0 +24,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
94884
1495
9
1
+ Added@statoscope/stats-extension-stats-validation-result@5.7.0-alpha.0
+ Added@statoscope/extensions@5.7.0-alpha.0(transitive)
+ Added@statoscope/helpers@5.7.0-alpha.0(transitive)
+ Added@statoscope/stats@5.7.0-alpha.0(transitive)
+ Added@statoscope/stats-extension-compressed@5.7.0-alpha.0(transitive)
+ Added@statoscope/stats-extension-package-info@5.7.0-alpha.0(transitive)
+ Added@statoscope/stats-extension-stats-validation-result@5.7.0-alpha.0(transitive)
+ Added@statoscope/types@5.7.0-alpha.0(transitive)
- Removedjora@^1.0.0-beta.5
- Removed@statoscope/extensions@5.28.1(transitive)
- Removed@statoscope/helpers@5.28.1(transitive)
- Removed@statoscope/stats@5.28.1(transitive)
- Removed@statoscope/stats-extension-compressed@5.28.1(transitive)
- Removed@statoscope/stats-extension-package-info@5.28.1(transitive)
Updated@statoscope/stats-extension-package-info@5.7.0-alpha.0