@octanejs/tanstack-start 0.1.0

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 (266) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +52 -0
  3. package/THIRD_PARTY_NOTICES.md +11 -0
  4. package/package.json +149 -0
  5. package/src/client-only.d.ts +1 -0
  6. package/src/client-only.js +0 -0
  7. package/src/client-rpc.d.ts +1 -0
  8. package/src/client-rpc.js +1 -0
  9. package/src/client.d.ts +3 -0
  10. package/src/client.js +2 -0
  11. package/src/default-entry/client.js +12 -0
  12. package/src/default-entry/server.js +13 -0
  13. package/src/default-entry/start.js +1 -0
  14. package/src/default-entry-paths.d.ts +5 -0
  15. package/src/default-entry-paths.js +11 -0
  16. package/src/index.d.ts +11 -0
  17. package/src/index.js +22 -0
  18. package/src/internal/README.md +15 -0
  19. package/src/internal/router-generator/config.d.ts +255 -0
  20. package/src/internal/router-generator/config.js +134 -0
  21. package/src/internal/router-generator/filesystem/physical/getRouteNodes.d.ts +53 -0
  22. package/src/internal/router-generator/filesystem/physical/getRouteNodes.js +335 -0
  23. package/src/internal/router-generator/filesystem/physical/rootPathId.d.ts +1 -0
  24. package/src/internal/router-generator/filesystem/physical/rootPathId.js +4 -0
  25. package/src/internal/router-generator/filesystem/virtual/config.d.ts +3 -0
  26. package/src/internal/router-generator/filesystem/virtual/config.js +36 -0
  27. package/src/internal/router-generator/filesystem/virtual/getRouteNodes.d.ts +31 -0
  28. package/src/internal/router-generator/filesystem/virtual/getRouteNodes.js +272 -0
  29. package/src/internal/router-generator/filesystem/virtual/loadConfigFile.d.ts +1 -0
  30. package/src/internal/router-generator/filesystem/virtual/loadConfigFile.js +10 -0
  31. package/src/internal/router-generator/generator.d.ts +119 -0
  32. package/src/internal/router-generator/generator.js +1080 -0
  33. package/src/internal/router-generator/index.d.ts +40 -0
  34. package/src/internal/router-generator/index.js +49 -0
  35. package/src/internal/router-generator/logger.d.ts +8 -0
  36. package/src/internal/router-generator/logger.js +30 -0
  37. package/src/internal/router-generator/plugin/types.d.ts +37 -0
  38. package/src/internal/router-generator/template.d.ts +38 -0
  39. package/src/internal/router-generator/template.js +220 -0
  40. package/src/internal/router-generator/transform/transform.d.ts +8 -0
  41. package/src/internal/router-generator/transform/transform.js +385 -0
  42. package/src/internal/router-generator/transform/types.d.ts +34 -0
  43. package/src/internal/router-generator/types.d.ts +73 -0
  44. package/src/internal/router-generator/utils.d.ts +270 -0
  45. package/src/internal/router-generator/utils.js +864 -0
  46. package/src/internal/router-generator/validate-route-params.d.ts +13 -0
  47. package/src/internal/router-generator/validate-route-params.js +75 -0
  48. package/src/internal/router-plugin/context.d.ts +2 -0
  49. package/src/internal/router-plugin/context.js +2 -0
  50. package/src/internal/router-plugin/core/code-splitter/compilers.d.ts +69 -0
  51. package/src/internal/router-plugin/core/code-splitter/compilers.js +1042 -0
  52. package/src/internal/router-plugin/core/code-splitter/framework-options.d.ts +11 -0
  53. package/src/internal/router-plugin/core/code-splitter/framework-options.js +41 -0
  54. package/src/internal/router-plugin/core/code-splitter/plugins/framework-plugins.d.ts +12 -0
  55. package/src/internal/router-plugin/core/code-splitter/plugins/framework-plugins.js +35 -0
  56. package/src/internal/router-plugin/core/code-splitter/plugins/octane-hmr-split-route-components.d.ts +5 -0
  57. package/src/internal/router-plugin/core/code-splitter/plugins/octane-hmr-split-route-components.js +106 -0
  58. package/src/internal/router-plugin/core/code-splitter/plugins/octane-split-route-components.d.ts +8 -0
  59. package/src/internal/router-plugin/core/code-splitter/plugins/octane-split-route-components.js +85 -0
  60. package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-ignored-route-exports.d.ts +2 -0
  61. package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-ignored-route-exports.js +55 -0
  62. package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-route-components.d.ts +2 -0
  63. package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-route-components.js +50 -0
  64. package/src/internal/router-plugin/core/code-splitter/plugins/react-stable-hmr-split-route-components.d.ts +5 -0
  65. package/src/internal/router-plugin/core/code-splitter/plugins/react-stable-hmr-split-route-components.js +54 -0
  66. package/src/internal/router-plugin/core/code-splitter/plugins.d.ts +62 -0
  67. package/src/internal/router-plugin/core/code-splitter/types.d.ts +9 -0
  68. package/src/internal/router-plugin/core/config.d.ts +294 -0
  69. package/src/internal/router-plugin/core/config.js +56 -0
  70. package/src/internal/router-plugin/core/constants.d.ts +12 -0
  71. package/src/internal/router-plugin/core/constants.js +13 -0
  72. package/src/internal/router-plugin/core/framework-plugin-order.d.ts +8 -0
  73. package/src/internal/router-plugin/core/framework-plugin-order.js +78 -0
  74. package/src/internal/router-plugin/core/hmr/handle-route-update.d.ts +1 -0
  75. package/src/internal/router-plugin/core/hmr/handle-route-update.js +126 -0
  76. package/src/internal/router-plugin/core/hmr/index.d.ts +5 -0
  77. package/src/internal/router-plugin/core/hmr/select-adapter.d.ts +17 -0
  78. package/src/internal/router-plugin/core/hmr/select-adapter.js +24 -0
  79. package/src/internal/router-plugin/core/hmr/vite-adapter.d.ts +18 -0
  80. package/src/internal/router-plugin/core/hmr/vite-adapter.js +73 -0
  81. package/src/internal/router-plugin/core/hmr/webpack-adapter.d.ts +22 -0
  82. package/src/internal/router-plugin/core/hmr/webpack-adapter.js +78 -0
  83. package/src/internal/router-plugin/core/router-code-splitter-plugin.d.ts +10 -0
  84. package/src/internal/router-plugin/core/router-code-splitter-plugin.js +244 -0
  85. package/src/internal/router-plugin/core/router-composed-plugin.d.ts +5 -0
  86. package/src/internal/router-plugin/core/router-composed-plugin.js +62 -0
  87. package/src/internal/router-plugin/core/router-generator-plugin.d.ts +10 -0
  88. package/src/internal/router-plugin/core/router-generator-plugin.js +125 -0
  89. package/src/internal/router-plugin/core/router-hmr-plugin.d.ts +13 -0
  90. package/src/internal/router-plugin/core/router-hmr-plugin.js +101 -0
  91. package/src/internal/router-plugin/core/router-plugin-context.d.ts +5 -0
  92. package/src/internal/router-plugin/core/router-plugin-context.js +6 -0
  93. package/src/internal/router-plugin/core/utils.d.ts +17 -0
  94. package/src/internal/router-plugin/core/utils.js +47 -0
  95. package/src/internal/router-plugin/esbuild.d.ts +197 -0
  96. package/src/internal/router-plugin/esbuild.js +58 -0
  97. package/src/internal/router-plugin/index.d.ts +19 -0
  98. package/src/internal/router-plugin/index.js +17 -0
  99. package/src/internal/router-plugin/rspack.d.ts +61 -0
  100. package/src/internal/router-plugin/rspack.js +92 -0
  101. package/src/internal/router-plugin/vite.d.ts +201 -0
  102. package/src/internal/router-plugin/vite.js +62 -0
  103. package/src/internal/router-plugin/webpack.d.ts +50 -0
  104. package/src/internal/router-plugin/webpack.js +77 -0
  105. package/src/internal/start-plugin-core/build-sitemap.d.ts +34 -0
  106. package/src/internal/start-plugin-core/build-sitemap.js +125 -0
  107. package/src/internal/start-plugin-core/config-context.d.ts +30 -0
  108. package/src/internal/start-plugin-core/config-context.js +89 -0
  109. package/src/internal/start-plugin-core/constants.d.ts +20 -0
  110. package/src/internal/start-plugin-core/constants.js +24 -0
  111. package/src/internal/start-plugin-core/debug.d.ts +1 -0
  112. package/src/internal/start-plugin-core/hydrate-when-transform.d.ts +5 -0
  113. package/src/internal/start-plugin-core/hydrate-when-transform.js +661 -0
  114. package/src/internal/start-plugin-core/hydration-constants.d.ts +1 -0
  115. package/src/internal/start-plugin-core/hydration-constants.js +4 -0
  116. package/src/internal/start-plugin-core/import-protection/adapterUtils.d.ts +40 -0
  117. package/src/internal/start-plugin-core/import-protection/adapterUtils.js +42 -0
  118. package/src/internal/start-plugin-core/import-protection/analysis.d.ts +63 -0
  119. package/src/internal/start-plugin-core/import-protection/analysis.js +533 -0
  120. package/src/internal/start-plugin-core/import-protection/constants.d.ts +11 -0
  121. package/src/internal/start-plugin-core/import-protection/constants.js +39 -0
  122. package/src/internal/start-plugin-core/import-protection/defaults.d.ts +19 -0
  123. package/src/internal/start-plugin-core/import-protection/defaults.js +34 -0
  124. package/src/internal/start-plugin-core/import-protection/extensionlessAbsoluteIdResolver.d.ts +22 -0
  125. package/src/internal/start-plugin-core/import-protection/extensionlessAbsoluteIdResolver.js +94 -0
  126. package/src/internal/start-plugin-core/import-protection/matchers.d.ts +18 -0
  127. package/src/internal/start-plugin-core/import-protection/matchers.js +39 -0
  128. package/src/internal/start-plugin-core/import-protection/rewrite.d.ts +29 -0
  129. package/src/internal/start-plugin-core/import-protection/rewrite.js +184 -0
  130. package/src/internal/start-plugin-core/import-protection/sourceLocation.d.ts +170 -0
  131. package/src/internal/start-plugin-core/import-protection/sourceLocation.js +376 -0
  132. package/src/internal/start-plugin-core/import-protection/trace.d.ts +89 -0
  133. package/src/internal/start-plugin-core/import-protection/trace.js +186 -0
  134. package/src/internal/start-plugin-core/import-protection/utils.d.ts +78 -0
  135. package/src/internal/start-plugin-core/import-protection/utils.js +171 -0
  136. package/src/internal/start-plugin-core/import-protection/virtualModules.d.ts +38 -0
  137. package/src/internal/start-plugin-core/import-protection/virtualModules.js +241 -0
  138. package/src/internal/start-plugin-core/index.d.ts +8 -0
  139. package/src/internal/start-plugin-core/index.js +2 -0
  140. package/src/internal/start-plugin-core/planning.d.ts +44 -0
  141. package/src/internal/start-plugin-core/planning.js +98 -0
  142. package/src/internal/start-plugin-core/post-build.d.ts +12 -0
  143. package/src/internal/start-plugin-core/post-build.js +40 -0
  144. package/src/internal/start-plugin-core/prerender.d.ts +17 -0
  145. package/src/internal/start-plugin-core/prerender.js +172 -0
  146. package/src/internal/start-plugin-core/queue.d.ts +37 -0
  147. package/src/internal/start-plugin-core/queue.js +118 -0
  148. package/src/internal/start-plugin-core/resolve-entries.d.ts +10 -0
  149. package/src/internal/start-plugin-core/resolve-entries.js +32 -0
  150. package/src/internal/start-plugin-core/schema.d.ts +1799 -0
  151. package/src/internal/start-plugin-core/schema.js +252 -0
  152. package/src/internal/start-plugin-core/serialization-adapters-module.d.ts +18 -0
  153. package/src/internal/start-plugin-core/serialization-adapters-module.js +37 -0
  154. package/src/internal/start-plugin-core/start-compiler/compiler.d.ts +181 -0
  155. package/src/internal/start-plugin-core/start-compiler/compiler.js +1078 -0
  156. package/src/internal/start-plugin-core/start-compiler/config.d.ts +20 -0
  157. package/src/internal/start-plugin-core/start-compiler/config.js +84 -0
  158. package/src/internal/start-plugin-core/start-compiler/handleClientOnlyJSX.d.ts +24 -0
  159. package/src/internal/start-plugin-core/start-compiler/handleClientOnlyJSX.js +25 -0
  160. package/src/internal/start-plugin-core/start-compiler/handleCreateIsomorphicFn.d.ts +11 -0
  161. package/src/internal/start-plugin-core/start-compiler/handleCreateIsomorphicFn.js +24 -0
  162. package/src/internal/start-plugin-core/start-compiler/handleCreateMiddleware.d.ts +11 -0
  163. package/src/internal/start-plugin-core/start-compiler/handleCreateMiddleware.js +35 -0
  164. package/src/internal/start-plugin-core/start-compiler/handleCreateServerFn.d.ts +22 -0
  165. package/src/internal/start-plugin-core/start-compiler/handleCreateServerFn.js +292 -0
  166. package/src/internal/start-plugin-core/start-compiler/handleEnvOnly.d.ts +14 -0
  167. package/src/internal/start-plugin-core/start-compiler/handleEnvOnly.js +41 -0
  168. package/src/internal/start-plugin-core/start-compiler/host.d.ts +44 -0
  169. package/src/internal/start-plugin-core/start-compiler/host.js +75 -0
  170. package/src/internal/start-plugin-core/start-compiler/server-fn-resolver-module.d.ts +10 -0
  171. package/src/internal/start-plugin-core/start-compiler/server-fn-resolver-module.js +87 -0
  172. package/src/internal/start-plugin-core/start-compiler/types.d.ts +119 -0
  173. package/src/internal/start-plugin-core/start-compiler/utils.d.ts +27 -0
  174. package/src/internal/start-plugin-core/start-compiler/utils.js +36 -0
  175. package/src/internal/start-plugin-core/start-manifest-plugin/inlineCss.d.ts +16 -0
  176. package/src/internal/start-plugin-core/start-manifest-plugin/inlineCss.js +131 -0
  177. package/src/internal/start-plugin-core/start-manifest-plugin/manifestBuilder.d.ts +64 -0
  178. package/src/internal/start-plugin-core/start-manifest-plugin/manifestBuilder.js +441 -0
  179. package/src/internal/start-plugin-core/start-router-plugin/constants.d.ts +1 -0
  180. package/src/internal/start-plugin-core/start-router-plugin/constants.js +4 -0
  181. package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/compose-generator-plugins.d.ts +6 -0
  182. package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/compose-generator-plugins.js +6 -0
  183. package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/prerender-routes-plugin.d.ts +6 -0
  184. package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/prerender-routes-plugin.js +27 -0
  185. package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/routes-manifest-plugin.d.ts +6 -0
  186. package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/routes-manifest-plugin.js +34 -0
  187. package/src/internal/start-plugin-core/start-router-plugin/pruneServerOnlySubtrees.d.ts +11 -0
  188. package/src/internal/start-plugin-core/start-router-plugin/pruneServerOnlySubtrees.js +42 -0
  189. package/src/internal/start-plugin-core/start-router-plugin/route-tree-footer.d.ts +6 -0
  190. package/src/internal/start-plugin-core/start-router-plugin/route-tree-footer.js +59 -0
  191. package/src/internal/start-plugin-core/types.d.ts +135 -0
  192. package/src/internal/start-plugin-core/types.js +4 -0
  193. package/src/internal/start-plugin-core/utils.d.ts +13 -0
  194. package/src/internal/start-plugin-core/utils.js +42 -0
  195. package/src/internal/start-plugin-core/vite/createVirtualModule.d.ts +15 -0
  196. package/src/internal/start-plugin-core/vite/createVirtualModule.js +27 -0
  197. package/src/internal/start-plugin-core/vite/dev-server-plugin/dev-styles.d.ts +26 -0
  198. package/src/internal/start-plugin-core/vite/dev-server-plugin/dev-styles.js +165 -0
  199. package/src/internal/start-plugin-core/vite/dev-server-plugin/plugin.d.ts +11 -0
  200. package/src/internal/start-plugin-core/vite/dev-server-plugin/plugin.js +170 -0
  201. package/src/internal/start-plugin-core/vite/import-protection-plugin/plugin.d.ts +4 -0
  202. package/src/internal/start-plugin-core/vite/import-protection-plugin/plugin.js +1553 -0
  203. package/src/internal/start-plugin-core/vite/import-protection-plugin/types.d.ts +103 -0
  204. package/src/internal/start-plugin-core/vite/import-protection-plugin/virtualModules.d.ts +40 -0
  205. package/src/internal/start-plugin-core/vite/import-protection-plugin/virtualModules.js +68 -0
  206. package/src/internal/start-plugin-core/vite/index.d.ts +13 -0
  207. package/src/internal/start-plugin-core/vite/index.js +4 -0
  208. package/src/internal/start-plugin-core/vite/load-env-plugin/plugin.d.ts +2 -0
  209. package/src/internal/start-plugin-core/vite/load-env-plugin/plugin.js +13 -0
  210. package/src/internal/start-plugin-core/vite/output-directory.d.ts +7 -0
  211. package/src/internal/start-plugin-core/vite/output-directory.js +18 -0
  212. package/src/internal/start-plugin-core/vite/planning.d.ts +112 -0
  213. package/src/internal/start-plugin-core/vite/planning.js +152 -0
  214. package/src/internal/start-plugin-core/vite/plugin.d.ts +7 -0
  215. package/src/internal/start-plugin-core/vite/plugin.js +208 -0
  216. package/src/internal/start-plugin-core/vite/plugins.d.ts +17 -0
  217. package/src/internal/start-plugin-core/vite/plugins.js +72 -0
  218. package/src/internal/start-plugin-core/vite/post-server-build.d.ts +9 -0
  219. package/src/internal/start-plugin-core/vite/post-server-build.js +22 -0
  220. package/src/internal/start-plugin-core/vite/prerender.d.ts +9 -0
  221. package/src/internal/start-plugin-core/vite/prerender.js +52 -0
  222. package/src/internal/start-plugin-core/vite/preview-server-plugin/plugin.d.ts +2 -0
  223. package/src/internal/start-plugin-core/vite/preview-server-plugin/plugin.js +54 -0
  224. package/src/internal/start-plugin-core/vite/schema.d.ts +2423 -0
  225. package/src/internal/start-plugin-core/vite/schema.js +17 -0
  226. package/src/internal/start-plugin-core/vite/serialization-adapters-plugin.d.ts +5 -0
  227. package/src/internal/start-plugin-core/vite/serialization-adapters-plugin.js +63 -0
  228. package/src/internal/start-plugin-core/vite/start-compiler-plugin/hot-update.d.ts +5 -0
  229. package/src/internal/start-plugin-core/vite/start-compiler-plugin/hot-update.js +14 -0
  230. package/src/internal/start-plugin-core/vite/start-compiler-plugin/module-specifier.d.ts +5 -0
  231. package/src/internal/start-plugin-core/vite/start-compiler-plugin/module-specifier.js +25 -0
  232. package/src/internal/start-plugin-core/vite/start-compiler-plugin/plugin.d.ts +29 -0
  233. package/src/internal/start-plugin-core/vite/start-compiler-plugin/plugin.js +380 -0
  234. package/src/internal/start-plugin-core/vite/start-manifest-plugin/normalized-client-build.d.ts +11 -0
  235. package/src/internal/start-plugin-core/vite/start-manifest-plugin/normalized-client-build.js +114 -0
  236. package/src/internal/start-plugin-core/vite/start-manifest-plugin/plugin.d.ts +3 -0
  237. package/src/internal/start-plugin-core/vite/start-manifest-plugin/plugin.js +103 -0
  238. package/src/internal/start-plugin-core/vite/start-router-plugin/plugin.d.ts +9 -0
  239. package/src/internal/start-plugin-core/vite/start-router-plugin/plugin.js +143 -0
  240. package/src/internal/start-plugin-core/vite/types.d.ts +17 -0
  241. package/src/package-names.js +10 -0
  242. package/src/plugin-vite.d.ts +23 -0
  243. package/src/plugin-vite.js +62 -0
  244. package/src/runtime/client/StartClient.d.ts +11 -0
  245. package/src/runtime/client/StartClient.js +16 -0
  246. package/src/runtime/client/hydrateStart.d.ts +4 -0
  247. package/src/runtime/client/hydrateStart.js +30 -0
  248. package/src/runtime/server/StartServer.d.ts +10 -0
  249. package/src/runtime/server/StartServer.js +6 -0
  250. package/src/runtime/server/defaultRenderHandler.d.ts +3 -0
  251. package/src/runtime/server/defaultRenderHandler.js +11 -0
  252. package/src/runtime/server/defaultStreamHandler.d.ts +3 -0
  253. package/src/runtime/server/defaultStreamHandler.js +13 -0
  254. package/src/server-entry.d.ts +11 -0
  255. package/src/server-entry.js +13 -0
  256. package/src/server-only.d.ts +1 -0
  257. package/src/server-only.js +0 -0
  258. package/src/server-rpc.d.ts +1 -0
  259. package/src/server-rpc.js +1 -0
  260. package/src/server.d.ts +6 -0
  261. package/src/server.js +4 -0
  262. package/src/ssr-rpc.d.ts +1 -0
  263. package/src/ssr-rpc.js +1 -0
  264. package/src/use-server-fn.d.ts +3 -0
  265. package/src/use-server-fn.js +18 -0
  266. package/src/validate-options.js +7 -0
@@ -0,0 +1,39 @@
1
+ import { SERVER_FN_LOOKUP } from '../constants.js';
2
+ //#region src/import-protection/constants.ts
3
+ var SERVER_FN_LOOKUP_QUERY = `?${SERVER_FN_LOOKUP}`;
4
+ var MOCK_MODULE_ID = 'tanstack-start-import-protection:mock';
5
+ var MOCK_BUILD_PREFIX = 'tanstack-start-import-protection:mock:build:';
6
+ var MOCK_EDGE_PREFIX = 'tanstack-start-import-protection:mock-edge:';
7
+ var MOCK_RUNTIME_PREFIX = 'tanstack-start-import-protection:mock-runtime:';
8
+ var MARKER_PREFIX = 'tanstack-start-import-protection:marker:';
9
+ var IMPORT_PROTECTION_DEBUG =
10
+ process.env.TSR_IMPORT_PROTECTION_DEBUG === '1' ||
11
+ process.env.TSR_IMPORT_PROTECTION_DEBUG === 'true';
12
+ var IMPORT_PROTECTION_DEBUG_FILTER = process.env.TSR_IMPORT_PROTECTION_DEBUG_FILTER;
13
+ var KNOWN_SOURCE_EXTENSIONS = new Set([
14
+ '.ts',
15
+ '.tsx',
16
+ '.tsrx',
17
+ '.mts',
18
+ '.cts',
19
+ '.js',
20
+ '.jsx',
21
+ '.mjs',
22
+ '.cjs',
23
+ '.json',
24
+ ]);
25
+ /** Vite's browser-visible prefix for virtual modules (replaces `\0`). */
26
+ var VITE_BROWSER_VIRTUAL_PREFIX = '/@id/__x00__';
27
+ //#endregion
28
+ export {
29
+ IMPORT_PROTECTION_DEBUG,
30
+ IMPORT_PROTECTION_DEBUG_FILTER,
31
+ KNOWN_SOURCE_EXTENSIONS,
32
+ MARKER_PREFIX,
33
+ MOCK_BUILD_PREFIX,
34
+ MOCK_EDGE_PREFIX,
35
+ MOCK_MODULE_ID,
36
+ MOCK_RUNTIME_PREFIX,
37
+ SERVER_FN_LOOKUP_QUERY,
38
+ VITE_BROWSER_VIRTUAL_PREFIX,
39
+ };
@@ -0,0 +1,19 @@
1
+ import { ImportProtectionEnvRules } from '../schema.js';
2
+ export interface DefaultImportProtectionRules {
3
+ client: Required<ImportProtectionEnvRules>;
4
+ server: Required<ImportProtectionEnvRules>;
5
+ }
6
+ /**
7
+ * Returns the default import protection rules.
8
+ *
9
+ * All framework variants are always included so that, e.g., a React
10
+ * project also denies `@tanstack/solid-start/server` imports.
11
+ */
12
+ export declare function getDefaultImportProtectionRules(): DefaultImportProtectionRules;
13
+ /**
14
+ * Marker module specifiers that restrict a file to a specific environment.
15
+ */
16
+ export declare function getMarkerSpecifiers(): {
17
+ serverOnly: Array<string>;
18
+ clientOnly: Array<string>;
19
+ };
@@ -0,0 +1,34 @@
1
+ import { startFrameworks } from '../types.js';
2
+ import { getStartPackage } from '#tanstack-start/package-names';
3
+ //#region src/import-protection/defaults.ts
4
+ /**
5
+ * Returns the default import protection rules.
6
+ *
7
+ * All framework variants are always included so that, e.g., a React
8
+ * project also denies `@tanstack/solid-start/server` imports.
9
+ */
10
+ function getDefaultImportProtectionRules() {
11
+ return {
12
+ client: {
13
+ specifiers: startFrameworks.map((fw) => `${getStartPackage(fw)}/server`),
14
+ files: ['**/*.server.*'],
15
+ excludeFiles: ['**/node_modules/**'],
16
+ },
17
+ server: {
18
+ specifiers: [],
19
+ files: ['**/*.client.*'],
20
+ excludeFiles: ['**/node_modules/**'],
21
+ },
22
+ };
23
+ }
24
+ /**
25
+ * Marker module specifiers that restrict a file to a specific environment.
26
+ */
27
+ function getMarkerSpecifiers() {
28
+ return {
29
+ serverOnly: startFrameworks.map((fw) => `${getStartPackage(fw)}/server-only`),
30
+ clientOnly: startFrameworks.map((fw) => `${getStartPackage(fw)}/client-only`),
31
+ };
32
+ }
33
+ //#endregion
34
+ export { getDefaultImportProtectionRules, getMarkerSpecifiers };
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Canonicalize extensionless absolute IDs like `/src/foo.server` to the
3
+ * physical file when possible.
4
+ *
5
+ * Keeps a small cache plus a reverse index so we can invalidate on HMR
6
+ * updates without clearing the whole map.
7
+ */
8
+ export declare class ExtensionlessAbsoluteIdResolver {
9
+ private entries;
10
+ private keysByDep;
11
+ clear(): void;
12
+ /**
13
+ * Invalidate any cached entries that might be affected by changes to `id`.
14
+ * We invalidate both the file and its containing directory.
15
+ */
16
+ invalidateByFile(id: string): void;
17
+ resolve(id: string): string;
18
+ private invalidateDep;
19
+ private buildDepsForKey;
20
+ private indexDeps;
21
+ private deleteKey;
22
+ }
@@ -0,0 +1,94 @@
1
+ import { KNOWN_SOURCE_EXTENSIONS } from './constants.js';
2
+ import { normalizeFilePath } from './utils.js';
3
+ import { basename, dirname, extname, isAbsolute } from 'node:path';
4
+ import { resolveModulePath } from 'exsolve';
5
+ //#region src/import-protection/extensionlessAbsoluteIdResolver.ts
6
+ var FILE_RESOLUTION_EXTENSIONS = [...KNOWN_SOURCE_EXTENSIONS];
7
+ /**
8
+ * Canonicalize extensionless absolute IDs like `/src/foo.server` to the
9
+ * physical file when possible.
10
+ *
11
+ * Keeps a small cache plus a reverse index so we can invalidate on HMR
12
+ * updates without clearing the whole map.
13
+ */
14
+ var ExtensionlessAbsoluteIdResolver = class {
15
+ entries = /* @__PURE__ */ new Map();
16
+ keysByDep = /* @__PURE__ */ new Map();
17
+ clear() {
18
+ this.entries.clear();
19
+ this.keysByDep.clear();
20
+ }
21
+ /**
22
+ * Invalidate any cached entries that might be affected by changes to `id`.
23
+ * We invalidate both the file and its containing directory.
24
+ */
25
+ invalidateByFile(id) {
26
+ const file = normalizeFilePath(id);
27
+ this.invalidateDep(`file:${file}`);
28
+ if (isAbsolute(file)) this.invalidateDep(`dir:${dirname(file)}`);
29
+ }
30
+ resolve(id) {
31
+ const key = normalizeFilePath(id);
32
+ const cached = this.entries.get(key);
33
+ if (cached) return cached.value;
34
+ let result = key;
35
+ let resolvedPhysical;
36
+ if (isAbsolute(key)) {
37
+ const ext = extname(key);
38
+ if (!FILE_RESOLUTION_EXTENSIONS.includes(ext)) {
39
+ const resolved = resolveModulePath(`./${basename(key)}`, {
40
+ from: dirname(key),
41
+ extensions: FILE_RESOLUTION_EXTENSIONS,
42
+ try: true,
43
+ });
44
+ if (resolved) {
45
+ resolvedPhysical = resolved;
46
+ result = normalizeFilePath(resolved);
47
+ }
48
+ }
49
+ }
50
+ const resolvedFile = resolvedPhysical ? normalizeFilePath(resolvedPhysical) : void 0;
51
+ const deps = this.buildDepsForKey(key, resolvedFile);
52
+ this.entries.set(key, {
53
+ value: result,
54
+ deps,
55
+ });
56
+ this.indexDeps(key, deps);
57
+ return result;
58
+ }
59
+ invalidateDep(dep) {
60
+ const keys = this.keysByDep.get(dep);
61
+ if (!keys) return;
62
+ for (const key of Array.from(keys)) this.deleteKey(key);
63
+ }
64
+ buildDepsForKey(key, resolvedFile) {
65
+ const deps = /* @__PURE__ */ new Set();
66
+ deps.add(`file:${key}`);
67
+ if (isAbsolute(key)) deps.add(`dir:${dirname(key)}`);
68
+ if (resolvedFile) deps.add(`file:${resolvedFile}`);
69
+ return deps;
70
+ }
71
+ indexDeps(key, deps) {
72
+ for (const dep of deps) {
73
+ let keys = this.keysByDep.get(dep);
74
+ if (!keys) {
75
+ keys = /* @__PURE__ */ new Set();
76
+ this.keysByDep.set(dep, keys);
77
+ }
78
+ keys.add(key);
79
+ }
80
+ }
81
+ deleteKey(key) {
82
+ const entry = this.entries.get(key);
83
+ this.entries.delete(key);
84
+ if (!entry) return;
85
+ for (const dep of entry.deps) {
86
+ const keys = this.keysByDep.get(dep);
87
+ if (!keys) continue;
88
+ keys.delete(key);
89
+ if (keys.size === 0) this.keysByDep.delete(dep);
90
+ }
91
+ }
92
+ };
93
+ //#endregion
94
+ export { ExtensionlessAbsoluteIdResolver };
@@ -0,0 +1,18 @@
1
+ import { Pattern } from './utils.js';
2
+ export interface CompiledMatcher {
3
+ pattern: Pattern;
4
+ literal?: string;
5
+ test: (value: string) => boolean;
6
+ }
7
+ export declare function isLiteralMatcherPattern(pattern: string): boolean;
8
+ /**
9
+ * Compile a Pattern (string glob or RegExp) into a fast test function.
10
+ * String patterns use picomatch for full glob support (**, *, ?, braces, etc.).
11
+ * RegExp patterns are used as-is.
12
+ */
13
+ export declare function compileMatcher(pattern: Pattern): CompiledMatcher;
14
+ export declare function compileMatchers(patterns: Array<Pattern>): Array<CompiledMatcher>;
15
+ export declare function matchesAny(
16
+ value: string,
17
+ matchers: Array<CompiledMatcher>,
18
+ ): CompiledMatcher | undefined;
@@ -0,0 +1,39 @@
1
+ import picomatch from 'picomatch';
2
+ //#region src/import-protection/matchers.ts
3
+ var globLikePatternRE = /[*?![\]{}()]/;
4
+ function isLiteralMatcherPattern(pattern) {
5
+ return !globLikePatternRE.test(pattern);
6
+ }
7
+ /**
8
+ * Compile a Pattern (string glob or RegExp) into a fast test function.
9
+ * String patterns use picomatch for full glob support (**, *, ?, braces, etc.).
10
+ * RegExp patterns are used as-is.
11
+ */
12
+ function compileMatcher(pattern) {
13
+ if (pattern instanceof RegExp)
14
+ return {
15
+ pattern,
16
+ test: (value) => {
17
+ pattern.lastIndex = 0;
18
+ return pattern.test(value);
19
+ },
20
+ };
21
+ if (isLiteralMatcherPattern(pattern))
22
+ return {
23
+ pattern,
24
+ literal: pattern,
25
+ test: (value) => value === pattern,
26
+ };
27
+ return {
28
+ pattern,
29
+ test: picomatch(pattern, { dot: true }),
30
+ };
31
+ }
32
+ function compileMatchers(patterns) {
33
+ return patterns.map(compileMatcher);
34
+ }
35
+ function matchesAny(value, matchers) {
36
+ for (const matcher of matchers) if (matcher.test(value)) return matcher;
37
+ }
38
+ //#endregion
39
+ export { compileMatchers, matchesAny };
@@ -0,0 +1,29 @@
1
+ import { SourceMapLike } from './sourceLocation.js';
2
+ /**
3
+ * Rewrite static imports/re-exports from denied sources using Babel AST transforms.
4
+ *
5
+ * Transforms:
6
+ * import { a as b, c } from 'denied'
7
+ * Into:
8
+ * import __tss_deny_0 from 'tanstack-start-import-protection:mock'
9
+ * const b = __tss_deny_0.a
10
+ * const c = __tss_deny_0.c
11
+ *
12
+ * Also handles:
13
+ * import def from 'denied' -> import def from mock
14
+ * import * as ns from 'denied' -> import ns from mock
15
+ * export { x } from 'denied' -> export const x = mock.x
16
+ * export * from 'denied' -> removed
17
+ * export { x as y } from 'denied' -> export const y = mock.x
18
+ */
19
+ export declare function rewriteDeniedImports(
20
+ code: string,
21
+ id: string,
22
+ deniedSources: Set<string>,
23
+ getMockModuleId?: (source: string) => string,
24
+ ):
25
+ | {
26
+ code: string;
27
+ map?: SourceMapLike;
28
+ }
29
+ | undefined;
@@ -0,0 +1,184 @@
1
+ import { MOCK_MODULE_ID } from './constants.js';
2
+ import * as t from '@babel/types';
3
+ import { generateFromAst, parseAst } from '@tanstack/router-utils';
4
+ //#region src/import-protection/rewrite.ts
5
+ function getModuleExportName(node) {
6
+ return t.isIdentifier(node) ? node.name : node.value;
7
+ }
8
+ function toMemberExpressionProperty(name) {
9
+ return t.isValidIdentifier(name)
10
+ ? {
11
+ property: t.identifier(name),
12
+ computed: false,
13
+ }
14
+ : {
15
+ property: t.stringLiteral(name),
16
+ computed: true,
17
+ };
18
+ }
19
+ function toModuleExportNameNode(name) {
20
+ return t.isValidIdentifier(name) ? t.identifier(name) : t.stringLiteral(name);
21
+ }
22
+ function createInternalReexportVarName(localName, mockIndex, usedNames) {
23
+ const baseName = t.isValidIdentifier(localName)
24
+ ? `__tss_reexport_${localName}`
25
+ : `__tss_reexport_${mockIndex}`;
26
+ let candidate = baseName;
27
+ let suffix = 0;
28
+ while (usedNames.has(candidate)) {
29
+ suffix++;
30
+ candidate = `${baseName}_${suffix}`;
31
+ }
32
+ usedNames.add(candidate);
33
+ return candidate;
34
+ }
35
+ /**
36
+ * Rewrite static imports/re-exports from denied sources using Babel AST transforms.
37
+ *
38
+ * Transforms:
39
+ * import { a as b, c } from 'denied'
40
+ * Into:
41
+ * import __tss_deny_0 from 'tanstack-start-import-protection:mock'
42
+ * const b = __tss_deny_0.a
43
+ * const c = __tss_deny_0.c
44
+ *
45
+ * Also handles:
46
+ * import def from 'denied' -> import def from mock
47
+ * import * as ns from 'denied' -> import ns from mock
48
+ * export { x } from 'denied' -> export const x = mock.x
49
+ * export * from 'denied' -> removed
50
+ * export { x as y } from 'denied' -> export const y = mock.x
51
+ */
52
+ function rewriteDeniedImports(code, id, deniedSources, getMockModuleId = () => MOCK_MODULE_ID) {
53
+ return rewriteDeniedImportsFromAst(
54
+ parseAst({
55
+ code,
56
+ filename: id,
57
+ }),
58
+ id,
59
+ deniedSources,
60
+ getMockModuleId,
61
+ );
62
+ }
63
+ function rewriteDeniedImportsFromAst(
64
+ ast,
65
+ id,
66
+ deniedSources,
67
+ getMockModuleId = () => MOCK_MODULE_ID,
68
+ ) {
69
+ let modified = false;
70
+ let mockCounter = 0;
71
+ for (let i = ast.program.body.length - 1; i >= 0; i--) {
72
+ const node = ast.program.body[i];
73
+ if (t.isImportDeclaration(node)) {
74
+ if (node.importKind === 'type') continue;
75
+ if (!deniedSources.has(node.source.value)) continue;
76
+ const mockVar = `__tss_deny_${mockCounter++}`;
77
+ const replacements = [];
78
+ replacements.push(
79
+ t.importDeclaration(
80
+ [t.importDefaultSpecifier(t.identifier(mockVar))],
81
+ t.stringLiteral(getMockModuleId(node.source.value)),
82
+ ),
83
+ );
84
+ for (const specifier of node.specifiers)
85
+ if (t.isImportDefaultSpecifier(specifier) || t.isImportNamespaceSpecifier(specifier))
86
+ replacements.push(
87
+ t.variableDeclaration('const', [
88
+ t.variableDeclarator(t.identifier(specifier.local.name), t.identifier(mockVar)),
89
+ ]),
90
+ );
91
+ else if (t.isImportSpecifier(specifier)) {
92
+ if (specifier.importKind === 'type') continue;
93
+ const memberProperty = toMemberExpressionProperty(
94
+ getModuleExportName(specifier.imported),
95
+ );
96
+ replacements.push(
97
+ t.variableDeclaration('const', [
98
+ t.variableDeclarator(
99
+ t.identifier(specifier.local.name),
100
+ t.memberExpression(
101
+ t.identifier(mockVar),
102
+ memberProperty.property,
103
+ memberProperty.computed,
104
+ ),
105
+ ),
106
+ ]),
107
+ );
108
+ }
109
+ ast.program.body.splice(i, 1, ...replacements);
110
+ modified = true;
111
+ continue;
112
+ }
113
+ if (t.isExportNamedDeclaration(node) && node.source) {
114
+ if (node.exportKind === 'type') continue;
115
+ if (!deniedSources.has(node.source.value)) continue;
116
+ const mockIndex = mockCounter++;
117
+ const mockVar = `__tss_deny_${mockIndex}`;
118
+ const replacements = [];
119
+ replacements.push(
120
+ t.importDeclaration(
121
+ [t.importDefaultSpecifier(t.identifier(mockVar))],
122
+ t.stringLiteral(getMockModuleId(node.source.value)),
123
+ ),
124
+ );
125
+ const usedInternalVars = /* @__PURE__ */ new Set();
126
+ const exportSpecifiers = [];
127
+ for (const specifier of node.specifiers)
128
+ if (t.isExportSpecifier(specifier)) {
129
+ if (specifier.exportKind === 'type') continue;
130
+ const localName = getModuleExportName(specifier.local);
131
+ const exportedName = getModuleExportName(specifier.exported);
132
+ const memberProperty = toMemberExpressionProperty(localName);
133
+ const internalVar = createInternalReexportVarName(localName, mockIndex, usedInternalVars);
134
+ replacements.push(
135
+ t.variableDeclaration('const', [
136
+ t.variableDeclarator(
137
+ t.identifier(internalVar),
138
+ t.memberExpression(
139
+ t.identifier(mockVar),
140
+ memberProperty.property,
141
+ memberProperty.computed,
142
+ ),
143
+ ),
144
+ ]),
145
+ );
146
+ exportSpecifiers.push({
147
+ localName: internalVar,
148
+ exportedName,
149
+ });
150
+ }
151
+ if (exportSpecifiers.length > 0)
152
+ replacements.push(
153
+ t.exportNamedDeclaration(
154
+ null,
155
+ exportSpecifiers.map((s) =>
156
+ t.exportSpecifier(t.identifier(s.localName), toModuleExportNameNode(s.exportedName)),
157
+ ),
158
+ ),
159
+ );
160
+ ast.program.body.splice(i, 1, ...replacements);
161
+ modified = true;
162
+ continue;
163
+ }
164
+ if (t.isExportAllDeclaration(node)) {
165
+ if (node.exportKind === 'type') continue;
166
+ if (!deniedSources.has(node.source.value)) continue;
167
+ ast.program.body.splice(i, 1);
168
+ modified = true;
169
+ continue;
170
+ }
171
+ }
172
+ if (!modified) return void 0;
173
+ const result = generateFromAst(ast, {
174
+ sourceMaps: true,
175
+ sourceFileName: id,
176
+ filename: id,
177
+ });
178
+ return {
179
+ code: result.code,
180
+ ...(result.map ? { map: result.map } : {}),
181
+ };
182
+ }
183
+ //#endregion
184
+ export { rewriteDeniedImports };
@@ -0,0 +1,170 @@
1
+ import { ImportAnalysis } from './analysis.js';
2
+ import { Loc } from './trace.js';
3
+ import { ParseAstResult } from '@tanstack/router-utils';
4
+ /**
5
+ * Minimal source-map shape used throughout the import-protection plugin.
6
+ */
7
+ export interface SourceMapLike {
8
+ file?: string;
9
+ sourceRoot?: string;
10
+ version: number | string;
11
+ sources: Array<string>;
12
+ names: Array<string>;
13
+ sourcesContent?: Array<string | null>;
14
+ mappings: string;
15
+ }
16
+ export interface ImportProtectionPerfRecorder {
17
+ count: (name: string, value?: number) => void;
18
+ time: (name: string, startedAt: number) => void;
19
+ }
20
+ export interface TransformResult {
21
+ code: string;
22
+ filename?: string;
23
+ map: SourceMapLike | undefined;
24
+ originalCode: string | undefined;
25
+ originalResult?: TransformResult;
26
+ /** Precomputed line index for `code` (index → line/col). */
27
+ lineIndex?: LineIndex;
28
+ parsedAst?: ParseAstResult;
29
+ analysis?: ImportAnalysis;
30
+ perf?: ImportProtectionPerfRecorder;
31
+ }
32
+ /**
33
+ * Provides the transformed code and composed sourcemap for a module.
34
+ *
35
+ * Populated from a late-running transform hook. By the time `resolveId`
36
+ * fires for an import, the importer has already been fully transformed.
37
+ */
38
+ export interface TransformResultProvider {
39
+ getTransformResult: (id: string) => TransformResult | undefined;
40
+ }
41
+ export interface ImportSpecifierLocationIndex {
42
+ find: FindImportSpecifierLocationIndex;
43
+ }
44
+ export type LineIndex = {
45
+ offsets: Array<number>;
46
+ };
47
+ export declare function buildLineIndex(code: string): LineIndex;
48
+ export declare function indexToLineColumn(
49
+ lineIndex: LineIndex,
50
+ idx: number,
51
+ ): {
52
+ line: number;
53
+ column: number;
54
+ };
55
+ export declare function normalizeSourceMap(map: SourceMapLike | null | undefined):
56
+ | {
57
+ version: number;
58
+ file: string;
59
+ sourceRoot?: string;
60
+ sources: Array<string>;
61
+ names: Array<string>;
62
+ sourcesContent?: Array<string>;
63
+ mappings: string;
64
+ }
65
+ | undefined;
66
+ /**
67
+ * Pick the most-likely original source text for `importerFile` from
68
+ * a sourcemap that may contain multiple sources.
69
+ */
70
+ export declare function pickOriginalCodeFromSourcesContent(
71
+ map: SourceMapLike | undefined,
72
+ importerFile: string,
73
+ root: string,
74
+ ): string | undefined;
75
+ export type ImportLocEntry = {
76
+ file?: string;
77
+ line: number;
78
+ column: number;
79
+ };
80
+ /**
81
+ * Cache for import statement locations with reverse index for O(1)
82
+ * invalidation by file. Keys: `${importerFile}::${source}`.
83
+ */
84
+ export declare class ImportLocCache {
85
+ private cache;
86
+ private reverseIndex;
87
+ has(key: string): boolean;
88
+ get(key: string): ImportLocEntry | null | undefined;
89
+ set(key: string, value: ImportLocEntry | null): void;
90
+ clear(): void;
91
+ /** Remove all cache entries where the importer matches `file`. */
92
+ deleteByFile(file: string): void;
93
+ }
94
+ export type FindImportSpecifierLocationIndex = (result: TransformResult, source: string) => number;
95
+ export declare function getOrCreateOriginalTransformResult(
96
+ result: TransformResult,
97
+ importerFile?: string,
98
+ root?: string,
99
+ ): TransformResult | undefined;
100
+ export declare function createImportSpecifierLocationIndex(): ImportSpecifierLocationIndex;
101
+ /**
102
+ * Find the location of an import statement in a transformed module
103
+ * by searching the post-transform code and mapping back via sourcemap.
104
+ * Results are cached in `importLocCache`.
105
+ */
106
+ export declare function findImportStatementLocationFromTransformed(
107
+ provider: TransformResultProvider,
108
+ importerId: string,
109
+ source: string,
110
+ importLocCache: ImportLocCache,
111
+ findImportSpecifierLocationIndex: FindImportSpecifierLocationIndex,
112
+ ): Promise<Loc | undefined>;
113
+ /**
114
+ * Find the first post-compile usage location for a denied import specifier.
115
+ * Best-effort: searches transformed code for non-import uses of imported
116
+ * bindings and maps back to original source via sourcemap.
117
+ */
118
+ export declare function findPostCompileUsageLocation(
119
+ provider: TransformResultProvider,
120
+ importerId: string,
121
+ source: string,
122
+ ): Promise<Loc | undefined>;
123
+ /**
124
+ * Best-effort original-source usage lookup for cases where a later transform
125
+ * removes or rewrites the import from emitted code but preserves the original
126
+ * source in `sourcesContent`.
127
+ */
128
+ export declare function findOriginalUsageLocation(
129
+ provider: TransformResultProvider,
130
+ importerId: string,
131
+ source: string,
132
+ envType?: 'client' | 'server',
133
+ root?: string,
134
+ ): Loc | undefined;
135
+ /**
136
+ * Annotate each trace hop with the location of the import that created the
137
+ * edge (file:line:col). Skips steps that already have a location.
138
+ */
139
+ export declare function addTraceImportLocations(
140
+ provider: TransformResultProvider,
141
+ trace: Array<{
142
+ file: string;
143
+ specifier?: string;
144
+ line?: number;
145
+ column?: number;
146
+ }>,
147
+ importLocCache: ImportLocCache,
148
+ findImportSpecifierLocationIndex: FindImportSpecifierLocationIndex,
149
+ ): Promise<void>;
150
+ export interface CodeSnippet {
151
+ /** Source lines with line numbers, e.g. `[" 6 | import { getSecret } from './secret.server'", ...]` */
152
+ lines: Array<string>;
153
+ /** The highlighted line (1-indexed original line number) */
154
+ highlightLine: number;
155
+ /** Clickable file:line reference */
156
+ location: string;
157
+ }
158
+ /**
159
+ * Build a vitest-style code snippet showing lines surrounding a location.
160
+ *
161
+ * Prefers `originalCode` from the sourcemap's sourcesContent; falls back
162
+ * to transformed code when unavailable.
163
+ */
164
+ export declare function buildCodeSnippet(
165
+ provider: TransformResultProvider,
166
+ moduleId: string,
167
+ loc: Loc,
168
+ contextLines?: number,
169
+ root?: string,
170
+ ): CodeSnippet | undefined;