fgc-cell 0.0.0-stage → 0.1.0-preview.2
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 +360 -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/skills/using-forguncy-react/SKILL.md +78 -0
- package/README.md +0 -3
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The compiler boundary: a normal module entry in, a platform artifact out.
|
|
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).
|
|
7
|
+
*
|
|
8
|
+
* Governing architecture Specs: #4, whose ownership boundary the decision audits
|
|
9
|
+
* enforce, and #5, the verified ReactCellType target whose entry shapes this boundary
|
|
10
|
+
* emits.
|
|
11
|
+
*
|
|
12
|
+
* #6 describes the boundary as "input is a normal module entry plus resolved
|
|
13
|
+
* dependency decisions" and "output is a platform artifact, not a generic web
|
|
14
|
+
* bundle", and then says the compiler should "use Vite+/Rolldown/tsdown
|
|
15
|
+
* capabilities rather than inventing a separate module resolver". Those two
|
|
16
|
+
* sentences together are why `CellBundlerPort` exists: the actual module
|
|
17
|
+
* resolution and code generation are a bundler's job, and this package's job is
|
|
18
|
+
* everything that makes the result a *Cell artifact* rather than a web bundle —
|
|
19
|
+
* assembly, the entry wrapper, the metadata, the guarantees and the error model.
|
|
20
|
+
*
|
|
21
|
+
* So `compileCell` does not name a bundler, and this module contains no resolver.
|
|
22
|
+
* It takes the bundler's report and decides whether it produced a legal artifact,
|
|
23
|
+
* which is a different question from whether it produced a working bundle:
|
|
24
|
+
*
|
|
25
|
+
* - a bundler can succeed and leave an `import` behind, and only the decisions
|
|
26
|
+
* say whether that import should have been inlined or mapped to a host global;
|
|
27
|
+
* - a bundler can succeed and emit a sibling chunk, which is a legitimate web
|
|
28
|
+
* bundle and an illegal Cell artifact;
|
|
29
|
+
* - a bundler can succeed after inlining a package that implements a
|
|
30
|
+
* Forguncy-owned capability, which is a platform conflict no bundler can see.
|
|
31
|
+
*
|
|
32
|
+
* The real Forguncy confirmation of the result is deliberately *not* claimed
|
|
33
|
+
* here. #7's validation plan performs it downstream, and AGENTS.md rule 7 forbids
|
|
34
|
+
* reporting a local green build as runtime compatibility. See
|
|
35
|
+
* `guarantees.ts` for which promises that leaves outstanding.
|
|
36
|
+
*
|
|
37
|
+
* Split by #162, under the shape-stabilisation Spec #152: assembly lives in
|
|
38
|
+
* `artifact-assembly.ts` and the artifact audits in `artifact-audits.ts`.
|
|
39
|
+
*/
|
|
40
|
+
import { assembleCellArtifact, CELL_ARTIFACT_BANNER } from "./artifact-assembly.js";
|
|
41
|
+
import { auditArtifactSource } from "./artifact-audits.js";
|
|
42
|
+
import { formatCellResourceLedger, isCellResourcePolicyError } from "./cell-resources.js";
|
|
43
|
+
import { createCellArtifactDiagnostic, dedupeCellArtifactDiagnostics, formatCellArtifactDiagnostics, } from "./diagnostics.js";
|
|
44
|
+
import { CELL_ENTRY_COMPONENT_BINDING } from "./entry.js";
|
|
45
|
+
import { auditFrontendLibraries, collectFrontendLibraries, FRONTEND_LIBRARIES_FIELD_NAME, frontendLibraryIds, } from "./frontend-libraries.js";
|
|
46
|
+
import { auditWorkspaceSource, formatWorkspaceSourceAudit } from "./workspace-source-audit.js";
|
|
47
|
+
export { assembleCellArtifact, CELL_ARTIFACT_BANNER };
|
|
48
|
+
// ---------------------------------------------------------------------------
|
|
49
|
+
// Verification and serialization
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
/**
|
|
52
|
+
* Re-checks an artifact that was assembled somewhere else, or read back out.
|
|
53
|
+
*
|
|
54
|
+
* This is the weaker half of the contract and it is important not to oversell it:
|
|
55
|
+
* `CompileCellResult` carries no entry metadata, so nothing here can confirm which
|
|
56
|
+
* entry shape the code exposes. What it can confirm is that the artifact is
|
|
57
|
+
* canonical and carries no refused construct — the two properties a diff and a
|
|
58
|
+
* reviewer depend on.
|
|
59
|
+
*/
|
|
60
|
+
export function verifyCellArtifact(artifact) {
|
|
61
|
+
const diagnostics = [];
|
|
62
|
+
if (!artifact.code.startsWith(CELL_ARTIFACT_BANNER)) {
|
|
63
|
+
diagnostics.push(createCellArtifactDiagnostic("non-canonical-artifact-metadata", "code", {
|
|
64
|
+
detail: "The artifact does not begin with the generated-artifact banner, so it was edited after generation or produced by something other than this compiler.",
|
|
65
|
+
}));
|
|
66
|
+
}
|
|
67
|
+
diagnostics.push(...auditFrontendLibraries(artifact.frontendLibraries));
|
|
68
|
+
// Nothing here can say which part of the artifact a construct came from: the
|
|
69
|
+
// result carries no provenance. The wording is one sentence rather than two
|
|
70
|
+
// because the honest answer for this caller is "the artifact".
|
|
71
|
+
diagnostics.push(...auditArtifactSource(artifact.code, () => "the artifact"));
|
|
72
|
+
return dedupeCellArtifactDiagnostics(diagnostics);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The canonical serialization of a result.
|
|
76
|
+
*
|
|
77
|
+
* Exists so "deterministic" is a property a test can assert rather than a word in
|
|
78
|
+
* a guarantee. Key order is written out instead of relied upon, and the trailing
|
|
79
|
+
* newline makes the string a well-formed file.
|
|
80
|
+
*/
|
|
81
|
+
export function serializeCompileCellResult(artifact) {
|
|
82
|
+
const canonical = {
|
|
83
|
+
code: artifact.code,
|
|
84
|
+
[FRONTEND_LIBRARIES_FIELD_NAME]: artifact.frontendLibraries.map(library => ({
|
|
85
|
+
libraryId: library.libraryId,
|
|
86
|
+
})),
|
|
87
|
+
};
|
|
88
|
+
return `${JSON.stringify(canonical, null, 2)}\n`;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* A report block for a CI log or a PR body, including which promises remain unproven.
|
|
92
|
+
*
|
|
93
|
+
* ## Why the workspace audit is printed here
|
|
94
|
+
*
|
|
95
|
+
* A workspace rejection carries `diagnostics: []` **by design** — #14's vocabulary is
|
|
96
|
+
* not #6's, so a cycle or an intercepting decision is reported through `workspace`
|
|
97
|
+
* rather than restated as a `CellArtifactDiagnostic`. That decision is only useful if
|
|
98
|
+
* the finding reaches a reader, and this function is the package's standard reporting
|
|
99
|
+
* path. Formatting `outcome.diagnostics` alone printed
|
|
100
|
+
* `Compilation rejected with 0 diagnostic(s):` — the structured diagnostic existed in
|
|
101
|
+
* memory and reached nobody, which would have undermined the very path this seam
|
|
102
|
+
* adds.
|
|
103
|
+
*
|
|
104
|
+
* So whenever a workspace audit is present it is printed in full, on both outcomes.
|
|
105
|
+
* On a *compiled* outcome that is the point rather than a bonus: the non-fatal
|
|
106
|
+
* findings (`workspace-package-in-frontend-libraries`, a transitive dependency with
|
|
107
|
+
* no decision) are exactly the ones a reader has to act on, and an artifact that
|
|
108
|
+
* compiles is where they are easiest to miss.
|
|
109
|
+
*
|
|
110
|
+
* A `WorkspaceSourceAudit` with nothing wrong still prints its summary lines, which is
|
|
111
|
+
* `formatWorkspaceSourceAudit`'s own contract — "no diagnostics" must not be readable
|
|
112
|
+
* as "the declared sharing was verified".
|
|
113
|
+
*/
|
|
114
|
+
export function formatCompileCellOutcome(outcome) {
|
|
115
|
+
const workspace = outcome.workspace === undefined ? [] : ["", formatWorkspaceSourceAudit(outcome.workspace)];
|
|
116
|
+
if (outcome.status === "compiled") {
|
|
117
|
+
const ids = frontendLibraryIds(outcome.artifact.frontendLibraries);
|
|
118
|
+
const resources = outcome.artifact.inlinedResources ?? [];
|
|
119
|
+
return [
|
|
120
|
+
`Compiled Cell artifact: ${outcome.artifact.code.length} characters, entry shape "${outcome.entryKind}".`,
|
|
121
|
+
`${FRONTEND_LIBRARIES_FIELD_NAME}: ${ids.join(", ") || "(none)"}`,
|
|
122
|
+
// Printed on every compiled artifact, not only on a resource-carrying one: a reader asking
|
|
123
|
+
// "how much of this Cell is inlined assets" has to be able to see the answer is none.
|
|
124
|
+
formatCellResourceLedger(resources),
|
|
125
|
+
"Real Forguncy runtime validation is not established by a local compile.",
|
|
126
|
+
...workspace,
|
|
127
|
+
].join("\n");
|
|
128
|
+
}
|
|
129
|
+
// The counts are reported per vocabulary rather than summed, because they are not
|
|
130
|
+
// the same kind of finding and a caller branching on either needs to see which one
|
|
131
|
+
// stopped the build. #6's diagnostics are empty on a pre-bundle rejection by design.
|
|
132
|
+
const artifactDiagnostics = `Compilation rejected with ${outcome.diagnostics.length} diagnostic(s):\n${formatCellArtifactDiagnostics(outcome.diagnostics)}`;
|
|
133
|
+
return [artifactDiagnostics, ...workspace].join("\n");
|
|
134
|
+
}
|
|
135
|
+
// ---------------------------------------------------------------------------
|
|
136
|
+
// The boundary function
|
|
137
|
+
// ---------------------------------------------------------------------------
|
|
138
|
+
function describeThrown(error) {
|
|
139
|
+
return error instanceof Error ? error.message : String(error);
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The request fields both bundler passes carry, built once.
|
|
143
|
+
*
|
|
144
|
+
* The pre-bundle pass and the build must be handed the same entry, decisions, extension
|
|
145
|
+
* mapping set and asset inline limit. Spelling that spread twice is how the two passes
|
|
146
|
+
* would eventually disagree, and a disagreement is exactly what the preflight exists to
|
|
147
|
+
* rule out. `componentBinding` is added by `bundle` alone, because only the build binds a
|
|
148
|
+
* component.
|
|
149
|
+
*/
|
|
150
|
+
function bundlingRequest(input, options) {
|
|
151
|
+
return {
|
|
152
|
+
entry: input.entry,
|
|
153
|
+
dependencies: input.dependencies,
|
|
154
|
+
...(options.extensionMappings === undefined ? {} : { extensionMappings: options.extensionMappings }),
|
|
155
|
+
...(options.assetInlineLimitBytes === undefined
|
|
156
|
+
? {}
|
|
157
|
+
: { assetInlineLimitBytes: options.assetInlineLimitBytes }),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* The public entry point.
|
|
162
|
+
*
|
|
163
|
+
* Bundler failure is converted into a diagnostic rather than rethrown: #6's error
|
|
164
|
+
* model exists so a caller never has to interpret an opaque build string, and an
|
|
165
|
+
* escaping exception is exactly that string.
|
|
166
|
+
*
|
|
167
|
+
* ## The workspace seam (#14 / #15)
|
|
168
|
+
*
|
|
169
|
+
* When the caller supplies `options.workspace`, `#14`'s audit runs over this compile
|
|
170
|
+
* and its result rides on the outcome as `workspace`. The seam has three parts, and
|
|
171
|
+
* the *order* is the part that matters.
|
|
172
|
+
*
|
|
173
|
+
* **1. A pre-bundle pass establishes what the cell imports.** The entry's specifiers
|
|
174
|
+
* are resolved but not built (`CellBundlerPort.resolveEntrySpecifiers`), and the
|
|
175
|
+
* audit's user-facing checks run against them. This happens *first* because two of
|
|
176
|
+
* the findings below have to stop the compile before any code is generated.
|
|
177
|
+
*
|
|
178
|
+
* **2. Two findings are fatal, and both are fatal before bundling.**
|
|
179
|
+
*
|
|
180
|
+
* - *A reachable workspace cycle.* #14 requires it to fail "before bundling rather
|
|
181
|
+
* than to be resolved by whichever traversal happens to run first". The bundler
|
|
182
|
+
* will happily inline a cyclic graph — ESM permits cycles — so the output looks
|
|
183
|
+
* fine and the ordering it picked is invisible in the result. Nothing downstream
|
|
184
|
+
* can catch it, and a bundler failure racing it could hide the structured
|
|
185
|
+
* diagnostic entirely.
|
|
186
|
+
* - *A dependency decision that can intercept workspace source.* This one is
|
|
187
|
+
* subtle enough to spell out. The bundler consults the host-bridge and
|
|
188
|
+
* extension-externals plans *during resolution*, so a decision naming a module id
|
|
189
|
+
* that a mapping also claims lets `interceptionFor` replace the import with a
|
|
190
|
+
* virtual runtime module **before** Rolldown ever resolves the local source. The
|
|
191
|
+
* artifact then contains no workspace import and no inlined workspace package, so
|
|
192
|
+
* every artifact-side audit passes — while the local package the cell actually
|
|
193
|
+
* imported was silently discarded. A local package named `antd` beside a `host`
|
|
194
|
+
* decision for `antd` is the working example. #14's output semantics are exactly
|
|
195
|
+
* what that violates, and only a check made *before* resolution can see it.
|
|
196
|
+
*
|
|
197
|
+
* **3. Everything else is reported, not fatal.** The remaining workspace findings
|
|
198
|
+
* that mean "this artifact has a runtime dependency on another workspace package"
|
|
199
|
+
* are already fatal from the output side: a workspace import the bundler left
|
|
200
|
+
* external reaches `auditExternalImports` as an unresolved decision, and a workspace
|
|
201
|
+
* package named in `frontendLibraries` trips that audit directly. Reporting those
|
|
202
|
+
* twice as two rejections would state one condition in two vocabularies, which is
|
|
203
|
+
* what `workspace-source.ts` records as the thing to avoid.
|
|
204
|
+
*
|
|
205
|
+
* **The audit still never resolves anything.** The graph is an *input to an audit*,
|
|
206
|
+
* not a second resolver: modules resolve through the bundler and `node_modules`, and
|
|
207
|
+
* removing the option changes no artifact byte. #6 forbids a second module resolver,
|
|
208
|
+
* and a graph that quietly redirected resolution would be exactly that.
|
|
209
|
+
*/
|
|
210
|
+
export async function compileCell(input, options) {
|
|
211
|
+
// The pre-bundle pass runs **only** when a graph was supplied, because it exists
|
|
212
|
+
// for one purpose: making #14's two fatal findings observable before anything is
|
|
213
|
+
// built. With no graph there is no workspace audit to run and nothing for the
|
|
214
|
+
// preflight to decide — so a graph-less #6 compile takes exactly the path it took
|
|
215
|
+
// before this seam existed: one `bundle()` and no analysis pass.
|
|
216
|
+
let entrySpecifiers;
|
|
217
|
+
if (options.workspace !== undefined) {
|
|
218
|
+
const resolveEntrySpecifiers = options.bundler.resolveEntrySpecifiers;
|
|
219
|
+
// A graph was supplied, so the pre-bundle guarantee is mandatory — and a port
|
|
220
|
+
// without the capability is refused rather than quietly audited after the build.
|
|
221
|
+
// That is the bound on the method being optional: optional preserves the
|
|
222
|
+
// graph-less boundary, and this makes the guarantee binding exactly when a
|
|
223
|
+
// workspace graph makes it meaningful. Falling back here would restore the defect
|
|
224
|
+
// the split exists to prevent — a cycle discovered only after Rolldown bundled.
|
|
225
|
+
if (resolveEntrySpecifiers === undefined) {
|
|
226
|
+
return {
|
|
227
|
+
status: "rejected",
|
|
228
|
+
diagnostics: [
|
|
229
|
+
createCellArtifactDiagnostic("bundler-failure", input.entry, {
|
|
230
|
+
detail: "A workspace graph was supplied, so the entry's specifiers must be resolved before bundling — but this bundler port implements no `resolveEntrySpecifiers`. #14 requires a reachable workspace cycle to fail before bundling, which cannot be decided without it. Use a port that provides the method, or omit `workspace`.",
|
|
231
|
+
}),
|
|
232
|
+
],
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
try {
|
|
236
|
+
entrySpecifiers = await resolveEntrySpecifiers(bundlingRequest(input, options));
|
|
237
|
+
}
|
|
238
|
+
catch (error) {
|
|
239
|
+
// A resource refusal is a finding about the Cell's *source*, not a bundler fault, so it
|
|
240
|
+
// keeps its own code and its remediation. Reducing it to `bundler-failure` would tell the
|
|
241
|
+
// caller to fix the bundler when the fix is in the stylesheet.
|
|
242
|
+
if (isCellResourcePolicyError(error)) {
|
|
243
|
+
return { status: "rejected", diagnostics: error.diagnostics };
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
status: "rejected",
|
|
247
|
+
diagnostics: [
|
|
248
|
+
createCellArtifactDiagnostic("bundler-failure", input.entry, {
|
|
249
|
+
detail: `The bundler could not resolve the entry: ${describeThrown(error)}`,
|
|
250
|
+
}),
|
|
251
|
+
],
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
const preflight = auditWorkspaceSource({
|
|
255
|
+
workspace: options.workspace,
|
|
256
|
+
dependencies: input.dependencies,
|
|
257
|
+
entryModuleIds: entrySpecifiers,
|
|
258
|
+
frontendLibraries: collectFrontendLibraries(input.dependencies).libraries,
|
|
259
|
+
});
|
|
260
|
+
if (preflight.diagnostics.some(isPreBundleFatalWorkspaceDiagnostic)) {
|
|
261
|
+
return {
|
|
262
|
+
status: "rejected",
|
|
263
|
+
// Empty on purpose: #14's vocabulary is not #6's, so a workspace finding is
|
|
264
|
+
// reported through `workspace` rather than restated as a
|
|
265
|
+
// `CellArtifactDiagnostic` whose `breaksGuarantees` would have to name a #6
|
|
266
|
+
// guarantee it is not about. Nothing was built, so there is nothing for the
|
|
267
|
+
// artifact vocabulary to describe either.
|
|
268
|
+
diagnostics: [],
|
|
269
|
+
// The whole audit, not only the fatal findings: a caller reading a rejection
|
|
270
|
+
// should see everything wrong with the graph, not just the one thing that
|
|
271
|
+
// stopped it. This is the audit the post-build step would have produced, minus
|
|
272
|
+
// the two inputs only the output can supply.
|
|
273
|
+
workspace: preflight,
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
let module;
|
|
278
|
+
try {
|
|
279
|
+
module = await options.bundler.bundle({
|
|
280
|
+
...bundlingRequest(input, options),
|
|
281
|
+
// The one thing the two halves of the pipeline must agree on, handed over
|
|
282
|
+
// rather than assumed.
|
|
283
|
+
componentBinding: CELL_ENTRY_COMPONENT_BINDING,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
catch (error) {
|
|
287
|
+
if (isCellResourcePolicyError(error)) {
|
|
288
|
+
return { status: "rejected", diagnostics: error.diagnostics };
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
status: "rejected",
|
|
292
|
+
diagnostics: [
|
|
293
|
+
createCellArtifactDiagnostic("bundler-failure", input.entry, {
|
|
294
|
+
detail: `The bundler reported: ${describeThrown(error)}`,
|
|
295
|
+
}),
|
|
296
|
+
],
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
// The post-build audit, over the same graph, now with what the build actually
|
|
300
|
+
// produced. It re-runs the preflight checks (they cannot newly fail) and adds the
|
|
301
|
+
// two that need the output: what the bundler left external, and the metadata that
|
|
302
|
+
// will be written.
|
|
303
|
+
//
|
|
304
|
+
// `entrySpecifiers` is defined whenever `options.workspace` is — the pre-bundle
|
|
305
|
+
// block above sets both together — so the pair is read from one narrowing rather
|
|
306
|
+
// than two independent `undefined` checks that could drift apart.
|
|
307
|
+
const workspace = options.workspace === undefined || entrySpecifiers === undefined
|
|
308
|
+
? undefined
|
|
309
|
+
: auditWorkspaceForCompile(input, options.workspace, module, entrySpecifiers);
|
|
310
|
+
const outcome = assembleCellArtifact({
|
|
311
|
+
module,
|
|
312
|
+
dependencies: input.dependencies,
|
|
313
|
+
...(options.entryKind === undefined ? {} : { entryKind: options.entryKind }),
|
|
314
|
+
...(options.codeBudgetCharacters === undefined
|
|
315
|
+
? {}
|
|
316
|
+
: { codeBudgetCharacters: options.codeBudgetCharacters }),
|
|
317
|
+
// The opt-out is the only thing assembly needs: everything else about the injection —
|
|
318
|
+
// what it is, what it names, how it stays idempotent — is `auto-height.ts`'s contract,
|
|
319
|
+
// not a per-compile decision. `"fixed"` is the sole spelling of "do not inject".
|
|
320
|
+
heightAdaptive: options.layout?.heightMode !== "fixed",
|
|
321
|
+
});
|
|
322
|
+
return workspace === undefined ? outcome : { ...outcome, workspace };
|
|
323
|
+
}
|
|
324
|
+
/**
|
|
325
|
+
* The workspace findings that stop a compile *before* any code is generated.
|
|
326
|
+
*
|
|
327
|
+
* Two codes, and each is here because nothing downstream can catch it — see
|
|
328
|
+
* `compileCell`'s header for the full argument. `circular-workspace-dependency` is
|
|
329
|
+
* #14's own "fail before bundling" requirement; a decision that can intercept
|
|
330
|
+
* workspace source is invisible the moment resolution replaces the import, so the
|
|
331
|
+
* artifact audits that would otherwise be the safety net cannot see it at all.
|
|
332
|
+
*
|
|
333
|
+
* A named predicate rather than an inline list so a future fatal code has one place
|
|
334
|
+
* to be added, and so the *reason* each is fatal is documented where it is enforced.
|
|
335
|
+
*/
|
|
336
|
+
function isPreBundleFatalWorkspaceDiagnostic(diagnostic) {
|
|
337
|
+
return (diagnostic.code === "circular-workspace-dependency" ||
|
|
338
|
+
diagnostic.code === "workspace-package-decided-as-dependency");
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* `#14`'s audit, with this compile's inputs.
|
|
342
|
+
*
|
|
343
|
+
* Every input is taken from something the build already established rather than
|
|
344
|
+
* asked of the caller a second time:
|
|
345
|
+
*
|
|
346
|
+
* - the graph is the caller's `options.workspace`, read from the project's own
|
|
347
|
+
* manifest by `loadPnpmWorkspaceGraph`;
|
|
348
|
+
* - the entry's module ids are the bundler's, from the pre-bundle pass;
|
|
349
|
+
* - the external imports are the bundler's own report, so the audit sees what
|
|
350
|
+
* actually survived rather than what was authored;
|
|
351
|
+
* - `frontendLibraries` is derived from the decisions by the same function assembly
|
|
352
|
+
* uses, so the metadata the audit checks and the metadata the artifact carries are
|
|
353
|
+
* one computation.
|
|
354
|
+
*
|
|
355
|
+
* The graph is handed over *raw* rather than pre-indexed, which is deliberate: the
|
|
356
|
+
* audit indexes it itself, so a graph whose own coherence is broken (a duplicated
|
|
357
|
+
* name, a machine-specific directory) reports that as part of this same result.
|
|
358
|
+
* Passing an already-indexed graph would silently drop exactly those findings.
|
|
359
|
+
*/
|
|
360
|
+
function auditWorkspaceForCompile(input, workspace, module, entrySpecifiers) {
|
|
361
|
+
return auditWorkspaceSource({
|
|
362
|
+
workspace,
|
|
363
|
+
dependencies: input.dependencies,
|
|
364
|
+
externalImports: module.externalImports ?? [],
|
|
365
|
+
frontendLibraries: collectFrontendLibraries(input.dependencies).libraries,
|
|
366
|
+
entryModuleIds: entrySpecifiers,
|
|
367
|
+
});
|
|
368
|
+
}
|