@tanstack/start-plugin-core 1.121.0-alpha.8 → 1.121.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/cjs/compilers.cjs +24 -10
- package/dist/cjs/compilers.cjs.map +1 -1
- package/dist/cjs/constants.cjs +10 -0
- package/dist/cjs/constants.cjs.map +1 -1
- package/dist/cjs/constants.d.cts +2 -0
- package/dist/cjs/debug.cjs +5 -0
- package/dist/cjs/debug.cjs.map +1 -0
- package/dist/cjs/debug.d.cts +1 -0
- package/dist/cjs/{extractHtmlScripts.cjs → dev-server-plugin/extract-html-scripts.cjs} +1 -1
- package/dist/cjs/dev-server-plugin/extract-html-scripts.cjs.map +1 -0
- package/dist/cjs/{nitro/dev-server-plugin.cjs → dev-server-plugin/plugin.cjs} +2 -2
- package/dist/cjs/dev-server-plugin/plugin.cjs.map +1 -0
- package/dist/cjs/load-env-plugin/plugin.cjs +34 -0
- package/dist/cjs/load-env-plugin/plugin.cjs.map +1 -0
- package/dist/cjs/load-env-plugin/plugin.d.cts +3 -0
- package/dist/cjs/{build-sitemap.cjs → nitro-plugin/build-sitemap.cjs} +12 -10
- package/dist/cjs/nitro-plugin/build-sitemap.cjs.map +1 -0
- package/dist/cjs/{build-sitemap.d.cts → nitro-plugin/build-sitemap.d.cts} +2 -2
- package/dist/cjs/{nitro/nitro-plugin.cjs → nitro-plugin/plugin.cjs} +79 -65
- package/dist/cjs/nitro-plugin/plugin.cjs.map +1 -0
- package/dist/cjs/{prerender.cjs → nitro-plugin/prerender.cjs} +18 -14
- package/dist/cjs/nitro-plugin/prerender.cjs.map +1 -0
- package/dist/cjs/{prerender.d.cts → nitro-plugin/prerender.d.cts} +1 -1
- package/dist/cjs/nitro-plugin/queue.cjs.map +1 -0
- package/dist/cjs/plugin.cjs +50 -38
- package/dist/cjs/plugin.cjs.map +1 -1
- package/dist/cjs/plugin.d.cts +14 -2657
- package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs +66 -0
- package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs.map +1 -0
- package/dist/cjs/resolve-virtual-entries-plugin/plugin.d.cts +3 -0
- package/dist/cjs/schema.cjs +5 -5
- package/dist/cjs/schema.cjs.map +1 -1
- package/dist/cjs/schema.d.cts +32 -16
- package/dist/cjs/start-compiler-plugin.cjs +21 -19
- package/dist/cjs/start-compiler-plugin.cjs.map +1 -1
- package/dist/cjs/start-compiler-plugin.d.cts +1 -1
- package/dist/cjs/start-manifest-plugin/plugin.cjs +182 -0
- package/dist/cjs/start-manifest-plugin/plugin.cjs.map +1 -0
- package/dist/{esm/routesManifestPlugin.d.ts → cjs/start-manifest-plugin/plugin.d.cts} +1 -1
- package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs +39 -0
- package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs.map +1 -0
- package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.d.cts +6 -0
- package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs +121 -0
- package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs.map +1 -0
- package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.d.cts +2 -0
- package/dist/cjs/start-router-plugin/plugin.cjs +21 -0
- package/dist/cjs/start-router-plugin/plugin.cjs.map +1 -0
- package/dist/cjs/start-router-plugin/plugin.d.cts +3 -0
- package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs +72 -0
- package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs.map +1 -0
- package/dist/cjs/start-router-plugin/route-tree-client-plugin.d.cts +6 -0
- package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs +30 -0
- package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs.map +1 -0
- package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.d.cts +4 -0
- package/dist/cjs/utils.cjs +11 -0
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +7 -0
- package/dist/esm/compilers.js +24 -10
- package/dist/esm/compilers.js.map +1 -1
- package/dist/esm/constants.d.ts +2 -0
- package/dist/esm/constants.js +10 -0
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/debug.d.ts +1 -0
- package/dist/esm/debug.js +5 -0
- package/dist/esm/debug.js.map +1 -0
- package/dist/esm/{extractHtmlScripts.js → dev-server-plugin/extract-html-scripts.js} +1 -1
- package/dist/esm/dev-server-plugin/extract-html-scripts.js.map +1 -0
- package/dist/esm/{nitro/dev-server-plugin.js → dev-server-plugin/plugin.js} +2 -2
- package/dist/esm/dev-server-plugin/plugin.js.map +1 -0
- package/dist/esm/load-env-plugin/plugin.d.ts +3 -0
- package/dist/esm/load-env-plugin/plugin.js +17 -0
- package/dist/esm/load-env-plugin/plugin.js.map +1 -0
- package/dist/esm/{build-sitemap.d.ts → nitro-plugin/build-sitemap.d.ts} +2 -2
- package/dist/esm/{build-sitemap.js → nitro-plugin/build-sitemap.js} +9 -7
- package/dist/esm/nitro-plugin/build-sitemap.js.map +1 -0
- package/dist/esm/nitro-plugin/plugin.js +181 -0
- package/dist/esm/nitro-plugin/plugin.js.map +1 -0
- package/dist/esm/{prerender.d.ts → nitro-plugin/prerender.d.ts} +1 -1
- package/dist/esm/{prerender.js → nitro-plugin/prerender.js} +15 -11
- package/dist/esm/nitro-plugin/prerender.js.map +1 -0
- package/dist/esm/nitro-plugin/queue.js.map +1 -0
- package/dist/esm/plugin.d.ts +14 -2657
- package/dist/esm/plugin.js +51 -39
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/resolve-virtual-entries-plugin/plugin.d.ts +3 -0
- package/dist/esm/resolve-virtual-entries-plugin/plugin.js +49 -0
- package/dist/esm/resolve-virtual-entries-plugin/plugin.js.map +1 -0
- package/dist/esm/schema.d.ts +32 -16
- package/dist/esm/start-compiler-plugin.d.ts +1 -1
- package/dist/esm/start-compiler-plugin.js +21 -19
- package/dist/esm/start-compiler-plugin.js.map +1 -1
- package/dist/{cjs/routesManifestPlugin.d.cts → esm/start-manifest-plugin/plugin.d.ts} +1 -1
- package/dist/esm/start-manifest-plugin/plugin.js +182 -0
- package/dist/esm/start-manifest-plugin/plugin.js.map +1 -0
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.d.ts +6 -0
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js +39 -0
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js.map +1 -0
- package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.d.ts +2 -0
- package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js +121 -0
- package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js.map +1 -0
- package/dist/esm/start-router-plugin/plugin.d.ts +3 -0
- package/dist/esm/start-router-plugin/plugin.js +21 -0
- package/dist/esm/start-router-plugin/plugin.js.map +1 -0
- package/dist/esm/start-router-plugin/route-tree-client-plugin.d.ts +6 -0
- package/dist/esm/start-router-plugin/route-tree-client-plugin.js +55 -0
- package/dist/esm/start-router-plugin/route-tree-client-plugin.js.map +1 -0
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.d.ts +4 -0
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js +30 -0
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js.map +1 -0
- package/dist/esm/utils.d.ts +7 -0
- package/dist/esm/utils.js +11 -0
- package/dist/esm/utils.js.map +1 -1
- package/package.json +8 -7
- package/src/compilers.ts +31 -131
- package/src/constants.ts +10 -0
- package/src/debug.ts +3 -0
- package/src/{nitro/dev-server-plugin.ts → dev-server-plugin/plugin.ts} +11 -1
- package/src/global.d.ts +8 -0
- package/src/load-env-plugin/plugin.ts +17 -0
- package/src/{build-sitemap.ts → nitro-plugin/build-sitemap.ts} +11 -8
- package/src/nitro-plugin/plugin.ts +244 -0
- package/src/{prerender.ts → nitro-plugin/prerender.ts} +17 -13
- package/src/plugin.ts +63 -41
- package/src/resolve-virtual-entries-plugin/plugin.ts +63 -0
- package/src/start-compiler-plugin.ts +25 -25
- package/src/start-manifest-plugin/plugin.ts +249 -0
- package/src/start-router-plugin/generator-plugins/routes-manifest-plugin.ts +43 -0
- package/src/start-router-plugin/generator-plugins/server-routes-plugin.ts +138 -0
- package/src/start-router-plugin/plugin.ts +35 -0
- package/src/start-router-plugin/route-tree-client-plugin.ts +76 -0
- package/src/start-router-plugin/virtual-route-tree-plugin.ts +30 -0
- package/src/utils.ts +11 -0
- package/dist/cjs/build-sitemap.cjs.map +0 -1
- package/dist/cjs/extractHtmlScripts.cjs.map +0 -1
- package/dist/cjs/nitro/build-nitro.cjs +0 -18
- package/dist/cjs/nitro/build-nitro.cjs.map +0 -1
- package/dist/cjs/nitro/build-nitro.d.cts +0 -2
- package/dist/cjs/nitro/dev-server-plugin.cjs.map +0 -1
- package/dist/cjs/nitro/nitro-plugin.cjs.map +0 -1
- package/dist/cjs/prerender.cjs.map +0 -1
- package/dist/cjs/queue.cjs.map +0 -1
- package/dist/cjs/routesManifestPlugin.cjs +0 -168
- package/dist/cjs/routesManifestPlugin.cjs.map +0 -1
- package/dist/cjs/start-server-routes-plugin/config.d.cts +0 -49
- package/dist/cjs/start-server-routes-plugin/plugin.cjs +0 -613
- package/dist/cjs/start-server-routes-plugin/plugin.cjs.map +0 -1
- package/dist/cjs/start-server-routes-plugin/plugin.d.cts +0 -3
- package/dist/cjs/start-server-routes-plugin/template.cjs +0 -111
- package/dist/cjs/start-server-routes-plugin/template.cjs.map +0 -1
- package/dist/cjs/start-server-routes-plugin/template.d.cts +0 -34
- package/dist/esm/build-sitemap.js.map +0 -1
- package/dist/esm/extractHtmlScripts.js.map +0 -1
- package/dist/esm/nitro/build-nitro.d.ts +0 -2
- package/dist/esm/nitro/build-nitro.js +0 -18
- package/dist/esm/nitro/build-nitro.js.map +0 -1
- package/dist/esm/nitro/dev-server-plugin.js.map +0 -1
- package/dist/esm/nitro/nitro-plugin.js +0 -167
- package/dist/esm/nitro/nitro-plugin.js.map +0 -1
- package/dist/esm/prerender.js.map +0 -1
- package/dist/esm/queue.js.map +0 -1
- package/dist/esm/routesManifestPlugin.js +0 -168
- package/dist/esm/routesManifestPlugin.js.map +0 -1
- package/dist/esm/start-server-routes-plugin/config.d.ts +0 -49
- package/dist/esm/start-server-routes-plugin/plugin.d.ts +0 -3
- package/dist/esm/start-server-routes-plugin/plugin.js +0 -613
- package/dist/esm/start-server-routes-plugin/plugin.js.map +0 -1
- package/dist/esm/start-server-routes-plugin/template.d.ts +0 -34
- package/dist/esm/start-server-routes-plugin/template.js +0 -111
- package/dist/esm/start-server-routes-plugin/template.js.map +0 -1
- package/src/nitro/build-nitro.ts +0 -27
- package/src/nitro/nitro-plugin.ts +0 -195
- package/src/routesManifestPlugin.ts +0 -220
- package/src/start-server-routes-plugin/config.ts +0 -8
- package/src/start-server-routes-plugin/plugin.ts +0 -899
- package/src/start-server-routes-plugin/template.ts +0 -164
- /package/dist/cjs/{extractHtmlScripts.d.cts → dev-server-plugin/extract-html-scripts.d.cts} +0 -0
- /package/dist/cjs/{nitro/dev-server-plugin.d.cts → dev-server-plugin/plugin.d.cts} +0 -0
- /package/dist/cjs/{nitro/nitro-plugin.d.cts → nitro-plugin/plugin.d.cts} +0 -0
- /package/dist/cjs/{queue.cjs → nitro-plugin/queue.cjs} +0 -0
- /package/dist/cjs/{queue.d.cts → nitro-plugin/queue.d.cts} +0 -0
- /package/dist/esm/{extractHtmlScripts.d.ts → dev-server-plugin/extract-html-scripts.d.ts} +0 -0
- /package/dist/esm/{nitro/dev-server-plugin.d.ts → dev-server-plugin/plugin.d.ts} +0 -0
- /package/dist/esm/{nitro/nitro-plugin.d.ts → nitro-plugin/plugin.d.ts} +0 -0
- /package/dist/esm/{queue.d.ts → nitro-plugin/queue.d.ts} +0 -0
- /package/dist/esm/{queue.js → nitro-plugin/queue.js} +0 -0
- /package/src/{extractHtmlScripts.ts → dev-server-plugin/extract-html-scripts.ts} +0 -0
- /package/src/{queue.ts → nitro-plugin/queue.ts} +0 -0
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const path = require("node:path");
|
|
4
|
-
const
|
|
4
|
+
const node_fs = require("node:fs");
|
|
5
5
|
const nitropack = require("nitropack");
|
|
6
6
|
const pathe = require("pathe");
|
|
7
|
-
const plugin = require("../plugin.cjs");
|
|
8
|
-
const prerender = require("../prerender.cjs");
|
|
9
7
|
const constants = require("../constants.cjs");
|
|
10
|
-
const buildSitemap = require("
|
|
11
|
-
const
|
|
12
|
-
const buildNitro = require("./build-nitro.cjs");
|
|
8
|
+
const buildSitemap = require("./build-sitemap.cjs");
|
|
9
|
+
const prerender = require("./prerender.cjs");
|
|
13
10
|
function nitroPlugin(options, getSsrBundle) {
|
|
14
11
|
const buildPreset = process.env["START_TARGET"] ?? options.target;
|
|
15
12
|
return [
|
|
16
|
-
devServerPlugin.devServerPlugin(),
|
|
17
13
|
{
|
|
18
14
|
name: "tanstack-vite-plugin-nitro",
|
|
19
15
|
configEnvironment(name) {
|
|
@@ -38,85 +34,54 @@ function nitroPlugin(options, getSsrBundle) {
|
|
|
38
34
|
builder: {
|
|
39
35
|
sharedPlugins: true,
|
|
40
36
|
async buildApp(builder) {
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
if (!clientEnv) {
|
|
37
|
+
const client = builder.environments[constants.VITE_ENVIRONMENT_NAMES.client];
|
|
38
|
+
const server = builder.environments[constants.VITE_ENVIRONMENT_NAMES.server];
|
|
39
|
+
if (!client) {
|
|
45
40
|
throw new Error("Client environment not found");
|
|
46
41
|
}
|
|
47
|
-
if (!
|
|
42
|
+
if (!server) {
|
|
48
43
|
throw new Error("SSR environment not found");
|
|
49
44
|
}
|
|
50
|
-
const clientOutputDir = pathe.resolve(options.root,
|
|
51
|
-
|
|
52
|
-
await builder.build(
|
|
53
|
-
await builder.build(
|
|
45
|
+
const clientOutputDir = pathe.resolve(options.root, constants.CLIENT_DIST_DIR);
|
|
46
|
+
node_fs.rmSync(clientOutputDir, { recursive: true, force: true });
|
|
47
|
+
await builder.build(client);
|
|
48
|
+
await builder.build(server);
|
|
54
49
|
const nitroConfig = {
|
|
55
50
|
dev: false,
|
|
56
|
-
// TODO do we need this? should this be made configurable?
|
|
51
|
+
// TODO: do we need this? should this be made configurable?
|
|
57
52
|
compatibilityDate: "2024-11-19",
|
|
58
53
|
logLevel: 3,
|
|
59
54
|
preset: buildPreset,
|
|
55
|
+
baseURL: globalThis.TSS_APP_BASE,
|
|
60
56
|
publicAssets: [
|
|
61
57
|
{
|
|
62
|
-
dir: path.resolve(options.root,
|
|
58
|
+
dir: path.resolve(options.root, constants.CLIENT_DIST_DIR),
|
|
59
|
+
baseURL: "/",
|
|
60
|
+
maxAge: 31536e3
|
|
61
|
+
// 1 year
|
|
63
62
|
}
|
|
64
63
|
],
|
|
65
64
|
typescript: {
|
|
66
65
|
generateTsConfig: false
|
|
67
66
|
},
|
|
68
67
|
prerender: void 0,
|
|
69
|
-
renderer:
|
|
68
|
+
renderer: constants.SSR_ENTRY_FILE,
|
|
69
|
+
plugins: [],
|
|
70
|
+
// Nitro's plugins
|
|
71
|
+
appConfigFiles: [],
|
|
72
|
+
scanDirs: [],
|
|
73
|
+
imports: false,
|
|
74
|
+
// unjs/unimport for global/magic imports
|
|
70
75
|
rollupConfig: {
|
|
71
76
|
plugins: [virtualBundlePlugin(getSsrBundle())]
|
|
77
|
+
},
|
|
78
|
+
virtual: {
|
|
79
|
+
// This is Nitro's way of defining virtual modules
|
|
80
|
+
// Should we define the ones for TanStack Start's here as well?
|
|
72
81
|
}
|
|
73
82
|
};
|
|
74
83
|
const nitro = await nitropack.createNitro(nitroConfig);
|
|
75
|
-
await
|
|
76
|
-
if (((_a = options.prerender) == null ? void 0 : _a.enabled) !== false) {
|
|
77
|
-
options.prerender = {
|
|
78
|
-
...options.prerender,
|
|
79
|
-
enabled: options.pages.some(
|
|
80
|
-
(d) => {
|
|
81
|
-
var _a2;
|
|
82
|
-
return typeof d === "string" ? false : !!((_a2 = d.prerender) == null ? void 0 : _a2.enabled);
|
|
83
|
-
}
|
|
84
|
-
)
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
if ((_b = options.spa) == null ? void 0 : _b.enabled) {
|
|
88
|
-
options.prerender = {
|
|
89
|
-
...options.prerender,
|
|
90
|
-
enabled: true
|
|
91
|
-
};
|
|
92
|
-
const maskUrl = new URL(
|
|
93
|
-
options.spa.maskPath,
|
|
94
|
-
"http://localhost"
|
|
95
|
-
);
|
|
96
|
-
maskUrl.searchParams.set("__TSS_SHELL", "true");
|
|
97
|
-
options.pages.push({
|
|
98
|
-
path: maskUrl.toString().replace("http://localhost", ""),
|
|
99
|
-
prerender: options.spa.prerender,
|
|
100
|
-
sitemap: {
|
|
101
|
-
exclude: true
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
if (options.prerender.enabled) {
|
|
106
|
-
await prerender.prerender({
|
|
107
|
-
options,
|
|
108
|
-
nitro,
|
|
109
|
-
builder
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
if (options.pages.length) {
|
|
113
|
-
await buildSitemap.buildSitemap({
|
|
114
|
-
options,
|
|
115
|
-
publicDir: nitro.options.output.publicDir
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
console.log(`
|
|
119
|
-
✅ Client and server bundles successfully built.`);
|
|
84
|
+
await buildNitroApp(builder, nitro, options);
|
|
120
85
|
}
|
|
121
86
|
}
|
|
122
87
|
};
|
|
@@ -124,6 +89,55 @@ function nitroPlugin(options, getSsrBundle) {
|
|
|
124
89
|
}
|
|
125
90
|
];
|
|
126
91
|
}
|
|
92
|
+
async function buildNitroApp(builder, nitro, options) {
|
|
93
|
+
var _a, _b;
|
|
94
|
+
await nitropack.prepare(nitro);
|
|
95
|
+
await nitropack.copyPublicAssets(nitro);
|
|
96
|
+
if (((_a = options.prerender) == null ? void 0 : _a.enabled) !== false) {
|
|
97
|
+
options.prerender = {
|
|
98
|
+
...options.prerender,
|
|
99
|
+
enabled: options.pages.some(
|
|
100
|
+
(d) => {
|
|
101
|
+
var _a2;
|
|
102
|
+
return typeof d === "string" ? false : !!((_a2 = d.prerender) == null ? void 0 : _a2.enabled);
|
|
103
|
+
}
|
|
104
|
+
)
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
if ((_b = options.spa) == null ? void 0 : _b.enabled) {
|
|
108
|
+
options.prerender = {
|
|
109
|
+
...options.prerender,
|
|
110
|
+
enabled: true
|
|
111
|
+
};
|
|
112
|
+
const maskUrl = new URL(options.spa.maskPath, "http://localhost");
|
|
113
|
+
maskUrl.searchParams.set("__TSS_SHELL", "true");
|
|
114
|
+
options.pages.push({
|
|
115
|
+
path: maskUrl.toString().replace("http://localhost", ""),
|
|
116
|
+
prerender: options.spa.prerender,
|
|
117
|
+
sitemap: {
|
|
118
|
+
exclude: true
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
if (options.prerender.enabled) {
|
|
123
|
+
await prerender.prerender({
|
|
124
|
+
options,
|
|
125
|
+
nitro,
|
|
126
|
+
builder
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
if (options.pages.length) {
|
|
130
|
+
buildSitemap.buildSitemap({
|
|
131
|
+
options,
|
|
132
|
+
publicDir: nitro.options.output.publicDir
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
await nitropack.build(nitro);
|
|
136
|
+
await nitro.close();
|
|
137
|
+
nitro.logger.success(
|
|
138
|
+
"Client and Server bundles for TanStack Start have been successfully built."
|
|
139
|
+
);
|
|
140
|
+
}
|
|
127
141
|
function virtualBundlePlugin(ssrBundle) {
|
|
128
142
|
const _modules = /* @__PURE__ */ new Map();
|
|
129
143
|
for (const [fileName, content] of Object.entries(ssrBundle)) {
|
|
@@ -164,4 +178,4 @@ function virtualBundlePlugin(ssrBundle) {
|
|
|
164
178
|
};
|
|
165
179
|
}
|
|
166
180
|
exports.nitroPlugin = nitroPlugin;
|
|
167
|
-
//# sourceMappingURL=
|
|
181
|
+
//# sourceMappingURL=plugin.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs","sources":["../../../src/nitro-plugin/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { rmSync } from 'node:fs'\nimport { build, copyPublicAssets, createNitro, prepare } from 'nitropack'\nimport { dirname, resolve } from 'pathe'\nimport {\n CLIENT_DIST_DIR,\n SSR_ENTRY_FILE,\n VITE_ENVIRONMENT_NAMES,\n} from '../constants'\nimport { buildSitemap } from './build-sitemap'\nimport { prerender } from './prerender'\nimport type {\n EnvironmentOptions,\n PluginOption,\n Rollup,\n ViteBuilder,\n} from 'vite'\nimport type { Nitro, NitroConfig } from 'nitropack'\nimport type { TanStackStartOutputConfig } from '../plugin'\n\nexport function nitroPlugin(\n options: TanStackStartOutputConfig,\n getSsrBundle: () => Rollup.OutputBundle,\n): Array<PluginOption> {\n const buildPreset =\n process.env['START_TARGET'] ?? (options.target as string | undefined)\n return [\n {\n name: 'tanstack-vite-plugin-nitro',\n configEnvironment(name) {\n if (name === VITE_ENVIRONMENT_NAMES.server) {\n return {\n build: {\n commonjsOptions: {\n include: [],\n },\n ssr: true,\n sourcemap: true,\n rollupOptions: {\n input: '/~start/server-entry',\n },\n },\n } satisfies EnvironmentOptions\n }\n\n return null\n },\n config() {\n return {\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 // Build the client bundle\n // i.e client entry file with `hydrateRoot(...)`\n const clientOutputDir = resolve(options.root, CLIENT_DIST_DIR)\n rmSync(clientOutputDir, { recursive: true, force: true })\n await builder.build(client)\n\n // Build the SSR bundle\n await builder.build(server)\n\n const nitroConfig: NitroConfig = {\n dev: false,\n // TODO: do we need this? should this be made configurable?\n compatibilityDate: '2024-11-19',\n logLevel: 3,\n preset: buildPreset,\n baseURL: globalThis.TSS_APP_BASE,\n publicAssets: [\n {\n dir: path.resolve(options.root, CLIENT_DIST_DIR),\n baseURL: '/',\n maxAge: 31536000, // 1 year\n },\n ],\n typescript: {\n generateTsConfig: false,\n },\n prerender: undefined,\n renderer: SSR_ENTRY_FILE,\n plugins: [], // Nitro's plugins\n appConfigFiles: [],\n scanDirs: [],\n imports: false, // unjs/unimport for global/magic imports\n rollupConfig: {\n plugins: [virtualBundlePlugin(getSsrBundle())],\n },\n virtual: {\n // This is Nitro's way of defining virtual modules\n // Should we define the ones for TanStack Start's here as well?\n },\n }\n\n const nitro = await createNitro(nitroConfig)\n\n await buildNitroApp(builder, nitro, options)\n },\n },\n }\n },\n },\n ]\n}\n\n/**\n * Correctly co-ordinates the nitro app build process to make sure that the\n * app is built, while also correctly handling the prerendering and sitemap\n * generation and including their outputs in the final build.\n */\nasync function buildNitroApp(\n builder: ViteBuilder,\n nitro: Nitro,\n options: TanStackStartOutputConfig,\n) {\n // Cleans the public and server directories for a fresh build\n // i.e the `.output/public` and `.output/server` directories\n await prepare(nitro)\n\n // Creates the `.output/public` directory and copies the public assets\n await copyPublicAssets(nitro)\n\n // If the user has not set a prerender option, we need to set it to true\n // if the pages array is not empty and has sub options requiring for prerendering\n if (options.prerender?.enabled !== false) {\n options.prerender = {\n ...options.prerender,\n enabled: options.pages.some((d) =>\n typeof d === 'string' ? false : !!d.prerender?.enabled,\n ),\n }\n }\n\n // Setup the options for prerendering the SPA shell (i.e `src/routes/__root.tsx`)\n if (options.spa?.enabled) {\n options.prerender = {\n ...options.prerender,\n enabled: true,\n }\n\n const maskUrl = new URL(options.spa.maskPath, 'http://localhost')\n\n maskUrl.searchParams.set('__TSS_SHELL', 'true')\n\n options.pages.push({\n path: maskUrl.toString().replace('http://localhost', ''),\n prerender: options.spa.prerender,\n sitemap: {\n exclude: true,\n },\n })\n }\n\n // Run the prerendering process\n if (options.prerender.enabled) {\n await prerender({\n options,\n nitro,\n builder,\n })\n }\n\n // Run the sitemap build process\n if (options.pages.length) {\n buildSitemap({\n options,\n publicDir: nitro.options.output.publicDir,\n })\n }\n\n // Build the nitro app\n // We only build the nitro app, once we've prepared the public assets,\n // prerendered the pages and built the sitemap.\n // If we try to do this earlier, then the public assets may not be available\n // in the production build.\n await build(nitro)\n\n // Close the nitro instance\n await nitro.close()\n nitro.logger.success(\n 'Client and Server bundles for TanStack Start have been successfully built.',\n )\n}\n\ntype NitroRollupPluginOption = NonNullable<\n NitroConfig['rollupConfig']\n>['plugins']\n\nfunction virtualBundlePlugin(\n ssrBundle: Rollup.OutputBundle,\n): NitroRollupPluginOption {\n type VirtualModule = { code: string; map: string | null }\n const _modules = new Map<string, VirtualModule>()\n\n // group chunks and source maps\n for (const [fileName, content] of Object.entries(ssrBundle)) {\n if (content.type === 'chunk') {\n const virtualModule: VirtualModule = {\n code: content.code,\n map: null,\n }\n const maybeMap = ssrBundle[`${fileName}.map`]\n if (maybeMap && maybeMap.type === 'asset') {\n virtualModule.map = maybeMap.source as string\n }\n _modules.set(fileName, virtualModule)\n _modules.set(resolve(fileName), virtualModule)\n }\n }\n\n return {\n name: 'virtual-bundle',\n resolveId(id, importer) {\n if (_modules.has(id)) {\n return resolve(id)\n }\n\n if (importer) {\n const resolved = resolve(dirname(importer), id)\n if (_modules.has(resolved)) {\n return resolved\n }\n }\n return null\n },\n load(id) {\n const m = _modules.get(id)\n if (!m) {\n return null\n }\n return m\n },\n }\n}\n"],"names":["VITE_ENVIRONMENT_NAMES","resolve","CLIENT_DIST_DIR","rmSync","SSR_ENTRY_FILE","createNitro","prepare","copyPublicAssets","_a","prerender","buildSitemap","build","dirname"],"mappings":";;;;;;;;;AAoBgB,SAAA,YACd,SACA,cACqB;AACrB,QAAM,cACJ,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X;AACF;;"}
|
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const
|
|
3
|
+
const node_fs = require("node:fs");
|
|
4
4
|
const os = require("node:os");
|
|
5
5
|
const path = require("node:path");
|
|
6
6
|
const rollup = require("nitropack/rollup");
|
|
7
7
|
const nitropack = require("nitropack");
|
|
8
8
|
const ufo = require("ufo");
|
|
9
|
+
const constants = require("../constants.cjs");
|
|
10
|
+
const utils = require("../utils.cjs");
|
|
9
11
|
const queue = require("./queue.cjs");
|
|
10
|
-
const buildNitro = require("./nitro/build-nitro.cjs");
|
|
11
|
-
const constants = require("./constants.cjs");
|
|
12
12
|
async function prerender({
|
|
13
13
|
options,
|
|
14
14
|
nitro,
|
|
15
15
|
builder
|
|
16
16
|
}) {
|
|
17
17
|
var _a;
|
|
18
|
-
|
|
18
|
+
const logger = utils.createLogger("prerender");
|
|
19
|
+
logger.info("Prendering pages...");
|
|
19
20
|
if (((_a = options.prerender) == null ? void 0 : _a.enabled) && !options.pages.length) {
|
|
20
21
|
options.pages = [
|
|
21
22
|
{
|
|
@@ -31,7 +32,10 @@ async function prerender({
|
|
|
31
32
|
}
|
|
32
33
|
const prerenderOutputDir = path.resolve(
|
|
33
34
|
options.root,
|
|
34
|
-
".tanstack
|
|
35
|
+
".tanstack",
|
|
36
|
+
"start",
|
|
37
|
+
"build",
|
|
38
|
+
"prerenderer"
|
|
35
39
|
);
|
|
36
40
|
const nodeNitro = await nitropack.createNitro({
|
|
37
41
|
...nitro.options._config,
|
|
@@ -55,7 +59,7 @@ async function prerender({
|
|
|
55
59
|
sourcemap: void 0
|
|
56
60
|
}
|
|
57
61
|
};
|
|
58
|
-
await
|
|
62
|
+
await nitropack.build(nodeNitro);
|
|
59
63
|
const serverFilename = typeof nodeNitroRollupOptions.output.entryFileNames === "string" ? nodeNitroRollupOptions.output.entryFileNames : "index.mjs";
|
|
60
64
|
const serverEntrypoint = path.resolve(
|
|
61
65
|
path.join(nodeNitro.options.output.serverDir, serverFilename)
|
|
@@ -63,12 +67,12 @@ async function prerender({
|
|
|
63
67
|
const { closePrerenderer, localFetch } = await import(serverEntrypoint);
|
|
64
68
|
try {
|
|
65
69
|
const pages = await prerenderPages();
|
|
66
|
-
|
|
70
|
+
logger.info(`Prerendered ${pages.length} pages:`);
|
|
67
71
|
pages.forEach((page) => {
|
|
68
|
-
|
|
72
|
+
logger.info(`- ${page}`);
|
|
69
73
|
});
|
|
70
74
|
} catch (error) {
|
|
71
|
-
|
|
75
|
+
logger.error(error);
|
|
72
76
|
} finally {
|
|
73
77
|
closePrerenderer();
|
|
74
78
|
}
|
|
@@ -89,7 +93,7 @@ async function prerender({
|
|
|
89
93
|
const seen = /* @__PURE__ */ new Set();
|
|
90
94
|
const retriesByPath = /* @__PURE__ */ new Map();
|
|
91
95
|
const concurrency = ((_a2 = options.prerender) == null ? void 0 : _a2.concurrency) ?? os.cpus().length;
|
|
92
|
-
|
|
96
|
+
logger.info(`Concurrency: ${concurrency}`);
|
|
93
97
|
const queue$1 = new queue.Queue({ concurrency });
|
|
94
98
|
options.pages.forEach((page) => addCrawlPageTask(page));
|
|
95
99
|
await queue$1.start();
|
|
@@ -109,7 +113,7 @@ async function prerender({
|
|
|
109
113
|
};
|
|
110
114
|
queue$1.add(async () => {
|
|
111
115
|
var _a4;
|
|
112
|
-
|
|
116
|
+
logger.info(`Crawling: ${page.path}`);
|
|
113
117
|
const retries = retriesByPath.get(page.path) || 0;
|
|
114
118
|
try {
|
|
115
119
|
const encodedRoute = encodeURI(page.path);
|
|
@@ -135,10 +139,10 @@ async function prerender({
|
|
|
135
139
|
);
|
|
136
140
|
const html = await res.text();
|
|
137
141
|
const filepath = path.join(nitro.options.output.publicDir, filename);
|
|
138
|
-
await
|
|
142
|
+
await node_fs.promises.mkdir(path.dirname(filepath), {
|
|
139
143
|
recursive: true
|
|
140
144
|
});
|
|
141
|
-
await
|
|
145
|
+
await node_fs.promises.writeFile(filepath, html);
|
|
142
146
|
const newPage = await ((_a4 = prerenderOptions.onSuccess) == null ? void 0 : _a4.call(prerenderOptions, { page, html }));
|
|
143
147
|
if (newPage) {
|
|
144
148
|
Object.assign(page, newPage);
|
|
@@ -151,7 +155,7 @@ async function prerender({
|
|
|
151
155
|
}
|
|
152
156
|
} catch (error) {
|
|
153
157
|
if (retries < (prerenderOptions.retryCount ?? 0)) {
|
|
154
|
-
|
|
158
|
+
logger.warn(`Encountered error, retrying: ${page.path} in 500ms`);
|
|
155
159
|
await new Promise(
|
|
156
160
|
(resolve) => setTimeout(resolve, prerenderOptions.retryDelay)
|
|
157
161
|
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prerender.cjs","sources":["../../../src/nitro-plugin/prerender.ts"],"sourcesContent":["import { promises as fsp } from 'node:fs'\nimport os from 'node:os'\nimport path from 'node:path'\nimport { getRollupConfig } from 'nitropack/rollup'\nimport { build as buildNitro, createNitro } from 'nitropack'\nimport { joinURL, withBase, withoutBase } from 'ufo'\nimport { VITE_ENVIRONMENT_NAMES } from '../constants'\nimport { createLogger } from '../utils'\nimport { Queue } from './queue'\nimport type { ViteBuilder } from 'vite'\nimport type { $Fetch, Nitro } from 'nitropack'\nimport type { TanStackStartOutputConfig } from '../plugin'\nimport type { Page } from '../schema'\n\nexport async function prerender({\n options,\n nitro,\n builder,\n}: {\n options: TanStackStartOutputConfig\n nitro: Nitro\n builder: ViteBuilder\n}) {\n const logger = createLogger('prerender')\n logger.info('Prendering pages...')\n\n // If prerender is enabled but no pages are provided, default to prerendering the root page\n if (options.prerender?.enabled && !options.pages.length) {\n options.pages = [\n {\n path: '/',\n },\n ]\n }\n\n const serverEnv = builder.environments[VITE_ENVIRONMENT_NAMES.server]\n\n if (!serverEnv) {\n throw new Error(\n `Vite's \"${VITE_ENVIRONMENT_NAMES.server}\" environment not found`,\n )\n }\n\n const prerenderOutputDir = path.resolve(\n options.root,\n '.tanstack',\n 'start',\n 'build',\n 'prerenderer',\n )\n\n const nodeNitro = await createNitro({\n ...nitro.options._config,\n preset: 'nitro-prerender',\n logLevel: 0,\n output: {\n dir: prerenderOutputDir,\n serverDir: path.resolve(prerenderOutputDir, 'server'),\n publicDir: path.resolve(prerenderOutputDir, 'public'),\n },\n })\n\n const nodeNitroRollupOptions = getRollupConfig(nodeNitro)\n\n const build = serverEnv.config.build\n\n build.outDir = prerenderOutputDir\n\n build.rollupOptions = {\n ...build.rollupOptions,\n ...nodeNitroRollupOptions,\n output: {\n ...build.rollupOptions.output,\n ...nodeNitroRollupOptions.output,\n sourcemap: undefined,\n },\n }\n\n await buildNitro(nodeNitro)\n\n // Import renderer entry\n const serverFilename =\n typeof nodeNitroRollupOptions.output.entryFileNames === 'string'\n ? nodeNitroRollupOptions.output.entryFileNames\n : 'index.mjs'\n\n const serverEntrypoint = path.resolve(\n path.join(nodeNitro.options.output.serverDir, serverFilename),\n )\n\n const { closePrerenderer, localFetch } = (await import(serverEntrypoint)) as {\n closePrerenderer: () => void\n localFetch: $Fetch\n }\n\n try {\n // Crawl all pages\n const pages = await prerenderPages()\n\n logger.info(`Prerendered ${pages.length} pages:`)\n pages.forEach((page) => {\n logger.info(`- ${page}`)\n })\n\n // TODO: Write the prerendered pages to the output directory\n } catch (error) {\n logger.error(error)\n } finally {\n // Ensure server is always closed\n // server.process.kill()\n closePrerenderer()\n }\n\n function extractLinks(html: string): Array<string> {\n const linkRegex = /<a[^>]+href=[\"']([^\"']+)[\"'][^>]*>/g\n const links: Array<string> = []\n let match\n\n while ((match = linkRegex.exec(html)) !== null) {\n const href = match[1]\n if (href && (href.startsWith('/') || href.startsWith('./'))) {\n links.push(href)\n }\n }\n\n return links\n }\n\n async function prerenderPages() {\n const seen = new Set<string>()\n const retriesByPath = new Map<string, number>()\n const concurrency = options.prerender?.concurrency ?? os.cpus().length\n logger.info(`Concurrency: ${concurrency}`)\n const queue = new Queue({ concurrency })\n\n options.pages.forEach((page) => addCrawlPageTask(page))\n\n await queue.start()\n\n return Array.from(seen)\n\n function addCrawlPageTask(page: Page) {\n // Was the page already seen?\n if (seen.has(page.path)) return\n\n // Add the page to the seen set\n seen.add(page.path)\n\n if (page.fromCrawl) {\n options.pages.push(page)\n }\n\n // If not enabled, skip\n if (!(page.prerender?.enabled ?? true)) return\n\n // If there is a filter link, check if the page should be prerendered\n if (options.prerender?.filter && !options.prerender.filter(page)) return\n\n // Resolve the merged default and page-specific prerender options\n const prerenderOptions = {\n ...options.prerender,\n ...page.prerender,\n }\n\n // Add the task\n queue.add(async () => {\n logger.info(`Crawling: ${page.path}`)\n const retries = retriesByPath.get(page.path) || 0\n try {\n // Fetch the route\n const encodedRoute = encodeURI(page.path)\n\n const res = await localFetch<Response>(\n withBase(encodedRoute, nodeNitro.options.baseURL),\n {\n headers: { 'x-nitro-prerender': encodedRoute },\n },\n )\n\n if (!res.ok) {\n throw new Error(`Failed to fetch ${page.path}: ${res.statusText}`, {\n cause: res,\n })\n }\n\n const cleanPagePath = (\n prerenderOptions.outputPath || page.path\n ).split(/[?#]/)[0]!\n\n // Guess route type and populate fileName\n const contentType = res.headers.get('content-type') || ''\n const isImplicitHTML =\n !cleanPagePath.endsWith('.html') && contentType.includes('html')\n // &&\n // !JsonSigRx.test(dataBuff.subarray(0, 32).toString('utf8'))\n const routeWithIndex = cleanPagePath.endsWith('/')\n ? cleanPagePath + 'index'\n : cleanPagePath\n\n const htmlPath =\n cleanPagePath.endsWith('/') || prerenderOptions.autoSubfolderIndex\n ? joinURL(cleanPagePath, 'index.html')\n : cleanPagePath + '.html'\n\n const filename = withoutBase(\n isImplicitHTML ? htmlPath : routeWithIndex,\n nitro.options.baseURL,\n )\n\n const html = await res.text()\n\n const filepath = path.join(nitro.options.output.publicDir, filename)\n\n await fsp.mkdir(path.dirname(filepath), {\n recursive: true,\n })\n\n await fsp.writeFile(filepath, html)\n\n const newPage = await prerenderOptions.onSuccess?.({ page, html })\n\n if (newPage) {\n Object.assign(page, newPage)\n }\n\n // Find new links\n if (prerenderOptions.crawlLinks ?? true) {\n const links = extractLinks(html)\n for (const link of links) {\n addCrawlPageTask({ path: link, fromCrawl: true })\n }\n }\n } catch (error) {\n if (retries < (prerenderOptions.retryCount ?? 0)) {\n logger.warn(`Encountered error, retrying: ${page.path} in 500ms`)\n await new Promise((resolve) =>\n setTimeout(resolve, prerenderOptions.retryDelay),\n )\n retriesByPath.set(page.path, retries + 1)\n addCrawlPageTask(page)\n } else {\n throw error\n }\n }\n })\n }\n }\n}\n"],"names":["createLogger","VITE_ENVIRONMENT_NAMES","createNitro","getRollupConfig","buildNitro","_a","queue","Queue","withBase","joinURL","withoutBase","fsp"],"mappings":";;;;;;;;;;;AAcA,eAAsB,UAAU;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AACF,GAIG;;AACK,QAAA,SAASA,mBAAa,WAAW;AACvC,SAAO,KAAK,qBAAqB;AAGjC,QAAI,aAAQ,cAAR,mBAAmB,YAAW,CAAC,QAAQ,MAAM,QAAQ;AACvD,YAAQ,QAAQ;AAAA,MACd;AAAA,QACE,MAAM;AAAA,MAAA;AAAA,IAEV;AAAA,EAAA;AAGF,QAAM,YAAY,QAAQ,aAAaC,UAAAA,uBAAuB,MAAM;AAEpE,MAAI,CAAC,WAAW;AACd,UAAM,IAAI;AAAA,MACR,WAAWA,iCAAuB,MAAM;AAAA,IAC1C;AAAA,EAAA;AAGF,QAAM,qBAAqB,KAAK;AAAA,IAC9B,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEM,QAAA,YAAY,MAAMC,sBAAY;AAAA,IAClC,GAAG,MAAM,QAAQ;AAAA,IACjB,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,QAAQ;AAAA,MACN,KAAK;AAAA,MACL,WAAW,KAAK,QAAQ,oBAAoB,QAAQ;AAAA,MACpD,WAAW,KAAK,QAAQ,oBAAoB,QAAQ;AAAA,IAAA;AAAA,EACtD,CACD;AAEK,Q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|
import { Nitro } from 'nitropack';
|
|
3
|
-
import { TanStackStartOutputConfig } from '
|
|
3
|
+
import { TanStackStartOutputConfig } from '../plugin.cjs';
|
|
4
4
|
export declare function prerender({ options, nitro, builder, }: {
|
|
5
5
|
options: TanStackStartOutputConfig;
|
|
6
6
|
nitro: Nitro;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.cjs","sources":["../../../src/nitro-plugin/queue.ts"],"sourcesContent":["interface PoolConfig {\n concurrency?: number\n started?: boolean\n tasks?: Array<() => Promise<any>>\n}\n\nconst defaultConfig: PoolConfig = {\n concurrency: 5,\n started: false,\n tasks: [],\n}\n\nexport class Queue<T> {\n private onSettles: Array<(res: any, error: any) => void> = []\n private onErrors: Array<(error: any, task: () => Promise<any>) => void> = []\n private onSuccesses: Array<(result: any, task: () => Promise<any>) => void> =\n []\n private running: boolean\n private active: Array<() => Promise<any>> = []\n private pending: Array<() => Promise<any>>\n private currentConcurrency: number\n\n constructor(config: PoolConfig = defaultConfig) {\n const { concurrency, started, tasks } = {\n ...defaultConfig,\n ...config,\n }\n this.running = started!\n this.pending = tasks as Array<() => Promise<any>>\n this.currentConcurrency = concurrency!\n }\n\n private tick() {\n if (!this.running) {\n return\n }\n while (\n this.active.length < this.currentConcurrency &&\n this.pending.length\n ) {\n const nextFn = this.pending.shift()\n if (!nextFn) {\n throw new Error('Found task that is not a function')\n }\n this.active.push(nextFn)\n ;(async () => {\n let success = false\n let res!: T\n let error: any\n try {\n res = await nextFn()\n success = true\n } catch (e) {\n error = e\n }\n this.active = this.active.filter((d) => d !== nextFn)\n if (success) {\n this.onSuccesses.forEach((d) => d(res, nextFn))\n } else {\n this.onErrors.forEach((d) => d(error, nextFn))\n }\n this.onSettles.forEach((d) => d(res, error))\n this.tick()\n })()\n }\n }\n\n add(fn: () => Promise<T> | T, { priority }: { priority?: boolean } = {}) {\n return new Promise<any>((resolve, reject) => {\n const task = () =>\n Promise.resolve(fn())\n .then((res) => {\n resolve(res)\n return res\n })\n .catch((err) => {\n reject(err)\n throw err\n })\n if (priority) {\n this.pending.unshift(task)\n } else {\n this.pending.push(task)\n }\n this.tick()\n })\n }\n\n throttle(n: number) {\n this.currentConcurrency = n\n }\n\n onSettled(cb: () => void) {\n this.onSettles.push(cb)\n return () => {\n this.onSettles = this.onSettles.filter((d) => d !== cb)\n }\n }\n\n onError(cb: (error: any, task: () => Promise<any>) => void) {\n this.onErrors.push(cb)\n return () => {\n this.onErrors = this.onErrors.filter((d) => d !== cb)\n }\n }\n\n onSuccess(cb: (result: any, task: () => Promise<any>) => void) {\n this.onSuccesses.push(cb)\n return () => {\n this.onSuccesses = this.onSuccesses.filter((d) => d !== cb)\n }\n }\n\n stop() {\n this.running = false\n }\n\n start() {\n this.running = true\n this.tick()\n return new Promise<void>((resolve) => {\n this.onSettled(() => {\n if (this.isSettled()) {\n resolve()\n }\n })\n })\n }\n\n clear() {\n this.pending = []\n }\n\n getActive() {\n return this.active\n }\n\n getPending() {\n return this.pending\n }\n\n getAll() {\n return [...this.active, ...this.pending]\n }\n\n isRunning() {\n return this.running\n }\n\n isSettled() {\n return !this.active.length && !this.pending.length\n }\n}\n"],"names":[],"mappings":";;;;;AAMA,MAAM,gBAA4B;AAAA,EAChC,aAAa;AAAA,EACb,SAAS;AAAA,EACT,OAAO,CAAA;AACT;AAEO,MAAM,MAAS;AAAA,EAUpB,YAAY,SAAqB,eAAe;AATxC,qCAAmD,CAAC;AACpD,oCAAkE,CAAC;AACnE,uCACN,CAAC;AACK;AACA,kCAAoC,CAAC;AACrC;AACA;AAGN,UAAM,EAAE,aAAa,SAAS,UAAU;AAAA,MACtC,GAAG;AAAA,MACH,GAAG;AAAA,IACL;AACA,SAAK,UAAU;AACf,SAAK,UAAU;AACf,SAAK,qBAAqB;AAAA,EAAA;AAAA,EAGpB,OAAO;AACT,QAAA,CAAC,KAAK,SAAS;AACjB;AAAA,IAAA;AAEF,WACE,KAAK,OAAO,SAAS,KAAK,sBAC1B,KAAK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Y,KAAK,UAAU,OAAO,CAAC,MAAM,MAAM,EAAE;AAAA,IACxD;AAAA,EAAA;AAAA,EAGF,QAAQ,IAAoD;AACrD,SAAA,SAAS,KAAK,EAAE;AACrB,WAAO,MAAM;AACX,WAAK,WAAW,KAAK,SAAS,OAAO,CAAC,MAAM,MAAM,EAAE;AAAA,IACtD;AAAA,EAAA;AAAA,EAGF,UAAU,IAAqD;AACxD,SAAA,YAAY,KAAK,EAAE;AACxB,WAAO,MAAM;AACX,WAAK,cAAc,KAAK,YAAY,OAAO,CAAC,MAAM,MAAM,EAAE;AAAA,IAC5D;AAAA,EAAA;AAAA,EAGF,OAAO;AACL,SAAK,UAAU;AAAA,EAAA;AAAA,EAGjB,QAAQ;AACN,SAAK,UAAU;AACf,SAAK,KAAK;AACH,WAAA,IAAI,QAAc,CAAC,YAAY;AACpC,WAAK,UAAU,MAAM;AACf,YAAA,KAAK,aAAa;AACZ,kBAAA;AAAA,QAAA;AAAA,MACV,CACD;AAAA,IAAA,CACF;AAAA,EAAA;AAAA,EAGH,QAAQ;AACN,SAAK,UAAU,CAAC;AAAA,EAAA;AAAA,EAGlB,YAAY;AACV,WAAO,KAAK;AAAA,EAAA;AAAA,EAGd,aAAa;AACX,WAAO,KAAK;AAAA,EAAA;AAAA,EAGd,SAAS;AACP,WAAO,CAAC,GAAG,KAAK,QAAQ,GAAG,KAAK,OAAO;AAAA,EAAA;AAAA,EAGzC,YAAY;AACV,WAAO,KAAK;AAAA,EAAA;AAAA,EAGd,YAAY;AACV,WAAO,CAAC,KAAK,OAAO,UAAU,CAAC,KAAK,QAAQ;AAAA,EAAA;AAEhD;;"}
|
package/dist/cjs/plugin.cjs
CHANGED
|
@@ -2,15 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const path = require("node:path");
|
|
4
4
|
const nitropack = require("nitropack");
|
|
5
|
-
const
|
|
5
|
+
const routerCore = require("@tanstack/router-core");
|
|
6
|
+
const startServerCore = require("@tanstack/start-server-core");
|
|
6
7
|
const serverFunctionsPlugin = require("@tanstack/server-functions-plugin");
|
|
7
|
-
const vite
|
|
8
|
+
const vite = require("vite");
|
|
8
9
|
const schema = require("./schema.cjs");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
10
|
+
const plugin$5 = require("./nitro-plugin/plugin.cjs");
|
|
11
|
+
const plugin$3 = require("./start-manifest-plugin/plugin.cjs");
|
|
11
12
|
const startCompilerPlugin = require("./start-compiler-plugin.cjs");
|
|
12
13
|
const constants = require("./constants.cjs");
|
|
13
|
-
const plugin = require("./start-
|
|
14
|
+
const plugin = require("./start-router-plugin/plugin.cjs");
|
|
15
|
+
const plugin$2 = require("./load-env-plugin/plugin.cjs");
|
|
16
|
+
const plugin$4 = require("./dev-server-plugin/plugin.cjs");
|
|
17
|
+
const plugin$1 = require("./resolve-virtual-entries-plugin/plugin.cjs");
|
|
14
18
|
function _interopNamespaceDefault(e) {
|
|
15
19
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
16
20
|
if (e) {
|
|
@@ -27,24 +31,22 @@ function _interopNamespaceDefault(e) {
|
|
|
27
31
|
n.default = e;
|
|
28
32
|
return Object.freeze(n);
|
|
29
33
|
}
|
|
30
|
-
const vite__namespace = /* @__PURE__ */ _interopNamespaceDefault(vite
|
|
31
|
-
schema.createTanStackStartOptionsSchema();
|
|
34
|
+
const vite__namespace = /* @__PURE__ */ _interopNamespaceDefault(vite);
|
|
32
35
|
schema.createTanStackConfig();
|
|
33
|
-
const clientDistDir = ".tanstack-start/build/client-dist";
|
|
34
|
-
const ssrEntryFile = "ssr.mjs";
|
|
35
36
|
let ssrBundle;
|
|
36
37
|
function TanStackStartVitePluginCore(opts, startConfig) {
|
|
37
38
|
return [
|
|
38
|
-
|
|
39
|
-
verboseFileRoutes: false,
|
|
39
|
+
plugin.tanStackStartRouter({
|
|
40
40
|
...startConfig.tsr,
|
|
41
41
|
target: opts.framework,
|
|
42
|
-
enableRouteGeneration: true,
|
|
43
42
|
autoCodeSplitting: true
|
|
44
43
|
}),
|
|
44
|
+
plugin$1.resolveVirtualEntriesPlugin(opts, startConfig),
|
|
45
45
|
{
|
|
46
46
|
name: "tanstack-start-core:config-client",
|
|
47
|
-
async config() {
|
|
47
|
+
async config(viteConfig) {
|
|
48
|
+
const viteAppBase = routerCore.trimPathRight(viteConfig.base || "/");
|
|
49
|
+
globalThis.TSS_APP_BASE = viteAppBase;
|
|
48
50
|
const nitroOutputPublicDir = await (async () => {
|
|
49
51
|
const dummyNitroApp = await nitropack.createNitro({
|
|
50
52
|
preset: startConfig.target,
|
|
@@ -58,11 +60,15 @@ function TanStackStartVitePluginCore(opts, startConfig) {
|
|
|
58
60
|
const entry = startConfig2.clientEntryPath.startsWith(
|
|
59
61
|
"/~start/default-client-entry"
|
|
60
62
|
) ? startConfig2.clientEntryPath : vite__namespace.normalizePath(
|
|
61
|
-
path.
|
|
63
|
+
path.join(
|
|
64
|
+
"/@fs",
|
|
65
|
+
path.resolve(startConfig2.root, startConfig2.clientEntryPath)
|
|
66
|
+
)
|
|
62
67
|
);
|
|
63
68
|
return entry;
|
|
64
69
|
};
|
|
65
70
|
return {
|
|
71
|
+
base: viteAppBase,
|
|
66
72
|
environments: {
|
|
67
73
|
[constants.VITE_ENVIRONMENT_NAMES.client]: {
|
|
68
74
|
consumer: "client",
|
|
@@ -73,9 +79,9 @@ function TanStackStartVitePluginCore(opts, startConfig) {
|
|
|
73
79
|
main: getClientEntryPath(startConfig)
|
|
74
80
|
},
|
|
75
81
|
output: {
|
|
76
|
-
dir: path.resolve(startConfig.root,
|
|
82
|
+
dir: path.resolve(startConfig.root, constants.CLIENT_DIST_DIR)
|
|
77
83
|
},
|
|
78
|
-
// TODO this should be removed
|
|
84
|
+
// TODO: this should be removed
|
|
79
85
|
external: ["node:fs", "node:path", "node:os", "node:crypto"]
|
|
80
86
|
}
|
|
81
87
|
}
|
|
@@ -90,12 +96,12 @@ function TanStackStartVitePluginCore(opts, startConfig) {
|
|
|
90
96
|
copyPublicDir: false,
|
|
91
97
|
rollupOptions: {
|
|
92
98
|
output: {
|
|
93
|
-
entryFileNames:
|
|
99
|
+
entryFileNames: constants.SSR_ENTRY_FILE
|
|
94
100
|
},
|
|
95
101
|
plugins: [
|
|
96
102
|
{
|
|
97
103
|
name: "capture-output",
|
|
98
|
-
generateBundle(
|
|
104
|
+
generateBundle(_options, bundle) {
|
|
99
105
|
ssrBundle = bundle;
|
|
100
106
|
}
|
|
101
107
|
}
|
|
@@ -119,34 +125,44 @@ function TanStackStartVitePluginCore(opts, startConfig) {
|
|
|
119
125
|
"@tanstack/start-router-manifest",
|
|
120
126
|
"@tanstack/start-config",
|
|
121
127
|
"@tanstack/server-functions-plugin",
|
|
122
|
-
"tanstack-start-router-manifest:v",
|
|
123
|
-
"tanstack-start-server-fn-manifest:v",
|
|
124
128
|
"nitropack",
|
|
125
|
-
"@tanstack/**"
|
|
129
|
+
"@tanstack/**start**",
|
|
130
|
+
...Object.values(startServerCore.VIRTUAL_MODULES)
|
|
126
131
|
]
|
|
127
132
|
},
|
|
133
|
+
optimizeDeps: {
|
|
134
|
+
exclude: [...Object.values(startServerCore.VIRTUAL_MODULES)]
|
|
135
|
+
},
|
|
128
136
|
/* prettier-ignore */
|
|
129
137
|
define: {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
138
|
+
// define is an esbuild function that replaces the any instances of given keys with the given values
|
|
139
|
+
// i.e: __FRAMEWORK_NAME__ can be replaced with JSON.stringify("TanStack Start")
|
|
140
|
+
// This is not the same as injecting environment variables.
|
|
141
|
+
...defineReplaceEnv("TSS_CLIENT_ENTRY", getClientEntryPath(startConfig)),
|
|
133
142
|
// This is consumed by the router-manifest, where the entry point is imported after the dev refresh runtime is resolved
|
|
134
|
-
...
|
|
135
|
-
...
|
|
143
|
+
...defineReplaceEnv("TSS_SERVER_FN_BASE", startConfig.serverFns.base),
|
|
144
|
+
...defineReplaceEnv("TSS_OUTPUT_PUBLIC_DIR", nitroOutputPublicDir),
|
|
145
|
+
...defineReplaceEnv("TSS_APP_BASE", viteAppBase)
|
|
136
146
|
}
|
|
137
147
|
};
|
|
138
148
|
}
|
|
139
149
|
},
|
|
140
150
|
// N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPluginEnv
|
|
141
|
-
startCompilerPlugin.
|
|
151
|
+
startCompilerPlugin.startCompilerPlugin(opts.framework, {
|
|
142
152
|
client: { envName: constants.VITE_ENVIRONMENT_NAMES.client },
|
|
143
153
|
server: { envName: constants.VITE_ENVIRONMENT_NAMES.server }
|
|
144
154
|
}),
|
|
145
155
|
serverFunctionsPlugin.TanStackServerFnPluginEnv({
|
|
146
156
|
// This is the ID that will be available to look up and import
|
|
147
157
|
// our server function manifest and resolve its module
|
|
148
|
-
manifestVirtualImportId:
|
|
149
|
-
manifestOutputFilename:
|
|
158
|
+
manifestVirtualImportId: startServerCore.VIRTUAL_MODULES.serverFnManifest,
|
|
159
|
+
manifestOutputFilename: path.join(
|
|
160
|
+
".tanstack",
|
|
161
|
+
"start",
|
|
162
|
+
"build",
|
|
163
|
+
"server",
|
|
164
|
+
"server-functions-manifest.json"
|
|
165
|
+
),
|
|
150
166
|
client: {
|
|
151
167
|
getRuntimeCode: () => `import { createClientRpc } from '@tanstack/${opts.framework}-start/server-functions-client'`,
|
|
152
168
|
replacer: (d) => `createClientRpc('${d.functionId}', '${startConfig.serverFns.base}')`,
|
|
@@ -165,21 +181,17 @@ function TanStackStartVitePluginCore(opts, startConfig) {
|
|
|
165
181
|
return serverEnv.runner.import(fn.extractedFilename);
|
|
166
182
|
}
|
|
167
183
|
}),
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
plugin.
|
|
171
|
-
|
|
172
|
-
target: opts.framework
|
|
173
|
-
})
|
|
184
|
+
plugin$2.loadEnvPlugin(startConfig),
|
|
185
|
+
plugin$3.startManifestPlugin(startConfig),
|
|
186
|
+
plugin$4.devServerPlugin(),
|
|
187
|
+
plugin$5.nitroPlugin(startConfig, () => ssrBundle)
|
|
174
188
|
];
|
|
175
189
|
}
|
|
176
|
-
function
|
|
190
|
+
function defineReplaceEnv(key, value) {
|
|
177
191
|
return {
|
|
178
192
|
[`process.env.${key}`]: JSON.stringify(value),
|
|
179
193
|
[`import.meta.env.${key}`]: JSON.stringify(value)
|
|
180
194
|
};
|
|
181
195
|
}
|
|
182
196
|
exports.TanStackStartVitePluginCore = TanStackStartVitePluginCore;
|
|
183
|
-
exports.clientDistDir = clientDistDir;
|
|
184
|
-
exports.ssrEntryFile = ssrEntryFile;
|
|
185
197
|
//# sourceMappingURL=plugin.cjs.map
|
package/dist/cjs/plugin.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs","sources":["../../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createNitro } from 'nitropack'\nimport { tanstackRouter } from '@tanstack/router-plugin/vite'\nimport { TanStackServerFnPluginEnv } from '@tanstack/server-functions-plugin'\nimport * as vite from 'vite'\nimport {\n createTanStackConfig,\n createTanStackStartOptionsSchema,\n} from './schema'\nimport { nitroPlugin } from './nitro/nitro-plugin'\nimport { startManifestPlugin } from './routesManifestPlugin'\nimport { TanStackStartCompilerPlugin } from './start-compiler-plugin'\nimport { VITE_ENVIRONMENT_NAMES } from './constants'\nimport { TanStackStartServerRoutesVite } from './start-server-routes-plugin/plugin'\nimport type { PluginOption, Rollup } from 'vite'\nimport type { z } from 'zod'\nimport type { CompileStartFrameworkOptions } from './compilers'\n\nconst TanStackStartOptionsSchema = createTanStackStartOptionsSchema()\nexport type TanStackStartInputConfig = z.input<\n typeof TanStackStartOptionsSchema\n>\n\nconst defaultConfig = createTanStackConfig()\nexport function getTanStackStartOptions(opts?: TanStackStartInputConfig) {\n return defaultConfig.parse(opts)\n}\n\nexport type TanStackStartOutputConfig = ReturnType<\n typeof getTanStackStartOptions\n>\n\nexport const clientDistDir = '.tanstack-start/build/client-dist'\nexport const ssrEntryFile = 'ssr.mjs'\n\nexport interface TanStackStartVitePluginCoreOptions {\n framework: CompileStartFrameworkOptions\n}\n// this needs to live outside of the TanStackStartVitePluginCore since it will be invoked multiple times by vite\nlet ssrBundle: Rollup.OutputBundle\n\nexport function TanStackStartVitePluginCore(\n opts: TanStackStartVitePluginCoreOptions,\n startConfig: TanStackStartOutputConfig,\n): Array<PluginOption> {\n return [\n tanstackRouter({\n verboseFileRoutes: false,\n ...startConfig.tsr,\n target: opts.framework,\n enableRouteGeneration: true,\n autoCodeSplitting: true,\n }),\n {\n name: 'tanstack-start-core:config-client',\n async config() {\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 getClientEntryPath = (startConfig: TanStackStartOutputConfig) => {\n // when the user specifies a custom client entry path, we need to resolve it\n // relative to the root of the project, keeping in mind that if not specified\n // it will be /~start/default-client-entry which is a virtual path\n // that is resolved by vite to the actual client entry path\n const entry = startConfig.clientEntryPath.startsWith(\n '/~start/default-client-entry',\n )\n ? startConfig.clientEntryPath\n : vite.normalizePath(\n path.resolve(startConfig.root, startConfig.clientEntryPath),\n )\n\n return entry\n }\n\n return {\n environments: {\n [VITE_ENVIRONMENT_NAMES.client]: {\n consumer: 'client',\n build: {\n manifest: true,\n rollupOptions: {\n input: {\n main: getClientEntryPath(startConfig),\n },\n output: {\n dir: path.resolve(startConfig.root, clientDistDir),\n },\n // TODO this should be removed\n external: ['node:fs', 'node:path', 'node:os', 'node:crypto'],\n },\n },\n },\n [VITE_ENVIRONMENT_NAMES.server]: {\n consumer: 'server',\n build: {\n ssr: true,\n // we don't write to the file system as the below 'capture-output' plugin will\n // capture the output and write it to the virtual file system\n write: false,\n copyPublicDir: false,\n rollupOptions: {\n output: {\n entryFileNames: ssrEntryFile,\n },\n plugins: [\n {\n name: 'capture-output',\n generateBundle(options, bundle) {\n // TODO can this hook be called more than once?\n ssrBundle = bundle\n },\n },\n ],\n },\n commonjsOptions: {\n include: [/node_modules/],\n },\n },\n },\n },\n resolve: {\n noExternal: [\n '@tanstack/start-client',\n '@tanstack/start-client-core',\n '@tanstack/start-server',\n '@tanstack/start-server-core',\n '@tanstack/start-server-functions-fetcher',\n '@tanstack/start-server-functions-client',\n '@tanstack/start-server-functions-server',\n '@tanstack/start-router-manifest',\n '@tanstack/start-config',\n '@tanstack/server-functions-plugin',\n 'tanstack-start-router-manifest:v',\n 'tanstack-start-server-fn-manifest:v',\n 'nitropack',\n '@tanstack/**',\n ],\n },\n /* prettier-ignore */\n define: {\n ...injectDefineEnv('TSS_PUBLIC_BASE', startConfig.public.base),\n ...injectDefineEnv('TSS_CLIENT_BASE', startConfig.client.base),\n ...injectDefineEnv('TSS_CLIENT_ENTRY', getClientEntryPath(startConfig)), // This is consumed by the router-manifest, where the entry point is imported after the dev refresh runtime is resolved\n ...injectDefineEnv('TSS_SERVER_FN_BASE', startConfig.serverFns.base),\n ...injectDefineEnv('TSS_OUTPUT_PUBLIC_DIR', nitroOutputPublicDir),\n },\n }\n },\n },\n // N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPluginEnv\n TanStackStartCompilerPlugin(opts.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: 'tanstack-start-server-fn-manifest:v',\n manifestOutputFilename:\n '.tanstack-start/build/server/server-functions-manifest.json',\n client: {\n getRuntimeCode: () =>\n `import { createClientRpc } from '@tanstack/${opts.framework}-start/server-functions-client'`,\n replacer: (d) =>\n `createClientRpc('${d.functionId}', '${startConfig.serverFns.base}')`,\n envName: VITE_ENVIRONMENT_NAMES.client,\n },\n server: {\n getRuntimeCode: () =>\n `import { createServerRpc } from '@tanstack/${opts.framework}-start/server-functions-server'`,\n replacer: (d) =>\n `createServerRpc('${d.functionId}', '${startConfig.serverFns.base}', ${d.fn})`,\n envName: VITE_ENVIRONMENT_NAMES.server,\n },\n importer: (fn) => {\n const serverEnv = (globalThis as any).viteDevServer.environments[\n VITE_ENVIRONMENT_NAMES.server\n ]\n if (!serverEnv) {\n throw new Error(`'ssr' vite dev environment not found`)\n }\n return serverEnv.runner.import(fn.extractedFilename)\n },\n }),\n startManifestPlugin(startConfig),\n nitroPlugin(startConfig, () => ssrBundle),\n TanStackStartServerRoutesVite({\n ...startConfig.tsr,\n target: opts.framework,\n }),\n ]\n}\n\nfunction injectDefineEnv<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":["createTanStackStartOptionsSchema","createTanStackConfig","tanstackRouter","createNitro","nitroOutputPublicDir","startConfig","vite","VITE_ENVIRONMENT_NAMES","TanStackStartCompilerPlugin","TanStackServerFnPluginEnv","startManifestPlugin","nitroPlugin","TanStackStartServerRoutesVite"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkBmCA,OAAiC,iCAAA;AAK9CC,OAAqB,qBAAA;AASpC,MAAM,gBAAgB;AACtB,MAAM,eAAe;AAM5B,IAAI;AAEY,SAAA,4BACd,MACA,aACqB;AACd,SAAA;AAAA,IACLC,oBAAe;AAAA,MACb,mBAAmB;AAAA,MACnB,GAAG,YAAY;AAAA,MACf,QAAQ,KAAK;AAAA,MACb,uBAAuB;AAAA,MACvB,mBAAmB;AAAA,IAAA,CACpB;AAAA,IACD;AAAA,MACE,MAAM;AAAA,MACN,MAAM,SAAS;AACP,cAAA,uBAAuB,OAAO,YAAY;AAExC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OAAO;AAChB,cAAM,YAAa,WAAmB,cAAc,aAClDA,UAAAA,uBAAuB,MACzB;AACA,YAAI,CAAC,WAAW;AACR,gBAAA,IAAI,MAAM,sCAAsC;AAAA,QAAA;AAExD,eAAO,UAAU,OAAO,OAAO,GAAG,iBAAiB;AAAA,MAAA;AAAA,IACrD,CACD;AAAA,IACDG,qBAAAA,oBAAoB,WAAW;AAAA,IAC/BC,wBAAY,aAAa,MAAM,SAAS;AAAA,IACxCC,qCAA8B;AAAA,MAC5B,GAAG,YAAY;AAAA,MACf,QAAQ,KAAK;AAAA,IACd,CAAA;AAAA,EACH;AACF;AAEA,SAAS,gBACP,KACA,OACsE;AAC/D,SAAA;AAAA,IACL,CAAC,eAAe,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,IAC5C,CAAC,mBAAmB,GAAG,EAAE,GAAG,KAAK,UAAU,KAAK;AAAA,EAClD;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.cjs","sources":["../../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createNitro } from 'nitropack'\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 { createTanStackConfig } from './schema'\nimport { nitroPlugin } from './nitro-plugin/plugin'\nimport { startManifestPlugin } from './start-manifest-plugin/plugin'\nimport { startCompilerPlugin } from './start-compiler-plugin'\nimport {\n CLIENT_DIST_DIR,\n SSR_ENTRY_FILE,\n VITE_ENVIRONMENT_NAMES,\n} from './constants'\nimport { tanStackStartRouter } from './start-router-plugin/plugin'\nimport { loadEnvPlugin } from './load-env-plugin/plugin'\nimport { devServerPlugin } from './dev-server-plugin/plugin'\nimport { resolveVirtualEntriesPlugin } from './resolve-virtual-entries-plugin/plugin'\nimport type { createTanStackStartOptionsSchema } from './schema'\nimport type { PluginOption, Rollup } from 'vite'\nimport type { z } from 'zod'\nimport type { CompileStartFrameworkOptions } from './compilers'\n\nexport type TanStackStartInputConfig = z.input<\n ReturnType<typeof createTanStackStartOptionsSchema>\n>\n\nconst defaultConfig = createTanStackConfig()\nexport function getTanStackStartOptions(opts?: TanStackStartInputConfig) {\n return defaultConfig.parse(opts)\n}\n\nexport type TanStackStartOutputConfig = ReturnType<\n typeof getTanStackStartOptions\n>\n\nexport interface TanStackStartVitePluginCoreOptions {\n framework: CompileStartFrameworkOptions\n getVirtualServerRootHandler: (ctx: {\n routerFilepath: string\n serverEntryFilepath: string\n }) => string\n getVirtualServerEntry: (ctx: { routerFilepath: string }) => string\n getVirtualClientEntry: (ctx: { routerFilepath: string }) => string\n}\n// this needs to live outside of the TanStackStartVitePluginCore since it will be invoked multiple times by vite\nlet ssrBundle: Rollup.OutputBundle\n\nexport function TanStackStartVitePluginCore(\n opts: TanStackStartVitePluginCoreOptions,\n startConfig: TanStackStartOutputConfig,\n): Array<PluginOption> {\n return [\n tanStackStartRouter({\n ...startConfig.tsr,\n target: opts.framework,\n autoCodeSplitting: true,\n }),\n resolveVirtualEntriesPlugin(opts, startConfig),\n {\n name: 'tanstack-start-core:config-client',\n async config(viteConfig) {\n const viteAppBase = trimPathRight(viteConfig.base || '/')\n globalThis.TSS_APP_BASE = viteAppBase\n\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 getClientEntryPath = (startConfig: TanStackStartOutputConfig) => {\n // when the user specifies a custom client entry path, we need to resolve it\n // relative to the root of the project, keeping in mind that if not specified\n // it will be /~start/default-client-entry which is a virtual path\n // that is resolved by vite to the actual client entry path\n const entry = startConfig.clientEntryPath.startsWith(\n '/~start/default-client-entry',\n )\n ? startConfig.clientEntryPath\n : vite.normalizePath(\n path.join(\n '/@fs',\n path.resolve(startConfig.root, startConfig.clientEntryPath),\n ),\n )\n\n return entry\n }\n\n return {\n base: viteAppBase,\n environments: {\n [VITE_ENVIRONMENT_NAMES.client]: {\n consumer: 'client',\n build: {\n manifest: true,\n rollupOptions: {\n input: {\n main: getClientEntryPath(startConfig),\n },\n output: {\n dir: path.resolve(startConfig.root, CLIENT_DIST_DIR),\n },\n // TODO: this should be removed\n external: ['node:fs', 'node:path', 'node:os', 'node:crypto'],\n },\n },\n },\n [VITE_ENVIRONMENT_NAMES.server]: {\n consumer: 'server',\n build: {\n ssr: true,\n // we don't write to the file system as the below 'capture-output' plugin will\n // capture the output and write it to the virtual file system\n write: false,\n copyPublicDir: false,\n rollupOptions: {\n output: {\n entryFileNames: SSR_ENTRY_FILE,\n },\n plugins: [\n {\n name: 'capture-output',\n generateBundle(_options, bundle) {\n // TODO: can this hook be called more than once?\n ssrBundle = bundle\n },\n },\n ],\n },\n commonjsOptions: {\n include: [/node_modules/],\n },\n },\n },\n },\n resolve: {\n noExternal: [\n '@tanstack/start-client',\n '@tanstack/start-client-core',\n '@tanstack/start-server',\n '@tanstack/start-server-core',\n '@tanstack/start-server-functions-fetcher',\n '@tanstack/start-server-functions-client',\n '@tanstack/start-server-functions-server',\n '@tanstack/start-router-manifest',\n '@tanstack/start-config',\n '@tanstack/server-functions-plugin',\n 'nitropack',\n '@tanstack/**start**',\n ...Object.values(VIRTUAL_MODULES),\n ],\n },\n optimizeDeps: {\n exclude: [...Object.values(VIRTUAL_MODULES)],\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_CLIENT_ENTRY', getClientEntryPath(startConfig)), // This is consumed by the router-manifest, where the entry point is imported after the dev refresh runtime is resolved\n ...defineReplaceEnv('TSS_SERVER_FN_BASE', startConfig.serverFns.base),\n ...defineReplaceEnv('TSS_OUTPUT_PUBLIC_DIR', nitroOutputPublicDir),\n ...defineReplaceEnv('TSS_APP_BASE', viteAppBase)\n },\n }\n },\n },\n // N.B. TanStackStartCompilerPlugin must be before the TanStackServerFnPluginEnv\n startCompilerPlugin(opts.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 manifestOutputFilename: path.join(\n '.tanstack',\n 'start',\n 'build',\n 'server',\n 'server-functions-manifest.json',\n ),\n client: {\n getRuntimeCode: () =>\n `import { createClientRpc } from '@tanstack/${opts.framework}-start/server-functions-client'`,\n replacer: (d) =>\n `createClientRpc('${d.functionId}', '${startConfig.serverFns.base}')`,\n envName: VITE_ENVIRONMENT_NAMES.client,\n },\n server: {\n getRuntimeCode: () =>\n `import { createServerRpc } from '@tanstack/${opts.framework}-start/server-functions-server'`,\n replacer: (d) =>\n `createServerRpc('${d.functionId}', '${startConfig.serverFns.base}', ${d.fn})`,\n envName: VITE_ENVIRONMENT_NAMES.server,\n },\n importer: (fn) => {\n const serverEnv = (globalThis as any).viteDevServer.environments[\n VITE_ENVIRONMENT_NAMES.server\n ]\n if (!serverEnv) {\n throw new Error(`'ssr' vite dev environment not found`)\n }\n return serverEnv.runner.import(fn.extractedFilename)\n },\n }),\n loadEnvPlugin(startConfig),\n startManifestPlugin(startConfig),\n devServerPlugin(),\n nitroPlugin(startConfig, () => ssrBundle),\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":["createTanStackConfig","tanStackStartRouter","resolveVirtualEntriesPlugin","trimPathRight","createNitro","nitroOutputPublicDir","startConfig","vite","VITE_ENVIRONMENT_NAMES","CLIENT_DIST_DIR","SSR_ENTRY_FILE","VIRTUAL_MODULES","startCompilerPlugin","TanStackServerFnPluginEnv","loadEnvPlugin","startManifestPlugin","devServerPlugin","nitroPlugin"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BsBA,OAAqB,qBAAA;AAmB3C,IAAI;AAEY,SAAA,4BACd,MACA,aACqB;AACd,SAAA;AAAA,IACLC,2BAAoB;AAAA,MAClB,GAAG,YAAY;AAAA,MACf,QAAQ,KAAK;AAAA,MACb,mBAAmB;AAAA,IAAA,CACpB;AAAA,IACDC,SAAA,4BAA4B,MAAM,WAAW;AAAA,IAC7C;AAAA,MACE,MAAM;AAAA,MACN,MAAM,OAAO,YAAY;AACvB,cAAM,cAAcC,WAAA,cAAc,WAAW,QAAQ,GAAG;AACxD,mBAAW,eAAe;AAEpB,cAAA,uBAAuB,OAAO,YAAY;AAExC,gBAAA,gBAAgB,MAAMC,sBAAY;AAAA,YACtC,QAAQ,YAAY;AAAA,YACpB,mBAAmB;AAAA,UAAA,CACpB;AAEKC,gBAAAA,wBAAuB,cAAc,QAAQ,OAAO;AAC1D,gBAAM,cAAc,MAAM;AAEnBA,iBAAAA;AAAAA,QAAAA,GACN;AAEG,cAAA,qBAAqB,CAACC,iBAA2C;AAK/D,gBAAA,QAAQA,aAAY,gBAAgB;AAAA,YACxC;AAAA,UAAA,IAEEA,aAAY,kBACZC,gBAAK;AAAA,YACH,KAAK;AAAA,cACH;AAAA,cACA,KAAK,QAAQD,aAAY,MAAMA,aAAY,eAAe;AAAA,YAAA;AAAA,UAE9D;AAEG,iBAAA;AAAA,QACT;AAEO,eAAA;AAAA,UACL,MAAM;AAAA,UACN,cAAc;AAAA,YACZ,CAACE,UAAAA,uBAAuB,MAAM,GAAG;AAAA,cAC/B,UAAU;AAA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