MCPcopy Create free account
hub / github.com/btd/rollup-plugin-visualizer / encodeReport

Function encodeReport

shared/share/codec.ts:161–275  ·  view source on GitHub ↗
(
  input: ShareReportInput,
  overrides: Partial<ShareLimits> = {},
)

Source from the content-addressed store, hash-verified

159};
160
161export const encodeReport = (
162 input: ShareReportInput,
163 overrides: Partial<ShareLimits> = {},
164): Uint8Array => {
165 const limits = resolveLimits(overrides),
166 data = validateReport(input.data, limits),
167 writer = new Writer(limits);
168 const title = input.title ?? "Rollup Visualizer";
169 if (typeof title !== "string") return invalid("Invalid report title.");
170 const metas = Object.entries(data.nodeMetas),
171 parts = Object.entries(data.nodeParts);
172 const moduleRows = index(metas.map(([uid]) => uid)),
173 partRows = index(parts.map(([uid]) => uid));
174 const recipe = treeRecipe(data, limits),
175 tree = recipe ? [] : flatten(data.tree);
176 const strings = [
177 ...new Set([
178 ...metas.map(([, meta]) => meta.id),
179 ...metas.flatMap(([, meta]) => Object.keys(meta.moduleParts)),
180 ...(recipe ? [recipe.rootName, ...recipe.names] : tree.map((node) => node.name)),
181 ]),
182 ].toSorted();
183 budget(strings.length, limits.maxEntries, "String count");
184 const stringRows = index(strings);
185 const uids = [...new Set([...moduleRows.keys(), ...partRows.keys()])].toSorted((a, b) => {
186 const [ap, an] = decomposeUid(a),
187 [bp, bn] = decomposeUid(b);
188 if (ap !== bp) return ap < bp ? -1 : 1;
189 if (an === null || bn === null) return an === bn ? 0 : an === null ? -1 : 1;
190 return an - bn;
191 });
192 const uidRows = index(uids);
193 writer.text(title);
194 writer.uint(
195 Number(data.options.gzip) +
196 2 * Number(data.options.brotli) +
197 4 * Number(data.options.sourcemap),
198 );
199 writer.text(JSON.stringify(data.env));
200 writeStrings(writer, strings);
201 writeUids(writer, uids);
202 writer.vector(
203 metas.map(([uid]) => uidRows.get(uid)!),
204 true,
205 );
206 writer.vector(
207 metas.map(([, meta]) => stringRows.get(meta.id)!),
208 true,
209 );
210 writer.vector(
211 metas.map(([, meta]) => boolState(meta, "isEntry") + 4 * boolState(meta, "isExternal")),
212 );
213 writer.vector(metas.map(([, meta]) => Object.keys(meta.moduleParts).length));
214 const memberships = metas.flatMap(([, meta]) => Object.entries(meta.moduleParts));
215 writer.vector(memberships.map(([bundle]) => stringRows.get(bundle)!));
216 writer.vector(
217 memberships.map(([, uid]) => partRows.get(uid)!),
218 true,

Callers 3

createShareLinkFunction · 0.85
encodeFragmentFunction · 0.85

Calls 15

textMethod · 0.95
uintMethod · 0.95
vectorMethod · 0.95
bytesMethod · 0.95
finishMethod · 0.95
resolveLimitsFunction · 0.85
validateReportFunction · 0.85
invalidFunction · 0.85
indexFunction · 0.85
treeRecipeFunction · 0.85
flattenFunction · 0.85
budgetFunction · 0.85

Tested by

no test coverage detected