@tanstack/start-plugin-core 1.140.5 → 1.141.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import { GeneratorResult, ParseAstOptions } from '@tanstack/router-utils';
2
2
  import * as babel from '@babel/core';
3
3
  import * as t from '@babel/types';
4
- export type CompileStartFrameworkOptions = 'react' | 'solid';
4
+ export type CompileStartFrameworkOptions = 'react' | 'solid' | 'vue';
5
5
  export declare function compileStartOutputFactory(framework: CompileStartFrameworkOptions): (opts: CompileOptions) => GeneratorResult;
6
6
  export type CompileOptions = ParseAstOptions & {
7
7
  env: 'server' | 'client';
@@ -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: 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;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,mBAAmB;AAAA,QAC7B,MAAM;AAAA,QACN,sBAAsB;AAAA,QACtB,OAAO,CAAA;AAAA,MAAC;AAAA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,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;"}
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' | 'vue'\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;AA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U,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.140.5",
3
+ "version": "1.141.0",
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": "^4.0.0",
61
61
  "zod": "^3.24.2",
62
- "@tanstack/router-core": "1.140.5",
63
- "@tanstack/router-generator": "1.140.5",
64
- "@tanstack/router-utils": "1.140.0",
65
- "@tanstack/router-plugin": "1.140.5",
66
- "@tanstack/server-functions-plugin": "1.140.0",
67
- "@tanstack/start-client-core": "1.140.5",
68
- "@tanstack/start-server-core": "1.140.5"
62
+ "@tanstack/router-generator": "1.141.0",
63
+ "@tanstack/router-plugin": "1.141.0",
64
+ "@tanstack/router-utils": "1.141.0",
65
+ "@tanstack/server-functions-plugin": "1.141.0",
66
+ "@tanstack/router-core": "1.141.0",
67
+ "@tanstack/start-client-core": "1.141.0",
68
+ "@tanstack/start-server-core": "1.141.0"
69
69
  },
70
70
  "devDependencies": {
71
71
  "@types/babel__code-frame": "^7.0.6",
@@ -15,7 +15,7 @@ import {
15
15
  } from './envOnly'
16
16
  import type { GeneratorResult, ParseAstOptions } from '@tanstack/router-utils'
17
17
 
18
- export type CompileStartFrameworkOptions = 'react' | 'solid'
18
+ export type CompileStartFrameworkOptions = 'react' | 'solid' | 'vue'
19
19
 
20
20
  type Identifiers = { [K in (typeof transformFuncs)[number]]: IdentifierConfig }
21
21