@ethisyscore/vite-plugin 1.5.2 → 1.6.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/dist/index.cjs +612 -49
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +220 -1
- package/dist/index.d.ts +220 -1
- package/dist/index.js +593 -14
- package/dist/index.js.map +1 -0
- package/package.json +14 -7
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,224 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Reference from the plugin manifest to an SDUI resource JSON file.
|
|
5
|
+
*
|
|
6
|
+
* Wave 0 convention: the manifest declares each declarative resource with
|
|
7
|
+
* a stable `uri` plus a `file` path (relative to the manifest's directory)
|
|
8
|
+
* pointing at the JSON document the host will serve. The static-file
|
|
9
|
+
* convention lets the Vite plugin validate the tree at build time without
|
|
10
|
+
* having to execute plugin runtime code.
|
|
11
|
+
*/
|
|
12
|
+
interface ManifestResourceRef {
|
|
13
|
+
uri: string;
|
|
14
|
+
/**
|
|
15
|
+
* Relative path (POSIX or platform-native) to the SDUI JSON document.
|
|
16
|
+
* Must not be absolute, must not contain `..` traversal segments.
|
|
17
|
+
*/
|
|
18
|
+
file?: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Top-level manifest reactivity-rule declaration. Each entry pairs an
|
|
22
|
+
* author-supplied identifier with a {@link import("@ethisyscore/protocol").ReactiveRule}.
|
|
23
|
+
*
|
|
24
|
+
* Reactivity declared inline on SDUI nodes (the `bindings` property) is
|
|
25
|
+
* validated by the SDUI-tree pass; this surface covers the rarer case of
|
|
26
|
+
* a manifest-level rule that applies cross-resource.
|
|
27
|
+
*/
|
|
28
|
+
interface ManifestReactiveRuleRef {
|
|
29
|
+
id: string;
|
|
30
|
+
rule: unknown;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The subset of the plugin manifest the Contract A Vite plugin pass cares
|
|
34
|
+
* about. The full manifest is intentionally a superset — the plugin
|
|
35
|
+
* tolerates additional fields it has not been taught yet so manifests
|
|
36
|
+
* built against a newer schema still load.
|
|
37
|
+
*/
|
|
38
|
+
interface ContractAManifest {
|
|
39
|
+
resources?: ManifestResourceRef[];
|
|
40
|
+
reactiveRules?: ManifestReactiveRuleRef[];
|
|
41
|
+
[key: string]: unknown;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Author-facing options for the Contract A Vite plugin pass.
|
|
45
|
+
*
|
|
46
|
+
* `root` defaults to Vite's resolved root at `configResolved` time, so the
|
|
47
|
+
* common case requires no configuration. `manifestPath` defaults to the
|
|
48
|
+
* `feature.manifest.json` convention emitted by the host-rendered
|
|
49
|
+
* scaffolding template; pass an absolute or relative path to override.
|
|
50
|
+
*/
|
|
51
|
+
interface ContractAPluginOptions {
|
|
52
|
+
/**
|
|
53
|
+
* Root directory the manifest path is resolved against. When omitted,
|
|
54
|
+
* Vite's `configResolved` populates it from `config.root`.
|
|
55
|
+
*/
|
|
56
|
+
root?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Manifest path. Relative paths resolve against `root`. Defaults to
|
|
59
|
+
* `feature.manifest.json` colocated with the Vite root.
|
|
60
|
+
*/
|
|
61
|
+
manifestPath?: string;
|
|
62
|
+
/**
|
|
63
|
+
* Output prefix for emitted SDUI assets. Defaults to `sdui/`. The plugin
|
|
64
|
+
* always emits an `${prefix}sdui-manifest.json` index alongside the
|
|
65
|
+
* validated resource JSON.
|
|
66
|
+
*/
|
|
67
|
+
outputPrefix?: string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Build-time Vite/Rollup plugin pass for EthisysCore Contract A
|
|
71
|
+
* (`renderMode: host-rendered`) plugins.
|
|
72
|
+
*
|
|
73
|
+
* Reads `feature.manifest.json` (or `extension.manifest.json` via
|
|
74
|
+
* `manifestPath`), validates each declared SDUI resource against the
|
|
75
|
+
* protocol's `SduiNode` Zod schema, validates each manifest-level
|
|
76
|
+
* reactivity rule against `ReactiveRule`, and emits the validated JSON
|
|
77
|
+
* into the Rollup bundle under the configured output prefix. Validation
|
|
78
|
+
* failures abort the build with a multi-line structured error that names
|
|
79
|
+
* the offending operator/primitive and the source file path + JSON
|
|
80
|
+
* pointer so the author can land on the offending node immediately.
|
|
81
|
+
*
|
|
82
|
+
* Worker-bundle emission for `renderMode: remote-runtime` is deferred to
|
|
83
|
+
* Wave 1's E7.S1b — this pass deliberately does nothing for non-Contract-A
|
|
84
|
+
* manifests.
|
|
85
|
+
*/
|
|
86
|
+
declare function ethisysContractAPlugin(options?: ContractAPluginOptions): Plugin;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* A single, structured validation failure surfaced by the Contract A
|
|
90
|
+
* schema validators. Carries enough context for a build-time error
|
|
91
|
+
* to be actionable without the plugin author opening the host runtime.
|
|
92
|
+
*/
|
|
93
|
+
interface ValidationFailure {
|
|
94
|
+
/** Absolute path of the source file whose JSON failed validation. */
|
|
95
|
+
filePath: string;
|
|
96
|
+
/**
|
|
97
|
+
* JSON-pointer (RFC 6901) into the failing JSON document, pointing at
|
|
98
|
+
* the offending node. Empty string when the offender is the root.
|
|
99
|
+
*/
|
|
100
|
+
pointer: string;
|
|
101
|
+
/** The offending operator / primitive / rule-kind name, if extractable. */
|
|
102
|
+
offender?: string;
|
|
103
|
+
/** Human-readable message suitable for surfacing at the build CLI. */
|
|
104
|
+
message: string;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Result of a validation call. Discriminated on `ok` so callers can branch
|
|
108
|
+
* narrowly without juggling exception flow for expected outcomes.
|
|
109
|
+
*/
|
|
110
|
+
type ValidationResult = {
|
|
111
|
+
ok: true;
|
|
112
|
+
} | {
|
|
113
|
+
ok: false;
|
|
114
|
+
failures: ValidationFailure[];
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Validate a single declarative SDUI resource against the protocol's
|
|
118
|
+
* {@link SduiNode} Zod schema. The recursive schema rejects unknown
|
|
119
|
+
* primitives and unknown JsonLogic operators at any depth of the tree.
|
|
120
|
+
*
|
|
121
|
+
* `filePath` is propagated into every emitted failure so the build CLI
|
|
122
|
+
* can point the author at the exact file on disk.
|
|
123
|
+
*/
|
|
124
|
+
declare function validateDeclarativeResource(doc: unknown, uri: string, filePath: string): ValidationResult;
|
|
125
|
+
/**
|
|
126
|
+
* Validate a single {@link ReactiveRule} against the protocol's curated
|
|
127
|
+
* JsonLogic operator subset. Used for top-level reactivity declarations
|
|
128
|
+
* declared on the manifest itself (i.e. not embedded under a `bindings`
|
|
129
|
+
* key on a SDUI node — those are covered by {@link validateDeclarativeResource}).
|
|
130
|
+
*/
|
|
131
|
+
declare function validateReactiveRule(rule: unknown, filePath: string): ValidationResult;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Contract B semantic primitive vocabulary (the closed v1 set authored in
|
|
135
|
+
* `sdk/extension-runtime/src/host/worker/component-registry.ts`). The names
|
|
136
|
+
* mirror the registry exactly; a drift between the two breaks the cross-repo
|
|
137
|
+
* agreement that E4.S4 locks in.
|
|
138
|
+
*/
|
|
139
|
+
declare const CONTRACT_B_SEMANTIC_PRIMITIVES: readonly ["Button", "DataTable", "Form", "EntityPicker", "CommandBar", "Drawer", "Modal", "CanvasSurface", "WebGLSurface"];
|
|
140
|
+
/**
|
|
141
|
+
* Non-component import-map entries — the runtime libraries the worker is
|
|
142
|
+
* permitted to resolve via bare specifiers. Authoring constraint: the plugin's
|
|
143
|
+
* single ESM bundle (Contract B emits exactly one — see `worker-bundle.ts`)
|
|
144
|
+
* can `import x from "react"` or `import { ... } from "@ethisyscore/extension-runtime"`
|
|
145
|
+
* and nothing else off-bundle.
|
|
146
|
+
*/
|
|
147
|
+
declare const CONTRACT_B_RUNTIME_IMPORTS: readonly ["react", "@ethisyscore/extension-runtime"];
|
|
148
|
+
/**
|
|
149
|
+
* Full allowlist of bare specifiers a Contract B plugin bundle may import.
|
|
150
|
+
* Frozen at module load so plugins can't mutate it via a transitive dep.
|
|
151
|
+
*/
|
|
152
|
+
declare const CONTRACT_B_IMPORT_MAP_ALLOWLIST: readonly string[];
|
|
153
|
+
/**
|
|
154
|
+
* The subset of a Contract B (`renderMode: remote-runtime`) plugin manifest
|
|
155
|
+
* that this Vite pass consumes. Manifests are tolerated as a superset — extra
|
|
156
|
+
* fields are ignored so newer-schema manifests still load.
|
|
157
|
+
*/
|
|
158
|
+
interface ContractBManifest {
|
|
159
|
+
renderMode?: string;
|
|
160
|
+
/**
|
|
161
|
+
* Worker bundle declaration. Required when `renderMode === "remote-runtime"`.
|
|
162
|
+
* The `entry` is a relative path (POSIX or platform-native) from the
|
|
163
|
+
* manifest's directory to the plugin's TypeScript/JavaScript entrypoint.
|
|
164
|
+
*
|
|
165
|
+
* Absolute paths, path-traversal, and non-host-origin URLs are rejected at
|
|
166
|
+
* build time — Contract B requires the worker bundle to be a host-origin
|
|
167
|
+
* asset (the import-map enforcement in E4.S4 builds on this guarantee).
|
|
168
|
+
*/
|
|
169
|
+
worker?: {
|
|
170
|
+
entry?: string;
|
|
171
|
+
};
|
|
172
|
+
[key: string]: unknown;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Author-facing options for the Contract B Vite pass.
|
|
176
|
+
*/
|
|
177
|
+
interface ContractBPluginOptions {
|
|
178
|
+
/**
|
|
179
|
+
* Root directory the manifest path is resolved against. When omitted,
|
|
180
|
+
* Vite's `configResolved` populates it from `config.root`.
|
|
181
|
+
*/
|
|
182
|
+
root?: string;
|
|
183
|
+
/**
|
|
184
|
+
* Manifest path. Relative paths resolve against `root`. Defaults to
|
|
185
|
+
* `feature.manifest.json`.
|
|
186
|
+
*/
|
|
187
|
+
manifestPath?: string;
|
|
188
|
+
/**
|
|
189
|
+
* Output prefix for emitted worker assets and the worker-bundle manifest.
|
|
190
|
+
* Defaults to `worker/`.
|
|
191
|
+
*/
|
|
192
|
+
outputPrefix?: string;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Build-time Vite/Rollup plugin pass for EthisysCore Contract B
|
|
196
|
+
* (`renderMode: remote-runtime`) plugins.
|
|
197
|
+
*
|
|
198
|
+
* Behaviour:
|
|
199
|
+
* - For `renderMode: "remote-runtime"`: declares a single ESM worker entry as
|
|
200
|
+
* the Rollup input table. The output is forced to `format: "es"` and
|
|
201
|
+
* `inlineDynamicImports: true` so a Contract B plugin always ships as ONE
|
|
202
|
+
* bundled module — no chunk splitting, no shared chunks, no async imports
|
|
203
|
+
* spread across multiple files. This is the precondition for E4.S4's
|
|
204
|
+
* frozen import map.
|
|
205
|
+
* - For any other `renderMode` (including `host-rendered` and `undefined`):
|
|
206
|
+
* the pass is a no-op. The Wave 0 Contract A path (`ethisysContractAPlugin`)
|
|
207
|
+
* continues to apply without interference. Composition is expected — the
|
|
208
|
+
* recommended template registers both plugins so a manifest can switch
|
|
209
|
+
* render modes without changing its Vite config.
|
|
210
|
+
*
|
|
211
|
+
* The pass also emits a `worker/worker-bundle.json` companion asset listing
|
|
212
|
+
* the bundled entry so the host (or downstream packaging) can inspect what
|
|
213
|
+
* the build produced without re-parsing the bundle.
|
|
214
|
+
*
|
|
215
|
+
* Origin enforcement on the import map (path-pinned host origin, no `data:` /
|
|
216
|
+
* `blob:` imports) is the responsibility of E4.S4 (worker bootstrap) — this
|
|
217
|
+
* pass only blocks remote/absolute paths at the manifest layer so a malformed
|
|
218
|
+
* manifest fails fast.
|
|
219
|
+
*/
|
|
220
|
+
declare function ethisysContractBPlugin(options?: ContractBPluginOptions): Plugin;
|
|
221
|
+
|
|
3
222
|
interface EthisysPluginOptions {
|
|
4
223
|
/**
|
|
5
224
|
* Path to the manifest file, relative to Vite's root directory.
|
|
@@ -23,4 +242,4 @@ interface EthisysPluginOptions {
|
|
|
23
242
|
*/
|
|
24
243
|
declare function ethisysManifestPlugin(options?: EthisysPluginOptions): Plugin;
|
|
25
244
|
|
|
26
|
-
export { type EthisysPluginOptions, ethisysManifestPlugin };
|
|
245
|
+
export { CONTRACT_B_IMPORT_MAP_ALLOWLIST, CONTRACT_B_RUNTIME_IMPORTS, CONTRACT_B_SEMANTIC_PRIMITIVES, type ContractAManifest, type ContractAPluginOptions, type ContractBManifest, type ContractBPluginOptions, type EthisysPluginOptions, type ManifestReactiveRuleRef, type ManifestResourceRef, type ValidationFailure, type ValidationResult, ethisysContractAPlugin, ethisysContractBPlugin, ethisysManifestPlugin, validateDeclarativeResource, validateReactiveRule };
|