@timber-js/app 0.2.0-alpha.224 → 0.2.0-alpha.226
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/_chunks/{actions-7dTXYJfu.js → actions-B1xSIv32.js} +2 -2
- package/dist/_chunks/{actions-7dTXYJfu.js.map → actions-B1xSIv32.js.map} +1 -1
- package/dist/_chunks/{cache-api-TDZ4hlDc.js → cache-api-DsSXA4Sp.js} +68 -47
- package/dist/_chunks/cache-api-DsSXA4Sp.js.map +1 -0
- package/dist/_chunks/{cli-check-Dv3f8d2j.js → cli-check-B33yhAPa.js} +2 -2
- package/dist/_chunks/{cli-check-Dv3f8d2j.js.map → cli-check-B33yhAPa.js.map} +1 -1
- package/dist/_chunks/cli-context-BPdyA7Fp.js +1 -0
- package/dist/_chunks/{cli-context-CbZp32SK.js → cli-context-CwTKMjVe.js} +10 -2
- package/dist/_chunks/cli-context-CwTKMjVe.js.map +1 -0
- package/dist/_chunks/{error-boundary-DRQXGWCp.js → error-boundary-D3YyVVuP.js} +2 -2
- package/dist/_chunks/{error-boundary-DRQXGWCp.js.map → error-boundary-D3YyVVuP.js.map} +1 -1
- package/dist/_chunks/navigation-root-M3B2ZrdO.js.map +1 -1
- package/dist/_chunks/{singleflight-BChPMjwH.js → singleflight-CzoOVB9Y.js} +2 -3
- package/dist/_chunks/singleflight-CzoOVB9Y.js.map +1 -0
- package/dist/_chunks/{status-page-marker-XIQXlTOb.js → status-page-marker-C8POawuF.js} +2 -2
- package/dist/_chunks/{status-page-marker-XIQXlTOb.js.map → status-page-marker-C8POawuF.js.map} +1 -1
- package/dist/adapters/cloudflare-kv-cache.d.ts +0 -1
- package/dist/adapters/cloudflare-kv-cache.d.ts.map +1 -1
- package/dist/adapters/cloudflare-kv-cache.js.map +1 -1
- package/dist/cache/index.d.ts +5 -5
- package/dist/cache/index.d.ts.map +1 -1
- package/dist/cache/index.js +1 -1
- package/dist/cache/redis-handler.d.ts +0 -1
- package/dist/cache/redis-handler.d.ts.map +1 -1
- package/dist/cache/singleflight.d.ts +12 -2
- package/dist/cache/singleflight.d.ts.map +1 -1
- package/dist/cache/stable-stringify.d.ts +6 -0
- package/dist/cache/stable-stringify.d.ts.map +1 -1
- package/dist/cache/tag-aware-handler.d.ts +0 -1
- package/dist/cache/tag-aware-handler.d.ts.map +1 -1
- package/dist/cache/timber-cache.d.ts +1 -1
- package/dist/cache/timber-cache.d.ts.map +1 -1
- package/dist/cli-context.d.ts +8 -0
- package/dist/cli-context.d.ts.map +1 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +8 -2
- package/dist/cli.js.map +1 -1
- package/dist/client/error-boundary.js +1 -1
- package/dist/client/internal.js +3 -3
- package/dist/client/navigation-root.d.ts.map +1 -1
- package/dist/client/nuqs-adapter.d.ts +4 -1
- package/dist/client/nuqs-adapter.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +112 -0
- package/dist/index.js.map +1 -1
- package/dist/plugins/client-in-server-package-deps.d.ts +63 -0
- package/dist/plugins/client-in-server-package-deps.d.ts.map +1 -0
- package/dist/plugins/optimize-package-imports.d.ts +11 -0
- package/dist/plugins/optimize-package-imports.d.ts.map +1 -1
- package/dist/server/flight-injector-core.d.ts.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/internal.js +162 -33
- package/dist/server/internal.js.map +1 -1
- package/dist/server/pipeline-helpers.d.ts +5 -2
- package/dist/server/pipeline-helpers.d.ts.map +1 -1
- package/dist/server/pipeline.d.ts.map +1 -1
- package/dist/server/prebuilt-runtime.d.ts.map +1 -1
- package/dist/server/response-framing.d.ts +43 -0
- package/dist/server/response-framing.d.ts.map +1 -0
- package/dist/server/ssr-entry.d.ts.map +1 -1
- package/dist/server/ssr-wrappers.d.ts +9 -10
- package/dist/server/ssr-wrappers.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/adapters/cloudflare-kv-cache.ts +1 -5
- package/src/cache/index.ts +7 -27
- package/src/cache/redis-handler.ts +1 -5
- package/src/cache/singleflight.ts +17 -5
- package/src/cache/stable-stringify.ts +53 -0
- package/src/cache/tag-aware-handler.ts +1 -5
- package/src/cache/timber-cache.ts +55 -52
- package/src/cli-context.ts +9 -0
- package/src/cli.ts +16 -0
- package/src/client/navigation-root.tsx +7 -6
- package/src/client/nuqs-adapter.tsx +46 -28
- package/src/index.ts +2 -0
- package/src/plugins/client-in-server-package-deps.ts +139 -0
- package/src/plugins/optimize-package-imports.ts +1 -1
- package/src/server/flight-injector-core.ts +13 -9
- package/src/server/pipeline-helpers.ts +9 -5
- package/src/server/pipeline.ts +7 -0
- package/src/server/prebuilt-runtime.ts +125 -121
- package/src/server/response-framing.ts +59 -0
- package/src/server/ssr-entry.ts +0 -2
- package/src/server/ssr-wrappers.tsx +39 -49
- package/dist/_chunks/cache-api-TDZ4hlDc.js.map +0 -1
- package/dist/_chunks/cli-context-CbZp32SK.js.map +0 -1
- package/dist/_chunks/cli-context-n5hmkdla.js +0 -1
- package/dist/_chunks/singleflight-BChPMjwH.js.map +0 -1
- package/dist/server/nuqs-ssr-provider.d.ts +0 -32
- package/dist/server/nuqs-ssr-provider.d.ts.map +0 -1
- package/src/server/nuqs-ssr-provider.tsx +0 -64
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stable-stringify.d.ts","sourceRoot":"","sources":["../../src/cache/stable-stringify.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"stable-stringify.d.ts","sourceRoot":"","sources":["../../src/cache/stable-stringify.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAkFtD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tag-aware-handler.d.ts","sourceRoot":"","sources":["../../src/cache/tag-aware-handler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH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,yEAAyE;IACzE,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,aAAa;IAIf,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC,CAsBzE;IAEK,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAgD3F;IAEK,UAAU,CAAC,IAAI,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA0CpE;YAIa,cAAc;YAWd,cAAc;CAe7B"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CacheHandler, CacheOptions } from './index.ts';
|
|
2
2
|
/**
|
|
3
|
-
* Set the timeout for
|
|
3
|
+
* Set the timeout for cache calls without a per-call timeoutMs.
|
|
4
4
|
* Called at framework boot with renderTimeoutMs from timber.config.ts so that
|
|
5
5
|
* cache calls without a per-call timeoutMs still get deadlock protection.
|
|
6
6
|
* See design/06-caching.md §"Singleflight Timeout — Deadlock Risk".
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"timber-cache.d.ts","sourceRoot":"","sources":["../../src/cache/timber-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"timber-cache.d.ts","sourceRoot":"","sources":["../../src/cache/timber-cache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AA4B7D;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,SAAS,EAAE,MAAM,GAAG,IAAI,CAErE;AAoED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,wBAAgB,WAAW,CAAC,EAAE,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,EACrE,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,YAAY,CAAC,EAAE,CAAC,EACtB,UAAU,EAAE,MAAM,YAAY,EAC9B,QAAQ,CAAC,EAAE,MAAM,GAChB,EAAE,CA8JJ"}
|
package/dist/cli-context.d.ts
CHANGED
|
@@ -27,6 +27,14 @@ export interface PluginWithApi {
|
|
|
27
27
|
name: string;
|
|
28
28
|
api?: unknown;
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Whether a resolved Vite plugin list includes timber. Vite resolves a
|
|
32
|
+
* missing config file to an empty one rather than failing, so a caller that
|
|
33
|
+
* needs timber must ask — `timber dev` would otherwise serve plain Vite.
|
|
34
|
+
*/
|
|
35
|
+
export declare function hasTimberPlugin(plugins: readonly {
|
|
36
|
+
name: string;
|
|
37
|
+
}[]): boolean;
|
|
30
38
|
/**
|
|
31
39
|
* Vite's own `resolveConfig`, narrowed to what this module passes and reads.
|
|
32
40
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-context.d.ts","sourceRoot":"","sources":["../src/cli-context.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAqB,KAAK,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAK5E,8DAA8D;AAC9D,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED;;;;;;;;;GASG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC9B,YAAY,EAAE;IAAE,UAAU,EAAE,MAAM,GAAG,SAAS,CAAA;CAA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;;GAaG;AACH,wBAAsB,MAAM,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAwErF;AAED;;;;GAIG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAMvF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBzF;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAsB,QAAQ,CAAC,OAAO,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC,CAMxF;AAID;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CA6C7D"}
|
package/dist/cli.js
CHANGED
|
@@ -88,6 +88,12 @@ function parseArgs(args) {
|
|
|
88
88
|
async function runDev(options, _deps) {
|
|
89
89
|
if (process.env.__TIMBER_DEV_WORKER) {
|
|
90
90
|
const server = await (_deps?.createServer ?? (await import("vite")).createServer)({ configFile: options.config });
|
|
91
|
+
const { hasTimberPlugin } = await import("./_chunks/cli-context-BPdyA7Fp.js");
|
|
92
|
+
if (!hasTimberPlugin(server.config.plugins)) {
|
|
93
|
+
await server.close();
|
|
94
|
+
const where = server.config.configFile ?? `no Vite config found in ${server.config.root}`;
|
|
95
|
+
throw new Error(`[timber] The Vite config does not use the timber plugin (${where}).\n\n \`timber dev\` stopped instead of starting plain Vite. This happens when a\n config file changes on disk, for example a git checkout to a branch\n without timber. Run \`timber dev\` again once vite.config.ts lists timber().`);
|
|
96
|
+
}
|
|
91
97
|
await server.listen();
|
|
92
98
|
server.printUrls();
|
|
93
99
|
return;
|
|
@@ -145,7 +151,7 @@ async function runBuild(options, _deps) {
|
|
|
145
151
|
* exists but fails to load throws, naming the file (TIM-1066).
|
|
146
152
|
*/
|
|
147
153
|
async function runPreview(options, _deps) {
|
|
148
|
-
const { resolveTimberContext } = await import("./_chunks/cli-context-
|
|
154
|
+
const { resolveTimberContext } = await import("./_chunks/cli-context-BPdyA7Fp.js");
|
|
149
155
|
const { adapterConfig, contextAdapter } = await import("./_chunks/plugin-context-BfSRKJfz.js");
|
|
150
156
|
const ctx = await resolveTimberContext("preview", options.config, _deps?.resolveViteConfig);
|
|
151
157
|
const adapter = contextAdapter(ctx);
|
|
@@ -173,7 +179,7 @@ async function runPreview(options, _deps) {
|
|
|
173
179
|
* `--project` names the tsconfig handed to tsgo.
|
|
174
180
|
*/
|
|
175
181
|
async function runCheck(options, _deps) {
|
|
176
|
-
const { checkRoutes, runTypeCheck } = await import("./_chunks/cli-check-
|
|
182
|
+
const { checkRoutes, runTypeCheck } = await import("./_chunks/cli-check-B33yhAPa.js");
|
|
177
183
|
const { root } = await checkRoutes({ viteConfigFile: options.config }, _deps);
|
|
178
184
|
await runTypeCheck({
|
|
179
185
|
root,
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\n// timber.js CLI\n//\n// Wraps Vite commands with timber-specific behavior.\n// See design/18-build-system.md §\"CLI\".\n//\n// Commands:\n// timber dev — Start Vite dev server with HMR\n// timber build — Run multi-environment build via createBuilder/buildApp\n// timber preview — Serve the production build\n// timber check — Validate types + routes without building\n// timber graph — Classify a file's module environment(s) (design/47)\n// timber dev status — List running dev servers for this checkout (design/21)\n// timber init — Point AGENTS.md / CLAUDE.md at the installed agent guide\n\n// Type-only — the implementation is imported dynamically inside runCheck so the\n// CLI's other commands never load the route scanner.\nimport type { CheckDeps } from './cli-check.ts';\nimport type { ResolveViteConfig } from './cli-context.ts';\n\nexport type { CheckDeps };\n\nconst COMMANDS = ['dev', 'build', 'preview', 'check', 'schema', 'init', 'graph'] as const;\ntype Command = (typeof COMMANDS)[number];\n\nexport interface ParsedArgs {\n command: Command;\n config: string | undefined;\n /** `--project`: the tsconfig `timber check` passes to tsgo. */\n project: string | undefined;\n /** `timber graph` and `timber dev status`: emit the machine-readable JSON contract. */\n json: boolean;\n /** `timber graph` only: classify the whole project. */\n all: boolean;\n /** Positional arguments after the command (`schema sync`, `dev status`, `graph <file>`). */\n rest: string[];\n}\n\nexport interface CommandOptions {\n /** Path to a Vite config file. Means the same thing for every command. */\n config?: string;\n /** `timber check` only: the tsconfig to type-check. */\n project?: string;\n}\n\n/**\n * Parse CLI arguments into a structured command + options.\n * Accepts: timber <command> [--config|-c <path>] [--project <path>]\n *\n * `--config` names a **Vite** config file for every command, `check` included\n * (TIM-1332): `check` resolves the project through Vite, so a project that\n * builds with `--config ./custom.vite.config.ts` has to be checkable the same\n * way. `--project` names the tsconfig, spelled as tsgo and tsc spell it, and\n * is meaningful only for `check`.\n *\n * Before TIM-1332 `--config` meant the tsconfig for `check` alone — one flag\n * with two meanings, which the docs had to carry a note to explain and which\n * left custom Vite configs unreachable from `check` entirely.\n *\n * Unknown flags are an error, not silently ignored — `timber dev --port 4000`\n * starting on the default port would contradict fail-loudly. The surface stays\n * deliberately small (design/11-platform.md §CLI); port selection goes through\n * the PORT env var or server.port in vite.config.ts.\n *\n * Each subcommand declares its exact flags (the `check --project` precedent,\n * TIM-1332): `graph` additionally accepts a file positional plus `--json` and\n * `--all`, and those two are rejected everywhere else — except `--json`,\n * which `dev status` accepts too.\n */\nexport function parseArgs(args: string[]): ParsedArgs {\n if (args.length === 0) {\n throw new Error(\n 'No command provided. Usage: timber <dev|build|preview|check|schema|init|graph> [--config <path>]'\n );\n }\n\n const command = args[0];\n if (!COMMANDS.includes(command as Command)) {\n throw new Error(`Unknown command: ${command}. Available commands: ${COMMANDS.join(', ')}`);\n }\n\n let config: string | undefined;\n let project: string | undefined;\n let json = false;\n let all = false;\n const rest: string[] = [];\n for (let i = 1; i < args.length; i++) {\n const arg = args[i];\n if (arg === '--config' || arg === '-c') {\n config = args[++i];\n if (!config) {\n throw new Error('--config requires a path argument');\n }\n } else if (arg === '--json') {\n json = true;\n } else if (arg === '--all') {\n if (command !== 'graph') {\n throw new Error(`--all is only valid for \\`timber graph\\` (the module-environment query).`);\n }\n all = true;\n } else if (arg === '--project') {\n if (command !== 'check') {\n throw new Error(\n `--project is only valid for \\`timber check\\` (it names the tsconfig to type-check). ` +\n `To point \\`timber ${command}\\` at a different Vite config, use --config <path>.`\n );\n }\n project = args[++i];\n if (!project) {\n throw new Error('--project requires a path argument');\n }\n } else if (arg.startsWith('-')) {\n const portHint =\n arg === '--port' || arg === '-p'\n ? ' To change the port, set the PORT environment variable (PORT=4000 timber dev) ' +\n 'or server.port in vite.config.ts.'\n : '';\n throw new Error(\n `Unknown option: ${arg}. The timber CLI accepts --config <path>` +\n ` (and --project <path> for \\`check\\`).${portHint}`\n );\n } else if (\n command === 'schema' ||\n command === 'init' ||\n command === 'graph' ||\n (command === 'dev' && rest.length === 0 && arg === 'status')\n ) {\n rest.push(arg);\n } else {\n throw new Error(`Unexpected argument: ${arg}. Usage: timber ${command} [--config <path>]`);\n }\n }\n\n // Checked after the loop so flag order does not matter (`dev --json status`).\n const devStatus = command === 'dev' && rest[0] === 'status';\n if (json && command !== 'graph' && !devStatus) {\n throw new Error(`--json is only valid for \\`timber graph\\` and \\`timber dev status\\`.`);\n }\n\n if (command === 'graph' && rest.length > 1) {\n throw new Error(\n `timber graph takes one file. Usage: timber graph <file> [--json], or timber graph --all --json`\n );\n }\n\n return { command: command as Command, config, project, json, all, rest };\n}\n\n// ─── Command Implementations ─────────────────────────────────────────────────\n\n/** @internal Dependency injection for testing. */\nexport interface ViteDeps {\n createServer?: typeof import('vite').createServer;\n createBuilder?: typeof import('vite').createBuilder;\n resolveViteConfig?: ResolveViteConfig;\n}\n\n/**\n * Start the Vite dev server with a supervisor that respawns the process\n * when timber.config.ts changes. Node's require cache for ESM modules\n * loaded via require() cannot be evicted, so an in-process restart\n * serves stale config. The supervisor forks a worker; when the worker\n * exits with RESTART_EXIT_CODE (set by timber-dev-server on config file\n * change), the supervisor spawns a fresh worker with a clean cache.\n *\n * The timber plugin binds the port immediately with a holding page\n * (in rootSync's config hook) so browsers see a \"starting...\" page\n * instead of ERR_CONNECTION_REFUSED during initialization.\n *\n * See design/21-dev-server.md, TIM-665, TIM-1444.\n */\nexport async function runDev(options: CommandOptions, _deps?: ViteDeps): Promise<void> {\n // Worker mode: run the dev server directly (forked by supervisor below)\n if (process.env.__TIMBER_DEV_WORKER) {\n const createServer = _deps?.createServer ?? (await import('vite')).createServer;\n const server = await createServer({\n configFile: options.config,\n });\n await server.listen();\n server.printUrls();\n return;\n }\n\n // Supervisor mode: fork a worker and respawn on config changes.\n const { fork } = await import('node:child_process');\n const { RESTART_EXIT_CODE } = await import('./plugins/dev-server.ts');\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n const result = await new Promise<{ code: number | null; signal: NodeJS.Signals | null }>(\n (resolve) => {\n const child = fork(process.argv[1], process.argv.slice(2), {\n stdio: 'inherit',\n env: { ...process.env, __TIMBER_DEV_WORKER: '1' },\n });\n\n // Forward signals to the child. SIGINT from Ctrl+C is sent to\n // the entire process group, but a targeted SIGTERM (from a\n // process manager or test teardown) only reaches the parent.\n const onSigint = () => child.kill('SIGINT');\n const onSigterm = () => child.kill('SIGTERM');\n process.on('SIGINT', onSigint);\n process.on('SIGTERM', onSigterm);\n\n child.on('exit', (code, signal) => {\n process.off('SIGINT', onSigint);\n process.off('SIGTERM', onSigterm);\n resolve({ code, signal });\n });\n }\n );\n\n if (result.code === RESTART_EXIT_CODE) {\n continue;\n }\n\n // Child was killed by a signal (e.g. SIGTERM) — re-raise on ourselves\n if (result.signal) {\n process.kill(process.pid, result.signal);\n }\n\n if (result.code != null && result.code !== 0) {\n process.exit(result.code);\n }\n\n break;\n }\n}\n\n/**\n * Run the production build using createBuilder + buildApp.\n * Direct build() calls do NOT trigger the RSC plugin's multi-environment\n * pipeline — createBuilder/buildApp is required.\n */\nexport async function runBuild(options: CommandOptions, _deps?: ViteDeps): Promise<void> {\n const createBuilder = _deps?.createBuilder ?? (await import('vite')).createBuilder;\n const builder = await createBuilder({\n configFile: options.config,\n });\n await builder.buildApp();\n}\n\n/**\n * Serve the production build for local testing.\n * The adapter's preview() serves it; without one, preview fails (TIM-1565).\n * There is no fallback to Vite preview: it would serve the build directory\n * itself — the server bundles as static files, with no root `index.html` —\n * which is useless in either output mode.\n *\n * The project is resolved through Vite, as `timber check` resolves it\n * (`cli-context.ts`), so the adapter, the output mode, and the build\n * directory are the ones `timber build` used — including `--config`, inline\n * `timber({ ... })` options, Vite's `root`, and `build.outDir`, none of which\n * a re-read of `timber.config.ts` can see (TIM-1531). A config file that\n * exists but fails to load throws, naming the file (TIM-1066).\n */\nexport async function runPreview(options: CommandOptions, _deps?: ViteDeps): Promise<void> {\n const { resolveTimberContext } = await import('./cli-context.ts');\n const { adapterConfig, contextAdapter } = await import('./plugin-context.ts');\n\n const ctx = await resolveTimberContext('preview', options.config, _deps?.resolveViteConfig);\n const adapter = contextAdapter(ctx);\n\n if (typeof adapter?.preview !== 'function') {\n const missing = adapter\n ? `The adapter '${adapter.name}' has no preview(), so \\`timber preview\\` cannot serve this build.`\n : `No adapter is configured, so \\`timber preview\\` has nothing to serve this build with.`;\n throw new Error(\n `[timber] ${missing} Use an adapter that implements preview() — ` +\n `cloudflare() from '@timber-js/app/adapters/cloudflare', or nitro() from ` +\n `'@timber-js/app/adapters/nitro' (any preset for a static build; node-server or bun ` +\n `for a server build) — or serve the build with your platform's own tooling.`\n );\n }\n\n await adapter.preview(adapterConfig(ctx), {\n output: ctx.config.output ?? 'server',\n outputDir: ctx.buildDir,\n });\n}\n\n/**\n * Validate routes and types without producing build output.\n *\n * Runs the route pass first — resolve the project through Vite, scan it, fail\n * on proven-fatal convention errors, print warnings, and regenerate the route\n * types — then `tsgo --noEmit`. Codegen has to precede the type pass: the\n * generated `.timber/*.d.ts` files are what type `<Link href>` and\n * `useSegmentParams()`, and a fresh clone has never produced them. See\n * `cli-check.ts` for the full reasoning.\n *\n * `--config` names the **Vite** config, as it does for every other command, so\n * an app that builds with a custom one is checkable the same way.\n * `--project` names the tsconfig handed to tsgo.\n */\nexport async function runCheck(options: CommandOptions, _deps?: CheckDeps): Promise<void> {\n const { checkRoutes, runTypeCheck } = await import('./cli-check.ts');\n const { root } = await checkRoutes({ viteConfigFile: options.config }, _deps);\n // tsgo runs from the root the route pass resolved, not from cwd — that is\n // where it just wrote the declarations tsgo has to read.\n await runTypeCheck({ root, config: options.project }, _deps);\n}\n\n// ─── Schema Subcommand ───────────────────────────────────────────────────────\n\n/**\n * `timber schema sync` — scan filesystem for dynamic segments, diff against\n * app/schema.ts, and append missing entries with type-appropriate codec defaults.\n *\n * See design/41-global-params.md §Auto-Scaffolding\n */\nexport async function runSchema(args: string[]): Promise<void> {\n const subcommand = args[0];\n\n if (subcommand !== 'sync') {\n throw new Error(\n `Unknown schema subcommand: ${subcommand ?? '(none)'}. Usage: timber schema sync`\n );\n }\n\n const { runSchemaSync, defaultCodecForSegment } = await import('./cli-schema-sync.ts');\n const result = runSchemaSync(process.cwd());\n\n if (result.filesystemSegments.length === 0) {\n console.log('[timber] No dynamic segments found in app/.');\n return;\n }\n\n if (result.created) {\n console.log(`[timber] Created app/schema.ts with ${result.addedSegments.length} segment(s):`);\n for (const seg of result.addedSegments) {\n console.log(` + ${seg}: ${defaultCodecForSegment(seg)}`);\n }\n return;\n }\n\n if (result.addedSegments.length === 0 && result.removedSegments.length === 0) {\n console.log('[timber] Schema is up to date — all segments are registered.');\n return;\n }\n\n if (result.addedSegments.length > 0) {\n console.log(`[timber] Added ${result.addedSegments.length} segment(s) to app/schema.ts:`);\n for (const seg of result.addedSegments) {\n console.log(` + ${seg}: ${defaultCodecForSegment(seg)}`);\n }\n }\n\n if (result.removedSegments.length > 0) {\n console.log(\n `[timber] Removed ${result.removedSegments.length} stale segment(s) from app/schema.ts:`\n );\n for (const seg of result.removedSegments) {\n console.log(` - ${seg}`);\n }\n }\n}\n\n// ─── Main Entry Point ────────────────────────────────────────────────────────\n\nasync function main(): Promise<void> {\n const parsed = parseArgs(process.argv.slice(2));\n const options: CommandOptions = { config: parsed.config, project: parsed.project };\n\n switch (parsed.command) {\n case 'dev':\n if (parsed.rest[0] === 'status') {\n const { runDevStatus } = await import('./cli-dev-status.ts');\n await runDevStatus({ config: parsed.config, json: parsed.json });\n } else {\n await runDev(options);\n }\n break;\n case 'build':\n await runBuild(options);\n break;\n case 'preview':\n await runPreview(options);\n break;\n case 'check':\n await runCheck(options);\n break;\n case 'schema':\n await runSchema(parsed.rest);\n break;\n case 'init': {\n const { runInit } = await import('./cli-init.ts');\n runInit(process.cwd());\n break;\n }\n case 'graph': {\n // Lazy import — the graph implementation (and, on a cache miss,\n // Vite + the crawl child) never loads for the other commands.\n const { runGraph } = await import('./analyze/graph-command.ts');\n await runGraph({\n file: parsed.rest[0],\n config: parsed.config,\n json: parsed.json,\n all: parsed.all,\n });\n break;\n }\n }\n}\n\n// Run main when executed as a CLI (not imported in tests).\n// The bin shim (bin/timber.mjs) does `import '../dist/cli.js'`, so\n// process.argv[1] points to the shim, not this file. We check both:\n// direct execution AND being imported by the timber bin shim.\nconst isDirectExecution =\n typeof process !== 'undefined' &&\n process.argv[1] &&\n (import.meta.url.endsWith(process.argv[1]) ||\n process.argv[1].endsWith('bin/timber.mjs') ||\n process.argv[1].endsWith('bin/timber'));\n\nif (isDirectExecution) {\n main().catch((err) => {\n console.error(err.message);\n process.exit(1);\n });\n}\n"],"mappings":";;AAuBA,IAAM,WAAW;CAAC;CAAO;CAAS;CAAW;CAAS;CAAU;CAAQ;AAAO;;;;;;;;;;;;;;;;;;;;;;;;;AA+C/E,SAAgB,UAAU,MAA4B;CACpD,IAAI,KAAK,WAAW,GAClB,MAAM,IAAI,MACR,kGACF;CAGF,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AAY,IAAI,SAAS,QAAQ,KAAK,EAAE,KACvC,QAAQ,KAAK,EAAE,CAAC,SAAS,gBAAgB,KACzC,QAAQ,KAAK,EAAE,CAAC,SAAS,YAAY,IAGvC,KAAK,CAAC,CAAC,OAAO,QAAQ;CACpB,QAAQ,MAAM,IAAI,OAAO;CACzB,QAAQ,KAAK,CAAC;AAChB,CAAC"}
|
|
1
|
+
{"version":3,"file":"cli.js","names":[],"sources":["../src/cli.ts"],"sourcesContent":["#!/usr/bin/env node\n\n// timber.js CLI\n//\n// Wraps Vite commands with timber-specific behavior.\n// See design/18-build-system.md §\"CLI\".\n//\n// Commands:\n// timber dev — Start Vite dev server with HMR\n// timber build — Run multi-environment build via createBuilder/buildApp\n// timber preview — Serve the production build\n// timber check — Validate types + routes without building\n// timber graph — Classify a file's module environment(s) (design/47)\n// timber dev status — List running dev servers for this checkout (design/21)\n// timber init — Point AGENTS.md / CLAUDE.md at the installed agent guide\n\n// Type-only — the implementation is imported dynamically inside runCheck so the\n// CLI's other commands never load the route scanner.\nimport type { CheckDeps } from './cli-check.ts';\nimport type { ResolveViteConfig } from './cli-context.ts';\n\nexport type { CheckDeps };\n\nconst COMMANDS = ['dev', 'build', 'preview', 'check', 'schema', 'init', 'graph'] as const;\ntype Command = (typeof COMMANDS)[number];\n\nexport interface ParsedArgs {\n command: Command;\n config: string | undefined;\n /** `--project`: the tsconfig `timber check` passes to tsgo. */\n project: string | undefined;\n /** `timber graph` and `timber dev status`: emit the machine-readable JSON contract. */\n json: boolean;\n /** `timber graph` only: classify the whole project. */\n all: boolean;\n /** Positional arguments after the command (`schema sync`, `dev status`, `graph <file>`). */\n rest: string[];\n}\n\nexport interface CommandOptions {\n /** Path to a Vite config file. Means the same thing for every command. */\n config?: string;\n /** `timber check` only: the tsconfig to type-check. */\n project?: string;\n}\n\n/**\n * Parse CLI arguments into a structured command + options.\n * Accepts: timber <command> [--config|-c <path>] [--project <path>]\n *\n * `--config` names a **Vite** config file for every command, `check` included\n * (TIM-1332): `check` resolves the project through Vite, so a project that\n * builds with `--config ./custom.vite.config.ts` has to be checkable the same\n * way. `--project` names the tsconfig, spelled as tsgo and tsc spell it, and\n * is meaningful only for `check`.\n *\n * Before TIM-1332 `--config` meant the tsconfig for `check` alone — one flag\n * with two meanings, which the docs had to carry a note to explain and which\n * left custom Vite configs unreachable from `check` entirely.\n *\n * Unknown flags are an error, not silently ignored — `timber dev --port 4000`\n * starting on the default port would contradict fail-loudly. The surface stays\n * deliberately small (design/11-platform.md §CLI); port selection goes through\n * the PORT env var or server.port in vite.config.ts.\n *\n * Each subcommand declares its exact flags (the `check --project` precedent,\n * TIM-1332): `graph` additionally accepts a file positional plus `--json` and\n * `--all`, and those two are rejected everywhere else — except `--json`,\n * which `dev status` accepts too.\n */\nexport function parseArgs(args: string[]): ParsedArgs {\n if (args.length === 0) {\n throw new Error(\n 'No command provided. Usage: timber <dev|build|preview|check|schema|init|graph> [--config <path>]'\n );\n }\n\n const command = args[0];\n if (!COMMANDS.includes(command as Command)) {\n throw new Error(`Unknown command: ${command}. Available commands: ${COMMANDS.join(', ')}`);\n }\n\n let config: string | undefined;\n let project: string | undefined;\n let json = false;\n let all = false;\n const rest: string[] = [];\n for (let i = 1; i < args.length; i++) {\n const arg = args[i];\n if (arg === '--config' || arg === '-c') {\n config = args[++i];\n if (!config) {\n throw new Error('--config requires a path argument');\n }\n } else if (arg === '--json') {\n json = true;\n } else if (arg === '--all') {\n if (command !== 'graph') {\n throw new Error(`--all is only valid for \\`timber graph\\` (the module-environment query).`);\n }\n all = true;\n } else if (arg === '--project') {\n if (command !== 'check') {\n throw new Error(\n `--project is only valid for \\`timber check\\` (it names the tsconfig to type-check). ` +\n `To point \\`timber ${command}\\` at a different Vite config, use --config <path>.`\n );\n }\n project = args[++i];\n if (!project) {\n throw new Error('--project requires a path argument');\n }\n } else if (arg.startsWith('-')) {\n const portHint =\n arg === '--port' || arg === '-p'\n ? ' To change the port, set the PORT environment variable (PORT=4000 timber dev) ' +\n 'or server.port in vite.config.ts.'\n : '';\n throw new Error(\n `Unknown option: ${arg}. The timber CLI accepts --config <path>` +\n ` (and --project <path> for \\`check\\`).${portHint}`\n );\n } else if (\n command === 'schema' ||\n command === 'init' ||\n command === 'graph' ||\n (command === 'dev' && rest.length === 0 && arg === 'status')\n ) {\n rest.push(arg);\n } else {\n throw new Error(`Unexpected argument: ${arg}. Usage: timber ${command} [--config <path>]`);\n }\n }\n\n // Checked after the loop so flag order does not matter (`dev --json status`).\n const devStatus = command === 'dev' && rest[0] === 'status';\n if (json && command !== 'graph' && !devStatus) {\n throw new Error(`--json is only valid for \\`timber graph\\` and \\`timber dev status\\`.`);\n }\n\n if (command === 'graph' && rest.length > 1) {\n throw new Error(\n `timber graph takes one file. Usage: timber graph <file> [--json], or timber graph --all --json`\n );\n }\n\n return { command: command as Command, config, project, json, all, rest };\n}\n\n// ─── Command Implementations ─────────────────────────────────────────────────\n\n/** @internal Dependency injection for testing. */\nexport interface ViteDeps {\n createServer?: typeof import('vite').createServer;\n createBuilder?: typeof import('vite').createBuilder;\n resolveViteConfig?: ResolveViteConfig;\n}\n\n/**\n * Start the Vite dev server with a supervisor that respawns the process\n * when timber.config.ts changes. Node's require cache for ESM modules\n * loaded via require() cannot be evicted, so an in-process restart\n * serves stale config. The supervisor forks a worker; when the worker\n * exits with RESTART_EXIT_CODE (set by timber-dev-server on config file\n * change), the supervisor spawns a fresh worker with a clean cache.\n *\n * The timber plugin binds the port immediately with a holding page\n * (in rootSync's config hook) so browsers see a \"starting...\" page\n * instead of ERR_CONNECTION_REFUSED during initialization.\n *\n * See design/21-dev-server.md, TIM-665, TIM-1444.\n */\nexport async function runDev(options: CommandOptions, _deps?: ViteDeps): Promise<void> {\n // Worker mode: run the dev server directly (forked by supervisor below)\n if (process.env.__TIMBER_DEV_WORKER) {\n const createServer = _deps?.createServer ?? (await import('vite')).createServer;\n const server = await createServer({\n configFile: options.config,\n });\n // The supervisor respawns this worker whenever a config file changes,\n // including when a git checkout removes it. Vite treats a missing config\n // as an empty one, so without this check the respawned worker would serve\n // plain Vite on its default port: no app, and full-page reloads for every\n // .html file it sees, the build output included.\n const { hasTimberPlugin } = await import('./cli-context.ts');\n if (!hasTimberPlugin(server.config.plugins)) {\n await server.close();\n const where = server.config.configFile ?? `no Vite config found in ${server.config.root}`;\n throw new Error(\n `[timber] The Vite config does not use the timber plugin (${where}).\\n\\n` +\n ` \\`timber dev\\` stopped instead of starting plain Vite. This happens when a\\n` +\n ` config file changes on disk, for example a git checkout to a branch\\n` +\n ` without timber. Run \\`timber dev\\` again once vite.config.ts lists timber().`\n );\n }\n await server.listen();\n server.printUrls();\n return;\n }\n\n // Supervisor mode: fork a worker and respawn on config changes.\n const { fork } = await import('node:child_process');\n const { RESTART_EXIT_CODE } = await import('./plugins/dev-server.ts');\n\n // eslint-disable-next-line no-constant-condition\n while (true) {\n const result = await new Promise<{ code: number | null; signal: NodeJS.Signals | null }>(\n (resolve) => {\n const child = fork(process.argv[1], process.argv.slice(2), {\n stdio: 'inherit',\n env: { ...process.env, __TIMBER_DEV_WORKER: '1' },\n });\n\n // Forward signals to the child. SIGINT from Ctrl+C is sent to\n // the entire process group, but a targeted SIGTERM (from a\n // process manager or test teardown) only reaches the parent.\n const onSigint = () => child.kill('SIGINT');\n const onSigterm = () => child.kill('SIGTERM');\n process.on('SIGINT', onSigint);\n process.on('SIGTERM', onSigterm);\n\n child.on('exit', (code, signal) => {\n process.off('SIGINT', onSigint);\n process.off('SIGTERM', onSigterm);\n resolve({ code, signal });\n });\n }\n );\n\n if (result.code === RESTART_EXIT_CODE) {\n continue;\n }\n\n // Child was killed by a signal (e.g. SIGTERM) — re-raise on ourselves\n if (result.signal) {\n process.kill(process.pid, result.signal);\n }\n\n if (result.code != null && result.code !== 0) {\n process.exit(result.code);\n }\n\n break;\n }\n}\n\n/**\n * Run the production build using createBuilder + buildApp.\n * Direct build() calls do NOT trigger the RSC plugin's multi-environment\n * pipeline — createBuilder/buildApp is required.\n */\nexport async function runBuild(options: CommandOptions, _deps?: ViteDeps): Promise<void> {\n const createBuilder = _deps?.createBuilder ?? (await import('vite')).createBuilder;\n const builder = await createBuilder({\n configFile: options.config,\n });\n await builder.buildApp();\n}\n\n/**\n * Serve the production build for local testing.\n * The adapter's preview() serves it; without one, preview fails (TIM-1565).\n * There is no fallback to Vite preview: it would serve the build directory\n * itself — the server bundles as static files, with no root `index.html` —\n * which is useless in either output mode.\n *\n * The project is resolved through Vite, as `timber check` resolves it\n * (`cli-context.ts`), so the adapter, the output mode, and the build\n * directory are the ones `timber build` used — including `--config`, inline\n * `timber({ ... })` options, Vite's `root`, and `build.outDir`, none of which\n * a re-read of `timber.config.ts` can see (TIM-1531). A config file that\n * exists but fails to load throws, naming the file (TIM-1066).\n */\nexport async function runPreview(options: CommandOptions, _deps?: ViteDeps): Promise<void> {\n const { resolveTimberContext } = await import('./cli-context.ts');\n const { adapterConfig, contextAdapter } = await import('./plugin-context.ts');\n\n const ctx = await resolveTimberContext('preview', options.config, _deps?.resolveViteConfig);\n const adapter = contextAdapter(ctx);\n\n if (typeof adapter?.preview !== 'function') {\n const missing = adapter\n ? `The adapter '${adapter.name}' has no preview(), so \\`timber preview\\` cannot serve this build.`\n : `No adapter is configured, so \\`timber preview\\` has nothing to serve this build with.`;\n throw new Error(\n `[timber] ${missing} Use an adapter that implements preview() — ` +\n `cloudflare() from '@timber-js/app/adapters/cloudflare', or nitro() from ` +\n `'@timber-js/app/adapters/nitro' (any preset for a static build; node-server or bun ` +\n `for a server build) — or serve the build with your platform's own tooling.`\n );\n }\n\n await adapter.preview(adapterConfig(ctx), {\n output: ctx.config.output ?? 'server',\n outputDir: ctx.buildDir,\n });\n}\n\n/**\n * Validate routes and types without producing build output.\n *\n * Runs the route pass first — resolve the project through Vite, scan it, fail\n * on proven-fatal convention errors, print warnings, and regenerate the route\n * types — then `tsgo --noEmit`. Codegen has to precede the type pass: the\n * generated `.timber/*.d.ts` files are what type `<Link href>` and\n * `useSegmentParams()`, and a fresh clone has never produced them. See\n * `cli-check.ts` for the full reasoning.\n *\n * `--config` names the **Vite** config, as it does for every other command, so\n * an app that builds with a custom one is checkable the same way.\n * `--project` names the tsconfig handed to tsgo.\n */\nexport async function runCheck(options: CommandOptions, _deps?: CheckDeps): Promise<void> {\n const { checkRoutes, runTypeCheck } = await import('./cli-check.ts');\n const { root } = await checkRoutes({ viteConfigFile: options.config }, _deps);\n // tsgo runs from the root the route pass resolved, not from cwd — that is\n // where it just wrote the declarations tsgo has to read.\n await runTypeCheck({ root, config: options.project }, _deps);\n}\n\n// ─── Schema Subcommand ───────────────────────────────────────────────────────\n\n/**\n * `timber schema sync` — scan filesystem for dynamic segments, diff against\n * app/schema.ts, and append missing entries with type-appropriate codec defaults.\n *\n * See design/41-global-params.md §Auto-Scaffolding\n */\nexport async function runSchema(args: string[]): Promise<void> {\n const subcommand = args[0];\n\n if (subcommand !== 'sync') {\n throw new Error(\n `Unknown schema subcommand: ${subcommand ?? '(none)'}. Usage: timber schema sync`\n );\n }\n\n const { runSchemaSync, defaultCodecForSegment } = await import('./cli-schema-sync.ts');\n const result = runSchemaSync(process.cwd());\n\n if (result.filesystemSegments.length === 0) {\n console.log('[timber] No dynamic segments found in app/.');\n return;\n }\n\n if (result.created) {\n console.log(`[timber] Created app/schema.ts with ${result.addedSegments.length} segment(s):`);\n for (const seg of result.addedSegments) {\n console.log(` + ${seg}: ${defaultCodecForSegment(seg)}`);\n }\n return;\n }\n\n if (result.addedSegments.length === 0 && result.removedSegments.length === 0) {\n console.log('[timber] Schema is up to date — all segments are registered.');\n return;\n }\n\n if (result.addedSegments.length > 0) {\n console.log(`[timber] Added ${result.addedSegments.length} segment(s) to app/schema.ts:`);\n for (const seg of result.addedSegments) {\n console.log(` + ${seg}: ${defaultCodecForSegment(seg)}`);\n }\n }\n\n if (result.removedSegments.length > 0) {\n console.log(\n `[timber] Removed ${result.removedSegments.length} stale segment(s) from app/schema.ts:`\n );\n for (const seg of result.removedSegments) {\n console.log(` - ${seg}`);\n }\n }\n}\n\n// ─── Main Entry Point ────────────────────────────────────────────────────────\n\nasync function main(): Promise<void> {\n const parsed = parseArgs(process.argv.slice(2));\n const options: CommandOptions = { config: parsed.config, project: parsed.project };\n\n switch (parsed.command) {\n case 'dev':\n if (parsed.rest[0] === 'status') {\n const { runDevStatus } = await import('./cli-dev-status.ts');\n await runDevStatus({ config: parsed.config, json: parsed.json });\n } else {\n await runDev(options);\n }\n break;\n case 'build':\n await runBuild(options);\n break;\n case 'preview':\n await runPreview(options);\n break;\n case 'check':\n await runCheck(options);\n break;\n case 'schema':\n await runSchema(parsed.rest);\n break;\n case 'init': {\n const { runInit } = await import('./cli-init.ts');\n runInit(process.cwd());\n break;\n }\n case 'graph': {\n // Lazy import — the graph implementation (and, on a cache miss,\n // Vite + the crawl child) never loads for the other commands.\n const { runGraph } = await import('./analyze/graph-command.ts');\n await runGraph({\n file: parsed.rest[0],\n config: parsed.config,\n json: parsed.json,\n all: parsed.all,\n });\n break;\n }\n }\n}\n\n// Run main when executed as a CLI (not imported in tests).\n// The bin shim (bin/timber.mjs) does `import '../dist/cli.js'`, so\n// process.argv[1] points to the shim, not this file. We check both:\n// direct execution AND being imported by the timber bin shim.\nconst isDirectExecution =\n typeof process !== 'undefined' &&\n process.argv[1] &&\n (import.meta.url.endsWith(process.argv[1]) ||\n process.argv[1].endsWith('bin/timber.mjs') ||\n process.argv[1].endsWith('bin/timber'));\n\nif (isDirectExecution) {\n main().catch((err) => {\n console.error(err.message);\n process.exit(1);\n });\n}\n"],"mappings":";;AAuBA,IAAM,WAAW;CAAC;CAAO;CAAS;CAAW;CAAS;CAAU;CAAQ;AAAO;;;;;;;;;;;;;;;;;;;;;;;;;AA+C/E,SAAgB,UAAU,MAA4B;CACpD,IAAI,KAAK,WAAW,GAClB,MAAM,IAAI,MACR,kGACF;CAGF,MAAM,UAAU,KAAK;CACrB,IAAI,CAAC,SAAS,SAAS,OAAkB,GACvC,MAAM,IAAI,MAAM,oBAAoB,Q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;IAClB,QAAQ,OAAO;IACf,MAAM,OAAO;IACb,KAAK,OAAO;GACd,CAAC;GACD;EACF;CACF;AACF;AAaA,IANE,OAAO,YAAY,eACnB,QAAQ,KAAK,OACZ,YAAY,IAAI,SAAS,QAAQ,KAAK,EAAE,KACvC,QAAQ,KAAK,EAAE,CAAC,SAAS,gBAAgB,KACzC,QAAQ,KAAK,EAAE,CAAC,SAAS,YAAY,IAGvC,KAAK,CAAC,CAAC,OAAO,QAAQ;CACpB,QAAQ,MAAM,IAAI,OAAO;CACzB,QAAQ,KAAK,CAAC;AAChB,CAAC"}
|
package/dist/client/internal.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { t as SingleflightTimeoutError } from "../_chunks/singleflight-
|
|
2
|
-
import { a as routerUrlKey, c as prefetchScopeOf, i as parseRouterUrl, n as createNavigationCommitter, o as PrefetchCache, r as isPartialNavigation, s as SegmentCache } from "../_chunks/status-page-marker-
|
|
1
|
+
import { t as SingleflightTimeoutError } from "../_chunks/singleflight-CzoOVB9Y.js";
|
|
2
|
+
import { a as routerUrlKey, c as prefetchScopeOf, i as parseRouterUrl, n as createNavigationCommitter, o as PrefetchCache, r as isPartialNavigation, s as SegmentCache } from "../_chunks/status-page-marker-C8POawuF.js";
|
|
3
3
|
import { c as cachedSearchParams, s as cachedSearch, t as _setCachedSearch } from "../_chunks/state-B-EBjeER.js";
|
|
4
4
|
import { a as setGlobalRouter, i as getRouterOrNull, r as getRouter } from "../_chunks/navigation-root-M3B2ZrdO.js";
|
|
5
5
|
import { n as registerSsrDataProvider, t as getSsrData } from "../_chunks/ssr-data-9hPtcNOr.js";
|
|
6
6
|
import { i as useNavigationContext, n as useSegmentContext, r as NavigationProvider, t as SegmentProvider } from "../_chunks/segment-context-CYiGTi3K.js";
|
|
7
|
-
import { a as createSpaExits, c as createRenderOwner, d as fetchRscPayload, f as readPayloadTree, i as createScrollEffects, l as isClientStale, n as TimberErrorBoundary, o as runAsHandle, p as readPublishedParams, r as createNavigationRecovery, s as recordSkew, u as NonRscResponse } from "../_chunks/error-boundary-
|
|
7
|
+
import { a as createSpaExits, c as createRenderOwner, d as fetchRscPayload, f as readPayloadTree, i as createScrollEffects, l as isClientStale, n as TimberErrorBoundary, o as runAsHandle, p as readPublishedParams, r as createNavigationRecovery, s as recordSkew, u as NonRscResponse } from "../_chunks/error-boundary-D3YyVVuP.js";
|
|
8
8
|
import { t as bindUseQueryStates } from "../_chunks/use-query-states-pkDV-jSg.js";
|
|
9
9
|
// src/client/history.ts
|
|
10
10
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"navigation-root.d.ts","sourceRoot":"","sources":["../../src/client/navigation-root.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,EAAoD,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACzF,OAAO,EAAa,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAInE;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,SAAS,CAAC;IACnB;;;;;;OAMG;IACH,OAAO,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAC7B,OAAO,EAAE,SAAS,EAClB,OAAO,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,EAC5B,KAAK,EAAE,SAAS,MAAM,EAAE,KACrB,IAAI,CAAC;AA8BV;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C;AAgBD;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,eAAe,GAChB,EAAE;IACD,QAAQ,EAAE,YAAY,CAAC;IACvB,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"navigation-root.d.ts","sourceRoot":"","sources":["../../src/client/navigation-root.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,EAAoD,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACzF,OAAO,EAAa,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAInE;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,SAAS,CAAC;IACnB;;;;;;OAMG;IACH,OAAO,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAC7B,OAAO,EAAE,SAAS,EAClB,OAAO,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,EAC5B,KAAK,EAAE,SAAS,MAAM,EAAE,KACrB,IAAI,CAAC;AA8BV;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAEtD;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,IAAI,OAAO,CAE1C;AAgBD;;;;;;;;;GASG;AACH,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,eAAe,GAChB,EAAE;IACD,QAAQ,EAAE,YAAY,CAAC;IACvB,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC,GAAG,SAAS,CAuEZ"}
|
|
@@ -3,7 +3,10 @@ import { type ReactNode } from 'react';
|
|
|
3
3
|
* Wraps the React tree with nuqs's adapter context, configured with
|
|
4
4
|
* timber's default options.
|
|
5
5
|
*
|
|
6
|
-
* Auto-injected
|
|
6
|
+
* Auto-injected around the app on both sides — the browser's root render
|
|
7
|
+
* (browser-entry/router-init.ts) and the SSR wrapper chain
|
|
8
|
+
* (server/ssr-wrappers.tsx) — no user setup required. It must sit above
|
|
9
|
+
* NavigationProvider's consumers, which every `useQueryStates` caller is.
|
|
7
10
|
*/
|
|
8
11
|
export declare function TimberNuqsAdapter({ children }: {
|
|
9
12
|
children: ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nuqs-adapter.d.ts","sourceRoot":"","sources":["../../src/client/nuqs-adapter.tsx"],"names":[],"mappings":"AAcA,OAAO,
|
|
1
|
+
{"version":3,"file":"nuqs-adapter.d.ts","sourceRoot":"","sources":["../../src/client/nuqs-adapter.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAW,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AA8GhD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,EAAE,SAAS,CAAA;CAAE,+BAatE"}
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAU,YAAY,EAAE,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAU,YAAY,EAAE,MAAM,MAAM,CAAC;AA6CjD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAa1D,YAAY,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAQ1D,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAElG;;;;;;;;;;;;GAYG;AAEH,MAAM,WAAW,MAAM;CAAG;AAE1B;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,gBAAgB,GAAG,gBAAgB,CAEvE;AAyGD,wBAAgB,MAAM,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,YAAY,EAAE,CAwXhE;eAEc,MAAM"}
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import { n as rscPayloadPath, t as RSC_PAYLOAD_DIR } from "./_chunks/rsc-payload
|
|
|
12
12
|
import { a as REDIRECTS_FILE, n as detectFsIdentity, o as RESERVED_OUTPUT_PATHS, r as fsKey, t as EXACT_FS_IDENTITY } from "./_chunks/fs-identity-BmQ_Agg-.js";
|
|
13
13
|
import { t as EMPTY_BUILD_MANIFEST } from "./_chunks/build-manifest-Y4jl7nwU.js";
|
|
14
14
|
import { t as fnv1aHash } from "./_chunks/fast-hash-DddxkU5Y.js";
|
|
15
|
+
import { i as detectDirective } from "./_chunks/classify--_kINHQV.js";
|
|
15
16
|
import { t as formatSize } from "./_chunks/format-DuPOoXUP.js";
|
|
16
17
|
import { createLogger, esmExternalRequirePlugin, isRunnableDevEnvironment, parseAst } from "vite";
|
|
17
18
|
import { basename, dirname, extname, isAbsolute, join, normalize, relative, resolve, win32 } from "node:path";
|
|
@@ -7969,6 +7970,116 @@ function timberOptimizePackageImports(ctx) {
|
|
|
7969
7970
|
}
|
|
7970
7971
|
};
|
|
7971
7972
|
}
|
|
7973
|
+
// src/plugins/client-in-server-package-deps.ts
|
|
7974
|
+
/**
|
|
7975
|
+
* timber-client-in-server-package-deps — in dev, the RSC environment resolves
|
|
7976
|
+
* a package's inner 'use client' file through its bare package path, so the
|
|
7977
|
+
* browser loads it from the client pre-bundle.
|
|
7978
|
+
*
|
|
7979
|
+
* plugin-rsc records a package source only for a file the RSC environment
|
|
7980
|
+
* reaches through a bare import. A server component that reaches a 'use
|
|
7981
|
+
* client' file through the package's own relative imports (lucide-react's
|
|
7982
|
+
* `icons/play.mjs` → `createLucideIcon.mjs` → `./Icon.mjs`, or
|
|
7983
|
+
* `@mui/material/Button` → `./Button.mjs`) gets a client reference whose
|
|
7984
|
+
* browser module re-exports the file's absolute path
|
|
7985
|
+
* (`client-in-server-package-proxy`). Vite serves that file, and everything it
|
|
7986
|
+
* imports, raw:
|
|
7987
|
+
*
|
|
7988
|
+
* - If an app client component also imports the package, the browser holds
|
|
7989
|
+
* two instances of those modules, the pre-bundled one and the raw one, so a
|
|
7990
|
+
* context the package provides (`LucideProvider`) does not reach icons
|
|
7991
|
+
* rendered by server components. plugin-rsc detects this and warns "client
|
|
7992
|
+
* component dependency is inconsistently optimized" on every dev start.
|
|
7993
|
+
* - If the file imports a CommonJS package (`prop-types`), the browser
|
|
7994
|
+
* cannot link it and the page fails (vitejs/vite-plugin-react#1538).
|
|
7995
|
+
*
|
|
7996
|
+
* This plugin resolves such an import as the bare specifier the file has from
|
|
7997
|
+
* the app root (`lucide-react/dist/esm/Icon.mjs`). plugin-rsc then records that
|
|
7998
|
+
* specifier as the file's package source and gives the browser
|
|
7999
|
+
* `client-package-proxy`, which imports the bare specifier. The client deps
|
|
8000
|
+
* optimizer pre-bundles it like any package import, splitting the modules it
|
|
8001
|
+
* shares with the package's own entry into one chunk, so the browser loads one
|
|
8002
|
+
* instance. No inconsistency remains, so plugin-rsc does not warn.
|
|
8003
|
+
*
|
|
8004
|
+
* Every rule leans toward leaving the import alone, which keeps plugin-rsc's
|
|
8005
|
+
* raw-file behavior:
|
|
8006
|
+
* - only in the RSC environment, in dev (a build has no proxy modules);
|
|
8007
|
+
* - only for a non-bare source (a bare one already gets a package source);
|
|
8008
|
+
* - only from a package file, or for an absolute path into `node_modules`
|
|
8009
|
+
* (what the barrel rewrite emits), so an app module's own relative imports
|
|
8010
|
+
* are not resolved twice;
|
|
8011
|
+
* - only when the resolved id is a plain file (no query but Vite's `?v=`; a
|
|
8012
|
+
* `?raw` or `?url` import asks for something other than the module), under
|
|
8013
|
+
* `node_modules`, whose directive prologue holds 'use client';
|
|
8014
|
+
* - only when the bare specifier resolves to the same file, from the importer
|
|
8015
|
+
* here and from the app root in plugin-rsc. A package whose `exports` hides
|
|
8016
|
+
* the file, or a transitive dependency the app cannot import by name, stays
|
|
8017
|
+
* as it is.
|
|
8018
|
+
*
|
|
8019
|
+
* A file found after startup is a new client dep, so the client optimizer
|
|
8020
|
+
* re-runs once, as for any import discovered late; Vite keeps it in the dep
|
|
8021
|
+
* cache for later starts. See design/21-dev-server.md §"Inner 'use client'
|
|
8022
|
+
* Files of Packages".
|
|
8023
|
+
*
|
|
8024
|
+
* Remove once plugin-rsc imports these files through the client pre-bundle
|
|
8025
|
+
* itself.
|
|
8026
|
+
*/
|
|
8027
|
+
var NODE_MODULES = "/node_modules/";
|
|
8028
|
+
var BARE_IMPORT_RE = /^(?![a-zA-Z]:)[\w@](?!.*:\/\/)/;
|
|
8029
|
+
/**
|
|
8030
|
+
* The bare specifier `file` has as a package path, or null when the file is not
|
|
8031
|
+
* inside a package. The last `node_modules` segment is the package, so a pnpm
|
|
8032
|
+
* store path (`.pnpm/lucide-react@1.66.0/node_modules/lucide-react/…`) names
|
|
8033
|
+
* the package, not the store.
|
|
8034
|
+
*/
|
|
8035
|
+
function packagePathOf(file) {
|
|
8036
|
+
const index = file.lastIndexOf(NODE_MODULES);
|
|
8037
|
+
if (index === -1) return null;
|
|
8038
|
+
const id = file.slice(index + 14);
|
|
8039
|
+
return id === "" || id.startsWith(".") ? null : id;
|
|
8040
|
+
}
|
|
8041
|
+
function timberClientInServerPackageDeps(rscEnvironmentName = "rsc") {
|
|
8042
|
+
const isClientFile = /* @__PURE__ */ new Map();
|
|
8043
|
+
function hasUseClient(file) {
|
|
8044
|
+
let cached = isClientFile.get(file);
|
|
8045
|
+
if (!cached) {
|
|
8046
|
+
cached = readFile(file, "utf8").then((code) => code.includes("use client") && detectDirective(code, file) === "use client", () => false);
|
|
8047
|
+
isClientFile.set(file, cached);
|
|
8048
|
+
}
|
|
8049
|
+
return cached;
|
|
8050
|
+
}
|
|
8051
|
+
return {
|
|
8052
|
+
name: "timber-client-in-server-package-deps",
|
|
8053
|
+
apply: "serve",
|
|
8054
|
+
resolveId: {
|
|
8055
|
+
order: "pre",
|
|
8056
|
+
async handler(source, importer, options) {
|
|
8057
|
+
if (this.environment.name !== rscEnvironmentName || !importer) return;
|
|
8058
|
+
if (BARE_IMPORT_RE.test(source) || source.startsWith("\0")) return;
|
|
8059
|
+
if (!importer.includes(NODE_MODULES) && !source.includes(NODE_MODULES)) return;
|
|
8060
|
+
const resolved = await this.resolve(source, importer, {
|
|
8061
|
+
...options,
|
|
8062
|
+
skipSelf: true
|
|
8063
|
+
});
|
|
8064
|
+
if (!resolved || resolved.external) return resolved;
|
|
8065
|
+
const file = asFilePath(resolved.id);
|
|
8066
|
+
const bare = file && packagePathOf(file);
|
|
8067
|
+
if (!file || !bare || !await hasUseClient(file)) return resolved;
|
|
8068
|
+
let viaPackage;
|
|
8069
|
+
try {
|
|
8070
|
+
viaPackage = await this.resolve(bare, importer, {
|
|
8071
|
+
...options,
|
|
8072
|
+
skipSelf: true
|
|
8073
|
+
});
|
|
8074
|
+
} catch {
|
|
8075
|
+
return resolved;
|
|
8076
|
+
}
|
|
8077
|
+
if (!viaPackage || asFilePath(viaPackage.id) !== file) return resolved;
|
|
8078
|
+
return viaPackage;
|
|
8079
|
+
}
|
|
8080
|
+
}
|
|
8081
|
+
};
|
|
8082
|
+
}
|
|
7972
8083
|
// src/plugins/callsite-jsx.ts
|
|
7973
8084
|
/**
|
|
7974
8085
|
* Try to extract a static JSON-safe value from an AST expression node.
|
|
@@ -10251,6 +10362,7 @@ function timber(config) {
|
|
|
10251
10362
|
fonts,
|
|
10252
10363
|
timberMdx(ctx),
|
|
10253
10364
|
timberOptimizePackageImports(ctx),
|
|
10365
|
+
timberClientInServerPackageDeps(),
|
|
10254
10366
|
timberRequestDep(ctx),
|
|
10255
10367
|
timberCacheTransform(ctx),
|
|
10256
10368
|
timberPrerenderSugar(ctx),
|