@tanstack/start-plugin-core 1.133.37 → 1.134.3

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.
@@ -23,27 +23,36 @@ function compileStartOutputFactory(framework) {
23
23
  name: "createIsomorphicFn",
24
24
  handleCallExpression: handleCreateIsomorphicFnCallExpression,
25
25
  paths: []
26
- },
27
- createMiddleware: {
26
+ }
27
+ };
28
+ if (opts.env === "client") {
29
+ identifiers.createMiddleware = {
28
30
  name: "createMiddleware",
29
31
  handleCallExpression: handleCreateMiddleware,
30
32
  paths: []
31
- }
32
- };
33
+ };
34
+ }
33
35
  const ast = parseAst(opts);
34
36
  const doDce = opts.dce ?? true;
35
37
  const refIdents = doDce ? findReferencedIdentifiers(ast) : void 0;
38
+ const validImportSources = [
39
+ `@tanstack/${framework}-start`,
40
+ "@tanstack/start-client-core"
41
+ ];
36
42
  babel.traverse(ast, {
37
43
  Program: {
38
44
  enter(programPath) {
39
45
  programPath.traverse({
40
46
  ImportDeclaration: (path) => {
41
- if (path.node.source.value !== `@tanstack/${framework}-start`) {
47
+ if (!validImportSources.includes(path.node.source.value)) {
42
48
  return;
43
49
  }
44
50
  path.node.specifiers.forEach((specifier) => {
45
51
  transformFuncs.forEach((identifierKey) => {
46
52
  const identifier = identifiers[identifierKey];
53
+ if (!identifier) {
54
+ return;
55
+ }
47
56
  if (specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier") {
48
57
  if (specifier.imported.name === identifierKey) {
49
58
  identifier.name = specifier.local.name;
@@ -57,11 +66,15 @@ function compileStartOutputFactory(framework) {
57
66
  },
58
67
  CallExpression: (path) => {
59
68
  transformFuncs.forEach((identifierKey) => {
60
- if (t.isIdentifier(path.node.callee) && path.node.callee.name === identifiers[identifierKey].name) {
61
- if (path.scope.getBinding(identifiers[identifierKey].name)?.path.node.type === "FunctionDeclaration") {
69
+ const identifier = identifiers[identifierKey];
70
+ if (!identifier) {
71
+ return;
72
+ }
73
+ if (t.isIdentifier(path.node.callee) && path.node.callee.name === identifier.name) {
74
+ if (path.scope.getBinding(identifier.name)?.path.node.type === "FunctionDeclaration") {
62
75
  return;
63
76
  }
64
- return identifiers[identifierKey].paths.push(path);
77
+ return identifier.paths.push(path);
65
78
  }
66
79
  if (t.isMemberExpression(path.node.callee)) {
67
80
  if (t.isIdentifier(path.node.callee.object) && t.isIdentifier(path.node.callee.property)) {
@@ -69,8 +82,8 @@ function compileStartOutputFactory(framework) {
69
82
  path.node.callee.object.name,
70
83
  path.node.callee.property.name
71
84
  ].join(".");
72
- if (callname === identifiers[identifierKey].name) {
73
- identifiers[identifierKey].paths.push(path);
85
+ if (callname === identifier.name) {
86
+ identifier.paths.push(path);
74
87
  }
75
88
  }
76
89
  }
@@ -79,8 +92,12 @@ function compileStartOutputFactory(framework) {
79
92
  }
80
93
  });
81
94
  transformFuncs.forEach((identifierKey) => {
82
- identifiers[identifierKey].paths.forEach((path) => {
83
- identifiers[identifierKey].handleCallExpression(
95
+ const identifier = identifiers[identifierKey];
96
+ if (!identifier) {
97
+ return;
98
+ }
99
+ identifier.paths.forEach((path) => {
100
+ identifier.handleCallExpression(
84
101
  path,
85
102
  opts
86
103
  );
@@ -1 +1 @@
1
- {"version":3,"file":"compilers.js","sources":["../../../src/start-compiler-plugin/compilers.ts"],"sourcesContent":["import * as babel from '@babel/core'\nimport * as t from '@babel/types'\n\nimport {\n deadCodeElimination,\n findReferencedIdentifiers,\n} from 'babel-dead-code-elimination'\nimport { generateFromAst, parseAst } from '@tanstack/router-utils'\nimport { handleCreateMiddleware } from '../create-server-fn-plugin/handleCreateMiddleware'\nimport { transformFuncs } from './constants'\nimport { handleCreateIsomorphicFnCallExpression } from './isomorphicFn'\nimport {\n handleCreateClientOnlyFnCallExpression,\n handleCreateServerOnlyFnCallExpression,\n} from './envOnly'\nimport type { GeneratorResult, ParseAstOptions } from '@tanstack/router-utils'\n\nexport type CompileStartFrameworkOptions = 'react' | 'solid'\n\ntype Identifiers = { [K in (typeof transformFuncs)[number]]: IdentifierConfig }\n\nexport function compileStartOutputFactory(\n framework: CompileStartFrameworkOptions,\n) {\n return function compileStartOutput(opts: CompileOptions): GeneratorResult {\n const identifiers: Identifiers = {\n createServerOnlyFn: {\n name: 'createServerOnlyFn',\n handleCallExpression: handleCreateServerOnlyFnCallExpression,\n paths: [],\n },\n createClientOnlyFn: {\n name: 'createClientOnlyFn',\n handleCallExpression: handleCreateClientOnlyFnCallExpression,\n paths: [],\n },\n createIsomorphicFn: {\n name: 'createIsomorphicFn',\n handleCallExpression: handleCreateIsomorphicFnCallExpression,\n paths: [],\n },\n createMiddleware: {\n name: 'createMiddleware',\n handleCallExpression: handleCreateMiddleware,\n paths: [],\n },\n }\n\n const ast = parseAst(opts)\n\n const doDce = opts.dce ?? true\n // find referenced identifiers *before* we transform anything\n const refIdents = doDce ? findReferencedIdentifiers(ast) : undefined\n\n babel.traverse(ast, {\n Program: {\n enter(programPath) {\n programPath.traverse({\n ImportDeclaration: (path) => {\n if (path.node.source.value !== `@tanstack/${framework}-start`) {\n return\n }\n\n // handle a destructured imports being renamed like \"import { createServerFn as myCreateServerFn } from '@tanstack/react-start';\"\n path.node.specifiers.forEach((specifier) => {\n transformFuncs.forEach((identifierKey) => {\n const identifier = identifiers[identifierKey]\n\n if (\n specifier.type === 'ImportSpecifier' &&\n specifier.imported.type === 'Identifier'\n ) {\n if (specifier.imported.name === identifierKey) {\n identifier.name = specifier.local.name\n }\n }\n\n // handle namespace imports like \"import * as TanStackStart from '@tanstack/react-start';\"\n if (specifier.type === 'ImportNamespaceSpecifier') {\n identifier.name = `${specifier.local.name}.${identifierKey}`\n }\n })\n })\n },\n CallExpression: (path) => {\n transformFuncs.forEach((identifierKey) => {\n // Check to see if the call expression is a call to the\n // identifiers[identifierKey].name\n if (\n t.isIdentifier(path.node.callee) &&\n path.node.callee.name === identifiers[identifierKey].name\n ) {\n // The identifier could be a call to the original function\n // in the source code. If this is case, we need to ignore it.\n // Check the scope to see if the identifier is a function declaration.\n // if it is, then we can ignore it.\n\n if (\n path.scope.getBinding(identifiers[identifierKey].name)?.path\n .node.type === 'FunctionDeclaration'\n ) {\n return\n }\n\n return identifiers[identifierKey].paths.push(path)\n }\n\n // handle namespace imports like \"import * as TanStackStart from '@tanstack/react-start';\"\n // which are then called like \"TanStackStart.createServerFn()\"\n if (t.isMemberExpression(path.node.callee)) {\n if (\n t.isIdentifier(path.node.callee.object) &&\n t.isIdentifier(path.node.callee.property)\n ) {\n const callname = [\n path.node.callee.object.name,\n path.node.callee.property.name,\n ].join('.')\n\n if (callname === identifiers[identifierKey].name) {\n identifiers[identifierKey].paths.push(path)\n }\n }\n }\n\n return\n })\n },\n })\n\n transformFuncs.forEach((identifierKey) => {\n identifiers[identifierKey].paths.forEach((path) => {\n identifiers[identifierKey].handleCallExpression(\n path as babel.NodePath<t.CallExpression>,\n opts,\n )\n })\n })\n },\n },\n })\n\n if (doDce) {\n deadCodeElimination(ast, refIdents)\n }\n\n return generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: opts.filename,\n filename: opts.filename,\n })\n }\n}\n\nexport type CompileOptions = ParseAstOptions & {\n env: 'server' | 'client'\n dce?: boolean\n filename: string\n}\n\nexport type IdentifierConfig = {\n name: string\n handleCallExpression: (\n path: babel.NodePath<t.CallExpression>,\n opts: CompileOptions,\n ) => void\n paths: Array<babel.NodePath>\n}\n"],"names":[],"mappings":";;;;;;;;AAqBO,SAAS,0BACd,WACA;AACA,SAAO,SAAS,mBAAmB,MAAuC;AACxE,UAAM,cAA2B;AAAA,MAC/B,oBAAoB;AAAA,QAClB,MAAM;AAAA,QACN,sBAAsB;AAAA,QACtB,OAAO,CAAA;AAAA,MAAC;AAAA,MAEV,oBAAoB;AAAA,QAClB,MAAM;AAAA,QACN,sBAAsB;AAAA,QACtB,OAAO,CAAA;AAAA,MAAC;AAAA,MAEV,oBAAoB;AAAA,QAClB,MAAM;AAAA,QACN,sBAAsB;AAAA,QACtB,OAAO,CAAA;AAAA,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KAAK,KAAK,OAAO,MAAM,KACtC,EAAE,aAAa,KAAK,KAAK,OAAO,QAAQ,GACxC;AACA,0BAAM,WAAW;AAAA,sBACf,KAAK,KAAK,OAAO,OAAO;AAAA,sBACxB,KAAK,KAAK,OAAO,SAAS;AAAA,oBAAA,EAC1B,KAAK,GAAG;AAEV,wBAAI,aAAa,YAAY,aAAa,EAAE,MAAM;AAChD,kCAAY,aAAa,EAAE,MAAM,KAAK,IAAI;AAAA,oBAC5C;AAAA,kBACF;AAAA,gBACF;AAEA;AAAA,cACF,CAAC;AAAA,YACH;AAAA,UAAA,CACD;AAED,yBAAe,QAAQ,CAAC,kBAAkB;AACxC,wBAAY,aAAa,EAAE,MAAM,QAAQ,CAAC,SAAS;AACjD,0BAAY,aAAa,EAAE;AAAA,gBACzB;AAAA,gBACA;AAAA,cAAA;AAAA,YAEJ,CAAC;AAAA,UACH,CAAC;AAAA,QACH;AAAA,MAAA;AAAA,IACF,CACD;AAED,QAAI,OAAO;AACT,0BAAoB,KAAK,SAAS;AAAA,IACpC;AAEA,WAAO,gBAAgB,KAAK;AAAA,MAC1B,YAAY;AAAA,MACZ,gBAAgB,KAAK;AAAA,MACrB,UAAU,KAAK;AAAA,IAAA,CAChB;AAAA,EACH;AACF;"}
1
+ {"version":3,"file":"compilers.js","sources":["../../../src/start-compiler-plugin/compilers.ts"],"sourcesContent":["import * as babel from '@babel/core'\nimport * as t from '@babel/types'\n\nimport {\n deadCodeElimination,\n findReferencedIdentifiers,\n} from 'babel-dead-code-elimination'\nimport { generateFromAst, parseAst } from '@tanstack/router-utils'\nimport { handleCreateMiddleware } from '../create-server-fn-plugin/handleCreateMiddleware'\nimport { transformFuncs } from './constants'\nimport { handleCreateIsomorphicFnCallExpression } from './isomorphicFn'\nimport {\n handleCreateClientOnlyFnCallExpression,\n handleCreateServerOnlyFnCallExpression,\n} from './envOnly'\nimport type { GeneratorResult, ParseAstOptions } from '@tanstack/router-utils'\n\nexport type CompileStartFrameworkOptions = 'react' | 'solid'\n\ntype Identifiers = { [K in (typeof transformFuncs)[number]]: IdentifierConfig }\n\nexport function compileStartOutputFactory(\n framework: CompileStartFrameworkOptions,\n) {\n return function compileStartOutput(opts: CompileOptions): GeneratorResult {\n const identifiers: Partial<Identifiers> = {\n createServerOnlyFn: {\n name: 'createServerOnlyFn',\n handleCallExpression: handleCreateServerOnlyFnCallExpression,\n paths: [],\n },\n createClientOnlyFn: {\n name: 'createClientOnlyFn',\n handleCallExpression: handleCreateClientOnlyFnCallExpression,\n paths: [],\n },\n createIsomorphicFn: {\n name: 'createIsomorphicFn',\n handleCallExpression: handleCreateIsomorphicFnCallExpression,\n paths: [],\n },\n }\n\n // createMiddleware only performs modifications in the client environment\n // so we can avoid executing this on the server\n if (opts.env === 'client') {\n identifiers.createMiddleware = {\n name: 'createMiddleware',\n handleCallExpression: handleCreateMiddleware,\n paths: [],\n }\n }\n\n const ast = parseAst(opts)\n\n const doDce = opts.dce ?? true\n // find referenced identifiers *before* we transform anything\n const refIdents = doDce ? findReferencedIdentifiers(ast) : undefined\n\n const validImportSources = [\n `@tanstack/${framework}-start`,\n '@tanstack/start-client-core',\n ]\n babel.traverse(ast, {\n Program: {\n enter(programPath) {\n programPath.traverse({\n ImportDeclaration: (path) => {\n if (!validImportSources.includes(path.node.source.value)) {\n return\n }\n\n // handle a destructured imports being renamed like \"import { createServerFn as myCreateServerFn } from '@tanstack/react-start';\"\n path.node.specifiers.forEach((specifier) => {\n transformFuncs.forEach((identifierKey) => {\n const identifier = identifiers[identifierKey]\n if (!identifier) {\n return\n }\n if (\n specifier.type === 'ImportSpecifier' &&\n specifier.imported.type === 'Identifier'\n ) {\n if (specifier.imported.name === identifierKey) {\n identifier.name = specifier.local.name\n }\n }\n\n // handle namespace imports like \"import * as TanStackStart from '@tanstack/react-start';\"\n if (specifier.type === 'ImportNamespaceSpecifier') {\n identifier.name = `${specifier.local.name}.${identifierKey}`\n }\n })\n })\n },\n CallExpression: (path) => {\n transformFuncs.forEach((identifierKey) => {\n const identifier = identifiers[identifierKey]\n if (!identifier) {\n return\n }\n // Check to see if the call expression is a call to the\n // identifiers[identifierKey].name\n if (\n t.isIdentifier(path.node.callee) &&\n path.node.callee.name === identifier.name\n ) {\n // The identifier could be a call to the original function\n // in the source code. If this is case, we need to ignore it.\n // Check the scope to see if the identifier is a function declaration.\n // if it is, then we can ignore it.\n\n if (\n path.scope.getBinding(identifier.name)?.path.node.type ===\n 'FunctionDeclaration'\n ) {\n return\n }\n\n return identifier.paths.push(path)\n }\n\n // handle namespace imports like \"import * as TanStackStart from '@tanstack/react-start';\"\n // which are then called like \"TanStackStart.createServerFn()\"\n if (t.isMemberExpression(path.node.callee)) {\n if (\n t.isIdentifier(path.node.callee.object) &&\n t.isIdentifier(path.node.callee.property)\n ) {\n const callname = [\n path.node.callee.object.name,\n path.node.callee.property.name,\n ].join('.')\n\n if (callname === identifier.name) {\n identifier.paths.push(path)\n }\n }\n }\n\n return\n })\n },\n })\n\n transformFuncs.forEach((identifierKey) => {\n const identifier = identifiers[identifierKey]\n if (!identifier) {\n return\n }\n identifier.paths.forEach((path) => {\n identifier.handleCallExpression(\n path as babel.NodePath<t.CallExpression>,\n opts,\n )\n })\n })\n },\n },\n })\n\n if (doDce) {\n deadCodeElimination(ast, refIdents)\n }\n\n return generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: opts.filename,\n filename: opts.filename,\n })\n }\n}\n\nexport type CompileOptions = ParseAstOptions & {\n env: 'server' | 'client'\n dce?: boolean\n filename: string\n}\n\nexport type IdentifierConfig = {\n name: string\n handleCallExpression: (\n path: babel.NodePath<t.CallExpression>,\n opts: CompileOptions,\n ) => void\n paths: Array<babel.NodePath>\n}\n"],"names":[],"mappings":";;;;;;;;AAqBO,SAAS,0BACd,WACA;AACA,SAAO,SAAS,mBAAmB,MAAuC;AACxE,UAAM,cAAoC;AAAA,MACxC,oBAAoB;AAAA,QAClB,MAAM;AAAA,QACN,sBAAsB;AAAA,QACtB,OAAO,CAAA;A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1
  {
2
2
  "name": "@tanstack/start-plugin-core",
3
- "version": "1.133.37",
3
+ "version": "1.134.3",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -59,13 +59,13 @@
59
59
  "vitefu": "^1.1.1",
60
60
  "xmlbuilder2": "^3.1.1",
61
61
  "zod": "^3.24.2",
62
- "@tanstack/router-core": "1.133.36",
62
+ "@tanstack/router-generator": "1.133.36",
63
63
  "@tanstack/router-plugin": "1.133.36",
64
- "@tanstack/router-utils": "1.133.19",
65
64
  "@tanstack/server-functions-plugin": "1.133.25",
66
- "@tanstack/router-generator": "1.133.36",
67
- "@tanstack/start-server-core": "1.133.36",
68
- "@tanstack/start-client-core": "1.133.36"
65
+ "@tanstack/start-client-core": "1.133.36",
66
+ "@tanstack/router-utils": "1.133.19",
67
+ "@tanstack/router-core": "1.133.36",
68
+ "@tanstack/start-server-core": "1.133.36"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@types/babel__code-frame": "^7.0.6",
@@ -23,7 +23,7 @@ export function compileStartOutputFactory(
23
23
  framework: CompileStartFrameworkOptions,
24
24
  ) {
25
25
  return function compileStartOutput(opts: CompileOptions): GeneratorResult {
26
- const identifiers: Identifiers = {
26
+ const identifiers: Partial<Identifiers> = {
27
27
  createServerOnlyFn: {
28
28
  name: 'createServerOnlyFn',
29
29
  handleCallExpression: handleCreateServerOnlyFnCallExpression,
@@ -39,11 +39,16 @@ export function compileStartOutputFactory(
39
39
  handleCallExpression: handleCreateIsomorphicFnCallExpression,
40
40
  paths: [],
41
41
  },
42
- createMiddleware: {
42
+ }
43
+
44
+ // createMiddleware only performs modifications in the client environment
45
+ // so we can avoid executing this on the server
46
+ if (opts.env === 'client') {
47
+ identifiers.createMiddleware = {
43
48
  name: 'createMiddleware',
44
49
  handleCallExpression: handleCreateMiddleware,
45
50
  paths: [],
46
- },
51
+ }
47
52
  }
48
53
 
49
54
  const ast = parseAst(opts)
@@ -52,12 +57,16 @@ export function compileStartOutputFactory(
52
57
  // find referenced identifiers *before* we transform anything
53
58
  const refIdents = doDce ? findReferencedIdentifiers(ast) : undefined
54
59
 
60
+ const validImportSources = [
61
+ `@tanstack/${framework}-start`,
62
+ '@tanstack/start-client-core',
63
+ ]
55
64
  babel.traverse(ast, {
56
65
  Program: {
57
66
  enter(programPath) {
58
67
  programPath.traverse({
59
68
  ImportDeclaration: (path) => {
60
- if (path.node.source.value !== `@tanstack/${framework}-start`) {
69
+ if (!validImportSources.includes(path.node.source.value)) {
61
70
  return
62
71
  }
63
72
 
@@ -65,7 +74,9 @@ export function compileStartOutputFactory(
65
74
  path.node.specifiers.forEach((specifier) => {
66
75
  transformFuncs.forEach((identifierKey) => {
67
76
  const identifier = identifiers[identifierKey]
68
-
77
+ if (!identifier) {
78
+ return
79
+ }
69
80
  if (
70
81
  specifier.type === 'ImportSpecifier' &&
71
82
  specifier.imported.type === 'Identifier'
@@ -84,11 +95,15 @@ export function compileStartOutputFactory(
84
95
  },
85
96
  CallExpression: (path) => {
86
97
  transformFuncs.forEach((identifierKey) => {
98
+ const identifier = identifiers[identifierKey]
99
+ if (!identifier) {
100
+ return
101
+ }
87
102
  // Check to see if the call expression is a call to the
88
103
  // identifiers[identifierKey].name
89
104
  if (
90
105
  t.isIdentifier(path.node.callee) &&
91
- path.node.callee.name === identifiers[identifierKey].name
106
+ path.node.callee.name === identifier.name
92
107
  ) {
93
108
  // The identifier could be a call to the original function
94
109
  // in the source code. If this is case, we need to ignore it.
@@ -96,13 +111,13 @@ export function compileStartOutputFactory(
96
111
  // if it is, then we can ignore it.
97
112
 
98
113
  if (
99
- path.scope.getBinding(identifiers[identifierKey].name)?.path
100
- .node.type === 'FunctionDeclaration'
114
+ path.scope.getBinding(identifier.name)?.path.node.type ===
115
+ 'FunctionDeclaration'
101
116
  ) {
102
117
  return
103
118
  }
104
119
 
105
- return identifiers[identifierKey].paths.push(path)
120
+ return identifier.paths.push(path)
106
121
  }
107
122
 
108
123
  // handle namespace imports like "import * as TanStackStart from '@tanstack/react-start';"
@@ -117,8 +132,8 @@ export function compileStartOutputFactory(
117
132
  path.node.callee.property.name,
118
133
  ].join('.')
119
134
 
120
- if (callname === identifiers[identifierKey].name) {
121
- identifiers[identifierKey].paths.push(path)
135
+ if (callname === identifier.name) {
136
+ identifier.paths.push(path)
122
137
  }
123
138
  }
124
139
  }
@@ -129,8 +144,12 @@ export function compileStartOutputFactory(
129
144
  })
130
145
 
131
146
  transformFuncs.forEach((identifierKey) => {
132
- identifiers[identifierKey].paths.forEach((path) => {
133
- identifiers[identifierKey].handleCallExpression(
147
+ const identifier = identifiers[identifierKey]
148
+ if (!identifier) {
149
+ return
150
+ }
151
+ identifier.paths.forEach((path) => {
152
+ identifier.handleCallExpression(
134
153
  path as babel.NodePath<t.CallExpression>,
135
154
  opts,
136
155
  )