@tanstack/start-plugin-core 1.132.0-alpha.8 → 1.132.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.
- package/dist/esm/constants.d.ts +2 -1
- package/dist/esm/constants.js +3 -2
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/create-server-fn-plugin/compiler.d.ts +64 -0
- package/dist/esm/create-server-fn-plugin/compiler.js +364 -0
- package/dist/esm/create-server-fn-plugin/compiler.js.map +1 -0
- package/dist/esm/create-server-fn-plugin/handleCreateMiddleware.d.ts +5 -0
- package/dist/esm/{start-compiler-plugin/middleware.js → create-server-fn-plugin/handleCreateMiddleware.js} +11 -11
- package/dist/esm/create-server-fn-plugin/handleCreateMiddleware.js.map +1 -0
- package/dist/esm/create-server-fn-plugin/handleCreateServerFn.d.ts +6 -0
- package/dist/esm/{start-compiler-plugin/serverFn.js → create-server-fn-plugin/handleCreateServerFn.js} +15 -17
- package/dist/esm/create-server-fn-plugin/handleCreateServerFn.js.map +1 -0
- package/dist/esm/create-server-fn-plugin/plugin.d.ts +3 -0
- package/dist/esm/create-server-fn-plugin/plugin.js +128 -0
- package/dist/esm/create-server-fn-plugin/plugin.js.map +1 -0
- package/dist/esm/dev-server-plugin/plugin.d.ts +4 -2
- package/dist/esm/dev-server-plugin/plugin.js +6 -2
- package/dist/esm/dev-server-plugin/plugin.js.map +1 -1
- package/dist/esm/plugin.d.ts +12 -6
- package/dist/esm/plugin.js +56 -68
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/resolve-entries.d.ts +0 -1
- package/dist/esm/resolve-entries.js +1 -1
- package/dist/esm/resolve-entries.js.map +1 -1
- package/dist/esm/schema.d.ts +375 -308
- package/dist/esm/schema.js +23 -11
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/start-compiler-plugin/compilers.js +17 -55
- package/dist/esm/start-compiler-plugin/compilers.js.map +1 -1
- package/dist/esm/start-compiler-plugin/constants.d.ts +1 -1
- package/dist/esm/start-compiler-plugin/constants.js +1 -6
- package/dist/esm/start-compiler-plugin/constants.js.map +1 -1
- package/dist/esm/start-compiler-plugin/plugin.d.ts +1 -8
- package/dist/esm/start-compiler-plugin/plugin.js +6 -13
- package/dist/esm/start-compiler-plugin/plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/constants.d.ts +1 -0
- package/dist/esm/start-router-plugin/constants.js +5 -0
- package/dist/esm/start-router-plugin/constants.js.map +1 -0
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js +3 -9
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/plugin.d.ts +3 -2
- package/dist/esm/start-router-plugin/plugin.js +191 -31
- package/dist/esm/start-router-plugin/plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.d.ts +8 -0
- package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.js +34 -0
- package/dist/esm/start-router-plugin/pruneServerOnlySubtrees.js.map +1 -0
- package/package.json +8 -8
- package/src/constants.ts +3 -2
- package/src/create-server-fn-plugin/compiler.ts +498 -0
- package/src/{start-compiler-plugin/middleware.ts → create-server-fn-plugin/handleCreateMiddleware.ts} +15 -12
- package/src/{start-compiler-plugin/serverFn.ts → create-server-fn-plugin/handleCreateServerFn.ts} +32 -39
- package/src/create-server-fn-plugin/plugin.ts +153 -0
- package/src/dev-server-plugin/plugin.ts +6 -3
- package/src/plugin.ts +78 -87
- package/src/resolve-entries.ts +1 -2
- package/src/schema.ts +31 -14
- package/src/start-compiler-plugin/compilers.ts +18 -57
- package/src/start-compiler-plugin/constants.ts +0 -5
- package/src/start-compiler-plugin/plugin.ts +7 -22
- package/src/start-router-plugin/constants.ts +1 -0
- package/src/start-router-plugin/generator-plugins/routes-manifest-plugin.ts +3 -9
- package/src/start-router-plugin/plugin.ts +233 -45
- package/src/start-router-plugin/pruneServerOnlySubtrees.ts +51 -0
- package/dist/esm/debug.js +0 -5
- package/dist/esm/debug.js.map +0 -1
- package/dist/esm/start-compiler-plugin/middleware.d.ts +0 -4
- package/dist/esm/start-compiler-plugin/middleware.js.map +0 -1
- package/dist/esm/start-compiler-plugin/serverFileRoute.d.ts +0 -4
- package/dist/esm/start-compiler-plugin/serverFileRoute.js +0 -38
- package/dist/esm/start-compiler-plugin/serverFileRoute.js.map +0 -1
- package/dist/esm/start-compiler-plugin/serverFn.d.ts +0 -4
- package/dist/esm/start-compiler-plugin/serverFn.js.map +0 -1
- package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.d.ts +0 -2
- package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js +0 -119
- package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js.map +0 -1
- package/dist/esm/start-router-plugin/route-tree-client-plugin.d.ts +0 -6
- package/dist/esm/start-router-plugin/route-tree-client-plugin.js +0 -56
- package/dist/esm/start-router-plugin/route-tree-client-plugin.js.map +0 -1
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.d.ts +0 -3
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js +0 -29
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js.map +0 -1
- package/src/start-compiler-plugin/serverFileRoute.ts +0 -59
- package/src/start-router-plugin/generator-plugins/server-routes-plugin.ts +0 -138
- package/src/start-router-plugin/route-tree-client-plugin.ts +0 -77
- package/src/start-router-plugin/virtual-route-tree-plugin.ts +0 -29
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { VITE_ENVIRONMENT_NAMES } from "../constants.js";
|
|
2
|
+
import { ServerFnCompiler } from "./compiler.js";
|
|
3
|
+
function cleanId(id) {
|
|
4
|
+
return id.split("?")[0];
|
|
5
|
+
}
|
|
6
|
+
function createServerFnPlugin(framework) {
|
|
7
|
+
const SERVER_FN_LOOKUP = "server-fn-module-lookup";
|
|
8
|
+
const compilers = {};
|
|
9
|
+
return [
|
|
10
|
+
{
|
|
11
|
+
name: "tanstack-start-core:capture-server-fn-module-lookup",
|
|
12
|
+
// we only need this plugin in dev mode
|
|
13
|
+
apply: "serve",
|
|
14
|
+
applyToEnvironment(env) {
|
|
15
|
+
return [
|
|
16
|
+
VITE_ENVIRONMENT_NAMES.client,
|
|
17
|
+
VITE_ENVIRONMENT_NAMES.server
|
|
18
|
+
].includes(env.name);
|
|
19
|
+
},
|
|
20
|
+
transform: {
|
|
21
|
+
filter: {
|
|
22
|
+
id: new RegExp(`${SERVER_FN_LOOKUP}$`)
|
|
23
|
+
},
|
|
24
|
+
handler(code, id) {
|
|
25
|
+
const compiler = compilers[this.environment.name];
|
|
26
|
+
compiler?.ingestModule({ code, id: cleanId(id) });
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: "tanstack-start-core::server-fn",
|
|
32
|
+
enforce: "pre",
|
|
33
|
+
applyToEnvironment(env) {
|
|
34
|
+
return [
|
|
35
|
+
VITE_ENVIRONMENT_NAMES.client,
|
|
36
|
+
VITE_ENVIRONMENT_NAMES.server
|
|
37
|
+
].includes(env.name);
|
|
38
|
+
},
|
|
39
|
+
transform: {
|
|
40
|
+
filter: {
|
|
41
|
+
id: {
|
|
42
|
+
exclude: new RegExp(`${SERVER_FN_LOOKUP}$`)
|
|
43
|
+
},
|
|
44
|
+
code: {
|
|
45
|
+
// only scan files that mention `.handler(` | `.server(` | `.client(`
|
|
46
|
+
include: [/\.handler\(/, /\.server\(/, /\.client\(/]
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
async handler(code, id) {
|
|
50
|
+
let compiler = compilers[this.environment.name];
|
|
51
|
+
if (!compiler) {
|
|
52
|
+
const env = this.environment.name === VITE_ENVIRONMENT_NAMES.client ? "client" : this.environment.name === VITE_ENVIRONMENT_NAMES.server ? "server" : (() => {
|
|
53
|
+
throw new Error(
|
|
54
|
+
`Environment ${this.environment.name} not configured`
|
|
55
|
+
);
|
|
56
|
+
})();
|
|
57
|
+
compiler = new ServerFnCompiler({
|
|
58
|
+
env,
|
|
59
|
+
lookupConfigurations: [
|
|
60
|
+
{
|
|
61
|
+
libName: `@tanstack/${framework}-start`,
|
|
62
|
+
rootExport: "createMiddleware"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
libName: `@tanstack/${framework}-start`,
|
|
66
|
+
rootExport: "createServerFn"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
libName: `@tanstack/${framework}-start`,
|
|
70
|
+
rootExport: "createStart"
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
loadModule: async (id2) => {
|
|
74
|
+
if (this.environment.mode === "build") {
|
|
75
|
+
const loaded = await this.load({ id: id2 });
|
|
76
|
+
if (!loaded.code) {
|
|
77
|
+
throw new Error(`could not load module ${id2}`);
|
|
78
|
+
}
|
|
79
|
+
compiler.ingestModule({ code: loaded.code, id: id2 });
|
|
80
|
+
} else if (this.environment.mode === "dev") {
|
|
81
|
+
await this.environment.fetchModule(
|
|
82
|
+
id2 + "?" + SERVER_FN_LOOKUP
|
|
83
|
+
);
|
|
84
|
+
} else {
|
|
85
|
+
throw new Error(
|
|
86
|
+
`could not load module ${id2}: unknown environment mode ${this.environment.mode}`
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
resolveId: async (source, importer) => {
|
|
91
|
+
const r = await this.resolve(source, importer);
|
|
92
|
+
if (r) {
|
|
93
|
+
if (!r.external) {
|
|
94
|
+
return cleanId(r.id);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
compilers[this.environment.name] = compiler;
|
|
101
|
+
}
|
|
102
|
+
id = cleanId(id);
|
|
103
|
+
const result = await compiler.compile({ id, code });
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
hotUpdate(ctx) {
|
|
108
|
+
const compiler = compilers[this.environment.name];
|
|
109
|
+
ctx.modules.forEach((m) => {
|
|
110
|
+
if (m.id) {
|
|
111
|
+
const deleted = compiler?.invalidateModule(m.id);
|
|
112
|
+
if (deleted) {
|
|
113
|
+
m.importers.forEach((importer) => {
|
|
114
|
+
if (importer.id) {
|
|
115
|
+
compiler?.invalidateModule(importer.id);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
];
|
|
124
|
+
}
|
|
125
|
+
export {
|
|
126
|
+
createServerFnPlugin
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +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 { 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\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 // only scan files that mention `.handler(` | `.server(` | `.client(`\n include: [/\\.handler\\(/, /\\.server\\(/, /\\.client\\(/],\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 lookupConfigurations: [\n {\n libName: `@tanstack/${framework}-start`,\n rootExport: 'createMiddleware',\n },\n\n {\n libName: `@tanstack/${framework}-start`,\n rootExport: 'createServerFn',\n },\n {\n libName: `@tanstack/${framework}-start`,\n rootExport: 'createStart',\n },\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":";;AAMA,SAAS,QAAQ,IAAoB;AACnC,SAAO,GAAG,MAAM,GAAG,EAAE,CAAC;AACxB;AAEO,SAAS,qBACd,WACc;AACd,QAAM,mBAAmB;AAEzB,QAAM,YAAqE,CAAA;AAC3E,SAAO;AAAA,IACL;AAAA,MACE,MAAM;AAAA;AAAA,MAEN,OAAO;AAAA,MACP,mBAAmB,KAAK;AACtB,eAAO;AAAA,UACL,uBAAuB;AAAA,UACvB,uBAAuB;AAAA,QAAA,EACvB,SAAS,IAAI,IAA4B;AAAA,MAC7C;AAAA,MACA,WAAW;AAAA,QACT,QAAQ;AAAA,UACN,IAAI,IAAI,OAAO,GAAG,gBAAgB,GAAG;AAAA,QAAA;AAAA,QAEvC,QAAQ,MAAM,IAAI;AAChB,gBAAM,WACJ,UAAU,KAAK,YAAY,IAA4B;AACzD,oBAAU,aAAa,EAAE,MAAM,IAAI,QAAQ,EAAE,GAAG;AAAA,QAClD;AAAA,MAAA;AAAA,IACF;AAAA,IAEF;AAAA,MACE,MAAM;AAAA,MACN,SAAS;AAAA,MAET,mBAAmB,KAAK;AACtB,eAAO;AAAA,UACL,uBAAuB;AAAA,UACvB,uBAAuB;AAAA,QAAA,EACvB,SAAS,IAAI,IAA4B;AAAA,MAC7C;AAAA,MACA,WAAW;AAAA,QACT,QAAQ;AAAA,UACN,IAAI;AAAA,YACF,SAAS,IAAI,OAAO,GAAG,gBAAgB,GAAG;AAAA,UAAA;AAAA,UAE5C,MAAM;AAAA;AAAA,YAEJ,SAAS,CAAC,eAAe,cAAc,YAAY;AAAA,UAAA;AAAA,QACrD;AAAA,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AAU;AACf,2BAAO,QAAQ,EAAE,EAAE;AAAA,kBACrB;AAAA,gBACF;AACA,uBAAO;AAAA,cACT;AAAA,YAAA,CACD;AACD,sBAAU,KAAK,YAAY,IAA4B,IAAI;AAAA,UAC7D;AAEA,eAAK,QAAQ,EAAE;AACf,gBAAM,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;"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { PluginOption } from 'vite';
|
|
2
2
|
import { TanStackStartOutputConfig } from '../schema.js';
|
|
3
|
-
export declare function devServerPlugin({
|
|
4
|
-
|
|
3
|
+
export declare function devServerPlugin({ getConfig, }: {
|
|
4
|
+
getConfig: () => {
|
|
5
|
+
startConfig: TanStackStartOutputConfig;
|
|
6
|
+
};
|
|
5
7
|
}): PluginOption;
|
|
@@ -5,7 +5,7 @@ import { VITE_ENVIRONMENT_NAMES, ENTRY_POINTS } from "../constants.js";
|
|
|
5
5
|
import { resolveViteId } from "../utils.js";
|
|
6
6
|
import { extractHtmlScripts } from "./extract-html-scripts.js";
|
|
7
7
|
function devServerPlugin({
|
|
8
|
-
|
|
8
|
+
getConfig
|
|
9
9
|
}) {
|
|
10
10
|
let isTest = false;
|
|
11
11
|
let injectedHeadScripts;
|
|
@@ -33,6 +33,7 @@ function devServerPlugin({
|
|
|
33
33
|
`Server environment ${VITE_ENVIRONMENT_NAMES.server} not found`
|
|
34
34
|
);
|
|
35
35
|
}
|
|
36
|
+
const { startConfig } = getConfig();
|
|
36
37
|
const installMiddleware = startConfig.vite?.installDevServerMiddleware;
|
|
37
38
|
if (installMiddleware === false) {
|
|
38
39
|
return;
|
|
@@ -64,7 +65,10 @@ function devServerPlugin({
|
|
|
64
65
|
return sendNodeResponse(res, webRes);
|
|
65
66
|
} catch (e) {
|
|
66
67
|
console.error(e);
|
|
67
|
-
|
|
68
|
+
try {
|
|
69
|
+
viteDevServer.ssrFixStacktrace(e);
|
|
70
|
+
} catch (_e) {
|
|
71
|
+
}
|
|
68
72
|
if (webReq.headers.get("content-type")?.includes("application/json")) {
|
|
69
73
|
return sendNodeResponse(
|
|
70
74
|
res,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["../../../src/dev-server-plugin/plugin.ts"],"sourcesContent":["import { isRunnableDevEnvironment } from 'vite'\nimport { VIRTUAL_MODULES } from '@tanstack/start-server-core'\nimport { NodeRequest, sendNodeResponse } from 'srvx/node'\nimport { ENTRY_POINTS, VITE_ENVIRONMENT_NAMES } from '../constants'\nimport { resolveViteId } from '../utils'\nimport { extractHtmlScripts } from './extract-html-scripts'\nimport type { Connect, DevEnvironment, PluginOption } from 'vite'\nimport type { TanStackStartOutputConfig } from '../schema'\n\nexport function devServerPlugin({\n
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["../../../src/dev-server-plugin/plugin.ts"],"sourcesContent":["import { isRunnableDevEnvironment } from 'vite'\nimport { VIRTUAL_MODULES } from '@tanstack/start-server-core'\nimport { NodeRequest, sendNodeResponse } from 'srvx/node'\nimport { ENTRY_POINTS, VITE_ENVIRONMENT_NAMES } from '../constants'\nimport { resolveViteId } from '../utils'\nimport { extractHtmlScripts } from './extract-html-scripts'\nimport type { Connect, DevEnvironment, PluginOption } from 'vite'\nimport type { TanStackStartOutputConfig } from '../schema'\n\nexport function devServerPlugin({\n getConfig,\n}: {\n getConfig: () => { startConfig: TanStackStartOutputConfig }\n}): PluginOption {\n let isTest = false\n\n let injectedHeadScripts: string | undefined\n\n return [\n {\n name: 'tanstack-start-core:dev-server',\n config(_userConfig, { mode }) {\n isTest = isTest ? isTest : mode === 'test'\n },\n async configureServer(viteDevServer) {\n if (isTest) {\n return\n }\n\n // Extract the scripts that Vite plugins would inject into the initial HTML\n const templateHtml = `<html><head></head><body></body></html>`\n const transformedHtml = await viteDevServer.transformIndexHtml(\n '/',\n templateHtml,\n )\n const scripts = extractHtmlScripts(transformedHtml)\n injectedHeadScripts = scripts\n .flatMap((script) => script.content ?? [])\n .join(';')\n\n return () => {\n const serverEnv = viteDevServer.environments[\n VITE_ENVIRONMENT_NAMES.server\n ] as DevEnvironment | undefined\n\n if (!serverEnv) {\n throw new Error(\n `Server environment ${VITE_ENVIRONMENT_NAMES.server} not found`,\n )\n }\n const { startConfig } = getConfig()\n const installMiddleware = startConfig.vite?.installDevServerMiddleware\n if (installMiddleware === false) {\n return\n }\n if (installMiddleware == undefined) {\n // do not install middleware in middlewareMode by default\n if (viteDevServer.config.server.middlewareMode) {\n return\n }\n\n // do not install middleware if SSR env in case another plugin already did\n if (\n !isRunnableDevEnvironment(serverEnv) ||\n // do not check via `isFetchableDevEnvironment` since nitro does implement the `FetchableDevEnvironment` interface but not via inheritance (which this helper checks)\n 'dispatchFetch' in serverEnv\n ) {\n return\n }\n }\n\n if (!isRunnableDevEnvironment(serverEnv)) {\n throw new Error(\n 'cannot install vite dev server middleware for TanStack Start since the SSR environment is not a RunnableDevEnvironment',\n )\n }\n\n viteDevServer.middlewares.use(async (req, res) => {\n // fix the request URL to match the original URL\n // otherwise, the request URL will '/index.html'\n if (req.originalUrl) {\n req.url = req.originalUrl\n }\n const webReq = new NodeRequest({ req, res })\n\n try {\n // Import and resolve the request by running the server request entry point\n // this request entry point must implement the `fetch` API as follows:\n /**\n * export default {\n * fetch(req: Request): Promise<Response>\n * }\n */\n const serverEntry = await serverEnv.runner.import(\n ENTRY_POINTS.server,\n )\n const webRes = await serverEntry['default'].fetch(webReq)\n\n return sendNodeResponse(res, webRes)\n } catch (e) {\n console.error(e)\n try {\n viteDevServer.ssrFixStacktrace(e as Error)\n } catch (_e) {}\n\n if (\n webReq.headers.get('content-type')?.includes('application/json')\n ) {\n return sendNodeResponse(\n res,\n new Response(\n JSON.stringify(\n {\n status: 500,\n error: 'Internal Server Error',\n message:\n 'An unexpected error occurred. Please try again later.',\n timestamp: new Date().toISOString(),\n },\n null,\n 2,\n ),\n {\n status: 500,\n headers: {\n 'Content-Type': 'application/json',\n },\n },\n ),\n )\n }\n\n return sendNodeResponse(\n res,\n new Response(\n `\n <!DOCTYPE html>\n <html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <title>Error</title>\n <script type=\"module\">\n import { ErrorOverlay } from '/@vite/client'\n document.body.appendChild(new ErrorOverlay(${JSON.stringify(\n prepareError(req, e),\n ).replace(/</g, '\\\\u003c')}))\n </script>\n </head>\n <body>\n </body>\n </html>\n `,\n {\n status: 500,\n headers: {\n 'Content-Type': 'text/html',\n },\n },\n ),\n )\n }\n })\n }\n },\n },\n {\n name: 'tanstack-start-core:dev-server:injected-head-scripts',\n sharedDuringBuild: true,\n applyToEnvironment: (env) => env.config.consumer === 'server',\n resolveId: {\n filter: { id: new RegExp(VIRTUAL_MODULES.injectedHeadScripts) },\n handler(_id) {\n return resolveViteId(VIRTUAL_MODULES.injectedHeadScripts)\n },\n },\n load: {\n filter: {\n id: new RegExp(resolveViteId(VIRTUAL_MODULES.injectedHeadScripts)),\n },\n handler() {\n const mod = `\n export const injectedHeadScripts = ${JSON.stringify(injectedHeadScripts) || 'undefined'}`\n return mod\n },\n },\n },\n ]\n}\n\n/**\n * Formats error for SSR message in error overlay\n * @param req\n * @param error\n * @returns\n */\nfunction prepareError(req: Connect.IncomingMessage, error: unknown) {\n const e = error as Error\n return {\n message: `An error occured while server rendering ${req.url}:\\n\\n\\t${\n typeof e === 'string' ? e : e.message\n } `,\n stack: typeof e === 'string' ? '' : e.stack,\n }\n}\n"],"names":[],"mappings":";;;;;;AASO,SAAS,gBAAgB;AAAA,EAC9B;AACF,GAEiB;AACf,MAAI,SAAS;AAEb,MAAI;AAEJ,SAAO;AAAA,IACL;AAAA,MACE,MAAM;AAAA,MACN,OAAO,aAAa,EAAE,QAAQ;AAC5B,iBAAS,SAAS,SAAS,SAAS;AAAA,MACtC;AAAA,MACA,MAAM,gBAAgB,eAAe;AACnC,YAAI,QAAQ;AACV;AAAA,QACF;AAGA,cAAM,eAAe;AACrB,cAAM,kBAAkB,MAAM,cAAc;AAAA,UAC1C;AAAA,UACA;AAAA,QAAA;AAEF,cAAM,UAAU,mBAAmB,eAAe;AAClD,8BAAsB,QACnB,QAAQ,CAAC,WAAW,OAAO,WAAW,CAAA,CAAE,EACxC,KAAK,GAAG;AAEX,eAAO,MAAM;AACX,gBAAM,YAAY,cAAc,aAC9B,uBAAuB,MACzB;AAEA,cAAI,CAAC,WAAW;AACd,kBAAM,IAAI;AAAA,cACR,sBAAsB,uBAAuB,MAAM;AAAA,YAAA;AAAA,UAEvD;AACA,gBAAM,EAAE,YAAA,IAAgB,UAAA;AACxB,gBAAM,oBAAoB,YAAY,MAAM;AAC5C,cAAI,sBAAsB,OAAO;AAC/B;AAAA,UACF;AACA,cAAI,qBAAqB,QAAW;AAElC,gBAAI,cAAc,OAAO,OAAO,gBAAgB;AAC9C;AAAA,YACF;AAGA,gBACE,CAAC,yBAAyB,SAAS;AAAA,YAEnC,mBAAmB,WACnB;AACA;AAAA,YACF;AAAA,UACF;AAEA,cAAI,CAAC,yBAAyB,SAAS,GAAG;AACxC,kBAAM,IAAI;AAAA,cACR;AAAA,YAAA;AAAA,UAEJ;AAEA,wBAAc,YAAY,IAAI,OAAO,KAAK,QAAQ;AAGhD,gBAAI,IAAI,aAAa;AACnB,kBAAI,MAAM,IAAI;AAAA,YAChB;AAC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AA,MACnB,oBAAoB,CAAC,QAAQ,IAAI,OAAO,aAAa;AAAA,MACrD,WAAW;AAAA,QACT,QAAQ,EAAE,IAAI,IAAI,OAAO,gBAAgB,mBAAmB,EAAA;AAAA,QAC5D,QAAQ,KAAK;AACX,iBAAO,cAAc,gBAAgB,mBAAmB;AAAA,QAC1D;AAAA,MAAA;AAAA,MAEF,MAAM;AAAA,QACJ,QAAQ;AAAA,UACN,IAAI,IAAI,OAAO,cAAc,gBAAgB,mBAAmB,CAAC;AAAA,QAAA;AAAA,QAEnE,UAAU;AACR,gBAAM,MAAM;AAAA,6CACuB,KAAK,UAAU,mBAAmB,KAAK,WAAW;AACrF,iBAAO;AAAA,QACT;AAAA,MAAA;AAAA,IACF;AAAA,EACF;AAEJ;AAQA,SAAS,aAAa,KAA8B,OAAgB;AAClE,QAAM,IAAI;AACV,SAAO;AAAA,IACL,SAAS,2CAA2C,IAAI,GAAG;AAAA;AAAA,GACzD,OAAO,MAAM,WAAW,IAAI,EAAE,OAChC;AAAA,IACA,OAAO,OAAO,MAAM,WAAW,KAAK,EAAE;AAAA,EAAA;AAE1C;"}
|
package/dist/esm/plugin.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TanStackStartInputConfig } from './schema.js';
|
|
1
|
+
import { TanStackStartInputConfig, TanStackStartOutputConfig } from './schema.js';
|
|
2
2
|
import { PluginOption } from 'vite';
|
|
3
3
|
import { CompileStartFrameworkOptions } from './start-compiler-plugin/compilers.js';
|
|
4
4
|
export interface TanStackStartVitePluginCoreOptions {
|
|
@@ -6,11 +6,17 @@ export interface TanStackStartVitePluginCoreOptions {
|
|
|
6
6
|
defaultEntryPaths: {
|
|
7
7
|
client: string;
|
|
8
8
|
server: string;
|
|
9
|
+
start: string;
|
|
9
10
|
};
|
|
10
|
-
crawlPackages?: (opts: {
|
|
11
|
-
name: string;
|
|
12
|
-
peerDependencies: Record<string, any>;
|
|
13
|
-
exports?: Record<string, any> | string;
|
|
14
|
-
}) => 'include' | 'exclude' | undefined;
|
|
15
11
|
}
|
|
12
|
+
export interface ResolvedStartConfig {
|
|
13
|
+
root: string;
|
|
14
|
+
startFilePath: string | undefined;
|
|
15
|
+
routerFilePath: string;
|
|
16
|
+
srcDirectory: string;
|
|
17
|
+
}
|
|
18
|
+
export type GetConfigFn = () => {
|
|
19
|
+
startConfig: TanStackStartOutputConfig;
|
|
20
|
+
resolvedStartConfig: ResolvedStartConfig;
|
|
21
|
+
};
|
|
16
22
|
export declare function TanStackStartVitePluginCore(corePluginOpts: TanStackStartVitePluginCoreOptions, startPluginOpts: TanStackStartInputConfig): Array<PluginOption>;
|
package/dist/esm/plugin.js
CHANGED
|
@@ -15,8 +15,28 @@ import { parseStartConfig } from "./schema.js";
|
|
|
15
15
|
import { resolveEntry } from "./resolve-entries.js";
|
|
16
16
|
import { getServerOutputDirectory, getClientOutputDirectory } from "./output-directory.js";
|
|
17
17
|
import { postServerBuild } from "./post-server-build.js";
|
|
18
|
+
import { createServerFnPlugin } from "./create-server-fn-plugin/plugin.js";
|
|
18
19
|
function TanStackStartVitePluginCore(corePluginOpts, startPluginOpts) {
|
|
19
|
-
const
|
|
20
|
+
const resolvedStartConfig = {
|
|
21
|
+
root: "",
|
|
22
|
+
startFilePath: void 0,
|
|
23
|
+
routerFilePath: "",
|
|
24
|
+
srcDirectory: ""
|
|
25
|
+
};
|
|
26
|
+
let startConfig;
|
|
27
|
+
const getConfig = () => {
|
|
28
|
+
if (!resolvedStartConfig.root) {
|
|
29
|
+
throw new Error(`Cannot get config before root is resolved`);
|
|
30
|
+
}
|
|
31
|
+
if (!startConfig) {
|
|
32
|
+
startConfig = parseStartConfig(
|
|
33
|
+
startPluginOpts,
|
|
34
|
+
corePluginOpts,
|
|
35
|
+
resolvedStartConfig.root
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
return { startConfig, resolvedStartConfig };
|
|
39
|
+
};
|
|
20
40
|
const capturedBundle = {};
|
|
21
41
|
function getBundle(envName) {
|
|
22
42
|
const bundle = capturedBundle[envName];
|
|
@@ -26,39 +46,44 @@ function TanStackStartVitePluginCore(corePluginOpts, startPluginOpts) {
|
|
|
26
46
|
return bundle;
|
|
27
47
|
}
|
|
28
48
|
return [
|
|
29
|
-
tanStackStartRouter({
|
|
30
|
-
...startConfig.router,
|
|
31
|
-
target: corePluginOpts.framework,
|
|
32
|
-
autoCodeSplitting: true
|
|
33
|
-
}),
|
|
34
49
|
{
|
|
35
50
|
name: "tanstack-start-core:config",
|
|
51
|
+
enforce: "pre",
|
|
36
52
|
async config(viteConfig, { command }) {
|
|
37
53
|
const viteAppBase = trimPathRight(viteConfig.base || "/");
|
|
38
54
|
globalThis.TSS_APP_BASE = viteAppBase;
|
|
39
55
|
const root = viteConfig.root || process.cwd();
|
|
40
|
-
|
|
56
|
+
resolvedStartConfig.root = root;
|
|
57
|
+
const { startConfig: startConfig2 } = getConfig();
|
|
58
|
+
const resolvedSrcDirectory = join(root, startConfig2.srcDirectory);
|
|
59
|
+
resolvedStartConfig.srcDirectory = resolvedSrcDirectory;
|
|
60
|
+
const startFilePath = resolveEntry({
|
|
61
|
+
type: "start entry",
|
|
62
|
+
configuredEntry: startConfig2.start.entry,
|
|
63
|
+
defaultEntry: "start",
|
|
64
|
+
resolvedSrcDirectory,
|
|
65
|
+
required: false
|
|
66
|
+
});
|
|
67
|
+
resolvedStartConfig.startFilePath = startFilePath;
|
|
41
68
|
const routerFilePath = resolveEntry({
|
|
42
69
|
type: "router entry",
|
|
43
|
-
configuredEntry:
|
|
70
|
+
configuredEntry: startConfig2.router.entry,
|
|
44
71
|
defaultEntry: "router",
|
|
45
|
-
root,
|
|
46
72
|
resolvedSrcDirectory,
|
|
47
73
|
required: true
|
|
48
74
|
});
|
|
75
|
+
resolvedStartConfig.routerFilePath = routerFilePath;
|
|
49
76
|
const clientEntryPath = resolveEntry({
|
|
50
77
|
type: "client entry",
|
|
51
|
-
configuredEntry:
|
|
78
|
+
configuredEntry: startConfig2.client.entry,
|
|
52
79
|
defaultEntry: "client",
|
|
53
|
-
root,
|
|
54
80
|
resolvedSrcDirectory,
|
|
55
81
|
required: false
|
|
56
82
|
});
|
|
57
83
|
const serverEntryPath = resolveEntry({
|
|
58
84
|
type: "server entry",
|
|
59
|
-
configuredEntry:
|
|
85
|
+
configuredEntry: startConfig2.server.entry,
|
|
60
86
|
defaultEntry: "server",
|
|
61
|
-
root,
|
|
62
87
|
resolvedSrcDirectory,
|
|
63
88
|
required: false
|
|
64
89
|
});
|
|
@@ -76,39 +101,26 @@ function TanStackStartVitePluginCore(corePluginOpts, startPluginOpts) {
|
|
|
76
101
|
} else {
|
|
77
102
|
serverAlias = corePluginOpts.defaultEntryPaths.server;
|
|
78
103
|
}
|
|
104
|
+
let startAlias;
|
|
105
|
+
if (startFilePath) {
|
|
106
|
+
startAlias = vite.normalizePath(path.resolve(root, startFilePath));
|
|
107
|
+
} else {
|
|
108
|
+
startAlias = corePluginOpts.defaultEntryPaths.start;
|
|
109
|
+
}
|
|
79
110
|
const entryAliasConfiguration = {
|
|
111
|
+
[ENTRY_POINTS.start]: startAlias,
|
|
80
112
|
[ENTRY_POINTS.router]: routerFilePath,
|
|
81
113
|
[ENTRY_POINTS.client]: clientAlias,
|
|
82
114
|
[ENTRY_POINTS.server]: serverAlias
|
|
83
115
|
};
|
|
84
116
|
const startPackageName = `@tanstack/${corePluginOpts.framework}-start`;
|
|
85
|
-
const
|
|
86
|
-
const additionalOptimizeDeps = {
|
|
87
|
-
include: /* @__PURE__ */ new Set(),
|
|
88
|
-
exclude: /* @__PURE__ */ new Set()
|
|
89
|
-
};
|
|
90
|
-
const result = await crawlFrameworkPkgs({
|
|
117
|
+
const crawlFrameworkPkgsResult = await crawlFrameworkPkgs({
|
|
91
118
|
root: process.cwd(),
|
|
92
119
|
isBuild: command === "build",
|
|
93
120
|
isFrameworkPkgByJson(pkgJson) {
|
|
94
|
-
if ([routerPackageName, startPackageName].includes(pkgJson.name)) {
|
|
95
|
-
return false;
|
|
96
|
-
}
|
|
97
121
|
const peerDependencies = pkgJson["peerDependencies"];
|
|
98
122
|
if (peerDependencies) {
|
|
99
|
-
|
|
100
|
-
name: pkgJson.name,
|
|
101
|
-
peerDependencies,
|
|
102
|
-
exports: pkgJson.exports
|
|
103
|
-
});
|
|
104
|
-
if (internalResult) {
|
|
105
|
-
if (internalResult === "exclude") {
|
|
106
|
-
additionalOptimizeDeps.exclude.add(pkgJson.name);
|
|
107
|
-
} else {
|
|
108
|
-
additionalOptimizeDeps.include.add(pkgJson.name);
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
return startPackageName in peerDependencies || routerPackageName in peerDependencies;
|
|
123
|
+
return startPackageName in peerDependencies;
|
|
112
124
|
}
|
|
113
125
|
return false;
|
|
114
126
|
}
|
|
@@ -142,52 +154,29 @@ function TanStackStartVitePluginCore(corePluginOpts, startPluginOpts) {
|
|
|
142
154
|
include: [/node_modules/]
|
|
143
155
|
},
|
|
144
156
|
copyPublicDir: viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]?.build?.copyPublicDir ?? false
|
|
145
|
-
},
|
|
146
|
-
optimizeDeps: {
|
|
147
|
-
exclude: [
|
|
148
|
-
...Object.values(VIRTUAL_MODULES),
|
|
149
|
-
...result.optimizeDeps.exclude.sort(),
|
|
150
|
-
...additionalOptimizeDeps.exclude,
|
|
151
|
-
`@tanstack/${corePluginOpts.framework}-start/server`
|
|
152
|
-
],
|
|
153
|
-
include: [
|
|
154
|
-
...additionalOptimizeDeps.include,
|
|
155
|
-
...result.optimizeDeps.include.sort()
|
|
156
|
-
]
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
},
|
|
160
160
|
resolve: {
|
|
161
161
|
noExternal: [
|
|
162
|
+
// ENTRY_POINTS.start,
|
|
162
163
|
"@tanstack/start**",
|
|
163
164
|
`@tanstack/${corePluginOpts.framework}-start**`,
|
|
164
|
-
...
|
|
165
|
-
startPackageName,
|
|
166
|
-
...result.ssr.noExternal.sort()
|
|
165
|
+
...crawlFrameworkPkgsResult.ssr.noExternal.sort()
|
|
167
166
|
],
|
|
168
|
-
dedupe: [startPackageName],
|
|
169
167
|
alias: {
|
|
170
168
|
...entryAliasConfiguration
|
|
171
169
|
}
|
|
172
170
|
},
|
|
173
|
-
optimizeDeps: {
|
|
174
|
-
exclude: [
|
|
175
|
-
...Object.values(VIRTUAL_MODULES),
|
|
176
|
-
startPackageName,
|
|
177
|
-
...result.optimizeDeps.exclude.sort(),
|
|
178
|
-
...additionalOptimizeDeps.exclude
|
|
179
|
-
],
|
|
180
|
-
include: [...additionalOptimizeDeps.include]
|
|
181
|
-
},
|
|
182
171
|
/* prettier-ignore */
|
|
183
172
|
define: {
|
|
184
173
|
// define is an esbuild function that replaces the any instances of given keys with the given values
|
|
185
174
|
// i.e: __FRAMEWORK_NAME__ can be replaced with JSON.stringify("TanStack Start")
|
|
186
175
|
// This is not the same as injecting environment variables.
|
|
187
|
-
...defineReplaceEnv("TSS_SERVER_FN_BASE",
|
|
176
|
+
...defineReplaceEnv("TSS_SERVER_FN_BASE", startConfig2.serverFns.base),
|
|
188
177
|
...defineReplaceEnv("TSS_CLIENT_OUTPUT_DIR", getClientOutputDirectory(viteConfig)),
|
|
189
178
|
...defineReplaceEnv("TSS_APP_BASE", viteAppBase),
|
|
190
|
-
...command === "serve" ? defineReplaceEnv("TSS_SHELL",
|
|
179
|
+
...command === "serve" ? defineReplaceEnv("TSS_SHELL", startConfig2.spa?.enabled ? "true" : "false") : {},
|
|
191
180
|
...defineReplaceEnv("TSS_DEV_SERVER", command === "serve" ? "true" : "false")
|
|
192
181
|
},
|
|
193
182
|
builder: {
|
|
@@ -208,17 +197,16 @@ function TanStackStartVitePluginCore(corePluginOpts, startPluginOpts) {
|
|
|
208
197
|
await builder.build(server);
|
|
209
198
|
}
|
|
210
199
|
const serverBundle = getBundle(VITE_ENVIRONMENT_NAMES.server);
|
|
211
|
-
await postServerBuild({ builder, startConfig, serverBundle });
|
|
200
|
+
await postServerBuild({ builder, startConfig: startConfig2, serverBundle });
|
|
212
201
|
}
|
|
213
202
|
}
|
|
214
203
|
};
|
|
215
204
|
}
|
|
216
205
|
},
|
|
206
|
+
tanStackStartRouter(startPluginOpts, getConfig, corePluginOpts),
|
|
217
207
|
// N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPluginEnv
|
|
218
|
-
startCompilerPlugin(corePluginOpts.framework,
|
|
219
|
-
|
|
220
|
-
server: { envName: VITE_ENVIRONMENT_NAMES.server }
|
|
221
|
-
}),
|
|
208
|
+
startCompilerPlugin(corePluginOpts.framework),
|
|
209
|
+
createServerFnPlugin(corePluginOpts.framework),
|
|
222
210
|
TanStackServerFnPluginEnv({
|
|
223
211
|
// This is the ID that will be available to look up and import
|
|
224
212
|
// our server function manifest and resolve its module
|
|
@@ -238,7 +226,7 @@ function TanStackStartVitePluginCore(corePluginOpts, startPluginOpts) {
|
|
|
238
226
|
startManifestPlugin({
|
|
239
227
|
getClientBundle: () => getBundle(VITE_ENVIRONMENT_NAMES.client)
|
|
240
228
|
}),
|
|
241
|
-
devServerPlugin({
|
|
229
|
+
devServerPlugin({ getConfig }),
|
|
242
230
|
{
|
|
243
231
|
name: "tanstack-start:core:capture-bundle",
|
|
244
232
|
applyToEnvironment(e) {
|
package/dist/esm/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["../../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { trimPathRight } from '@tanstack/router-core'\nimport { VIRTUAL_MODULES } from '@tanstack/start-server-core'\nimport { TanStackServerFnPluginEnv } from '@tanstack/server-functions-plugin'\nimport * as vite from 'vite'\nimport { crawlFrameworkPkgs } from 'vitefu'\nimport { join } from 'pathe'\nimport { startManifestPlugin } from './start-manifest-plugin/plugin'\nimport { startCompilerPlugin } from './start-compiler-plugin/plugin'\nimport { ENTRY_POINTS, VITE_ENVIRONMENT_NAMES } from './constants'\nimport { tanStackStartRouter } from './start-router-plugin/plugin'\nimport { loadEnvPlugin } from './load-env-plugin/plugin'\nimport { devServerPlugin } from './dev-server-plugin/plugin'\nimport { parseStartConfig } from './schema'\nimport { resolveEntry } from './resolve-entries'\nimport {\n getClientOutputDirectory,\n getServerOutputDirectory,\n} from './output-directory'\nimport { postServerBuild } from './post-server-build'\nimport type { ViteEnvironmentNames } from './constants'\nimport type { TanStackStartInputConfig } from './schema'\nimport type { PluginOption } from 'vite'\nimport type { CompileStartFrameworkOptions } from './start-compiler-plugin/compilers'\n\nexport interface TanStackStartVitePluginCoreOptions {\n framework: CompileStartFrameworkOptions\n defaultEntryPaths: {\n client: string\n server: string\n }\n crawlPackages?: (opts: {\n name: string\n peerDependencies: Record<string, any>\n exports?: Record<string, any> | string\n }) => 'include' | 'exclude' | undefined\n}\n\nexport function TanStackStartVitePluginCore(\n corePluginOpts: TanStackStartVitePluginCoreOptions,\n startPluginOpts: TanStackStartInputConfig,\n): Array<PluginOption> {\n const startConfig = parseStartConfig(startPluginOpts)\n\n const capturedBundle: Partial<\n Record<ViteEnvironmentNames, vite.Rollup.OutputBundle>\n > = {}\n\n function getBundle(envName: ViteEnvironmentNames): vite.Rollup.OutputBundle {\n const bundle = capturedBundle[envName]\n if (!bundle) {\n throw new Error(`No bundle captured for environment: ${envName}`)\n }\n return bundle\n }\n\n return [\n tanStackStartRouter({\n ...startConfig.router,\n target: corePluginOpts.framework,\n autoCodeSplitting: true,\n }),\n {\n name: 'tanstack-start-core:config',\n async config(viteConfig, { command }) {\n const viteAppBase = trimPathRight(viteConfig.base || '/')\n globalThis.TSS_APP_BASE = viteAppBase\n\n const root = viteConfig.root || process.cwd()\n const resolvedSrcDirectory = join(root, startConfig.srcDirectory)\n\n const routerFilePath = resolveEntry({\n type: 'router entry',\n configuredEntry: startConfig.router.entry,\n defaultEntry: 'router',\n root,\n resolvedSrcDirectory,\n required: true,\n })\n const clientEntryPath = resolveEntry({\n type: 'client entry',\n configuredEntry: startConfig.client.entry,\n defaultEntry: 'client',\n root,\n resolvedSrcDirectory,\n required: false,\n })\n\n const serverEntryPath = resolveEntry({\n type: 'server entry',\n configuredEntry: startConfig.server.entry,\n defaultEntry: 'server',\n root,\n resolvedSrcDirectory,\n required: false,\n })\n\n let clientAlias: string\n if (clientEntryPath) {\n clientAlias = vite.normalizePath(\n path.join('/@fs', path.resolve(root, clientEntryPath)),\n )\n } else {\n clientAlias = corePluginOpts.defaultEntryPaths.client\n }\n let serverAlias: string\n if (serverEntryPath) {\n serverAlias = vite.normalizePath(path.resolve(root, serverEntryPath))\n } else {\n serverAlias = corePluginOpts.defaultEntryPaths.server\n }\n const entryAliasConfiguration: Record<\n (typeof ENTRY_POINTS)[keyof typeof ENTRY_POINTS],\n string\n > = {\n [ENTRY_POINTS.router]: routerFilePath,\n [ENTRY_POINTS.client]: clientAlias,\n [ENTRY_POINTS.server]: serverAlias,\n }\n\n // TODO\n /* const nitroOutputPublicDir = await (async () => {\n // Create a dummy nitro app to get the resolved public output path\n const dummyNitroApp = await createNitro({\n preset: startConfig.target,\n compatibilityDate: '2024-12-01',\n })\n\n const nitroOutputPublicDir = dummyNitroApp.options.output.publicDir\n await dummyNitroApp.close()\n\n return nitroOutputPublicDir\n })()*/\n\n const startPackageName = `@tanstack/${corePluginOpts.framework}-start`\n const routerPackageName = `@tanstack/${corePluginOpts.framework}-router`\n\n const additionalOptimizeDeps = {\n include: new Set<string>(),\n exclude: new Set<string>(),\n }\n\n // crawl packages that have start in \"peerDependencies\"\n // see https://github.com/svitejs/vitefu/blob/d8d82fa121e3b2215ba437107093c77bde51b63b/src/index.js#L95-L101\n\n // this is currently uncached; could be implemented similarly as vite handles lock file changes\n // see https://github.com/vitejs/vite/blob/557f797d29422027e8c451ca50dd84bf8c41b5f0/packages/vite/src/node/optimizer/index.ts#L1282\n\n const result = await crawlFrameworkPkgs({\n root: process.cwd(),\n isBuild: command === 'build',\n isFrameworkPkgByJson(pkgJson) {\n if ([routerPackageName, startPackageName].includes(pkgJson.name)) {\n return false\n }\n\n const peerDependencies = pkgJson['peerDependencies']\n\n if (peerDependencies) {\n const internalResult = corePluginOpts.crawlPackages?.({\n name: pkgJson.name,\n peerDependencies,\n exports: pkgJson.exports,\n })\n if (internalResult) {\n if (internalResult === 'exclude') {\n additionalOptimizeDeps.exclude.add(pkgJson.name)\n } else {\n additionalOptimizeDeps.include.add(pkgJson.name)\n }\n }\n return (\n startPackageName in peerDependencies ||\n routerPackageName in peerDependencies\n )\n }\n return false\n },\n })\n\n return {\n base: viteAppBase,\n // see https://vite.dev/config/shared-options.html#apptype\n // this will prevent vite from injecting middlewares that we don't want\n appType: viteConfig.appType ?? 'custom',\n environments: {\n [VITE_ENVIRONMENT_NAMES.client]: {\n consumer: 'client',\n build: {\n rollupOptions: {\n input: {\n main: ENTRY_POINTS.client,\n },\n },\n outDir: getClientOutputDirectory(viteConfig),\n },\n },\n [VITE_ENVIRONMENT_NAMES.server]: {\n consumer: 'server',\n build: {\n ssr: true,\n rollupOptions: {\n input:\n viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]\n ?.build?.rollupOptions?.input ?? ENTRY_POINTS.server,\n },\n outDir: getServerOutputDirectory(viteConfig),\n commonjsOptions: {\n include: [/node_modules/],\n },\n copyPublicDir:\n viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]\n ?.build?.copyPublicDir ?? false,\n },\n optimizeDeps: {\n exclude: [\n ...Object.values(VIRTUAL_MODULES),\n ...result.optimizeDeps.exclude.sort(),\n ...additionalOptimizeDeps.exclude,\n `@tanstack/${corePluginOpts.framework}-start/server`,\n ],\n include: [\n ...additionalOptimizeDeps.include,\n ...result.optimizeDeps.include.sort(),\n ],\n },\n },\n },\n resolve: {\n noExternal: [\n '@tanstack/start**',\n `@tanstack/${corePluginOpts.framework}-start**`,\n ...Object.values(VIRTUAL_MODULES),\n startPackageName,\n ...result.ssr.noExternal.sort(),\n ],\n dedupe: [startPackageName],\n alias: {\n ...entryAliasConfiguration,\n },\n },\n optimizeDeps: {\n exclude: [\n ...Object.values(VIRTUAL_MODULES),\n startPackageName,\n ...result.optimizeDeps.exclude.sort(),\n ...additionalOptimizeDeps.exclude,\n ],\n include: [...additionalOptimizeDeps.include],\n },\n /* prettier-ignore */\n define: {\n // define is an esbuild function that replaces the any instances of given keys with the given values\n // i.e: __FRAMEWORK_NAME__ can be replaced with JSON.stringify(\"TanStack Start\")\n // This is not the same as injecting environment variables.\n\n ...defineReplaceEnv('TSS_SERVER_FN_BASE', startConfig.serverFns.base),\n ...defineReplaceEnv('TSS_CLIENT_OUTPUT_DIR', getClientOutputDirectory(viteConfig)),\n ...defineReplaceEnv('TSS_APP_BASE', viteAppBase),\n ...(command === 'serve' ? defineReplaceEnv('TSS_SHELL', startConfig.spa?.enabled ? 'true' : 'false') : {}),\n ...defineReplaceEnv('TSS_DEV_SERVER', command === 'serve' ? 'true' : 'false'),\n },\n builder: {\n sharedPlugins: true,\n async buildApp(builder) {\n const client = builder.environments[VITE_ENVIRONMENT_NAMES.client]\n const server = builder.environments[VITE_ENVIRONMENT_NAMES.server]\n\n if (!client) {\n throw new Error('Client environment not found')\n }\n\n if (!server) {\n throw new Error('SSR environment not found')\n }\n\n if (!client.isBuilt) {\n // Build the client bundle first\n await builder.build(client)\n }\n if (!server.isBuilt) {\n // Build the SSR bundle\n await builder.build(server)\n }\n const serverBundle = getBundle(VITE_ENVIRONMENT_NAMES.server)\n await postServerBuild({ builder, startConfig, serverBundle })\n },\n },\n }\n },\n },\n // N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPluginEnv\n startCompilerPlugin(corePluginOpts.framework, {\n client: { envName: VITE_ENVIRONMENT_NAMES.client },\n server: { envName: VITE_ENVIRONMENT_NAMES.server },\n }),\n TanStackServerFnPluginEnv({\n // This is the ID that will be available to look up and import\n // our server function manifest and resolve its module\n manifestVirtualImportId: VIRTUAL_MODULES.serverFnManifest,\n client: {\n getRuntimeCode: () =>\n `import { createClientRpc } from '@tanstack/${corePluginOpts.framework}-start/client'`,\n replacer: (d) => `createClientRpc('${d.functionId}')`,\n envName: VITE_ENVIRONMENT_NAMES.client,\n },\n server: {\n getRuntimeCode: () =>\n `import { createServerRpc } from '@tanstack/${corePluginOpts.framework}-start/server'`,\n replacer: (d) => `createServerRpc('${d.functionId}', ${d.fn})`,\n envName: VITE_ENVIRONMENT_NAMES.server,\n },\n }),\n loadEnvPlugin(),\n startManifestPlugin({\n getClientBundle: () => getBundle(VITE_ENVIRONMENT_NAMES.client),\n }),\n devServerPlugin({ startConfig }),\n {\n name: 'tanstack-start:core:capture-bundle',\n applyToEnvironment(e) {\n return (\n e.name === VITE_ENVIRONMENT_NAMES.client ||\n e.name === VITE_ENVIRONMENT_NAMES.server\n )\n },\n enforce: 'post',\n generateBundle(_options, bundle) {\n const environment = this.environment.name as ViteEnvironmentNames\n if (!Object.values(VITE_ENVIRONMENT_NAMES).includes(environment)) {\n throw new Error(`Unknown environment: ${environment}`)\n }\n capturedBundle[environment] = bundle\n },\n },\n ]\n}\n\nfunction defineReplaceEnv<TKey extends string, TValue extends string>(\n key: TKey,\n value: TValue,\n): { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue } {\n return {\n [`process.env.${key}`]: JSON.stringify(value),\n [`import.meta.env.${key}`]: JSON.stringify(value),\n } as { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue }\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAsCO,SAAS,4BACd,gBACA,iBACqB;AACrB,QAAM,cAAc,iBAAiB,eAAe;AAEpD,QAAM,iBAEF,CAAA;AAEJ,WAAS,UAAU,SAAyD;AAC1E,UAAM,SAAS,eAAe,OAAO;AACrC,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,uCAAuC,OAAO,EAAE;AAAA,IAClE;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,oBAAoB;AAAA,MAClB,GAAG,YAAY;AAAA,MACf,QAAQ,eAAe;AAAA,MACvB,mBAAmB;AAAA,IAA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D,SAAS,uBAAuB;AAAA,MAAA;AAAA,IAClC,CACD;AAAA,IACD,cAAA;AAAA,IACA,oBAAoB;AAAA,MAClB,iBAAiB,MAAM,UAAU,uBAAuB,MAAM;AAAA,IAAA,CAC/D;AAAA,IACD,gBAAgB,EAAE,aAAa;AAAA,IAC/B;AAAA,MACE,MAAM;AAAA,MACN,mBAAmB,GAAG;AACpB,eACE,EAAE,SAAS,uBAAuB,UAClC,EAAE,SAAS,uBAAuB;AAAA,MAEtC;AAAA,MACA,SAAS;AAAA,MACT,eAAe,UAAU,QAAQ;AAC/B,cAAM,cAAc,KAAK,YAAY;AACrC,YAAI,CAAC,OAAO,OAAO,sBAAsB,EAAE,SAAS,WAAW,GAAG;AAChE,gBAAM,IAAI,MAAM,wBAAwB,WAAW,EAAE;AAAA,QACvD;AACA,uBAAe,WAAW,IAAI;AAAA,MAChC;AAAA,IAAA;AAAA,EACF;AAEJ;AAEA,SAAS,iBACP,KACA,OACsE;AACtE,SAAO;AAAA,IACL,CAAC,eAAe,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,IAC5C,CAAC,mBAAmB,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,EAAA;AAEpD;"}
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["../../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { trimPathRight } from '@tanstack/router-core'\nimport { VIRTUAL_MODULES } from '@tanstack/start-server-core'\nimport { TanStackServerFnPluginEnv } from '@tanstack/server-functions-plugin'\nimport * as vite from 'vite'\nimport { crawlFrameworkPkgs } from 'vitefu'\nimport { join } from 'pathe'\nimport { startManifestPlugin } from './start-manifest-plugin/plugin'\nimport { startCompilerPlugin } from './start-compiler-plugin/plugin'\nimport { ENTRY_POINTS, VITE_ENVIRONMENT_NAMES } from './constants'\nimport { tanStackStartRouter } from './start-router-plugin/plugin'\nimport { loadEnvPlugin } from './load-env-plugin/plugin'\nimport { devServerPlugin } from './dev-server-plugin/plugin'\nimport { parseStartConfig } from './schema'\nimport { resolveEntry } from './resolve-entries'\nimport {\n getClientOutputDirectory,\n getServerOutputDirectory,\n} from './output-directory'\nimport { postServerBuild } from './post-server-build'\nimport { createServerFnPlugin } from './create-server-fn-plugin/plugin'\nimport type { ViteEnvironmentNames } from './constants'\nimport type {\n TanStackStartInputConfig,\n TanStackStartOutputConfig,\n} from './schema'\nimport type { PluginOption } from 'vite'\nimport type { CompileStartFrameworkOptions } from './start-compiler-plugin/compilers'\n\nexport interface TanStackStartVitePluginCoreOptions {\n framework: CompileStartFrameworkOptions\n defaultEntryPaths: {\n client: string\n server: string\n start: string\n }\n}\n\nexport interface ResolvedStartConfig {\n root: string\n startFilePath: string | undefined\n routerFilePath: string\n srcDirectory: string\n}\n\nexport type GetConfigFn = () => {\n startConfig: TanStackStartOutputConfig\n resolvedStartConfig: ResolvedStartConfig\n}\nexport function TanStackStartVitePluginCore(\n corePluginOpts: TanStackStartVitePluginCoreOptions,\n startPluginOpts: TanStackStartInputConfig,\n): Array<PluginOption> {\n const resolvedStartConfig: ResolvedStartConfig = {\n root: '',\n startFilePath: undefined,\n routerFilePath: '',\n srcDirectory: '',\n }\n\n let startConfig: TanStackStartOutputConfig | null\n const getConfig: GetConfigFn = () => {\n if (!resolvedStartConfig.root) {\n throw new Error(`Cannot get config before root is resolved`)\n }\n if (!startConfig) {\n startConfig = parseStartConfig(\n startPluginOpts,\n corePluginOpts,\n resolvedStartConfig.root,\n )\n }\n return { startConfig, resolvedStartConfig }\n }\n\n const capturedBundle: Partial<\n Record<ViteEnvironmentNames, vite.Rollup.OutputBundle>\n > = {}\n\n function getBundle(envName: ViteEnvironmentNames): vite.Rollup.OutputBundle {\n const bundle = capturedBundle[envName]\n if (!bundle) {\n throw new Error(`No bundle captured for environment: ${envName}`)\n }\n return bundle\n }\n\n return [\n {\n name: 'tanstack-start-core:config',\n enforce: 'pre',\n async config(viteConfig, { command }) {\n const viteAppBase = trimPathRight(viteConfig.base || '/')\n globalThis.TSS_APP_BASE = viteAppBase\n\n const root = viteConfig.root || process.cwd()\n resolvedStartConfig.root = root\n\n const { startConfig } = getConfig()\n const resolvedSrcDirectory = join(root, startConfig.srcDirectory)\n resolvedStartConfig.srcDirectory = resolvedSrcDirectory\n\n const startFilePath = resolveEntry({\n type: 'start entry',\n configuredEntry: startConfig.start.entry,\n defaultEntry: 'start',\n resolvedSrcDirectory,\n required: false,\n })\n resolvedStartConfig.startFilePath = startFilePath\n\n const routerFilePath = resolveEntry({\n type: 'router entry',\n configuredEntry: startConfig.router.entry,\n defaultEntry: 'router',\n resolvedSrcDirectory,\n required: true,\n })\n resolvedStartConfig.routerFilePath = routerFilePath\n\n const clientEntryPath = resolveEntry({\n type: 'client entry',\n configuredEntry: startConfig.client.entry,\n defaultEntry: 'client',\n resolvedSrcDirectory,\n required: false,\n })\n\n const serverEntryPath = resolveEntry({\n type: 'server entry',\n configuredEntry: startConfig.server.entry,\n defaultEntry: 'server',\n resolvedSrcDirectory,\n required: false,\n })\n\n let clientAlias: string\n if (clientEntryPath) {\n clientAlias = vite.normalizePath(\n path.join('/@fs', path.resolve(root, clientEntryPath)),\n )\n } else {\n clientAlias = corePluginOpts.defaultEntryPaths.client\n }\n\n let serverAlias: string\n if (serverEntryPath) {\n serverAlias = vite.normalizePath(path.resolve(root, serverEntryPath))\n } else {\n serverAlias = corePluginOpts.defaultEntryPaths.server\n }\n\n let startAlias: string\n if (startFilePath) {\n startAlias = vite.normalizePath(path.resolve(root, startFilePath))\n } else {\n startAlias = corePluginOpts.defaultEntryPaths.start\n }\n\n const entryAliasConfiguration: Record<\n (typeof ENTRY_POINTS)[keyof typeof ENTRY_POINTS],\n string\n > = {\n [ENTRY_POINTS.start]: startAlias,\n [ENTRY_POINTS.router]: routerFilePath,\n [ENTRY_POINTS.client]: clientAlias,\n [ENTRY_POINTS.server]: serverAlias,\n }\n\n const startPackageName =\n `@tanstack/${corePluginOpts.framework}-start` as const\n\n // crawl packages that have start in \"peerDependencies\"\n // see https://github.com/svitejs/vitefu/blob/d8d82fa121e3b2215ba437107093c77bde51b63b/src/index.js#L95-L101\n\n // this is currently uncached; could be implemented similarly as vite handles lock file changes\n // see https://github.com/vitejs/vite/blob/557f797d29422027e8c451ca50dd84bf8c41b5f0/packages/vite/src/node/optimizer/index.ts#L1282\n\n const crawlFrameworkPkgsResult = await crawlFrameworkPkgs({\n root: process.cwd(),\n isBuild: command === 'build',\n isFrameworkPkgByJson(pkgJson) {\n const peerDependencies = pkgJson['peerDependencies']\n\n if (peerDependencies) {\n return startPackageName in peerDependencies\n }\n\n return false\n },\n })\n\n return {\n base: viteAppBase,\n // see https://vite.dev/config/shared-options.html#apptype\n // this will prevent vite from injecting middlewares that we don't want\n appType: viteConfig.appType ?? 'custom',\n environments: {\n [VITE_ENVIRONMENT_NAMES.client]: {\n consumer: 'client',\n build: {\n rollupOptions: {\n input: {\n main: ENTRY_POINTS.client,\n },\n },\n outDir: getClientOutputDirectory(viteConfig),\n },\n },\n [VITE_ENVIRONMENT_NAMES.server]: {\n consumer: 'server',\n\n build: {\n ssr: true,\n rollupOptions: {\n input:\n viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]\n ?.build?.rollupOptions?.input ?? ENTRY_POINTS.server,\n },\n outDir: getServerOutputDirectory(viteConfig),\n commonjsOptions: {\n include: [/node_modules/],\n },\n copyPublicDir:\n viteConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]\n ?.build?.copyPublicDir ?? false,\n },\n },\n },\n\n resolve: {\n noExternal: [\n // ENTRY_POINTS.start,\n '@tanstack/start**',\n `@tanstack/${corePluginOpts.framework}-start**`,\n ...crawlFrameworkPkgsResult.ssr.noExternal.sort(),\n ],\n alias: {\n ...entryAliasConfiguration,\n },\n },\n /* prettier-ignore */\n define: {\n // define is an esbuild function that replaces the any instances of given keys with the given values\n // i.e: __FRAMEWORK_NAME__ can be replaced with JSON.stringify(\"TanStack Start\")\n // This is not the same as injecting environment variables.\n\n ...defineReplaceEnv('TSS_SERVER_FN_BASE', startConfig.serverFns.base),\n ...defineReplaceEnv('TSS_CLIENT_OUTPUT_DIR', getClientOutputDirectory(viteConfig)),\n ...defineReplaceEnv('TSS_APP_BASE', viteAppBase),\n ...(command === 'serve' ? defineReplaceEnv('TSS_SHELL', startConfig.spa?.enabled ? 'true' : 'false') : {}),\n ...defineReplaceEnv('TSS_DEV_SERVER', command === 'serve' ? 'true' : 'false'),\n },\n builder: {\n sharedPlugins: true,\n async buildApp(builder) {\n const client = builder.environments[VITE_ENVIRONMENT_NAMES.client]\n const server = builder.environments[VITE_ENVIRONMENT_NAMES.server]\n\n if (!client) {\n throw new Error('Client environment not found')\n }\n\n if (!server) {\n throw new Error('SSR environment not found')\n }\n\n if (!client.isBuilt) {\n // Build the client bundle first\n await builder.build(client)\n }\n if (!server.isBuilt) {\n // Build the SSR bundle\n await builder.build(server)\n }\n const serverBundle = getBundle(VITE_ENVIRONMENT_NAMES.server)\n await postServerBuild({ builder, startConfig, serverBundle })\n },\n },\n }\n },\n },\n tanStackStartRouter(startPluginOpts, getConfig, corePluginOpts),\n // N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPluginEnv\n startCompilerPlugin(corePluginOpts.framework),\n createServerFnPlugin(corePluginOpts.framework),\n\n TanStackServerFnPluginEnv({\n // This is the ID that will be available to look up and import\n // our server function manifest and resolve its module\n manifestVirtualImportId: VIRTUAL_MODULES.serverFnManifest,\n client: {\n getRuntimeCode: () =>\n `import { createClientRpc } from '@tanstack/${corePluginOpts.framework}-start/client'`,\n replacer: (d) => `createClientRpc('${d.functionId}')`,\n envName: VITE_ENVIRONMENT_NAMES.client,\n },\n server: {\n getRuntimeCode: () =>\n `import { createServerRpc } from '@tanstack/${corePluginOpts.framework}-start/server'`,\n replacer: (d) => `createServerRpc('${d.functionId}', ${d.fn})`,\n envName: VITE_ENVIRONMENT_NAMES.server,\n },\n }),\n loadEnvPlugin(),\n startManifestPlugin({\n getClientBundle: () => getBundle(VITE_ENVIRONMENT_NAMES.client),\n }),\n devServerPlugin({ getConfig }),\n {\n name: 'tanstack-start:core:capture-bundle',\n applyToEnvironment(e) {\n return (\n e.name === VITE_ENVIRONMENT_NAMES.client ||\n e.name === VITE_ENVIRONMENT_NAMES.server\n )\n },\n enforce: 'post',\n generateBundle(_options, bundle) {\n const environment = this.environment.name as ViteEnvironmentNames\n if (!Object.values(VITE_ENVIRONMENT_NAMES).includes(environment)) {\n throw new Error(`Unknown environment: ${environment}`)\n }\n capturedBundle[environment] = bundle\n },\n },\n ]\n}\n\nfunction defineReplaceEnv<TKey extends string, TValue extends string>(\n key: TKey,\n value: TValue,\n): { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue } {\n return {\n [`process.env.${key}`]: JSON.stringify(value),\n [`import.meta.env.${key}`]: JSON.stringify(value),\n } as { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue }\n}\n"],"names":["startConfig"],"mappings":";;;;;;;;;;;;;;;;;;AAiDO,SAAS,4BACd,gBACA,iBACqB;AACrB,QAAM,sBAA2C;AAAA,IAC/C,MAAM;AAAA,IACN,eAAe;AAAA,IACf,gBAAgB;AAAA,IAChB,cAAc;AAAA,EAAA;AAGhB,MAAI;AACJ,QAAM,YAAyB,MAAM;AACnC,QAAI,CAAC,oBAAoB,MAAM;AAC7B,YAAM,IAAI,MAAM,2CAA2C;AAAA,IAC7D;AACA,QAAI,CAAC,aAAa;AAChB,oBAAc;AAAA,QACZ;AAAA,QACA;AAAA,QACA,oBAAoB;AAAA,MAAA;AAAA,IAExB;AACA,WAAO,EAAE,aAAa,oBAAA;AAAA,EACxB;AAEA,QAAM,iBAEF,CAAA;AAEJ,WAAS,UAAU,SAAyD;AAC1E,UAAM,SAAS,eAAe,OAAO;AACrC,QAAI,CAAC,QAAQ;AACX,YAAM,IAAI,MAAM,uCAAuC,OAAO,EAAE;AAAA,IAClE;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL;AAAA,MACE,MAAM;AAAA,MACN,SAAS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}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-entries.js","sources":["../../src/resolve-entries.ts"],"sourcesContent":["import { resolveModulePath } from 'exsolve'\n\ninterface ResolveModuleOptions {\n baseName: string\n from: string\n}\nfunction resolveModule(opts: ResolveModuleOptions): string | undefined {\n let baseName = opts.baseName\n if (!baseName.startsWith('./')) {\n baseName = `./${baseName}`\n }\n return resolveModulePath(baseName, {\n from: opts.from,\n extensions: ['.ts', '.js', '.mts', '.mjs', '.tsx', '.jsx'],\n try: true,\n })\n}\n\nexport function resolveEntry<\n TRequired extends boolean,\n TReturn = TRequired extends true ? string : string | undefined,\n>(opts: {\n type: string\n configuredEntry?: string\n defaultEntry: string\n resolvedSrcDirectory: string\n
|
|
1
|
+
{"version":3,"file":"resolve-entries.js","sources":["../../src/resolve-entries.ts"],"sourcesContent":["import { resolveModulePath } from 'exsolve'\n\ninterface ResolveModuleOptions {\n baseName: string\n from: string\n}\nfunction resolveModule(opts: ResolveModuleOptions): string | undefined {\n let baseName = opts.baseName\n if (!baseName.startsWith('./')) {\n baseName = `./${baseName}`\n }\n return resolveModulePath(baseName, {\n from: opts.from,\n extensions: ['.ts', '.js', '.mts', '.mjs', '.tsx', '.jsx'],\n try: true,\n })\n}\n\nexport function resolveEntry<\n TRequired extends boolean,\n TReturn = TRequired extends true ? string : string | undefined,\n>(opts: {\n type: string\n configuredEntry?: string\n defaultEntry: string\n resolvedSrcDirectory: string\n required: TRequired\n}): TReturn {\n let resolveOptions: ResolveModuleOptions\n\n // if entry was not configured, use default relative to srcDirectory\n if (!opts.configuredEntry) {\n resolveOptions = {\n baseName: opts.defaultEntry,\n from: opts.resolvedSrcDirectory,\n }\n } else {\n resolveOptions = {\n baseName: opts.configuredEntry,\n from: opts.resolvedSrcDirectory,\n }\n }\n\n const resolvedEntry = resolveModule(resolveOptions)\n if (opts.required && !resolvedEntry) {\n throw new Error(\n `Could not resolve entry for ${opts.type}: ${resolveOptions.baseName} in ${resolveOptions.from}`,\n )\n }\n return resolvedEntry as TReturn\n}\n"],"names":[],"mappings":";AAMA,SAAS,cAAc,MAAgD;AACrE,MAAI,WAAW,KAAK;AACpB,MAAI,CAAC,SAAS,WAAW,IAAI,GAAG;AAC9B,eAAW,KAAK,QAAQ;AAAA,EAC1B;AACA,SAAO,kBAAkB,UAAU;AAAA,IACjC,MAAM,KAAK;AAAA,IACX,YAAY,CAAC,OAAO,OAAO,QAAQ,QAAQ,QAAQ,MAAM;AAAA,IACzD,KAAK;AAAA,EAAA,CACN;AACH;AAEO,SAAS,aAGd,MAMU;AACV,MAAI;AAGJ,MAAI,CAAC,KAAK,iBAAiB;AACzB,qBAAiB;AAAA,MACf,UAAU,KAAK;AAAA,MACf,MAAM,KAAK;AAAA,IAAA;AAAA,EAEf,OAAO;AACL,qBAAiB;AAAA,MACf,UAAU,KAAK;AAAA,MACf,MAAM,KAAK;AAAA,IAAA;AAAA,EAEf;AAEA,QAAM,gBAAgB,cAAc,cAAc;AAClD,MAAI,KAAK,YAAY,CAAC,eAAe;AACnC,UAAM,IAAI;AAAA,MACR,+BAA+B,KAAK,IAAI,KAAK,eAAe,QAAQ,OAAO,eAAe,IAAI;AAAA,IAAA;AAAA,EAElG;AACA,SAAO;AACT;"}
|