@tanstack/start-plugin-core 1.132.0-alpha.9 → 1.132.1

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 (78) hide show
  1. package/dist/esm/constants.d.ts +2 -1
  2. package/dist/esm/constants.js +3 -2
  3. package/dist/esm/constants.js.map +1 -1
  4. package/dist/esm/create-server-fn-plugin/compiler.d.ts +8 -5
  5. package/dist/esm/create-server-fn-plugin/compiler.js +74 -46
  6. package/dist/esm/create-server-fn-plugin/compiler.js.map +1 -1
  7. package/dist/esm/create-server-fn-plugin/handleCreateMiddleware.d.ts +5 -0
  8. package/dist/esm/{start-compiler-plugin/middleware.js → create-server-fn-plugin/handleCreateMiddleware.js} +11 -11
  9. package/dist/esm/create-server-fn-plugin/handleCreateMiddleware.js.map +1 -0
  10. package/dist/esm/create-server-fn-plugin/handleCreateServerFn.js +8 -8
  11. package/dist/esm/create-server-fn-plugin/handleCreateServerFn.js.map +1 -1
  12. package/dist/esm/create-server-fn-plugin/plugin.d.ts +1 -1
  13. package/dist/esm/create-server-fn-plugin/plugin.js +22 -7
  14. package/dist/esm/create-server-fn-plugin/plugin.js.map +1 -1
  15. package/dist/esm/dev-server-plugin/plugin.d.ts +4 -2
  16. package/dist/esm/dev-server-plugin/plugin.js +6 -2
  17. package/dist/esm/dev-server-plugin/plugin.js.map +1 -1
  18. package/dist/esm/plugin.d.ts +12 -6
  19. package/dist/esm/plugin.js +54 -65
  20. package/dist/esm/plugin.js.map +1 -1
  21. package/dist/esm/resolve-entries.d.ts +0 -1
  22. package/dist/esm/resolve-entries.js +1 -1
  23. package/dist/esm/resolve-entries.js.map +1 -1
  24. package/dist/esm/schema.d.ts +375 -308
  25. package/dist/esm/schema.js +23 -11
  26. package/dist/esm/schema.js.map +1 -1
  27. package/dist/esm/start-compiler-plugin/compilers.js +17 -49
  28. package/dist/esm/start-compiler-plugin/compilers.js.map +1 -1
  29. package/dist/esm/start-compiler-plugin/constants.d.ts +1 -1
  30. package/dist/esm/start-compiler-plugin/constants.js +1 -5
  31. package/dist/esm/start-compiler-plugin/constants.js.map +1 -1
  32. package/dist/esm/start-router-plugin/constants.d.ts +1 -0
  33. package/dist/esm/start-router-plugin/constants.js +5 -0
  34. package/dist/esm/start-router-plugin/constants.js.map +1 -0
  35. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js +3 -9
  36. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js.map +1 -1
  37. package/dist/esm/start-router-plugin/plugin.d.ts +3 -2
  38. package/dist/esm/start-router-plugin/plugin.js +191 -31
  39. package/dist/esm/start-router-plugin/plugin.js.map +1 -1
  40. package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.d.ts +8 -0
  41. package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.js +34 -0
  42. package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.js.map +1 -0
  43. package/package.json +8 -8
  44. package/src/constants.ts +3 -2
  45. package/src/create-server-fn-plugin/compiler.ts +99 -57
  46. package/src/{start-compiler-plugin/middleware.ts → create-server-fn-plugin/handleCreateMiddleware.ts} +15 -12
  47. package/src/create-server-fn-plugin/handleCreateServerFn.ts +11 -8
  48. package/src/create-server-fn-plugin/plugin.ts +24 -9
  49. package/src/dev-server-plugin/plugin.ts +6 -3
  50. package/src/plugin.ts +76 -84
  51. package/src/resolve-entries.ts +1 -2
  52. package/src/schema.ts +31 -14
  53. package/src/start-compiler-plugin/compilers.ts +18 -51
  54. package/src/start-compiler-plugin/constants.ts +0 -4
  55. package/src/start-router-plugin/constants.ts +1 -0
  56. package/src/start-router-plugin/generator-plugins/routes-manifest-plugin.ts +3 -9
  57. package/src/start-router-plugin/plugin.ts +233 -45
  58. package/src/start-router-plugin/pruneServerOnlySubtrees.ts +51 -0
  59. package/dist/esm/debug.js +0 -5
  60. package/dist/esm/debug.js.map +0 -1
  61. package/dist/esm/start-compiler-plugin/middleware.d.ts +0 -4
  62. package/dist/esm/start-compiler-plugin/middleware.js.map +0 -1
  63. package/dist/esm/start-compiler-plugin/serverFileRoute.d.ts +0 -4
  64. package/dist/esm/start-compiler-plugin/serverFileRoute.js +0 -38
  65. package/dist/esm/start-compiler-plugin/serverFileRoute.js.map +0 -1
  66. package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.d.ts +0 -2
  67. package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js +0 -119
  68. package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js.map +0 -1
  69. package/dist/esm/start-router-plugin/route-tree-client-plugin.d.ts +0 -6
  70. package/dist/esm/start-router-plugin/route-tree-client-plugin.js +0 -56
  71. package/dist/esm/start-router-plugin/route-tree-client-plugin.js.map +0 -1
  72. package/dist/esm/start-router-plugin/virtual-route-tree-plugin.d.ts +0 -3
  73. package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js +0 -29
  74. package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js.map +0 -1
  75. package/src/start-compiler-plugin/serverFileRoute.ts +0 -59
  76. package/src/start-router-plugin/generator-plugins/server-routes-plugin.ts +0 -138
  77. package/src/start-router-plugin/route-tree-client-plugin.ts +0 -77
  78. package/src/start-router-plugin/virtual-route-tree-plugin.ts +0 -29
@@ -1,29 +0,0 @@
1
- import path from "node:path";
2
- import { normalizePath } from "vite";
3
- import { VIRTUAL_MODULES } from "@tanstack/start-server-core";
4
- import { debug } from "../debug.js";
5
- function virtualRouteTreePlugin(config) {
6
- const generatedRouteTreePath = normalizePath(
7
- path.resolve(config.generatedRouteTree)
8
- );
9
- return {
10
- name: "tanstack-start:virtual-route-tree",
11
- enforce: "pre",
12
- sharedDuringBuild: true,
13
- resolveId: {
14
- filter: { id: new RegExp(VIRTUAL_MODULES.routeTree) },
15
- handler(id) {
16
- let resolvedId = null;
17
- if (id === VIRTUAL_MODULES.routeTree) {
18
- if (debug) console.info("resolving id", id, generatedRouteTreePath);
19
- resolvedId = generatedRouteTreePath;
20
- }
21
- return resolvedId;
22
- }
23
- }
24
- };
25
- }
26
- export {
27
- virtualRouteTreePlugin
28
- };
29
- //# sourceMappingURL=virtual-route-tree-plugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"virtual-route-tree-plugin.js","sources":["../../../src/start-router-plugin/virtual-route-tree-plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { normalizePath } from 'vite'\nimport { VIRTUAL_MODULES } from '@tanstack/start-server-core'\nimport { debug } from '../debug'\nimport type { Config } from '@tanstack/router-generator'\nimport type { Plugin } from 'vite'\n\nexport function virtualRouteTreePlugin(config: Config): Plugin {\n const generatedRouteTreePath = normalizePath(\n path.resolve(config.generatedRouteTree),\n )\n\n return {\n name: 'tanstack-start:virtual-route-tree',\n enforce: 'pre',\n sharedDuringBuild: true,\n resolveId: {\n filter: { id: new RegExp(VIRTUAL_MODULES.routeTree) },\n handler(id) {\n let resolvedId: string | null = null\n if (id === VIRTUAL_MODULES.routeTree) {\n if (debug) console.info('resolving id', id, generatedRouteTreePath)\n resolvedId = generatedRouteTreePath\n }\n return resolvedId\n },\n },\n }\n}\n"],"names":[],"mappings":";;;;AAOO,SAAS,uBAAuB,QAAwB;AAC7D,QAAM,yBAAyB;AAAA,IAC7B,KAAK,QAAQ,OAAO,kBAAkB;AAAA,EAAA;AAGxC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,mBAAmB;AAAA,IACnB,WAAW;AAAA,MACT,QAAQ,EAAE,IAAI,IAAI,OAAO,gBAAgB,SAAS,EAAA;AAAA,MAClD,QAAQ,IAAI;AACV,YAAI,aAA4B;AAChC,YAAI,OAAO,gBAAgB,WAAW;AACpC,cAAI,MAAO,SAAQ,KAAK,gBAAgB,IAAI,sBAAsB;AAClE,uBAAa;AAAA,QACf;AACA,eAAO;AAAA,MACT;AAAA,IAAA;AAAA,EACF;AAEJ;"}
@@ -1,59 +0,0 @@
1
- import * as t from '@babel/types'
2
- import type * as babel from '@babel/core'
3
-
4
- import type { CompileOptions, CompileStartFrameworkOptions } from './compilers'
5
-
6
- export function handleCreateServerFileRouteCallExpressionFactory(
7
- framework: CompileStartFrameworkOptions,
8
- method:
9
- | 'createServerFileRoute'
10
- | 'createServerRoute'
11
- | 'createServerRootRoute',
12
- ) {
13
- return function handleCreateServerFileRouteCallExpression(
14
- path: babel.NodePath<t.CallExpression>,
15
- opts: CompileOptions,
16
- ) {
17
- const PACKAGES = { start: `@tanstack/${framework}-start/server` }
18
-
19
- let highestParent: babel.NodePath<any> = path
20
-
21
- while (highestParent.parentPath && !highestParent.parentPath.isProgram()) {
22
- highestParent = highestParent.parentPath
23
- }
24
-
25
- const programPath = highestParent.parentPath as babel.NodePath<t.Program>
26
-
27
- // If we're on the client, remove the entire variable
28
- if (opts.env === 'client') {
29
- highestParent.remove()
30
- return
31
- }
32
-
33
- let isCreateServerFileRouteImported = false as boolean
34
-
35
- programPath.traverse({
36
- ImportDeclaration(importPath) {
37
- const importSource = importPath.node.source.value
38
- if (importSource === PACKAGES.start) {
39
- const specifiers = importPath.node.specifiers
40
- isCreateServerFileRouteImported ||= specifiers.some((specifier) => {
41
- return (
42
- t.isImportSpecifier(specifier) &&
43
- t.isIdentifier(specifier.imported) &&
44
- specifier.imported.name === method
45
- )
46
- })
47
- }
48
- },
49
- })
50
-
51
- if (!isCreateServerFileRouteImported) {
52
- const importDeclaration = t.importDeclaration(
53
- [t.importSpecifier(t.identifier(method), t.identifier(method))],
54
- t.stringLiteral(PACKAGES.start),
55
- )
56
- programPath.node.body.unshift(importDeclaration)
57
- }
58
- }
59
- }
@@ -1,138 +0,0 @@
1
- import {
2
- checkRouteFullPathUniqueness,
3
- ensureStringArgument,
4
- hasChildWithExport,
5
- } from '@tanstack/router-generator'
6
-
7
- import type {
8
- GeneratorPluginWithTransform,
9
- ImportDeclaration,
10
- TransformImportsConfig,
11
- } from '@tanstack/router-generator'
12
-
13
- const EXPORT_NAME = 'ServerRoute'
14
- export function serverRoutesPlugin(): GeneratorPluginWithTransform {
15
- return {
16
- name: 'server-routes-plugin',
17
- transformPlugin: {
18
- name: 'server-routes-transform',
19
- exportName: EXPORT_NAME,
20
- imports: (ctx) => {
21
- const targetModule = `@tanstack/${ctx.target}-start/server`
22
- const imports: TransformImportsConfig = {}
23
- if (ctx.verboseFileRoutes === false) {
24
- imports.banned = [
25
- {
26
- source: targetModule,
27
- specifiers: [{ imported: 'createServerFileRoute' }],
28
- },
29
- ]
30
- } else {
31
- imports.required = [
32
- {
33
- source: targetModule,
34
- specifiers: [{ imported: 'createServerFileRoute' }],
35
- },
36
- ]
37
- }
38
- return imports
39
- },
40
- onExportFound: ({ ctx, decl }) => {
41
- let appliedChanges = false
42
- if (decl.init?.type === 'CallExpression') {
43
- let call = decl.init
44
- let callee = call.callee
45
-
46
- while (
47
- callee.type === 'MemberExpression' &&
48
- callee.object.type === 'CallExpression'
49
- ) {
50
- call = callee.object
51
- callee = call.callee
52
- }
53
- if (
54
- call.callee.type === 'Identifier' &&
55
- call.callee.name === 'createServerFileRoute'
56
- ) {
57
- if (!ctx.verboseFileRoutes) {
58
- if (call.arguments.length) {
59
- call.arguments = []
60
- appliedChanges = true
61
- }
62
- } else {
63
- appliedChanges = ensureStringArgument(
64
- call,
65
- ctx.routeId,
66
- ctx.preferredQuote,
67
- )
68
- }
69
- } else {
70
- throw new Error(
71
- `Expected "createServerFileRoute" call, but got "${call.callee.type}"`,
72
- )
73
- }
74
- }
75
- return appliedChanges
76
- },
77
- },
78
- moduleAugmentation: ({ generator }) => ({
79
- module: `@tanstack/${generator.config.target}-start/server`,
80
- interfaceName: 'ServerFileRoutesByPath',
81
- }),
82
- onRouteTreesChanged: ({ routeTrees, generator }) => {
83
- const tree = routeTrees.find((tree) => tree.exportName === EXPORT_NAME)
84
- if (tree) {
85
- checkRouteFullPathUniqueness(tree.sortedRouteNodes, generator.config)
86
- }
87
- },
88
- imports: (ctx) => {
89
- const imports: Array<ImportDeclaration> = []
90
-
91
- const targetModule = `@tanstack/${ctx.generator.config.target}-start/server`
92
- if (ctx.generator.config.verboseFileRoutes === false) {
93
- imports.push({
94
- specifiers: [
95
- { imported: 'CreateServerFileRoute' },
96
- { imported: 'ServerFileRoutesByPath' },
97
- ],
98
- source: targetModule,
99
- importKind: 'type',
100
- })
101
- }
102
- // don't add the import if there are no server routes defined
103
- const hasMatchingRouteFiles = ctx.acc.routeNodes.length > 0
104
- if (hasMatchingRouteFiles) {
105
- // needs a virtual root route
106
- if (!ctx.rootRouteNode.exports?.includes(EXPORT_NAME)) {
107
- imports.push({
108
- specifiers: [{ imported: 'createServerRootRoute' }],
109
- source: targetModule,
110
- })
111
- }
112
- }
113
- return imports
114
- },
115
- routeModuleAugmentation: ({ routeNode }) => {
116
- // server routes don't support lazy routes
117
- if (routeNode._fsRouteType === 'lazy') {
118
- return undefined
119
- }
120
- return `const createServerFileRoute: CreateServerFileRoute<
121
- ServerFileRoutesByPath['${routeNode.routePath}']['parentRoute'],
122
- ServerFileRoutesByPath['${routeNode.routePath}']['id'],
123
- ServerFileRoutesByPath['${routeNode.routePath}']['path'],
124
- ServerFileRoutesByPath['${routeNode.routePath}']['fullPath'],
125
- ${hasChildWithExport(routeNode, 'ServerRoute') ? `${routeNode.variableName}ServerRouteChildren` : 'unknown'}
126
- >`
127
- },
128
- createRootRouteCode: () => `createServerRootRoute()`,
129
- createVirtualRouteCode: ({ node }) =>
130
- `createServerFileRoute('${node.routePath}')`,
131
- config: ({ sortedRouteNodes }) => {
132
- const hasMatchingRouteFiles = sortedRouteNodes.length > 0
133
- return {
134
- virtualRootRoute: hasMatchingRouteFiles,
135
- }
136
- },
137
- }
138
- }
@@ -1,77 +0,0 @@
1
- import path from 'node:path'
2
- import * as t from '@babel/types'
3
- import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'
4
- import { normalizePath } from 'vite'
5
- import { deadCodeElimination } from 'babel-dead-code-elimination'
6
- import { debug } from '../debug'
7
- import { VITE_ENVIRONMENT_NAMES } from '../constants'
8
- import type { Plugin } from 'vite'
9
- import type { Config } from '@tanstack/router-generator'
10
-
11
- /**
12
- * This removes the server part from the generated route tree so that it can be used on the client.
13
- */
14
- export function routeTreeClientPlugin(config: Config): Plugin {
15
- const generatedRouteTreePath = normalizePath(
16
- path.resolve(config.generatedRouteTree),
17
- )
18
-
19
- return {
20
- name: 'tanstack-start:route-tree-client-plugin',
21
- enforce: 'pre',
22
- // only run this plugin in the client environment
23
- applyToEnvironment: (env) => env.name === VITE_ENVIRONMENT_NAMES.client,
24
- transform: {
25
- filter: { id: generatedRouteTreePath },
26
- handler(code, id) {
27
- if (id !== generatedRouteTreePath) {
28
- return null
29
- }
30
- if (debug) console.info(`Compiling route tree for the client`, id)
31
- const ast = parseAst({ code, sourceFilename: id })
32
-
33
- // only keep `export const routeTree = ... `
34
- const filteredBody = ast.program.body.filter((node) => {
35
- if (t.isExportNamedDeclaration(node)) {
36
- if (
37
- node.declaration &&
38
- t.isVariableDeclaration(node.declaration) &&
39
- node.declaration.declarations.length === 1 &&
40
- node.declaration.declarations[0] &&
41
- t.isVariableDeclarator(node.declaration.declarations[0]) &&
42
- t.isIdentifier(node.declaration.declarations[0].id) &&
43
- node.declaration.declarations[0].id.name === 'routeTree'
44
- ) {
45
- return true
46
- }
47
- return false
48
- }
49
- // strip off the typescript interface & module declarations since they also reference the server routes
50
- if (
51
- t.isTSInterfaceDeclaration(node) ||
52
- t.isTSModuleDeclaration(node)
53
- ) {
54
- return false
55
- }
56
- return true
57
- })
58
-
59
- ast.program.body = filteredBody
60
-
61
- deadCodeElimination(ast)
62
-
63
- const compiled = generateFromAst(ast, {
64
- sourceMaps: true,
65
- sourceFileName: id,
66
- filename: id,
67
- })
68
- if (debug) {
69
- logDiff(code, compiled.code)
70
- console.log('Output:\n', compiled.code, '\n\n')
71
- }
72
-
73
- return compiled
74
- },
75
- },
76
- }
77
- }
@@ -1,29 +0,0 @@
1
- import path from 'node:path'
2
- import { normalizePath } from 'vite'
3
- import { VIRTUAL_MODULES } from '@tanstack/start-server-core'
4
- import { debug } from '../debug'
5
- import type { Config } from '@tanstack/router-generator'
6
- import type { Plugin } from 'vite'
7
-
8
- export function virtualRouteTreePlugin(config: Config): Plugin {
9
- const generatedRouteTreePath = normalizePath(
10
- path.resolve(config.generatedRouteTree),
11
- )
12
-
13
- return {
14
- name: 'tanstack-start:virtual-route-tree',
15
- enforce: 'pre',
16
- sharedDuringBuild: true,
17
- resolveId: {
18
- filter: { id: new RegExp(VIRTUAL_MODULES.routeTree) },
19
- handler(id) {
20
- let resolvedId: string | null = null
21
- if (id === VIRTUAL_MODULES.routeTree) {
22
- if (debug) console.info('resolving id', id, generatedRouteTreePath)
23
- resolvedId = generatedRouteTreePath
24
- }
25
- return resolvedId
26
- },
27
- },
28
- }
29
- }