@statoscope/webpack-model
Advanced tools
Comparing version 5.0.0 to 5.1.0-alpha.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = make; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function warnCache(entities, getId, cache) { | ||
if (Array.isArray(entities) || entities instanceof Set) { | ||
for (const entity of entities) { | ||
cache.set(getId(entity), entity); | ||
if (Array.isArray(entities) || entities instanceof Set) { | ||
for (const entity of entities) { | ||
cache.set(getId(entity), entity); | ||
} | ||
} | ||
} else if (entities instanceof Map) { | ||
for (const [, entity] of entities) { | ||
cache.set(getId(entity), entity); | ||
else if (entities instanceof Map) { | ||
for (const [, entity] of entities) { | ||
cache.set(getId(entity), entity); | ||
} | ||
} | ||
} else { | ||
for (const name in entities) { | ||
const entity = entities[name]; | ||
cache.set(getId(entity), entity); | ||
else { | ||
for (const name in entities) { | ||
const entity = entities[name]; | ||
cache.set(getId(entity), entity); | ||
} | ||
} | ||
} | ||
} | ||
function make(entities, getId) { | ||
const cache = new Map(); | ||
warnCache(entities, getId, cache); | ||
return id => { | ||
const cached = cache.get(id); | ||
if (cached) { | ||
return cached; | ||
} | ||
let result = null; | ||
if (Array.isArray(entities) || entities instanceof Set) { | ||
for (const entity of entities) { | ||
if (getId(entity) === id) { | ||
result = entity; | ||
break; | ||
const cache = new Map(); | ||
warnCache(entities, getId, cache); | ||
return (id) => { | ||
const cached = cache.get(id); | ||
if (cached) { | ||
return cached; | ||
} | ||
} | ||
} else if (entities instanceof Map) { | ||
for (const [, entity] of entities) { | ||
if (getId(entity) === id) { | ||
result = entity; | ||
break; | ||
let result = null; | ||
if (Array.isArray(entities) || entities instanceof Set) { | ||
for (const entity of entities) { | ||
if (getId(entity) === id) { | ||
result = entity; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} else { | ||
for (const name in entities) { | ||
const entity = entities[name]; | ||
if (getId(entity) === id) { | ||
result = entity; | ||
break; | ||
else if (entities instanceof Map) { | ||
for (const [, entity] of entities) { | ||
if (getId(entity) === id) { | ||
result = entity; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if (result) { | ||
cache.set(id, result); | ||
} | ||
return result; | ||
}; | ||
} | ||
else { | ||
for (const name in entities) { | ||
const entity = entities[name]; | ||
if (getId(entity) === id) { | ||
result = entity; | ||
break; | ||
} | ||
} | ||
} | ||
if (result) { | ||
cache.set(id, result); | ||
} | ||
return result; | ||
}; | ||
} | ||
exports.default = make; | ||
//# sourceMappingURL=entity-resolver.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.prepareWithJora = exports.normalize = exports.joraHelpers = exports.module = exports.validate = exports.makeEntityResolver = void 0; | ||
// @ts-ignore | ||
const jora_1 = __importDefault(require("jora")); | ||
const jora_helpers_1 = __importDefault(require("./jora-helpers")); | ||
exports.joraHelpers = jora_helpers_1.default; | ||
const normalize_1 = __importDefault(require("./normalize")); | ||
exports.normalize = normalize_1.default; | ||
var entity_resolver_1 = require("./entity-resolver"); | ||
Object.defineProperty(exports, "makeEntityResolver", { enumerable: true, get: function () { return __importDefault(entity_resolver_1).default; } }); | ||
var validate_1 = require("./validate"); | ||
Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return __importDefault(validate_1).default; } }); | ||
exports.module = __importStar(require("./module")); | ||
function prepareWithJora(stats, options = {}) { | ||
const { files, compilations } = normalize_1.default(stats); | ||
const j = jora_1.default.setup({ | ||
...options.helpers, | ||
...jora_helpers_1.default(compilations), | ||
}); | ||
const context = {}; | ||
return { | ||
files, | ||
compilations: compilations.map((c) => c.data), | ||
query: (query, data) => j(query)(data || files, context), | ||
}; | ||
} | ||
exports.prepareWithJora = prepareWithJora; | ||
Object.defineProperty(exports, "joraHelpers", { | ||
enumerable: true, | ||
get: function () { | ||
return _joraHelpers.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "normalize", { | ||
enumerable: true, | ||
get: function () { | ||
return _normalize.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "makeEntityResolver", { | ||
enumerable: true, | ||
get: function () { | ||
return _entityResolver.default; | ||
} | ||
}); | ||
Object.defineProperty(exports, "validate", { | ||
enumerable: true, | ||
get: function () { | ||
return _validate.default; | ||
} | ||
}); | ||
exports.module = void 0; | ||
var _jora = _interopRequireDefault(require("jora")); | ||
var _joraHelpers = _interopRequireDefault(require("./jora-helpers")); | ||
var _normalize = _interopRequireDefault(require("./normalize")); | ||
var _entityResolver = _interopRequireDefault(require("./entity-resolver")); | ||
var _validate = _interopRequireDefault(require("./validate")); | ||
var _module = _interopRequireWildcard(require("./module")); | ||
exports.module = _module; | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function prepareWithJora(stats, options = {}) { | ||
const { | ||
files, | ||
compilations | ||
} = (0, _normalize.default)(stats); | ||
const j = _jora.default.setup({ ...options.helpers, | ||
...(0, _joraHelpers.default)(compilations) | ||
}); | ||
const context = {}; | ||
return { | ||
files, | ||
compilations, | ||
query: (query, data) => j(query)(data || files, context) | ||
}; | ||
} | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = _default; | ||
var _module = require("./module"); | ||
var _entityResolver = _interopRequireDefault(require("./entity-resolver")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _default(compilations) { | ||
const resolveCompilation = (0, _entityResolver.default)(compilations, item => { | ||
var _item$data; | ||
return item === null || item === void 0 ? void 0 : (_item$data = item.data) === null || _item$data === void 0 ? void 0 : _item$data.hash; | ||
}); | ||
return { | ||
moduleSize(module) { | ||
// todo gzip | ||
return module.size; | ||
}, | ||
chunkName(chunk) { | ||
return `${chunk.names[0] ? chunk.names.join(', ') : chunk.id}${chunk.reason ? ' [' + chunk.reason + ']' : ''}`; | ||
}, | ||
getTotalFilesSize: asset => (asset.files || []).reduce((sum, file) => sum + file.size, 0), | ||
resolveChunk(id, compilationHash) { | ||
var _resolveCompilation; | ||
return (_resolveCompilation = resolveCompilation(compilationHash)) === null || _resolveCompilation === void 0 ? void 0 : _resolveCompilation.resolvers.resolveChunk(id); | ||
}, | ||
resolveAsset(id, compilationHash) { | ||
var _resolveCompilation2; | ||
return (_resolveCompilation2 = resolveCompilation(compilationHash)) === null || _resolveCompilation2 === void 0 ? void 0 : _resolveCompilation2.resolvers.resolveAsset(id); | ||
}, | ||
resolveModule(id, compilationHash) { | ||
var _resolveCompilation3; | ||
return (_resolveCompilation3 = resolveCompilation(compilationHash)) === null || _resolveCompilation3 === void 0 ? void 0 : _resolveCompilation3.resolvers.resolveModule(id); | ||
}, | ||
resolvePackage(id, compilationHash) { | ||
var _resolveCompilation4; | ||
return (_resolveCompilation4 = resolveCompilation(compilationHash)) === null || _resolveCompilation4 === void 0 ? void 0 : _resolveCompilation4.resolvers.resolvePackage(id); | ||
}, | ||
resolveStat(id) { | ||
const resolved = resolveCompilation(id); | ||
return resolved && { | ||
file: resolved === null || resolved === void 0 ? void 0 : resolved.file, | ||
compilation: resolved === null || resolved === void 0 ? void 0 : resolved.data | ||
}; | ||
}, | ||
resolveCompilation(id) { | ||
const resolved = resolveCompilation(id); | ||
return resolved && (resolved === null || resolved === void 0 ? void 0 : resolved.data); | ||
}, | ||
moduleResource: _module.moduleResource, | ||
moduleReasonResource: _module.moduleReasonResource, | ||
moduleNameResource: _module.moduleNameResource, | ||
nodeModule: _module.nodeModule, | ||
statName(stat) { | ||
if (!stat) { | ||
return 'unknown'; | ||
} | ||
const hash = stat.compilation.hash.slice(0, 7); | ||
const compilationName = stat.compilation.name && (0, _module.moduleNameResource)(stat.compilation.name); | ||
if (stat.file.name) { | ||
return `${stat.file.name} (${compilationName || hash})`; | ||
} else if (compilationName) { | ||
return `${compilationName} (${hash})`; | ||
} | ||
return hash; | ||
} | ||
}; | ||
} | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const module_1 = require("./module"); | ||
const entity_resolver_1 = __importDefault(require("./entity-resolver")); | ||
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; }); | ||
return { | ||
moduleSize(module) { | ||
// todo gzip | ||
return module.size; | ||
}, | ||
chunkName(chunk) { | ||
return `${chunk.names[0] ? chunk.names.join(', ') : chunk.id}${chunk.reason ? ' [' + chunk.reason + ']' : ''}`; | ||
}, | ||
getTotalFilesSize: (asset) => asset.files.reduce((sum, file) => sum + file.size, 0), | ||
resolveChunk(id, compilationHash) { | ||
var _a; | ||
return ((_a = resolveCompilation(compilationHash)) === null || _a === void 0 ? void 0 : _a.resolvers.resolveChunk(id)) || null; | ||
}, | ||
resolveAsset(id, compilationHash) { | ||
var _a; | ||
return ((_a = resolveCompilation(compilationHash)) === null || _a === void 0 ? void 0 : _a.resolvers.resolveAsset(id)) || null; | ||
}, | ||
resolveModule(id, compilationHash) { | ||
var _a; | ||
return ((_a = resolveCompilation(compilationHash)) === null || _a === void 0 ? void 0 : _a.resolvers.resolveModule(id)) || null; | ||
}, | ||
resolvePackage(id, compilationHash) { | ||
var _a; | ||
return ((_a = resolveCompilation(compilationHash)) === null || _a === void 0 ? void 0 : _a.resolvers.resolvePackage(id)) || null; | ||
}, | ||
resolveStat(id) { | ||
const resolved = resolveCompilation(id); | ||
return (resolved && { file: resolved === null || resolved === void 0 ? void 0 : resolved.file, compilation: resolved === null || resolved === void 0 ? void 0 : resolved.data }) || null; | ||
}, | ||
resolveCompilation(id) { | ||
const resolved = resolveCompilation(id); | ||
return (resolved && (resolved === null || resolved === void 0 ? void 0 : resolved.data)) || null; | ||
}, | ||
moduleResource: module_1.moduleResource, | ||
moduleReasonResource: module_1.moduleReasonResource, | ||
moduleNameResource: module_1.moduleNameResource, | ||
nodeModule: module_1.nodeModule, | ||
statName(stat) { | ||
if (!stat) { | ||
return 'unknown'; | ||
} | ||
const hash = stat.compilation.hash.slice(0, 7); | ||
const compilationName = stat.compilation.name && module_1.moduleNameResource(stat.compilation.name); | ||
if (stat.file.name) { | ||
return `${stat.file.name} (${compilationName || hash})`; | ||
} | ||
else if (compilationName) { | ||
return `${compilationName} (${hash})`; | ||
} | ||
return hash; | ||
}, | ||
}; | ||
} | ||
exports.default = default_1; | ||
//# sourceMappingURL=jora-helpers.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.matchRxValue = matchRxValue; | ||
exports.moduleNameResource = moduleNameResource; | ||
exports.moduleResource = moduleResource; | ||
exports.moduleReasonResource = moduleReasonResource; | ||
exports.nodeModule = nodeModule; | ||
exports.contextIdRx = exports.concatenatedIdRx = exports.extractFileRx = void 0; | ||
const extractFileRx = /.*(?:^|!|\s+)(\.?\.?[\\/].+)/; | ||
exports.extractFileRx = extractFileRx; | ||
const concatenatedIdRx = /(.+) \+ \d+ modules$/; | ||
exports.concatenatedIdRx = concatenatedIdRx; | ||
const contextIdRx = /(.+) (?:sync|eager|weak|async-weak|lazy|lazy-once)(?:\s|$)/; | ||
exports.contextIdRx = contextIdRx; | ||
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.concatenatedIdRx = /(.+) \+ \d+ modules$/; | ||
exports.contextIdRx = /(.+) (?:sync|eager|weak|async-weak|lazy|lazy-once)(?:\s|$)/; | ||
function matchRxValue(rx, string) { | ||
const [, match] = string.match(rx) || []; | ||
return match || null; | ||
const [, match] = string.match(rx) || []; | ||
return match || null; | ||
} | ||
exports.matchRxValue = matchRxValue; | ||
function moduleNameResource(name) { | ||
if (name && !name.includes('(ignored)') && !name.startsWith('multi')) { | ||
const normalized = matchRxValue(extractFileRx, name.replace('(webpack)', '/node_modules/webpack')); | ||
if (!normalized) { | ||
return name; | ||
if (name && !name.includes('(ignored)') && !name.startsWith('multi')) { | ||
const normalized = matchRxValue(exports.extractFileRx, name.replace('(webpack)', '/node_modules/webpack')); | ||
if (!normalized) { | ||
return name; | ||
} | ||
const nameResource = matchRxValue(exports.concatenatedIdRx, normalized) || | ||
matchRxValue(exports.contextIdRx, normalized) || | ||
normalized; | ||
if (nameResource.startsWith('./') || nameResource.startsWith('.\\')) { | ||
return nameResource.slice(2); | ||
} | ||
return nameResource; | ||
} | ||
const nameResource = matchRxValue(concatenatedIdRx, normalized) || matchRxValue(contextIdRx, normalized) || normalized; | ||
if (nameResource.startsWith('./') || nameResource.startsWith('.\\')) { | ||
return nameResource.slice(2); | ||
} | ||
return nameResource; | ||
} | ||
return null; | ||
return null; | ||
} | ||
exports.moduleNameResource = moduleNameResource; | ||
function moduleResource(module) { | ||
return moduleNameResource(module && module.name); | ||
return moduleNameResource(module && module.name); | ||
} | ||
exports.moduleResource = moduleResource; | ||
function moduleReasonResource(reason) { | ||
return moduleNameResource(reason && reason.moduleName); | ||
return moduleNameResource(reason && reason.moduleName); | ||
} | ||
exports.moduleReasonResource = moduleReasonResource; | ||
function nodeModule(path) { | ||
if (!path) { | ||
return null; | ||
} | ||
const lastNodeModulesRx = /.*(?:^|[/\\])node_modules[/\\](@.+?[/\\][^/\\\s]+|[^/\\\s]+)/; | ||
const [input, name] = path.match(lastNodeModulesRx) || []; | ||
const isRoot = input ? !input.match(/\/node_modules\/.+\/node_modules\//) : false; | ||
return name ? { | ||
path: input, | ||
name, | ||
isRoot | ||
} : null; | ||
} | ||
if (!path) { | ||
return null; | ||
} | ||
const lastNodeModulesRx = /.*(?:^|[/\\])node_modules[/\\](@.+?[/\\][^/\\\s]+|[^/\\\s]+)/; | ||
const [input, name] = path.match(lastNodeModulesRx) || []; | ||
const isRoot = input ? !input.match(/\/node_modules\/.+\/node_modules\//) : false; | ||
return name ? { path: input, name, isRoot } : null; | ||
} | ||
exports.nodeModule = nodeModule; | ||
//# sourceMappingURL=module.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = modulesToFoamTree; | ||
var _module = require("./module"); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const module_1 = require("./module"); | ||
function makeNode(data, size, path) { | ||
return { | ||
label: data.label, | ||
weight: size, | ||
groups: [], | ||
link: data.link, | ||
path | ||
}; | ||
return { | ||
label: data.label, | ||
weight: size, | ||
groups: [], | ||
link: data.link, | ||
path, | ||
}; | ||
} | ||
function handleModule(root, module) { | ||
const resource = (0, _module.moduleResource)(module); | ||
if (!resource) { | ||
return; | ||
} | ||
const parts = resource.split(/[/\\]/).map(label => ({ | ||
label | ||
})); | ||
let currentPackage = null; | ||
for (const [i, part] of parts.entries()) { | ||
if (part.label === 'node_modules') { | ||
currentPackage = { | ||
name: '' | ||
}; | ||
} else if (currentPackage) { | ||
if (part.label[0] === '@') { | ||
currentPackage = { | ||
name: part.label | ||
const resource = module_1.moduleResource(module); | ||
if (!resource) { | ||
return; | ||
} | ||
const parts = resource.split(/[/\\]/).map((label) => ({ label })); | ||
let currentPackage = null; | ||
for (const [i, part] of parts.entries()) { | ||
if (part.label === 'node_modules') { | ||
currentPackage = { name: '' }; | ||
} | ||
else if (currentPackage) { | ||
if (part.label[0] === '@') { | ||
currentPackage = { name: part.label }; | ||
} | ||
else { | ||
currentPackage.name += (currentPackage.name ? '/' : '') + part.label; | ||
part.link = { | ||
page: 'package', | ||
id: currentPackage.name, | ||
params: { | ||
instance: parts | ||
.map((part) => part.label) | ||
.slice(0, i + 1) | ||
.join('/'), | ||
}, | ||
}; | ||
currentPackage = null; | ||
} | ||
} | ||
} | ||
if (parts.length) { | ||
const last = parts[parts.length - 1]; | ||
last.link = { | ||
page: 'module', | ||
id: module.id || module.name, | ||
}; | ||
} else { | ||
currentPackage.name += (currentPackage.name ? '/' : '') + part.label; | ||
part.link = { | ||
page: 'package', | ||
id: currentPackage.name, | ||
params: { | ||
instance: parts.map(part => part.label).slice(0, i + 1).join('/') | ||
} | ||
}; | ||
currentPackage = null; | ||
} | ||
} | ||
} | ||
if (parts.length) { | ||
const last = parts[parts.length - 1]; | ||
last.link = { | ||
page: 'module', | ||
id: module.id || module.name | ||
}; | ||
} | ||
apply(root, parts, module.modules ? 0 : module.size); | ||
apply(root, parts, module.modules ? 0 : module.size); | ||
} | ||
function apply(root, parts, size) { | ||
const stack = [root]; | ||
let cursor = root; | ||
function applyToStack(stack, size) { | ||
for (const item of stack) { | ||
item.weight += size; | ||
const stack = [root]; | ||
let cursor = root; | ||
function applyToStack(stack, size) { | ||
for (const item of stack) { | ||
item.weight += size; | ||
} | ||
} | ||
} | ||
for (const part of parts) { | ||
let node = cursor.groups.find(node => node.label === part.label); | ||
if (!node) { | ||
node = makeNode(part, 0, [...stack, part].map(item => item.label).filter(Boolean).join('/')); | ||
cursor.groups.push(node); | ||
for (const part of parts) { | ||
let node = (cursor === null || cursor === void 0 ? void 0 : cursor.groups.find((node) => node.label === part.label)) || null; | ||
if (!node) { | ||
node = makeNode(part, 0, [...stack, part] | ||
.map((item) => item.label) | ||
.filter(Boolean) | ||
.join('/')); | ||
cursor.groups.push(node); | ||
} | ||
cursor = node; | ||
stack.push(cursor); | ||
} | ||
cursor = node; | ||
stack.push(cursor); | ||
} | ||
applyToStack(stack, size); | ||
applyToStack(stack, size); | ||
} | ||
function modulesToFoamTree(modules) { | ||
const root = makeNode('', 0, '/'); | ||
for (const module of modules) { | ||
handleModule(root, module); | ||
if (module.modules) { | ||
for (const innerModule of module.modules) { | ||
handleModule(root, innerModule); | ||
} | ||
const root = makeNode({ label: '' }, 0, '/'); | ||
for (const module of modules) { | ||
handleModule(root, module); | ||
if (module.modules) { | ||
for (const innerModule of module.modules) { | ||
handleModule(root, innerModule); | ||
} | ||
} | ||
} | ||
} | ||
return root; | ||
} | ||
return root; | ||
} | ||
exports.default = modulesToFoamTree; | ||
//# sourceMappingURL=modules-to-foam-tree.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = normalize; | ||
exports.handleRawFile = handleRawFile; | ||
var _md = _interopRequireDefault(require("md5")); | ||
var _validate = _interopRequireDefault(require("./validate")); | ||
var _module = require("./module"); | ||
var _entityResolver = _interopRequireDefault(require("./entity-resolver")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.handleRawFile = void 0; | ||
const md5_1 = __importDefault(require("md5")); | ||
const validate_1 = __importDefault(require("./validate")); | ||
const module_1 = require("./module"); | ||
const entity_resolver_1 = __importDefault(require("./entity-resolver")); | ||
function getHash(compilation, parent) { | ||
if (compilation.hash) { | ||
return compilation.hash; | ||
} | ||
if (parent) { | ||
return (0, _md.default)(parent.hash + String(compilation.name)); | ||
} | ||
return (0, _md.default)(compilation.name); | ||
if (compilation.hash) { | ||
return compilation.hash; | ||
} | ||
if (parent) { | ||
return md5_1.default(parent.hash + String(compilation.name)); | ||
} | ||
return md5_1.default(compilation.name || 'unknown'); | ||
} | ||
function prepareCompilation(compilation, parent) { | ||
return { | ||
time: compilation.time, | ||
builtAt: compilation.builtAt, | ||
name: compilation.name, | ||
hash: getHash(compilation, parent), | ||
entrypoints: compilation.entrypoints || [], | ||
chunks: compilation.chunks || [], | ||
assets: compilation.assets || [], | ||
modules: [], | ||
nodeModules: [], | ||
children: (compilation.children || []).map(child => prepareCompilation(child, compilation)), | ||
isChild: !!(parent !== null && parent !== void 0 && parent.hash), | ||
parent: (parent === null || parent === void 0 ? void 0 : parent.hash) || null | ||
}; | ||
} | ||
function normalize(rawData) { | ||
const files = []; | ||
const compilations = []; | ||
if (!Array.isArray(rawData)) { | ||
rawData = [rawData]; | ||
} | ||
for (const rawFile of rawData) { | ||
const handledFile = handleRawFile(rawFile); | ||
files.push(handledFile.file); | ||
compilations.push(...handledFile.compilations); | ||
} | ||
return { | ||
files, | ||
compilations | ||
}; | ||
const files = []; | ||
const compilations = []; | ||
if (!Array.isArray(rawData)) { | ||
rawData = [rawData]; | ||
} | ||
for (const rawFile of rawData) { | ||
const handledFile = handleRawFile(rawFile); | ||
files.push(handledFile.file); | ||
compilations.push(...handledFile.compilations); | ||
} | ||
return { files, compilations }; | ||
} | ||
exports.default = normalize; | ||
function handleRawFile(rawStatsFileDescriptor) { | ||
const file = { | ||
name: rawStatsFileDescriptor.name, | ||
version: rawStatsFileDescriptor.data.version || 'unknown', | ||
validation: (0, _validate.default)(rawStatsFileDescriptor.data), | ||
compilations: [] | ||
}; | ||
const compilations = []; | ||
const stack = [prepareCompilation(rawStatsFileDescriptor.data)]; | ||
let cursor; | ||
while (cursor = stack.pop()) { | ||
const handled = handleCompilation(cursor, file); | ||
file.compilations.push(handled.data); | ||
compilations.push(handled); | ||
for (const child of cursor.children) { | ||
stack.push(child); | ||
const file = { | ||
name: rawStatsFileDescriptor.name, | ||
version: rawStatsFileDescriptor.data.version || 'unknown', | ||
validation: validate_1.default(rawStatsFileDescriptor.data), | ||
compilations: [], | ||
}; | ||
const compilations = []; | ||
const stack = [ | ||
{ | ||
compilation: rawStatsFileDescriptor.data, | ||
parent: null, | ||
}, | ||
]; | ||
let cursor; | ||
while ((cursor = stack.pop())) { | ||
const handled = handleCompilation(cursor.compilation, file, cursor.parent); | ||
if (cursor.parent) { | ||
cursor.parent.children.push(handled.data); | ||
} | ||
file.compilations.push(handled.data); | ||
compilations.push(handled); | ||
for (const child of cursor.compilation.children || []) { | ||
stack.push({ compilation: child, parent: handled.data }); | ||
} | ||
} | ||
} | ||
return { | ||
file, | ||
compilations | ||
}; | ||
return { file, compilations }; | ||
} | ||
function handleCompilation(compilation, file) { | ||
const resolveModule = makeModuleResolver(compilation); | ||
const resolveChunk = (0, _entityResolver.default)(compilation.chunks, ({ | ||
id | ||
}) => id); | ||
const resolveAsset = (0, _entityResolver.default)(compilation.assets, ({ | ||
name | ||
}) => name); | ||
const resolvePackage = (0, _entityResolver.default)(compilation.nodeModules, ({ | ||
name | ||
}) => name); | ||
const resolvers = { | ||
resolveModule, | ||
resolveChunk, | ||
resolveAsset, | ||
resolvePackage | ||
}; | ||
prepareModules(compilation, resolvers); | ||
prepareChunks(compilation, resolvers); | ||
prepareAssets(compilation, resolvers); | ||
prepareEntries(compilation, resolvers); | ||
extractPackages(compilation, resolvers); | ||
return { | ||
data: compilation, | ||
resolvers, | ||
file | ||
}; | ||
exports.handleRawFile = handleRawFile; | ||
function handleCompilation(compilation, file, parent) { | ||
const normalized = { | ||
time: compilation.time, | ||
builtAt: compilation.builtAt, | ||
name: compilation.name, | ||
hash: getHash(compilation, parent), | ||
entrypoints: [], | ||
chunks: compilation.chunks || [], | ||
assets: compilation.assets || [], | ||
modules: compilation.modules || [], | ||
nodeModules: [], | ||
children: [], | ||
isChild: !!(parent === null || parent === void 0 ? void 0 : parent.hash), | ||
parent: (parent === null || parent === void 0 ? void 0 : parent.hash) || null, | ||
}; | ||
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 resolvers = { | ||
resolveModule, | ||
resolveChunk, | ||
resolveAsset, | ||
resolvePackage, | ||
}; | ||
prepareModules(compilation, resolvers); | ||
prepareChunks(compilation, resolvers); | ||
prepareAssets(compilation, resolvers); | ||
normalized.entrypoints = prepareEntries(compilation, resolvers); | ||
extractPackages(normalized, resolvers); | ||
return { | ||
data: normalized, | ||
resolvers, | ||
file, | ||
}; | ||
} | ||
function makeModuleResolver(compilation) { | ||
var _compilation$modules; | ||
const modulesMap = new Map(); | ||
for (const chunk of compilation.chunks) { | ||
if (!chunk.modules) { | ||
continue; | ||
const modules = [...compilation.modules]; | ||
const resolve = entity_resolver_1.default(modules, ({ name }) => name); | ||
for (const chunk of compilation.chunks) { | ||
for (const [ix, module] of Object.entries(chunk.modules || [])) { | ||
const resolved = resolve(module.name); | ||
if (!resolved) { | ||
modules.push(module); | ||
} | ||
else { | ||
// @ts-ignore | ||
chunk.modules[ix] = module; | ||
} | ||
} | ||
} | ||
for (const module of chunk.modules) { | ||
modulesMap.set(module.name, module); | ||
compilation.modules.length = 0; | ||
for (const module of modules) { | ||
compilation.modules.push(module); | ||
for (const innerModule of module.modules || []) { | ||
modules.push(innerModule); | ||
compilation.modules.push(module); | ||
} | ||
} | ||
} | ||
if ((_compilation$modules = compilation.modules) !== null && _compilation$modules !== void 0 && _compilation$modules.length) { | ||
for (const module of compilation.modules) { | ||
if (!modulesMap.has(module.name)) { | ||
modulesMap.set(module.name, module); | ||
} | ||
return resolve; | ||
} | ||
function prepareModule(module, { resolveChunk, resolveModule }) { | ||
module.resolvedResource = module_1.moduleResource(module); | ||
if (module.issuerPath) { | ||
module.issuerPath.map((i) => (i.resolvedModule = resolveModule(i.name))); | ||
} | ||
} | ||
compilation.modules = [...modulesMap.values()]; | ||
for (const [, module] of modulesMap) { | ||
if (!module.modules) { | ||
continue; | ||
if (module.chunks) { | ||
module.chunks = module.chunks | ||
.map((c) => resolveChunk(typeof c === 'string' ? c : c.id)) | ||
.filter(Boolean); | ||
} | ||
for (const innerModule of module.modules) { | ||
modulesMap.set(innerModule.name, innerModule); | ||
else { | ||
module.chunks = []; | ||
} | ||
} | ||
const modules = [...modulesMap.values()]; | ||
return (0, _entityResolver.default)(modules, ({ | ||
name | ||
}) => name); | ||
if (module.reasons) { | ||
module.reasons = module.reasons.filter((r) => r.moduleName !== module.name); | ||
module.reasons.forEach((r) => (r.resolvedModule = resolveModule(r.moduleName))); | ||
} | ||
else { | ||
module.reasons = []; | ||
} | ||
} | ||
function prepareModule(module, { | ||
resolveChunk, | ||
resolveModule | ||
}) { | ||
module.resolvedResource = (0, _module.moduleResource)(module); | ||
if (module.issuerPath) { | ||
module.issuerPath.map(i => i.resolvedModule = resolveModule(i.name)); | ||
} | ||
if (module.chunks) { | ||
module.chunks = module.chunks.map(c => resolveChunk(c)).filter(Boolean); | ||
} else { | ||
module.chunks = []; | ||
} | ||
if (module.reasons) { | ||
module.reasons = module.reasons.filter(r => r.moduleName !== module.name); | ||
module.reasons.forEach(r => r.resolvedModule = resolveModule(r.moduleName)); | ||
} else { | ||
module.reasons = []; | ||
} | ||
} | ||
function prepareModules(compilation, resolvers) { | ||
for (const module of compilation.modules) { | ||
prepareModule(module, resolvers); | ||
if (module.modules) { | ||
for (const innerModule of module.modules) { | ||
prepareModule(innerModule, resolvers); | ||
} | ||
for (const module of compilation.modules || []) { | ||
prepareModule(module, resolvers); | ||
if (module.modules) { | ||
for (const innerModule of module.modules) { | ||
prepareModule(innerModule, resolvers); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
function prepareChunks(compilation, { | ||
resolveModule, | ||
resolveAsset, | ||
resolveChunk | ||
}) { | ||
for (const chunk of compilation.chunks) { | ||
if (chunk.modules) { | ||
chunk.modules = chunk.modules.map(m => resolveModule(m.name)).filter(Boolean); | ||
} else { | ||
chunk.modules = []; | ||
function prepareChunks(compilation, { resolveModule, resolveAsset, resolveChunk }) { | ||
for (const chunk of compilation.chunks || []) { | ||
if (chunk.modules) { | ||
chunk.modules = chunk.modules | ||
.map((m) => resolveModule(m.name)) | ||
.filter(Boolean); | ||
} | ||
else { | ||
chunk.modules = []; | ||
} | ||
if (chunk.files) { | ||
chunk.files = chunk.files | ||
.map((f) => resolveAsset(typeof f === 'string' ? f : f.name)) | ||
.filter(Boolean); | ||
} | ||
else { | ||
chunk.files = []; | ||
} | ||
if (chunk.children) { | ||
chunk.children = chunk.children | ||
.map((c) => resolveChunk(typeof c === 'string' ? c : c.id)) | ||
.filter(Boolean); | ||
} | ||
else { | ||
chunk.children = []; | ||
} | ||
if (chunk.siblings) { | ||
chunk.siblings = chunk.siblings | ||
.map((c) => resolveChunk(typeof c === 'string' ? c : c.id)) | ||
.filter(Boolean); | ||
} | ||
else { | ||
chunk.siblings = []; | ||
} | ||
if (chunk.parents) { | ||
chunk.parents = chunk.parents | ||
.map((c) => resolveChunk(typeof c === 'string' ? c : c.id)) | ||
.filter(Boolean); | ||
} | ||
else { | ||
chunk.parents = []; | ||
} | ||
if (chunk.origins) { | ||
chunk.origins | ||
.map((o) => (o.resolvedModule = resolveModule(o.moduleName))) | ||
.filter(Boolean); | ||
} | ||
else { | ||
chunk.origins = []; | ||
} | ||
} | ||
if (chunk.files) { | ||
chunk.files = chunk.files.map(f => resolveAsset(f)).filter(Boolean); | ||
} else { | ||
chunk.files = []; | ||
} | ||
if (chunk.children) { | ||
chunk.children = chunk.children.map(c => resolveChunk(c)).filter(Boolean); | ||
} else { | ||
chunk.children = []; | ||
} | ||
if (chunk.siblings) { | ||
chunk.siblings = chunk.siblings.map(c => resolveChunk(c)).filter(Boolean); | ||
} else { | ||
chunk.siblings = []; | ||
} | ||
if (chunk.parents) { | ||
chunk.parents = chunk.parents.map(c => resolveChunk(c)).filter(Boolean); | ||
} else { | ||
chunk.parents = []; | ||
} | ||
if (chunk.origins) { | ||
chunk.origins.map(o => o.resolvedModule = resolveModule(o.moduleName)); | ||
} else { | ||
chunk.origins = []; | ||
} | ||
} | ||
} | ||
function prepareAssets(compilation, { | ||
resolveChunk | ||
}) { | ||
for (const asset of compilation.assets) { | ||
if (asset.chunks) { | ||
asset.chunks = asset.chunks.map(c => resolveChunk(c)).filter(Boolean); | ||
function prepareAssets(compilation, { resolveChunk }) { | ||
for (const asset of compilation.assets || []) { | ||
if (asset.chunks) { | ||
asset.chunks = asset.chunks | ||
.map((c) => resolveChunk(typeof c === 'string' ? c : c.id)) | ||
.filter(Boolean); | ||
} | ||
else { | ||
asset.chunks = []; | ||
} | ||
asset.files = asset.files || []; | ||
} | ||
} | ||
} | ||
function prepareEntries(compilation, { | ||
resolveChunk, | ||
resolveAsset | ||
}) { | ||
const entrypoints = []; | ||
for (const name in compilation.entrypoints) { | ||
const entry = compilation.entrypoints[name]; | ||
if (entry.chunks) { | ||
entry.chunks = entry.chunks.map(c => resolveChunk(c)).filter(Boolean); | ||
function prepareEntries(compilation, { resolveChunk, resolveAsset }) { | ||
const entrypoints = []; | ||
for (const name in compilation.entrypoints) { | ||
const entry = compilation.entrypoints[name]; | ||
if (entry.chunks) { | ||
entry.chunks = entry.chunks | ||
.map((c) => resolveChunk(typeof c === 'string' ? c : c.id)) | ||
.filter(Boolean); | ||
} | ||
if (entry.assets) { | ||
entry.assets = entry.assets | ||
.map((a) => resolveAsset(typeof a === 'string' ? a : a.name)) | ||
.filter(Boolean); | ||
} | ||
entrypoints.push({ name, data: entry }); | ||
} | ||
if (entry.assets) { | ||
entry.assets = entry.assets.map(a => resolveAsset(a.name || a)).filter(Boolean); | ||
} | ||
entrypoints.push({ | ||
name, | ||
data: entry | ||
}); | ||
} | ||
compilation.entrypoints = entrypoints; | ||
return entrypoints; | ||
} | ||
function extractPackages(compilation, { | ||
resolvePackage | ||
}) { | ||
const buildReasonKey = (type, moduleName, loc) => { | ||
return [type, moduleName, loc].join(';'); | ||
}; | ||
const extractModulePackages = module => { | ||
const resource = (0, _module.moduleResource)(module); | ||
if (!resource) { | ||
return; | ||
} | ||
const modulePackage = (0, _module.nodeModule)(resource); | ||
if (modulePackage) { | ||
let resolvedPackage = resolvePackage(modulePackage.name); | ||
if (!resolvedPackage) { | ||
resolvedPackage = { | ||
name: modulePackage.name, | ||
instances: [] | ||
}; | ||
compilation.nodeModules.push(resolvedPackage); | ||
} | ||
let instance = resolvedPackage.instances.find(({ | ||
path | ||
}) => path === modulePackage.path); | ||
if (!instance) { | ||
const isRoot = !modulePackage.path.match(/\/node_modules\/.+\/node_modules\//); | ||
instance = { | ||
path: modulePackage.path, | ||
isRoot, | ||
reasons: [], | ||
modules: [module] | ||
}; | ||
resolvedPackage.instances.push(instance); | ||
} else { | ||
if (!instance.modules.includes(module)) { | ||
instance.modules.push(module); | ||
function extractPackages(compilation, { resolvePackage }) { | ||
const buildReasonKey = (type, moduleName, loc) => { | ||
return [type, moduleName, loc].join(';'); | ||
}; | ||
const extractModulePackages = (module) => { | ||
const resource = module_1.moduleResource(module); | ||
if (!resource) { | ||
return; | ||
} | ||
} | ||
const instanceReasonsKeys = new Set(instance.reasons.map(reason => { | ||
return buildReasonKey(reason.type, reason.data.moduleName, reason.data.loc); | ||
})); | ||
for (const reason of module.reasons) { | ||
const reasonPackage = (0, _module.nodeModule)((0, _module.moduleReasonResource)(reason)); | ||
if (reasonPackage && reasonPackage.path === instance.path) { | ||
continue; | ||
const modulePackage = module_1.nodeModule(resource); | ||
if (modulePackage) { | ||
let resolvedPackage = resolvePackage(modulePackage.name); | ||
if (!resolvedPackage) { | ||
resolvedPackage = { name: modulePackage.name, instances: [] }; | ||
compilation.nodeModules.push(resolvedPackage); | ||
} | ||
let instance = resolvedPackage.instances.find(({ path }) => path === modulePackage.path); | ||
if (!instance) { | ||
const isRoot = !modulePackage.path.match(/\/node_modules\/.+\/node_modules\//); | ||
instance = { path: modulePackage.path, isRoot, reasons: [], modules: [module] }; | ||
resolvedPackage.instances.push(instance); | ||
} | ||
else { | ||
if (!instance.modules.includes(module)) { | ||
instance.modules.push(module); | ||
} | ||
} | ||
const instanceReasonsKeys = new Set(instance.reasons.map((reason) => { | ||
return buildReasonKey(reason.type, reason.data.moduleName, reason.data.loc); | ||
})); | ||
for (const reason of module.reasons) { | ||
const reasonPackage = module_1.nodeModule(module_1.moduleReasonResource(reason)); | ||
if (reasonPackage && reasonPackage.path === instance.path) { | ||
continue; | ||
} | ||
const reasonType = 'module'; | ||
const reasonKey = buildReasonKey(reasonType, reason.moduleName, reason.loc); | ||
if (!instanceReasonsKeys.has(reasonKey)) { | ||
instance.reasons.push({ type: reasonType, data: reason }); | ||
instanceReasonsKeys.add(reasonKey); | ||
} | ||
} | ||
} | ||
const reasonType = 'module'; | ||
const reasonKey = buildReasonKey(reasonType, reason.moduleName, reason.loc); | ||
if (!instanceReasonsKeys.has(reasonKey)) { | ||
instance.reasons.push({ | ||
type: reasonType, | ||
data: reason | ||
}); | ||
instanceReasonsKeys.add(reasonKey); | ||
}; | ||
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); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
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); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
//# sourceMappingURL=normalize.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const ajv_1 = __importDefault(require("ajv")); | ||
const stats_json_1 = __importDefault(require("./schema/stats.json")); | ||
function validateStats(stats) { | ||
const ajv = new ajv_1.default(); | ||
const validate = ajv.compile(stats_json_1.default); | ||
const valid = validate(stats); | ||
if (!valid) { | ||
return { result: false, errors: validate.errors }; | ||
} | ||
return { result: true }; | ||
} | ||
exports.default = validateStats; | ||
var _ajv = _interopRequireDefault(require("ajv")); | ||
var _stats = _interopRequireDefault(require("../schema/stats.json")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function validateStats(stats) { | ||
const ajv = new _ajv.default(); | ||
const validate = ajv.compile(_stats.default); | ||
const valid = validate(stats); | ||
if (!valid) { | ||
return { | ||
result: false, | ||
errors: validate.errors | ||
}; | ||
} | ||
return { | ||
result: true | ||
}; | ||
} | ||
//# sourceMappingURL=validate.js.map |
{ | ||
"name": "@statoscope/webpack-model", | ||
"version": "5.0.0", | ||
"version": "5.1.0-alpha.0", | ||
"description": "This package contains helpers to process webpack stats", | ||
"main": "./dist/index.js", | ||
"scripts": { | ||
"build": "../../node_modules/.bin/babel src -d dist" | ||
"build": "../../node_modules/.bin/tsc" | ||
}, | ||
@@ -18,3 +18,2 @@ "repository": "https://github.com/statoscope/statoscope.git", | ||
"files": [ | ||
"schema/*", | ||
"dist/*" | ||
@@ -29,3 +28,6 @@ ], | ||
}, | ||
"gitHead": "989f5733a477d2827f9e1fd670125cde277b5819" | ||
"devDependencies": { | ||
"@types/md5": "^2.3.0" | ||
}, | ||
"gitHead": "06db3ad9799680a03da119197203ea5131ff146c" | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
106840
46
1760
1
1
1