@statoscope/webpack-model
Advanced tools
Comparing version 5.26.2 to 5.27.0
@@ -1,3 +0,6 @@ | ||
import { HandledCompilation, HandledFileContext } from '../types'; | ||
import { Webpack } from '../webpack'; | ||
import { HandledCompilation, HandledFileContext, ProcessingContext } from '../types'; | ||
import { NormalizedFile, RawStatsFileDescriptor } from '../types'; | ||
import Compilation = Webpack.Compilation; | ||
export default function handleCompilations(rawStatsFileDescriptor: RawStatsFileDescriptor, file: NormalizedFile, fileContext: HandledFileContext): HandledCompilation[]; | ||
export declare function extractPackages(compilation: Compilation, context: ProcessingContext): void; |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.extractPackages = void 0; | ||
const md5_1 = __importDefault(require("md5")); | ||
@@ -82,4 +83,10 @@ const graph_1 = __importDefault(require("@statoscope/helpers/dist/graph")); | ||
function moduleIdModifier(id) { | ||
return id.replace(/(.+[|\s])([a-f0-9]+)$/, '$1root'); | ||
let cached = moduleIdModifier.cache.get(id); | ||
if (!cached) { | ||
cached = id.replace(/(.+[|\s])([a-f0-9]+)$/, '$1root'); | ||
moduleIdModifier.cache.set(id, cached); | ||
} | ||
return cached; | ||
} | ||
moduleIdModifier.cache = new Map(); | ||
function handleCompilation(compilation, file, parent, fileContext) { | ||
@@ -471,7 +478,4 @@ var _a; | ||
function extractPackages(compilation, context) { | ||
const buildReasonKey = (type, moduleIdentifier, loc) => { | ||
return [type, moduleIdentifier, loc].join(';'); | ||
}; | ||
const extractModulePackages = (module) => { | ||
var _a, _b, _c; | ||
var _a, _b; | ||
const resource = (0, module_1.moduleResource)(module); | ||
@@ -486,3 +490,2 @@ if (!resource) { | ||
resolvedPackage = { name: modulePackage.name, instances: [] }; | ||
compilation.nodeModules.push(resolvedPackage); | ||
context.indexes.packages.add(resolvedPackage); | ||
@@ -509,6 +512,3 @@ } | ||
} | ||
const instanceReasonsKeys = new Set(instance.reasons.map((reason) => { | ||
var _a, _b; | ||
return buildReasonKey(reason.type, (_a = reason.data.moduleIdentifier) !== null && _a !== void 0 ? _a : 'unknown', (_b = reason.data.loc) !== null && _b !== void 0 ? _b : 'unknown'); | ||
})); | ||
const instanceReasonsKeys = new Set(instance.reasons.map((r) => r.data.identifier)); | ||
// reasons already ungrouped and normalized | ||
@@ -522,5 +522,8 @@ const reasons = module.reasons; | ||
const reasonType = 'module'; | ||
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)) { | ||
instance.reasons.push({ type: reasonType, data: reason }); | ||
const reasonKey = (_b = reason.moduleIdentifier) !== null && _b !== void 0 ? _b : 'unknown'; | ||
if (!instanceReasonsKeys.has(reasonKey) && reason.resolvedModule) { | ||
instance.reasons.push({ | ||
type: reasonType, | ||
data: reason.resolvedModule, | ||
}); | ||
instanceReasonsKeys.add(reasonKey); | ||
@@ -534,3 +537,7 @@ } | ||
} | ||
for (const packageItem of context.indexes.packages.getAll()) { | ||
compilation.nodeModules.push(packageItem); | ||
} | ||
} | ||
exports.extractPackages = extractPackages; | ||
//# sourceMappingURL=handleCompilation.js.map |
@@ -88,2 +88,3 @@ import type { Size } from '@statoscope/stats-extension-compressed/dist/generator'; | ||
entrypoint_getAsyncAssets(entrypoint: NormalizedEntrypointItem): NormalizedAsset[]; | ||
module_retained_modules: (module?: NormalizedModule) => NormalizedModule[]; | ||
}; |
@@ -379,2 +379,39 @@ "use strict"; | ||
}, | ||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type | ||
module_retained_modules: (() => { | ||
const cache = new WeakMap(); | ||
return (module) => { | ||
var _a; | ||
if (!module) { | ||
return []; | ||
} | ||
const cached = cache.get(module); | ||
if (cached) { | ||
return [...cached]; | ||
} | ||
const passed = new Set(); | ||
const stack = [module]; | ||
let cursor; | ||
while ((cursor = stack.pop())) { | ||
if (passed.has(cursor)) { | ||
continue; | ||
} | ||
if (cursor !== module && | ||
cursor.reasons.some((r) => r.resolvedModule && | ||
r.resolvedModule !== module && | ||
!passed.has(r.resolvedModule))) { | ||
continue; | ||
} | ||
passed.add(cursor); | ||
for (const dep of (_a = cursor.deps) !== null && _a !== void 0 ? _a : []) { | ||
if (dep.module) { | ||
stack.push(dep.module); | ||
} | ||
} | ||
} | ||
passed.delete(module); | ||
cache.set(module, passed); | ||
return [...passed]; | ||
}; | ||
})(), | ||
}; | ||
@@ -381,0 +418,0 @@ } |
@@ -11,13 +11,25 @@ "use strict"; | ||
exports.matchRxValue = matchRxValue; | ||
const resourceNameCache = new Map(); | ||
const nodeModuleNameCache = new Map(); | ||
function moduleNameResource(name) { | ||
if (name && !name.includes('(ignored)') && !name.startsWith('multi')) { | ||
const normalized = matchRxValue(exports.extractFileRx, name.replace('(webpack)', 'node_modules/webpack')); | ||
if (!normalized) { | ||
return name; | ||
if (name) { | ||
const cached = resourceNameCache.get(name); | ||
if (cached) { | ||
return cached; | ||
} | ||
const nameResource = matchRxValue(exports.concatenatedIdRx, normalized) || normalized; | ||
if (nameResource.startsWith('./') || nameResource.startsWith('.\\')) { | ||
return nameResource.slice(2); | ||
if (!name.includes('(ignored)') && !name.startsWith('multi')) { | ||
const normalized = matchRxValue(exports.extractFileRx, name.replace('(webpack)', 'node_modules/webpack')); | ||
if (!normalized) { | ||
resourceNameCache.set(name, name); | ||
return name; | ||
} | ||
const nameResource = matchRxValue(exports.concatenatedIdRx, normalized) || normalized; | ||
if (nameResource.startsWith('./') || nameResource.startsWith('.\\')) { | ||
const result = nameResource.slice(2); | ||
resourceNameCache.set(name, result); | ||
return result; | ||
} | ||
resourceNameCache.set(name, nameResource); | ||
return nameResource; | ||
} | ||
return nameResource; | ||
} | ||
@@ -28,2 +40,3 @@ return null; | ||
function moduleResource(module) { | ||
var _a; | ||
if ((module === null || module === void 0 ? void 0 : module.moduleType) && | ||
@@ -34,7 +47,8 @@ ((module === null || module === void 0 ? void 0 : module.moduleType) === 'provide-module' || | ||
} | ||
return moduleNameResource(module && module.name); | ||
return moduleNameResource((_a = module === null || module === void 0 ? void 0 : module.name) !== null && _a !== void 0 ? _a : null); | ||
} | ||
exports.moduleResource = moduleResource; | ||
function moduleReasonResource(reason) { | ||
return moduleNameResource(reason && reason.moduleName); | ||
var _a; | ||
return moduleNameResource((_a = reason === null || reason === void 0 ? void 0 : reason.moduleName) !== null && _a !== void 0 ? _a : null); | ||
} | ||
@@ -46,10 +60,17 @@ exports.moduleReasonResource = moduleReasonResource; | ||
} | ||
const lastNodeModulesRx = /.*(?:^|[/\\])node_modules[/\\](@.+?[/\\][^/\\\s]+|[^/\\\s]+)/; | ||
const [input, name] = path.match(lastNodeModulesRx) || []; | ||
const isRoot = input | ||
? !/.*(?:^|[/\\])node_modules[/\\].+[/\\]node_modules[/\\]/.test(input) | ||
: false; | ||
return name ? { path: input, name, isRoot } : null; | ||
let cached = nodeModuleNameCache.get(path); | ||
if (!cached) { | ||
const lastNodeModulesRx = /.*node_modules[/\\](?:(@.+?)[/\\])?([^/\\]+)/; | ||
const [input, namespace, name] = path.match(lastNodeModulesRx) || []; | ||
const isRoot = input | ||
? input.indexOf('node_modules') === input.lastIndexOf('node_modules') | ||
: false; | ||
cached = name | ||
? { path: input, name: [namespace, name].filter(Boolean).join('/'), isRoot } | ||
: null; | ||
nodeModuleNameCache.set(path, cached); | ||
} | ||
return cached; | ||
} | ||
exports.nodeModule = nodeModule; | ||
//# sourceMappingURL=module.js.map |
{ | ||
"name": "@statoscope/webpack-model", | ||
"version": "5.26.2", | ||
"version": "5.27.0", | ||
"description": "This package contains helpers to process webpack stats", | ||
@@ -25,6 +25,6 @@ "main": "./dist/index.js", | ||
"@statoscope/stats-extension-compressed": "5.25.0", | ||
"@statoscope/stats-extension-custom-reports": "5.25.0", | ||
"@statoscope/stats-extension-package-info": "5.25.0", | ||
"@statoscope/stats-extension-stats-validation-result": "5.25.0", | ||
"@statoscope/types": "5.22.0", | ||
"@statoscope/stats-extension-custom-reports": "5.27.0", | ||
"@statoscope/stats-extension-package-info": "5.27.0", | ||
"@statoscope/stats-extension-stats-validation-result": "5.27.0", | ||
"@statoscope/types": "5.27.0", | ||
"md5": "^2.3.0" | ||
@@ -37,3 +37,3 @@ }, | ||
}, | ||
"gitHead": "228b7f1d677df062c35d8fd72e87b1d67ef4d562" | ||
"gitHead": "9fbcea0159a2e50316d9618c73b312fd41091a79" | ||
} |
@@ -78,3 +78,3 @@ import { ResolverFn } from '@statoscope/helpers/dist/entity-resolver'; | ||
isRoot: boolean; | ||
reasons: Array<{ type: 'module' | 'entry'; data: NormalizedReason }>; | ||
reasons: Array<{ type: 'module'; data: NormalizedModule }>; | ||
modules: NormalizedModule[]; | ||
@@ -81,0 +81,0 @@ version?: string; |
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
87674
1986
+ Added@statoscope/stats-extension-custom-reports@5.27.0(transitive)
+ Added@statoscope/stats-extension-package-info@5.27.0(transitive)
+ Added@statoscope/stats-extension-stats-validation-result@5.27.0(transitive)
+ Added@statoscope/types@5.27.0(transitive)
- Removed@statoscope/stats-extension-custom-reports@5.25.0(transitive)
- Removed@statoscope/stats-extension-package-info@5.25.0(transitive)
- Removed@statoscope/stats-extension-stats-validation-result@5.25.0(transitive)
- Removed@statoscope/types@5.22.0(transitive)
Updated@statoscope/stats-extension-stats-validation-result@5.27.0
Updated@statoscope/types@5.27.0