@bleedingdev/modern-js-plugin-tanstack 3.2.0-ultramodern.12 → 3.2.0-ultramodern.121

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 (136) hide show
  1. package/dist/cjs/cli/index.js +89 -31
  2. package/dist/cjs/cli/routeSplitting.js +55 -0
  3. package/dist/cjs/cli/tanstackTypes.js +172 -170
  4. package/dist/cjs/cli.js +12 -8
  5. package/dist/cjs/runtime/basepathRewrite.js +12 -8
  6. package/dist/cjs/runtime/dataMutation.js +9 -5
  7. package/dist/cjs/runtime/hooks.js +20 -19
  8. package/dist/cjs/runtime/hydrationBoundary.js +48 -0
  9. package/dist/cjs/runtime/index.js +79 -35
  10. package/dist/cjs/runtime/lifecycle.js +21 -91
  11. package/dist/cjs/runtime/loaderBridge.js +173 -0
  12. package/dist/cjs/runtime/outlet.js +58 -0
  13. package/dist/cjs/runtime/plugin.js +195 -114
  14. package/dist/cjs/runtime/plugin.node.js +45 -45
  15. package/dist/cjs/runtime/plugin.worker.js +53 -0
  16. package/dist/cjs/runtime/pluginCore.js +55 -0
  17. package/dist/cjs/runtime/prefetchLink.js +10 -6
  18. package/dist/cjs/runtime/register.js +56 -0
  19. package/dist/cjs/runtime/routeTree.js +74 -207
  20. package/dist/cjs/runtime/router.js +41 -0
  21. package/dist/cjs/runtime/rsc/ClientSlot.js +9 -5
  22. package/dist/cjs/runtime/rsc/CompositeComponent.js +9 -5
  23. package/dist/cjs/runtime/rsc/ReplayableStream.js +14 -9
  24. package/dist/cjs/runtime/rsc/RscNodeRenderer.js +9 -5
  25. package/dist/cjs/runtime/rsc/SlotContext.js +9 -5
  26. package/dist/cjs/runtime/rsc/client.js +9 -5
  27. package/dist/cjs/runtime/rsc/createRscProxy.js +9 -5
  28. package/dist/cjs/runtime/rsc/index.js +9 -5
  29. package/dist/cjs/runtime/rsc/payloadRouter.js +44 -6
  30. package/dist/cjs/runtime/rsc/server.js +9 -5
  31. package/dist/cjs/runtime/rsc/slotUsageSanitizer.js +9 -5
  32. package/dist/cjs/runtime/rsc/symbols.js +20 -15
  33. package/dist/cjs/runtime/state.js +45 -0
  34. package/dist/cjs/runtime/types.js +31 -1
  35. package/dist/cjs/runtime/utils.js +9 -10
  36. package/dist/cjs/runtime.js +9 -5
  37. package/dist/esm/cli/index.mjs +75 -27
  38. package/dist/esm/cli/routeSplitting.mjs +14 -0
  39. package/dist/esm/cli/tanstackTypes.mjs +158 -160
  40. package/dist/esm/runtime/hooks.mjs +1 -8
  41. package/dist/esm/runtime/hydrationBoundary.mjs +10 -0
  42. package/dist/esm/runtime/index.mjs +5 -2
  43. package/dist/esm/runtime/lifecycle.mjs +1 -82
  44. package/dist/esm/runtime/loaderBridge.mjs +114 -0
  45. package/dist/esm/runtime/outlet.mjs +17 -0
  46. package/dist/esm/runtime/plugin.mjs +191 -114
  47. package/dist/esm/runtime/plugin.node.mjs +40 -44
  48. package/dist/esm/runtime/plugin.worker.mjs +1 -0
  49. package/dist/esm/runtime/pluginCore.mjs +14 -0
  50. package/dist/esm/runtime/prefetchLink.mjs +1 -1
  51. package/dist/esm/runtime/register.mjs +18 -0
  52. package/dist/esm/runtime/routeTree.mjs +59 -193
  53. package/dist/esm/runtime/router.mjs +2 -0
  54. package/dist/esm/runtime/rsc/payloadRouter.mjs +35 -1
  55. package/dist/esm/runtime/state.mjs +7 -0
  56. package/dist/esm/runtime/types.mjs +7 -0
  57. package/dist/esm/runtime/utils.mjs +0 -5
  58. package/dist/esm-node/cli/index.mjs +75 -27
  59. package/dist/esm-node/cli/routeSplitting.mjs +15 -0
  60. package/dist/esm-node/cli/tanstackTypes.mjs +158 -160
  61. package/dist/esm-node/runtime/hooks.mjs +1 -8
  62. package/dist/esm-node/runtime/hydrationBoundary.mjs +11 -0
  63. package/dist/esm-node/runtime/index.mjs +5 -2
  64. package/dist/esm-node/runtime/lifecycle.mjs +1 -82
  65. package/dist/esm-node/runtime/loaderBridge.mjs +115 -0
  66. package/dist/esm-node/runtime/outlet.mjs +18 -0
  67. package/dist/esm-node/runtime/plugin.mjs +191 -114
  68. package/dist/esm-node/runtime/plugin.node.mjs +40 -44
  69. package/dist/esm-node/runtime/plugin.worker.mjs +2 -0
  70. package/dist/esm-node/runtime/pluginCore.mjs +15 -0
  71. package/dist/esm-node/runtime/prefetchLink.mjs +1 -1
  72. package/dist/esm-node/runtime/register.mjs +19 -0
  73. package/dist/esm-node/runtime/routeTree.mjs +59 -193
  74. package/dist/esm-node/runtime/router.mjs +3 -0
  75. package/dist/esm-node/runtime/rsc/payloadRouter.mjs +35 -1
  76. package/dist/esm-node/runtime/state.mjs +8 -0
  77. package/dist/esm-node/runtime/types.mjs +7 -0
  78. package/dist/esm-node/runtime/utils.mjs +0 -5
  79. package/dist/types/cli/index.d.ts +14 -1
  80. package/dist/types/cli/routeSplitting.d.ts +20 -0
  81. package/dist/types/cli/tanstackTypes.d.ts +21 -1
  82. package/dist/types/runtime/hooks.d.ts +8 -33
  83. package/dist/types/runtime/hydrationBoundary.d.ts +2 -0
  84. package/dist/types/runtime/index.d.ts +8 -3
  85. package/dist/types/runtime/lifecycle.d.ts +7 -22
  86. package/dist/types/runtime/loaderBridge.d.ts +48 -0
  87. package/dist/types/runtime/outlet.d.ts +2 -0
  88. package/dist/types/runtime/plugin.d.ts +2 -15
  89. package/dist/types/runtime/plugin.node.d.ts +2 -15
  90. package/dist/types/runtime/plugin.worker.d.ts +1 -0
  91. package/dist/types/runtime/pluginCore.d.ts +21 -0
  92. package/dist/types/runtime/register.d.ts +9 -0
  93. package/dist/types/runtime/routeTree.d.ts +0 -2
  94. package/dist/types/runtime/router.d.ts +14 -0
  95. package/dist/types/runtime/state.d.ts +16 -0
  96. package/dist/types/runtime/types.d.ts +14 -53
  97. package/package.json +42 -40
  98. package/rstest.config.mts +6 -0
  99. package/src/cli/index.ts +162 -23
  100. package/src/cli/routeSplitting.ts +43 -0
  101. package/src/cli/tanstackTypes.ts +331 -187
  102. package/src/runtime/hooks.ts +10 -27
  103. package/src/runtime/hydrationBoundary.tsx +12 -0
  104. package/src/runtime/index.tsx +17 -7
  105. package/src/runtime/lifecycle.ts +16 -151
  106. package/src/runtime/loaderBridge.ts +257 -0
  107. package/src/runtime/outlet.tsx +48 -0
  108. package/src/runtime/plugin.node.tsx +72 -85
  109. package/src/runtime/plugin.tsx +361 -206
  110. package/src/runtime/plugin.worker.tsx +4 -0
  111. package/src/runtime/pluginCore.ts +48 -0
  112. package/src/runtime/prefetchLink.tsx +1 -1
  113. package/src/runtime/register.ts +58 -0
  114. package/src/runtime/routeTree.ts +163 -354
  115. package/src/runtime/router.ts +15 -0
  116. package/src/runtime/rsc/payloadRouter.ts +45 -2
  117. package/src/runtime/ssr-shim.d.ts +1 -3
  118. package/src/runtime/state.ts +29 -0
  119. package/src/runtime/types.ts +32 -66
  120. package/src/runtime/utils.tsx +3 -6
  121. package/tests/router/cli.test.ts +586 -5
  122. package/tests/router/fastDefaults.test.ts +25 -0
  123. package/tests/router/hooks.test.ts +26 -0
  124. package/tests/router/hydrationBoundary.test.tsx +23 -0
  125. package/tests/router/loaderBridge.test.ts +211 -0
  126. package/tests/router/packageSurface.test.ts +24 -0
  127. package/tests/router/prefetchLink.test.tsx +43 -7
  128. package/tests/router/register.test.ts +46 -0
  129. package/tests/router/routeTree.test.ts +381 -81
  130. package/tests/router/rsc.test.tsx +70 -0
  131. package/tests/router/tanstackTypes.test.ts +573 -1
  132. package/dist/cjs/runtime/DefaultNotFound.js +0 -47
  133. package/dist/esm/runtime/DefaultNotFound.mjs +0 -13
  134. package/dist/esm-node/runtime/DefaultNotFound.mjs +0 -14
  135. package/dist/types/runtime/DefaultNotFound.d.ts +0 -2
  136. package/src/runtime/DefaultNotFound.tsx +0 -15
@@ -10,11 +10,15 @@ var __webpack_require__ = {};
10
10
  };
11
11
  })();
12
12
  (()=>{
13
- __webpack_require__.d = (exports1, definition)=>{
14
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
- enumerable: true,
16
- get: definition[key]
17
- });
13
+ __webpack_require__.d = (exports1, getters, values)=>{
14
+ var define = (defs, kind)=>{
15
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
16
+ enumerable: true,
17
+ [kind]: defs[key]
18
+ });
19
+ };
20
+ define(getters, "get");
21
+ define(values, "value");
18
22
  };
19
23
  })();
20
24
  (()=>{
@@ -33,24 +37,13 @@ var __webpack_require__ = {};
33
37
  var __webpack_exports__ = {};
34
38
  __webpack_require__.r(__webpack_exports__);
35
39
  __webpack_require__.d(__webpack_exports__, {
36
- generateTanstackRouterTypesSourceForEntry: ()=>generateTanstackRouterTypesSourceForEntry,
37
- isTanstackRouterFrameworkEnabled: ()=>isTanstackRouterFrameworkEnabled
40
+ collectCanonicalRoutesForEntry: ()=>collectCanonicalRoutesForEntry,
41
+ generateTanstackRouterTypesSourceForEntry: ()=>generateTanstackRouterTypesSourceForEntry
38
42
  });
43
+ const cli_namespaceObject = require("@modern-js/runtime/cli");
39
44
  const utils_namespaceObject = require("@modern-js/utils");
40
45
  const external_path_namespaceObject = require("path");
41
46
  var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
42
- const reservedWords = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public';
43
- const builtins = 'arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl';
44
- const forbidList = new Set(`${reservedWords} ${builtins}`.split(' '));
45
- function makeLegalIdentifier(str) {
46
- const identifier = str.replace(/-(\w)/g, (_, letter)=>letter.toUpperCase()).replace(/[^$_a-zA-Z0-9]/g, '_');
47
- if (/\d/.test(identifier[0]) || forbidList.has(identifier)) return `_${identifier}`;
48
- return identifier || '_';
49
- }
50
- function getPathWithoutExt(filename) {
51
- const extname = external_path_default().extname(filename);
52
- return extname ? filename.slice(0, -extname.length) : filename;
53
- }
54
47
  const JS_OR_TS_EXTS = [
55
48
  '.js',
56
49
  '.jsx',
@@ -75,7 +68,7 @@ function toTanstackPath(pathname) {
75
68
  }
76
69
  async function resolveFileNoExt(inputNoExtPath) {
77
70
  const file = (0, utils_namespaceObject.findExists)(JS_OR_TS_EXTS.map((ext)=>`${inputNoExtPath}${ext}`));
78
- return file ? getPathWithoutExt(file) : null;
71
+ return file ? (0, cli_namespaceObject.getPathWithoutExt)(file) : null;
79
72
  }
80
73
  function quote(str) {
81
74
  return JSON.stringify(str);
@@ -94,6 +87,14 @@ function pickModernLoaderModule(route) {
94
87
  inline
95
88
  };
96
89
  }
90
+ function pickRouteSearchContractModules(route) {
91
+ const validateSearchPath = route.validateSearch;
92
+ const loaderDepsPath = route.loaderDeps;
93
+ return {
94
+ validateSearchPath: 'string' == typeof validateSearchPath ? validateSearchPath : null,
95
+ loaderDepsPath: 'string' == typeof loaderDepsPath ? loaderDepsPath : null
96
+ };
97
+ }
97
98
  function isPathlessLayout(route) {
98
99
  return 'nested' === route.type && 'boolean' != typeof route.index && void 0 === route.path;
99
100
  }
@@ -108,16 +109,78 @@ function createRouteStaticDataSnippet(opts) {
108
109
  if (!staticDataLines.length) return null;
109
110
  return `staticData: createRouteStaticData({\n ${staticDataLines.join('\n ')}\n }),`;
110
111
  }
111
- async function isTanstackRouterFrameworkEnabled(appContext) {
112
- const runtimeConfigBase = external_path_default().join(appContext.srcDirectory, appContext.runtimeConfigFile);
113
- const runtimeConfigFile = (0, utils_namespaceObject.findExists)(JS_OR_TS_EXTS.map((ext)=>`${runtimeConfigBase}${ext}`));
114
- if (!runtimeConfigFile) return false;
115
- try {
116
- const content = await utils_namespaceObject.fs.readFile(runtimeConfigFile, 'utf-8');
117
- return /framework\s*:\s*['"]tanstack['"]/.test(content);
118
- } catch {
119
- return false;
112
+ const LOCALE_PARAM_SEGMENTS = new Set([
113
+ ':lang',
114
+ ':locale',
115
+ ':language',
116
+ '$lang',
117
+ '$locale',
118
+ '$language'
119
+ ]);
120
+ function paramsTypeForCanonicalPath(canonicalPath) {
121
+ const fields = [];
122
+ for (const segment of canonicalPath.split('/'))if (segment) {
123
+ if ('*' === segment || '$' === segment) {
124
+ fields.push("'_splat'?: string");
125
+ continue;
126
+ }
127
+ if (segment.startsWith('{-$') && segment.endsWith('}')) {
128
+ fields.push(`${JSON.stringify(segment.slice(3, -1))}?: string`);
129
+ continue;
130
+ }
131
+ if (segment.startsWith('$')) {
132
+ fields.push(`${JSON.stringify(segment.slice(1))}: string`);
133
+ continue;
134
+ }
135
+ if (segment.startsWith(':')) {
136
+ const optional = segment.endsWith('?');
137
+ const name = segment.slice(1, optional ? void 0 : segment.length);
138
+ fields.push(`${JSON.stringify(optional ? name.slice(0, -1) : name)}${optional ? '?' : ''}: string`);
139
+ }
120
140
  }
141
+ return fields.length > 0 ? `{ ${fields.join('; ')} }` : 'Record<string, never>';
142
+ }
143
+ function collectCanonicalRoutesForEntry(routes, options = {}) {
144
+ const { localeParamHeuristic = true } = options;
145
+ const canonicalParams = new Map();
146
+ let hasI18nSurface = false;
147
+ const normalizeJoined = (joined)=>{
148
+ const collapsed = joined.replace(/\/+/g, '/');
149
+ const withLeading = collapsed.startsWith('/') ? collapsed : `/${collapsed}`;
150
+ return withLeading.length > 1 ? withLeading.replace(/\/+$/, '') : withLeading;
151
+ };
152
+ const record = (canonicalPath)=>{
153
+ const normalized = normalizeJoined(canonicalPath || '/');
154
+ const key = toTanstackPath(normalized);
155
+ if (!canonicalParams.has(key)) canonicalParams.set(key, paramsTypeForCanonicalPath(normalized));
156
+ };
157
+ const visit = (route, parentPath)=>{
158
+ let currentPath = parentPath;
159
+ if ('string' == typeof route.modernCanonicalPath) {
160
+ hasI18nSurface = true;
161
+ currentPath = normalizeJoined(route.modernCanonicalPath);
162
+ } else if ('string' == typeof route.path && route.path.length > 0) {
163
+ const segments = route.path.replace(/\[(.+?)\]/g, ':$1').split('/').filter(Boolean);
164
+ if (localeParamHeuristic && '' === parentPath && LOCALE_PARAM_SEGMENTS.has(segments[0])) {
165
+ hasI18nSurface = true;
166
+ segments.shift();
167
+ }
168
+ currentPath = segments.length ? normalizeJoined(`${parentPath}/${segments.join('/')}`) : parentPath;
169
+ }
170
+ const children = route.children;
171
+ if (children && children.length > 0) {
172
+ for (const child of children)visit(child, currentPath);
173
+ return;
174
+ }
175
+ record(currentPath || '/');
176
+ };
177
+ const rootModern = routes.find((route)=>route.isRoot);
178
+ const topLevel = rootModern ? rootModern.children ?? [] : routes;
179
+ for (const route of topLevel)visit(route, '');
180
+ if (!hasI18nSurface || 0 === canonicalParams.size) return null;
181
+ return Object.fromEntries([
182
+ ...canonicalParams.entries()
183
+ ].sort(([a], [b])=>a.localeCompare(b)));
121
184
  }
122
185
  async function generateTanstackRouterTypesSourceForEntry(opts) {
123
186
  const { appContext, entryName, generatedDirName = 'modern-tanstack', routes } = opts;
@@ -127,8 +190,39 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
127
190
  const imports = [];
128
191
  const statements = [];
129
192
  const loaderImportMap = new Map();
193
+ const componentImportMap = new Map();
194
+ const searchContractImportMap = new Map();
195
+ const usedRouteVarNames = new Set();
130
196
  let loaderIndex = 0;
197
+ let componentIndex = 0;
198
+ let validateSearchIndex = 0;
199
+ let loaderDepsIndex = 0;
131
200
  let routeIndex = 0;
201
+ const getImportNameForComponent = (componentPath)=>{
202
+ if ('string' != typeof componentPath || 0 === componentPath.length) return Promise.resolve(null);
203
+ let pendingImportName = componentImportMap.get(componentPath);
204
+ if (!pendingImportName) {
205
+ pendingImportName = (async ()=>{
206
+ const resolvedNoExt = await resolveRouteModuleNoExt(componentPath);
207
+ if (!resolvedNoExt) return null;
208
+ const relImport = normalizeRelativeImport(external_path_default().relative(outDir, resolvedNoExt));
209
+ const componentName = `component_${componentIndex++}`;
210
+ imports.push(`import ${componentName} from ${quote(relImport)};`);
211
+ return componentName;
212
+ })();
213
+ componentImportMap.set(componentPath, pendingImportName);
214
+ }
215
+ return pendingImportName;
216
+ };
217
+ const resolveRouteModuleNoExt = async (aliasedNoExtPath)=>{
218
+ const prefix = `${appContext.internalSrcAlias}/`;
219
+ let absNoExt;
220
+ if (aliasedNoExtPath.startsWith(prefix)) {
221
+ const rel = aliasedNoExtPath.slice(prefix.length);
222
+ absNoExt = external_path_default().join(appContext.srcDirectory, rel);
223
+ } else absNoExt = external_path_default().isAbsolute(aliasedNoExtPath) ? aliasedNoExtPath : external_path_default().join(appContext.srcDirectory, aliasedNoExtPath);
224
+ return resolveFileNoExt(absNoExt);
225
+ };
132
226
  const getImportNamesForLoader = async (aliasedNoExtPath, inline, hasAction)=>{
133
227
  const key = `${inline ? 'inline' : 'default'}:${hasAction ? 'action' : 'loader'}:${aliasedNoExtPath}`;
134
228
  const existing = loaderImportMap.get(key);
@@ -136,13 +230,7 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
136
230
  loaderName: existing,
137
231
  actionName: hasAction ? existing.replace(/^loader_/, 'action_') : null
138
232
  };
139
- const prefix = `${appContext.internalSrcAlias}/`;
140
- let absNoExt;
141
- if (aliasedNoExtPath.startsWith(prefix)) {
142
- const rel = aliasedNoExtPath.slice(prefix.length);
143
- absNoExt = external_path_default().join(appContext.srcDirectory, rel);
144
- } else absNoExt = external_path_default().isAbsolute(aliasedNoExtPath) ? aliasedNoExtPath : external_path_default().join(appContext.srcDirectory, aliasedNoExtPath);
145
- const resolvedNoExt = await resolveFileNoExt(absNoExt);
233
+ const resolvedNoExt = await resolveRouteModuleNoExt(aliasedNoExtPath);
146
234
  if (!resolvedNoExt) return null;
147
235
  const relImport = normalizeRelativeImport(external_path_default().relative(outDir, resolvedNoExt));
148
236
  const importName = `loader_${loaderIndex++}`;
@@ -160,10 +248,29 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
160
248
  actionName
161
249
  };
162
250
  };
251
+ const getImportNameForSearchContract = async (aliasedNoExtPath, exportName)=>{
252
+ const key = `${exportName}:${aliasedNoExtPath}`;
253
+ const existing = searchContractImportMap.get(key);
254
+ if (existing) return existing;
255
+ const resolvedNoExt = await resolveRouteModuleNoExt(aliasedNoExtPath);
256
+ if (!resolvedNoExt) return null;
257
+ const relImport = normalizeRelativeImport(external_path_default().relative(outDir, resolvedNoExt));
258
+ const importName = 'validateSearch' === exportName ? `validateSearch_${validateSearchIndex++}` : `loaderDeps_${loaderDepsIndex++}`;
259
+ imports.push(`import { ${exportName} as ${importName} } from ${quote(relImport)};`);
260
+ searchContractImportMap.set(key, importName);
261
+ return importName;
262
+ };
263
+ const reserveRouteVarName = (preferred)=>{
264
+ let candidate = preferred;
265
+ let suffix = 1;
266
+ while(usedRouteVarNames.has(candidate))candidate = `${preferred}_${suffix++}`;
267
+ usedRouteVarNames.add(candidate);
268
+ return candidate;
269
+ };
163
270
  const createRouteVarName = (route)=>{
164
271
  const id = route.id;
165
- const base = id ? makeLegalIdentifier(id) : `r_${routeIndex++}`;
166
- return `route_${base}`;
272
+ const base = id ? (0, cli_namespaceObject.makeLegalIdentifier)(id) : `r_${routeIndex++}`;
273
+ return reserveRouteVarName(`route_${base}`);
167
274
  };
168
275
  const buildRoute = async (opts)=>{
169
276
  const { parentVar, route } = opts;
@@ -173,11 +280,16 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
173
280
  const loaderImports = loaderInfo ? await getImportNamesForLoader(loaderInfo.loaderPath, loaderInfo.inline, Boolean(loaderInfo.inline && routeAction === loaderInfo.loaderPath)) : null;
174
281
  const loaderName = loaderImports?.loaderName || null;
175
282
  const actionName = loaderImports?.actionName || null;
283
+ const searchContractInfo = pickRouteSearchContractModules(route);
284
+ const validateSearchName = searchContractInfo.validateSearchPath ? await getImportNameForSearchContract(searchContractInfo.validateSearchPath, 'validateSearch') : null;
285
+ const loaderDepsName = searchContractInfo.loaderDepsPath ? await getImportNameForSearchContract(searchContractInfo.loaderDepsPath, 'loaderDeps') : null;
176
286
  const rawPath = route.path;
177
287
  const hasSplat = 'string' == typeof rawPath && rawPath.includes('*');
178
288
  const routeOpts = [
179
289
  `getParentRoute: () => ${parentVar},`
180
290
  ];
291
+ const componentName = await getImportNameForComponent(route._component);
292
+ if (componentName) routeOpts.push(`component: ${componentName},`);
181
293
  if (isPathlessLayout(route)) {
182
294
  const id = route.id;
183
295
  routeOpts.push(`id: ${quote(id || 'pathless')},`);
@@ -186,20 +298,24 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
186
298
  routeOpts.push(`path: ${quote(p)},`);
187
299
  }
188
300
  if (loaderName) routeOpts.push(`loader: modernLoaderToTanstack({ hasSplat: ${hasSplat} }, ${loaderName}),`);
301
+ if (validateSearchName) routeOpts.push(`validateSearch: ${validateSearchName},`);
302
+ if (loaderDepsName) routeOpts.push(`loaderDeps: ${loaderDepsName},`);
189
303
  const staticDataSnippet = createRouteStaticDataSnippet({
190
304
  modernRouteId: route.id,
191
305
  loaderName,
192
306
  actionName
193
307
  });
194
308
  if (staticDataSnippet) routeOpts.push(staticDataSnippet);
195
- statements.push(`const ${varName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
196
309
  const children = route.children;
310
+ const hasChildren = Boolean(children && children.length > 0);
311
+ const routeCtorVarName = hasChildren ? reserveRouteVarName(`${varName}__base`) : varName;
312
+ statements.push(`const ${routeCtorVarName} = createRoute({\n ${routeOpts.join('\n ')}\n});`);
197
313
  if (children && children.length > 0) {
198
314
  const childVars = await Promise.all(children.map((child)=>buildRoute({
199
- parentVar: varName,
315
+ parentVar: routeCtorVarName,
200
316
  route: child
201
317
  })));
202
- statements.push(`${varName}.addChildren([${childVars.join(', ')}]);`);
318
+ statements.push(`const ${varName} = ${routeCtorVarName}.addChildren([${childVars.join(', ')}]);`);
203
319
  }
204
320
  return varName;
205
321
  };
@@ -208,12 +324,19 @@ async function generateTanstackRouterTypesSourceForEntry(opts) {
208
324
  const rootLoaderImports = rootLoaderInfo?.loaderPath ? await getImportNamesForLoader(rootLoaderInfo.loaderPath, rootLoaderInfo.inline, Boolean(rootLoaderInfo.inline && rootAction === rootLoaderInfo.loaderPath)) : null;
209
325
  const rootLoaderName = rootLoaderImports?.loaderName || null;
210
326
  const rootActionName = rootLoaderImports?.actionName || null;
327
+ const rootSearchContractInfo = rootModern ? pickRouteSearchContractModules(rootModern) : null;
328
+ const rootValidateSearchName = rootSearchContractInfo?.validateSearchPath ? await getImportNameForSearchContract(rootSearchContractInfo.validateSearchPath, 'validateSearch') : null;
329
+ const rootLoaderDepsName = rootSearchContractInfo?.loaderDepsPath ? await getImportNameForSearchContract(rootSearchContractInfo.loaderDepsPath, 'loaderDeps') : null;
211
330
  const topLevelVars = await Promise.all(topLevel.map((route)=>buildRoute({
212
331
  parentVar: 'rootRoute',
213
332
  route
214
333
  })));
215
334
  const rootOpts = [];
335
+ const rootComponentName = await getImportNameForComponent(rootModern?._component);
336
+ if (rootComponentName) rootOpts.push(`component: ${rootComponentName},`);
216
337
  if (rootLoaderName) rootOpts.push(`loader: modernLoaderToTanstack({ hasSplat: false }, ${rootLoaderName}),`);
338
+ if (rootValidateSearchName) rootOpts.push(`validateSearch: ${rootValidateSearchName},`);
339
+ if (rootLoaderDepsName) rootOpts.push(`loaderDeps: ${rootLoaderDepsName},`);
217
340
  const routerGenTs = `/* eslint-disable */
218
341
  // This file is auto-generated by Modern.js. Do not edit manually.
219
342
 
@@ -222,134 +345,12 @@ import {
222
345
  createRootRouteWithContext,
223
346
  createRoute,
224
347
  createRouter,
225
- notFound,
226
- redirect,
348
+ createRouteStaticData,
349
+ type ModernRouterContext,
350
+ modernLoaderToTanstack,
351
+ modernTanstackRouterFastDefaults,
227
352
  } from '@modern-js/plugin-tanstack/runtime';
228
353
 
229
- type ModernRouterContext = {
230
- request?: Request;
231
- requestContext?: unknown;
232
- };
233
-
234
- function isResponse(value: unknown): value is Response {
235
- return (
236
- value != null &&
237
- typeof value === 'object' &&
238
- typeof (value as any).status === 'number' &&
239
- typeof (value as any).headers === 'object'
240
- );
241
- }
242
-
243
- const redirectStatusCodes = new Set([301, 302, 303, 307, 308]);
244
- function isRedirectResponse(res: Response) {
245
- return redirectStatusCodes.has(res.status);
246
- }
247
-
248
- function throwTanstackRedirect(location: string) {
249
- const target = location || '/';
250
- try {
251
- void new URL(target);
252
- throw redirect({ href: target });
253
- } catch {
254
- throw redirect({ to: target });
255
- }
256
- }
257
-
258
- function mapParamsForModernLoader(params: Record<string, string>, hasSplat: boolean) {
259
- if (!hasSplat) {
260
- return params;
261
- }
262
-
263
- const { _splat, ...rest } = params as any;
264
- if (typeof _splat !== 'undefined') {
265
- return { ...rest, '*': _splat };
266
- }
267
- return rest;
268
- }
269
-
270
- function createRouteStaticData(opts: {
271
- modernRouteId?: string;
272
- modernRouteAction?: unknown;
273
- modernRouteLoader?: unknown;
274
- }) {
275
- const staticData: Record<string, unknown> = {};
276
-
277
- if (opts.modernRouteId) {
278
- staticData.modernRouteId = opts.modernRouteId;
279
- }
280
-
281
- if (opts.modernRouteLoader) {
282
- staticData.modernRouteLoader = opts.modernRouteLoader;
283
- }
284
-
285
- if (opts.modernRouteAction) {
286
- staticData.modernRouteAction = opts.modernRouteAction;
287
- }
288
-
289
- return Object.keys(staticData).length > 0 ? staticData : undefined;
290
- }
291
-
292
- function modernLoaderToTanstack<TLoader extends (args: any) => any>(
293
- opts: { hasSplat: boolean },
294
- modernLoader: TLoader,
295
- ) {
296
- type LoaderResult = Awaited<ReturnType<TLoader>>;
297
-
298
- return async (ctx: any): Promise<LoaderResult> => {
299
- try {
300
- const signal: AbortSignal =
301
- ctx?.abortController?.signal ||
302
- ctx?.signal ||
303
- new AbortController().signal;
304
- const baseRequest: Request | undefined =
305
- ctx?.context?.request instanceof Request ? ctx.context.request : undefined;
306
-
307
- const href =
308
- typeof ctx?.location === 'string'
309
- ? ctx.location
310
- : ctx?.location?.publicHref ||
311
- ctx?.location?.href ||
312
- ctx?.location?.url?.href ||
313
- '';
314
-
315
- const request = baseRequest
316
- ? new Request(baseRequest, { signal })
317
- : new Request(href, { signal });
318
-
319
- const params = mapParamsForModernLoader(ctx?.params || {}, opts.hasSplat);
320
-
321
- const result = await (modernLoader as any)({
322
- request,
323
- params,
324
- context: ctx?.context?.requestContext,
325
- });
326
-
327
- if (isResponse(result)) {
328
- if (isRedirectResponse(result)) {
329
- const location = result.headers.get('Location') || '/';
330
- throwTanstackRedirect(location);
331
- }
332
- if (result.status === 404) {
333
- throw notFound();
334
- }
335
- }
336
-
337
- return result as LoaderResult;
338
- } catch (err) {
339
- if (isResponse(err)) {
340
- if (isRedirectResponse(err)) {
341
- const location = err.headers.get('Location') || '/';
342
- throwTanstackRedirect(location);
343
- }
344
- if (err.status === 404) {
345
- throw notFound();
346
- }
347
- }
348
- throw err;
349
- }
350
- };
351
- }
352
-
353
354
  ${imports.join('\n')}
354
355
 
355
356
  export const rootRoute = createRootRouteWithContext<ModernRouterContext>()({
@@ -366,6 +367,7 @@ ${statements.join('\n\n')}
366
367
  export const routeTree = rootRoute.addChildren([${topLevelVars.join(', ')}]);
367
368
 
368
369
  export const router = createRouter({
370
+ ...modernTanstackRouterFastDefaults,
369
371
  routeTree,
370
372
  history: createMemoryHistory({
371
373
  initialEntries: ['/'],
@@ -377,11 +379,11 @@ export const router = createRouter({
377
379
  routerGenTs
378
380
  };
379
381
  }
382
+ exports.collectCanonicalRoutesForEntry = __webpack_exports__.collectCanonicalRoutesForEntry;
380
383
  exports.generateTanstackRouterTypesSourceForEntry = __webpack_exports__.generateTanstackRouterTypesSourceForEntry;
381
- exports.isTanstackRouterFrameworkEnabled = __webpack_exports__.isTanstackRouterFrameworkEnabled;
382
384
  for(var __rspack_i in __webpack_exports__)if (-1 === [
383
- "generateTanstackRouterTypesSourceForEntry",
384
- "isTanstackRouterFrameworkEnabled"
385
+ "collectCanonicalRoutesForEntry",
386
+ "generateTanstackRouterTypesSourceForEntry"
385
387
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
386
388
  Object.defineProperty(exports, '__esModule', {
387
389
  value: true
package/dist/cjs/cli.js CHANGED
@@ -24,11 +24,15 @@ function __webpack_require__(moduleId) {
24
24
  };
25
25
  })();
26
26
  (()=>{
27
- __webpack_require__.d = (exports1, definition)=>{
28
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
29
- enumerable: true,
30
- get: definition[key]
31
- });
27
+ __webpack_require__.d = (exports1, getters, values)=>{
28
+ var define = (defs, kind)=>{
29
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
30
+ enumerable: true,
31
+ [kind]: defs[key]
32
+ });
33
+ };
34
+ define(getters, "get");
35
+ define(values, "value");
32
36
  };
33
37
  })();
34
38
  (()=>{
@@ -47,14 +51,14 @@ function __webpack_require__(moduleId) {
47
51
  var __webpack_exports__ = {};
48
52
  (()=>{
49
53
  __webpack_require__.r(__webpack_exports__);
50
- __webpack_require__.d(__webpack_exports__, {
51
- default: ()=>_cli_index__rspack_import_0_default.a
52
- });
53
54
  var _cli_index__rspack_import_0 = __webpack_require__("./cli/index");
54
55
  var _cli_index__rspack_import_0_default = /*#__PURE__*/ __webpack_require__.n(_cli_index__rspack_import_0);
55
56
  var __rspack_reexport = {};
56
57
  for(const __rspack_import_key in _cli_index__rspack_import_0)if ("default" !== __rspack_import_key) __rspack_reexport[__rspack_import_key] = ()=>_cli_index__rspack_import_0[__rspack_import_key];
57
58
  __webpack_require__.d(__webpack_exports__, __rspack_reexport);
59
+ __webpack_require__.d(__webpack_exports__, {
60
+ default: ()=>_cli_index__rspack_import_0_default.a
61
+ });
58
62
  })();
59
63
  exports["default"] = __webpack_exports__["default"];
60
64
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
3
  (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
9
13
  };
10
14
  })();
11
15
  (()=>{
@@ -23,9 +27,6 @@ var __webpack_require__ = {};
23
27
  })();
24
28
  var __webpack_exports__ = {};
25
29
  __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- createModernBasepathRewrite: ()=>createModernBasepathRewrite
28
- });
29
30
  function normalizeBasepath(basepath) {
30
31
  if (!basepath) return '/';
31
32
  let normalized = basepath.startsWith('/') ? basepath : `/${basepath}`;
@@ -53,6 +54,9 @@ function createModernBasepathRewrite(basepath, caseSensitive = false) {
53
54
  }
54
55
  };
55
56
  }
57
+ __webpack_require__.d(__webpack_exports__, {
58
+ createModernBasepathRewrite: ()=>createModernBasepathRewrite
59
+ });
56
60
  exports.createModernBasepathRewrite = __webpack_exports__.createModernBasepathRewrite;
57
61
  for(var __rspack_i in __webpack_exports__)if (-1 === [
58
62
  "createModernBasepathRewrite"
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
3
  (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
9
13
  };
10
14
  })();
11
15
  (()=>{
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
  var __webpack_require__ = {};
3
3
  (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
4
+ __webpack_require__.d = (exports1, getters, values)=>{
5
+ var define = (defs, kind)=>{
6
+ for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
7
+ enumerable: true,
8
+ [kind]: defs[key]
9
+ });
10
+ };
11
+ define(getters, "get");
12
+ define(values, "value");
9
13
  };
10
14
  })();
11
15
  (()=>{
@@ -24,33 +28,30 @@ var __webpack_require__ = {};
24
28
  var __webpack_exports__ = {};
25
29
  __webpack_require__.r(__webpack_exports__);
26
30
  __webpack_require__.d(__webpack_exports__, {
27
- modifyRoutes: ()=>modifyRoutes,
28
- onAfterCreateRouter: ()=>onAfterCreateRouter,
29
- onAfterHydrateRouter: ()=>onAfterHydrateRouter,
30
- onBeforeCreateRouter: ()=>onBeforeCreateRouter,
31
- onBeforeCreateRoutes: ()=>onBeforeCreateRoutes,
32
- onBeforeHydrateRouter: ()=>onBeforeHydrateRouter
31
+ modifyRoutes: ()=>context_namespaceObject.modifyRoutes,
32
+ onAfterCreateRouter: ()=>context_namespaceObject.onAfterCreateRouter,
33
+ onAfterHydrateRouter: ()=>context_namespaceObject.onAfterHydrateRouter,
34
+ onBeforeCreateRouter: ()=>context_namespaceObject.onBeforeCreateRouter,
35
+ onBeforeCreateRoutes: ()=>context_namespaceObject.onBeforeCreateRoutes,
36
+ onBeforeHydrateRouter: ()=>context_namespaceObject.onBeforeHydrateRouter,
37
+ routerProviderRegistryHooks: ()=>context_namespaceObject.routerProviderRegistryHooks
33
38
  });
34
- const plugin_namespaceObject = require("@modern-js/plugin");
35
- const modifyRoutes = (0, plugin_namespaceObject.createSyncHook)();
36
- const onBeforeCreateRoutes = (0, plugin_namespaceObject.createSyncHook)();
37
- const onBeforeCreateRouter = (0, plugin_namespaceObject.createSyncHook)();
38
- const onAfterCreateRouter = (0, plugin_namespaceObject.createSyncHook)();
39
- const onBeforeHydrateRouter = (0, plugin_namespaceObject.createSyncHook)();
40
- const onAfterHydrateRouter = (0, plugin_namespaceObject.createSyncHook)();
39
+ const context_namespaceObject = require("@modern-js/runtime/context");
41
40
  exports.modifyRoutes = __webpack_exports__.modifyRoutes;
42
41
  exports.onAfterCreateRouter = __webpack_exports__.onAfterCreateRouter;
43
42
  exports.onAfterHydrateRouter = __webpack_exports__.onAfterHydrateRouter;
44
43
  exports.onBeforeCreateRouter = __webpack_exports__.onBeforeCreateRouter;
45
44
  exports.onBeforeCreateRoutes = __webpack_exports__.onBeforeCreateRoutes;
46
45
  exports.onBeforeHydrateRouter = __webpack_exports__.onBeforeHydrateRouter;
46
+ exports.routerProviderRegistryHooks = __webpack_exports__.routerProviderRegistryHooks;
47
47
  for(var __rspack_i in __webpack_exports__)if (-1 === [
48
48
  "modifyRoutes",
49
49
  "onAfterCreateRouter",
50
50
  "onAfterHydrateRouter",
51
51
  "onBeforeCreateRouter",
52
52
  "onBeforeCreateRoutes",
53
- "onBeforeHydrateRouter"
53
+ "onBeforeHydrateRouter",
54
+ "routerProviderRegistryHooks"
54
55
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
55
56
  Object.defineProperty(exports, '__esModule', {
56
57
  value: true