@zerosumstudio/spool 0.0.0-stage → 1.0.0
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/LICENSE +21 -0
- package/README.md +600 -2
- package/dist/federation/Remote.svelte +106 -0
- package/dist/federation/Remote.vue +118 -0
- package/dist/federation/core.ts +421 -0
- package/dist/federation/overrides.ts +289 -0
- package/dist/federation/remote.tsx +105 -0
- package/dist/index.js +7798 -0
- package/dist/navigation/binding.react.ts +6 -0
- package/dist/navigation/binding.svelte.ts +13 -0
- package/dist/navigation/binding.vue.ts +12 -0
- package/dist/navigation/history.ts +98 -0
- package/dist/sentry/scrub.ts +157 -0
- package/dist/vite.d.ts +110 -0
- package/dist/vite.js +1068 -0
- package/package.json +87 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 zerosum studio
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,601 @@
|
|
|
1
|
-
#
|
|
1
|
+
# <picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/zerosumstudio/spool/main/.github/assets/zerosum-on-dark.png"><img src="https://raw.githubusercontent.com/zerosumstudio/spool/main/.github/assets/zerosum-on-light.png" alt="" height="32"></picture> spool
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://badge.fury.io/js/@zerosumstudio%2Fspool)
|
|
4
|
+
[](https://github.com/zerosumstudio/spool/actions/workflows/release.yml)
|
|
5
|
+
[](https://codecov.io/gh/zerosumstudio/spool)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
|
|
8
|
+
spool is a small CLI for building micro frontends. It scaffolds a monorepo of Module Federation apps on Vite, runs them together with one command, and keeps all the wiring in a single `spool.json`. Hosts mount remotes with a `<Remote>` component that behaves the same in React, Vue and Svelte, and a `./vite` export reads the manifest, so a workspace carries no copy of spool's own helper code.
|
|
9
|
+
|
|
10
|
+
Live demo: [spool-demo-shell.pages.dev](https://spool-demo-shell.pages.dev), a music UI where the browse view, search, and player bar are independently deployed remotes sharing one player state through [@zerosumstudio/clutch](https://github.com/zerosumstudio/clutch).
|
|
11
|
+
|
|
12
|
+
Coming from `@bkincz/spool` 4.0? See the [migration guide](https://github.com/zerosumstudio/spool/blob/main/docs/migration-1.0.md).
|
|
13
|
+
|
|
14
|
+
## Install
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install -g @zerosumstudio/spool
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Requires Node 26 or newer. Workspaces run on pnpm, npm or yarn.
|
|
21
|
+
|
|
22
|
+
Up to 4.0.0 this was published as `@bkincz/spool`. Run `npm uninstall -g @bkincz/spool` before installing the new name, since both provide the `spool` command.
|
|
23
|
+
|
|
24
|
+
## Quick start
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
spool create acme --host shell --remotes "dashboard, profile"
|
|
28
|
+
cd acme
|
|
29
|
+
spool dev
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Open http://localhost:5173 to see the host with its remotes mounted. Run `spool create` with no arguments to be prompted instead.
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
spool build
|
|
36
|
+
spool preview
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
`build` compiles every app for production, remotes first. `preview` serves the built apps together on localhost.
|
|
40
|
+
|
|
41
|
+
## Commands
|
|
42
|
+
|
|
43
|
+
Every command takes `-h, --help`, and `spool -v` prints the version.
|
|
44
|
+
|
|
45
|
+
| Command | What it does |
|
|
46
|
+
| -------------------------- | -------------------------------------------------------------------------------- |
|
|
47
|
+
| `spool create [dir]` | Scaffold a workspace |
|
|
48
|
+
| `spool add <name>` | Add an app and wire it in |
|
|
49
|
+
| `spool addon [addons...]` | Add extras to an existing workspace |
|
|
50
|
+
| `spool remove <name>` | Remove an app and unwire it from every consumer |
|
|
51
|
+
| `spool dev` | Run all apps together, remotes first |
|
|
52
|
+
| `spool build` | Production build. Remotes first, then hosts, each tier in parallel |
|
|
53
|
+
| `spool preview` | Serve the built apps locally |
|
|
54
|
+
| `spool types` | Type each remote's exposes from its real source |
|
|
55
|
+
| `spool deploy` | Run each app's `deploy` command, remotes first |
|
|
56
|
+
| `spool ci` | Generate GitHub workflows: one checking the workspace, one per deployable app |
|
|
57
|
+
| `spool upgrade [files...]` | Migrate `spool.json`, regenerate spool-owned files and move dependencies forward |
|
|
58
|
+
| `spool doctor` | Check ports, wiring, generated files, shared deps and environment |
|
|
59
|
+
| `spool graph` | Print hosts, remotes, what each consumes and exposes, and the shared list |
|
|
60
|
+
| `spool eject` | Remove the spool dependency and keep everything it generated |
|
|
61
|
+
|
|
62
|
+
### create
|
|
63
|
+
|
|
64
|
+
| Option | Description |
|
|
65
|
+
| ------------------- | -------------------------------------------------------------------------------------------------- |
|
|
66
|
+
| `-n, --name <name>` | Workspace name. Defaults to the folder name |
|
|
67
|
+
| `--host <name>` | Host app, as `name` or `name:framework` |
|
|
68
|
+
| `--remotes <list>` | Comma-separated remotes, each as `name` or `name:framework` |
|
|
69
|
+
| `--framework <fw>` | Default framework: `react`, `svelte` or `vue`. Defaults to `react` |
|
|
70
|
+
| `--addons <list>` | Extras: `ladle`, `playwright`, `lint`, `test`, `turbo`, `state`, `sentry`, `navigation`, or `none` |
|
|
71
|
+
| `--pm <manager>` | `pnpm`, `npm` or `yarn` |
|
|
72
|
+
| `--here` | Scaffold into the current folder. It stops and lists any generated file that already exists |
|
|
73
|
+
| `--no-install` | Skip the install step |
|
|
74
|
+
|
|
75
|
+
Names are lowercase letters, digits and single hyphens, like `acme-frontend`, at most 64 characters. Windows device names such as `con` or `nul` are rejected on every OS, and so is an app named like a shared package.
|
|
76
|
+
|
|
77
|
+
Anything you leave out, spool asks for. Without a terminal it asks for nothing: `create` needs `--name` (or a folder), `--host`, `--remotes` and `--pm`, and `--addons` defaults to none.
|
|
78
|
+
|
|
79
|
+
### add
|
|
80
|
+
|
|
81
|
+
| Option | Description |
|
|
82
|
+
| ------------------ | --------------------------------------------------- |
|
|
83
|
+
| `-t, --type` | `host` or `remote`. Defaults to `remote` |
|
|
84
|
+
| `-p, --port` | Dev server port. Defaults to the next free one |
|
|
85
|
+
| `--host <name>` | Host to wire the remote into. Defaults to the first |
|
|
86
|
+
| `--framework <fw>` | `react`, `svelte` or `vue` |
|
|
87
|
+
| `--no-install` | Skip the install step |
|
|
88
|
+
|
|
89
|
+
`spool add` updates `spool.json`, typings and the host's remote registry, then prints where to render `<Remote name="..." />`. It never edits your components.
|
|
90
|
+
|
|
91
|
+
### addon
|
|
92
|
+
|
|
93
|
+
`spool addon sentry navigation` adds extras to an existing workspace. `--only <list>` limits the per-app files to some apps, and `--no-install` skips the install step. It never rewrites a component you may have edited.
|
|
94
|
+
|
|
95
|
+
### remove
|
|
96
|
+
|
|
97
|
+
`spool remove <name>` takes the app out of `spool.json` and unwires it from every app that lists it as a remote. The folder stays on disk until you pass `--files`, which asks before deleting. Without a terminal, `--files` needs `--yes`.
|
|
98
|
+
|
|
99
|
+
### dev
|
|
100
|
+
|
|
101
|
+
| Option | Description |
|
|
102
|
+
| --------------------- | ---------------------------------------------------------------------------- |
|
|
103
|
+
| `--only <list>` | Run a subset of apps |
|
|
104
|
+
| `--rest <mode>` | Where the remotes a subset needs come from: `built` or `env:<name>` |
|
|
105
|
+
| `--timeout <seconds>` | How long to wait for each remote's manifest before giving up. Defaults to 20 |
|
|
106
|
+
| `--no-ladle` | Skip the component workshop |
|
|
107
|
+
| `--kill` | Stop a previous run and free the ports, then exit |
|
|
108
|
+
|
|
109
|
+
Working on one remote does not need every server up. `--rest built` previews the other remotes' `dist/`, and `--rest env:staging` loads each one from its `urls.staging` (or `url`):
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
spool dev --only shell,dashboard --rest env:staging
|
|
113
|
+
spool dev --only dashboard --rest built
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
`spool dev` writes `.spool/dev.pid` while it runs. `spool dev --kill` stops only processes it started: each one is checked against the start time and command line recorded in the pidfile. A manifest port held by anything else is reported, left running, and fails with `PORT_IN_USE`.
|
|
117
|
+
|
|
118
|
+
### build
|
|
119
|
+
|
|
120
|
+
| Option | Description |
|
|
121
|
+
| ------------------- | --------------------------------------------------------- |
|
|
122
|
+
| `--only <list>` | Build a subset of apps |
|
|
123
|
+
| `--env <name>` | Select each remote's `urls.<name>` for this build |
|
|
124
|
+
| `--concurrency <n>` | Apps built at once. Defaults to half the cores, at most 4 |
|
|
125
|
+
| `--json` | Print one JSON document. See [Scripting](#scripting) |
|
|
126
|
+
|
|
127
|
+
`build` and `dev` run `spool types` first, then start each app's own `vite` directly. They do not read the apps' `package.json` scripts. After a build, spool compares what each app resolved for every shared dep and fails only when one app would load a version another cannot accept. An exported `SPOOL_ENV` counts like `--env`.
|
|
128
|
+
|
|
129
|
+
### preview
|
|
130
|
+
|
|
131
|
+
`spool preview` serves each app's `dist/` on its manifest port, remotes first. It takes `--only <list>` and `--kill`, and fails when an app has no `dist/`. A remote that has a deployed `url` in `spool.json` is loaded from there by hosts built with `spool build`, so preview warns about it.
|
|
132
|
+
|
|
133
|
+
### deploy
|
|
134
|
+
|
|
135
|
+
| Option | Description |
|
|
136
|
+
| --------------- | ---------------------------------------------------- |
|
|
137
|
+
| `--only <list>` | Deploy a subset of apps |
|
|
138
|
+
| `--env <name>` | Exposed to the command as `SPOOL_ENV`, and recorded |
|
|
139
|
+
| `--json` | Print one JSON document. See [Scripting](#scripting) |
|
|
140
|
+
|
|
141
|
+
Apps deploy one at a time, remotes first, and the run stops at the first failure. `--env` also writes what shipped to `.spool/deploys.json`: the commit, the url, the time, and the shared dep versions the app was built with. Commit that file. Before each deploy spool compares the app's shared versions with what the other apps last shipped to that environment, and refuses when one would load a version another cannot accept, naming both.
|
|
142
|
+
|
|
143
|
+
### upgrade
|
|
144
|
+
|
|
145
|
+
| Option | Description |
|
|
146
|
+
| ------------- | ---------------------------------------------------------------------------------- |
|
|
147
|
+
| `--dry-run` | Report what would change without writing |
|
|
148
|
+
| `--downgrade` | Write this CLI's dependency ranges even when the workspace is ahead of them |
|
|
149
|
+
| `--force` | Overwrite generated files that have local changes. Name paths after it to limit it |
|
|
150
|
+
|
|
151
|
+
See [Checks and upgrades](#checks-and-upgrades).
|
|
152
|
+
|
|
153
|
+
### doctor, graph, eject, ci and types
|
|
154
|
+
|
|
155
|
+
| Command | Options |
|
|
156
|
+
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
157
|
+
| `spool doctor` | `--fix` repairs what it safely can, `--dry-run` shows those changes first, `--remote` also fetches each deployed remote url, `--env <name>` checks `urls.<name>` instead of `url`, `--json` |
|
|
158
|
+
| `spool graph` | `--json`, `--dot` for Graphviz |
|
|
159
|
+
| `spool eject` | `--yes` skips the confirmation. Required without a terminal |
|
|
160
|
+
| `spool ci` | `--force` overwrites existing workflow files |
|
|
161
|
+
| `spool types` | `--only <list>` |
|
|
162
|
+
|
|
163
|
+
## The manifest
|
|
164
|
+
|
|
165
|
+
Everything lives in one `spool.json`. Each app's `vite.config.ts` reads it through [`spoolApp()`](#vite-config) when Vite starts, so the manifest is the only thing you edit. The file is validated as it loads, and an unknown key is an error.
|
|
166
|
+
|
|
167
|
+
<!-- prettier-ignore -->
|
|
168
|
+
```json
|
|
169
|
+
{
|
|
170
|
+
"name": "acme",
|
|
171
|
+
"version": 2,
|
|
172
|
+
"packageManager": "pnpm",
|
|
173
|
+
"shared": ["react", "react-dom"],
|
|
174
|
+
"apps": {
|
|
175
|
+
"shell": { "type": "host", "path": "apps/shell", "port": 5173, "remotes": ["dashboard"] },
|
|
176
|
+
"dashboard": { "type": "remote", "path": "apps/dashboard", "port": 5174, "exposes": { "./App": "./src/app/app.tsx" },
|
|
177
|
+
"url": "https://dashboard.example.com/mf-manifest.json" }
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
| Field | Description |
|
|
183
|
+
| ---------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
|
|
184
|
+
| `name` | Workspace name |
|
|
185
|
+
| `version` | Required, and `2`. A file without it, or with `1`, fails with `MANIFEST_VERSION`. Run `spool upgrade` |
|
|
186
|
+
| `packageManager` | `pnpm` (default), `npm` or `yarn` |
|
|
187
|
+
| `bundler` | `vite`, the only value and the default |
|
|
188
|
+
| `shared` | Deps shared as singletons across apps. Defaults to `react` and `react-dom`. A dep an app does not install is dropped for it |
|
|
189
|
+
| `shareStrategy` | `loaded-first` (default) or `version-first` |
|
|
190
|
+
| `csp` | `default` or `strict`. See [Headers and CSP](#headers-and-csp) |
|
|
191
|
+
| `addons` | Extras enabled in this workspace. See [Addons](#addons) |
|
|
192
|
+
| `server` | Dev and preview server settings every app gets. See [Server settings](#server-settings) |
|
|
193
|
+
| `overrides` | `{ "origins": [...] }`. Origins a runtime remote override may load from. See [Overrides](#overrides) |
|
|
194
|
+
| `apps.<name>.type` | `host` consumes remotes, `remote` exposes modules |
|
|
195
|
+
| `apps.<name>.framework` | `react` (default), `svelte` or `vue` |
|
|
196
|
+
| `apps.<name>.path` | Folder, relative to the workspace. Lowercase, and never outside it |
|
|
197
|
+
| `apps.<name>.port` | Dev server port, 1 to 65535 |
|
|
198
|
+
| `apps.<name>.remotes` | Remotes this app mounts. A remote can consume remotes too |
|
|
199
|
+
| `apps.<name>.exposes` | Modules a remote exposes, keys starting with `./` and values a file inside the app |
|
|
200
|
+
| `apps.<name>.url` | Deployed `mf-manifest.json`, used by host production builds |
|
|
201
|
+
| `apps.<name>.urls` | Per-environment manifests, like `{ "staging": "https://..." }`. `--env` selects one |
|
|
202
|
+
| `apps.<name>.deploy` | Shell command `spool deploy` runs in the app folder |
|
|
203
|
+
| `apps.<name>.deployEnv` | Upper-case secret names the generated deploy workflow passes to `deploy`. Defaults to none |
|
|
204
|
+
| `apps.<name>.headers` | Extra response headers for this app, in dev, preview and the built `_headers` |
|
|
205
|
+
| `apps.<name>.frameAncestors` | Who may frame this app: `self`, `none`, origins, or `["edge"]` alone. Defaults to `self` |
|
|
206
|
+
|
|
207
|
+
`url` and `urls` values are http or https urls with no username or password. Header names are letters, digits and hyphens, and values cannot hold line breaks or control characters.
|
|
208
|
+
|
|
209
|
+
The manifest also fails right away, naming the app, for a remote that names itself or is not in the workspace, a cycle through `remotes`, an expose outside its app folder, or an app `path` outside the workspace. `spool doctor` catches the rest after hand-editing.
|
|
210
|
+
|
|
211
|
+
### Server settings
|
|
212
|
+
|
|
213
|
+
`server` holds what every app's dev and preview server needs, so you never edit a generated `vite.config.ts`.
|
|
214
|
+
|
|
215
|
+
| Field | Description |
|
|
216
|
+
| --------- | ------------------------------------------------------------------------------------------------------- |
|
|
217
|
+
| `proxy` | Vite proxy entries. Each is a target string or `{ target, changeOrigin, secure, ws }` |
|
|
218
|
+
| `headers` | Headers for dev and preview only, not the built `_headers` |
|
|
219
|
+
| `host` | `true`, `false` or a host name |
|
|
220
|
+
| `cors` | List of allowed origins, like `["http://localhost:5173"]`. Defaults to every app's own localhost origin |
|
|
221
|
+
| `fs` | `{ "allow": [...] }`: folders outside the workspace the dev server may serve |
|
|
222
|
+
|
|
223
|
+
```json
|
|
224
|
+
{
|
|
225
|
+
"server": {
|
|
226
|
+
"proxy": {
|
|
227
|
+
"/api": { "target": "${ACME_BACKEND:-http://localhost:3000}", "changeOrigin": true }
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
`${VAR}` and `${VAR:-fallback}` read the environment at startup in `proxy`, `host` and `fs.allow`. Only variables named `SPOOL_*` or `VITE_*` expand, so a manifest edit cannot pull in an unrelated secret. Any other name becomes its fallback, or an empty string.
|
|
234
|
+
|
|
235
|
+
### Serving files outside the workspace
|
|
236
|
+
|
|
237
|
+
Vite's dev server only serves files inside the workspace, so a module linked in from a sibling folder gets a 403. List the folders in `server.fs.allow`, relative to the folder `spool.json` is in:
|
|
238
|
+
|
|
239
|
+
```text
|
|
240
|
+
contracts/packages/schemas shared zod schemas, linked with "link:../contracts/packages/schemas"
|
|
241
|
+
frontend/spool.json
|
|
242
|
+
frontend/apps/shell
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
```json
|
|
246
|
+
{
|
|
247
|
+
"server": {
|
|
248
|
+
"fs": { "allow": ["../contracts/packages"] }
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
Every app's dev server then allows the workspace root, as Vite does by default, plus each folder you list, as absolute paths. Vite's `fs.deny` defaults (`.env`, `.env.*`, certificates, `.git`) still apply inside them. `preview` serves only the built `dist/` and ignores the setting.
|
|
254
|
+
|
|
255
|
+
An empty entry or the filesystem root is rejected. A folder that does not exist yet is only a `spool doctor` warning, since Vite ignores it. Entries may use `${VAR}`. `doctor` skips those, and the dev server refuses one that expands to nothing.
|
|
256
|
+
|
|
257
|
+
## Addons
|
|
258
|
+
|
|
259
|
+
Pick extras at the `spool create` prompt, or pass `--addons "ladle, playwright, lint, test, turbo, state, sentry, navigation"`. `spool addon` adds one to an existing workspace later. Federation is not an addon: every host has it.
|
|
260
|
+
|
|
261
|
+
- **Ladle**: a React design-system package in `packages/ui` with a component workshop. `spool dev` starts it alongside your apps, or open it on its own with `pnpm --filter ui ladle`. It needs at least one React app.
|
|
262
|
+
- **Playwright**: e2e tests in `packages/e2e` that boot the workspace and check every remote mounts. Run `npx playwright install` once, then `pnpm --filter e2e test`. It needs a host.
|
|
263
|
+
- **ESLint**: one flat config at the root with `strictTypeChecked` rules and the plugin each framework you use needs. It adds Prettier and the `format` and `format:check` scripts.
|
|
264
|
+
- **Vitest**: a `vitest.config.ts` per app, separate from `vite.config.ts` because federation cannot run under a test. Any app with `remotes` gets them stubbed in `src/test`, regenerated when the remote list changes.
|
|
265
|
+
- **Turborepo**: a `turbo.json` that puts `spool.json` and the `SPOOL_ENV` and `SPOOL_REMOTE_*` variables into the cache key, so a wiring change never gets a stale hit. `spool dev` and `spool build` are unchanged. Turbo covers the tasks spool does not run.
|
|
266
|
+
- **Shared state**: [@zerosumstudio/clutch](https://github.com/zerosumstudio/clutch) shared as a singleton, plus `src/state/counter.ts` in every app, a `sharedStore` that resolves every copy to one store per page. It validates its shape with a plain predicate, so swap in a zod or valibot schema if you want one. Bump its `version` and add a `migrate` when the shape changes.
|
|
267
|
+
- **Sentry**: error reporting wired into every app. See [Sentry](#sentry).
|
|
268
|
+
- **Navigation**: one url every bundle on the page agrees on, in `src/navigation`. `navigate` and `useLocation` ride on `window.history`, so back and forward work across remotes and deep links resolve on load. `matchRoute` returns the value at the longest url prefix that matches, such as a `RemoteName`.
|
|
269
|
+
|
|
270
|
+
Addons picked together at create time compose. With the state addon every remote renders a working counter and the host shows the live count, and the Playwright spec gains a test proving a remote's click updates the host.
|
|
271
|
+
|
|
272
|
+
A generated workspace has Node `>=26` in `engines` and `.nvmrc`, a root named `<name>-workspace`, and per-app `type-check` scripts: `tsc` for React, `vue-tsc` for Vue and `svelte-check` for Svelte. Each app's `package.json` also has `dev`, `build` and `preview` scripts that run `vite`, for use outside spool.
|
|
273
|
+
|
|
274
|
+
## Vite config
|
|
275
|
+
|
|
276
|
+
Each app's `vite.config.ts` calls `spoolApp()` from `@zerosumstudio/spool/vite`. The export reads and validates `spool.json` with the CLI's own parser, so a typo fails at config load with the same message `spool doctor` gives, prefixed with `[spool]`.
|
|
277
|
+
|
|
278
|
+
```ts
|
|
279
|
+
import { federation } from '@module-federation/vite'
|
|
280
|
+
import react from '@vitejs/plugin-react'
|
|
281
|
+
import { spoolApp } from '@zerosumstudio/spool/vite'
|
|
282
|
+
import { defineConfig } from 'vite'
|
|
283
|
+
|
|
284
|
+
export default defineConfig(({ command }) => {
|
|
285
|
+
const app = spoolApp('shell', { root: import.meta.dirname, command })
|
|
286
|
+
|
|
287
|
+
return {
|
|
288
|
+
server: app.server,
|
|
289
|
+
preview: app.server,
|
|
290
|
+
plugins: [react(), federation(app.federation), app.plugin],
|
|
291
|
+
build: { target: 'esnext' },
|
|
292
|
+
}
|
|
293
|
+
})
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
| Return value | What it holds |
|
|
297
|
+
| ------------ | --------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
298
|
+
| `server` | Port, `strictPort`, the `cors` allowlist, `proxy`, `fs`, and the headers. Use it for both `server` and `preview` |
|
|
299
|
+
| `federation` | Options for `federation()`: name, exposes, remotes, `shared` as singletons, `shareStrategy`, and the manifest |
|
|
300
|
+
| `plugin` | Defines the override origins, serves the same per-path headers in dev and preview, and writes `_headers` into the build. Keep it in `plugins` |
|
|
301
|
+
|
|
302
|
+
`command` decides where a host finds its remotes. A build reads `SPOOL_REMOTE_<NAME>`, then the remote's `urls` entry for `SPOOL_ENV`, then its `url`, then `http://localhost:<port>/mf-manifest.json`. A dev server skips the deployed urls and uses the environment variable or localhost. `SPOOL_REMOTE_<NAME>` must be an http or https url with no credentials. `spoolApp` never shares `svelte`, whatever `shared` lists.
|
|
303
|
+
|
|
304
|
+
`spool eject` writes the helper to `spool.vite.js` and `spool.vite.d.ts` at the workspace root and points each `vite.config.ts` at it, for a workspace that wants to own the code.
|
|
305
|
+
|
|
306
|
+
## Federation
|
|
307
|
+
|
|
308
|
+
Every host has `<Remote>`, the remote registry and `preloadRemote`, in `src/federation`. Mount a remote by name, across frameworks. Every module a remote exposes gets a name: `<Remote name="dashboard" />` is its app, and `<Remote name="dashboard/Panel" />` is a widget it also offers. The names make up a generated `RemoteName` type, so a typo like `<Remote name="dashbaord" />` or `preloadRemote("serach")` does not compile. A name that only arrives at runtime goes through `isRemoteName(name)` first. An unknown name renders nothing, and warns in dev.
|
|
309
|
+
|
|
310
|
+
React remotes expose a component. Vue and Svelte remotes expose a mount function that takes the target element and props once, and returns an unmount function. Hosts mount each remote by its contract, and a non-React host gets a small React bridge for a React remote.
|
|
311
|
+
|
|
312
|
+
### React
|
|
313
|
+
|
|
314
|
+
```tsx
|
|
315
|
+
import { Remote } from '@/federation'
|
|
316
|
+
|
|
317
|
+
export function Dashboard() {
|
|
318
|
+
return (
|
|
319
|
+
<Remote
|
|
320
|
+
name="dashboard"
|
|
321
|
+
props={{ compact: true }}
|
|
322
|
+
fallback={<p>Loading</p>}
|
|
323
|
+
renderError={(error, retry) => (
|
|
324
|
+
<button type="button" onClick={retry}>
|
|
325
|
+
{error.code}: try again
|
|
326
|
+
</button>
|
|
327
|
+
)}
|
|
328
|
+
onError={(error, name) => console.warn(name, error.code)}
|
|
329
|
+
/>
|
|
330
|
+
)
|
|
331
|
+
}
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
| Prop | Description |
|
|
335
|
+
| ------------- | ------------------------------------------------------------------------------------- |
|
|
336
|
+
| `name` | A `RemoteName` |
|
|
337
|
+
| `props` | Props for a component remote, or the second argument of a mount function |
|
|
338
|
+
| `fallback` | Rendered while the remote loads. Defaults to nothing |
|
|
339
|
+
| `renderError` | `(error, retry) => ReactNode` for a load failure. Defaults to a message with a button |
|
|
340
|
+
| `onError` | `(error, name)`, called once per failure |
|
|
341
|
+
|
|
342
|
+
An error a remote throws while rendering, after it has loaded, is not a load failure. `<Remote>` does not report it and passes it on, exactly as thrown, to your app's own error boundaries. Give the host an error boundary around its routes, or React unmounts the page.
|
|
343
|
+
|
|
344
|
+
### Vue
|
|
345
|
+
|
|
346
|
+
```vue
|
|
347
|
+
<script setup lang="ts">
|
|
348
|
+
import { Remote } from '@/federation'
|
|
349
|
+
</script>
|
|
350
|
+
|
|
351
|
+
<template>
|
|
352
|
+
<Remote name="dashboard" :props="{ compact: true }">
|
|
353
|
+
<template #fallback>
|
|
354
|
+
<p>Loading</p>
|
|
355
|
+
</template>
|
|
356
|
+
<template #error="{ error, retry }">
|
|
357
|
+
<button type="button" @click="retry">{{ error.code }}: try again</button>
|
|
358
|
+
</template>
|
|
359
|
+
</Remote>
|
|
360
|
+
</template>
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
| API | Description |
|
|
364
|
+
| ---------------- | ------------------------------------------------------------- |
|
|
365
|
+
| `name`, `props` | As in React |
|
|
366
|
+
| `#fallback` slot | Rendered while the remote loads |
|
|
367
|
+
| `#error` slot | Scope `{ error, retry }`. Defaults to a message with a button |
|
|
368
|
+
| `@error` event | `(error, name)`, emitted once per failure |
|
|
369
|
+
|
|
370
|
+
### Svelte
|
|
371
|
+
|
|
372
|
+
```svelte
|
|
373
|
+
<script lang="ts">
|
|
374
|
+
import { Remote } from '@/federation'
|
|
375
|
+
</script>
|
|
376
|
+
|
|
377
|
+
<Remote name="dashboard" props={{ compact: true }}>
|
|
378
|
+
{#snippet fallback()}
|
|
379
|
+
<p>Loading</p>
|
|
380
|
+
{/snippet}
|
|
381
|
+
{#snippet error(failure, retry)}
|
|
382
|
+
<button type="button" onclick={retry}>{failure.code}: try again</button>
|
|
383
|
+
{/snippet}
|
|
384
|
+
</Remote>
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
| Prop | Description |
|
|
388
|
+
| ------------------ | ----------------------------------------------------- |
|
|
389
|
+
| `name`, `props` | As in React |
|
|
390
|
+
| `fallback` snippet | Rendered while the remote loads |
|
|
391
|
+
| `error` snippet | `(error, retry)`. Defaults to a message with a button |
|
|
392
|
+
| `onError` | `(error, name)`, called once per failure |
|
|
393
|
+
|
|
394
|
+
### Loading, errors and retry
|
|
395
|
+
|
|
396
|
+
A load that takes longer than 15 seconds rejects with `TIMEOUT`. Every failure is a `RemoteError` with a `code`, the `remote` id it was loading, a `needsReload` flag and the original `cause`.
|
|
397
|
+
|
|
398
|
+
| Code | Meaning |
|
|
399
|
+
| -------------- | --------------------------------------------------------------------- |
|
|
400
|
+
| `TIMEOUT` | The manifest or entry did not load within 15 seconds |
|
|
401
|
+
| `ENTRY_FAILED` | The remote's manifest or `remoteEntry.js` could not be fetched or run |
|
|
402
|
+
| `CHUNK_FAILED` | The entry loaded, but one of its modules did not |
|
|
403
|
+
| `NOT_FOUND` | No remote is registered under that name |
|
|
404
|
+
|
|
405
|
+
`needsReload` is true when the remote's entry had already loaded before the failure, since a browser such as WebKit keeps a failed module import for the life of the page. The default error UI then shows "Reload page" in place of "Try again", and a custom one should do the same.
|
|
406
|
+
|
|
407
|
+
`retry` fetches the remote's manifest and entry again, so once the remote is back it renders without a page reload. A failed `preloadRemote` does not stick: the first mount after it loads the remote again by itself, so a short outage during a boot preload recovers without anyone clicking retry. Every host on the page, nested hosts included, shares what it knows about each remote's entry, so once any of them has loaded a remote the rest reuse it and no retry evaluates it twice. If one expose of a loaded remote fails, only that expose is retried.
|
|
408
|
+
|
|
409
|
+
`src/federation/report.ts` is called with every failed load before `onError`. It logs with `console.error`, or with the Sentry addon sends the error with a `remote` tag. It is spool-owned like the rest of `src/federation`, and `spool upgrade` asks before replacing an edited copy.
|
|
410
|
+
|
|
411
|
+
### Svelte is never shared
|
|
412
|
+
|
|
413
|
+
A Svelte app mounts with its own Svelte runtime. Sharing `svelte` across federation splits the runtime between a remote's `mount` and its components, so `spoolApp` never shares `svelte` or a `svelte/*` subpath, and `create`, `add` and `upgrade` keep it out of `shared`. A page with two Svelte apps carries two copies of the runtime, which share nothing but the DOM node they are given. Share state through `@zerosumstudio/clutch`, which does not depend on Svelte. The reasoning is in [ADR 8](https://github.com/zerosumstudio/spool/blob/main/docs/adr/0008-svelte-not-shared.md).
|
|
414
|
+
|
|
415
|
+
### Composing remotes
|
|
416
|
+
|
|
417
|
+
Composing remotes is your own code, one region or many, persistent or routed:
|
|
418
|
+
|
|
419
|
+
```tsx
|
|
420
|
+
import { useLocation, matchRoute } from '@/navigation'
|
|
421
|
+
import { Remote, preloadRemote, type RemoteName } from '@/federation'
|
|
422
|
+
|
|
423
|
+
const routes: Record<string, RemoteName> = { '/': 'browse', '/search': 'search' }
|
|
424
|
+
|
|
425
|
+
export function Layout() {
|
|
426
|
+
const active = matchRoute(useLocation().pathname, routes)
|
|
427
|
+
|
|
428
|
+
return (
|
|
429
|
+
<>
|
|
430
|
+
<Remote name="player" props={{ compact: true }} /> {/* always mounted */}
|
|
431
|
+
{active && <Remote name={active} />} {/* swaps with the url */}
|
|
432
|
+
<a href="/search" onMouseEnter={() => preloadRemote('search')}>
|
|
433
|
+
Search
|
|
434
|
+
</a>
|
|
435
|
+
</>
|
|
436
|
+
)
|
|
437
|
+
}
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
### Types across the boundary
|
|
441
|
+
|
|
442
|
+
`spool types` emits declarations for every expose using the workspace's TypeScript into `.spool/types`, then rewrites each consumer's `src/remotes.d.ts` to point at them. `<Remote name="dashboard/Panel" props={...} />` is typed against the real component, and a changed prop fails type-check in the host. `spool dev` and `spool build` run it first. Without a TypeScript install spool falls back to prop-less typing and says so.
|
|
443
|
+
|
|
444
|
+
## Overrides
|
|
445
|
+
|
|
446
|
+
Point a running host at a different build of one remote from the browser console. The override lives in `localStorage` and only affects you:
|
|
447
|
+
|
|
448
|
+
```ts
|
|
449
|
+
import { setRemoteOverride, listRemoteOverrides } from '@/federation'
|
|
450
|
+
|
|
451
|
+
setRemoteOverride('dashboard', 'https://dashboard-pr-42.example.com/mf-manifest.json')
|
|
452
|
+
listRemoteOverrides() // { dashboard: { url, expiresAt } }
|
|
453
|
+
setRemoteOverride('dashboard', null) // back to the build's url
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
Reload the page after setting one. An override is never read from the page url, so a crafted link cannot swap in someone else's remote.
|
|
457
|
+
|
|
458
|
+
- **Origins are an allowlist.** The url's origin must be in `overrides.origins` in `spool.json`, with no list meaning no overrides. A build allows only that list. A dev server also allows every app's own localhost origin.
|
|
459
|
+
- **The url is checked.** It must be https (http to localhost, in dev only), carry no credentials, query or fragment, and end in `mf-manifest.json` or `remoteEntry.js`. The remote's manifest must also load its code from a listed origin.
|
|
460
|
+
- **It expires in 24 hours.** `setRemoteOverride(name, url, { ttlMs })` can only shorten that. An expired or invalid override is removed.
|
|
461
|
+
- **It announces itself.** The console shows `[federation] "dashboard" is overridden to ... until ...` once per remote.
|
|
462
|
+
|
|
463
|
+
```json
|
|
464
|
+
{ "overrides": { "origins": ["https://dashboard-pr-42.example.com"] } }
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
A listed origin can run code in your page, so list only origins that serve your own builds. With `csp: "strict"` they are added to `script-src` and `connect-src`.
|
|
468
|
+
|
|
469
|
+
## Headers and CSP
|
|
470
|
+
|
|
471
|
+
The `./vite` plugin writes `dist/_headers` from `spool.json` at build, so the shipped file always follows the manifest. Cloudflare Pages and Netlify read it as-is. On Vercel, set the same headers in `vercel.json`. Nothing about headers is generated into your workspace.
|
|
472
|
+
|
|
473
|
+
| Path | Headers |
|
|
474
|
+
| -------------------------------------- | ----------------------------------------------------------------------------------------- |
|
|
475
|
+
| `/mf-manifest.json`, `/remoteEntry.js` | `Cache-Control: no-cache` |
|
|
476
|
+
| `/assets/*` | `Cache-Control: public, max-age=31536000, immutable` |
|
|
477
|
+
| `/*` | `X-Content-Type-Options: nosniff`, `Content-Security-Policy`, and the app's own `headers` |
|
|
478
|
+
|
|
479
|
+
A remote's manifest, entry and `/assets/*` also get `Access-Control-Allow-Origin: *`, since hosts fetch them cross-origin. A header in `apps.<name>.headers` with the same name as a generated one replaces it.
|
|
480
|
+
|
|
481
|
+
The default policy for every app is `frame-ancestors 'self'; object-src 'none'; base-uri 'self'`. `csp: "strict"` adds `script-src` and `connect-src`:
|
|
482
|
+
|
|
483
|
+
- **Sources**: `'self'` plus the origin of every remote the app consumes (its `url`, each `urls` entry, and any `SPOOL_REMOTE_<NAME>`) and every `overrides.origins` entry.
|
|
484
|
+
- **`connect-src`** also allows the Sentry origin, read from `VITE_SENTRY_DSN` when the sentry addon is on.
|
|
485
|
+
|
|
486
|
+
A host that must be framed by a partner sets `frameAncestors: ["https://partner.example"]`. When an edge layer in front of the app decides that per request, set `frameAncestors: ["edge"]` and spool leaves `frame-ancestors` out of the policy, since two `frame-ancestors` headers intersect and would block the frame.
|
|
487
|
+
|
|
488
|
+
`spool preview` serves the same policy, caching and custom headers as `_headers`, strict sources included. CORS is the exception: preview follows the `server.cors` list, not `*`. `spool dev` serves them too, except the strict `script-src` and `connect-src` and the immutable `/assets/*` cache, which hot reload cannot work with.
|
|
489
|
+
|
|
490
|
+
Both `build` and `preview` read `VITE_SENTRY_DSN` from the environment, then the app's `.env` files, to allow the Sentry origin. If preview finds none under `csp: "strict"`, it warns that `connect-src` leaves Sentry out, which happens when the DSN only exists as a build-time variable.
|
|
491
|
+
|
|
492
|
+
## Sentry
|
|
493
|
+
|
|
494
|
+
The sentry addon gives each app its framework SDK (Sentry 11), a `src/sentry.ts` called from its entry, a `src/sentry-scrub.ts` and a `.env.example`. Set `VITE_SENTRY_DSN` per app. Without it, `initSentry` does nothing.
|
|
495
|
+
|
|
496
|
+
Errors are tagged `mfe` with the app whose chunk threw them, so a remote failing inside a host is filed under the remote, and `remote` with the name a host asked for and could not load.
|
|
497
|
+
|
|
498
|
+
What stays out of events:
|
|
499
|
+
|
|
500
|
+
- `dataCollection` is off for user info, cookies, request and response headers, and bodies. The `Console` integration is removed.
|
|
501
|
+
- Every url is cut to its origin and path: the request url, urls in exception and event messages, and breadcrumb urls and messages. A request's query string and `Referer` header are removed.
|
|
502
|
+
- The Vue SDK's `attachProps` is off, and any component props are stripped from the event.
|
|
503
|
+
|
|
504
|
+
Tracing is off by default. If you turn it on, wire `scrubEvent` from `src/sentry-scrub.ts` into `beforeSendTransaction` (or the span hook your Sentry version offers), so transaction urls lose their query strings too. Nothing scrubs them for you.
|
|
505
|
+
|
|
506
|
+
With `SENTRY_AUTH_TOKEN`, `SENTRY_ORG` and `SENTRY_PROJECT` in CI, `spool build` uploads hidden source maps, deletes them from `dist/`, and tags the release with `SENTRY_RELEASE`, or the short git sha when that is unset.
|
|
507
|
+
|
|
508
|
+
## Deploying
|
|
509
|
+
|
|
510
|
+
Every app builds to a plain static site. Give apps a `deploy` command in `spool.json`, deploy the remotes, set each remote's `url` to its deployed `mf-manifest.json`, then rebuild and deploy the host:
|
|
511
|
+
|
|
512
|
+
```bash
|
|
513
|
+
spool build
|
|
514
|
+
spool deploy --env production
|
|
515
|
+
```
|
|
516
|
+
|
|
517
|
+
A host resolves each remote in this order:
|
|
518
|
+
|
|
519
|
+
1. `SPOOL_REMOTE_<NAME>` env var (dev and build)
|
|
520
|
+
2. the remote's `urls` entry for `--env` or `SPOOL_ENV` (production builds only)
|
|
521
|
+
3. the remote's `url` in `spool.json` (production builds only)
|
|
522
|
+
4. `http://localhost:<port>/mf-manifest.json`
|
|
523
|
+
|
|
524
|
+
For staging and friends, give a remote per-environment urls and build with `spool build --env staging`. `spool deploy --env staging` passes the name to your deploy commands as `SPOOL_ENV`, and `spool doctor --remote --env staging` probes those urls. Example deploy commands: `wrangler pages deploy dist --project-name=<p>`, `netlify deploy --prod --dir=dist`, `vercel deploy dist --prod`, `aws s3 sync dist s3://<bucket> --delete`.
|
|
525
|
+
|
|
526
|
+
### CI
|
|
527
|
+
|
|
528
|
+
`spool ci` writes a check workflow that runs whichever of `doctor`, `type-check`, `lint`, `test` and `build` your root `package.json` has, plus a path-filtered deploy workflow per app with a `deploy` command. Every action is pinned to a commit sha. Deploy jobs wait for the check job, run only on `main`, have read-only permissions, never cancel a running deploy, and trigger on the app's folder, the workspace packages and the workspace files.
|
|
529
|
+
|
|
530
|
+
A deploy job passes no secrets by default. List the ones its command reads in `deployEnv`, then rerun `spool ci --force`:
|
|
531
|
+
|
|
532
|
+
```json
|
|
533
|
+
{
|
|
534
|
+
"apps": {
|
|
535
|
+
"dashboard": {
|
|
536
|
+
"deploy": "wrangler pages deploy dist --project-name=dashboard",
|
|
537
|
+
"deployEnv": ["CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID"]
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
Deploy jobs run in the `production` GitHub environment, which accepts every branch until you restrict it. In Settings > Environments, set Deployment branches to `main` and add required reviewers. Without that, anyone with write access can run the workflow from their own branch and read the deploy secrets.
|
|
544
|
+
|
|
545
|
+
## Checks and upgrades
|
|
546
|
+
|
|
547
|
+
- `spool doctor` checks ports (including one another process holds), wiring, exposed files, registry and typings, generated files against what spool wrote, shared dep versions across every workspace member, shared entries an app never imports, a leftover `spool.vite.ts` or `public/_headers`, and the environment the addons need. `--fix` repairs what it safely can, `--dry-run` shows the changes first, and `--json` prints the problems for CI.
|
|
548
|
+
- `spool upgrade` migrates a version 1 `spool.json`, regenerates spool-owned files and syncs dependency ranges. It never overwrites your edits: spool hashes every file it writes into `.spool/generated.json`, so a later run can tell its own output from yours. Edited files are offered, not replaced. `--force` skips the asking and takes paths to limit it. Commit `.spool/generated.json`. `.spool/types` and pidfiles are ignored.
|
|
549
|
+
- Versions only move forward, onto the highest range already in the workspace, so a workspace ahead of spool stays ahead. `--downgrade` writes spool's own ranges regardless. Prereleases and `>=` ranges are never chosen as the target.
|
|
550
|
+
- `spool graph` shows the workspace as a tree, or as `--dot` for Graphviz.
|
|
551
|
+
- For the apps a change touches, use `pnpm --filter "...[<ref>]"` or `turbo --affected`.
|
|
552
|
+
- `spool eject` removes the spool dependency and leaves the rest in place. `spool.json`, `spool.workspace.ts` and every generated config keep working without the CLI. It deletes `.spool/`, and swaps the `dev` and `build` scripts for plain package manager ones, which run apps in whatever order the manager picks.
|
|
553
|
+
|
|
554
|
+
`spool.workspace.ts` reads the manifest when you import it, so nothing built on it goes stale:
|
|
555
|
+
|
|
556
|
+
```ts
|
|
557
|
+
import { apps, hosts, remotes, srcDirs, app, root } from '../../spool.workspace'
|
|
558
|
+
```
|
|
559
|
+
|
|
560
|
+
Each app has `name`, `type`, `framework`, `port`, absolute `dir` and `src`, `remotes`, and `exposes`. The module also exports `workspaceName`, `shared` and `addons`.
|
|
561
|
+
|
|
562
|
+
## Scripting
|
|
563
|
+
|
|
564
|
+
`build`, `deploy`, `doctor` and `graph` take `--json`. The run prints exactly one document to stdout, with logs and the output of commands spool runs on stderr, and never prompts:
|
|
565
|
+
|
|
566
|
+
```json
|
|
567
|
+
{ "ok": true, "command": "build", "results": [{ "name": "dashboard", "ok": true, "durationMs": 4210 }] }
|
|
568
|
+
{ "ok": false, "command": "build", "error": { "code": "BUILD_FAILED", "message": "..." }, "results": [] }
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
| Command | Fields besides `ok` and `command` |
|
|
572
|
+
| ----------------- | ------------------------------------------------------------------------------------------- |
|
|
573
|
+
| `build`, `deploy` | `results`: `{ name, ok, durationMs, error? }` per app, also on a failure |
|
|
574
|
+
| `doctor` | `problems`: `{ level, code, app, message }`. Fails with `CHECK_FAILED` when any is an error |
|
|
575
|
+
| `graph` | `name`, `apps` (`name`, `type`, `framework`, `port`, `consumes`, `exposes`) and `shared` |
|
|
576
|
+
|
|
577
|
+
A bad flag under `--json` gets the failure document too.
|
|
578
|
+
|
|
579
|
+
| Exit code | Meaning |
|
|
580
|
+
| --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
581
|
+
| `0` | Success |
|
|
582
|
+
| `1` | A failure: a build, a check, a port, a file. `error.code` says which |
|
|
583
|
+
| `2` | Bad usage, or input that could not be asked for: `USAGE`, `INVALID_NAME`, `INVALID_PATH`, `INVALID_VALUE`, `INPUT_REQUIRED`, `CONFIRMATION_REQUIRED` |
|
|
584
|
+
| `130` | Cancelled with Ctrl+C at a prompt |
|
|
585
|
+
|
|
586
|
+
Without a terminal, spool never prompts. A missing value exits 2 with `INPUT_REQUIRED` and names the flag, and a destructive step without `--yes` exits 2 with `CONFIRMATION_REQUIRED`. `remove --files` and `eject` need `--yes`. The failure codes are `NO_WORKSPACE`, `MANIFEST_INVALID`, `MANIFEST_VERSION`, `APP_NOT_FOUND`, `TARGET_EXISTS`, `TARGET_NOT_EMPTY`, `UNSAFE_PATH`, `BUILD_FAILED`, `DEPLOY_FAILED`, `PORT_IN_USE`, `CHECK_FAILED`, `FAILED` and `INTERNAL`.
|
|
587
|
+
|
|
588
|
+
## Windows
|
|
589
|
+
|
|
590
|
+
- Names and paths that Windows cannot hold are rejected on every OS, so a workspace made anywhere clones everywhere. That covers device names (`con`, `nul`, `aux`, `prn`, `com1` and so on) in names and paths, network and device paths, and drive-relative paths like `C:foo`.
|
|
591
|
+
- `dev`, `preview` and `build` start each app's `vite` through the same Node that runs spool, so no `.cmd` shim or shell is involved.
|
|
592
|
+
- `spool dev --kill` checks a process's start time and command line through PowerShell before it ends the tree with `taskkill`. Port owners come from `netstat`. All three are run from the system folder, not from `PATH`.
|
|
593
|
+
- Generated workspaces have a `.gitattributes` that keeps line endings as LF, so a file written on Windows does not show as entirely changed to everyone else.
|
|
594
|
+
|
|
595
|
+
## Upgrading to 1.0
|
|
596
|
+
|
|
597
|
+
1.0 is the first release under `@zerosumstudio`. Coming from `@bkincz/spool` 4.0, run `spool upgrade` in the workspace, then `spool doctor`. `spool.json` moves to version 2, `spool.vite.ts` and `public/_headers` give way to the `./vite` import, `promote`, `rollback` and `affected` are gone, exit codes and `--json` change, and Node 26 is required. The [migration guide](https://github.com/zerosumstudio/spool/blob/main/docs/migration-1.0.md) opens with a checklist and covers each change with a before and after. The full list is in the [changelog](https://github.com/zerosumstudio/spool/blob/main/CHANGELOG.md).
|
|
598
|
+
|
|
599
|
+
## License
|
|
600
|
+
|
|
601
|
+
MIT © zerosum studio
|