@tanstack/start-plugin-core 1.132.0-alpha.0 → 1.132.0-alpha.10

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 (67) hide show
  1. package/dist/esm/create-server-fn-plugin/compiler.d.ts +61 -0
  2. package/dist/esm/create-server-fn-plugin/compiler.js +336 -0
  3. package/dist/esm/create-server-fn-plugin/compiler.js.map +1 -0
  4. package/dist/esm/create-server-fn-plugin/handleCreateServerFn.d.ts +6 -0
  5. package/dist/esm/create-server-fn-plugin/handleCreateServerFn.js +85 -0
  6. package/dist/esm/create-server-fn-plugin/handleCreateServerFn.js.map +1 -0
  7. package/dist/esm/create-server-fn-plugin/plugin.d.ts +3 -0
  8. package/dist/esm/create-server-fn-plugin/plugin.js +113 -0
  9. package/dist/esm/create-server-fn-plugin/plugin.js.map +1 -0
  10. package/dist/esm/index.d.ts +1 -0
  11. package/dist/esm/index.js +2 -0
  12. package/dist/esm/index.js.map +1 -1
  13. package/dist/esm/output-directory.js +5 -2
  14. package/dist/esm/output-directory.js.map +1 -1
  15. package/dist/esm/plugin.d.ts +1 -1
  16. package/dist/esm/plugin.js +23 -14
  17. package/dist/esm/plugin.js.map +1 -1
  18. package/dist/esm/schema.d.ts +20 -28
  19. package/dist/esm/schema.js +10 -14
  20. package/dist/esm/schema.js.map +1 -1
  21. package/dist/esm/start-compiler-plugin/compilers.d.ts +15 -0
  22. package/dist/esm/start-compiler-plugin/compilers.js +131 -0
  23. package/dist/esm/start-compiler-plugin/compilers.js.map +1 -0
  24. package/dist/esm/start-compiler-plugin/constants.d.ts +1 -0
  25. package/dist/esm/start-compiler-plugin/constants.js +13 -0
  26. package/dist/esm/start-compiler-plugin/constants.js.map +1 -0
  27. package/dist/esm/start-compiler-plugin/envOnly.d.ts +5 -0
  28. package/dist/esm/start-compiler-plugin/envOnly.js +41 -0
  29. package/dist/esm/start-compiler-plugin/envOnly.js.map +1 -0
  30. package/dist/esm/start-compiler-plugin/isomorphicFn.d.ts +4 -0
  31. package/dist/esm/start-compiler-plugin/isomorphicFn.js +49 -0
  32. package/dist/esm/start-compiler-plugin/isomorphicFn.js.map +1 -0
  33. package/dist/esm/start-compiler-plugin/middleware.d.ts +4 -0
  34. package/dist/esm/start-compiler-plugin/middleware.js +51 -0
  35. package/dist/esm/start-compiler-plugin/middleware.js.map +1 -0
  36. package/dist/esm/{start-compiler-plugin.d.ts → start-compiler-plugin/plugin.d.ts} +1 -8
  37. package/dist/esm/start-compiler-plugin/plugin.js +96 -0
  38. package/dist/esm/start-compiler-plugin/plugin.js.map +1 -0
  39. package/dist/esm/start-compiler-plugin/serverFileRoute.d.ts +4 -0
  40. package/dist/esm/start-compiler-plugin/serverFileRoute.js +38 -0
  41. package/dist/esm/start-compiler-plugin/serverFileRoute.js.map +1 -0
  42. package/dist/esm/start-compiler-plugin/utils.d.ts +13 -0
  43. package/dist/esm/start-compiler-plugin/utils.js +30 -0
  44. package/dist/esm/start-compiler-plugin/utils.js.map +1 -0
  45. package/package.json +8 -8
  46. package/src/create-server-fn-plugin/compiler.ts +456 -0
  47. package/src/create-server-fn-plugin/handleCreateServerFn.ts +153 -0
  48. package/src/create-server-fn-plugin/plugin.ts +138 -0
  49. package/src/index.ts +2 -0
  50. package/src/output-directory.ts +13 -6
  51. package/src/plugin.ts +24 -21
  52. package/src/schema.ts +10 -16
  53. package/src/start-compiler-plugin/compilers.ts +195 -0
  54. package/src/start-compiler-plugin/constants.ts +9 -0
  55. package/src/start-compiler-plugin/envOnly.ts +58 -0
  56. package/src/start-compiler-plugin/isomorphicFn.ts +78 -0
  57. package/src/start-compiler-plugin/middleware.ts +79 -0
  58. package/src/start-compiler-plugin/plugin.ts +122 -0
  59. package/src/start-compiler-plugin/serverFileRoute.ts +59 -0
  60. package/src/start-compiler-plugin/utils.ts +41 -0
  61. package/dist/esm/compilers.d.ts +0 -21
  62. package/dist/esm/compilers.js +0 -395
  63. package/dist/esm/compilers.js.map +0 -1
  64. package/dist/esm/start-compiler-plugin.js +0 -78
  65. package/dist/esm/start-compiler-plugin.js.map +0 -1
  66. package/src/compilers.ts +0 -659
  67. package/src/start-compiler-plugin.ts +0 -115
@@ -0,0 +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 { transformFuncs } from './constants'\nimport { handleCreateServerFileRouteCallExpressionFactory } from './serverFileRoute'\nimport { handleCreateIsomorphicFnCallExpression } from './isomorphicFn'\nimport { handleCreateMiddlewareCallExpression } from './middleware'\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 }\nconst getIdentifiers = (\n framework: CompileStartFrameworkOptions,\n): Identifiers => ({\n createServerRootRoute: {\n name: 'createServerRootRoute',\n handleCallExpression: handleCreateServerFileRouteCallExpressionFactory(\n framework,\n 'createServerRootRoute',\n ),\n paths: [],\n },\n createServerRoute: {\n name: 'createServerRoute',\n handleCallExpression: handleCreateServerFileRouteCallExpressionFactory(\n framework,\n 'createServerRoute',\n ),\n paths: [],\n },\n createServerFileRoute: {\n name: 'createServerFileRoute',\n handleCallExpression: handleCreateServerFileRouteCallExpressionFactory(\n framework,\n 'createServerFileRoute',\n ),\n paths: [],\n },\n createMiddleware: {\n name: 'createMiddleware',\n handleCallExpression: handleCreateMiddlewareCallExpression,\n paths: [],\n },\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\nexport function compileStartOutputFactory(\n framework: CompileStartFrameworkOptions,\n) {\n return function compileStartOutput(opts: CompileOptions): GeneratorResult {\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 const identifiers = getIdentifiers(framework)\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":"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"}
@@ -0,0 +1 @@
1
+ export declare const transformFuncs: readonly ["createMiddleware", "createServerOnlyFn", "createClientOnlyFn", "createIsomorphicFn", "createServerRoute", "createServerFileRoute", "createServerRootRoute"];
@@ -0,0 +1,13 @@
1
+ const transformFuncs = [
2
+ "createMiddleware",
3
+ "createServerOnlyFn",
4
+ "createClientOnlyFn",
5
+ "createIsomorphicFn",
6
+ "createServerRoute",
7
+ "createServerFileRoute",
8
+ "createServerRootRoute"
9
+ ];
10
+ export {
11
+ transformFuncs
12
+ };
13
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sources":["../../../src/start-compiler-plugin/constants.ts"],"sourcesContent":["export const transformFuncs = [\n 'createMiddleware',\n 'createServerOnlyFn',\n 'createClientOnlyFn',\n 'createIsomorphicFn',\n 'createServerRoute',\n 'createServerFileRoute',\n 'createServerRootRoute',\n] as const\n"],"names":[],"mappings":"AAAO,MAAM,iBAAiB;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;"}
@@ -0,0 +1,5 @@
1
+ import { CompileOptions } from './compilers.js';
2
+ import * as t from '@babel/types';
3
+ import type * as babel from '@babel/core';
4
+ export declare const handleCreateServerOnlyFnCallExpression: (path: babel.NodePath<t.CallExpression>, opts: CompileOptions) => void;
5
+ export declare const handleCreateClientOnlyFnCallExpression: (path: babel.NodePath<t.CallExpression>, opts: CompileOptions) => void;
@@ -0,0 +1,41 @@
1
+ import * as t from "@babel/types";
2
+ function capitalize(str) {
3
+ if (!str) return "";
4
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
5
+ }
6
+ function buildEnvOnlyCallExpressionHandler(env) {
7
+ return function envOnlyCallExpressionHandler(path, opts) {
8
+ const isEnvMatch = env === "client" ? opts.env === "client" : opts.env === "server";
9
+ if (isEnvMatch) {
10
+ const innerInputExpression = path.node.arguments[0];
11
+ if (!t.isExpression(innerInputExpression)) {
12
+ throw new Error(
13
+ `${env}Only() functions must be called with a function!`
14
+ );
15
+ }
16
+ path.replaceWith(innerInputExpression);
17
+ return;
18
+ }
19
+ path.replaceWith(
20
+ t.arrowFunctionExpression(
21
+ [],
22
+ t.blockStatement([
23
+ t.throwStatement(
24
+ t.newExpression(t.identifier("Error"), [
25
+ t.stringLiteral(
26
+ `create${capitalize(env)}OnlyFn() functions can only be called on the ${env}!`
27
+ )
28
+ ])
29
+ )
30
+ ])
31
+ )
32
+ );
33
+ };
34
+ }
35
+ const handleCreateServerOnlyFnCallExpression = buildEnvOnlyCallExpressionHandler("server");
36
+ const handleCreateClientOnlyFnCallExpression = buildEnvOnlyCallExpressionHandler("client");
37
+ export {
38
+ handleCreateClientOnlyFnCallExpression,
39
+ handleCreateServerOnlyFnCallExpression
40
+ };
41
+ //# sourceMappingURL=envOnly.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envOnly.js","sources":["../../../src/start-compiler-plugin/envOnly.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport type * as babel from '@babel/core'\n\nimport type { CompileOptions } from './compilers'\n\nfunction capitalize(str: string) {\n if (!str) return ''\n return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase()\n}\n\nfunction buildEnvOnlyCallExpressionHandler(env: 'client' | 'server') {\n return function envOnlyCallExpressionHandler(\n path: babel.NodePath<t.CallExpression>,\n opts: CompileOptions,\n ) {\n // if (debug)\n // console.info(`Handling ${env}Only call expression:`, path.toString())\n\n const isEnvMatch =\n env === 'client' ? opts.env === 'client' : opts.env === 'server'\n\n if (isEnvMatch) {\n // extract the inner function from the call expression\n const innerInputExpression = path.node.arguments[0]\n\n if (!t.isExpression(innerInputExpression)) {\n throw new Error(\n `${env}Only() functions must be called with a function!`,\n )\n }\n\n path.replaceWith(innerInputExpression)\n return\n }\n\n // If we're on the wrong environment, replace the call expression\n // with a function that always throws an error.\n path.replaceWith(\n t.arrowFunctionExpression(\n [],\n t.blockStatement([\n t.throwStatement(\n t.newExpression(t.identifier('Error'), [\n t.stringLiteral(\n `create${capitalize(env)}OnlyFn() functions can only be called on the ${env}!`,\n ),\n ]),\n ),\n ]),\n ),\n )\n }\n}\n\nexport const handleCreateServerOnlyFnCallExpression =\n buildEnvOnlyCallExpressionHandler('server')\nexport const handleCreateClientOnlyFnCallExpression =\n buildEnvOnlyCallExpressionHandler('client')\n"],"names":[],"mappings":";AAKA,SAAS,WAAW,KAAa;AAC/B,MAAI,CAAC,IAAK,QAAO;AACjB,SAAO,IAAI,OAAO,CAAC,EAAE,gBAAgB,IAAI,MAAM,CAAC,EAAE,YAAA;AACpD;AAEA,SAAS,kCAAkC,KAA0B;AACnE,SAAO,SAAS,6BACd,MACA,MACA;AAIA,UAAM,aACJ,QAAQ,WAAW,KAAK,QAAQ,WAAW,KAAK,QAAQ;AAE1D,QAAI,YAAY;AAEd,YAAM,uBAAuB,KAAK,KAAK,UAAU,CAAC;AAElD,UAAI,CAAC,EAAE,aAAa,oBAAoB,GAAG;AACzC,cAAM,IAAI;AAAA,UACR,GAAG,GAAG;AAAA,QAAA;AAAA,MAEV;AAEA,WAAK,YAAY,oBAAoB;AACrC;AAAA,IACF;AAIA,SAAK;AAAA,MACH,EAAE;AAAA,QACA,CAAA;AAAA,QACA,EAAE,eAAe;AAAA,UACf,EAAE;AAAA,YACA,EAAE,cAAc,EAAE,WAAW,OAAO,GAAG;AAAA,cACrC,EAAE;AAAA,gBACA,SAAS,WAAW,GAAG,CAAC,gDAAgD,GAAG;AAAA,cAAA;AAAA,YAC7E,CACD;AAAA,UAAA;AAAA,QACH,CACD;AAAA,MAAA;AAAA,IACH;AAAA,EAEJ;AACF;AAEO,MAAM,yCACX,kCAAkC,QAAQ;AACrC,MAAM,yCACX,kCAAkC,QAAQ;"}
@@ -0,0 +1,4 @@
1
+ import { CompileOptions } from './compilers.js';
2
+ import * as t from '@babel/types';
3
+ import type * as babel from '@babel/core';
4
+ export declare function handleCreateIsomorphicFnCallExpression(path: babel.NodePath<t.CallExpression>, opts: CompileOptions): void;
@@ -0,0 +1,49 @@
1
+ import * as t from "@babel/types";
2
+ import { getRootCallExpression } from "./utils.js";
3
+ function handleCreateIsomorphicFnCallExpression(path, opts) {
4
+ const rootCallExpression = getRootCallExpression(path);
5
+ const callExpressionPaths = {
6
+ client: null,
7
+ server: null
8
+ };
9
+ const validMethods = Object.keys(callExpressionPaths);
10
+ rootCallExpression.traverse({
11
+ MemberExpression(memberExpressionPath) {
12
+ if (t.isIdentifier(memberExpressionPath.node.property)) {
13
+ const name = memberExpressionPath.node.property.name;
14
+ if (validMethods.includes(name) && memberExpressionPath.parentPath.isCallExpression()) {
15
+ callExpressionPaths[name] = memberExpressionPath.parentPath;
16
+ }
17
+ }
18
+ }
19
+ });
20
+ if (validMethods.every(
21
+ (method) => !callExpressionPaths[method]
22
+ )) {
23
+ const variableId = rootCallExpression.parentPath.isVariableDeclarator() ? rootCallExpression.parentPath.node.id : null;
24
+ console.warn(
25
+ "createIsomorphicFn called without a client or server implementation!",
26
+ "This will result in a no-op function.",
27
+ "Variable name:",
28
+ t.isIdentifier(variableId) ? variableId.name : "unknown"
29
+ );
30
+ }
31
+ const envCallExpression = callExpressionPaths[opts.env];
32
+ if (!envCallExpression) {
33
+ rootCallExpression.replaceWith(
34
+ t.arrowFunctionExpression([], t.blockStatement([]))
35
+ );
36
+ return;
37
+ }
38
+ const innerInputExpression = envCallExpression.node.arguments[0];
39
+ if (!t.isExpression(innerInputExpression)) {
40
+ throw new Error(
41
+ `createIsomorphicFn().${opts.env}(func) must be called with a function!`
42
+ );
43
+ }
44
+ rootCallExpression.replaceWith(innerInputExpression);
45
+ }
46
+ export {
47
+ handleCreateIsomorphicFnCallExpression
48
+ };
49
+ //# sourceMappingURL=isomorphicFn.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isomorphicFn.js","sources":["../../../src/start-compiler-plugin/isomorphicFn.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport { getRootCallExpression } from './utils'\nimport type * as babel from '@babel/core'\n\nimport type { CompileOptions } from './compilers'\n\nexport function handleCreateIsomorphicFnCallExpression(\n path: babel.NodePath<t.CallExpression>,\n opts: CompileOptions,\n) {\n const rootCallExpression = getRootCallExpression(path)\n\n // if (debug)\n // console.info(\n // 'Handling createIsomorphicFn call expression:',\n // rootCallExpression.toString(),\n // )\n\n const callExpressionPaths = {\n client: null as babel.NodePath<t.CallExpression> | null,\n server: null as babel.NodePath<t.CallExpression> | null,\n }\n\n const validMethods = Object.keys(callExpressionPaths)\n\n rootCallExpression.traverse({\n MemberExpression(memberExpressionPath) {\n if (t.isIdentifier(memberExpressionPath.node.property)) {\n const name = memberExpressionPath.node.property\n .name as keyof typeof callExpressionPaths\n\n if (\n validMethods.includes(name) &&\n memberExpressionPath.parentPath.isCallExpression()\n ) {\n callExpressionPaths[name] = memberExpressionPath.parentPath\n }\n }\n },\n })\n\n if (\n validMethods.every(\n (method) =>\n !callExpressionPaths[method as keyof typeof callExpressionPaths],\n )\n ) {\n const variableId = rootCallExpression.parentPath.isVariableDeclarator()\n ? rootCallExpression.parentPath.node.id\n : null\n console.warn(\n 'createIsomorphicFn called without a client or server implementation!',\n 'This will result in a no-op function.',\n 'Variable name:',\n t.isIdentifier(variableId) ? variableId.name : 'unknown',\n )\n }\n\n const envCallExpression = callExpressionPaths[opts.env]\n\n if (!envCallExpression) {\n // if we don't have an implementation for this environment, default to a no-op\n rootCallExpression.replaceWith(\n t.arrowFunctionExpression([], t.blockStatement([])),\n )\n return\n }\n\n const innerInputExpression = envCallExpression.node.arguments[0]\n\n if (!t.isExpression(innerInputExpression)) {\n throw new Error(\n `createIsomorphicFn().${opts.env}(func) must be called with a function!`,\n )\n }\n\n rootCallExpression.replaceWith(innerInputExpression)\n}\n"],"names":[],"mappings":";;AAMO,SAAS,uCACd,MACA,MACA;AACA,QAAM,qBAAqB,sBAAsB,IAAI;AAQrD,QAAM,sBAAsB;AAAA,IAC1B,QAAQ;AAAA,IACR,QAAQ;AAAA,EAAA;AAGV,QAAM,eAAe,OAAO,KAAK,mBAAmB;AAEpD,qBAAmB,SAAS;AAAA,IAC1B,iBAAiB,sBAAsB;AACrC,UAAI,EAAE,aAAa,qBAAqB,KAAK,QAAQ,GAAG;AACtD,cAAM,OAAO,qBAAqB,KAAK,SACpC;AAEH,YACE,aAAa,SAAS,IAAI,KAC1B,qBAAqB,WAAW,oBAChC;AACA,8BAAoB,IAAI,IAAI,qBAAqB;AAAA,QACnD;AAAA,MACF;AAAA,IACF;AAAA,EAAA,CACD;AAED,MACE,aAAa;AAAA,IACX,CAAC,WACC,CAAC,oBAAoB,MAA0C;AAAA,EAAA,GAEnE;AACA,UAAM,aAAa,mBAAmB,WAAW,qBAAA,IAC7C,mBAAmB,WAAW,KAAK,KACnC;AACJ,YAAQ;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA,EAAE,aAAa,UAAU,IAAI,WAAW,OAAO;AAAA,IAAA;AAAA,EAEnD;AAEA,QAAM,oBAAoB,oBAAoB,KAAK,GAAG;AAEtD,MAAI,CAAC,mBAAmB;AAEtB,uBAAmB;AAAA,MACjB,EAAE,wBAAwB,CAAA,GAAI,EAAE,eAAe,CAAA,CAAE,CAAC;AAAA,IAAA;AAEpD;AAAA,EACF;AAEA,QAAM,uBAAuB,kBAAkB,KAAK,UAAU,CAAC;AAE/D,MAAI,CAAC,EAAE,aAAa,oBAAoB,GAAG;AACzC,UAAM,IAAI;AAAA,MACR,wBAAwB,KAAK,GAAG;AAAA,IAAA;AAAA,EAEpC;AAEA,qBAAmB,YAAY,oBAAoB;AACrD;"}
@@ -0,0 +1,4 @@
1
+ import { CompileOptions } from './compilers.js';
2
+ import * as t from '@babel/types';
3
+ import type * as babel from '@babel/core';
4
+ export declare function handleCreateMiddlewareCallExpression(path: babel.NodePath<t.CallExpression>, opts: CompileOptions): void;
@@ -0,0 +1,51 @@
1
+ import * as t from "@babel/types";
2
+ import { getRootCallExpression } from "./utils.js";
3
+ function handleCreateMiddlewareCallExpression(path, opts) {
4
+ const rootCallExpression = getRootCallExpression(path);
5
+ const callExpressionPaths = {
6
+ middleware: null,
7
+ validator: null,
8
+ client: null,
9
+ server: null
10
+ };
11
+ const validMethods = Object.keys(callExpressionPaths);
12
+ rootCallExpression.traverse({
13
+ MemberExpression(memberExpressionPath) {
14
+ if (t.isIdentifier(memberExpressionPath.node.property)) {
15
+ const name = memberExpressionPath.node.property.name;
16
+ if (validMethods.includes(name) && memberExpressionPath.parentPath.isCallExpression()) {
17
+ callExpressionPaths[name] = memberExpressionPath.parentPath;
18
+ }
19
+ }
20
+ }
21
+ });
22
+ if (callExpressionPaths.validator) {
23
+ const innerInputExpression = callExpressionPaths.validator.node.arguments[0];
24
+ if (!innerInputExpression) {
25
+ throw new Error(
26
+ "createMiddleware().validator() must be called with a validator!"
27
+ );
28
+ }
29
+ if (opts.env === "client") {
30
+ if (t.isMemberExpression(callExpressionPaths.validator.node.callee)) {
31
+ callExpressionPaths.validator.replaceWith(
32
+ callExpressionPaths.validator.node.callee.object
33
+ );
34
+ }
35
+ }
36
+ }
37
+ const serverFnPath = callExpressionPaths.server?.get(
38
+ "arguments.0"
39
+ );
40
+ if (callExpressionPaths.server && serverFnPath.node && opts.env === "client") {
41
+ if (t.isMemberExpression(callExpressionPaths.server.node.callee)) {
42
+ callExpressionPaths.server.replaceWith(
43
+ callExpressionPaths.server.node.callee.object
44
+ );
45
+ }
46
+ }
47
+ }
48
+ export {
49
+ handleCreateMiddlewareCallExpression
50
+ };
51
+ //# sourceMappingURL=middleware.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"middleware.js","sources":["../../../src/start-compiler-plugin/middleware.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport { getRootCallExpression } from './utils'\nimport type * as babel from '@babel/core'\n\nimport type { CompileOptions } from './compilers'\n\nexport function handleCreateMiddlewareCallExpression(\n path: babel.NodePath<t.CallExpression>,\n opts: CompileOptions,\n) {\n const rootCallExpression = getRootCallExpression(path)\n\n // if (debug)\n // console.info(\n // 'Handling createMiddleware call expression:',\n // rootCallExpression.toString(),\n // )\n\n const callExpressionPaths = {\n middleware: null as babel.NodePath<t.CallExpression> | null,\n validator: null as babel.NodePath<t.CallExpression> | null,\n client: null as babel.NodePath<t.CallExpression> | null,\n server: null as babel.NodePath<t.CallExpression> | null,\n }\n\n const validMethods = Object.keys(callExpressionPaths)\n\n rootCallExpression.traverse({\n MemberExpression(memberExpressionPath) {\n if (t.isIdentifier(memberExpressionPath.node.property)) {\n const name = memberExpressionPath.node.property\n .name as keyof typeof callExpressionPaths\n\n if (\n validMethods.includes(name) &&\n memberExpressionPath.parentPath.isCallExpression()\n ) {\n callExpressionPaths[name] = memberExpressionPath.parentPath\n }\n }\n },\n })\n\n if (callExpressionPaths.validator) {\n const innerInputExpression = callExpressionPaths.validator.node.arguments[0]\n\n if (!innerInputExpression) {\n throw new Error(\n 'createMiddleware().validator() must be called with a validator!',\n )\n }\n\n // If we're on the client, remove the validator call expression\n if (opts.env === 'client') {\n if (t.isMemberExpression(callExpressionPaths.validator.node.callee)) {\n callExpressionPaths.validator.replaceWith(\n callExpressionPaths.validator.node.callee.object,\n )\n }\n }\n }\n\n const serverFnPath = callExpressionPaths.server?.get(\n 'arguments.0',\n ) as babel.NodePath<any>\n\n if (\n callExpressionPaths.server &&\n serverFnPath.node &&\n opts.env === 'client'\n ) {\n // If we're on the client, remove the server call expression\n if (t.isMemberExpression(callExpressionPaths.server.node.callee)) {\n callExpressionPaths.server.replaceWith(\n callExpressionPaths.server.node.callee.object,\n )\n }\n }\n}\n"],"names":[],"mappings":";;AAMO,SAAS,qCACd,MACA,MACA;AACA,QAAM,qBAAqB,sBAAsB,IAAI;AAQrD,QAAM,sBAAsB;AAAA,IAC1B,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,QAAQ;AAAA,EAAA;AAGV,QAAM,eAAe,OAAO,KAAK,mBAAmB;AAEpD,qBAAmB,SAAS;AAAA,IAC1B,iBAAiB,sBAAsB;AACrC,UAAI,EAAE,aAAa,qBAAqB,KAAK,QAAQ,GAAG;AACtD,cAAM,OAAO,qBAAqB,KAAK,SACpC;AAEH,YACE,aAAa,SAAS,IAAI,KAC1B,qBAAqB,WAAW,oBAChC;AACA,8BAAoB,IAAI,IAAI,qBAAqB;AAAA,QACnD;AAAA,MACF;AAAA,IACF;AAAA,EAAA,CACD;AAED,MAAI,oBAAoB,WAAW;AACjC,UAAM,uBAAuB,oBAAoB,UAAU,KAAK,UAAU,CAAC;AAE3E,QAAI,CAAC,sBAAsB;AACzB,YAAM,IAAI;AAAA,QACR;AAAA,MAAA;AAAA,IAEJ;AAGA,QAAI,KAAK,QAAQ,UAAU;AACzB,UAAI,EAAE,mBAAmB,oBAAoB,UAAU,KAAK,MAAM,GAAG;AACnE,4BAAoB,UAAU;AAAA,UAC5B,oBAAoB,UAAU,KAAK,OAAO;AAAA,QAAA;AAAA,MAE9C;AAAA,IACF;AAAA,EACF;AAEA,QAAM,eAAe,oBAAoB,QAAQ;AAAA,IAC/C;AAAA,EAAA;AAGF,MACE,oBAAoB,UACpB,aAAa,QACb,KAAK,QAAQ,UACb;AAEA,QAAI,EAAE,mBAAmB,oBAAoB,OAAO,KAAK,MAAM,GAAG;AAChE,0BAAoB,OAAO;AAAA,QACzB,oBAAoB,OAAO,KAAK,OAAO;AAAA,MAAA;AAAA,IAE3C;AAAA,EACF;AACF;"}
@@ -3,11 +3,4 @@ import { CompileStartFrameworkOptions } from './compilers.js';
3
3
  export type TanStackStartViteOptions = {
4
4
  globalMiddlewareEntry: string;
5
5
  };
6
- export declare function startCompilerPlugin(framework: CompileStartFrameworkOptions, inputOpts?: {
7
- client?: {
8
- envName?: string;
9
- };
10
- server?: {
11
- envName?: string;
12
- };
13
- }): Plugin;
6
+ export declare function startCompilerPlugin(framework: CompileStartFrameworkOptions): Plugin;
@@ -0,0 +1,96 @@
1
+ import { pathToFileURL, fileURLToPath } from "node:url";
2
+ import { createRequire } from "node:module";
3
+ import { logDiff } from "@tanstack/router-utils";
4
+ import { VIRTUAL_MODULES } from "@tanstack/start-server-core";
5
+ import { normalizePath } from "vite";
6
+ import path from "pathe";
7
+ import { VITE_ENVIRONMENT_NAMES } from "../constants.js";
8
+ import { compileStartOutputFactory } from "./compilers.js";
9
+ import { transformFuncs } from "./constants.js";
10
+ const debug = process.env.TSR_VITE_DEBUG && ["true", "start-plugin"].includes(process.env.TSR_VITE_DEBUG);
11
+ const tokenRegex = new RegExp(transformFuncs.join("|"));
12
+ const require2 = createRequire(import.meta.url);
13
+ function resolveRuntimeFiles(opts) {
14
+ const pkgRoot = resolvePackage(opts.package);
15
+ const basePath = path.join(pkgRoot, "dist", "esm");
16
+ return opts.files.map((file) => normalizePath(path.join(basePath, file)));
17
+ }
18
+ function resolvePackage(packageName) {
19
+ const pkgRoot = path.dirname(require2.resolve(packageName + "/package.json"));
20
+ return pkgRoot;
21
+ }
22
+ function startCompilerPlugin(framework) {
23
+ const compileStartOutput = compileStartOutputFactory(framework);
24
+ return {
25
+ name: "tanstack-start-core:compiler",
26
+ enforce: "pre",
27
+ applyToEnvironment(env) {
28
+ return [
29
+ VITE_ENVIRONMENT_NAMES.client,
30
+ VITE_ENVIRONMENT_NAMES.server
31
+ ].includes(env.name);
32
+ },
33
+ transform: {
34
+ filter: {
35
+ code: tokenRegex,
36
+ id: {
37
+ exclude: [
38
+ VIRTUAL_MODULES.serverFnManifest,
39
+ // N.B. the following files either just re-export or provide the runtime implementation of those functions
40
+ // we do not want to include them in the transformation
41
+ // however, those packages (especially start-client-core ATM) also USE these functions
42
+ // (namely `createIsomorphicFn` in `packages/start-client-core/src/getRouterInstance.ts`) and thus need to be transformed
43
+ ...resolveRuntimeFiles({
44
+ package: "@tanstack/start-client-core",
45
+ files: [
46
+ "index.js",
47
+ "createIsomorphicFn.js",
48
+ "envOnly.js",
49
+ "createServerFn.js",
50
+ "createMiddleware.js",
51
+ "serverFnFetcher.js"
52
+ ]
53
+ }),
54
+ ...resolveRuntimeFiles({
55
+ package: "@tanstack/start-server-core",
56
+ files: [
57
+ "index.js",
58
+ "server-functions-handler.js",
59
+ "serverRoute.js"
60
+ ]
61
+ }),
62
+ ...resolveRuntimeFiles({
63
+ package: `@tanstack/${framework}-start-client`,
64
+ files: ["index.js"]
65
+ })
66
+ ]
67
+ }
68
+ },
69
+ handler(code, id) {
70
+ const env = this.environment.name === VITE_ENVIRONMENT_NAMES.client ? "client" : this.environment.name === VITE_ENVIRONMENT_NAMES.server ? "server" : (() => {
71
+ throw new Error(
72
+ `Environment ${this.environment.name} not configured`
73
+ );
74
+ })();
75
+ const url = pathToFileURL(id);
76
+ url.searchParams.delete("v");
77
+ id = fileURLToPath(url).replace(/\\/g, "/");
78
+ if (debug) console.info(`${env} Compiling Start: `, id);
79
+ const compiled = compileStartOutput({
80
+ code,
81
+ filename: id,
82
+ env
83
+ });
84
+ if (debug) {
85
+ logDiff(code, compiled.code);
86
+ console.log("Output:\n", compiled.code + "\n\n");
87
+ }
88
+ return compiled;
89
+ }
90
+ }
91
+ };
92
+ }
93
+ export {
94
+ startCompilerPlugin
95
+ };
96
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["../../../src/start-compiler-plugin/plugin.ts"],"sourcesContent":["import { fileURLToPath, pathToFileURL } from 'node:url'\nimport { createRequire } from 'node:module'\nimport { logDiff } from '@tanstack/router-utils'\n\nimport { VIRTUAL_MODULES } from '@tanstack/start-server-core'\nimport { normalizePath } from 'vite'\nimport path from 'pathe'\nimport { VITE_ENVIRONMENT_NAMES } from '../constants'\nimport { compileStartOutputFactory } from './compilers'\nimport { transformFuncs } from './constants'\nimport type { ViteEnvironmentNames } from '../constants'\nimport type { Plugin } from 'vite'\nimport type { CompileStartFrameworkOptions } from './compilers'\n\nconst debug =\n process.env.TSR_VITE_DEBUG &&\n ['true', 'start-plugin'].includes(process.env.TSR_VITE_DEBUG)\n\nexport type TanStackStartViteOptions = {\n globalMiddlewareEntry: string\n}\n\nconst tokenRegex = new RegExp(transformFuncs.join('|'))\n\nconst require = createRequire(import.meta.url)\n\nfunction resolveRuntimeFiles(opts: { package: string; files: Array<string> }) {\n const pkgRoot = resolvePackage(opts.package)\n const basePath = path.join(pkgRoot, 'dist', 'esm')\n\n return opts.files.map((file) => normalizePath(path.join(basePath, file)))\n}\n\nfunction resolvePackage(packageName: string): string {\n const pkgRoot = path.dirname(require.resolve(packageName + '/package.json'))\n return pkgRoot\n}\n\nexport function startCompilerPlugin(\n framework: CompileStartFrameworkOptions,\n): Plugin {\n const compileStartOutput = compileStartOutputFactory(framework)\n\n return {\n name: 'tanstack-start-core:compiler',\n enforce: 'pre',\n applyToEnvironment(env) {\n return [\n VITE_ENVIRONMENT_NAMES.client,\n VITE_ENVIRONMENT_NAMES.server,\n ].includes(env.name as ViteEnvironmentNames)\n },\n transform: {\n filter: {\n code: tokenRegex,\n id: {\n exclude: [\n VIRTUAL_MODULES.serverFnManifest,\n // N.B. the following files either just re-export or provide the runtime implementation of those functions\n // we do not want to include them in the transformation\n // however, those packages (especially start-client-core ATM) also USE these functions\n // (namely `createIsomorphicFn` in `packages/start-client-core/src/getRouterInstance.ts`) and thus need to be transformed\n ...resolveRuntimeFiles({\n package: '@tanstack/start-client-core',\n files: [\n 'index.js',\n 'createIsomorphicFn.js',\n 'envOnly.js',\n 'createServerFn.js',\n 'createMiddleware.js',\n 'serverFnFetcher.js',\n ],\n }),\n ...resolveRuntimeFiles({\n package: '@tanstack/start-server-core',\n files: [\n 'index.js',\n 'server-functions-handler.js',\n 'serverRoute.js',\n ],\n }),\n ...resolveRuntimeFiles({\n package: `@tanstack/${framework}-start-client`,\n files: ['index.js'],\n }),\n ],\n },\n },\n handler(code, id) {\n const env =\n this.environment.name === VITE_ENVIRONMENT_NAMES.client\n ? 'client'\n : this.environment.name === VITE_ENVIRONMENT_NAMES.server\n ? 'server'\n : (() => {\n throw new Error(\n `Environment ${this.environment.name} not configured`,\n )\n })()\n\n const url = pathToFileURL(id)\n url.searchParams.delete('v')\n id = fileURLToPath(url).replace(/\\\\/g, '/')\n\n if (debug) console.info(`${env} Compiling Start: `, id)\n\n const compiled = compileStartOutput({\n code,\n filename: id,\n env,\n })\n\n if (debug) {\n logDiff(code, compiled.code)\n console.log('Output:\\n', compiled.code + '\\n\\n')\n }\n\n return compiled\n },\n },\n }\n}\n"],"names":["require"],"mappings":";;;;;;;;;AAcA,MAAM,QACJ,QAAQ,IAAI,kBACZ,CAAC,QAAQ,cAAc,EAAE,SAAS,QAAQ,IAAI,cAAc;AAM9D,MAAM,aAAa,IAAI,OAAO,eAAe,KAAK,GAAG,CAAC;AAEtD,MAAMA,WAAU,cAAc,YAAY,GAAG;AAE7C,SAAS,oBAAoB,MAAiD;AAC5E,QAAM,UAAU,eAAe,KAAK,OAAO;AAC3C,QAAM,WAAW,KAAK,KAAK,SAAS,QAAQ,KAAK;AAEjD,SAAO,KAAK,MAAM,IAAI,CAAC,SAAS,cAAc,KAAK,KAAK,UAAU,IAAI,CAAC,CAAC;AAC1E;AAEA,SAAS,eAAe,aAA6B;AACnD,QAAM,UAAU,KAAK,QAAQA,SAAQ,QAAQ,cAAc,eAAe,CAAC;AAC3E,SAAO;AACT;AAEO,SAAS,oBACd,WACQ;AACR,QAAM,qBAAqB,0BAA0B,SAAS;AAE9D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,mBAAmB,KAAK;AACtB,aAAO;AAAA,QACL,uBAAuB;AAAA,QACvB,uBAAuB;AAAA,MAAA,EACvB,SAAS,IAAI,IAA4B;AAAA,IAC7C;AAAA,IACA,WAAW;AAAA,MACT,QAAQ;AAAA,QACN,MAAM;AAAA,QACN,IAAI;AAAA,UACF,SAAS;AAAA,YACP,gBAAgB;AAAA;AAAA;AAAA;AAAA;AAAA,YAKhB,GAAG,oBAAoB;AAAA,cACrB,SAAS;AAAA,cACT,OAAO;AAAA,gBACL;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,gBACA;AAAA,cAAA;AAAA,YACF,CACD;AAAA,YACD,GAAG,oBAAoB;AAAA,cACrB,SAAS;AAAA,cACT,OAAO;AAAA,gBACL;AAAA,gBACA;AAAA,gBACA;AAAA,cAAA;AAAA,YACF,CACD;AAAA,YACD,GAAG,oBAAoB;AAAA,cACrB,SAAS,aAAa,SAAS;AAAA,cAC/B,OAAO,CAAC,UAAU;AAAA,YAAA,CACnB;AAAA,UAAA;AAAA,QACH;AAAA,MACF;AAAA,MAEF,QAAQ,MAAM,IAAI;AAChB,cAAM,MACJ,KAAK,YAAY,SAAS,uBAAuB,SAC7C,WACA,KAAK,YAAY,SAAS,uBAAuB,SAC/C,YACC,MAAM;AACL,gBAAM,IAAI;AAAA,YACR,eAAe,KAAK,YAAY,IAAI;AAAA,UAAA;AAAA,QAExC,GAAA;AAER,cAAM,MAAM,cAAc,EAAE;AAC5B,YAAI,aAAa,OAAO,GAAG;AAC3B,aAAK,cAAc,GAAG,EAAE,QAAQ,OAAO,GAAG;AAE1C,YAAI,MAAO,SAAQ,KAAK,GAAG,GAAG,sBAAsB,EAAE;AAEtD,cAAM,WAAW,mBAAmB;AAAA,UAClC;AAAA,UACA,UAAU;AAAA,UACV;AAAA,QAAA,CACD;AAED,YAAI,OAAO;AACT,kBAAQ,MAAM,SAAS,IAAI;AAC3B,kBAAQ,IAAI,aAAa,SAAS,OAAO,MAAM;AAAA,QACjD;AAEA,eAAO;AAAA,MACT;AAAA,IAAA;AAAA,EACF;AAEJ;"}
@@ -0,0 +1,4 @@
1
+ import { CompileOptions, CompileStartFrameworkOptions } from './compilers.js';
2
+ import * as t from '@babel/types';
3
+ import type * as babel from '@babel/core';
4
+ export declare function handleCreateServerFileRouteCallExpressionFactory(framework: CompileStartFrameworkOptions, method: 'createServerFileRoute' | 'createServerRoute' | 'createServerRootRoute'): (path: babel.NodePath<t.CallExpression>, opts: CompileOptions) => void;
@@ -0,0 +1,38 @@
1
+ import * as t from "@babel/types";
2
+ function handleCreateServerFileRouteCallExpressionFactory(framework, method) {
3
+ return function handleCreateServerFileRouteCallExpression(path, opts) {
4
+ const PACKAGES = { start: `@tanstack/${framework}-start/server` };
5
+ let highestParent = path;
6
+ while (highestParent.parentPath && !highestParent.parentPath.isProgram()) {
7
+ highestParent = highestParent.parentPath;
8
+ }
9
+ const programPath = highestParent.parentPath;
10
+ if (opts.env === "client") {
11
+ highestParent.remove();
12
+ return;
13
+ }
14
+ let isCreateServerFileRouteImported = false;
15
+ programPath.traverse({
16
+ ImportDeclaration(importPath) {
17
+ const importSource = importPath.node.source.value;
18
+ if (importSource === PACKAGES.start) {
19
+ const specifiers = importPath.node.specifiers;
20
+ isCreateServerFileRouteImported ||= specifiers.some((specifier) => {
21
+ return t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported) && specifier.imported.name === method;
22
+ });
23
+ }
24
+ }
25
+ });
26
+ if (!isCreateServerFileRouteImported) {
27
+ const importDeclaration = t.importDeclaration(
28
+ [t.importSpecifier(t.identifier(method), t.identifier(method))],
29
+ t.stringLiteral(PACKAGES.start)
30
+ );
31
+ programPath.node.body.unshift(importDeclaration);
32
+ }
33
+ };
34
+ }
35
+ export {
36
+ handleCreateServerFileRouteCallExpressionFactory
37
+ };
38
+ //# sourceMappingURL=serverFileRoute.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serverFileRoute.js","sources":["../../../src/start-compiler-plugin/serverFileRoute.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport type * as babel from '@babel/core'\n\nimport type { CompileOptions, CompileStartFrameworkOptions } from './compilers'\n\nexport function handleCreateServerFileRouteCallExpressionFactory(\n framework: CompileStartFrameworkOptions,\n method:\n | 'createServerFileRoute'\n | 'createServerRoute'\n | 'createServerRootRoute',\n) {\n return function handleCreateServerFileRouteCallExpression(\n path: babel.NodePath<t.CallExpression>,\n opts: CompileOptions,\n ) {\n const PACKAGES = { start: `@tanstack/${framework}-start/server` }\n\n let highestParent: babel.NodePath<any> = path\n\n while (highestParent.parentPath && !highestParent.parentPath.isProgram()) {\n highestParent = highestParent.parentPath\n }\n\n const programPath = highestParent.parentPath as babel.NodePath<t.Program>\n\n // If we're on the client, remove the entire variable\n if (opts.env === 'client') {\n highestParent.remove()\n return\n }\n\n let isCreateServerFileRouteImported = false as boolean\n\n programPath.traverse({\n ImportDeclaration(importPath) {\n const importSource = importPath.node.source.value\n if (importSource === PACKAGES.start) {\n const specifiers = importPath.node.specifiers\n isCreateServerFileRouteImported ||= specifiers.some((specifier) => {\n return (\n t.isImportSpecifier(specifier) &&\n t.isIdentifier(specifier.imported) &&\n specifier.imported.name === method\n )\n })\n }\n },\n })\n\n if (!isCreateServerFileRouteImported) {\n const importDeclaration = t.importDeclaration(\n [t.importSpecifier(t.identifier(method), t.identifier(method))],\n t.stringLiteral(PACKAGES.start),\n )\n programPath.node.body.unshift(importDeclaration)\n }\n }\n}\n"],"names":[],"mappings":";AAKO,SAAS,iDACd,WACA,QAIA;AACA,SAAO,SAAS,0CACd,MACA,MACA;AACA,UAAM,WAAW,EAAE,OAAO,aAAa,SAAS,gBAAA;AAEhD,QAAI,gBAAqC;AAEzC,WAAO,cAAc,cAAc,CAAC,cAAc,WAAW,aAAa;AACxE,sBAAgB,cAAc;AAAA,IAChC;AAEA,UAAM,cAAc,cAAc;AAGlC,QAAI,KAAK,QAAQ,UAAU;AACzB,oBAAc,OAAA;AACd;AAAA,IACF;AAEA,QAAI,kCAAkC;AAEtC,gBAAY,SAAS;AAAA,MACnB,kBAAkB,YAAY;AAC5B,cAAM,eAAe,WAAW,KAAK,OAAO;AAC5C,YAAI,iBAAiB,SAAS,OAAO;AACnC,gBAAM,aAAa,WAAW,KAAK;AACnC,8CAAoC,WAAW,KAAK,CAAC,cAAc;AACjE,mBACE,EAAE,kBAAkB,SAAS,KAC7B,EAAE,aAAa,UAAU,QAAQ,KACjC,UAAU,SAAS,SAAS;AAAA,UAEhC,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IAAA,CACD;AAED,QAAI,CAAC,iCAAiC;AACpC,YAAM,oBAAoB,EAAE;AAAA,QAC1B,CAAC,EAAE,gBAAgB,EAAE,WAAW,MAAM,GAAG,EAAE,WAAW,MAAM,CAAC,CAAC;AAAA,QAC9D,EAAE,cAAc,SAAS,KAAK;AAAA,MAAA;AAEhC,kBAAY,KAAK,KAAK,QAAQ,iBAAiB;AAAA,IACjD;AAAA,EACF;AACF;"}
@@ -0,0 +1,13 @@
1
+ import type * as t from '@babel/types';
2
+ import type * as babel from '@babel/core';
3
+ export declare function getRootCallExpression(path: babel.NodePath<t.CallExpression>): babel.NodePath<t.CallExpression>;
4
+ export declare function codeFrameError(code: string, loc: {
5
+ start: {
6
+ line: number;
7
+ column: number;
8
+ };
9
+ end: {
10
+ line: number;
11
+ column: number;
12
+ };
13
+ }, message: string): Error;
@@ -0,0 +1,30 @@
1
+ import { codeFrameColumns } from "@babel/code-frame";
2
+ function getRootCallExpression(path) {
3
+ let rootCallExpression = path;
4
+ while (rootCallExpression.parentPath.isMemberExpression()) {
5
+ const parent = rootCallExpression.parentPath;
6
+ if (parent.parentPath.isCallExpression()) {
7
+ rootCallExpression = parent.parentPath;
8
+ }
9
+ }
10
+ return rootCallExpression;
11
+ }
12
+ function codeFrameError(code, loc, message) {
13
+ const frame = codeFrameColumns(
14
+ code,
15
+ {
16
+ start: loc.start,
17
+ end: loc.end
18
+ },
19
+ {
20
+ highlightCode: true,
21
+ message
22
+ }
23
+ );
24
+ return new Error(frame);
25
+ }
26
+ export {
27
+ codeFrameError,
28
+ getRootCallExpression
29
+ };
30
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sources":["../../../src/start-compiler-plugin/utils.ts"],"sourcesContent":["import { codeFrameColumns } from '@babel/code-frame'\nimport type * as t from '@babel/types'\nimport type * as babel from '@babel/core'\n\nexport function getRootCallExpression(path: babel.NodePath<t.CallExpression>) {\n // Find the highest callExpression parent\n let rootCallExpression: babel.NodePath<t.CallExpression> = path\n\n // Traverse up the chain of CallExpressions\n while (rootCallExpression.parentPath.isMemberExpression()) {\n const parent = rootCallExpression.parentPath\n if (parent.parentPath.isCallExpression()) {\n rootCallExpression = parent.parentPath\n }\n }\n\n return rootCallExpression\n}\n\nexport function codeFrameError(\n code: string,\n loc: {\n start: { line: number; column: number }\n end: { line: number; column: number }\n },\n message: string,\n) {\n const frame = codeFrameColumns(\n code,\n {\n start: loc.start,\n end: loc.end,\n },\n {\n highlightCode: true,\n message,\n },\n )\n\n return new Error(frame)\n}\n"],"names":[],"mappings":";AAIO,SAAS,sBAAsB,MAAwC;AAE5E,MAAI,qBAAuD;AAG3D,SAAO,mBAAmB,WAAW,sBAAsB;AACzD,UAAM,SAAS,mBAAmB;AAClC,QAAI,OAAO,WAAW,oBAAoB;AACxC,2BAAqB,OAAO;AAAA,IAC9B;AAAA,EACF;AAEA,SAAO;AACT;AAEO,SAAS,eACd,MACA,KAIA,SACA;AACA,QAAM,QAAQ;AAAA,IACZ;AAAA,IACA;AAAA,MACE,OAAO,IAAI;AAAA,MACX,KAAK,IAAI;AAAA,IAAA;AAAA,IAEX;AAAA,MACE,eAAe;AAAA,MACf;AAAA,IAAA;AAAA,EACF;AAGF,SAAO,IAAI,MAAM,KAAK;AACxB;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/start-plugin-core",
3
- "version": "1.132.0-alpha.0",
3
+ "version": "1.132.0-alpha.10",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -42,7 +42,7 @@
42
42
  "src"
43
43
  ],
44
44
  "engines": {
45
- "node": ">=12"
45
+ "node": ">=22.12.0"
46
46
  },
47
47
  "dependencies": {
48
48
  "@babel/code-frame": "7.26.2",
@@ -57,12 +57,12 @@
57
57
  "vitefu": "^1.1.1",
58
58
  "xmlbuilder2": "^3.1.1",
59
59
  "zod": "^3.24.2",
60
- "@tanstack/router-core": "1.132.0-alpha.0",
61
- "@tanstack/router-generator": "1.132.0-alpha.0",
62
- "@tanstack/router-plugin": "1.132.0-alpha.0",
63
- "@tanstack/router-utils": "1.132.0-alpha.0",
64
- "@tanstack/server-functions-plugin": "1.132.0-alpha.0",
65
- "@tanstack/start-server-core": "1.132.0-alpha.0"
60
+ "@tanstack/router-generator": "1.132.0-alpha.9",
61
+ "@tanstack/router-core": "1.132.0-alpha.8",
62
+ "@tanstack/router-plugin": "1.132.0-alpha.9",
63
+ "@tanstack/router-utils": "1.132.0-alpha.9",
64
+ "@tanstack/server-functions-plugin": "1.132.0-alpha.9",
65
+ "@tanstack/start-server-core": "1.132.0-alpha.10"
66
66
  },
67
67
  "devDependencies": {
68
68
  "@types/babel__code-frame": "^7.0.6",