@tanstack/start-plugin-core 1.133.37 → 1.134.2

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,13 +23,15 @@ 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;
@@ -44,6 +46,9 @@ function compileStartOutputFactory(framework) {
44
46
  path.node.specifiers.forEach((specifier) => {
45
47
  transformFuncs.forEach((identifierKey) => {
46
48
  const identifier = identifiers[identifierKey];
49
+ if (!identifier) {
50
+ return;
51
+ }
47
52
  if (specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier") {
48
53
  if (specifier.imported.name === identifierKey) {
49
54
  identifier.name = specifier.local.name;
@@ -57,11 +62,15 @@ function compileStartOutputFactory(framework) {
57
62
  },
58
63
  CallExpression: (path) => {
59
64
  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") {
65
+ const identifier = identifiers[identifierKey];
66
+ if (!identifier) {
67
+ return;
68
+ }
69
+ if (t.isIdentifier(path.node.callee) && path.node.callee.name === identifier.name) {
70
+ if (path.scope.getBinding(identifier.name)?.path.node.type === "FunctionDeclaration") {
62
71
  return;
63
72
  }
64
- return identifiers[identifierKey].paths.push(path);
73
+ return identifier.paths.push(path);
65
74
  }
66
75
  if (t.isMemberExpression(path.node.callee)) {
67
76
  if (t.isIdentifier(path.node.callee.object) && t.isIdentifier(path.node.callee.property)) {
@@ -69,8 +78,8 @@ function compileStartOutputFactory(framework) {
69
78
  path.node.callee.object.name,
70
79
  path.node.callee.property.name
71
80
  ].join(".");
72
- if (callname === identifiers[identifierKey].name) {
73
- identifiers[identifierKey].paths.push(path);
81
+ if (callname === identifier.name) {
82
+ identifier.paths.push(path);
74
83
  }
75
84
  }
76
85
  }
@@ -79,8 +88,12 @@ function compileStartOutputFactory(framework) {
79
88
  }
80
89
  });
81
90
  transformFuncs.forEach((identifierKey) => {
82
- identifiers[identifierKey].paths.forEach((path) => {
83
- identifiers[identifierKey].handleCallExpression(
91
+ const identifier = identifiers[identifierKey];
92
+ if (!identifier) {
93
+ return;
94
+ }
95
+ identifier.paths.forEach((path) => {
96
+ identifier.handleCallExpression(
84
97
  path,
85
98
  opts
86
99
  );
@@ -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,MAAC;AAAA,MAEV,kBAAkB;AAAA,QAChB,MAAM;AAAA,QACN,sBAAsB;AAAA,QACtB,OAAO,CAAA;AAAA,MAAC;AAAA,IACV;AAGF,UAAM,MAAM,SAAS,IAAI;AAEzB,UAAM,QAAQ,KAAK,OAAO;AAE1B,UAAM,YAAY,QAAQ,0BAA0B,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I,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 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 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;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,MAAC;AAAA,IACV;AAKF,QAAI,KAAK,QAAQ,UAAU;AACzB,kBAAY,mBA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,mBAAmB,KAAK,KAAK,MAAM,GAAG;AAC1C,sBACE,EAAE,aAAa,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,WAAW,MAAM;AAChC,iCAAW,MAAM,KAAK,IAAI;AAAA,oBAC5B;AAAA,kBACF;AAAA,gBACF;AAEA;AAAA,cACF,CAAC;AAAA,YACH;AAAA,UAAA,CACD;AAED,yBAAe,QAAQ,CAAC,kBAAkB;AACxC,kBAAM,aAAa,YAAY,aAAa;AAC5C,gBAAI,CAAC,YAAY;AACf;AAAA,YACF;AACA,uBAAW,MAAM,QAAQ,CAAC,SAAS;AACjC,yBAAW;AAAA,gBACT;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;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/start-plugin-core",
3
- "version": "1.133.37",
3
+ "version": "1.134.2",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -60,10 +60,10 @@
60
60
  "xmlbuilder2": "^3.1.1",
61
61
  "zod": "^3.24.2",
62
62
  "@tanstack/router-core": "1.133.36",
63
+ "@tanstack/router-generator": "1.133.36",
63
64
  "@tanstack/router-plugin": "1.133.36",
64
- "@tanstack/router-utils": "1.133.19",
65
65
  "@tanstack/server-functions-plugin": "1.133.25",
66
- "@tanstack/router-generator": "1.133.36",
66
+ "@tanstack/router-utils": "1.133.19",
67
67
  "@tanstack/start-server-core": "1.133.36",
68
68
  "@tanstack/start-client-core": "1.133.36"
69
69
  },
@@ -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)
@@ -65,7 +70,9 @@ export function compileStartOutputFactory(
65
70
  path.node.specifiers.forEach((specifier) => {
66
71
  transformFuncs.forEach((identifierKey) => {
67
72
  const identifier = identifiers[identifierKey]
68
-
73
+ if (!identifier) {
74
+ return
75
+ }
69
76
  if (
70
77
  specifier.type === 'ImportSpecifier' &&
71
78
  specifier.imported.type === 'Identifier'
@@ -84,11 +91,15 @@ export function compileStartOutputFactory(
84
91
  },
85
92
  CallExpression: (path) => {
86
93
  transformFuncs.forEach((identifierKey) => {
94
+ const identifier = identifiers[identifierKey]
95
+ if (!identifier) {
96
+ return
97
+ }
87
98
  // Check to see if the call expression is a call to the
88
99
  // identifiers[identifierKey].name
89
100
  if (
90
101
  t.isIdentifier(path.node.callee) &&
91
- path.node.callee.name === identifiers[identifierKey].name
102
+ path.node.callee.name === identifier.name
92
103
  ) {
93
104
  // The identifier could be a call to the original function
94
105
  // in the source code. If this is case, we need to ignore it.
@@ -96,13 +107,13 @@ export function compileStartOutputFactory(
96
107
  // if it is, then we can ignore it.
97
108
 
98
109
  if (
99
- path.scope.getBinding(identifiers[identifierKey].name)?.path
100
- .node.type === 'FunctionDeclaration'
110
+ path.scope.getBinding(identifier.name)?.path.node.type ===
111
+ 'FunctionDeclaration'
101
112
  ) {
102
113
  return
103
114
  }
104
115
 
105
- return identifiers[identifierKey].paths.push(path)
116
+ return identifier.paths.push(path)
106
117
  }
107
118
 
108
119
  // handle namespace imports like "import * as TanStackStart from '@tanstack/react-start';"
@@ -117,8 +128,8 @@ export function compileStartOutputFactory(
117
128
  path.node.callee.property.name,
118
129
  ].join('.')
119
130
 
120
- if (callname === identifiers[identifierKey].name) {
121
- identifiers[identifierKey].paths.push(path)
131
+ if (callname === identifier.name) {
132
+ identifier.paths.push(path)
122
133
  }
123
134
  }
124
135
  }
@@ -129,8 +140,12 @@ export function compileStartOutputFactory(
129
140
  })
130
141
 
131
142
  transformFuncs.forEach((identifierKey) => {
132
- identifiers[identifierKey].paths.forEach((path) => {
133
- identifiers[identifierKey].handleCallExpression(
143
+ const identifier = identifiers[identifierKey]
144
+ if (!identifier) {
145
+ return
146
+ }
147
+ identifier.paths.forEach((path) => {
148
+ identifier.handleCallExpression(
134
149
  path as babel.NodePath<t.CallExpression>,
135
150
  opts,
136
151
  )