rollup-plugin-visualizer
Advanced tools
Comparing version 5.4.1 to 5.5.0
# Changelog | ||
## 5.5.0 | ||
* Refactor internal data structures to optimise perfomance | ||
## 5.4.1 | ||
@@ -4,0 +8,0 @@ |
@@ -52,5 +52,4 @@ #!/usr/bin/env node | ||
}; | ||
const nodes = {}; | ||
const nodeParts = {}; | ||
let links = []; | ||
const nodeMetas = {}; | ||
for (const { file, data } of fileContents) { | ||
@@ -67,5 +66,4 @@ if (data.version !== version_1.version) { | ||
} | ||
Object.assign(nodes, data.nodes); | ||
Object.assign(nodeParts, data.nodeParts); | ||
links = links.concat(data.links); | ||
Object.assign(nodeMetas, data.nodeMetas); | ||
} | ||
@@ -75,5 +73,4 @@ const data = { | ||
tree, | ||
links, | ||
nodes, | ||
nodeParts, | ||
nodeMetas, | ||
env: fileContents[0].data.env, | ||
@@ -80,0 +77,0 @@ options: fileContents[0].data.options, |
import { GetModuleInfo } from "rollup"; | ||
import { ModuleLink, ModuleRenderInfo, ModuleTree, ModuleTreeLeaf } from "../types/types"; | ||
import { ModuleLengths, ModuleTree, ModuleTreeLeaf } from "../types/types"; | ||
import { ModuleMapper } from "./module-mapper"; | ||
export declare const buildTree: (bundleId: string, modules: Array<ModuleRenderInfo>, mapper: ModuleMapper) => ModuleTree; | ||
export declare const buildTree: (bundleId: string, modules: Array<ModuleLengths & { | ||
id: string; | ||
}>, mapper: ModuleMapper) => ModuleTree; | ||
export declare const mergeTrees: (trees: Array<ModuleTree | ModuleTreeLeaf>) => ModuleTree; | ||
export declare const addLinks: (bundleId: string, startModuleId: string, getModuleInfo: GetModuleInfo, links: ModuleLink[], mapper: ModuleMapper) => void; | ||
export declare const addLinks: (startModuleId: string, getModuleInfo: GetModuleInfo, mapper: ModuleMapper) => void; |
@@ -59,3 +59,3 @@ "use strict"; | ||
for (const { id, renderedLength, gzipLength, brotliLength } of modules) { | ||
const bundleModuleUid = mapper.setValue(bundleId, id, { renderedLength, gzipLength, brotliLength }); | ||
const bundleModuleUid = mapper.setNodePart(bundleId, id, { renderedLength, gzipLength, brotliLength }); | ||
const trimmedModuleId = mapper.trimProjectRootId(id); | ||
@@ -85,3 +85,3 @@ const pathParts = trimmedModuleId.split(/\\|\//).filter((p) => p !== ""); | ||
exports.mergeTrees = mergeTrees; | ||
const addLinks = (bundleId, startModuleId, getModuleInfo, links, mapper) => { | ||
const addLinks = (startModuleId, getModuleInfo, mapper) => { | ||
const processedNodes = {}; | ||
@@ -98,5 +98,2 @@ const moduleIds = [startModuleId]; | ||
const moduleInfo = getModuleInfo(moduleId); | ||
if (!mapper.hasValue(bundleId, moduleId)) { | ||
mapper.setValue(bundleId, moduleId, { renderedLength: 0 }); | ||
} | ||
if (!moduleInfo) { | ||
@@ -106,16 +103,15 @@ return; | ||
if (moduleInfo.isEntry) { | ||
mapper.appendValue(bundleId, moduleId, { isEntry: true }); | ||
mapper.setNodeMeta(moduleId, { isEntry: true }); | ||
} | ||
if (moduleInfo.isExternal) { | ||
mapper.appendValue(bundleId, moduleId, { isExternal: true }); | ||
mapper.setNodeMeta(moduleId, { isExternal: true }); | ||
} | ||
const moduleUid = mapper.getModuleUid(moduleId); | ||
for (const importedId of moduleInfo.importedIds) { | ||
const importedUid = mapper.getModuleUid(importedId); | ||
links.push({ source: moduleUid, target: importedUid }); | ||
mapper.addImportedByLink(importedId, moduleId); | ||
mapper.addImportedLink(moduleId, importedId); | ||
moduleIds.push(importedId); | ||
} | ||
for (const importedId of moduleInfo.dynamicallyImportedIds) { | ||
const importedUid = mapper.getModuleUid(importedId); | ||
links.push({ source: moduleUid, target: importedUid, dynamic: true }); | ||
mapper.addImportedByLink(importedId, moduleId); | ||
mapper.addImportedLink(moduleId, importedId, true); | ||
moduleIds.push(importedId); | ||
@@ -122,0 +118,0 @@ } |
@@ -36,21 +36,9 @@ "use strict"; | ||
: defaultSizeGetter; | ||
const getAdditionalFilesInfo = async (code) => { | ||
const info = {}; | ||
if (gzipSize) { | ||
info.gzipLength = code == null || code == "" ? 0 : await gzipSizeGetter(code); | ||
} | ||
if (brotliSize) { | ||
info.brotliLength = code == null || code == "" ? 0 : await brotliSizeGetter(code); | ||
} | ||
return info; | ||
}; | ||
const renderedModuleToInfo = async (id, mod) => { | ||
const ModuleLengths = async ({ id, renderedLength, code, }) => { | ||
const result = { | ||
id, | ||
...mod, | ||
...(await getAdditionalFilesInfo(mod.code)), | ||
gzipLength: code == null || code == "" ? 0 : await gzipSizeGetter(code), | ||
brotliLength: code == null || code == "" ? 0 : await brotliSizeGetter(code), | ||
renderedLength: code == null || code == "" ? renderedLength : Buffer.byteLength(code, "utf-8"), | ||
}; | ||
if (mod.code != null) { | ||
result.renderedLength = Buffer.byteLength(mod.code, "utf-8"); | ||
} | ||
return result; | ||
@@ -67,3 +55,2 @@ }; | ||
const mapper = new module_mapper_1.ModuleMapper(projectRoot); | ||
const links = []; | ||
// collect trees | ||
@@ -82,3 +69,3 @@ for (const [bundleId, bundle] of Object.entries(outputBundle)) { | ||
const code = (_a = bundle.modules[id]) === null || _a === void 0 ? void 0 : _a.code; | ||
return renderedModuleToInfo(id, { renderedLength, code }); | ||
return ModuleLengths({ id, renderedLength, code }); | ||
})); | ||
@@ -88,13 +75,14 @@ tree = data_1.buildTree(bundleId, moduleRenderInfo, mapper); | ||
else { | ||
const modules = await Promise.all(Object.entries(bundle.modules).map(([id, mod]) => renderedModuleToInfo(id, mod))); | ||
const modules = await Promise.all(Object.entries(bundle.modules).map(([id, { renderedLength, code }]) => ModuleLengths({ id, renderedLength, code }))); | ||
tree = data_1.buildTree(bundleId, modules, mapper); | ||
} | ||
if (tree.children.length === 0) { | ||
const bundleInfo = await getAdditionalFilesInfo(bundle.code); | ||
const bundleSizes = { ...bundleInfo, renderedLength: bundle.code.length }; | ||
const bundleSizes = await ModuleLengths({ | ||
id: bundleId, | ||
renderedLength: bundle.code.length, | ||
code: bundle.code, | ||
}); | ||
const facadeModuleId = (_c = bundle.facadeModuleId) !== null && _c !== void 0 ? _c : `${bundleId}-unknown`; | ||
const bundleUid = mapper.setValue(bundleId, facadeModuleId, { | ||
isEntry: true, | ||
...bundleSizes, | ||
}); | ||
const bundleUid = mapper.setNodePart(bundleId, facadeModuleId, bundleSizes); | ||
mapper.setNodeMeta(facadeModuleId, { isEntry: true }); | ||
const leaf = { name: bundleId, uid: bundleUid }; | ||
@@ -108,6 +96,6 @@ roots.push(leaf); | ||
// after trees we process links (this is mostly for uids) | ||
for (const [bundleId, bundle] of Object.entries(outputBundle)) { | ||
for (const [, bundle] of Object.entries(outputBundle)) { | ||
if (bundle.type !== "chunk" || bundle.facadeModuleId == null) | ||
continue; //only chunks | ||
data_1.addLinks(bundleId, bundle.facadeModuleId, this.getModuleInfo.bind(this), links, mapper); | ||
data_1.addLinks(bundle.facadeModuleId, this.getModuleInfo.bind(this), mapper); | ||
} | ||
@@ -118,5 +106,4 @@ const tree = data_1.mergeTrees(roots); | ||
tree, | ||
nodes: mapper.getNodes(), | ||
nodeParts: mapper.getNodeParts(), | ||
links, | ||
nodeMetas: mapper.getNodeMetas(), | ||
env: { | ||
@@ -123,0 +110,0 @@ rollup: this.meta.rollupVersion, |
@@ -1,6 +0,6 @@ | ||
import { ModuleRenderInfo, ModuleUID } from "../types/types"; | ||
import { ModuleMeta, ModuleLengths, ModuleUID } from "../types/types"; | ||
export declare class ModuleMapper { | ||
private projectRoot; | ||
private nodes; | ||
private nodeIds; | ||
private nodeParts; | ||
private nodeMetas; | ||
constructor(projectRoot: string | RegExp); | ||
@@ -10,7 +10,12 @@ trimProjectRootId(moduleId: string): string; | ||
getBundleModuleUid(bundleId: string, moduleId: string): ModuleUID; | ||
setValue(bundleId: string, moduleId: string, value: Omit<ModuleRenderInfo, "id">): ModuleUID; | ||
appendValue(bundleId: string, moduleId: string, value: Partial<Omit<ModuleRenderInfo, "id">>): ModuleUID; | ||
hasValue(bundleId: string, moduleId: string): boolean; | ||
getNodes(): ModuleMapper["nodes"]; | ||
getNodeParts(): Record<ModuleUID, Record<string, ModuleUID>>; | ||
setNodePart(bundleId: string, moduleId: string, value: ModuleLengths): ModuleUID; | ||
setNodeMeta(moduleId: string, value: { | ||
isEntry?: boolean; | ||
isExternal?: boolean; | ||
}): void; | ||
hasNodePart(bundleId: string, moduleId: string): boolean; | ||
getNodeParts(): ModuleMapper["nodeParts"]; | ||
getNodeMetas(): Record<ModuleUID, ModuleMeta>; | ||
addImportedByLink(targetId: string, sourceId: string): void; | ||
addImportedLink(sourceId: string, targetId: string, dynamic?: boolean): void; | ||
} |
@@ -12,4 +12,4 @@ "use strict"; | ||
this.projectRoot = projectRoot; | ||
this.nodes = {}; | ||
this.nodeIds = {}; | ||
this.nodeParts = {}; | ||
this.nodeMetas = {}; | ||
} | ||
@@ -20,49 +20,86 @@ trimProjectRootId(moduleId) { | ||
getModuleUid(moduleId) { | ||
if (!(moduleId in this.nodeIds)) { | ||
this.nodeIds[moduleId] = { bundles: {}, uid: uniqueId() }; | ||
if (!(moduleId in this.nodeMetas)) { | ||
this.nodeMetas[moduleId] = { | ||
uid: uniqueId(), | ||
meta: { id: this.trimProjectRootId(moduleId), moduleParts: {}, imported: new Set(), importedBy: new Set() }, | ||
}; | ||
} | ||
return this.nodeIds[moduleId].uid; | ||
return this.nodeMetas[moduleId].uid; | ||
} | ||
getBundleModuleUid(bundleId, moduleId) { | ||
if (!(moduleId in this.nodeIds)) { | ||
this.nodeIds[moduleId] = { bundles: {}, uid: uniqueId() }; | ||
if (!(moduleId in this.nodeMetas)) { | ||
this.nodeMetas[moduleId] = { | ||
uid: uniqueId(), | ||
meta: { id: this.trimProjectRootId(moduleId), moduleParts: {}, imported: new Set(), importedBy: new Set() }, | ||
}; | ||
} | ||
if (!(bundleId in this.nodeIds[moduleId].bundles)) { | ||
this.nodeIds[moduleId].bundles[bundleId] = uniqueId(); | ||
if (!(bundleId in this.nodeMetas[moduleId].meta.moduleParts)) { | ||
this.nodeMetas[moduleId].meta.moduleParts[bundleId] = uniqueId(); | ||
} | ||
return this.nodeIds[moduleId].bundles[bundleId]; | ||
return this.nodeMetas[moduleId].meta.moduleParts[bundleId]; | ||
} | ||
setValue(bundleId, moduleId, value) { | ||
setNodePart(bundleId, moduleId, value) { | ||
const uid = this.getBundleModuleUid(bundleId, moduleId); | ||
if (uid in this.nodes) { | ||
throw new Error(`Override module: bundle id ${bundleId}, module id ${moduleId}, value ${JSON.stringify(value)}, existing value: ${JSON.stringify(this.nodes[uid])}`); | ||
if (uid in this.nodeParts) { | ||
throw new Error(`Override module: bundle id ${bundleId}, module id ${moduleId}, value ${JSON.stringify(value)}, existing value: ${JSON.stringify(this.nodeParts[uid])}`); | ||
} | ||
const id = this.trimProjectRootId(moduleId); | ||
this.nodes[uid] = { ...value, id }; | ||
this.nodeParts[uid] = { ...value, mainUid: this.getModuleUid(moduleId) }; | ||
return uid; | ||
} | ||
appendValue(bundleId, moduleId, value) { | ||
const uid = this.getBundleModuleUid(bundleId, moduleId); | ||
if (!(uid in this.nodes)) { | ||
throw new Error(`Missing module: bundle id ${bundleId}, module id ${moduleId}, value ${JSON.stringify(value)}`); | ||
setNodeMeta(moduleId, value) { | ||
this.getModuleUid(moduleId); | ||
this.nodeMetas[moduleId].meta.isEntry = value.isEntry; | ||
this.nodeMetas[moduleId].meta.isExternal = value.isExternal; | ||
} | ||
hasNodePart(bundleId, moduleId) { | ||
if (!(moduleId in this.nodeMetas)) { | ||
return false; | ||
} | ||
const id = this.trimProjectRootId(moduleId); | ||
this.nodes[uid] = { ...this.nodes[uid], ...value, id }; | ||
return uid; | ||
if (!(bundleId in this.nodeMetas[moduleId].meta.moduleParts)) { | ||
return false; | ||
} | ||
if (!(this.nodeMetas[moduleId].meta.moduleParts[bundleId] in this.nodeParts)) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
hasValue(bundleId, moduleId) { | ||
var _a, _b, _c; | ||
return !!((_c = (_b = (_a = this.nodeIds) === null || _a === void 0 ? void 0 : _a[moduleId]) === null || _b === void 0 ? void 0 : _b.bundles) === null || _c === void 0 ? void 0 : _c[bundleId]); | ||
getNodeParts() { | ||
return this.nodeParts; | ||
} | ||
getNodes() { | ||
return this.nodes; | ||
} | ||
getNodeParts() { | ||
const nodeParts = {}; | ||
for (const nodeId of Object.values(this.nodeIds)) { | ||
nodeParts[nodeId.uid] = nodeId.bundles; | ||
getNodeMetas() { | ||
const nodeMetas = {}; | ||
for (const { uid, meta } of Object.values(this.nodeMetas)) { | ||
nodeMetas[uid] = { | ||
...meta, | ||
imported: [...meta.imported].map((rawImport) => { | ||
const [uid, dynamic] = rawImport.split(","); | ||
const importData = { uid }; | ||
if (dynamic === "true") { | ||
importData.dynamic = true; | ||
} | ||
return importData; | ||
}), | ||
importedBy: [...meta.importedBy].map((rawImport) => { | ||
const [uid, dynamic] = rawImport.split(","); | ||
const importData = { uid }; | ||
if (dynamic === "true") { | ||
importData.dynamic = true; | ||
} | ||
return importData; | ||
}), | ||
}; | ||
} | ||
return nodeParts; | ||
return nodeMetas; | ||
} | ||
addImportedByLink(targetId, sourceId) { | ||
const sourceUid = this.getModuleUid(sourceId); | ||
this.getModuleUid(targetId); | ||
this.nodeMetas[targetId].meta.importedBy.add(sourceUid); | ||
} | ||
addImportedLink(sourceId, targetId, dynamic = false) { | ||
const targetUid = this.getModuleUid(targetId); | ||
this.getModuleUid(sourceId); | ||
this.nodeMetas[sourceId].meta.imported.add(String([targetUid, dynamic])); | ||
} | ||
} | ||
exports.ModuleMapper = ModuleMapper; |
export declare type SizeKey = "renderedLength" | "gzipLength" | "brotliLength"; | ||
export declare const isModuleTree: (mod: ModuleTree | ModuleTreeLeaf) => mod is ModuleTree; | ||
export declare type ModuleUID = string; | ||
export declare type BundleId = string; | ||
export interface ModuleTreeLeaf { | ||
@@ -12,23 +13,27 @@ name: string; | ||
} | ||
export declare type ModuleRenderInfo = { | ||
id: string; | ||
export declare type ModulePart = { | ||
mainUid: ModuleUID; | ||
} & ModuleLengths; | ||
export declare type ModuleImport = { | ||
uid: ModuleUID; | ||
dynamic?: boolean; | ||
}; | ||
export declare type ModuleMeta = { | ||
moduleParts: Record<BundleId, ModuleUID>; | ||
importedBy: ModuleImport[]; | ||
imported: ModuleImport[]; | ||
isEntry?: boolean; | ||
isExternal?: boolean; | ||
} & ModuleRenderSizes; | ||
export interface ModuleRenderSizes { | ||
id: string; | ||
}; | ||
export interface ModuleLengths { | ||
renderedLength: number; | ||
gzipLength?: number; | ||
brotliLength?: number; | ||
gzipLength: number; | ||
brotliLength: number; | ||
} | ||
export interface ModuleLink { | ||
source: ModuleUID; | ||
target: ModuleUID; | ||
dynamic?: boolean; | ||
} | ||
export interface VisualizerData { | ||
version: number; | ||
tree: ModuleTree; | ||
nodes: Record<ModuleUID, ModuleRenderInfo>; | ||
nodeParts: Record<ModuleUID, Record<string, ModuleUID>>; | ||
links: ModuleLink[]; | ||
nodeParts: Record<ModuleUID, ModulePart>; | ||
nodeMetas: Record<ModuleUID, ModuleMeta>; | ||
env: { | ||
@@ -35,0 +40,0 @@ [key: string]: unknown; |
{ | ||
"name": "rollup-plugin-visualizer", | ||
"version": "5.4.1", | ||
"version": "5.5.0", | ||
"main": "./dist/plugin/index.js", | ||
@@ -64,4 +64,4 @@ "author": "Denis Bardadym <bardadymchik@gmail.com>", | ||
"del-cli": "^3.0.1", | ||
"eslint": "^7.24.0", | ||
"eslint-config-prettier": "^8.2.0", | ||
"eslint": "^7.25.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-import": "^2.22.1", | ||
@@ -72,10 +72,10 @@ "eslint-plugin-prettier": "^3.4.0", | ||
"npm-run-all": "^4.1.5", | ||
"postcss": "^8.2.10", | ||
"postcss": "^8.2.13", | ||
"postcss-url": "^10.1.3", | ||
"preact": "^10.5.13", | ||
"prettier": "^2.2.1", | ||
"rollup": "^2.45.2", | ||
"rollup": "^2.46.0", | ||
"rollup-plugin-postcss": "^4.0.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"sass": "^1.32.10", | ||
"sass": "^1.32.12", | ||
"typescript": "^4.2.4", | ||
@@ -82,0 +82,0 @@ "webcola": "^3.4.0" |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
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
13310
2013787