@rudderjs/vite 1.0.2 → 2.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/README.md +56 -5
- package/dist/hooks/headersResponse.d.ts +12 -0
- package/dist/hooks/headersResponse.d.ts.map +1 -0
- package/dist/hooks/headersResponse.js +13 -0
- package/dist/hooks/headersResponse.js.map +1 -0
- package/dist/hooks/onCreatePageContext.d.ts +8 -0
- package/dist/hooks/onCreatePageContext.d.ts.map +1 -0
- package/dist/hooks/onCreatePageContext.js +10 -0
- package/dist/hooks/onCreatePageContext.js.map +1 -0
- package/dist/hooks/onError.d.ts +14 -0
- package/dist/hooks/onError.d.ts.map +1 -0
- package/dist/hooks/onError.js +25 -0
- package/dist/hooks/onError.js.map +1 -0
- package/dist/index.d.ts +17 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +211 -215
- package/dist/index.js.map +1 -1
- package/dist/page-context-enhancers.d.ts +35 -0
- package/dist/page-context-enhancers.d.ts.map +1 -0
- package/dist/page-context-enhancers.js +56 -0
- package/dist/page-context-enhancers.js.map +1 -0
- package/dist/views-scanner.d.ts.map +1 -1
- package/dist/views-scanner.js +64 -7
- package/dist/views-scanner.js.map +1 -1
- package/package.json +29 -4
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @rudderjs/vite
|
|
2
2
|
|
|
3
|
-
Vite plugin for RudderJS. Registers Vike (SSR), sets the `@/` path
|
|
3
|
+
Vite plugin for RudderJS. Registers Vike (SSR), sets the `@/` and `App/` path aliases, externalizes server-only packages from the client bundle, wires up WebSocket upgrade handling for `@rudderjs/broadcast` and `@rudderjs/sync`, and installs Vike framework hooks (page-context enhancers, error routing, per-page response headers) so other `@rudderjs/*` packages can light up their Vike integrations automatically.
|
|
4
4
|
|
|
5
5
|
```bash
|
|
6
6
|
pnpm add @rudderjs/vite
|
|
@@ -26,9 +26,10 @@ That's it. `rudderjs()` handles:
|
|
|
26
26
|
|
|
27
27
|
- **Vike registration** — auto-detects and registers `vike/plugin` for SSR + file-based routing
|
|
28
28
|
- **View scanner** — scans `app/Views/**` and generates virtual Vike pages under `pages/__view/` for `@rudderjs/view`
|
|
29
|
+
- **Vike framework hooks** — writes `+onCreatePageContext.ts`, `+onError.ts`, and `+headersResponse.ts` stubs into `pages/` on first sync, wiring the page-context enhancer registry, error reporting through `@rudderjs/core`, and per-page response headers from `view(id, props, { headers })`
|
|
29
30
|
- **HMR route reload** — watches `routes/`, `bootstrap/`, and `app/` so edits there invalidate the SSR module graph without restarting the dev server
|
|
30
31
|
- **Path alias** — `@/` and `App/` resolve to the app directory
|
|
31
|
-
- **SSR externals** — server-only packages (database drivers, Redis, queue adapters) are externalized from the client bundle
|
|
32
|
+
- **SSR externals** — server-only packages (database drivers, Redis, queue adapters, storage, image) are externalized from the client bundle
|
|
32
33
|
- **SSR no-externals** — `@rudderjs/server-hono` is forced non-external so Vite processes virtual module imports
|
|
33
34
|
- **WebSocket upgrade** — intercepts `http.createServer` to attach the `__rudderjs_ws_upgrade__` handler for `@rudderjs/broadcast` and `@rudderjs/sync`
|
|
34
35
|
- **`x-real-ip` injection** — dev-only, populates the header from the Node socket so `req.ip` works through Vike's universal middleware
|
|
@@ -37,7 +38,7 @@ That's it. `rudderjs()` handles:
|
|
|
37
38
|
|
|
38
39
|
## What it produces
|
|
39
40
|
|
|
40
|
-
|
|
41
|
+
Six Vite plugins (plus Vike's own):
|
|
41
42
|
|
|
42
43
|
| Plugin | Purpose |
|
|
43
44
|
|--------|---------|
|
|
@@ -45,7 +46,7 @@ Five Vite plugins:
|
|
|
45
46
|
| `rudderjs:ws` | WebSocket upgrade handler via `configureServer` |
|
|
46
47
|
| `rudderjs:ip` | Dev-only `x-real-ip` injection from Node socket |
|
|
47
48
|
| `rudderjs:routes` | HMR watcher for `routes/` + `bootstrap/` + `app/`; invalidates SSR modules + clears `__rudderjs_instance__` and `__rudderjs_app__` globals so the next request re-bootstraps cleanly |
|
|
48
|
-
| `rudderjs:views` | View scanner — generates virtual Vike pages from `app/Views/**` |
|
|
49
|
+
| `rudderjs:views` | View scanner — generates virtual Vike pages from `app/Views/**` and seeds top-level Vike hook stubs in `pages/` |
|
|
49
50
|
| *(vike plugins)* | SSR rendering, file-based routing (auto-registered) |
|
|
50
51
|
|
|
51
52
|
### HMR notes
|
|
@@ -53,14 +54,52 @@ Five Vite plugins:
|
|
|
53
54
|
- `rudderjs:routes` never calls `server.restart()` — doing so closes Vite's module runner and breaks in-flight SSR requests. Module invalidation + globalThis cleanup is enough to force a full re-bootstrap on the next request.
|
|
54
55
|
- Changes under `app/` require the full cleanup (not just invalidation) because models, controllers, and resources are captured in provider closures during boot.
|
|
55
56
|
|
|
57
|
+
## Vike framework hooks
|
|
58
|
+
|
|
59
|
+
On first sync, the view scanner writes three top-level Vike hook files to `pages/` — each is a one-line re-export from `@rudderjs/vite`:
|
|
60
|
+
|
|
61
|
+
| File | Re-exports from | What it does |
|
|
62
|
+
|---|---|---|
|
|
63
|
+
| `pages/+onCreatePageContext.ts` | `@rudderjs/vite/hooks/onCreatePageContext` | Runs every registered page-context enhancer (see below) on every page render |
|
|
64
|
+
| `pages/+onError.ts` | `@rudderjs/vite/hooks/onError` | Routes Vike SSR errors through `@rudderjs/core`'s `report()` pipeline (falls back to `console.error` if core isn't installed) |
|
|
65
|
+
| `pages/+headersResponse.ts` | `@rudderjs/vite/hooks/headersResponse` | Reads response headers off `pageContext.viewHeaders` (set by `view(id, props, { headers })` in `@rudderjs/view`) |
|
|
66
|
+
|
|
67
|
+
Stubs are written **only if missing** — edit any file in place and your version wins on subsequent syncs. Need to replace one entirely? Just overwrite it. Want to keep the framework default but add your own logic? Re-export and wrap.
|
|
68
|
+
|
|
69
|
+
### Page-context enhancers
|
|
70
|
+
|
|
71
|
+
`@rudderjs/vite/page-context-enhancers` is the registry that backs `+onCreatePageContext`. Framework packages register enhancers from their provider's `boot()` so per-request state lands on every `pageContext` without per-view boilerplate:
|
|
72
|
+
|
|
73
|
+
| Package | Adds to `pageContext` |
|
|
74
|
+
|---|---|
|
|
75
|
+
| `@rudderjs/auth` | `pageContext.user` — current authenticated user (or `null`) |
|
|
76
|
+
| `@rudderjs/session` | `pageContext.flash` — flash bag carried over from the previous request |
|
|
77
|
+
| `@rudderjs/localization` | `pageContext.locale` — resolved locale for the current request |
|
|
78
|
+
|
|
79
|
+
Custom enhancers live in app code — typically a service provider — and use the same registry:
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import { registerPageContextEnhancer } from '@rudderjs/vite/page-context-enhancers'
|
|
83
|
+
|
|
84
|
+
registerPageContextEnhancer(async (pageContext) => {
|
|
85
|
+
pageContext.tenant = await resolveTenantForRequest()
|
|
86
|
+
})
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Enhancers run in registration order on every render and should be fast.
|
|
90
|
+
|
|
56
91
|
## SSR Externals
|
|
57
92
|
|
|
58
93
|
These packages are externalized from the SSR bundle (Node.js-only, not browser-compatible):
|
|
59
94
|
|
|
60
|
-
- `@rudderjs/
|
|
95
|
+
- `@rudderjs/view` (linked-package workaround for fresh scaffolds)
|
|
96
|
+
- `@rudderjs/queue-inngest`, `@rudderjs/queue-bullmq`
|
|
97
|
+
- `@rudderjs/orm-drizzle`, `@rudderjs/orm-prisma`
|
|
98
|
+
- `@rudderjs/storage`, `@rudderjs/image`
|
|
61
99
|
- Database drivers: `pg`, `mysql2`, `better-sqlite3`, `@prisma/adapter-*`, `@libsql/client`
|
|
62
100
|
- Redis: `ioredis`
|
|
63
101
|
- CLI prompts: `@clack/core`, `@clack/prompts`
|
|
102
|
+
- Optional icon adapters: `@tabler/icons-react`, `@phosphor-icons/react`, `@remixicon/react`
|
|
64
103
|
|
|
65
104
|
## Peer Dependencies
|
|
66
105
|
|
|
@@ -68,10 +107,22 @@ These packages are externalized from the SSR bundle (Node.js-only, not browser-c
|
|
|
68
107
|
|---------|----------|-------|
|
|
69
108
|
| `vite` | Yes | Build tool |
|
|
70
109
|
| `vike` | Yes | SSR framework |
|
|
110
|
+
| `@rudderjs/core` | Optional | Used by `+onError` to route SSR errors through `report()`; falls back to `console.error` if missing |
|
|
71
111
|
| `@vitejs/plugin-react` | Optional | For React projects |
|
|
72
112
|
| `@vitejs/plugin-vue` | Optional | For Vue projects |
|
|
73
113
|
| `vike-solid` | Optional | For Solid projects |
|
|
74
114
|
|
|
115
|
+
## Subpath exports
|
|
116
|
+
|
|
117
|
+
The hook implementations and the enhancer registry ship as subpath exports so the generated stubs (and your own code) can import them directly:
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { registerPageContextEnhancer } from '@rudderjs/vite/page-context-enhancers'
|
|
121
|
+
import { onCreatePageContext } from '@rudderjs/vite/hooks/onCreatePageContext'
|
|
122
|
+
import { onError } from '@rudderjs/vite/hooks/onError'
|
|
123
|
+
import { headersResponse } from '@rudderjs/vite/hooks/headersResponse'
|
|
124
|
+
```
|
|
125
|
+
|
|
75
126
|
## Framework Plugins
|
|
76
127
|
|
|
77
128
|
Add your UI framework plugin separately — `rudderjs()` does not include one:
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { PageContext } from 'vike/types';
|
|
2
|
+
/**
|
|
3
|
+
* Vike `+headersResponse` hook — returns the response headers for the page.
|
|
4
|
+
*
|
|
5
|
+
* Sources headers from `pageContext.viewHeaders`, which `@rudderjs/view`'s
|
|
6
|
+
* `ViewResponse.toResponse()` sets on the renderPage() call. Pages rendered
|
|
7
|
+
* outside of `view()` (file-based Vike pages with no controller) have an
|
|
8
|
+
* empty `viewHeaders` and this returns `{}` — Vike merges it with the
|
|
9
|
+
* defaults so no harm done.
|
|
10
|
+
*/
|
|
11
|
+
export declare function headersResponse(pageContext: PageContext): Record<string, string>;
|
|
12
|
+
//# sourceMappingURL=headersResponse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headersResponse.d.ts","sourceRoot":"","sources":["../../src/hooks/headersResponse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAAC,WAAW,EAAE,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAEhF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vike `+headersResponse` hook — returns the response headers for the page.
|
|
3
|
+
*
|
|
4
|
+
* Sources headers from `pageContext.viewHeaders`, which `@rudderjs/view`'s
|
|
5
|
+
* `ViewResponse.toResponse()` sets on the renderPage() call. Pages rendered
|
|
6
|
+
* outside of `view()` (file-based Vike pages with no controller) have an
|
|
7
|
+
* empty `viewHeaders` and this returns `{}` — Vike merges it with the
|
|
8
|
+
* defaults so no harm done.
|
|
9
|
+
*/
|
|
10
|
+
export function headersResponse(pageContext) {
|
|
11
|
+
return pageContext.viewHeaders ?? {};
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=headersResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"headersResponse.js","sourceRoot":"","sources":["../../src/hooks/headersResponse.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAAC,WAAwB;IACtD,OAAQ,WAAwD,CAAC,WAAW,IAAI,EAAE,CAAA;AACpF,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { PageContext } from 'vike/types';
|
|
2
|
+
/**
|
|
3
|
+
* Vike `+onCreatePageContext` hook — runs after routing on every page render.
|
|
4
|
+
*
|
|
5
|
+
* Wired via `@rudderjs/vite/config` (the user's `pages/+config.ts` extends it).
|
|
6
|
+
*/
|
|
7
|
+
export declare function onCreatePageContext(pageContext: PageContext): Promise<void>;
|
|
8
|
+
//# sourceMappingURL=onCreatePageContext.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onCreatePageContext.d.ts","sourceRoot":"","sources":["../../src/hooks/onCreatePageContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAG7C;;;;GAIG;AACH,wBAAsB,mBAAmB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAEjF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { runPageContextEnhancers } from '../page-context-enhancers.js';
|
|
2
|
+
/**
|
|
3
|
+
* Vike `+onCreatePageContext` hook — runs after routing on every page render.
|
|
4
|
+
*
|
|
5
|
+
* Wired via `@rudderjs/vite/config` (the user's `pages/+config.ts` extends it).
|
|
6
|
+
*/
|
|
7
|
+
export async function onCreatePageContext(pageContext) {
|
|
8
|
+
await runPageContextEnhancers(pageContext);
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=onCreatePageContext.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onCreatePageContext.js","sourceRoot":"","sources":["../../src/hooks/onCreatePageContext.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAA;AAEtE;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,WAAwB;IAChE,MAAM,uBAAuB,CAAC,WAAW,CAAC,CAAA;AAC5C,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { PageContext } from 'vike/types';
|
|
2
|
+
/**
|
|
3
|
+
* Vike `+onError` hook — receives every SSR error.
|
|
4
|
+
*
|
|
5
|
+
* Routes the error through `@rudderjs/core`'s `report()` so SSR errors land in
|
|
6
|
+
* the same reporter / renderer chain as HTTP route errors. Falls back to
|
|
7
|
+
* `console.error` when `@rudderjs/core` isn't installed (the package is an
|
|
8
|
+
* optional runtime peer — `@rudderjs/vite` is usable standalone).
|
|
9
|
+
*
|
|
10
|
+
* The lazy import means cold-boot apps pay the import cost on first error
|
|
11
|
+
* only; non-erroring requests never load `@rudderjs/core` through this path.
|
|
12
|
+
*/
|
|
13
|
+
export declare function onError(error: unknown, pageContext: PageContext): Promise<void>;
|
|
14
|
+
//# sourceMappingURL=onError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onError.d.ts","sourceRoot":"","sources":["../../src/hooks/onError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C;;;;;;;;;;GAUG;AACH,wBAAsB,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAWrF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vike `+onError` hook — receives every SSR error.
|
|
3
|
+
*
|
|
4
|
+
* Routes the error through `@rudderjs/core`'s `report()` so SSR errors land in
|
|
5
|
+
* the same reporter / renderer chain as HTTP route errors. Falls back to
|
|
6
|
+
* `console.error` when `@rudderjs/core` isn't installed (the package is an
|
|
7
|
+
* optional runtime peer — `@rudderjs/vite` is usable standalone).
|
|
8
|
+
*
|
|
9
|
+
* The lazy import means cold-boot apps pay the import cost on first error
|
|
10
|
+
* only; non-erroring requests never load `@rudderjs/core` through this path.
|
|
11
|
+
*/
|
|
12
|
+
export async function onError(error, pageContext) {
|
|
13
|
+
try {
|
|
14
|
+
const core = await import('@rudderjs/core').catch(() => null);
|
|
15
|
+
if (core?.report) {
|
|
16
|
+
core.report(error, { source: 'vike', url: pageContext.urlOriginal });
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// fall through to console
|
|
22
|
+
}
|
|
23
|
+
console.error('[RudderJS] Vike SSR error:', error);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=onError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"onError.js","sourceRoot":"","sources":["../../src/hooks/onError.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAAC,KAAc,EAAE,WAAwB;IACpE,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,gBAAgB,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAA8E,CAAA;QAC1I,IAAI,IAAI,EAAE,MAAM,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,WAAW,CAAC,WAAW,EAAE,CAAC,CAAA;YACpE,OAAM;QACR,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACP,0BAA0B;IAC5B,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,KAAK,CAAC,CAAA;AACpD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,22 +2,34 @@ import type { Plugin } from 'vite';
|
|
|
2
2
|
/**
|
|
3
3
|
* RudderJS Vite plugin.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Sets the @/ and App/ path aliases, externalises RudderJS optional-peer
|
|
6
|
+
* packages from the SSR bundle, wires the views-scanner, and patches Vite's
|
|
7
|
+
* HTTP server with the WebSocket upgrade handler used by `@rudderjs/broadcast`
|
|
8
|
+
* and `@rudderjs/sync`.
|
|
7
9
|
*
|
|
8
|
-
*
|
|
10
|
+
* **You must register `vike()` yourself.** Vike was previously bundled into
|
|
11
|
+
* this factory, but that wrapped Vike's plugin IIFE inside our own async
|
|
12
|
+
* factory and tripped a microtask race against Vike's internal
|
|
13
|
+
* `isOnlyResolvingUserConfig` flag — see vikejs/vike#3258. The supported
|
|
14
|
+
* pattern is to call `vike()` synchronously in your own `vite.config.ts`.
|
|
15
|
+
*
|
|
16
|
+
* **Plugin order matters.** Put `rudderjs()` **before** `vike()`. The views
|
|
17
|
+
* scanner writes auto-generated stubs to `pages/__view/` during plugin
|
|
18
|
+
* construction, and Vike scans `pages/` during its own construction — so the
|
|
19
|
+
* stubs must exist on disk before `vike()` is called.
|
|
9
20
|
*
|
|
10
21
|
* @example
|
|
11
22
|
* // vite.config.ts
|
|
12
23
|
* import { defineConfig } from 'vite'
|
|
24
|
+
* import vike from 'vike/plugin'
|
|
13
25
|
* import rudderjs from '@rudderjs/vite'
|
|
14
26
|
* import tailwindcss from '@tailwindcss/vite'
|
|
15
27
|
* import react from '@vitejs/plugin-react'
|
|
16
28
|
*
|
|
17
29
|
* export default defineConfig({
|
|
18
|
-
* plugins: [rudderjs(), tailwindcss(), react()],
|
|
30
|
+
* plugins: [rudderjs(), vike(), tailwindcss(), react()],
|
|
19
31
|
* })
|
|
20
32
|
*/
|
|
21
|
-
export declare function rudderjs():
|
|
33
|
+
export declare function rudderjs(): Plugin[];
|
|
22
34
|
export default rudderjs;
|
|
23
35
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAgDlC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,QAAQ,IAAI,MAAM,EAAE,CAsMnC;AAED,eAAe,QAAQ,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
-
import { createRequire } from 'node:module';
|
|
3
2
|
import { viewsScannerPlugin } from './views-scanner.js';
|
|
4
3
|
// ─── SSR / build externals ─────────────────────────────────
|
|
5
4
|
const SSR_EXTERNALS = [
|
|
@@ -41,245 +40,242 @@ const SSR_EXTERNALS = [
|
|
|
41
40
|
const SSR_NO_EXTERNALS = [
|
|
42
41
|
'@rudderjs/server-hono',
|
|
43
42
|
];
|
|
44
|
-
// ─── Helpers ───────────────────────────────────────────────
|
|
45
|
-
// Resolve from the app root so we pick up the user's installed packages,
|
|
46
|
-
// not a copy inside packages/vite/node_modules.
|
|
47
|
-
const _require = createRequire(process.cwd() + '/package.json');
|
|
48
43
|
// ─── Main plugin ───────────────────────────────────────────
|
|
49
44
|
/**
|
|
50
45
|
* RudderJS Vite plugin.
|
|
51
46
|
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
47
|
+
* Sets the @/ and App/ path aliases, externalises RudderJS optional-peer
|
|
48
|
+
* packages from the SSR bundle, wires the views-scanner, and patches Vite's
|
|
49
|
+
* HTTP server with the WebSocket upgrade handler used by `@rudderjs/broadcast`
|
|
50
|
+
* and `@rudderjs/sync`.
|
|
54
51
|
*
|
|
55
|
-
*
|
|
52
|
+
* **You must register `vike()` yourself.** Vike was previously bundled into
|
|
53
|
+
* this factory, but that wrapped Vike's plugin IIFE inside our own async
|
|
54
|
+
* factory and tripped a microtask race against Vike's internal
|
|
55
|
+
* `isOnlyResolvingUserConfig` flag — see vikejs/vike#3258. The supported
|
|
56
|
+
* pattern is to call `vike()` synchronously in your own `vite.config.ts`.
|
|
57
|
+
*
|
|
58
|
+
* **Plugin order matters.** Put `rudderjs()` **before** `vike()`. The views
|
|
59
|
+
* scanner writes auto-generated stubs to `pages/__view/` during plugin
|
|
60
|
+
* construction, and Vike scans `pages/` during its own construction — so the
|
|
61
|
+
* stubs must exist on disk before `vike()` is called.
|
|
56
62
|
*
|
|
57
63
|
* @example
|
|
58
64
|
* // vite.config.ts
|
|
59
65
|
* import { defineConfig } from 'vite'
|
|
66
|
+
* import vike from 'vike/plugin'
|
|
60
67
|
* import rudderjs from '@rudderjs/vite'
|
|
61
68
|
* import tailwindcss from '@tailwindcss/vite'
|
|
62
69
|
* import react from '@vitejs/plugin-react'
|
|
63
70
|
*
|
|
64
71
|
* export default defineConfig({
|
|
65
|
-
* plugins: [rudderjs(), tailwindcss(), react()],
|
|
72
|
+
* plugins: [rudderjs(), vike(), tailwindcss(), react()],
|
|
66
73
|
* })
|
|
67
74
|
*/
|
|
68
75
|
export function rudderjs() {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
return [
|
|
87
|
-
...vikePlugins,
|
|
88
|
-
viewsScanner,
|
|
89
|
-
{
|
|
90
|
-
// Inject x-real-ip header from the Node socket so downstream Hono
|
|
91
|
-
// middleware can read the client IP. Vike's universal-middleware
|
|
92
|
-
// converts the Express request to a Web Request which loses socket info.
|
|
93
|
-
name: 'rudderjs:ip',
|
|
94
|
-
configureServer(server) {
|
|
95
|
-
server.middlewares.use((req, _res, next) => {
|
|
96
|
-
if (!req.headers['x-real-ip'] && !req.headers['x-forwarded-for']) {
|
|
97
|
-
const ip = req.socket?.remoteAddress;
|
|
98
|
-
if (ip)
|
|
99
|
-
req.headers['x-real-ip'] = ip;
|
|
100
|
-
}
|
|
101
|
-
next();
|
|
102
|
-
});
|
|
103
|
-
},
|
|
76
|
+
return [
|
|
77
|
+
viewsScannerPlugin(),
|
|
78
|
+
{
|
|
79
|
+
// Inject x-real-ip header from the Node socket so downstream Hono
|
|
80
|
+
// middleware can read the client IP. Vike's universal-middleware
|
|
81
|
+
// converts the Express request to a Web Request which loses socket info.
|
|
82
|
+
name: 'rudderjs:ip',
|
|
83
|
+
configureServer(server) {
|
|
84
|
+
server.middlewares.use((req, _res, next) => {
|
|
85
|
+
if (!req.headers['x-real-ip'] && !req.headers['x-forwarded-for']) {
|
|
86
|
+
const ip = req.socket?.remoteAddress;
|
|
87
|
+
if (ip)
|
|
88
|
+
req.headers['x-real-ip'] = ip;
|
|
89
|
+
}
|
|
90
|
+
next();
|
|
91
|
+
});
|
|
104
92
|
},
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: 'rudderjs:ws',
|
|
96
|
+
configureServer(server) {
|
|
97
|
+
// Attach the WebSocket upgrade handler to Vite's own HTTP server.
|
|
98
|
+
//
|
|
99
|
+
// GlobalThis contract for cross-package WS wiring:
|
|
100
|
+
// __rudderjs_ws_upgrade__ — handler function. Written by
|
|
101
|
+
// @rudderjs/broadcast and
|
|
102
|
+
// @rudderjs/sync provider boot.
|
|
103
|
+
// Read here in dev and by
|
|
104
|
+
// @rudderjs/server-hono in prod.
|
|
105
|
+
// __rudderjs_http_upgrade_patched__ — sentinel set by whichever
|
|
106
|
+
// plugin/runtime claims the
|
|
107
|
+
// `upgrade` event first. Both
|
|
108
|
+
// this plugin AND server-hono's
|
|
109
|
+
// module-load patch attach
|
|
110
|
+
// upgrade listeners; without the
|
|
111
|
+
// sentinel, handleUpgrade()
|
|
112
|
+
// would fire twice per socket
|
|
113
|
+
// (duplicate WS connection + the
|
|
114
|
+
// classic "already destroyed"
|
|
115
|
+
// error from `ws`).
|
|
116
|
+
//
|
|
117
|
+
// The sentinel slot is shared with @rudderjs/server-hono; renaming
|
|
118
|
+
// it requires a coordinated change in both packages.
|
|
119
|
+
const _G = globalThis;
|
|
120
|
+
if (_G['__rudderjs_http_upgrade_patched__'])
|
|
121
|
+
return;
|
|
122
|
+
_G['__rudderjs_http_upgrade_patched__'] = true;
|
|
123
|
+
// Buffer early upgrade requests that arrive before providers have
|
|
124
|
+
// registered __rudderjs_ws_upgrade__ (the page SSR can trigger a
|
|
125
|
+
// browser WS connect before provider boot finishes).
|
|
126
|
+
let pending = [];
|
|
127
|
+
const flush = () => {
|
|
128
|
+
if (!pending)
|
|
118
129
|
return;
|
|
119
|
-
_G['
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
pending = null;
|
|
132
|
-
for (const [r, s, h] of queued)
|
|
133
|
-
handler(r, s, h);
|
|
134
|
-
};
|
|
135
|
-
// Poll briefly for the handler to appear (providers boot async)
|
|
136
|
-
const interval = setInterval(() => {
|
|
137
|
-
if (_G['__rudderjs_ws_upgrade__']) {
|
|
138
|
-
flush();
|
|
139
|
-
clearInterval(interval);
|
|
140
|
-
}
|
|
141
|
-
}, 50);
|
|
142
|
-
setTimeout(() => {
|
|
130
|
+
const handler = _G['__rudderjs_ws_upgrade__'];
|
|
131
|
+
if (!handler)
|
|
132
|
+
return;
|
|
133
|
+
const queued = pending;
|
|
134
|
+
pending = null;
|
|
135
|
+
for (const [r, s, h] of queued)
|
|
136
|
+
handler(r, s, h);
|
|
137
|
+
};
|
|
138
|
+
// Poll briefly for the handler to appear (providers boot async)
|
|
139
|
+
const interval = setInterval(() => {
|
|
140
|
+
if (_G['__rudderjs_ws_upgrade__']) {
|
|
141
|
+
flush();
|
|
143
142
|
clearInterval(interval);
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
143
|
+
}
|
|
144
|
+
}, 50);
|
|
145
|
+
setTimeout(() => {
|
|
146
|
+
clearInterval(interval);
|
|
147
|
+
if (pending) {
|
|
148
|
+
for (const [, socket] of pending)
|
|
149
|
+
socket.destroy();
|
|
150
|
+
pending = null;
|
|
151
|
+
}
|
|
152
|
+
}, 10_000);
|
|
153
|
+
server.httpServer?.on('upgrade', (req, socket, head) => {
|
|
154
|
+
// Skip Vite's own HMR WebSocket (handled by Vite internally)
|
|
155
|
+
if (req.headers['sec-websocket-protocol'] === 'vite-hmr')
|
|
156
|
+
return;
|
|
157
|
+
if (req.headers['sec-websocket-protocol'] === 'vite-ping')
|
|
158
|
+
return;
|
|
159
|
+
const handler = _G['__rudderjs_ws_upgrade__'];
|
|
160
|
+
if (handler) {
|
|
161
|
+
handler(req, socket, head);
|
|
162
|
+
}
|
|
163
|
+
else if (pending) {
|
|
164
|
+
pending.push([req, socket, head]);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
165
167
|
},
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
server.watcher.
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
});
|
|
201
|
-
}
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
name: 'rudderjs:routes',
|
|
171
|
+
configureServer(server) {
|
|
172
|
+
// Watch route, bootstrap, and app files for SSR changes. These files
|
|
173
|
+
// are dynamically imported during bootstrap or within route handlers
|
|
174
|
+
// so Vite doesn't track them in its SSR module graph — changes go
|
|
175
|
+
// unnoticed without an explicit watcher.
|
|
176
|
+
const cwd = process.cwd();
|
|
177
|
+
const watchDirs = [
|
|
178
|
+
path.resolve(cwd, 'routes'),
|
|
179
|
+
path.resolve(cwd, 'bootstrap'),
|
|
180
|
+
path.resolve(cwd, 'app'),
|
|
181
|
+
];
|
|
182
|
+
for (const dir of watchDirs)
|
|
183
|
+
server.watcher.add(dir);
|
|
184
|
+
server.watcher.on('change', (file) => {
|
|
185
|
+
if (!watchDirs.some(d => file.startsWith(d)))
|
|
186
|
+
return;
|
|
187
|
+
// Clear the two top-level singletons so a new RudderJS + Application
|
|
188
|
+
// pair is created when the module re-executes. App files (models,
|
|
189
|
+
// resources, controllers) are captured in closures during bootstrap
|
|
190
|
+
// so they also need a full re-bootstrap to pick up changes.
|
|
191
|
+
const g = globalThis;
|
|
192
|
+
delete g['__rudderjs_instance__'];
|
|
193
|
+
delete g['__rudderjs_app__'];
|
|
194
|
+
// Invalidate all SSR modules so Vike re-executes bootstrap/app.ts
|
|
195
|
+
// (and transitively all app code) on the next request. This is
|
|
196
|
+
// lighter than server.restart() and avoids closing the module runner
|
|
197
|
+
// while requests may still be in flight.
|
|
198
|
+
server.environments.ssr.moduleGraph.invalidateAll();
|
|
199
|
+
// Tell the browser to do a full page reload so it picks up the
|
|
200
|
+
// changes via a fresh SSR request.
|
|
201
|
+
server.hot.send({ type: 'full-reload' });
|
|
202
|
+
console.log(`[RudderJS] change detected — reloading (${path.relative(cwd, file)})`);
|
|
203
|
+
});
|
|
202
204
|
},
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
return
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
name: 'rudderjs:config',
|
|
208
|
+
configResolved(config) {
|
|
209
|
+
// Suppress "Sourcemap points to missing source files" for @rudderjs/* packages.
|
|
210
|
+
// Vite emits these via logger.warnOnce() when published dist/ has sourcemaps
|
|
211
|
+
// referencing the original .ts sources not shipped in the npm package.
|
|
212
|
+
const filter = (msg) =>
|
|
213
|
+
// Suppress sourcemap warnings for published @rudderjs/* packages
|
|
214
|
+
msg.includes('Sourcemap') &&
|
|
215
|
+
msg.includes('missing source files') &&
|
|
216
|
+
msg.includes('@rudderjs');
|
|
217
|
+
const origWarn = config.logger.warn.bind(config.logger);
|
|
218
|
+
const origWarnOnce = config.logger.warnOnce.bind(config.logger);
|
|
219
|
+
config.logger.warn = (msg, opts) => { if (!filter(msg))
|
|
220
|
+
origWarn(msg, opts); };
|
|
221
|
+
config.logger.warnOnce = (msg, opts) => { if (!filter(msg))
|
|
222
|
+
origWarnOnce(msg, opts); };
|
|
223
|
+
},
|
|
224
|
+
config() {
|
|
225
|
+
return {
|
|
226
|
+
resolve: {
|
|
227
|
+
alias: [
|
|
228
|
+
{ find: '@', replacement: path.resolve(process.cwd(), 'src') },
|
|
229
|
+
{ find: /^App\//, replacement: path.resolve(process.cwd(), 'app') + '/' },
|
|
230
|
+
],
|
|
231
|
+
},
|
|
232
|
+
// `@rudderjs/view` is imported from routes/web.ts during SSR. Vite's
|
|
233
|
+
// first-run dep pre-bundler can't resolve it when the package is
|
|
234
|
+
// linked via pnpm overrides in a non-workspace project (e.g. a
|
|
235
|
+
// fresh scaffolded app pointing at a local rudderjs checkout) —
|
|
236
|
+
// the second `vike dev` invocation succeeds because Vite's cache
|
|
237
|
+
// is warm, but the first cold boot fails with a cryptic
|
|
238
|
+
// "Cannot find module '@rudderjs/view'" error. Excluding it from
|
|
239
|
+
// dep optimization lets Vite resolve it via normal Node ESM and
|
|
240
|
+
// skips the flaky scan.
|
|
241
|
+
optimizeDeps: {
|
|
242
|
+
exclude: ['@rudderjs/view'],
|
|
243
|
+
},
|
|
244
|
+
ssr: {
|
|
245
|
+
external: SSR_EXTERNALS,
|
|
246
|
+
noExternal: SSR_NO_EXTERNALS,
|
|
247
|
+
},
|
|
248
|
+
build: {
|
|
249
|
+
rollupOptions: {
|
|
250
|
+
external: (id, importer, isResolved) => {
|
|
251
|
+
// Externalize known server-only packages
|
|
252
|
+
if (SSR_EXTERNALS.some(e => id === e || id.startsWith(e + '/')))
|
|
253
|
+
return true;
|
|
254
|
+
// Externalize node: built-ins that leak through @rudderjs/* packages
|
|
255
|
+
if (id.startsWith('node:'))
|
|
256
|
+
return true;
|
|
257
|
+
return false;
|
|
258
|
+
},
|
|
259
|
+
onwarn(warning, warn) {
|
|
260
|
+
// Suppress "externalized for browser compatibility" for server-only
|
|
261
|
+
// packages — node:crypto (middleware), node:module (support), ioredis.
|
|
262
|
+
if (warning.message.includes('has been externalized for browser compatibility') &&
|
|
263
|
+
(warning.message.includes('/packages/middleware/') ||
|
|
264
|
+
warning.message.includes('/packages/support/') ||
|
|
265
|
+
warning.message.includes('/packages/storage/') ||
|
|
266
|
+
warning.message.includes('ioredis')))
|
|
267
|
+
return;
|
|
268
|
+
// Suppress sourcemap errors from vendor:publish copies (tsx without maps).
|
|
269
|
+
if (warning.message.includes('Error when using sourcemap'))
|
|
270
|
+
return;
|
|
271
|
+
warn(warning);
|
|
270
272
|
},
|
|
271
273
|
},
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
+
},
|
|
275
|
+
};
|
|
274
276
|
},
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
// Attach _vikeVitePluginOptions to the Promise itself.
|
|
278
|
-
// Vike's self-detection scans the *raw* (unresolved) plugins array for this
|
|
279
|
-
// property — finding it here prevents the deprecation warning and the
|
|
280
|
-
// "added 2 times" double-registration error.
|
|
281
|
-
Object.assign(promise, { _vikeVitePluginOptions: {} });
|
|
282
|
-
return promise;
|
|
277
|
+
},
|
|
278
|
+
];
|
|
283
279
|
}
|
|
284
280
|
export default rudderjs;
|
|
285
281
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAA;AAE5B,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAEvD,8DAA8D;AAE9D,MAAM,aAAa,GAAG;IACpB,0EAA0E;IAC1E,yEAAyE;IACzE,oEAAoE;IACpE,6DAA6D;IAC7D,gBAAgB;IAChB,8CAA8C;IAC9C,aAAa;IACb,gBAAgB;IAChB,+BAA+B;IAC/B,yBAAyB;IACzB,wBAAwB;IACxB,6BAA6B;IAC7B,uBAAuB;IACvB,sBAAsB;IACtB,uEAAuE;IACvE,IAAI;IACJ,QAAQ;IACR,gBAAgB;IAChB,oBAAoB;IACpB,wBAAwB;IACxB,gCAAgC;IAChC,wBAAwB;IACxB,gBAAgB;IAChB,sBAAsB;IACtB,SAAS;IACT,kDAAkD;IAClD,mBAAmB;IACnB,qCAAqC;IAC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BACD,MAAM,CAAC,OAAO,EAAE,IAAI;gCAClB,oEAAoE;gCACpE,uEAAuE;gCACvE,IACE,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,iDAAiD,CAAC;oCAC3E,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAC;wCAChD,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC;wCAC9C,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC;wCAC9C,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;oCACtC,OAAM;gCACR,2EAA2E;gCAC3E,IAAI,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,4BAA4B,CAAC;oCAAE,OAAM;gCAClE,IAAI,CAAC,OAAO,CAAC,CAAA;4BACf,CAAC;yBACF;qBACF;iBACF,CAAA;YACH,CAAC;SACF;KACF,CAAA;AACH,CAAC;AAED,eAAe,QAAQ,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page-context enhancer registry.
|
|
3
|
+
*
|
|
4
|
+
* Framework packages register a function here from their provider's `boot()`;
|
|
5
|
+
* the registered functions run on every page render via Vike's `+onCreatePageContext`
|
|
6
|
+
* hook (wired in `hooks/onCreatePageContext.ts`).
|
|
7
|
+
*
|
|
8
|
+
* Use this for cross-cutting properties that should land on every `pageContext`
|
|
9
|
+
* without per-view boilerplate — `pageContext.user`, `pageContext.locale`,
|
|
10
|
+
* `pageContext.flash`, etc.
|
|
11
|
+
*
|
|
12
|
+
* Each enhancer should be fast — they run on every request.
|
|
13
|
+
*/
|
|
14
|
+
import type { PageContext } from 'vike/types';
|
|
15
|
+
export type PageContextEnhancer = (pageContext: PageContext) => void | Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Register a function that runs on every page render.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* // In a provider's boot()
|
|
21
|
+
* registerPageContextEnhancer(async (pageContext) => {
|
|
22
|
+
* pageContext.user = await Auth.user()
|
|
23
|
+
* })
|
|
24
|
+
*/
|
|
25
|
+
export declare function registerPageContextEnhancer(fn: PageContextEnhancer): void;
|
|
26
|
+
/**
|
|
27
|
+
* Run every registered enhancer against `pageContext`, in registration order.
|
|
28
|
+
* Wired into Vike via `+onCreatePageContext`.
|
|
29
|
+
*/
|
|
30
|
+
export declare function runPageContextEnhancers(pageContext: PageContext): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Test-only: clear the registry. NEVER call from app code.
|
|
33
|
+
*/
|
|
34
|
+
export declare function _resetPageContextEnhancersForTests(): void;
|
|
35
|
+
//# sourceMappingURL=page-context-enhancers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-context-enhancers.d.ts","sourceRoot":"","sources":["../src/page-context-enhancers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C,MAAM,MAAM,mBAAmB,GAAG,CAAC,WAAW,EAAE,WAAW,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAkBpF;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CAAC,EAAE,EAAE,mBAAmB,GAAG,IAAI,CAEzE;AAED;;;GAGG;AACH,wBAAsB,uBAAuB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAIrF;AAED;;GAEG;AACH,wBAAgB,kCAAkC,IAAI,IAAI,CAGzD"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page-context enhancer registry.
|
|
3
|
+
*
|
|
4
|
+
* Framework packages register a function here from their provider's `boot()`;
|
|
5
|
+
* the registered functions run on every page render via Vike's `+onCreatePageContext`
|
|
6
|
+
* hook (wired in `hooks/onCreatePageContext.ts`).
|
|
7
|
+
*
|
|
8
|
+
* Use this for cross-cutting properties that should land on every `pageContext`
|
|
9
|
+
* without per-view boilerplate — `pageContext.user`, `pageContext.locale`,
|
|
10
|
+
* `pageContext.flash`, etc.
|
|
11
|
+
*
|
|
12
|
+
* Each enhancer should be fast — they run on every request.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Process-wide enhancer registry. Lives on `globalThis` so it survives
|
|
16
|
+
* Vite SSR module re-evaluation in dev (same pattern as `__rudderjs_app__`).
|
|
17
|
+
*/
|
|
18
|
+
const REGISTRY_KEY = '__rudderjs_page_context_enhancers__';
|
|
19
|
+
function getRegistry() {
|
|
20
|
+
const g = globalThis;
|
|
21
|
+
let registry = g[REGISTRY_KEY];
|
|
22
|
+
if (!registry) {
|
|
23
|
+
registry = [];
|
|
24
|
+
g[REGISTRY_KEY] = registry;
|
|
25
|
+
}
|
|
26
|
+
return registry;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Register a function that runs on every page render.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* // In a provider's boot()
|
|
33
|
+
* registerPageContextEnhancer(async (pageContext) => {
|
|
34
|
+
* pageContext.user = await Auth.user()
|
|
35
|
+
* })
|
|
36
|
+
*/
|
|
37
|
+
export function registerPageContextEnhancer(fn) {
|
|
38
|
+
getRegistry().push(fn);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Run every registered enhancer against `pageContext`, in registration order.
|
|
42
|
+
* Wired into Vike via `+onCreatePageContext`.
|
|
43
|
+
*/
|
|
44
|
+
export async function runPageContextEnhancers(pageContext) {
|
|
45
|
+
for (const fn of getRegistry()) {
|
|
46
|
+
await fn(pageContext);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Test-only: clear the registry. NEVER call from app code.
|
|
51
|
+
*/
|
|
52
|
+
export function _resetPageContextEnhancersForTests() {
|
|
53
|
+
const g = globalThis;
|
|
54
|
+
g[REGISTRY_KEY] = [];
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=page-context-enhancers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"page-context-enhancers.js","sourceRoot":"","sources":["../src/page-context-enhancers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAMH;;;GAGG;AACH,MAAM,YAAY,GAAG,qCAAqC,CAAA;AAE1D,SAAS,WAAW;IAClB,MAAM,CAAC,GAAG,UAAqC,CAAA;IAC/C,IAAI,QAAQ,GAAG,CAAC,CAAC,YAAY,CAAsC,CAAA;IACnE,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,QAAQ,GAAG,EAAE,CAAA;QACb,CAAC,CAAC,YAAY,CAAC,GAAG,QAAQ,CAAA;IAC5B,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,2BAA2B,CAAC,EAAuB;IACjE,WAAW,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;AACxB,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAAC,WAAwB;IACpE,KAAK,MAAM,EAAE,IAAI,WAAW,EAAE,EAAE,CAAC;QAC/B,MAAM,EAAE,CAAC,WAAW,CAAC,CAAA;IACvB,CAAC;AACH,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kCAAkC;IAChD,MAAM,CAAC,GAAG,UAAqC,CAAA;IAC/C,CAAC,CAAC,YAAY,CAAC,GAAG,EAAE,CAAA;AACtB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"views-scanner.d.ts","sourceRoot":"","sources":["../src/views-scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"views-scanner.d.ts","sourceRoot":"","sources":["../src/views-scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAIH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAiZlC;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,MAAM,CAgD3C"}
|
package/dist/views-scanner.js
CHANGED
|
@@ -88,6 +88,17 @@ function walk(dir, extensions, base = dir) {
|
|
|
88
88
|
* deliberate obfuscation.
|
|
89
89
|
*/
|
|
90
90
|
const ROUTE_EXPORT_RE = /(?:^|[\s;])export\s+const\s+route\s*(?::\s*string)?\s*=\s*['"`]([^'"`]+)['"`]/m;
|
|
91
|
+
/**
|
|
92
|
+
* Read the `export const route = '...'` override from a view file, if any.
|
|
93
|
+
*
|
|
94
|
+
* Returns `null` on read failure (missing file, permission error, encoding
|
|
95
|
+
* issue) so callers fall back to the id-derived URL. This swallow is
|
|
96
|
+
* intentional: a transient read error during dev rescans should not crash
|
|
97
|
+
* the scanner — the next `change` event from the watcher will retry. Real
|
|
98
|
+
* authoring mistakes (typo in the export, wrong quote style) silently fall
|
|
99
|
+
* through to the convention URL, which is the same behavior as "no override
|
|
100
|
+
* present" — surfaces as a mismatched URL the developer can see.
|
|
101
|
+
*/
|
|
91
102
|
function readRouteOverride(absPath) {
|
|
92
103
|
try {
|
|
93
104
|
const source = fs.readFileSync(absPath, 'utf8');
|
|
@@ -223,20 +234,65 @@ export default '${view.url}'
|
|
|
223
234
|
}
|
|
224
235
|
/**
|
|
225
236
|
* Single shared config at the views root that tells Vike to serialize
|
|
226
|
-
* `viewProps` from server pageContext to the client. Without
|
|
227
|
-
* server SSR works but hydration crashes because the client
|
|
228
|
-
* receives `props = {}` (viewProps is undefined client-side).
|
|
237
|
+
* `viewProps` + `viewHeaders` from server pageContext to the client. Without
|
|
238
|
+
* this, the server SSR works but hydration crashes because the client
|
|
239
|
+
* component receives `props = {}` (viewProps is undefined client-side).
|
|
229
240
|
*/
|
|
230
241
|
const VIEW_ROOT_CONFIG = `// AUTO-GENERATED by @rudderjs/vite — do not edit.
|
|
231
|
-
// Forwards controller-supplied viewProps
|
|
242
|
+
// Forwards controller-supplied viewProps + viewHeaders to client hydration.
|
|
232
243
|
import type { Config } from 'vike/types'
|
|
233
244
|
|
|
234
245
|
export default {
|
|
235
|
-
passToClient: ['viewProps'],
|
|
246
|
+
passToClient: ['viewProps', 'viewHeaders'],
|
|
236
247
|
} satisfies Config
|
|
237
248
|
`;
|
|
249
|
+
const FRAMEWORK_HOOK_STUBS = [
|
|
250
|
+
{
|
|
251
|
+
filename: '+onCreatePageContext.ts',
|
|
252
|
+
contents: `// AUTO-GENERATED by @rudderjs/vite — overwrite freely to customize.
|
|
253
|
+
// Wires the page-context enhancer registry so packages can inject typed
|
|
254
|
+
// per-request data into pageContext (e.g. \`pageContext.user\` from @rudderjs/auth).
|
|
255
|
+
export { onCreatePageContext } from '@rudderjs/vite/hooks/onCreatePageContext'
|
|
256
|
+
`,
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
filename: '+onError.ts',
|
|
260
|
+
contents: `// AUTO-GENERATED by @rudderjs/vite — overwrite freely to customize.
|
|
261
|
+
// Routes Vike SSR errors through @rudderjs/core's report() pipeline.
|
|
262
|
+
export { onError } from '@rudderjs/vite/hooks/onError'
|
|
263
|
+
`,
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
filename: '+headersResponse.ts',
|
|
267
|
+
contents: `// AUTO-GENERATED by @rudderjs/vite — overwrite freely to customize.
|
|
268
|
+
// Reads response headers off pageContext.viewHeaders (set by view('id', props, { headers })).
|
|
269
|
+
export { headersResponse } from '@rudderjs/vite/hooks/headersResponse'
|
|
270
|
+
`,
|
|
271
|
+
},
|
|
272
|
+
];
|
|
273
|
+
function generateFrameworkHooks(pagesRoot) {
|
|
274
|
+
fs.mkdirSync(pagesRoot, { recursive: true });
|
|
275
|
+
for (const stub of FRAMEWORK_HOOK_STUBS) {
|
|
276
|
+
const target = path.join(pagesRoot, stub.filename);
|
|
277
|
+
// Only create on first run — preserve user customizations on subsequent
|
|
278
|
+
// syncs. Users who want to override the hook just edit the file in place.
|
|
279
|
+
if (fs.existsSync(target))
|
|
280
|
+
continue;
|
|
281
|
+
fs.writeFileSync(target, stub.contents);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
238
284
|
// ─── File IO ───────────────────────────────────────────────
|
|
239
285
|
const ALL_PAGE_FILENAMES = ['+Page.tsx', '+Page.jsx', '+Page.vue', '+Page.ts', '+Page.js'];
|
|
286
|
+
/**
|
|
287
|
+
* Idempotent file write — read-compare-then-write. Returns `true` only when
|
|
288
|
+
* the content actually changed.
|
|
289
|
+
*
|
|
290
|
+
* Load-bearing for watch stability: Vite's HMR fires on any `fs.writeFile`
|
|
291
|
+
* to a tracked path, even if the bytes are identical. During `buildStart()`
|
|
292
|
+
* and watcher-triggered rescans the scanner re-generates every page file;
|
|
293
|
+
* without this guard, every rescan would trigger a full SSR module
|
|
294
|
+
* invalidation for unchanged pages, causing dev-mode page flicker.
|
|
295
|
+
*/
|
|
240
296
|
function writeIfChanged(file, contents) {
|
|
241
297
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
242
298
|
if (fs.existsSync(file)) {
|
|
@@ -259,10 +315,11 @@ function purgeStalePageFiles(outDir, keep) {
|
|
|
259
315
|
fs.rmSync(p);
|
|
260
316
|
}
|
|
261
317
|
}
|
|
262
|
-
function generate(generatedRoot, views, framework) {
|
|
318
|
+
function generate(generatedRoot, pagesRoot, views, framework) {
|
|
263
319
|
if (views.length === 0)
|
|
264
320
|
return;
|
|
265
321
|
writeIfChanged(path.join(generatedRoot, '+config.ts'), VIEW_ROOT_CONFIG);
|
|
322
|
+
generateFrameworkHooks(pagesRoot);
|
|
266
323
|
const generator = STUB_GENERATORS[framework];
|
|
267
324
|
for (const v of views) {
|
|
268
325
|
const stub = generator(v);
|
|
@@ -320,7 +377,7 @@ export function viewsScannerPlugin() {
|
|
|
320
377
|
const fw = getFramework();
|
|
321
378
|
const views = discover(viewsRoot, pagesRoot, fw);
|
|
322
379
|
cleanStale(generatedRoot, views);
|
|
323
|
-
generate(generatedRoot, views, fw);
|
|
380
|
+
generate(generatedRoot, pagesRoot, views, fw);
|
|
324
381
|
};
|
|
325
382
|
// Eager sync at plugin construction time — Vike scans `pages/` during its
|
|
326
383
|
// own plugin init, so the generated stubs MUST exist on disk before any
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"views-scanner.js","sourceRoot":"","sources":["../src/views-scanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,IAAI,MAAM,WAAW,CAAA;AAgC5B,8DAA8D;AAE9D;;;;;;;GAOG;AACH,SAAS,eAAe,CAAC,GAAW;IAClC,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAA;IAClD,MAAM,SAAS,GAAgB,EAAE,CAAA;IACjC,KAAK,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI;QACtB,CAAC,YAAY,EAAE,OAAO,CAAC;QACvB,CAAC,UAAU,EAAI,KAAK,CAAC;QACrB,CAAC,YAAY,EAAE,OAAO,CAAC;KACf,EAAE,CAAC;QACX,IAAI,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,GAAG,EAAE,cAAc,CAAC,CAAC,EAAE,CAAC;YAC/D,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;QACpB,CAAC;IACH,CAAC;IAED,IAAI,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CACb,2DAA2D,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK;YACpF,uDAAuD,CACxD,CAAA;IACH,CAAC;IACD,OAAO,SAAS,CAAC,CAAC,CAAC,IAAI,SAAS,CAAA;AAClC,CAAC;AAED,8DAA8D;AAE9D,MAAM,uBAAuB,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AAI,EAAE,CAAA;QACR,CAAC;QACD,eAAe,CAAC,MAAM;YACpB,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,SAAS,CAAC;gBAAE,OAAM;YACrC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAA;YAC7B,MAAM,QAAQ,GAAG,CAAC,IAAY,EAAQ,EAAE;gBACtC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC;oBAAE,OAAM;gBACvC,MAAM,IAAI,GAAG,uBAAuB,CAAC,YAAY,EAAE,CAAC,CAAA;gBACpD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;oBAAE,OAAM;gBAC3D,IAAI,EAAE,CAAA;YACR,CAAC,CAAA;YACD,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAK,QAAQ,CAAC,CAAA;YACrC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;YACrC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAA;QACvC,CAAC;KACF,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rudderjs/vite",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -18,6 +18,26 @@
|
|
|
18
18
|
".": {
|
|
19
19
|
"import": "./dist/index.js",
|
|
20
20
|
"types": "./dist/index.d.ts"
|
|
21
|
+
},
|
|
22
|
+
"./page-context-enhancers": {
|
|
23
|
+
"import": "./dist/page-context-enhancers.js",
|
|
24
|
+
"default": "./dist/page-context-enhancers.js",
|
|
25
|
+
"types": "./dist/page-context-enhancers.d.ts"
|
|
26
|
+
},
|
|
27
|
+
"./hooks/onCreatePageContext": {
|
|
28
|
+
"import": "./dist/hooks/onCreatePageContext.js",
|
|
29
|
+
"default": "./dist/hooks/onCreatePageContext.js",
|
|
30
|
+
"types": "./dist/hooks/onCreatePageContext.d.ts"
|
|
31
|
+
},
|
|
32
|
+
"./hooks/onError": {
|
|
33
|
+
"import": "./dist/hooks/onError.js",
|
|
34
|
+
"default": "./dist/hooks/onError.js",
|
|
35
|
+
"types": "./dist/hooks/onError.d.ts"
|
|
36
|
+
},
|
|
37
|
+
"./hooks/headersResponse": {
|
|
38
|
+
"import": "./dist/hooks/headersResponse.js",
|
|
39
|
+
"default": "./dist/hooks/headersResponse.js",
|
|
40
|
+
"types": "./dist/hooks/headersResponse.d.ts"
|
|
21
41
|
}
|
|
22
42
|
},
|
|
23
43
|
"peerDependencies": {
|
|
@@ -25,9 +45,13 @@
|
|
|
25
45
|
"vike": ">=0.4.0",
|
|
26
46
|
"@vitejs/plugin-react": ">=4.0.0",
|
|
27
47
|
"@vitejs/plugin-vue": ">=5.0.0",
|
|
28
|
-
"vike-solid": ">=0.8.0"
|
|
48
|
+
"vike-solid": ">=0.8.0",
|
|
49
|
+
"@rudderjs/core": "^1.1.4"
|
|
29
50
|
},
|
|
30
51
|
"peerDependenciesMeta": {
|
|
52
|
+
"@rudderjs/core": {
|
|
53
|
+
"optional": true
|
|
54
|
+
},
|
|
31
55
|
"@vitejs/plugin-react": {
|
|
32
56
|
"optional": true
|
|
33
57
|
},
|
|
@@ -45,7 +69,8 @@
|
|
|
45
69
|
"typescript": "^5.4.0",
|
|
46
70
|
"vike": "^0.4.239",
|
|
47
71
|
"vike-solid": "^0.8.1",
|
|
48
|
-
"vite": "^7.1.0"
|
|
72
|
+
"vite": "^7.1.0",
|
|
73
|
+
"@rudderjs/core": "^1.1.4"
|
|
49
74
|
},
|
|
50
75
|
"author": "Suleiman Shahbari",
|
|
51
76
|
"scripts": {
|
|
@@ -53,7 +78,7 @@
|
|
|
53
78
|
"dev": "tsc -p tsconfig.build.json --watch",
|
|
54
79
|
"typecheck": "tsc --noEmit",
|
|
55
80
|
"lint": "eslint src",
|
|
56
|
-
"test": "tsc -p tsconfig.test.json && node --test dist-test
|
|
81
|
+
"test": "tsc -p tsconfig.test.json && node --test 'dist-test/**/*.test.js'; EXIT=$?; rm -rf dist-test; exit $EXIT",
|
|
57
82
|
"clean": "rm -rf dist"
|
|
58
83
|
}
|
|
59
84
|
}
|