@timber-js/app 0.2.0-alpha.234 → 0.2.0-alpha.235

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.
Files changed (59) hide show
  1. package/dist/_chunks/{cli-check-BAKOSTkg.js → cli-check-Dl3yo3Zv.js} +3 -3
  2. package/dist/_chunks/{cli-check-BAKOSTkg.js.map → cli-check-Dl3yo3Zv.js.map} +1 -1
  3. package/dist/_chunks/{cli-context-BPdyA7Fp.js → cli-context-BbwVqarO.js} +1 -1
  4. package/dist/_chunks/{cli-context-CwTKMjVe.js → cli-context-DZh5v0yd.js} +2 -2
  5. package/dist/_chunks/{cli-context-CwTKMjVe.js.map → cli-context-DZh5v0yd.js.map} +1 -1
  6. package/dist/_chunks/{cli-schema-sync-y_8ijmzO.js → cli-schema-sync-CTWiBMZZ.js} +1 -1
  7. package/dist/_chunks/{cli-schema-sync-CAllbqRB.js → cli-schema-sync-CyrOHbAo.js} +2 -2
  8. package/dist/_chunks/{cli-schema-sync-CAllbqRB.js.map → cli-schema-sync-CyrOHbAo.js.map} +1 -1
  9. package/dist/_chunks/dev-server-DrYBIg66.js +1 -0
  10. package/dist/_chunks/{dev-server-Rq659RR1.js → dev-server-cmWVDgTf.js} +2 -2
  11. package/dist/_chunks/{dev-server-Rq659RR1.js.map → dev-server-cmWVDgTf.js.map} +1 -1
  12. package/dist/_chunks/dev-span-_NzMX-au.js.map +1 -1
  13. package/dist/_chunks/{plugin-context-FCkaNLUB.js → plugin-context-BtaQcMuh.js} +2 -2
  14. package/dist/_chunks/{plugin-context-FCkaNLUB.js.map → plugin-context-BtaQcMuh.js.map} +1 -1
  15. package/dist/_chunks/{plugin-context-BfSRKJfz.js → plugin-context-I1dvGccO.js} +1 -1
  16. package/dist/_chunks/{walkers-D_QHR_nf.js → walkers-DFC9KsBL.js} +2 -2
  17. package/dist/_chunks/{walkers-D_QHR_nf.js.map → walkers-DFC9KsBL.js.map} +1 -1
  18. package/dist/analyze/crawl-entry.js +1 -1
  19. package/dist/analyze/graph-command.js +2 -2
  20. package/dist/cli.js +6 -6
  21. package/dist/client/dev-pill/store.d.ts +0 -18
  22. package/dist/client/dev-pill/store.d.ts.map +1 -1
  23. package/dist/client/dev-pill/view.d.ts.map +1 -1
  24. package/dist/client/dev-pill/waterfall.d.ts +64 -0
  25. package/dist/client/dev-pill/waterfall.d.ts.map +1 -0
  26. package/dist/dev-tools/await-span.d.ts +5 -1
  27. package/dist/dev-tools/await-span.d.ts.map +1 -1
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +113 -12
  30. package/dist/index.js.map +1 -1
  31. package/dist/native/rsc/dev-tools/await-span.js +6 -6
  32. package/dist/native/rsc/dev-tools/await-span.js.map +1 -1
  33. package/dist/native/rsc/manifest.json +1 -2
  34. package/dist/native/rsc/shared/dev-span.js +4 -3
  35. package/dist/native/rsc/shared/dev-span.js.map +1 -1
  36. package/dist/native/ssr/dev-tools/await-span.js +6 -6
  37. package/dist/native/ssr/dev-tools/await-span.js.map +1 -1
  38. package/dist/native/ssr/shared/dev-span.js +4 -3
  39. package/dist/native/ssr/shared/dev-span.js.map +1 -1
  40. package/dist/plugins/dev-await.d.ts +3 -0
  41. package/dist/plugins/dev-await.d.ts.map +1 -1
  42. package/dist/plugins/native-runtime.d.ts +2 -2
  43. package/dist/plugins/native-runtime.d.ts.map +1 -1
  44. package/dist/plugins/plugin-rsc-package.d.ts +35 -0
  45. package/dist/plugins/plugin-rsc-package.d.ts.map +1 -0
  46. package/dist/routing/index.js +1 -1
  47. package/dist/shared/dev-span.d.ts +9 -2
  48. package/dist/shared/dev-span.d.ts.map +1 -1
  49. package/package.json +2 -2
  50. package/src/client/dev-pill/store.ts +5 -64
  51. package/src/client/dev-pill/view.ts +165 -53
  52. package/src/client/dev-pill/waterfall.ts +194 -0
  53. package/src/dev-tools/await-span.ts +22 -13
  54. package/src/index.ts +3 -10
  55. package/src/plugins/dev-await.ts +61 -3
  56. package/src/plugins/native-runtime.ts +4 -3
  57. package/src/plugins/plugin-rsc-package.ts +81 -0
  58. package/src/shared/dev-span.ts +12 -4
  59. package/dist/_chunks/dev-server-L8biS7Az.js +0 -1
@@ -30,8 +30,8 @@
30
30
  * `__vite_rsc_require__`, so a global alias stands in for it.
31
31
  *
32
32
  * Used only when timber runs from an installed package with its mirrors, and
33
- * `TIMBER_DEV_NATIVE_RUNTIME` is not `0`; RSC also needs the app's React,
34
- * react-dom and plugin-rsc to be the versions the mirror bundled, and falls
33
+ * `TIMBER_DEV_NATIVE_RUNTIME` is not `0`; RSC also needs the app's React and
34
+ * react-dom to be the versions the mirror bundled, and falls
35
35
  * back to Vite with a warning otherwise (design/51 §"Two dev paths").
36
36
  * timber's own repo and examples alias `@timber-js/app` to `src/` and keep the
37
37
  * Vite path.
@@ -44,6 +44,7 @@ import { parseAst, type Plugin } from 'vite';
44
44
  import MagicString from 'magic-string';
45
45
 
46
46
  import { SRC_DIR } from './entries.ts';
47
+ import { isInstalledPackage } from './plugin-rsc-package.ts';
47
48
  import {
48
49
  NATIVE_MANIFEST_FILE,
49
50
  type NativeManifest,
@@ -98,7 +99,7 @@ export function decideNativeRuntime(
98
99
  if (env.TIMBER_DEV_NATIVE_RUNTIME === '0') return everywhere('TIMBER_DEV_NATIVE_RUNTIME=0');
99
100
  // An installed package. timber's repo, its examples and linked apps run
100
101
  // src/ through Vite, where edits to timber itself hot-reload.
101
- if (!srcDir.includes(`${sep}node_modules${sep}`)) {
102
+ if (!isInstalledPackage(srcDir)) {
102
103
  return everywhere('timber is not an installed package');
103
104
  }
104
105
  const decision: NativeRuntimeDecision = { manifests: {}, vitePath: {}, warn: false };
@@ -0,0 +1,81 @@
1
+ /**
2
+ * Which copy of `@vitejs/plugin-rsc` timber runs, and the one Vite setting
3
+ * that follows from it.
4
+ *
5
+ * plugin-rsc is a dependency of `@timber-js/app`, pinned exactly: apps never
6
+ * import it, and the RSC mirror bundles that version's Flight runtime
7
+ * (design/51-native-dev-runtime.md). So:
8
+ *
9
+ * - **An installed timber loads its own copy.** The plugin, the runtime that
10
+ * timber's modules import and the bundled Flight runtime are then one
11
+ * version, whatever else the app installed. Package managers give that copy
12
+ * the app's Vite through timber's `vite` peer.
13
+ * - **A linked or from-source timber loads the app's copy.** It has its own
14
+ * `node_modules` with its own Vite, and plugin-rsc checks environments
15
+ * against the Vite it imports (`vite.isRunnableDevEnvironment`), so a copy
16
+ * resolved from timber would see a second Vite. This repo's examples and
17
+ * `pnpm link` setups take this path, with plugin-rsc installed in the
18
+ * workspace or the app.
19
+ */
20
+
21
+ import { createRequire } from 'node:module';
22
+ import { join, sep } from 'node:path';
23
+ import type { Plugin } from 'vite';
24
+
25
+ import { SRC_DIR } from './entries.ts';
26
+
27
+ const PLUGIN_RSC = '@vitejs/plugin-rsc';
28
+
29
+ /** Whether timber's `src/` is inside an installed package, not a checkout or link. */
30
+ export function isInstalledPackage(srcDir: string): boolean {
31
+ return srcDir.includes(`${sep}node_modules${sep}`);
32
+ }
33
+
34
+ /** Whether this timber runs the plugin-rsc it depends on, rather than the app's. */
35
+ const usesOwnPluginRsc = isInstalledPackage(SRC_DIR);
36
+
37
+ /** plugin-rsc's plugin factory: timber's own copy when installed, the app's otherwise. */
38
+ export function loadPluginRsc(appRoot: string): (typeof import('@vitejs/plugin-rsc'))['default'] {
39
+ const from = usesOwnPluginRsc ? SRC_DIR : appRoot;
40
+ const load = createRequire(join(from, 'package.json'));
41
+ try {
42
+ load.resolve(PLUGIN_RSC);
43
+ } catch {
44
+ throw new Error(
45
+ `timber runs from source or a link here, and loads ${PLUGIN_RSC} from the app: install ${PLUGIN_RSC} in ${appRoot}.`
46
+ );
47
+ }
48
+ // Synchronous require() of an ESM package works on Node 22.12+ and
49
+ // returns its namespace.
50
+ const mod: typeof import('@vitejs/plugin-rsc') = load(PLUGIN_RSC);
51
+ return mod.default;
52
+ }
53
+
54
+ /**
55
+ * plugin-rsc lists its vendored Flight runtime in each environment's
56
+ * `optimizeDeps.include` by bare specifier, which Vite resolves from the app's
57
+ * root. An app that does not install plugin-rsc itself cannot resolve it
58
+ * there, so the browser's Flight client would be found only mid-load, and
59
+ * pre-bundled with a full page reload. When timber runs its own copy, each
60
+ * entry names the package it comes through (`@timber-js/app > …`), which Vite
61
+ * resolves from timber.
62
+ */
63
+ export function timberPluginRscDeps(): Plugin {
64
+ return {
65
+ name: 'timber-plugin-rsc-deps',
66
+ apply: 'serve',
67
+ // After plugin-rsc adds its entries, and after timber-node-flight-builds
68
+ // swaps the server environments' edge builds for Node ones.
69
+ enforce: 'post',
70
+ configEnvironment: {
71
+ order: 'post',
72
+ handler(_name, config) {
73
+ const deps = config.optimizeDeps;
74
+ if (!usesOwnPluginRsc || !deps?.include) return;
75
+ deps.include = deps.include.map((entry) =>
76
+ entry.startsWith(`${PLUGIN_RSC}/`) ? `@timber-js/app > ${entry}` : entry
77
+ );
78
+ },
79
+ },
80
+ };
81
+ }
@@ -33,6 +33,14 @@ export const DEV_AWAIT_KEY = Symbol.for('timber.dev.await');
33
33
  /** Span name for one awaited call in app server code. */
34
34
  export const AWAIT_SPAN_NAME = 'timber.await';
35
35
 
36
+ /**
37
+ * Set on an await span that waited on work started elsewhere: a promise
38
+ * another await already took (React's `cache()`), or one made before the
39
+ * await began (`const p = load(); … await p`). The work's own spans nest
40
+ * where it started, so the wait adds no new information when they exist.
41
+ */
42
+ export const AWAIT_WAIT_ATTRIBUTE = 'timber.await_wait';
43
+
36
44
  /**
37
45
  * Await spans shorter than this are dropped before they reach the terminal
38
46
  * tree or the pill: `await params` and other awaits of settled values would
@@ -67,8 +75,8 @@ export const DEV_SPAN_ATTRIBUTES = [
67
75
  'timber.await_label',
68
76
  /** `path/relative/to/root.ts:line` of the await. */
69
77
  'timber.await_location',
70
- /** The awaited promise was already awaited elsewhere: a wait on shared work, not new work. */
71
- 'timber.await_shared',
78
+ /** See `AWAIT_WAIT_ATTRIBUTE`. */
79
+ 'timber.await_wait',
72
80
  ] as const;
73
81
 
74
82
  export type DevSpanAttribute = (typeof DEV_SPAN_ATTRIBUTES)[number];
@@ -172,9 +180,9 @@ export function devSpanLabel(name: string, attrs: SpanAttributes): { label: stri
172
180
  return { label: `page ${slotPrefix(attrs)}${String(route)}`, env: 'rsc' };
173
181
  }
174
182
  case AWAIT_SPAN_NAME:
175
- // Shared: waited on a promise another await already took — no new work.
183
+ // A wait on work started elsewhere — no new work under it.
176
184
  return {
177
- label: `await ${String(attrs['timber.await_label'] ?? '')}${attrs['timber.await_shared'] === true ? ' (shared)' : ''}`,
185
+ label: `await ${String(attrs['timber.await_label'] ?? '')}${attrs[AWAIT_WAIT_ATTRIBUTE] === true ? ' (wait)' : ''}`,
178
186
  env: 'await',
179
187
  };
180
188
  case 'timber.fetch': {
@@ -1 +0,0 @@
1
- export { t as RESTART_EXIT_CODE } from "./dev-server-Rq659RR1.js";