fgc-cell 0.0.0-stage → 0.1.0-preview.1
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/cell-compiler/src/artifact-assembly.js +159 -0
- package/cell-compiler/src/artifact-audits.js +444 -0
- package/cell-compiler/src/artifact.js +368 -0
- package/cell-compiler/src/auto-height.js +462 -0
- package/cell-compiler/src/build-cell-project.js +228 -0
- package/cell-compiler/src/cell-resources.js +382 -0
- package/cell-compiler/src/diagnostics.js +231 -0
- package/cell-compiler/src/entry.js +298 -0
- package/cell-compiler/src/extension-externals.js +424 -0
- package/cell-compiler/src/frontend-libraries.js +167 -0
- package/cell-compiler/src/guarantees.js +109 -0
- package/cell-compiler/src/host-bridge-diagnostics.js +66 -0
- package/cell-compiler/src/host-bridge-modules.js +357 -0
- package/cell-compiler/src/host-bridge-plan.js +319 -0
- package/cell-compiler/src/host-bridge.js +80 -0
- package/cell-compiler/src/index.js +23 -0
- package/cell-compiler/src/internal.js +102 -0
- package/cell-compiler/src/provenance.js +131 -0
- package/cell-compiler/src/registry-plan.js +81 -0
- package/cell-compiler/src/rolldown-bundler-hooks.js +422 -0
- package/cell-compiler/src/rolldown-bundler-report.js +245 -0
- package/cell-compiler/src/rolldown-bundler.js +456 -0
- package/cell-compiler/src/runtime-binding.js +203 -0
- package/cell-compiler/src/source-guard.js +298 -0
- package/cell-compiler/src/specifier.js +120 -0
- package/cell-compiler/src/workspace-graph.js +374 -0
- package/cell-compiler/src/workspace-source-audit.js +707 -0
- package/cell-compiler/src/workspace-source.js +448 -0
- package/cell-project/src/build.js +321 -0
- package/cell-project/src/cli.js +327 -0
- package/cell-project/src/compiled-cells.js +55 -0
- package/cell-project/src/index.js +52 -0
- package/cell-project/src/plan.js +250 -0
- package/cell-project/src/project.js +236 -0
- package/cell-project/src/sync.js +174 -0
- package/core/src/bindings-config.js +671 -0
- package/core/src/browser.js +99 -0
- package/core/src/build-failure.js +108 -0
- package/core/src/canonical.js +76 -0
- package/core/src/cell-assets.js +764 -0
- package/core/src/cell-bundler-options.js +102 -0
- package/core/src/cell-code-budget.js +451 -0
- package/core/src/cell-compile-fingerprint.js +52 -0
- package/core/src/cell-props.js +63 -0
- package/core/src/cell-registry.js +689 -0
- package/core/src/code-units.js +33 -0
- package/core/src/config-loader.js +179 -0
- package/core/src/diagnostics.js +108 -0
- package/core/src/extension-externals.js +823 -0
- package/core/src/extension-mappings-config.js +534 -0
- package/core/src/forguncy-config.js +171 -0
- package/core/src/governance.js +241 -0
- package/core/src/guards.js +24 -0
- package/core/src/host-bridge.js +793 -0
- package/core/src/index.js +19 -0
- package/core/src/internal.js +94 -0
- package/core/src/lock-canonical.js +157 -0
- package/core/src/lock-freshness.js +471 -0
- package/core/src/lock-types.js +316 -0
- package/core/src/lock-validate.js +668 -0
- package/core/src/ownership.js +139 -0
- package/core/src/platform-conflicts.js +226 -0
- package/core/src/portability.js +122 -0
- package/core/src/probe-protocol.js +907 -0
- package/core/src/provenance.js +39 -0
- package/core/src/rejection.js +107 -0
- package/core/src/resolve-config.js +454 -0
- package/core/src/runtime-contract.js +1512 -0
- package/core/src/selection-policy.js +689 -0
- package/core/src/selection-signals.js +598 -0
- package/core/src/specifier.js +31 -0
- package/core/src/strategy.js +311 -0
- package/dependency-resolver/src/decision-conformance.js +453 -0
- package/dependency-resolver/src/decision-recording.js +140 -0
- package/dependency-resolver/src/index.js +18 -0
- package/dependency-resolver/src/install-graph.js +186 -0
- package/dependency-resolver/src/install-identity/config-digests.js +223 -0
- package/dependency-resolver/src/install-identity/install-graph-identity.js +94 -0
- package/dependency-resolver/src/install-identity/link-targets.js +227 -0
- package/dependency-resolver/src/install-identity/lockfile-discovery.js +363 -0
- package/dependency-resolver/src/install-identity/npm-tree.js +64 -0
- package/dependency-resolver/src/install-identity/pnpm-tree.js +647 -0
- package/dependency-resolver/src/install-identity/primitives.js +239 -0
- package/dependency-resolver/src/install-identity/toolchain.js +70 -0
- package/dependency-resolver/src/install-identity.js +75 -0
- package/dependency-resolver/src/internal.js +96 -0
- package/dependency-resolver/src/local.js +75 -0
- package/dependency-resolver/src/lock-store.js +266 -0
- package/dependency-resolver/src/package-locator.js +224 -0
- package/dependency-resolver/src/probe/artifact-scan.js +216 -0
- package/dependency-resolver/src/probe/asset-inventory.js +151 -0
- package/dependency-resolver/src/probe/browser-entry.js +615 -0
- package/dependency-resolver/src/probe/build-configuration.js +40 -0
- package/dependency-resolver/src/probe/build.js +211 -0
- package/dependency-resolver/src/probe/cache-invalidation.js +214 -0
- package/dependency-resolver/src/probe/cache.js +99 -0
- package/dependency-resolver/src/probe/export-metadata.js +346 -0
- package/dependency-resolver/src/probe/fingerprint.js +178 -0
- package/dependency-resolver/src/probe/identity.js +261 -0
- package/dependency-resolver/src/probe/module-source-analysis.js +395 -0
- package/dependency-resolver/src/probe/module-source-reachability.js +400 -0
- package/dependency-resolver/src/probe/node-scan.js +647 -0
- package/dependency-resolver/src/probe/probe-engine.js +449 -0
- package/dependency-resolver/src/probe/runtime-pattern-scan.js +174 -0
- package/dependency-resolver/src/probe/scan-utils.js +112 -0
- package/dependency-resolver/src/probe/size.js +270 -0
- package/dev-harness/src/alias-audit.js +706 -0
- package/dev-harness/src/cell-assets.js +144 -0
- package/dev-harness/src/cell-plugin.js +199 -0
- package/dev-harness/src/extension-substitutions.js +380 -0
- package/dev-harness/src/host-modules.js +401 -0
- package/dev-harness/src/index.js +15 -0
- package/dev-harness/src/internal.js +90 -0
- package/dev-harness/src/local-decision-projection.js +320 -0
- package/dev-harness/src/local-dev-audit.js +277 -0
- package/dev-harness/src/loopback.js +87 -0
- package/dev-harness/src/mount.js +122 -0
- package/dev-harness/src/provenance.js +69 -0
- package/dev-harness/src/server-audit.js +135 -0
- package/dev-harness/src/temp-project.js +155 -0
- package/dev-harness/src/types.js +33 -0
- package/dev-harness/src/vite-config.js +198 -0
- package/dev-harness/src/vite-plugin.js +597 -0
- package/mcp-sync/src/bindings-sync.js +452 -0
- package/mcp-sync/src/capability-surface.js +764 -0
- package/mcp-sync/src/designer-transport.js +638 -0
- package/mcp-sync/src/diagnostics.js +328 -0
- package/mcp-sync/src/divergence.js +360 -0
- package/mcp-sync/src/executor.js +30 -0
- package/mcp-sync/src/extension-verification.js +105 -0
- package/mcp-sync/src/fingerprint.js +285 -0
- package/mcp-sync/src/guarantees.js +503 -0
- package/mcp-sync/src/index.js +19 -0
- package/mcp-sync/src/internal.js +85 -0
- package/mcp-sync/src/port.js +121 -0
- package/mcp-sync/src/provenance.js +83 -0
- package/mcp-sync/src/registry-target.js +159 -0
- package/mcp-sync/src/step-outcomes.js +78 -0
- package/mcp-sync/src/sync-batch.js +172 -0
- package/mcp-sync/src/sync-execution.js +482 -0
- package/mcp-sync/src/sync-failure.js +175 -0
- package/mcp-sync/src/sync-plan.js +378 -0
- package/mcp-sync/src/sync-report.js +79 -0
- package/mcp-sync/src/sync-run-steps.js +21 -0
- package/mcp-sync/src/sync-run.js +107 -0
- package/mcp-sync/src/target.js +69 -0
- package/package.json +18 -4
- package/runtime/src/capabilities.js +661 -0
- package/runtime/src/cell-fixture.js +220 -0
- package/runtime/src/cell-runtime.js +671 -0
- package/runtime/src/cell.js +21 -0
- package/runtime/src/contract.js +281 -0
- package/runtime/src/facade-types.js +35 -0
- package/runtime/src/facade.js +402 -0
- package/runtime/src/host-globals.js +30 -0
- package/runtime/src/host-provider.js +131 -0
- package/runtime/src/index.js +23 -0
- package/runtime/src/internal.js +99 -0
- package/runtime/src/local-dev-audit.js +245 -0
- package/runtime/src/local-dev-claims.js +232 -0
- package/runtime/src/local-dev-diagnostics.js +123 -0
- package/runtime/src/local-dev-host-modules.js +603 -0
- package/runtime/src/local-dev.js +595 -0
- package/runtime/src/mock-provider.js +394 -0
- package/runtime/src/port.js +33 -0
- package/runtime/src/provenance.js +97 -0
- package/runtime/src/provider.js +423 -0
- package/README.md +0 -3
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Turns a bundler report into a Cell artifact — the assembly half of the boundary.
|
|
3
|
+
*
|
|
4
|
+
* Decision source: GitHub Issue #6 — "Spec: generated ReactCellType artifact and
|
|
5
|
+
* compiler boundary"
|
|
6
|
+
* (https://github.com/Mang-X/forguncy-react-workspace/issues/6). The artifact audits
|
|
7
|
+
* live in `artifact-audits.ts`, and the `compileCell` orchestration that calls this
|
|
8
|
+
* assembly lives in `artifact.ts`.
|
|
9
|
+
*
|
|
10
|
+
* Split out of `artifact.ts` by #162, under the shape-stabilisation Spec #152.
|
|
11
|
+
*/
|
|
12
|
+
import { CELL_RUNTIME_BINDING_CONTRACT } from "../../core/src/index.js";
|
|
13
|
+
import { artifactOriginOf, auditArtifactSource, auditCodeBudget, auditDependencyDecisions, auditEmittedAssets, auditExternalImports, auditInlinedPackages, auditInlinedResourceUrls, } from "./artifact-audits.js";
|
|
14
|
+
import { renderAutoHeightInjection } from "./auto-height.js";
|
|
15
|
+
import { cellResourcesNeedStyleInstaller, renderCellStyleInstaller } from "./cell-resources.js";
|
|
16
|
+
import { dedupeCellArtifactDiagnostics } from "./diagnostics.js";
|
|
17
|
+
import { renderCellEntryWrapper } from "./entry.js";
|
|
18
|
+
import { auditFrontendLibraries, collectFrontendLibraries } from "./frontend-libraries.js";
|
|
19
|
+
/**
|
|
20
|
+
* The first line of every artifact.
|
|
21
|
+
*
|
|
22
|
+
* Fixed text, no timestamp and no tool version: #6 permits a non-deterministic
|
|
23
|
+
* banner only if it is documented, and documenting one that does not exist would
|
|
24
|
+
* be worse than emitting none. It states #6's source-of-truth rule because the
|
|
25
|
+
* banner is the one place a person reading designer-held code will see it.
|
|
26
|
+
*/
|
|
27
|
+
export const CELL_ARTIFACT_BANNER = "/* Generated by @forguncy-react-workspace/cell-compiler. Do not edit: repository source is authoritative, this is deployment output. */";
|
|
28
|
+
/**
|
|
29
|
+
* The artifact a compile produced, with whatever per-package attribution the bundler reported.
|
|
30
|
+
*
|
|
31
|
+
* One constructor for both outcomes, so the compiled and rejected paths cannot hand back documents
|
|
32
|
+
* that differ in anything but the diagnostics.
|
|
33
|
+
*/
|
|
34
|
+
function artifactOf(code, frontendLibraries, module) {
|
|
35
|
+
return {
|
|
36
|
+
code,
|
|
37
|
+
frontendLibraries,
|
|
38
|
+
...(module.inlinedPackageSizes === undefined ? {} : { inlinedPackageSizes: module.inlinedPackageSizes }),
|
|
39
|
+
...(module.resources === undefined ? {} : { inlinedResources: module.resources }),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Turns a bundler report into a Cell artifact, or refuses it with diagnostics.
|
|
44
|
+
*
|
|
45
|
+
* Checks run in a fixed order so the diagnostic list is itself deterministic —
|
|
46
|
+
* two runs over the same input cannot report the same problems in a different
|
|
47
|
+
* order, which matters because the list ends up in CI logs that get diffed.
|
|
48
|
+
*/
|
|
49
|
+
export function assembleCellArtifact(input) {
|
|
50
|
+
const { module, dependencies } = input;
|
|
51
|
+
const decisionDiagnostics = auditDependencyDecisions(dependencies);
|
|
52
|
+
const importDiagnostics = auditExternalImports(module.externalImports ?? [], dependencies);
|
|
53
|
+
const inlinedDiagnostics = auditInlinedPackages(module.inlinedPackages ?? [], dependencies, module.inlinedSpecifiers);
|
|
54
|
+
const assetDiagnostics = auditEmittedAssets(module.emittedAssets ?? []);
|
|
55
|
+
const collection = collectFrontendLibraries(dependencies);
|
|
56
|
+
const wrapper = renderCellEntryWrapper({
|
|
57
|
+
...(input.entryKind === undefined ? {} : { entryKind: input.entryKind }),
|
|
58
|
+
// The wrapper may only publish live props when the binding that declares the variable is
|
|
59
|
+
// in this artifact; the bundler's report is the only source that knows (#83).
|
|
60
|
+
runtimeBinding: module.runtimeBindingGenerated === true,
|
|
61
|
+
});
|
|
62
|
+
const wrapperSource = wrapper.status === "emitted" ? wrapper.source : "";
|
|
63
|
+
// The artifact-scope props variable, declared *outside* the bundle and *before* it (#83).
|
|
64
|
+
//
|
|
65
|
+
// This placement is the seam, and both halves are load-bearing:
|
|
66
|
+
//
|
|
67
|
+
// - **outside the bundle's IIFE**, because the binding module is inside it, the entry
|
|
68
|
+
// wrapper is beside it, and only a declaration at the artifact's own scope is visible to
|
|
69
|
+
// both. Declared inside the bundle, the wrapper could not assign to it; declared after
|
|
70
|
+
// it, the initial value would not be there when the module body installs the provider.
|
|
71
|
+
// - **only when a binding was generated**, because a façade-free artifact must not carry a
|
|
72
|
+
// name nothing uses — and a wrapper that assigned to an undeclared variable would be a
|
|
73
|
+
// `ReferenceError` at the first render, in strict mode, which every IIFE bundle is.
|
|
74
|
+
//
|
|
75
|
+
// `var` rather than a block-scoped declaration because the wrapper *reassigns* it, and the
|
|
76
|
+
// initial value is the evaluation's wrapper-local `props`, which is what keeps a
|
|
77
|
+
// `render-call` or `top-level-element-variable` shape working at all.
|
|
78
|
+
//
|
|
79
|
+
// Nothing here is a page global: a `var` in the platform's `new Function` body is a
|
|
80
|
+
// per-evaluation binding exactly as the provider slot is per copy.
|
|
81
|
+
const livePropsDeclaration = module.runtimeBindingGenerated === true && wrapper.status === "emitted"
|
|
82
|
+
? `var ${CELL_RUNTIME_BINDING_CONTRACT.livePropsVariable} = props;\n`
|
|
83
|
+
: "";
|
|
84
|
+
// The style installer (#98) goes before the bundle, beside the live-props declaration and for
|
|
85
|
+
// the same structural reason: the stylesheet modules are inside the bundle, and a `var` or
|
|
86
|
+
// `function` declaration at the artifact's own scope is the only thing both sides can see.
|
|
87
|
+
//
|
|
88
|
+
// Emitted only when a style was actually inlined. A Cell with no CSS must not carry a page-level
|
|
89
|
+
// registry it never reads, and the *decision* is the bundler's report rather than a search of
|
|
90
|
+
// `code` for a marker — a fixture port that reports no resources therefore gets the plain
|
|
91
|
+
// artifact, exactly as it gets no live-props declaration.
|
|
92
|
+
const styleInstaller = cellResourcesNeedStyleInstaller(module.resources ?? []) ? renderCellStyleInstaller() : "";
|
|
93
|
+
// The auto-height injection (#185) goes before the bundle too, but for a different reason than
|
|
94
|
+
// the two declarations above: it is not a shared binding, it is *earlier execution*. The patch
|
|
95
|
+
// is three timing-tolerant mechanisms (prototype wrap, repair pass, observer — see
|
|
96
|
+
// `auto-height.ts`), and artifact evaluation precedes the platform's own instantiation of this
|
|
97
|
+
// cell, so the primary path is served no matter where in the artifact the block sits. Before
|
|
98
|
+
// the bundle is still the deliberate choice: the injection is environment wiring in the same
|
|
99
|
+
// family as the host-provider install, a reviewer expects platform-shaping code ahead of the
|
|
100
|
+
// Cell's own, and an evaluation-time throw inside the bundle cannot then leave the patch
|
|
101
|
+
// unapplied — the failure ordering reads correctly in either direction.
|
|
102
|
+
//
|
|
103
|
+
// It is deliberately *not* a bundler interception: #82's binding reaches the artifact because
|
|
104
|
+
// a façade import pulls the virtual module in, while this patch must exist even in a Cell that
|
|
105
|
+
// never imports the façade — a façade-free artifact is still a ReactCellType cell with the
|
|
106
|
+
// same hardcoded container. Emitted once, here, the block is single by construction within one
|
|
107
|
+
// artifact; across artifacts and re-compiles the prototype guard carries idempotency.
|
|
108
|
+
const heightAdaptive = input.heightAdaptive ?? true;
|
|
109
|
+
const autoHeight = heightAdaptive ? renderAutoHeightInjection() : "";
|
|
110
|
+
const code = `${CELL_ARTIFACT_BANNER}\n${livePropsDeclaration}${styleInstaller}${autoHeight}${module.code}\n${wrapperSource}\n`;
|
|
111
|
+
// The origin arithmetic needs the prefix's real length, because the bundle no longer
|
|
112
|
+
// starts at "banner + newline" once a declaration, an installer or the injection sits
|
|
113
|
+
// between them — see `artifactOriginOf` for why the length travels rather than being
|
|
114
|
+
// re-derived.
|
|
115
|
+
const prefixLength = livePropsDeclaration.length + styleInstaller.length + autoHeight.length;
|
|
116
|
+
const sourceDiagnostics = auditArtifactSource(code, artifactOriginOf(module.code, prefixLength));
|
|
117
|
+
const budgetDiagnostics = auditCodeBudget(code, input.codeBudgetCharacters);
|
|
118
|
+
const metadataDiagnostics = auditFrontendLibraries(collection.libraries);
|
|
119
|
+
const resourceDiagnostics = auditInlinedResourceUrls(module.resources ?? []);
|
|
120
|
+
const diagnostics = dedupeCellArtifactDiagnostics([
|
|
121
|
+
// The bundler's own findings first: when one of them names the same
|
|
122
|
+
// condition an audit below also reports (an unmapped extension decision is
|
|
123
|
+
// visible both in the plan and in the output report), the build's more
|
|
124
|
+
// specific explanation — which can say *why* the mapping is unusable — is
|
|
125
|
+
// the one a reader keeps after deduplication.
|
|
126
|
+
...(module.diagnostics ?? []),
|
|
127
|
+
...decisionDiagnostics,
|
|
128
|
+
...importDiagnostics,
|
|
129
|
+
...inlinedDiagnostics,
|
|
130
|
+
...assetDiagnostics,
|
|
131
|
+
...resourceDiagnostics,
|
|
132
|
+
...collection.diagnostics,
|
|
133
|
+
...(wrapper.status === "emitted" ? [] : wrapper.diagnostics),
|
|
134
|
+
...sourceDiagnostics,
|
|
135
|
+
...budgetDiagnostics,
|
|
136
|
+
...metadataDiagnostics,
|
|
137
|
+
]);
|
|
138
|
+
// A wrapper that could not be emitted always contributes a diagnostic, so the
|
|
139
|
+
// second half of this test is redundant at runtime and present for the type
|
|
140
|
+
// system: it is what narrows `wrapper` to the emitted case below.
|
|
141
|
+
if (diagnostics.length > 0 || wrapper.status !== "emitted") {
|
|
142
|
+
// The composed source travels with the rejection: the diagnostics are *about* this document, and
|
|
143
|
+
// a caller recording a size verdict has to identify the artifact the verdict measured rather
|
|
144
|
+
// than a re-derivation of it. A wrapper that could not be emitted leaves the code incomplete, so
|
|
145
|
+
// it is not handed back — there is no artifact, only a diagnostic saying why.
|
|
146
|
+
return {
|
|
147
|
+
status: "rejected",
|
|
148
|
+
diagnostics,
|
|
149
|
+
...(wrapper.status === "emitted"
|
|
150
|
+
? { artifact: artifactOf(code, collection.libraries, module) }
|
|
151
|
+
: {}),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
return {
|
|
155
|
+
status: "compiled",
|
|
156
|
+
artifact: artifactOf(code, collection.libraries, module),
|
|
157
|
+
entryKind: wrapper.kind,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The audits the artifact boundary runs over a bundler report and a composed Cell.
|
|
3
|
+
*
|
|
4
|
+
* Decision source: GitHub Issue #6 — "Spec: generated ReactCellType artifact and
|
|
5
|
+
* compiler boundary"
|
|
6
|
+
* (https://github.com/Mang-X/forguncy-react-workspace/issues/6). These checks decide
|
|
7
|
+
* whether a bundle is a legal Cell artifact; assembly and the `compileCell` orchestration
|
|
8
|
+
* that apply them stay in `artifact-assembly.ts` and `artifact.ts`.
|
|
9
|
+
*
|
|
10
|
+
* Split out of `artifact.ts` by #162, under the shape-stabilisation Spec #152.
|
|
11
|
+
*/
|
|
12
|
+
import { CELL_CODE_BUDGET_MEASUREMENT, CELL_USER_SCOPE_BINDINGS, assertCellCodeBudget, classifyCellCodeSize, validateDependencyDecisionShape, } from "../../core/src/index.js";
|
|
13
|
+
import { CELL_ARTIFACT_BANNER } from "./artifact-assembly.js";
|
|
14
|
+
import { createCellArtifactDiagnostic } from "./diagnostics.js";
|
|
15
|
+
import { findDependencyDecision, isSourceSpecifier, packageNameOfSpecifier } from "./specifier.js";
|
|
16
|
+
import { auditCellSource } from "./source-guard.js";
|
|
17
|
+
// The specifier primitives (`specifier.ts`) and the resource ledger (`cell-resources.ts`) are
|
|
18
|
+
// imported here and *not* re-exported (#157). They used to be forwarded "so a caller that imported
|
|
19
|
+
// them from here keeps working", and no such caller exists: the barrel names them from their own
|
|
20
|
+
// modules, and every consumer inside this package imports the defining module. A second door into
|
|
21
|
+
// the same four functions is one more name to keep in step, for nobody.
|
|
22
|
+
/**
|
|
23
|
+
* The bindings a `host` dependency may be mapped onto.
|
|
24
|
+
*
|
|
25
|
+
* `injected-parameter` are the `new Function` arguments the runtime passes, and
|
|
26
|
+
* `page-global` are page-level names such as `ReactDOM` the runtime itself uses.
|
|
27
|
+
* `wrapper-local` and `extension-global` are deliberately absent: the first is
|
|
28
|
+
* created inside the cell's own generated closure, the second belongs to the
|
|
29
|
+
* `extension` strategy and reaching it as `host` would skip both the
|
|
30
|
+
* `libraryId` reference and the readiness guarantee.
|
|
31
|
+
*/
|
|
32
|
+
const HOST_IDENTITY_KINDS = ["injected-parameter", "page-global"];
|
|
33
|
+
function subjectOf(decision) {
|
|
34
|
+
return decision.packageName.trim().length > 0 ? decision.packageName : "<unnamed package>";
|
|
35
|
+
}
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
// Decision audit
|
|
38
|
+
// ---------------------------------------------------------------------------
|
|
39
|
+
/**
|
|
40
|
+
* Audits the decision list itself.
|
|
41
|
+
*
|
|
42
|
+
* The shape checks come from `core` rather than being reimplemented: a decision
|
|
43
|
+
* record that is internally inconsistent is #4's problem, and the compiler's only
|
|
44
|
+
* job is to translate that verdict into a code the artifact-level report can
|
|
45
|
+
* branch on. The translation is per strategy because the fix differs — an
|
|
46
|
+
* extension with no global is a mapping problem, a host with no global is a
|
|
47
|
+
* mapping problem of a different kind, and a replacement with no recorded
|
|
48
|
+
* rejection is an unresolved decision.
|
|
49
|
+
*/
|
|
50
|
+
export function auditDependencyDecisions(dependencies) {
|
|
51
|
+
const diagnostics = [];
|
|
52
|
+
const byPackage = new Map();
|
|
53
|
+
for (const decision of dependencies) {
|
|
54
|
+
const name = decision.packageName;
|
|
55
|
+
const existing = byPackage.get(name);
|
|
56
|
+
if (existing === undefined)
|
|
57
|
+
byPackage.set(name, [decision]);
|
|
58
|
+
else
|
|
59
|
+
existing.push(decision);
|
|
60
|
+
}
|
|
61
|
+
for (const [packageName, decisions] of byPackage) {
|
|
62
|
+
if (decisions.length > 1 && packageName.trim().length > 0) {
|
|
63
|
+
diagnostics.push(createCellArtifactDiagnostic("unresolved-dependency-decision", packageName, {
|
|
64
|
+
detail: `${decisions.length} decisions target this package (${decisions.map(item => item.strategy).join(", ")}), so there is no single strategy to compile against.`,
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
for (const decision of dependencies) {
|
|
69
|
+
const subject = subjectOf(decision);
|
|
70
|
+
for (const problem of validateDependencyDecisionShape(decision)) {
|
|
71
|
+
diagnostics.push(createCellArtifactDiagnostic(diagnosticCodeForStrategy(decision.strategy), subject, { detail: problem }));
|
|
72
|
+
}
|
|
73
|
+
if (decision.strategy === "host") {
|
|
74
|
+
const binding = CELL_USER_SCOPE_BINDINGS.find(candidate => candidate.name === decision.globalName);
|
|
75
|
+
if (binding === undefined) {
|
|
76
|
+
diagnostics.push(createCellArtifactDiagnostic("duplicate-host-mapping", subject, {
|
|
77
|
+
detail: `The global "${decision.globalName}" is not one of the names the runtime contract verified as visible inside a cell, so the artifact would reference a global that may never exist.`,
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
else if (!HOST_IDENTITY_KINDS.includes(binding.kind)) {
|
|
81
|
+
// Being a verified *name* is not the same as being a runtime *identity*.
|
|
82
|
+
// `props`, `useState` and `render` are wrapper-locals the generated
|
|
83
|
+
// function creates per render, so mapping a dependency onto one would
|
|
84
|
+
// replace a module with something that does not exist outside this cell's
|
|
85
|
+
// own closure.
|
|
86
|
+
diagnostics.push(createCellArtifactDiagnostic("duplicate-host-mapping", subject, {
|
|
87
|
+
detail: `The global "${decision.globalName}" is verified inside a cell, but it is a "${binding.kind}" rather than a host runtime identity a dependency can be mapped onto.`,
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
diagnostics.push(...auditHostGlobalClaims(dependencies));
|
|
93
|
+
return diagnostics;
|
|
94
|
+
}
|
|
95
|
+
function diagnosticCodeForStrategy(strategy) {
|
|
96
|
+
switch (strategy) {
|
|
97
|
+
case "extension":
|
|
98
|
+
return "missing-extension-mapping";
|
|
99
|
+
case "host":
|
|
100
|
+
return "duplicate-host-mapping";
|
|
101
|
+
case "replace":
|
|
102
|
+
case "inline":
|
|
103
|
+
return "unresolved-dependency-decision";
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Reports two packages claiming one host global.
|
|
108
|
+
*
|
|
109
|
+
* Separate from the single-decision check because the problem is only visible
|
|
110
|
+
* across decisions: each record is valid on its own, and the artifact still ends
|
|
111
|
+
* up with one global serving two module identities.
|
|
112
|
+
*/
|
|
113
|
+
function auditHostGlobalClaims(dependencies) {
|
|
114
|
+
const diagnostics = [];
|
|
115
|
+
const claimants = new Map();
|
|
116
|
+
for (const decision of dependencies) {
|
|
117
|
+
if (decision.strategy !== "host")
|
|
118
|
+
continue;
|
|
119
|
+
const globalName = decision.globalName.trim();
|
|
120
|
+
if (globalName.length === 0)
|
|
121
|
+
continue;
|
|
122
|
+
const existing = claimants.get(globalName);
|
|
123
|
+
if (existing === undefined)
|
|
124
|
+
claimants.set(globalName, [decision.packageName]);
|
|
125
|
+
else if (!existing.includes(decision.packageName))
|
|
126
|
+
existing.push(decision.packageName);
|
|
127
|
+
}
|
|
128
|
+
for (const [globalName, packages] of claimants) {
|
|
129
|
+
if (packages.length > 1) {
|
|
130
|
+
diagnostics.push(createCellArtifactDiagnostic("duplicate-host-mapping", globalName, {
|
|
131
|
+
detail: `${packages.length} packages map to this host global (${packages.join(", ")}), so they would share one module identity.`,
|
|
132
|
+
}));
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return diagnostics;
|
|
136
|
+
}
|
|
137
|
+
// ---------------------------------------------------------------------------
|
|
138
|
+
// Bundler report audit
|
|
139
|
+
// ---------------------------------------------------------------------------
|
|
140
|
+
/**
|
|
141
|
+
* Reports every specifier the bundler left external.
|
|
142
|
+
*
|
|
143
|
+
* The decision, not the bundler, says what should have happened instead, so the
|
|
144
|
+
* diagnostic code is chosen from the strategy. This is the mapping that makes the
|
|
145
|
+
* difference between "your bundler is misconfigured" and "your dependency
|
|
146
|
+
* decision is wrong" visible in the report.
|
|
147
|
+
*/
|
|
148
|
+
export function auditExternalImports(externalImports, dependencies) {
|
|
149
|
+
const diagnostics = [];
|
|
150
|
+
for (const specifier of externalImports) {
|
|
151
|
+
const decision = findDependencyDecision(dependencies, specifier);
|
|
152
|
+
if (decision === undefined) {
|
|
153
|
+
// A file path left external is not a missing decision; it is workspace
|
|
154
|
+
// source the bundler failed to flatten, so sending the caller to the
|
|
155
|
+
// dependency layer would point at the wrong fix. The check is exact for
|
|
156
|
+
// relative and absolute specifiers; see `isSourceSpecifier`.
|
|
157
|
+
diagnostics.push(isSourceSpecifier(specifier)
|
|
158
|
+
? createCellArtifactDiagnostic("source-level-import-remains", specifier, {
|
|
159
|
+
detail: `"${specifier}" is workspace source, which is inlined like any other source file, but the bundler left it external.`,
|
|
160
|
+
})
|
|
161
|
+
: createCellArtifactDiagnostic("unresolved-dependency-decision", specifier, {
|
|
162
|
+
detail: `The bundler could not flatten "${specifier}" and no decision covers it.`,
|
|
163
|
+
}));
|
|
164
|
+
continue;
|
|
165
|
+
}
|
|
166
|
+
switch (decision.strategy) {
|
|
167
|
+
case "extension":
|
|
168
|
+
diagnostics.push(createCellArtifactDiagnostic("missing-extension-mapping", decision.packageName, {
|
|
169
|
+
detail: `"${specifier}" is decided \`extension\` but reached the artifact as a source import, so no extension global was referenced in its place.`,
|
|
170
|
+
}));
|
|
171
|
+
break;
|
|
172
|
+
case "replace":
|
|
173
|
+
if (decision.rejection.kind === "architectural") {
|
|
174
|
+
diagnostics.push(createCellArtifactDiagnostic("platform-conflicting-dependency", decision.packageName, {
|
|
175
|
+
detail: `"${specifier}" was architecturally rejected (${decision.rejection.code}) and still reaches the artifact. ${decision.rejection.remediation}`,
|
|
176
|
+
}));
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
diagnostics.push(createCellArtifactDiagnostic("source-level-import-remains", specifier, {
|
|
180
|
+
detail: `"${specifier}" was rejected as a technical bundling failure (${decision.rejection.code}) but is still imported. ${decision.rejection.remediation}`,
|
|
181
|
+
}));
|
|
182
|
+
}
|
|
183
|
+
break;
|
|
184
|
+
case "host":
|
|
185
|
+
diagnostics.push(createCellArtifactDiagnostic("source-level-import-remains", specifier, {
|
|
186
|
+
detail: `"${specifier}" is decided \`host\` and must be referenced through the global "${decision.globalName}"; a surviving import is resolved by nothing at runtime.`,
|
|
187
|
+
}));
|
|
188
|
+
break;
|
|
189
|
+
case "inline":
|
|
190
|
+
diagnostics.push(createCellArtifactDiagnostic("source-level-import-remains", specifier, {
|
|
191
|
+
detail: `"${specifier}" is decided \`inline\` but was left external instead of being flattened into the Cell code.`,
|
|
192
|
+
}));
|
|
193
|
+
break;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return diagnostics;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Reports packages flattened into the artifact that should not have been.
|
|
200
|
+
*
|
|
201
|
+
* The bundled set is the only place these failures are visible: a bundle that
|
|
202
|
+
* works looks identical to one that carries a second React, an inlined copy of a
|
|
203
|
+
* library the page is also about to load as an extension, or a package the
|
|
204
|
+
* resolver rejected. All three only become real at runtime, which is why they are
|
|
205
|
+
* checked here rather than left to the platform.
|
|
206
|
+
*/
|
|
207
|
+
export function auditInlinedPackages(inlinedPackages, dependencies, inlinedSpecifiers) {
|
|
208
|
+
const diagnostics = [];
|
|
209
|
+
// Specifier-level provenance when present: each bare specifier keeps its
|
|
210
|
+
// exact-subpath identity so `findDependencyDecision` can apply exact-first
|
|
211
|
+
// precedence. Package names fall back for fixture bundlers that only report
|
|
212
|
+
// package roots, and for packages in the set that no specifier covers.
|
|
213
|
+
const specifierPackageNames = new Set((inlinedSpecifiers ?? []).map(specifier => packageNameOfSpecifier(specifier)));
|
|
214
|
+
const leftoverPackages = inlinedPackages.filter(name => !specifierPackageNames.has(name));
|
|
215
|
+
const subjects = [...(inlinedSpecifiers ?? []), ...leftoverPackages];
|
|
216
|
+
for (const subject of subjects) {
|
|
217
|
+
const decision = findDependencyDecision(dependencies, subject);
|
|
218
|
+
if (decision === undefined)
|
|
219
|
+
continue;
|
|
220
|
+
switch (decision.strategy) {
|
|
221
|
+
case "host":
|
|
222
|
+
diagnostics.push(createCellArtifactDiagnostic("duplicate-host-mapping", decision.packageName, {
|
|
223
|
+
detail: `The bundle contains its own copy of a package decided \`host\`, so the artifact carries a second module identity for the global "${decision.globalName}".`,
|
|
224
|
+
}));
|
|
225
|
+
break;
|
|
226
|
+
case "extension":
|
|
227
|
+
diagnostics.push(createCellArtifactDiagnostic("missing-extension-mapping", decision.packageName, {
|
|
228
|
+
detail: `The bundle contains its own copy of a package decided \`extension\`, so the artifact ignores the extension global "${decision.globalName}" the page is told to load and carries a duplicate instead.`,
|
|
229
|
+
}));
|
|
230
|
+
break;
|
|
231
|
+
case "replace":
|
|
232
|
+
if (decision.rejection.kind === "architectural") {
|
|
233
|
+
diagnostics.push(createCellArtifactDiagnostic("platform-conflicting-dependency", decision.packageName, {
|
|
234
|
+
detail: `The package was architecturally rejected (${decision.rejection.code}) and was bundled anyway. ${decision.rejection.remediation}`,
|
|
235
|
+
}));
|
|
236
|
+
}
|
|
237
|
+
else {
|
|
238
|
+
diagnostics.push(createCellArtifactDiagnostic("unresolved-dependency-decision", decision.packageName, {
|
|
239
|
+
detail: `The decision for "${decision.packageName}" is \`replace\` because it failed as an artifact (${decision.rejection.code}), yet the bundle contains it. There is no usable decision for the package as it appears here. ${decision.rejection.remediation}`,
|
|
240
|
+
}));
|
|
241
|
+
}
|
|
242
|
+
break;
|
|
243
|
+
case "inline":
|
|
244
|
+
// Exactly what should have happened.
|
|
245
|
+
break;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
return diagnostics;
|
|
249
|
+
}
|
|
250
|
+
export function auditEmittedAssets(emittedAssets) {
|
|
251
|
+
return emittedAssets.map(asset => createCellArtifactDiagnostic("unsupported-runtime-asset", asset, {
|
|
252
|
+
detail: `The bundler emitted "${asset}" beside the Cell code. A ReactCellType cell is one script, so there is nowhere for a sibling asset to be loaded from.`,
|
|
253
|
+
}));
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Audits the inlined resource ledger for an entry the artifact could not have inlined (#98).
|
|
257
|
+
*
|
|
258
|
+
* The ledger is produced by the same reader that generated the module text, so every entry that
|
|
259
|
+
* reached here *should* carry a `data:` URI. This check is the audit rather than the producer's
|
|
260
|
+
* promise, and the distinction is the point of the issue's "every inlined asset URL is traceable"
|
|
261
|
+
* criterion: a reader that inlined nothing and one that inlined everything both produce an
|
|
262
|
+
* artifact, and only the ledger plus an audit can tell them apart.
|
|
263
|
+
*
|
|
264
|
+
* It is a pure function over the report, so the compiler does not re-parse base64 to run it.
|
|
265
|
+
*/
|
|
266
|
+
export function auditInlinedResourceUrls(resources) {
|
|
267
|
+
const diagnostics = [];
|
|
268
|
+
for (const resource of resources) {
|
|
269
|
+
if (resource.kind === "style") {
|
|
270
|
+
// A stylesheet's own references were rewritten by the reader, which refuses rather than
|
|
271
|
+
// leaving one behind. The ledger carries their counts rather than their URLs, so there is
|
|
272
|
+
// nothing here to re-check without re-reading the stylesheet the artifact already embeds.
|
|
273
|
+
continue;
|
|
274
|
+
}
|
|
275
|
+
if (!resource.dataUri.startsWith("data:")) {
|
|
276
|
+
diagnostics.push(createCellArtifactDiagnostic("rejected-cell-asset", resource.fileName, {
|
|
277
|
+
detail: `The inlined asset "${resource.fileName}" is not reported as a data: URI, so the artifact would carry an untraceable external reference. A Cell is one script with no sibling files and no runtime directory; rebuild through the compiler so the asset is inlined.`,
|
|
278
|
+
}));
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return diagnostics;
|
|
282
|
+
}
|
|
283
|
+
// ---------------------------------------------------------------------------
|
|
284
|
+
// Source and budget audit
|
|
285
|
+
// ---------------------------------------------------------------------------
|
|
286
|
+
/**
|
|
287
|
+
* Runs both source checks over a composed artifact.
|
|
288
|
+
*
|
|
289
|
+
* Shared by assembly and verification on purpose. The two callers differ only in
|
|
290
|
+
* what they can say about *where* a construct came from — assembly knows which
|
|
291
|
+
* part of the artifact it composed, verification only has the finished string —
|
|
292
|
+
* so the origin is a function of the offset rather than a reason to write the
|
|
293
|
+
* checks twice. Two copies would be two places for the wording or the code to
|
|
294
|
+
* drift, which is exactly what makes a report disagree with itself.
|
|
295
|
+
*
|
|
296
|
+
* One audit call, not two, because both checks need the same parse and an artifact
|
|
297
|
+
* can be megabytes of minified bundle.
|
|
298
|
+
*/
|
|
299
|
+
export function auditArtifactSource(composedCode, originOf) {
|
|
300
|
+
const diagnostics = [];
|
|
301
|
+
const audit = auditCellSource(composedCode);
|
|
302
|
+
for (const finding of audit.findings) {
|
|
303
|
+
diagnostics.push(createCellArtifactDiagnostic("rejected-cell-source-construct", finding.specifier ?? finding.match, {
|
|
304
|
+
detail: `Found ${finding.occurrences} time(s) in ${originOf(finding.index)}, at line ${finding.line}. ReactCellType rejects it with: "${finding.platformMessage}"`,
|
|
305
|
+
location: `line ${finding.line}`,
|
|
306
|
+
}));
|
|
307
|
+
}
|
|
308
|
+
for (const dynamicImport of audit.dynamicImports) {
|
|
309
|
+
diagnostics.push(createCellArtifactDiagnostic("unsupported-runtime-asset", dynamicImport.match, {
|
|
310
|
+
detail: `Found ${dynamicImport.occurrences} dynamic import call(s) in ${originOf(dynamicImport.index)}, at line ${dynamicImport.line}. The platform validator does not reject these, so nothing downstream will catch one that survives into production.`,
|
|
311
|
+
location: `line ${dynamicImport.line}`,
|
|
312
|
+
}));
|
|
313
|
+
}
|
|
314
|
+
return diagnostics;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Attributes an offset in a composed artifact to the part it came from.
|
|
318
|
+
*
|
|
319
|
+
* By offset rather than by comparing line counts: the composed source has a
|
|
320
|
+
* header line before the bundle, so line arithmetic would be off by one in
|
|
321
|
+
* exactly the case the origin matters most. A test covers it by asserting that a
|
|
322
|
+
* construct near the bundle's end is still attributed to the bundle.
|
|
323
|
+
*
|
|
324
|
+
* ## The prefix length is an input, not a constant (#185)
|
|
325
|
+
*
|
|
326
|
+
* Before the auto-height injection this function computed the bundle's start as
|
|
327
|
+
* "banner + newline", which was exact only because nothing else sat between the
|
|
328
|
+
* banner and the bundle. The composed artifact is now
|
|
329
|
+
* `banner + livePropsDeclaration? + styleInstaller? + autoHeight? + bundle + wrapper`,
|
|
330
|
+
* so the bundle's start is the banner plus *whatever prefix this assembly emitted* —
|
|
331
|
+
* and the prefix lengths are passed in rather than re-derived here, because the
|
|
332
|
+
* alternative (measuring the patch source again) is a second spelling of
|
|
333
|
+
* assembly's composition that can drift away from it. Assembly knows exactly what
|
|
334
|
+
* it emitted; this function's job is only the arithmetic.
|
|
335
|
+
*
|
|
336
|
+
* Everything before the bundle — the live-props declaration, the style installer,
|
|
337
|
+
* the injection — is reported as "the generated artifact header", which is the
|
|
338
|
+
* honest granularity: they are all compiler-emitted wiring rather than the Cell's
|
|
339
|
+
* bundle or its entry wrapper, and a diagnostic about one of them is a compiler
|
|
340
|
+
* bug report either way.
|
|
341
|
+
*/
|
|
342
|
+
export function artifactOriginOf(bundledCode, prefixLength = 0) {
|
|
343
|
+
const bundleStart = CELL_ARTIFACT_BANNER.length + 1 + prefixLength;
|
|
344
|
+
const bundleEnd = bundleStart + bundledCode.length;
|
|
345
|
+
return index => {
|
|
346
|
+
if (index < bundleStart)
|
|
347
|
+
return "the generated artifact header";
|
|
348
|
+
if (index < bundleEnd)
|
|
349
|
+
return "bundled dependency code";
|
|
350
|
+
return "the generated entry wrapper";
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* Checks a composed artifact against the caller's budget, saying *which measured
|
|
355
|
+
* band* the size falls in.
|
|
356
|
+
*
|
|
357
|
+
* Decision source: GitHub Issue #21 —
|
|
358
|
+
* "Research: measure ReactCellType generated-code budget and performance envelope"
|
|
359
|
+
* (https://github.com/Mang-X/forguncy-react-workspace/issues/21). Before #21 this
|
|
360
|
+
* function reported only "over budget", which is the one thing a caller can act on
|
|
361
|
+
* and the least useful thing it could say: a 600 KiB artifact and a 4 MiB one are
|
|
362
|
+
* both "over" a 512 KiB budget and are not remotely the same decision.
|
|
363
|
+
*
|
|
364
|
+
* The band comes from `core`'s measured record rather than from a second table
|
|
365
|
+
* here. `core` owns the measurement (#21) and `cell-compiler` takes it as
|
|
366
|
+
* configuration — the same division the package's other Specs use, and the reason
|
|
367
|
+
* the measurement is not restated: two copies would drift, and the drift would be
|
|
368
|
+
* invisible because both would look plausible.
|
|
369
|
+
*
|
|
370
|
+
* The code stays `cell-code-budget-exceeded`, because that is #6's public
|
|
371
|
+
* vocabulary and a downstream consumer branches on it. What changed is that the
|
|
372
|
+
* detail now names the band and the measured cost, so a caller that sees this
|
|
373
|
+
* diagnostic can tell "worth a look" from "get an extension" without re-deriving
|
|
374
|
+
* the thresholds.
|
|
375
|
+
*/
|
|
376
|
+
export function auditCodeBudget(code, budget) {
|
|
377
|
+
if (budget === undefined)
|
|
378
|
+
return [];
|
|
379
|
+
// The budget is validated, not trusted, and the guard is `core`'s rather than a
|
|
380
|
+
// second copy here: the probe's `size` step compares a cap too, so one contract
|
|
381
|
+
// for "what may a programmatic cap be" is what keeps the two from disagreeing
|
|
382
|
+
// about a value the caller supplied once. See `assertCellCodeBudget` for why an
|
|
383
|
+
// unvalidated one fails in the most confusing direction available.
|
|
384
|
+
assertCellCodeBudget(budget);
|
|
385
|
+
if (code.length <= budget)
|
|
386
|
+
return [];
|
|
387
|
+
const verdict = classifyCellCodeSize(code.length);
|
|
388
|
+
const { write, browserEntry } = verdict.definition.representativeMeasurements;
|
|
389
|
+
// Two different situations produce this diagnostic and they need different
|
|
390
|
+
// advice, which is why the guidance is chosen rather than copied from the band:
|
|
391
|
+
//
|
|
392
|
+
// - The artifact is large by measurement (`review` or above). The band's own
|
|
393
|
+
// guidance is the right advice.
|
|
394
|
+
// - The artifact is inside the measured ordinary range and the *budget* is what
|
|
395
|
+
// is tight. Printing the inline band's "no review needed" next to a hard
|
|
396
|
+
// rejection would have the diagnostic contradict itself, and would send the
|
|
397
|
+
// caller looking for a problem in an artifact the measurement says is fine.
|
|
398
|
+
//
|
|
399
|
+
// The second case is the one where the two concepts must not be conflated, so it
|
|
400
|
+
// says what is actually true of this rejection: the budget is a hard cap, and the
|
|
401
|
+
// band is an advisory classification that a raised cap does not start reporting.
|
|
402
|
+
//
|
|
403
|
+
// The claim is scoped to *this* check, and that scoping is load-bearing. This
|
|
404
|
+
// function returns one diagnostic among several that `assembleCellArtifact`
|
|
405
|
+
// collects, so an artifact can carry a budget rejection beside an unrelated one —
|
|
406
|
+
// reproduced with an unflattened inline import: a tight budget yields
|
|
407
|
+
// `[source-level-import-remains, cell-code-budget-exceeded]`, and raising the
|
|
408
|
+
// budget yields `[source-level-import-remains]` and the compile is *still*
|
|
409
|
+
// rejected. Saying a raised budget "accepts the artifact outright" would be false
|
|
410
|
+
// in exactly that case, and would send the caller away believing the build is
|
|
411
|
+
// clean. Nothing here knows whether other diagnostics exist, so the honest form is
|
|
412
|
+
// conditional: this rejection goes, anything else stands.
|
|
413
|
+
const guidance = verdict.withinInlineBand
|
|
414
|
+
? `The artifact is inside the measured ordinary range (${verdict.band}, ceiling ` +
|
|
415
|
+
`${String(verdict.definition.maxCharacters)} characters), so this rejection is the configured budget's ` +
|
|
416
|
+
`rather than a cost the measurement found. Raising the budget removes this budget rejection; any other ` +
|
|
417
|
+
`artifact diagnostic still applies. Bands are an advisory classification, not a severity this diagnostic ` +
|
|
418
|
+
`re-reports once a size is allowed.`
|
|
419
|
+
: verdict.definition.guidance;
|
|
420
|
+
return [
|
|
421
|
+
createCellArtifactDiagnostic("cell-code-budget-exceeded", "Cell artifact", {
|
|
422
|
+
detail: `The composed artifact is ${code.length} characters against a configured budget of ${budget}. ` +
|
|
423
|
+
`The measurement is taken on the composed artifact because that is what is written into the cell. ` +
|
|
424
|
+
`Measured band: ${verdict.band} (#21). Those figures were taken against ` +
|
|
425
|
+
`${CELL_CODE_BUDGET_MEASUREMENT.target}, which is not the build this project targets, so they are ` +
|
|
426
|
+
`a carried-forward reference rather than a measurement of this target: at this band's own measured ` +
|
|
427
|
+
`points the designer write took ${String(write.ms)} ms at ${String(write.characters)} characters ` +
|
|
428
|
+
`(${write.artifact}) and the browser's first cell entry took ${String(browserEntry.ms)} ms at ` +
|
|
429
|
+
`${String(browserEntry.characters)} characters (${browserEntry.artifact}). ${guidance}`,
|
|
430
|
+
// The measurement travels with the diagnostic so it has exactly one producer (#77 round 5).
|
|
431
|
+
// A caller that wants to record this rejection has to take these numbers — it cannot type its
|
|
432
|
+
// own, which is what makes the recorded evidence compiler-origin rather than attested.
|
|
433
|
+
//
|
|
434
|
+
// Deliberately just the two figures: the *identity* of the compile is composed one level up,
|
|
435
|
+
// where the entry's source and the decision set are in hand (see
|
|
436
|
+
// `composeCellCompileFingerprint`). Composing it here would mean deriving the entry source
|
|
437
|
+
// from the composed artifact, which no longer exists as a separate input.
|
|
438
|
+
budgetEvidence: {
|
|
439
|
+
budgetCharacters: budget,
|
|
440
|
+
codeCharacters: code.length,
|
|
441
|
+
},
|
|
442
|
+
}),
|
|
443
|
+
];
|
|
444
|
+
}
|