@afterpack/protection-map 0.1.0 → 0.2.0-rc.20260930T1421

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
1
  # @afterpack/protection-map
2
2
 
3
3
  The viewer for the [AfterPack](https://www.afterpack.dev) Protection Map: a single HTML file that
4
- shows your original source, shaded by how strongly each part was protected, with the weak spots a
5
- build left readable.
4
+ shows your original source, shaded by how much transformation each part went through, with the weak
5
+ spots a build left readable.
6
6
 
7
7
  You usually do not need to install this package. The AfterPack CLI and every AfterPack plugin
8
8
  already use it to write `.afterpack/protectionMap.html` when your build has source maps. Open that
@@ -12,7 +12,8 @@ or off, and [`protectionMap.detailed`](https://www.afterpack.dev/docs/config#pro
12
12
  set to `false` leaves out the per-region list of transformations for a smaller file.
13
13
 
14
14
  The Protection Map contains your original source. Keep it local: never deploy, publish or commit
15
- it. The AfterPack tools add `.afterpack/` to your `.gitignore` for you.
15
+ it. AfterPack tools write it under `.afterpack/`, which carries its own `.gitignore` and
16
+ self-ignores.
16
17
 
17
18
  ## Render one yourself
18
19
 
package/codec.mjs CHANGED
@@ -41,7 +41,15 @@ const SPOTLIGHT_COLUMNS = [
41
41
  "proHint",
42
42
  "reversalClass",
43
43
  ];
44
- const LINEAGE_COLUMNS = ["transform", "category", "phase", "entropyGain", "sizeDeltaEst", "label"];
44
+ const LINEAGE_COLUMNS = [
45
+ "transform",
46
+ "category",
47
+ "phase",
48
+ "entropyGain",
49
+ "credit",
50
+ "sizeDeltaEst",
51
+ "label",
52
+ ];
45
53
 
46
54
  function regionScalar(r, col) {
47
55
  switch (col) {
@@ -163,6 +171,7 @@ export function encodeCompact(data, { includeLineage = true } = {}) {
163
171
  intern("category", st.category),
164
172
  intern("phase", st.phase),
165
173
  st.entropyGain,
174
+ st.credit == null ? 0 : st.credit,
166
175
  st.sizeDeltaEst,
167
176
  st.label == null ? null : st.label,
168
177
  ]);
@@ -194,6 +203,10 @@ export function encodeCompact(data, { includeLineage = true } = {}) {
194
203
  aggregate: fdoc.aggregate,
195
204
  ...(fdoc.renamedSpans?.length ? { renamedSpans: fdoc.renamedSpans } : {}),
196
205
  ...(fdoc.extractedSpans?.length ? { extractedSpans: fdoc.extractedSpans } : {}),
206
+ ...(fdoc.complexitySpans?.length ? { complexitySpans: fdoc.complexitySpans } : {}),
207
+ ...(fdoc.declarationSpans?.length
208
+ ? { declarationKinds: fdoc.declarationKinds, declarationSpans: fdoc.declarationSpans }
209
+ : {}),
197
210
  };
198
211
  });
199
212
 
@@ -207,6 +220,7 @@ export function encodeCompact(data, { includeLineage = true } = {}) {
207
220
  ...(data && data.spanUnits !== undefined ? { spanUnits: data.spanUnits } : {}),
208
221
  generatedAt: data && data.generatedAt !== undefined ? data.generatedAt : null,
209
222
  engine: data && data.engine !== undefined ? data.engine : null,
223
+ ...(data && data.totals !== undefined ? { totals: data.totals } : {}),
210
224
  legend,
211
225
  dict: prunedDict,
212
226
  columns: { region: REGION_COLUMNS, spotlight: SPOTLIGHT_COLUMNS, lineage: LINEAGE_COLUMNS },
@@ -277,6 +291,9 @@ function afterpackDecodeDocument(c) {
277
291
  aggregate: fc.aggregate,
278
292
  renamedSpans: fc.renamedSpans || [],
279
293
  extractedSpans: fc.extractedSpans || [],
294
+ complexitySpans: fc.complexitySpans || [],
295
+ declarationKinds: fc.declarationKinds || [],
296
+ declarationSpans: fc.declarationSpans || [],
280
297
  };
281
298
  });
282
299
 
@@ -285,6 +302,7 @@ function afterpackDecodeDocument(c) {
285
302
  ...(c.spanUnits !== undefined ? { spanUnits: c.spanUnits } : {}),
286
303
  generatedAt: c.generatedAt !== undefined ? c.generatedAt : null,
287
304
  engine: c.engine !== undefined ? c.engine : null,
305
+ ...(c.totals !== undefined ? { totals: c.totals } : {}),
288
306
  files,
289
307
  };
290
308
  }
package/index.d.ts CHANGED
@@ -11,6 +11,10 @@ export interface ProtectionMap {
11
11
  complexity: number;
12
12
  [key: string]: unknown;
13
13
  };
14
+ totals?: {
15
+ userCode: { regions: number; transforms: number; protectedRegions: number };
16
+ machinery: { regions: number; transforms: number };
17
+ };
14
18
  files: ProtectionMapFile[];
15
19
  }
16
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afterpack/protection-map",
3
- "version": "0.1.0",
3
+ "version": "0.2.0-rc.20260930T1421",
4
4
  "description": "AfterPack Protection Map viewer: render protection data into a self-contained HTML report",
5
5
  "type": "module",
6
6
  "main": "./index.mjs",
package/render-core.mjs CHANGED
@@ -3,7 +3,8 @@ import { createRequire } from "node:module";
3
3
  import { gzipSync } from "node:zlib";
4
4
  import { encodeCompact } from "./codec.mjs";
5
5
 
6
- export const LINEAGE_EMBED_CAP = 20;
6
+ export const LINEAGE_EMBED_CAP = 200;
7
+ export const LINEAGE_TOTAL_BUDGET = 20000;
7
8
  export const PLACEHOLDER = "__AFTERPACK_DATA__";
8
9
 
9
10
  export function defaultTemplatePath() {
@@ -22,15 +23,19 @@ export function normalizeToFiles(raw) {
22
23
  export function capLineage(data) {
23
24
  let cappedRegions = 0;
24
25
  let totalLineageStepsRemoved = 0;
26
+ let remaining = LINEAGE_TOTAL_BUDGET;
25
27
  for (const fileDoc of data.files || []) {
26
28
  for (const region of fileDoc?.regions || []) {
27
- if (Array.isArray(region.lineage) && region.lineage.length > LINEAGE_EMBED_CAP) {
28
- const originalLength = region.lineage.length;
29
- region.lineage = region.lineage.slice(0, LINEAGE_EMBED_CAP);
29
+ if (!Array.isArray(region.lineage)) continue;
30
+ const originalLength = region.lineage.length;
31
+ const allow = Math.min(LINEAGE_EMBED_CAP, Math.max(0, remaining));
32
+ if (originalLength > allow) {
33
+ region.lineage = region.lineage.slice(0, allow);
30
34
  region.lineageCapped = originalLength;
31
35
  cappedRegions += 1;
32
- totalLineageStepsRemoved += originalLength - LINEAGE_EMBED_CAP;
36
+ totalLineageStepsRemoved += originalLength - allow;
33
37
  }
38
+ remaining -= region.lineage.length;
34
39
  }
35
40
  }
36
41
  return { cappedRegions, totalLineageStepsRemoved };