@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
package/dist/index.js CHANGED
@@ -1,12 +1,12 @@
1
- import { a as formatMissingPeers, i as checkPeerDependencies, n as timberDevServer, o as reportConfigErrors, s as validateConfig } from "./_chunks/dev-server-Rq659RR1.js";
1
+ import { a as formatMissingPeers, i as checkPeerDependencies, n as timberDevServer, o as reportConfigErrors, s as validateConfig } from "./_chunks/dev-server-cmWVDgTf.js";
2
2
  import { i as resolveRenderTimeoutMs } from "./_chunks/render-timeout-MrrqD1wd.js";
3
3
  import { t as writeFileAtomic } from "./_chunks/write-file-atomic-DW8m_Atv.js";
4
4
  import { d as collectInterceptionRewrites, l as getPrerenderExport, n as scanRoutes } from "./_chunks/scanner-BNQ4qnLX.js";
5
5
  import { b as swallow } from "./_chunks/logger-YtMSKfft.js";
6
6
  import { c as buildDirToRouteMap, n as formatConventionWarnings, o as flushCodegenWrites, r as lintConventions, s as writeRouteCodegen, t as checkAppDirExists } from "./_chunks/convention-lint-D54k6uUM.js";
7
- import { a as contextAdapter, c as loadTimberConfigFile, d as resolveBuildDir, f as resolveClientJavascript, l as mergeFileConfig, m as createNoopTimer, o as createPluginContext, r as adapterConfig, u as resolveAppDir } from "./_chunks/plugin-context-FCkaNLUB.js";
7
+ import { a as contextAdapter, c as loadTimberConfigFile, d as resolveBuildDir, f as resolveClientJavascript, l as mergeFileConfig, m as createNoopTimer, o as createPluginContext, r as adapterConfig, u as resolveAppDir } from "./_chunks/plugin-context-BtaQcMuh.js";
8
8
  import { i as withBasePath, n as normalizeBasePath, t as isRelativeBase } from "./_chunks/base-path-DDIx0FXe.js";
9
- import { r as validateSchemaAgainstRoutes, t as collectLeafRoutes } from "./_chunks/walkers-D_QHR_nf.js";
9
+ import { r as validateSchemaAgainstRoutes, t as collectLeafRoutes } from "./_chunks/walkers-DFC9KsBL.js";
10
10
  import { i as poisonPillSource, r as markerFor, t as EXPLICIT_MARKERS } from "./_chunks/poison-rules-Bmz-lCPi.js";
11
11
  import { n as rscPayloadPath, t as RSC_PAYLOAD_DIR } from "./_chunks/rsc-payload-path-EphpDB-J.js";
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";
@@ -16,11 +16,11 @@ import { i as detectDirective } from "./_chunks/classify-_W0RWa5w.js";
16
16
  import { t as formatSize } from "./_chunks/format-DuPOoXUP.js";
17
17
  import { createLogger, esmExternalRequirePlugin, isRunnableDevEnvironment, parseAst } from "vite";
18
18
  import { basename, dirname, extname, isAbsolute, join, normalize, relative, resolve, sep, win32 } from "node:path";
19
- import { SourceMap, builtinModules, createRequire } from "node:module";
20
19
  import react from "@vitejs/plugin-react";
21
20
  import { existsSync, readFileSync } from "node:fs";
22
21
  import nodeHTTP from "node:http";
23
22
  import { fileURLToPath, pathToFileURL } from "node:url";
23
+ import { SourceMap, builtinModules, createRequire } from "node:module";
24
24
  import { createHash, randomUUID } from "node:crypto";
25
25
  import { copyFile, mkdir, readFile, readdir, rename, rm, stat, writeFile } from "node:fs/promises";
26
26
  import { gzipSync } from "node:zlib";
@@ -8196,6 +8196,67 @@ function timberNodeFlightBuilds() {
8196
8196
  }
8197
8197
  };
8198
8198
  }
8199
+ // src/plugins/plugin-rsc-package.ts
8200
+ /**
8201
+ * Which copy of `@vitejs/plugin-rsc` timber runs, and the one Vite setting
8202
+ * that follows from it.
8203
+ *
8204
+ * plugin-rsc is a dependency of `@timber-js/app`, pinned exactly: apps never
8205
+ * import it, and the RSC mirror bundles that version's Flight runtime
8206
+ * (design/51-native-dev-runtime.md). So:
8207
+ *
8208
+ * - **An installed timber loads its own copy.** The plugin, the runtime that
8209
+ * timber's modules import and the bundled Flight runtime are then one
8210
+ * version, whatever else the app installed. Package managers give that copy
8211
+ * the app's Vite through timber's `vite` peer.
8212
+ * - **A linked or from-source timber loads the app's copy.** It has its own
8213
+ * `node_modules` with its own Vite, and plugin-rsc checks environments
8214
+ * against the Vite it imports (`vite.isRunnableDevEnvironment`), so a copy
8215
+ * resolved from timber would see a second Vite. This repo's examples and
8216
+ * `pnpm link` setups take this path, with plugin-rsc installed in the
8217
+ * workspace or the app.
8218
+ */
8219
+ var PLUGIN_RSC = "@vitejs/plugin-rsc";
8220
+ /** Whether timber's `src/` is inside an installed package, not a checkout or link. */
8221
+ function isInstalledPackage(srcDir) {
8222
+ return srcDir.includes(`${sep}node_modules${sep}`);
8223
+ }
8224
+ /** Whether this timber runs the plugin-rsc it depends on, rather than the app's. */
8225
+ var usesOwnPluginRsc = isInstalledPackage(SRC_DIR);
8226
+ /** plugin-rsc's plugin factory: timber's own copy when installed, the app's otherwise. */
8227
+ function loadPluginRsc(appRoot) {
8228
+ const load = createRequire(join(usesOwnPluginRsc ? SRC_DIR : appRoot, "package.json"));
8229
+ try {
8230
+ load.resolve(PLUGIN_RSC);
8231
+ } catch {
8232
+ throw new Error(`timber runs from source or a link here, and loads ${PLUGIN_RSC} from the app: install ${PLUGIN_RSC} in ${appRoot}.`);
8233
+ }
8234
+ return load(PLUGIN_RSC).default;
8235
+ }
8236
+ /**
8237
+ * plugin-rsc lists its vendored Flight runtime in each environment's
8238
+ * `optimizeDeps.include` by bare specifier, which Vite resolves from the app's
8239
+ * root. An app that does not install plugin-rsc itself cannot resolve it
8240
+ * there, so the browser's Flight client would be found only mid-load, and
8241
+ * pre-bundled with a full page reload. When timber runs its own copy, each
8242
+ * entry names the package it comes through (`@timber-js/app > …`), which Vite
8243
+ * resolves from timber.
8244
+ */
8245
+ function timberPluginRscDeps() {
8246
+ return {
8247
+ name: "timber-plugin-rsc-deps",
8248
+ apply: "serve",
8249
+ enforce: "post",
8250
+ configEnvironment: {
8251
+ order: "post",
8252
+ handler(_name, config) {
8253
+ const deps = config.optimizeDeps;
8254
+ if (!usesOwnPluginRsc || !deps?.include) return;
8255
+ deps.include = deps.include.map((entry) => entry.startsWith(`${PLUGIN_RSC}/`) ? `@timber-js/app > ${entry}` : entry);
8256
+ }
8257
+ }
8258
+ };
8259
+ }
8199
8260
  // src/plugins/native-runtime-boundary.ts
8200
8261
  /**
8201
8262
  * Packages the RSC mirror loads with Node that themselves import React, with
@@ -8248,8 +8309,8 @@ var NATIVE_MANIFEST_FILE = "manifest.json";
8248
8309
  * `__vite_rsc_require__`, so a global alias stands in for it.
8249
8310
  *
8250
8311
  * Used only when timber runs from an installed package with its mirrors, and
8251
- * `TIMBER_DEV_NATIVE_RUNTIME` is not `0`; RSC also needs the app's React,
8252
- * react-dom and plugin-rsc to be the versions the mirror bundled, and falls
8312
+ * `TIMBER_DEV_NATIVE_RUNTIME` is not `0`; RSC also needs the app's React and
8313
+ * react-dom to be the versions the mirror bundled, and falls
8253
8314
  * back to Vite with a warning otherwise (design/51 §"Two dev paths").
8254
8315
  * timber's own repo and examples alias `@timber-js/app` to `src/` and keep the
8255
8316
  * Vite path.
@@ -8272,7 +8333,7 @@ function decideNativeRuntime(srcDir, { env = process.env, installedVersion }) {
8272
8333
  warn: false
8273
8334
  });
8274
8335
  if (env.TIMBER_DEV_NATIVE_RUNTIME === "0") return everywhere("TIMBER_DEV_NATIVE_RUNTIME=0");
8275
- if (!srcDir.includes(`${sep}node_modules${sep}`)) return everywhere("timber is not an installed package");
8336
+ if (!isInstalledPackage(srcDir)) return everywhere("timber is not an installed package");
8276
8337
  const decision = {
8277
8338
  manifests: {},
8278
8339
  vitePath: {},
@@ -9489,6 +9550,9 @@ function timberPrerenderSugar(ctx) {
9489
9550
  * const rows = await __timber_await$(() => (db.select().from(users)),
9490
9551
  * "db.select().from(users)", "app/users/page.tsx:12");
9491
9552
  *
9553
+ * An operand that starts no work (`await call`, `await Promise.all([a, b])`)
9554
+ * gets a fourth argument, `true`, so the wrapper can mark the await a wait.
9555
+ *
9492
9556
  * `__timber_await$` is declared once per module and looks the wrapper up on
9493
9557
  * `globalThis[DEV_AWAIT_KEY]` at call time (installed with dev tracing,
9494
9558
  * `dev-tools/await-span.ts`); with none installed it calls the thunk. A
@@ -9539,6 +9603,43 @@ function containsAwait(node) {
9539
9603
  if (FUNCTION_TYPES.has(node.type)) return false;
9540
9604
  return children(node).some(containsAwait);
9541
9605
  }
9606
+ /** Wrappers that change nothing about what the operand is. */
9607
+ var TRANSPARENT_TYPES = /* @__PURE__ */ new Set([
9608
+ "ParenthesizedExpression",
9609
+ "TSAsExpression",
9610
+ "TSSatisfiesExpression",
9611
+ "TSNonNullExpression"
9612
+ ]);
9613
+ var PROMISE_COMBINATORS = /* @__PURE__ */ new Set([
9614
+ "all",
9615
+ "allSettled",
9616
+ "any",
9617
+ "race"
9618
+ ]);
9619
+ /** `p`, `this.p`, `state.pending?.p`: a value that already exists. */
9620
+ function isReference(node) {
9621
+ if (TRANSPARENT_TYPES.has(node.type) && isNode(node.expression)) return isReference(node.expression);
9622
+ if (node.type === "ChainExpression" && isNode(node.expression)) return isReference(node.expression);
9623
+ return node.type === "Identifier" || node.type === "MemberExpression";
9624
+ }
9625
+ /**
9626
+ * The operand starts no work of its own: it reads a promise that already
9627
+ * exists (`await call`, `await this.pending`), or combines such promises
9628
+ * (`await Promise.all([a, b])`). The work began when the promise was made,
9629
+ * so its spans nest wherever that happened, not under this await. The
9630
+ * wrapper marks the await a wait if the value is a native promise; a getter
9631
+ * that starts work shows up as a wait with children, which the pill treats
9632
+ * as work.
9633
+ */
9634
+ function startsNoWork(node) {
9635
+ if (TRANSPARENT_TYPES.has(node.type) && isNode(node.expression)) return startsNoWork(node.expression);
9636
+ if (isReference(node)) return true;
9637
+ if (node.type !== "CallExpression") return false;
9638
+ const callee = node.callee;
9639
+ const args = node.arguments ?? [];
9640
+ const array = args[0];
9641
+ return isNode(callee) && callee.type === "MemberExpression" && isNode(callee.object) && callee.object.type === "Identifier" && callee.object.name === "Promise" && isNode(callee.property) && PROMISE_COMBINATORS.has(String(callee.property.name)) && args.length === 1 && isNode(array) && array.type === "ArrayExpression" && (array.elements ?? []).every((e) => isNode(e) && isReference(e));
9642
+ }
9542
9643
  /** Parser dialect for a module path: the transform sees original source. */
9543
9644
  function langFor(file) {
9544
9645
  if (/\.tsx$/.test(file)) return "tsx";
@@ -9720,12 +9821,13 @@ function instrumentAwaits(code, relPath, options = {}) {
9720
9821
  const location = JSON.stringify(`${relPath}:${lineOf(node.start)}`);
9721
9822
  const thunk = containsAwait(arg) ? "async () => (" : "() => (";
9722
9823
  s.prependRight(arg.start, `${HELPER}(${thunk}`);
9723
- s.appendLeft(arg.end, `), ${text}, ${location})`);
9824
+ const wait = startsNoWork(arg) ? ", true" : "";
9825
+ s.appendLeft(arg.end, `), ${text}, ${location}${wait})`);
9724
9826
  count++;
9725
9827
  };
9726
9828
  visit(program, false);
9727
9829
  if (count === 0) return null;
9728
- const helper = `\nconst ${HELPER} = (f, l, c) => (globalThis[Symbol.for("timber.dev.await")] ?? ((g) => g()))(f, l, c);\n`;
9830
+ const helper = `\nconst ${HELPER} = (f, l, c, w) => (globalThis[Symbol.for("timber.dev.await")] ?? ((g) => g()))(f, l, c, w);\n`;
9729
9831
  s.appendLeft(prologue.end, helper);
9730
9832
  return {
9731
9833
  code: s.toString(),
@@ -10932,10 +11034,8 @@ function patchReactCompilerForProdJsx(plugins) {
10932
11034
  }
10933
11035
  function timber(config) {
10934
11036
  const ctx = createPluginContext(config);
10935
- const consumerRequire = createRequire(join(process.cwd(), "package.json"));
10936
11037
  ctx.timer.start("rsc-plugin-import");
10937
- const rscMod = consumerRequire("@vitejs/plugin-rsc");
10938
- const vitePluginRsc = rscMod.default ?? rscMod;
11038
+ const vitePluginRsc = loadPluginRsc(process.cwd());
10939
11039
  ctx.timer.end("rsc-plugin-import");
10940
11040
  const encryptionKeyExpr = resolveEncryptionKeyExpression();
10941
11041
  const earlyFileConfig = loadTimberConfigFile(process.cwd());
@@ -11054,6 +11154,7 @@ function timber(config) {
11054
11154
  timberReactResolve(),
11055
11155
  timberNodeFlightBuilds(),
11056
11156
  timberNativeRuntime(),
11157
+ timberPluginRscDeps(),
11057
11158
  timberReactProd(),
11058
11159
  ...patchReactCompilerForProdJsx(react({ compiler: effectiveReactCompiler || false })),
11059
11160
  vitePluginRsc(createRscOptions(ctx, encryptionKeyExpr)),