@timber-js/app 0.2.0-alpha.59 → 0.2.0-alpha.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +30 -1
- package/dist/index.js.map +1 -1
- package/dist/plugins/shims.d.ts +5 -7
- package/dist/plugins/shims.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/plugins/shims.ts +69 -11
package/dist/plugins/shims.d.ts
CHANGED
|
@@ -5,13 +5,11 @@
|
|
|
5
5
|
* shim implementations. This enables Next.js-compatible libraries
|
|
6
6
|
* (nuqs, next-intl, etc.) to work unmodified.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* code in browser bundles. See TIM-568 for why src/ remapping was
|
|
14
|
-
* removed.
|
|
8
|
+
* This plugin also remaps ALL @timber-js/app/* subpath imports to src/ in
|
|
9
|
+
* server environments (RSC + SSR). This is required because dist/ chunks
|
|
10
|
+
* are pre-built and miss Vite's RSC transforms (e.g. createContext from
|
|
11
|
+
* 'react' doesn't exist in RSC's React build). It also ensures a single
|
|
12
|
+
* module instance for shared mutable state. See SUBPATH_SRC_MAP and TIM-568.
|
|
15
13
|
*
|
|
16
14
|
* Design doc: 18-build-system.md §"Shim Map"
|
|
17
15
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shims.d.ts","sourceRoot":"","sources":["../../src/plugins/shims.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"shims.d.ts","sourceRoot":"","sources":["../../src/plugins/shims.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAGnC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAmEjD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,aAAa,GAAG,MAAM,CA+KvD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@timber-js/app",
|
|
3
|
-
"version": "0.2.0-alpha.
|
|
3
|
+
"version": "0.2.0-alpha.60",
|
|
4
4
|
"description": "Vite-native React framework built for Servers and Serverless Platforms — correct HTTP semantics, real status codes, pages that work without JavaScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare-workers",
|
package/src/plugins/shims.ts
CHANGED
|
@@ -5,13 +5,11 @@
|
|
|
5
5
|
* shim implementations. This enables Next.js-compatible libraries
|
|
6
6
|
* (nuqs, next-intl, etc.) to work unmodified.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* code in browser bundles. See TIM-568 for why src/ remapping was
|
|
14
|
-
* removed.
|
|
8
|
+
* This plugin also remaps ALL @timber-js/app/* subpath imports to src/ in
|
|
9
|
+
* server environments (RSC + SSR). This is required because dist/ chunks
|
|
10
|
+
* are pre-built and miss Vite's RSC transforms (e.g. createContext from
|
|
11
|
+
* 'react' doesn't exist in RSC's React build). It also ensures a single
|
|
12
|
+
* module instance for shared mutable state. See SUBPATH_SRC_MAP and TIM-568.
|
|
15
13
|
*
|
|
16
14
|
* Design doc: 18-build-system.md §"Shim Map"
|
|
17
15
|
*/
|
|
@@ -41,6 +39,24 @@ const SHIMS_DIR = resolve(PKG_ROOT, 'src', 'shims');
|
|
|
41
39
|
const SERVER_ONLY_VIRTUAL = '\0timber:server-only';
|
|
42
40
|
const CLIENT_ONLY_VIRTUAL = '\0timber:client-only';
|
|
43
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Map from @timber-js/app/<subpath> to relative src/ file paths.
|
|
44
|
+
*
|
|
45
|
+
* Used by the catch-all resolveId rule to remap subpath imports to src/
|
|
46
|
+
* in server environments. When adding a new subpath export to package.json,
|
|
47
|
+
* add it here too. See TIM-568.
|
|
48
|
+
*/
|
|
49
|
+
const SUBPATH_SRC_MAP: Record<string, string> = {
|
|
50
|
+
'cache': 'cache/index.ts',
|
|
51
|
+
'content': 'content/index.ts',
|
|
52
|
+
'cookies': 'cookies/index.ts',
|
|
53
|
+
'params': 'params/index.ts',
|
|
54
|
+
'search-params': 'search-params/index.ts',
|
|
55
|
+
'routing': 'routing/index.ts',
|
|
56
|
+
'adapters/cloudflare': 'adapters/cloudflare.ts',
|
|
57
|
+
'adapters/nitro': 'adapters/nitro.ts',
|
|
58
|
+
};
|
|
59
|
+
|
|
44
60
|
/**
|
|
45
61
|
* Map from next/* import specifiers to shim file paths.
|
|
46
62
|
*
|
|
@@ -120,15 +136,57 @@ export function timberShims(_ctx: PluginContext): Plugin {
|
|
|
120
136
|
return SHIM_MAP[cleanId];
|
|
121
137
|
}
|
|
122
138
|
|
|
123
|
-
// @timber-js/app
|
|
124
|
-
//
|
|
125
|
-
//
|
|
126
|
-
//
|
|
139
|
+
// ── @timber-js/app/* → src/ resolution in server environments ──
|
|
140
|
+
//
|
|
141
|
+
// All @timber-js/app/* subpath imports are remapped to src/ in server
|
|
142
|
+
// environments (RSC + SSR). This is required for two reasons:
|
|
143
|
+
//
|
|
144
|
+
// 1. RSC correctness: dist/ chunks eagerly import from 'react' (e.g.
|
|
145
|
+
// createContext in segment-context) which doesn't exist in RSC's
|
|
146
|
+
// React build. Vite's RSC plugin only transforms src/ files —
|
|
147
|
+
// dist/ chunks are pre-built and served as-is.
|
|
148
|
+
//
|
|
149
|
+
// 2. Module singleton correctness: framework internals use relative
|
|
150
|
+
// imports that resolve within src/. If user code resolved to dist/
|
|
151
|
+
// while framework code resolved to src/, mutable module-level state
|
|
152
|
+
// (ALS refs, registered callbacks) would be duplicated. By remapping
|
|
153
|
+
// all @timber-js/app/* to src/, everything shares one module graph.
|
|
154
|
+
//
|
|
155
|
+
// Exception: @timber-js/app/client in RSC resolves to dist/ where
|
|
156
|
+
// 'use client' is preserved for client boundary detection.
|
|
157
|
+
//
|
|
158
|
+
// In the client (browser) environment, all imports resolve to dist/
|
|
159
|
+
// via package.json exports (no remapping needed).
|
|
160
|
+
|
|
127
161
|
if (cleanId === '@timber-js/app/server') {
|
|
128
162
|
const envName = (this as unknown as { environment?: { name?: string } }).environment?.name;
|
|
129
163
|
if (envName === 'client') {
|
|
130
164
|
return '\0timber:server-empty';
|
|
131
165
|
}
|
|
166
|
+
// RSC + SSR: remap to src/
|
|
167
|
+
return resolve(PKG_ROOT, 'src', 'server', 'index.ts');
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (cleanId === '@timber-js/app/client') {
|
|
171
|
+
const envName = (this as unknown as { environment?: { name?: string } }).environment?.name;
|
|
172
|
+
// SSR only — RSC needs dist/ for 'use client' boundary detection
|
|
173
|
+
if (envName === 'ssr') {
|
|
174
|
+
return resolve(PKG_ROOT, 'src', 'client', 'index.ts');
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Catch-all: remap any other @timber-js/app/<subpath> to src/
|
|
180
|
+
// in non-client environments (RSC + SSR).
|
|
181
|
+
if (cleanId.startsWith('@timber-js/app/') && cleanId !== '@timber-js/app/package.json') {
|
|
182
|
+
const envName = (this as unknown as { environment?: { name?: string } }).environment?.name;
|
|
183
|
+
if (envName !== 'client') {
|
|
184
|
+
const subpath = cleanId.slice('@timber-js/app/'.length);
|
|
185
|
+
const srcPath = SUBPATH_SRC_MAP[subpath];
|
|
186
|
+
if (srcPath) {
|
|
187
|
+
return resolve(PKG_ROOT, 'src', srcPath);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
132
190
|
}
|
|
133
191
|
|
|
134
192
|
return null;
|