@seedprotocol/vite 0.7.5-next.871.g8788c94 → 0.7.6-next.920.gdd0b533
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +33 -32
- package/dist/aliases.d.ts +15 -0
- package/dist/aliases.d.ts.map +1 -0
- package/dist/index.d.ts +29 -51
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +280 -457
- package/dist/index.js.map +1 -1
- package/dist/nodeGlobals.d.ts +22 -0
- package/dist/nodeGlobals.d.ts.map +1 -0
- package/dist/nodePolyfills.d.ts +24 -0
- package/dist/nodePolyfills.d.ts.map +1 -0
- package/package.json +3 -4
- package/dist/arweave-default-shim.d.ts +0 -4
- package/dist/arweave-default-shim.d.ts.map +0 -1
- package/dist/arweave-default-shim.js +0 -6
- package/dist/debug-default-shim.d.ts +0 -3
- package/dist/debug-default-shim.d.ts.map +0 -1
- package/dist/debug-default-shim.js +0 -19
package/README.md
CHANGED
|
@@ -4,22 +4,16 @@
|
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
[](https://seedprotocol.io)
|
|
6
6
|
|
|
7
|
-
Vite plugin for browser
|
|
7
|
+
Vite plugin for browser apps that use [`@seedprotocol/sdk`](https://www.npmjs.com/package/@seedprotocol/sdk). It sends the cross-origin isolation headers SQLite WASM and OPFS need on the dev and preview servers, builds workers as ES modules, and makes Seed packages linked from outside the app (`file:`, `link:`, a workspace) work under `vite dev`.
|
|
8
8
|
|
|
9
9
|
## Installation
|
|
10
10
|
|
|
11
|
-
`vite` (8 or later) is a peer dependency.
|
|
11
|
+
`vite` (8 or later) is a peer dependency.
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
14
|
npm install -D @seedprotocol/vite
|
|
15
|
-
# or
|
|
16
|
-
bun add -d @seedprotocol/vite
|
|
17
|
-
# or
|
|
18
|
-
pnpm add -D @seedprotocol/vite
|
|
19
15
|
```
|
|
20
16
|
|
|
21
|
-
Your app also needs `@seedprotocol/sdk` and the ZenFS packages it uses in the browser. Pin the versions the SDK declares (currently `@zenfs/core@2.5.6` and `@zenfs/dom@1.2.9`) so only one copy is installed.
|
|
22
|
-
|
|
23
17
|
## Usage
|
|
24
18
|
|
|
25
19
|
`seedVitePlugin()` returns an **array** of plugins, so spread it into `plugins`:
|
|
@@ -35,56 +29,63 @@ export default defineConfig({
|
|
|
35
29
|
})
|
|
36
30
|
```
|
|
37
31
|
|
|
38
|
-
|
|
32
|
+
Don't list `@seedprotocol/*` packages, `sqlocal`, `drizzle-orm` or `@sqlite.org/sqlite-wasm` in `optimizeDeps.exclude`. Vite pre-bundles them, and under pnpm an excluded `sqlocal` can't be resolved from the pre-bundled SDK.
|
|
39
33
|
|
|
40
|
-
|
|
41
|
-
import { configure } from '@zenfs/core'
|
|
42
|
-
import { IndexedDB } from '@zenfs/dom'
|
|
34
|
+
## What it configures
|
|
43
35
|
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
- **Cross-origin isolation headers** on the dev and preview servers: `Cross-Origin-Opener-Policy: same-origin`, `Cross-Origin-Embedder-Policy: credentialless`, `Cross-Origin-Resource-Policy: same-origin`. They are also set in `writeHead`, so React Router Framework Mode HTML responses get them. Without them the page isn't cross-origin isolated and the SDK can't keep its database in OPFS.
|
|
37
|
+
- **`worker.format: 'es'`**, unless you set a format. SQLite's worker code-splits, which Vite's default `'iife'` worker format can't do, so the database never opens in a production build.
|
|
38
|
+
- **`optimizeDeps.rolldownOptions.output.strictExecutionOrder: true`**, unless you set it. drizzle-orm's modules import each other in a cycle; when your app imports both `@seedprotocol/sdk` and `@seedprotocol/sdk/drizzle`, the dev pre-bundle can otherwise run them out of order and fail with `Cannot read properties of undefined (reading 'Symbol')`.
|
|
39
|
+
- **`resolve.dedupe`** for React, thirdweb, xstate, ZenFS and the Seed packages, each only when your app root resolves it. A linked Seed package otherwise loads its own React (hooks fail) or its own copy of a Seed package.
|
|
40
|
+
- **`server.fs.allow`** for the SDK, sqlocal and SQLite WASM directories when they are outside your app, so `vite dev` can serve the database worker and WASM file of a linked SDK.
|
|
46
41
|
|
|
47
|
-
|
|
42
|
+
With an SDK installed from npm in the app itself, only the first three matter, and you can set them without the plugin:
|
|
48
43
|
|
|
49
|
-
|
|
44
|
+
```ts
|
|
45
|
+
const isolation = {
|
|
46
|
+
'Cross-Origin-Opener-Policy': 'same-origin',
|
|
47
|
+
'Cross-Origin-Embedder-Policy': 'credentialless',
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default defineConfig({
|
|
51
|
+
plugins: [react()],
|
|
52
|
+
server: { headers: isolation },
|
|
53
|
+
preview: { headers: isolation },
|
|
54
|
+
worker: { format: 'es' },
|
|
55
|
+
optimizeDeps: { rolldownOptions: { output: { strictExecutionOrder: true } } },
|
|
56
|
+
})
|
|
57
|
+
```
|
|
50
58
|
|
|
51
|
-
-
|
|
52
|
-
- **Cross-origin isolation headers** on the dev and preview servers: `Cross-Origin-Opener-Policy: same-origin`, `Cross-Origin-Embedder-Policy: credentialless`, `Cross-Origin-Resource-Policy: same-origin`. They are applied on `writeHead` too, so React Router Framework Mode HTML responses get them.
|
|
53
|
-
- **`fs` aliases** to ZenFS (`fs`, `fs/promises`, `node:fs`, `node:fs/promises`), plus stable ESM entry points for `@zenfs/core` and `@zenfs/dom`.
|
|
54
|
-
- **Interop shims** for `debug` default imports and the `nanoid-dictionary` ESM build.
|
|
55
|
-
- **`optimizeDeps.include`** for fragile CommonJS dependencies, including the SDK's nested EAS SDK.
|
|
56
|
-
- **Inline `global` / `process` shims** in `index.html`. `process.env.NODE_ENV` follows the Vite `mode`, so React Refresh works under `vite serve`.
|
|
59
|
+
[VITE_RENDERER.md](https://github.com/JournoLabs/seed-protocol-sdk/blob/main/packages/vite/VITE_RENDERER.md) lists what each setting is needed for, how that was tested, and what the plugin no longer does.
|
|
57
60
|
|
|
58
61
|
## Options
|
|
59
62
|
|
|
60
63
|
```ts
|
|
61
64
|
seedVitePlugin({
|
|
62
|
-
includeNodePolyfills: true,
|
|
63
65
|
isolationHeaders: true,
|
|
64
|
-
|
|
66
|
+
includeNodePolyfills: false,
|
|
67
|
+
fsModules: [],
|
|
65
68
|
debug: false,
|
|
66
69
|
})
|
|
67
70
|
```
|
|
68
71
|
|
|
69
72
|
| Option | Default | Description |
|
|
70
73
|
|--------|---------|-------------|
|
|
71
|
-
| `
|
|
72
|
-
| `
|
|
73
|
-
| `fsModules` | `['fs', 'fs/promises', 'node:fs', 'node:fs/promises']
|
|
74
|
-
| `
|
|
75
|
-
| `debug` | `false` | Log plugin diagnostics. |
|
|
74
|
+
| `isolationHeaders` | `true` | COOP/COEP/CORP on the dev and preview servers. `false` disables them; `{ coop, coep, corp }` overrides individual values. A value you set in `server.headers` or `preview.headers` wins for that server. |
|
|
75
|
+
| `includeNodePolyfills` | `false` | Add `vite-plugin-node-polyfills` for `path`, `buffer`, `events`, `string_decoder` and `util` and the `Buffer` / `process` / `global` globals, a minimal `stream` stub, and inline `global` / `process` shims in `index.html`. The SDK doesn't need them; turn this on when another dependency uses Node built-ins in the browser. Full `stream` and `crypto` polyfills are left out because they break Vite SSR and React Router prerender. |
|
|
76
|
+
| `fsModules` | `[]` | Modules aliased to ZenFS (`@zenfs/core`, or `@zenfs/core/promises` for ids containing "promises"), for app code or other dependencies that import `fs` in the browser. The SDK doesn't. For example `['fs', 'fs/promises', 'node:fs', 'node:fs/promises']`. |
|
|
77
|
+
| `debug` | `false` | Log what the plugin adds, and warn about Node-only globals (`process`, `Buffer`, `global`, `__dirname`, `__filename`) left in production chunks. |
|
|
76
78
|
|
|
77
79
|
The options type is exported as `SeedVitePluginOptions`.
|
|
78
80
|
|
|
79
81
|
## Production hosting
|
|
80
82
|
|
|
81
|
-
The headers only apply to `vite
|
|
83
|
+
The headers only apply to `vite dev` and `vite preview`. In production, your host must send `Cross-Origin-Opener-Policy: same-origin` and `Cross-Origin-Embedder-Policy: credentialless` (or `require-corp`) on the HTML document, for example through nginx or a Netlify `_headers` file.
|
|
82
84
|
|
|
83
85
|
## Documentation
|
|
84
86
|
|
|
85
87
|
- Full documentation: **https://seedprotocol.io**
|
|
86
|
-
- [
|
|
87
|
-
- [Getting started](https://github.com/JournoLabs/seed-protocol-sdk/blob/main/docs/GETTING_STARTED.md)
|
|
88
|
+
- [What each setting is for, and upgrading from 0.7](https://github.com/JournoLabs/seed-protocol-sdk/blob/main/packages/vite/VITE_RENDERER.md)
|
|
88
89
|
- Core SDK: [`@seedprotocol/sdk`](https://www.npmjs.com/package/@seedprotocol/sdk)
|
|
89
90
|
- React bindings: [`@seedprotocol/react`](https://www.npmjs.com/package/@seedprotocol/react)
|
|
90
91
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { UserConfig } from 'vite';
|
|
2
|
+
export type AliasEntry = {
|
|
3
|
+
find: string | RegExp;
|
|
4
|
+
replacement: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function normalizeAliasEntries(alias: NonNullable<UserConfig['resolve']>['alias'] | undefined): AliasEntry[];
|
|
7
|
+
/** `existing` plus the `additions` whose find it doesn't already have, after it. */
|
|
8
|
+
export declare function mergeAliasEntries(existing: AliasEntry[], additions: AliasEntry[]): AliasEntry[];
|
|
9
|
+
/**
|
|
10
|
+
* Append aliases to the user's config in place. Vite merges a returned alias list *before*
|
|
11
|
+
* the existing one, so returning ours would let it shadow the user's; appending (Vite's
|
|
12
|
+
* documented escape hatch when merging can't express the order) keeps user aliases first.
|
|
13
|
+
*/
|
|
14
|
+
export declare function appendAliases(userConfig: UserConfig, additions: AliasEntry[]): void;
|
|
15
|
+
//# sourceMappingURL=aliases.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aliases.d.ts","sourceRoot":"","sources":["../src/aliases.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAEtC,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,CAAA;AAEvE,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,WAAW,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,SAAS,GAC7D,UAAU,EAAE,CAWd;AAED,oFAAoF;AACpF,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,UAAU,EAAE,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE,CAY/F;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,IAAI,CAMnF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,67 +1,45 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
2
|
export interface SeedVitePluginOptions {
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* the
|
|
7
|
-
*
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* Whether to inject a ZenFS initialization script into index.html that mounts
|
|
12
|
-
* IndexedDB at `/`. Leave this false with the SDK: `client.init()` mounts OPFS
|
|
13
|
-
* at `/` itself, so apps do not configure ZenFS, and this mount would only be
|
|
14
|
-
* replaced. The script also imports the bare specifiers '@zenfs/core' and
|
|
15
|
-
* '@zenfs/dom', which browsers cannot resolve without an import map.
|
|
16
|
-
* @default false
|
|
4
|
+
* Cross-origin isolation headers for SQLite WASM, SharedArrayBuffer and OPFS on the dev and
|
|
5
|
+
* preview servers, also applied in `writeHead` because Vite's `server.headers` is not copied
|
|
6
|
+
* onto React Router Framework Mode HTML responses. Without them the SDK can't keep its
|
|
7
|
+
* database in OPFS. Set `false` to disable, or pass `{ coop, coep, corp }` to override values.
|
|
8
|
+
* A COOP/COEP/CORP value you set in `server.headers` or `preview.headers` (any letter case)
|
|
9
|
+
* wins for that server.
|
|
10
|
+
* @default true (`COOP: same-origin`, `COEP: credentialless`, `CORP: same-origin`)
|
|
17
11
|
*/
|
|
18
|
-
|
|
12
|
+
isolationHeaders?: boolean | {
|
|
13
|
+
coop?: string;
|
|
14
|
+
coep?: string;
|
|
15
|
+
corp?: string;
|
|
16
|
+
};
|
|
19
17
|
/**
|
|
20
|
-
*
|
|
18
|
+
* Add vite-plugin-node-polyfills (`path`, `buffer`, `events`, `string_decoder`, `util`, and
|
|
19
|
+
* the `Buffer` / `process` / `global` globals), a `stream` stub and inline `global` /
|
|
20
|
+
* `process` shims in index.html. The SDK doesn't need them; turn this on when another
|
|
21
|
+
* dependency of your app uses Node built-ins in the browser.
|
|
21
22
|
* @default false
|
|
22
23
|
*/
|
|
23
|
-
|
|
24
|
+
includeNodePolyfills?: boolean;
|
|
24
25
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* stream-browserify and break Vite SSR / React Router prerender). A minimal
|
|
30
|
-
* `stream` stub is still aliased so sax/rss-parser do not warn. Use `false`
|
|
31
|
-
* for Framework Mode / prerender.
|
|
32
|
-
* @default true
|
|
26
|
+
* Modules to alias to ZenFS (`@zenfs/core`, or `@zenfs/core/promises` for ids containing
|
|
27
|
+
* "promises"), for app code or dependencies that import Node's `fs` in the browser. The SDK's
|
|
28
|
+
* browser build doesn't.
|
|
29
|
+
* @default []
|
|
33
30
|
*/
|
|
34
|
-
|
|
31
|
+
fsModules?: string[];
|
|
35
32
|
/**
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* because Vite `server.headers` is not copied onto Framework-Mode HTML responses.
|
|
39
|
-
* Set `false` to disable. Pass `{ coop, coep, corp }` to override values.
|
|
40
|
-
* A COOP/COEP/CORP value you set yourself in `server.headers` or `preview.headers`
|
|
41
|
-
* (any letter case) wins over both this option and the defaults, for that server.
|
|
42
|
-
* @default true (`COOP: same-origin`, `COEP: credentialless`, `CORP: same-origin`)
|
|
33
|
+
* Log what the plugin adds, and warn about Node-only globals left in production chunks.
|
|
34
|
+
* @default false
|
|
43
35
|
*/
|
|
44
|
-
|
|
45
|
-
coop?: string;
|
|
46
|
-
coep?: string;
|
|
47
|
-
corp?: string;
|
|
48
|
-
};
|
|
36
|
+
debug?: boolean;
|
|
49
37
|
}
|
|
50
38
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* -
|
|
54
|
-
* -
|
|
55
|
-
* - Allowlists linked SDK / sqlocal worker paths on server.fs.allow for Vite dev
|
|
56
|
-
* - Optionally wires up vite-plugin-node-polyfills with safe defaults
|
|
57
|
-
*
|
|
58
|
-
* This plugin assumes the SDK does not bundle Node-only code in the browser entry.
|
|
59
|
-
* For Electron, Node-only work (e.g. better-sqlite3) should run in the
|
|
60
|
-
* main process; the renderer should only use browser-safe SDK usage.
|
|
61
|
-
*
|
|
62
|
-
* For the renderer build:
|
|
63
|
-
* - Use the SDK's ESM entry: import from '@seedprotocol/sdk' (resolves to dist/main.js).
|
|
64
|
-
* - Do not configure ZenFS yourself: `client.init()` mounts OPFS at `/`.
|
|
39
|
+
* The Vite settings a browser app using @seedprotocol/sdk needs: cross-origin isolation headers
|
|
40
|
+
* on the dev and preview servers, ES module workers, in-order dev pre-bundles, and, for SDK
|
|
41
|
+
* packages installed outside the app root, deduplication and dev-server file access. Node polyfills and `fs` aliases are
|
|
42
|
+
* opt-in.
|
|
65
43
|
*/
|
|
66
44
|
export declare function seedVitePlugin(options?: SeedVitePluginOptions): Plugin[];
|
|
67
45
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAgC,MAAM,MAAM,CAAA;AAahE,MAAM,WAAW,qBAAqB;IACpC;;;;;;;;OAQG;IACH,gBAAgB,CAAC,EAAE,OAAO,GAAG;QAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,IAAI,CAAC,EAAE,MAAM,CAAA;KACd,CAAA;IAED;;;;;;OAMG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAE9B;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,EAAE,CAAA;IAEpB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAyFD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,MAAM,EAAE,CA8F5E"}
|