@tanstack/start-plugin-core 1.132.52 → 1.132.54
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.
|
@@ -69,7 +69,7 @@ function createServerFnPlugin(framework) {
|
|
|
69
69
|
code: {
|
|
70
70
|
// TODO apply this plugin with a different filter per environment so that .createMiddleware() calls are not scanned in server env
|
|
71
71
|
// only scan files that mention `.handler(` | `.createMiddleware()`
|
|
72
|
-
include: [
|
|
72
|
+
include: [/\.\s*handler\(/, /\.\s*createMiddleware\(\)/]
|
|
73
73
|
}
|
|
74
74
|
},
|
|
75
75
|
async handler(code, id) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["../../../src/create-server-fn-plugin/plugin.ts"],"sourcesContent":["import { VITE_ENVIRONMENT_NAMES } from '../constants'\nimport { ServerFnCompiler } from './compiler'\nimport type { LookupConfig, LookupKind } from './compiler'\nimport type { CompileStartFrameworkOptions } from '../start-compiler-plugin/compilers'\nimport type { ViteEnvironmentNames } from '../constants'\nimport type { PluginOption } from 'vite'\n\nfunction cleanId(id: string): string {\n return id.split('?')[0]!\n}\n\nconst LookupKindsPerEnv: Record<'client' | 'server', Set<LookupKind>> = {\n client: new Set(['Middleware', 'ServerFn'] as const),\n server: new Set(['ServerFn'] as const),\n}\n\nconst getLookupConfigurationsForEnv = (\n env: 'client' | 'server',\n framework: CompileStartFrameworkOptions,\n): Array<LookupConfig> => {\n const createServerFnConfig: LookupConfig = {\n libName: `@tanstack/${framework}-start`,\n rootExport: 'createServerFn',\n }\n if (env === 'client') {\n return [\n {\n libName: `@tanstack/${framework}-start`,\n rootExport: 'createMiddleware',\n },\n {\n libName: `@tanstack/${framework}-start`,\n rootExport: 'createStart',\n },\n\n createServerFnConfig,\n ]\n } else {\n return [createServerFnConfig]\n }\n}\nexport function createServerFnPlugin(\n framework: CompileStartFrameworkOptions,\n): PluginOption {\n const SERVER_FN_LOOKUP = 'server-fn-module-lookup'\n\n const compilers: Partial<Record<ViteEnvironmentNames, ServerFnCompiler>> = {}\n return [\n {\n name: 'tanstack-start-core:capture-server-fn-module-lookup',\n // we only need this plugin in dev mode\n apply: 'serve',\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 id: new RegExp(`${SERVER_FN_LOOKUP}$`),\n },\n handler(code, id) {\n const compiler =\n compilers[this.environment.name as ViteEnvironmentNames]\n compiler?.ingestModule({ code, id: cleanId(id) })\n },\n },\n },\n {\n name: 'tanstack-start-core::server-fn',\n enforce: 'pre',\n\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 id: {\n exclude: new RegExp(`${SERVER_FN_LOOKUP}$`),\n },\n code: {\n // TODO apply this plugin with a different filter per environment so that .createMiddleware() calls are not scanned in server env\n // only scan files that mention `.handler(` | `.createMiddleware()`\n include: [
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["../../../src/create-server-fn-plugin/plugin.ts"],"sourcesContent":["import { VITE_ENVIRONMENT_NAMES } from '../constants'\nimport { ServerFnCompiler } from './compiler'\nimport type { LookupConfig, LookupKind } from './compiler'\nimport type { CompileStartFrameworkOptions } from '../start-compiler-plugin/compilers'\nimport type { ViteEnvironmentNames } from '../constants'\nimport type { PluginOption } from 'vite'\n\nfunction cleanId(id: string): string {\n return id.split('?')[0]!\n}\n\nconst LookupKindsPerEnv: Record<'client' | 'server', Set<LookupKind>> = {\n client: new Set(['Middleware', 'ServerFn'] as const),\n server: new Set(['ServerFn'] as const),\n}\n\nconst getLookupConfigurationsForEnv = (\n env: 'client' | 'server',\n framework: CompileStartFrameworkOptions,\n): Array<LookupConfig> => {\n const createServerFnConfig: LookupConfig = {\n libName: `@tanstack/${framework}-start`,\n rootExport: 'createServerFn',\n }\n if (env === 'client') {\n return [\n {\n libName: `@tanstack/${framework}-start`,\n rootExport: 'createMiddleware',\n },\n {\n libName: `@tanstack/${framework}-start`,\n rootExport: 'createStart',\n },\n\n createServerFnConfig,\n ]\n } else {\n return [createServerFnConfig]\n }\n}\nexport function createServerFnPlugin(\n framework: CompileStartFrameworkOptions,\n): PluginOption {\n const SERVER_FN_LOOKUP = 'server-fn-module-lookup'\n\n const compilers: Partial<Record<ViteEnvironmentNames, ServerFnCompiler>> = {}\n return [\n {\n name: 'tanstack-start-core:capture-server-fn-module-lookup',\n // we only need this plugin in dev mode\n apply: 'serve',\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 id: new RegExp(`${SERVER_FN_LOOKUP}$`),\n },\n handler(code, id) {\n const compiler =\n compilers[this.environment.name as ViteEnvironmentNames]\n compiler?.ingestModule({ code, id: cleanId(id) })\n },\n },\n },\n {\n name: 'tanstack-start-core::server-fn',\n enforce: 'pre',\n\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 id: {\n exclude: new RegExp(`${SERVER_FN_LOOKUP}$`),\n },\n code: {\n // TODO apply this plugin with a different filter per environment so that .createMiddleware() calls are not scanned in server env\n // only scan files that mention `.handler(` | `.createMiddleware()`\n include: [/\\.\\s*handler\\(/, /\\.\\s*createMiddleware\\(\\)/],\n },\n },\n async handler(code, id) {\n let compiler =\n compilers[this.environment.name as ViteEnvironmentNames]\n if (!compiler) {\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 compiler = new ServerFnCompiler({\n env,\n lookupKinds: LookupKindsPerEnv[env],\n lookupConfigurations: getLookupConfigurationsForEnv(\n env,\n framework,\n ),\n loadModule: async (id: string) => {\n if (this.environment.mode === 'build') {\n const loaded = await this.load({ id })\n if (!loaded.code) {\n throw new Error(`could not load module ${id}`)\n }\n compiler!.ingestModule({ code: loaded.code, id })\n } else if (this.environment.mode === 'dev') {\n /**\n * in dev, vite does not return code from `ctx.load()`\n * so instead, we need to take a different approach\n * we must force vite to load the module and run it through the vite plugin pipeline\n * we can do this by using the `fetchModule` method\n * the `captureServerFnModuleLookupPlugin` captures the module code via its transform hook and invokes analyzeModuleAST\n */\n await this.environment.fetchModule(\n id + '?' + SERVER_FN_LOOKUP,\n )\n } else {\n throw new Error(\n `could not load module ${id}: unknown environment mode ${this.environment.mode}`,\n )\n }\n },\n resolveId: async (source: string, importer?: string) => {\n const r = await this.resolve(source, importer)\n if (r) {\n if (!r.external) {\n return cleanId(r.id)\n }\n }\n return null\n },\n })\n compilers[this.environment.name as ViteEnvironmentNames] = compiler\n }\n\n id = cleanId(id)\n const result = await compiler.compile({ id, code })\n return result\n },\n },\n\n hotUpdate(ctx) {\n const compiler =\n compilers[this.environment.name as ViteEnvironmentNames]\n\n ctx.modules.forEach((m) => {\n if (m.id) {\n const deleted = compiler?.invalidateModule(m.id)\n if (deleted) {\n m.importers.forEach((importer) => {\n if (importer.id) {\n compiler?.invalidateModule(importer.id)\n }\n })\n }\n }\n })\n },\n },\n ]\n}\n"],"names":["id"],"mappings":";;AAOA,SAAS,QAAQ,IAAoB;AACnC,SAAO,GAAG,MAAM,GAAG,EAAE,CAAC;AACxB;AAEA,MAAM,oBAAkE;AAAA,EACtE,QAAQ,oBAAI,IAAI,CAAC,cAAc,UAAU,CAAU;AAAA,EACnD,QAAQ,oBAAI,IAAI,CAAC,UAAU,CAAU;AACvC;AAEA,MAAM,gCAAgC,CACpC,KACA,cACwB;AACxB,QAAM,uBAAqC;AAAA,IACzC,SAAS,aAAa,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AM,SAAS,MAAM,SAAS,QAAQ,EAAE,IAAI,MAAM;AAClD,iBAAO;AAAA,QACT;AAAA,MAAA;AAAA,MAGF,UAAU,KAAK;AACb,cAAM,WACJ,UAAU,KAAK,YAAY,IAA4B;AAEzD,YAAI,QAAQ,QAAQ,CAAC,MAAM;AACzB,cAAI,EAAE,IAAI;AACR,kBAAM,UAAU,UAAU,iBAAiB,EAAE,EAAE;AAC/C,gBAAI,SAAS;AACX,gBAAE,UAAU,QAAQ,CAAC,aAAa;AAChC,oBAAI,SAAS,IAAI;AACf,4BAAU,iBAAiB,SAAS,EAAE;AAAA,gBACxC;AAAA,cACF,CAAC;AAAA,YACH;AAAA,UACF;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/start-plugin-core",
|
|
3
|
-
"version": "1.132.
|
|
3
|
+
"version": "1.132.54",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -60,12 +60,12 @@
|
|
|
60
60
|
"xmlbuilder2": "^3.1.1",
|
|
61
61
|
"zod": "^3.24.2",
|
|
62
62
|
"@tanstack/router-core": "1.132.47",
|
|
63
|
+
"@tanstack/router-generator": "1.132.51",
|
|
63
64
|
"@tanstack/router-plugin": "1.132.51",
|
|
64
65
|
"@tanstack/router-utils": "1.132.51",
|
|
65
|
-
"@tanstack/server-functions-plugin": "1.132.
|
|
66
|
-
"@tanstack/
|
|
67
|
-
"@tanstack/start-server-core": "1.132.
|
|
68
|
-
"@tanstack/start-client-core": "1.132.48"
|
|
66
|
+
"@tanstack/server-functions-plugin": "1.132.53",
|
|
67
|
+
"@tanstack/start-client-core": "1.132.54",
|
|
68
|
+
"@tanstack/start-server-core": "1.132.54"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@types/babel__code-frame": "^7.0.6",
|
|
@@ -85,7 +85,7 @@ export function createServerFnPlugin(
|
|
|
85
85
|
code: {
|
|
86
86
|
// TODO apply this plugin with a different filter per environment so that .createMiddleware() calls are not scanned in server env
|
|
87
87
|
// only scan files that mention `.handler(` | `.createMiddleware()`
|
|
88
|
-
include: [
|
|
88
|
+
include: [/\.\s*handler\(/, /\.\s*createMiddleware\(\)/],
|
|
89
89
|
},
|
|
90
90
|
},
|
|
91
91
|
async handler(code, id) {
|