@timber-js/app 0.2.0-alpha.114 → 0.2.0-alpha.116

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 (43) hide show
  1. package/dist/_chunks/{actions-ILhDUzES.js → actions-DAVm0FQe.js} +17 -17
  2. package/dist/_chunks/actions-DAVm0FQe.js.map +1 -0
  3. package/dist/_chunks/{define-a0CCE6Nx.js → define-zQX6e1tN.js} +2 -2
  4. package/dist/_chunks/{define-a0CCE6Nx.js.map → define-zQX6e1tN.js.map} +1 -1
  5. package/dist/_chunks/{navigation-root-CY3pRMxF.js → navigation-root-DKsJ5Di7.js} +2 -2
  6. package/dist/_chunks/{navigation-root-CY3pRMxF.js.map → navigation-root-DKsJ5Di7.js.map} +1 -1
  7. package/dist/_chunks/tracing-DvKLzCFa.js.map +1 -1
  8. package/dist/_chunks/{use-segment-params-BSt_O2cb.js → use-segment-params-CskiK-59.js} +2 -2
  9. package/dist/_chunks/{use-segment-params-BSt_O2cb.js.map → use-segment-params-CskiK-59.js.map} +1 -1
  10. package/dist/_chunks/{walkers-DGV9dQRq.js → walkers-DgOXkTts.js} +12 -10
  11. package/dist/_chunks/walkers-DgOXkTts.js.map +1 -0
  12. package/dist/client/index.js +3 -3
  13. package/dist/client/internal.js +2 -2
  14. package/dist/client/use-segment-params.d.ts +3 -3
  15. package/dist/client/use-segment-params.d.ts.map +1 -1
  16. package/dist/index.js +43 -26
  17. package/dist/index.js.map +1 -1
  18. package/dist/plugins/routing.d.ts.map +1 -1
  19. package/dist/routing/codegen-types.d.ts +3 -0
  20. package/dist/routing/codegen-types.d.ts.map +1 -1
  21. package/dist/routing/index.js +1 -1
  22. package/dist/routing/segment-codegen.d.ts +22 -9
  23. package/dist/routing/segment-codegen.d.ts.map +1 -1
  24. package/dist/segment-params/index.js +1 -1
  25. package/dist/server/als-registry.d.ts +5 -4
  26. package/dist/server/als-registry.d.ts.map +1 -1
  27. package/dist/server/index.js +1 -1
  28. package/dist/server/internal.js +3 -3
  29. package/dist/server/internal.js.map +1 -1
  30. package/dist/server/pipeline-phases.d.ts.map +1 -1
  31. package/dist/server/request-context.d.ts +9 -9
  32. package/dist/server/request-context.d.ts.map +1 -1
  33. package/package.json +1 -1
  34. package/src/client/use-segment-params.ts +4 -4
  35. package/src/plugins/routing.ts +26 -17
  36. package/src/routing/codegen-types.ts +3 -0
  37. package/src/routing/codegen.ts +18 -9
  38. package/src/routing/segment-codegen.ts +46 -21
  39. package/src/server/als-registry.ts +5 -4
  40. package/src/server/pipeline-phases.ts +9 -7
  41. package/src/server/request-context.ts +17 -17
  42. package/dist/_chunks/actions-ILhDUzES.js.map +0 -1
  43. package/dist/_chunks/walkers-DGV9dQRq.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { n as setViteServer } from "./_chunks/warnings-B30wpfaS.js";
2
2
  import { h as swallow } from "./_chunks/logger-DDmK5skc.js";
3
3
  import { t as scanRoutes } from "./_chunks/scanner-DmfoB7iK.js";
4
- import { n as collectInterceptionRewrites, r as generateRouteMap, t as collectLeafRoutes } from "./_chunks/walkers-DGV9dQRq.js";
4
+ import { n as collectInterceptionRewrites, r as generateRouteMap, t as collectLeafRoutes } from "./_chunks/walkers-DgOXkTts.js";
5
5
  import { a as DEFAULT_BUILD_DIR, c as mergeFileConfig, d as resolveClientJavascript, f as createNoopTimer, l as resolveAppDir, n as findSchemaFile, o as createPluginContext, r as parseExistingSchemaKeys, s as loadTimberConfigFile, t as collectDynamicSegments, u as resolveBuildDir } from "./_chunks/cli-schema-sync-DFZmnmqG.js";
6
6
  import { t as formatSize } from "./_chunks/format-CR6v1pWE.js";
7
7
  import { dirname, extname, join, normalize, resolve } from "node:path";
@@ -1981,34 +1981,47 @@ function timberMdx(ctx) {
1981
1981
  //#endregion
1982
1982
  //#region src/routing/segment-codegen.ts
1983
1983
  /**
1984
- * _segment type generation and directory-to-route mapping.
1984
+ * $segment type generation and directory-to-route mapping.
1985
1985
  *
1986
- * Generates per-route _segment.d.ts files in .timber/types/ that mirror
1986
+ * Generates per-route $segment.d.ts files in .timber/types/ that mirror
1987
1987
  * the app/ directory structure. TypeScript's rootDirs feature makes these
1988
- * importable as './_segment' from route files.
1988
+ * importable as './$segment' from route files.
1989
1989
  *
1990
- * Design doc: design/41-global-params.md §The _segment Module
1990
+ * Design doc: design/41-global-params.md §The $segment Module
1991
1991
  */
1992
1992
  /**
1993
- * Build a map of absolute filesystem directory → route pattern.
1994
- * Used by resolveId to map a _segment import's importer to the correct route.
1993
+ * Build a map of absolute filesystem directory → segment info.
1994
+ * Used by resolveId to map a $segment import's importer to the correct route,
1995
+ * and by writeSegmentTypes to generate per-route $segment.d.ts files.
1995
1996
  *
1996
1997
  * Walks every segment (not just leaves) so layouts and middleware
1997
- * at any depth can import _segment.
1998
+ * at any depth can import $segment.
1998
1999
  */
1999
2000
  function buildDirToRouteMap(tree, appDir) {
2000
2001
  const map = /* @__PURE__ */ new Map();
2001
- function walk(node, fsPath) {
2002
- const routePattern = node.urlPath || "/";
2003
- map.set(fsPath, routePattern);
2004
- for (const child of node.children) walk(child, join(fsPath, child.segmentName));
2005
- for (const [slotName, slotNode] of Object.entries(node.slots)) walk(slotNode, join(fsPath, slotName));
2002
+ function walk(node, fsPath, treePath) {
2003
+ map.set(fsPath, {
2004
+ route: node.urlPath || "/",
2005
+ segmentPath: treePath || "/"
2006
+ });
2007
+ for (const child of node.children) walk(child, join(fsPath, child.segmentName), `${treePath}/${child.segmentName}`);
2008
+ for (const [slotName, slotNode] of Object.entries(node.slots)) walk(slotNode, join(fsPath, `@${slotName}`), `${treePath}/@${slotName}`);
2006
2009
  }
2007
- walk(tree.root, appDir);
2010
+ walk(tree.root, appDir, "");
2008
2011
  return map;
2009
2012
  }
2010
2013
  /**
2011
- * Generate per-route _segment.d.ts files in .timber/types/ mirroring
2014
+ * Generate the full $segment.d.ts content for a segment.
2015
+ */
2016
+ function generateSegmentDts(info) {
2017
+ return [
2018
+ `export const ROUTE: '${info.route}';`,
2019
+ `export const SEGMENT_PATH: '${info.segmentPath}';`,
2020
+ ""
2021
+ ].join("\n");
2022
+ }
2023
+ /**
2024
+ * Generate per-route $segment.d.ts files in .timber/types/ mirroring
2012
2025
  * the app/ directory structure. These files are importable via TypeScript's
2013
2026
  * rootDirs feature.
2014
2027
  */
@@ -2016,11 +2029,11 @@ async function writeSegmentTypes(routeTree, appDir, root) {
2016
2029
  const typesBase = join(root, ".timber", "types", appDir.slice(root.length + 1));
2017
2030
  const map = buildDirToRouteMap(routeTree, appDir);
2018
2031
  const writes = [];
2019
- for (const [fsDir, routePattern] of map) {
2032
+ for (const [fsDir, info] of map) {
2020
2033
  const segmentDir = join(typesBase, fsDir.slice(appDir.length));
2021
- const segmentPath = join(segmentDir, "_segment.d.ts");
2022
- const content = `export const route: '${routePattern}';\n`;
2023
- writes.push(mkdir(segmentDir, { recursive: true }).then(() => writeFile(segmentPath, content, "utf-8")));
2034
+ const segmentFile = join(segmentDir, "$segment.d.ts");
2035
+ const content = generateSegmentDts(info);
2036
+ writes.push(mkdir(segmentDir, { recursive: true }).then(() => writeFile(segmentFile, content, "utf-8")));
2024
2037
  }
2025
2038
  await Promise.all(writes);
2026
2039
  }
@@ -2263,7 +2276,7 @@ var SEARCH_PARAMS_REGISTRY_ID = "virtual:timber-search-params-registry";
2263
2276
  var RESOLVED_SEARCH_PARAMS_REGISTRY_ID = `\0${SEARCH_PARAMS_REGISTRY_ID}`;
2264
2277
  var SCHEMA_ID = "virtual:timber-schema";
2265
2278
  var RESOLVED_SCHEMA_ID = `\0${SCHEMA_ID}`;
2266
- var SEGMENT_PREFIX = "\0_segment:";
2279
+ var SEGMENT_PREFIX = "\0$segment:";
2267
2280
  /**
2268
2281
  * File convention names we track for changes that require manifest regeneration.
2269
2282
  */
@@ -2315,7 +2328,7 @@ function writeCodegen(ctx) {
2315
2328
  function timberRouting(ctx) {
2316
2329
  /** Track warned files to avoid repeating warnings on rescan. */
2317
2330
  const warnedFiles = /* @__PURE__ */ new Set();
2318
- /** Maps absolute filesystem directory → route pattern for _segment resolution. */
2331
+ /** Maps absolute filesystem directory → segment info for $segment resolution. */
2319
2332
  let dirToRoute = /* @__PURE__ */ new Map();
2320
2333
  function rescan() {
2321
2334
  const appDirWarning = checkAppDirExists(ctx.appDir);
@@ -2352,11 +2365,11 @@ function timberRouting(ctx) {
2352
2365
  if (cleanId.endsWith(`/${VIRTUAL_MODULE_ID$1}`)) return RESOLVED_VIRTUAL_ID$1;
2353
2366
  if (cleanId === SEARCH_PARAMS_REGISTRY_ID || cleanId.endsWith(`/${SEARCH_PARAMS_REGISTRY_ID}`)) return RESOLVED_SEARCH_PARAMS_REGISTRY_ID;
2354
2367
  if (cleanId === SCHEMA_ID || cleanId.endsWith(`/${SCHEMA_ID}`)) return RESOLVED_SCHEMA_ID;
2355
- if (importer && (cleanId === "./_segment" || cleanId === "./_segment.js" || cleanId === "./_segment.ts")) {
2368
+ if (importer && (cleanId === "./$segment" || cleanId === "./$segment.js" || cleanId === "./$segment.ts")) {
2356
2369
  const cleanImporter = importer.startsWith("\0") ? importer.slice(1) : importer;
2357
2370
  const importerDir = cleanImporter.substring(0, cleanImporter.lastIndexOf("/"));
2358
- const routePattern = dirToRoute.get(importerDir);
2359
- if (routePattern !== void 0) return `${SEGMENT_PREFIX}${routePattern}`;
2371
+ const segmentInfo = dirToRoute.get(importerDir);
2372
+ if (segmentInfo !== void 0) return `${SEGMENT_PREFIX}${JSON.stringify(segmentInfo)}`;
2360
2373
  }
2361
2374
  return null;
2362
2375
  },
@@ -2371,8 +2384,12 @@ function timberRouting(ctx) {
2371
2384
  }
2372
2385
  if (id === RESOLVED_SCHEMA_ID) return generateSchemaModule(ctx.appDir);
2373
2386
  if (id.startsWith(SEGMENT_PREFIX)) {
2374
- const routePattern = id.slice(10);
2375
- return `export const route = ${JSON.stringify(routePattern)};\n`;
2387
+ const info = JSON.parse(id.slice(10));
2388
+ return [
2389
+ `export const ROUTE = ${JSON.stringify(info.route)};`,
2390
+ `export const SEGMENT_PATH = ${JSON.stringify(info.segmentPath)};`,
2391
+ ""
2392
+ ].join("\n");
2376
2393
  }
2377
2394
  return null;
2378
2395
  },