oidc-spa 10.2.7 → 10.2.9
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/core/createOidc.js +1 -1
- package/esm/core/createOidc.mjs +1 -1
- package/esm/vite-plugin/handleClientEntrypoint.d.ts +5 -0
- package/esm/vite-plugin/handleClientEntrypoint.mjs +23 -17
- package/esm/vite-plugin/handleClientEntrypoint.mjs.map +1 -1
- package/esm/vite-plugin/handleTanstackStartClientOutput.d.ts +16 -0
- package/esm/vite-plugin/handleTanstackStartClientOutput.mjs +298 -0
- package/esm/vite-plugin/handleTanstackStartClientOutput.mjs.map +1 -0
- package/esm/vite-plugin/vite-plugin.mjs +51 -3
- package/esm/vite-plugin/vite-plugin.mjs.map +1 -1
- package/package.json +1 -1
- package/src/vite-plugin/handleClientEntrypoint.ts +41 -27
- package/src/vite-plugin/handleTanstackStartClientOutput.ts +453 -0
- package/src/vite-plugin/vite-plugin.ts +66 -4
package/core/createOidc.js
CHANGED
|
@@ -76,7 +76,7 @@ const StateDataCookie_1 = require("./StateDataCookie");
|
|
|
76
76
|
const loadWebcryptoLinerShim_1 = require("../tools/loadWebcryptoLinerShim");
|
|
77
77
|
const lazySessionStorage_2 = require("../tools/lazySessionStorage");
|
|
78
78
|
// NOTE: Replaced at build time
|
|
79
|
-
const VERSION = "10.2.
|
|
79
|
+
const VERSION = "10.2.9";
|
|
80
80
|
const globalContext = {
|
|
81
81
|
prOidcByConfigId: new Map(),
|
|
82
82
|
hasLogoutBeenCalled: (0, id_1.id)(false),
|
package/esm/core/createOidc.mjs
CHANGED
|
@@ -36,7 +36,7 @@ import { setStateDataCookieIfEnabled, clearStateDataCookie, getIsStateDataCookie
|
|
|
36
36
|
import { loadWebcryptoLinerShim, hasLoadWebcryptoLinerShimBeenCalled } from "../tools/loadWebcryptoLinerShim.mjs";
|
|
37
37
|
import { SESSION_STORAGE_GLOBAL_PREFIX } from "../tools/lazySessionStorage.mjs";
|
|
38
38
|
// NOTE: Replaced at build time
|
|
39
|
-
const VERSION = "10.2.
|
|
39
|
+
const VERSION = "10.2.9";
|
|
40
40
|
const globalContext = {
|
|
41
41
|
prOidcByConfigId: new Map(),
|
|
42
42
|
hasLogoutBeenCalled: id(false),
|
|
@@ -10,5 +10,10 @@ export declare function createHandleClientEntrypoint(params: {
|
|
|
10
10
|
load_handleClientEntrypoint: (params: {
|
|
11
11
|
id: string;
|
|
12
12
|
pluginContext: PluginContext;
|
|
13
|
+
doUseOriginalEntrypoint: boolean;
|
|
14
|
+
buildMarker?: string;
|
|
13
15
|
}) => Promise<null | string>;
|
|
16
|
+
getClientEntrypointSource: (params: {
|
|
17
|
+
applicationEntrypointImportSpecifier: string;
|
|
18
|
+
}) => string;
|
|
14
19
|
};
|
|
@@ -16,20 +16,8 @@ export function createHandleClientEntrypoint(params) {
|
|
|
16
16
|
config: resolvedConfig,
|
|
17
17
|
projectType
|
|
18
18
|
});
|
|
19
|
-
|
|
20
|
-
const {
|
|
21
|
-
const { path: rawPath, queryParams } = splitId(id);
|
|
22
|
-
const normalizedRequestPath = normalizeRequestPath(rawPath);
|
|
23
|
-
const isMatch = normalizedRequestPath && normalizedRequestPath === entryResolution.normalizedPath;
|
|
24
|
-
if (!isMatch) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
const isOriginalRequest = queryParams.getAll(ORIGINAL_QUERY_PARAM).includes("true");
|
|
28
|
-
if (isOriginalRequest) {
|
|
29
|
-
entryResolution.watchFiles.forEach(file => pluginContext.addWatchFile(file));
|
|
30
|
-
return fs.readFile(entryResolution.absolutePath, "utf8");
|
|
31
|
-
}
|
|
32
|
-
entryResolution.watchFiles.forEach(file => pluginContext.addWatchFile(file));
|
|
19
|
+
function getClientEntrypointSource(params) {
|
|
20
|
+
const { applicationEntrypointImportSpecifier } = params;
|
|
33
21
|
const { browserRuntimeFreeze, tokenSubstitution, DPoP, sessionRestorationMethod } = oidcSpaVitePluginParams ?? {};
|
|
34
22
|
return [
|
|
35
23
|
`import { oidcEarlyInit } from "oidc-spa/entrypoint";`,
|
|
@@ -60,8 +48,7 @@ export function createHandleClientEntrypoint(params) {
|
|
|
60
48
|
`});`,
|
|
61
49
|
``,
|
|
62
50
|
`if (shouldLoadApp) {`,
|
|
63
|
-
|
|
64
|
-
`import("./${path.basename(entryResolution.absolutePath)}?${ORIGINAL_QUERY_PARAM}=true");`,
|
|
51
|
+
`import(${JSON.stringify(applicationEntrypointImportSpecifier)});`,
|
|
65
52
|
`}`
|
|
66
53
|
].join("\n");
|
|
67
54
|
function paramsToJsLiteral(params) {
|
|
@@ -85,7 +72,26 @@ export function createHandleClientEntrypoint(params) {
|
|
|
85
72
|
].join(" ");
|
|
86
73
|
}
|
|
87
74
|
}
|
|
88
|
-
|
|
75
|
+
async function load_handleClientEntrypoint(params) {
|
|
76
|
+
const { id, pluginContext, doUseOriginalEntrypoint, buildMarker } = params;
|
|
77
|
+
const { path: rawPath, queryParams } = splitId(id);
|
|
78
|
+
const normalizedRequestPath = normalizeRequestPath(rawPath);
|
|
79
|
+
const isMatch = normalizedRequestPath && normalizedRequestPath === entryResolution.normalizedPath;
|
|
80
|
+
if (!isMatch) {
|
|
81
|
+
return null;
|
|
82
|
+
}
|
|
83
|
+
const isOriginalRequest = doUseOriginalEntrypoint || queryParams.getAll(ORIGINAL_QUERY_PARAM).includes("true");
|
|
84
|
+
if (isOriginalRequest) {
|
|
85
|
+
entryResolution.watchFiles.forEach(file => pluginContext.addWatchFile(file));
|
|
86
|
+
const originalSource = await fs.readFile(entryResolution.absolutePath, "utf8");
|
|
87
|
+
return buildMarker === undefined ? originalSource : `${buildMarker}\n${originalSource}`;
|
|
88
|
+
}
|
|
89
|
+
entryResolution.watchFiles.forEach(file => pluginContext.addWatchFile(file));
|
|
90
|
+
return getClientEntrypointSource({
|
|
91
|
+
applicationEntrypointImportSpecifier: `./${path.basename(entryResolution.absolutePath)}?${ORIGINAL_QUERY_PARAM}=true`
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
return { load_handleClientEntrypoint, getClientEntrypointSource };
|
|
89
95
|
}
|
|
90
96
|
function resolveEntryForProject({ config, projectType }) {
|
|
91
97
|
const root = config.root;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleClientEntrypoint.mjs","sourceRoot":"","sources":["../../src/vite-plugin/handleClientEntrypoint.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnE,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAG/C,OAAO,EACH,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,EACjB,OAAO,EACP,oBAAoB,EACvB,MAAM,SAAS,CAAC;AAQjB,MAAM,oBAAoB,GAAG,mBAAmB,CAAC;AAEjD,MAAM,6BAA6B,GAAG;IAClC,kBAAkB;IAClB,iBAAiB;IACjB,kBAAkB;IAClB,iBAAiB;CACpB,CAAC;AAEF,MAAM,yBAAyB,GAAG,CAAC,YAAY,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;AAEzF,MAAM,UAAU,4BAA4B,CAAC,MAI5C;IACG,MAAM,EAAE,uBAAuB,EAAE,cAAc,EAAE,WAAW,EAAE,GAAG,MAAM,CAAC;IAExE,MAAM,eAAe,GAAG,sBAAsB,CAAC;QAC3C,MAAM,EAAE,cAAc;QACtB,WAAW;KACd,CAAC,CAAC;IAEH,
|
|
1
|
+
{"version":3,"file":"handleClientEntrypoint.mjs","sourceRoot":"","sources":["../../src/vite-plugin/handleClientEntrypoint.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,QAAQ,IAAI,EAAE,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACnE,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,MAAM,EA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
export declare function createHandleTanstackStartClientOutput(params: {
|
|
3
|
+
resolvedConfig: ResolvedConfig;
|
|
4
|
+
getClientEntrypointSource: (params: {
|
|
5
|
+
applicationEntrypointImportSpecifier: string;
|
|
6
|
+
}) => string;
|
|
7
|
+
}): {
|
|
8
|
+
resolveId: (id: string) => null | string | {
|
|
9
|
+
id: string;
|
|
10
|
+
external: true;
|
|
11
|
+
};
|
|
12
|
+
load: (id: string) => null | string;
|
|
13
|
+
buildStart: (this: Rollup.PluginContext) => void;
|
|
14
|
+
generateBundle: (this: Rollup.PluginContext, _options: Rollup.NormalizedOutputOptions, bundle: Rollup.OutputBundle) => Promise<void>;
|
|
15
|
+
applicationEntryBuildMarker: string;
|
|
16
|
+
};
|
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
const BOOTSTRAP_ENTRY_ID = "virtual:oidc-spa/tanstack-start-client-bootstrap";
|
|
6
|
+
const RESOLVED_BOOTSTRAP_ENTRY_ID = `\0${BOOTSTRAP_ENTRY_ID}`;
|
|
7
|
+
const APPLICATION_ENTRY_PLACEHOLDER = "oidc-spa:tanstack-start-application-entry";
|
|
8
|
+
export function createHandleTanstackStartClientOutput(params) {
|
|
9
|
+
const { resolvedConfig, getClientEntrypointSource } = params;
|
|
10
|
+
const bootstrapSource = getClientEntrypointSource({
|
|
11
|
+
applicationEntrypointImportSpecifier: APPLICATION_ENTRY_PLACEHOLDER
|
|
12
|
+
});
|
|
13
|
+
const applicationEntryBuildMarker = getApplicationEntryBuildMarker({ bootstrapSource });
|
|
14
|
+
function resolveId(id) {
|
|
15
|
+
if (id === BOOTSTRAP_ENTRY_ID) {
|
|
16
|
+
return RESOLVED_BOOTSTRAP_ENTRY_ID;
|
|
17
|
+
}
|
|
18
|
+
if (id === APPLICATION_ENTRY_PLACEHOLDER) {
|
|
19
|
+
return { id, external: true };
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
function load(id) {
|
|
24
|
+
return id === RESOLVED_BOOTSTRAP_ENTRY_ID ? bootstrapSource : null;
|
|
25
|
+
}
|
|
26
|
+
function buildStart() {
|
|
27
|
+
if (!isClientEnvironment({ pluginContext: this, resolvedConfig })) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// This keeps the bootstrap independent from the application graph. The
|
|
31
|
+
// temporary entry is finalized and removed before TanStack captures it.
|
|
32
|
+
this.emitFile({
|
|
33
|
+
type: "chunk",
|
|
34
|
+
id: BOOTSTRAP_ENTRY_ID,
|
|
35
|
+
name: "oidc-spa-bootstrap",
|
|
36
|
+
preserveSignature: false
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async function generateBundle(_options, bundle) {
|
|
40
|
+
if (!isClientEnvironment({ pluginContext: this, resolvedConfig })) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const bootstrapChunk = Object.values(bundle).find((output) => output.type === "chunk" && output.moduleIds.includes(RESOLVED_BOOTSTRAP_ENTRY_ID));
|
|
44
|
+
if (bootstrapChunk === undefined) {
|
|
45
|
+
this.error("oidc-spa: The TanStack Start client bootstrap chunk was not emitted.");
|
|
46
|
+
}
|
|
47
|
+
const applicationEntryChunks = Object.values(bundle).filter((output) => output.type === "chunk" && output.isEntry && output !== bootstrapChunk);
|
|
48
|
+
if (applicationEntryChunks.length !== 1) {
|
|
49
|
+
this.error(`oidc-spa: Expected exactly one TanStack Start client entry chunk, found ${applicationEntryChunks.length}.`);
|
|
50
|
+
}
|
|
51
|
+
const [entryChunk] = applicationEntryChunks;
|
|
52
|
+
assertBootstrapSynchronousGraphIsIsolated({
|
|
53
|
+
pluginContext: this,
|
|
54
|
+
bundle,
|
|
55
|
+
bootstrapChunk,
|
|
56
|
+
applicationEntryChunk: entryChunk
|
|
57
|
+
});
|
|
58
|
+
const applicationEntryFileName = getApplicationEntryFileName({
|
|
59
|
+
entryFileName: entryChunk.fileName,
|
|
60
|
+
bundle
|
|
61
|
+
});
|
|
62
|
+
for (const output of Object.values(bundle)) {
|
|
63
|
+
if (output.type !== "chunk") {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
rewriteChunkEntryReferences({
|
|
67
|
+
chunk: output,
|
|
68
|
+
previousEntryFileName: entryChunk.fileName,
|
|
69
|
+
applicationEntryFileName
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
const applicationEntryCode = entryChunk.code;
|
|
73
|
+
const applicationEntryMap = entryChunk.map;
|
|
74
|
+
const outputHash = createHash("sha256")
|
|
75
|
+
.update(applicationEntryCode)
|
|
76
|
+
.update("\0")
|
|
77
|
+
.update(bootstrapChunk.code)
|
|
78
|
+
.digest("base64url")
|
|
79
|
+
.slice(0, 12);
|
|
80
|
+
const finalizedBootstrapFileName = addFileNameSuffix({
|
|
81
|
+
fileName: bootstrapChunk.fileName,
|
|
82
|
+
suffix: outputHash
|
|
83
|
+
});
|
|
84
|
+
const finalizedBootstrapCode = replaceApplicationEntryPlaceholder({
|
|
85
|
+
code: bootstrapChunk.code,
|
|
86
|
+
applicationEntryImportSpecifier: toRelativeImportSpecifier({
|
|
87
|
+
importerFileName: finalizedBootstrapFileName,
|
|
88
|
+
importedFileName: applicationEntryFileName
|
|
89
|
+
})
|
|
90
|
+
});
|
|
91
|
+
delete bundle[bootstrapChunk.fileName];
|
|
92
|
+
this.emitFile({
|
|
93
|
+
type: "prebuilt-chunk",
|
|
94
|
+
fileName: finalizedBootstrapFileName,
|
|
95
|
+
code: finalizedBootstrapCode,
|
|
96
|
+
exports: bootstrapChunk.exports
|
|
97
|
+
});
|
|
98
|
+
this.emitFile({
|
|
99
|
+
type: "prebuilt-chunk",
|
|
100
|
+
fileName: applicationEntryFileName,
|
|
101
|
+
code: applicationEntryCode,
|
|
102
|
+
exports: entryChunk.exports,
|
|
103
|
+
map: applicationEntryMap === null
|
|
104
|
+
? undefined
|
|
105
|
+
: {
|
|
106
|
+
...applicationEntryMap,
|
|
107
|
+
file: path.posix.basename(applicationEntryFileName)
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
for (const fileName of [finalizedBootstrapFileName, applicationEntryFileName]) {
|
|
111
|
+
initializeViteMetadataForPrebuiltChunk({ bundle, fileName });
|
|
112
|
+
}
|
|
113
|
+
const bootstrapImportSpecifier = toRelativeImportSpecifier({
|
|
114
|
+
importerFileName: entryChunk.fileName,
|
|
115
|
+
importedFileName: finalizedBootstrapFileName
|
|
116
|
+
});
|
|
117
|
+
entryChunk.code = `import ${JSON.stringify(bootstrapImportSpecifier)};\n`;
|
|
118
|
+
const mutableEntryChunk = entryChunk;
|
|
119
|
+
mutableEntryChunk.map = null;
|
|
120
|
+
}
|
|
121
|
+
return { resolveId, load, buildStart, generateBundle, applicationEntryBuildMarker };
|
|
122
|
+
}
|
|
123
|
+
function initializeViteMetadataForPrebuiltChunk(params) {
|
|
124
|
+
const { bundle, fileName } = params;
|
|
125
|
+
const output = bundle[fileName];
|
|
126
|
+
if (output === undefined || output.type !== "chunk") {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const outputWithViteMetadata = output;
|
|
130
|
+
if (outputWithViteMetadata.viteMetadata !== undefined) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
// Rollup exposes prebuilt chunks emitted during generateBundle immediately,
|
|
134
|
+
// after Vite's renderChunk metadata initializer has already run.
|
|
135
|
+
outputWithViteMetadata.viteMetadata = {
|
|
136
|
+
importedAssets: new Set(),
|
|
137
|
+
importedCss: new Set(),
|
|
138
|
+
__modules: output.modules
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function getApplicationEntryBuildMarker(params) {
|
|
142
|
+
const { bootstrapSource } = params;
|
|
143
|
+
const packageVersion = findOidcSpaPackageVersion();
|
|
144
|
+
const fingerprint = createHash("sha256")
|
|
145
|
+
.update(packageVersion)
|
|
146
|
+
.update("\0")
|
|
147
|
+
.update(bootstrapSource)
|
|
148
|
+
.digest("hex")
|
|
149
|
+
.slice(0, 16);
|
|
150
|
+
// This property read survives tree-shaking and executes only after the
|
|
151
|
+
// security bootstrap elects to load the application.
|
|
152
|
+
return `globalThis[${JSON.stringify(`__oidcSpaBuild_${fingerprint}`)}];`;
|
|
153
|
+
}
|
|
154
|
+
function findOidcSpaPackageVersion() {
|
|
155
|
+
let directory = path.dirname(fileURLToPath(import.meta.url));
|
|
156
|
+
while (true) {
|
|
157
|
+
const packageJsonPath = path.join(directory, "package.json");
|
|
158
|
+
if (existsSync(packageJsonPath)) {
|
|
159
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8"));
|
|
160
|
+
if (packageJson.name === "oidc-spa" && typeof packageJson.version === "string") {
|
|
161
|
+
return packageJson.version;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
const parentDirectory = path.dirname(directory);
|
|
165
|
+
if (parentDirectory === directory) {
|
|
166
|
+
throw new Error("oidc-spa: Could not read the package version for the build marker.");
|
|
167
|
+
}
|
|
168
|
+
directory = parentDirectory;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function assertBootstrapSynchronousGraphIsIsolated(params) {
|
|
172
|
+
const { pluginContext, bundle, bootstrapChunk, applicationEntryChunk } = params;
|
|
173
|
+
const allowedModuleIds = new Set();
|
|
174
|
+
const pendingModuleIds = [RESOLVED_BOOTSTRAP_ENTRY_ID];
|
|
175
|
+
while (pendingModuleIds.length !== 0) {
|
|
176
|
+
const moduleId = pendingModuleIds.pop();
|
|
177
|
+
if (moduleId === undefined || allowedModuleIds.has(moduleId)) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
allowedModuleIds.add(moduleId);
|
|
181
|
+
const moduleInfo = pluginContext.getModuleInfo(moduleId);
|
|
182
|
+
if (moduleInfo === null) {
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
pendingModuleIds.push(...moduleInfo.importedIds);
|
|
186
|
+
}
|
|
187
|
+
const chunksByFileName = new Map(Object.values(bundle)
|
|
188
|
+
.filter((output) => output.type === "chunk")
|
|
189
|
+
.map(chunk => [chunk.fileName, chunk]));
|
|
190
|
+
const pendingChunks = [bootstrapChunk];
|
|
191
|
+
const visitedChunkFileNames = new Set();
|
|
192
|
+
while (pendingChunks.length !== 0) {
|
|
193
|
+
const chunk = pendingChunks.pop();
|
|
194
|
+
if (chunk === undefined || visitedChunkFileNames.has(chunk.fileName)) {
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
visitedChunkFileNames.add(chunk.fileName);
|
|
198
|
+
if (chunk === applicationEntryChunk) {
|
|
199
|
+
throw new Error("oidc-spa: TanStack Start placed the application entry in the synchronous bootstrap graph.");
|
|
200
|
+
}
|
|
201
|
+
const unexpectedModuleId = chunk.moduleIds.find(moduleId => !allowedModuleIds.has(moduleId) && !isViteRuntimeModule(moduleId));
|
|
202
|
+
if (unexpectedModuleId !== undefined) {
|
|
203
|
+
throw new Error(`oidc-spa: TanStack Start placed an application module in the synchronous bootstrap graph: ${unexpectedModuleId}`);
|
|
204
|
+
}
|
|
205
|
+
for (const importedFileName of chunk.imports) {
|
|
206
|
+
const importedChunk = chunksByFileName.get(importedFileName);
|
|
207
|
+
if (importedChunk !== undefined) {
|
|
208
|
+
pendingChunks.push(importedChunk);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
function isViteRuntimeModule(moduleId) {
|
|
214
|
+
return (moduleId.startsWith("\0vite/") ||
|
|
215
|
+
moduleId.startsWith("\0rolldown/") ||
|
|
216
|
+
moduleId.startsWith("\0commonjsHelpers") ||
|
|
217
|
+
moduleId.includes("vite/preload-helper"));
|
|
218
|
+
}
|
|
219
|
+
function addFileNameSuffix(params) {
|
|
220
|
+
const { fileName, suffix } = params;
|
|
221
|
+
const extension = path.posix.extname(fileName);
|
|
222
|
+
if (extension === "") {
|
|
223
|
+
return `${fileName}-${suffix}`;
|
|
224
|
+
}
|
|
225
|
+
return `${fileName.slice(0, -extension.length)}-${suffix}${extension}`;
|
|
226
|
+
}
|
|
227
|
+
function isClientEnvironment(params) {
|
|
228
|
+
const { pluginContext, resolvedConfig } = params;
|
|
229
|
+
const environmentName = pluginContext.environment?.name;
|
|
230
|
+
if (environmentName !== undefined) {
|
|
231
|
+
return environmentName === "client";
|
|
232
|
+
}
|
|
233
|
+
return !resolvedConfig.build.ssr;
|
|
234
|
+
}
|
|
235
|
+
function getApplicationEntryFileName(params) {
|
|
236
|
+
const { entryFileName, bundle } = params;
|
|
237
|
+
const directory = path.posix.dirname(entryFileName);
|
|
238
|
+
const basename = path.posix.basename(entryFileName);
|
|
239
|
+
for (let index = 0; index < basename.length; index++) {
|
|
240
|
+
if (basename[index] !== "-") {
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
const candidateBasename = `${basename.slice(0, index)}_${basename.slice(index + 1)}`;
|
|
244
|
+
const candidate = path.posix.join(directory === "." ? "" : directory, candidateBasename);
|
|
245
|
+
if (bundle[candidate] === undefined) {
|
|
246
|
+
return candidate;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
for (let index = 0; index < basename.length; index++) {
|
|
250
|
+
if (basename[index] === "_") {
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
const candidateBasename = `${basename.slice(0, index)}_${basename.slice(index + 1)}`;
|
|
254
|
+
const candidate = path.posix.join(directory === "." ? "" : directory, candidateBasename);
|
|
255
|
+
if (bundle[candidate] === undefined) {
|
|
256
|
+
return candidate;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
throw new Error(`oidc-spa: Could not allocate an application entry beside "${entryFileName}".`);
|
|
260
|
+
}
|
|
261
|
+
function rewriteChunkEntryReferences(params) {
|
|
262
|
+
const { chunk, previousEntryFileName, applicationEntryFileName } = params;
|
|
263
|
+
const previousRelativeSpecifier = toRelativeImportSpecifier({
|
|
264
|
+
importerFileName: chunk.fileName,
|
|
265
|
+
importedFileName: previousEntryFileName
|
|
266
|
+
});
|
|
267
|
+
const applicationRelativeSpecifier = toRelativeImportSpecifier({
|
|
268
|
+
importerFileName: chunk.fileName,
|
|
269
|
+
importedFileName: applicationEntryFileName
|
|
270
|
+
});
|
|
271
|
+
const replacements = new Map([
|
|
272
|
+
[previousEntryFileName, applicationEntryFileName],
|
|
273
|
+
[previousRelativeSpecifier, applicationRelativeSpecifier]
|
|
274
|
+
]);
|
|
275
|
+
for (const [from, to] of replacements) {
|
|
276
|
+
if (from === to) {
|
|
277
|
+
continue;
|
|
278
|
+
}
|
|
279
|
+
if (from.length !== to.length) {
|
|
280
|
+
throw new Error("oidc-spa: Internal entry rewrite changed generated code offsets.");
|
|
281
|
+
}
|
|
282
|
+
chunk.code = chunk.code.split(from).join(to);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function replaceApplicationEntryPlaceholder(params) {
|
|
286
|
+
const { code, applicationEntryImportSpecifier } = params;
|
|
287
|
+
const occurrences = code.split(APPLICATION_ENTRY_PLACEHOLDER).length - 1;
|
|
288
|
+
if (occurrences !== 1) {
|
|
289
|
+
throw new Error(`oidc-spa: Expected one application entry placeholder in the generated bootstrap, found ${occurrences}.`);
|
|
290
|
+
}
|
|
291
|
+
return code.replace(APPLICATION_ENTRY_PLACEHOLDER, applicationEntryImportSpecifier);
|
|
292
|
+
}
|
|
293
|
+
function toRelativeImportSpecifier(params) {
|
|
294
|
+
const { importerFileName, importedFileName } = params;
|
|
295
|
+
const relativePath = path.posix.relative(path.posix.dirname(importerFileName), importedFileName);
|
|
296
|
+
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
297
|
+
}
|
|
298
|
+
//# sourceMappingURL=handleTanstackStartClientOutput.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handleTanstackStartClientOutput.mjs","sourceRoot":"","sources":["../../src/vite-plugin/handleTanstackStartClientO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AAI,CAAC,KAAK,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,gBAAgB,CAAC,CAAC;IACjG,OAAO,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,YAAY,EAAE,CAAC;AAC7E,CAAC"}
|
|
@@ -4,10 +4,17 @@ import { createHandleServerEntrypoint } from "./handleServerEntrypoint.mjs";
|
|
|
4
4
|
import { manageOptimizedDeps } from "./manageOptimizedDeps.mjs";
|
|
5
5
|
import { transformCreateFileRoute } from "./transformTanstackRouterCreateFileRoute.mjs";
|
|
6
6
|
import { getProjectType } from "./projectType.mjs";
|
|
7
|
+
import { createHandleTanstackStartClientOutput } from "./handleTanstackStartClientOutput.mjs";
|
|
7
8
|
export function oidcSpa(params = {}) {
|
|
8
9
|
let load_handleClientEntrypoint = undefined;
|
|
10
|
+
let resolveId_handleTanstackStartClientOutput = undefined;
|
|
11
|
+
let load_handleTanstackStartClientOutput = undefined;
|
|
12
|
+
let buildStart_handleTanstackStartClientOutput = undefined;
|
|
13
|
+
let generateBundle_handleTanstackStartClientOutput = undefined;
|
|
14
|
+
let tanstackStartApplicationEntryBuildMarker = undefined;
|
|
9
15
|
let load_handleServerEntrypoint = undefined;
|
|
10
16
|
let projectType = undefined;
|
|
17
|
+
let isBuild = false;
|
|
11
18
|
const plugin = {
|
|
12
19
|
name: "oidc-spa",
|
|
13
20
|
enforce: "pre",
|
|
@@ -23,14 +30,29 @@ export function oidcSpa(params = {}) {
|
|
|
23
30
|
return userConfig;
|
|
24
31
|
},
|
|
25
32
|
configResolved(resolvedConfig) {
|
|
33
|
+
isBuild = resolvedConfig.command === "build";
|
|
26
34
|
projectType = getProjectType({
|
|
27
35
|
pluginNames: resolvedConfig.plugins.map(({ name }) => name)
|
|
28
36
|
});
|
|
29
|
-
|
|
37
|
+
const clientEntrypointHandler = createHandleClientEntrypoint({
|
|
30
38
|
oidcSpaVitePluginParams: params,
|
|
31
39
|
resolvedConfig,
|
|
32
40
|
projectType
|
|
33
|
-
})
|
|
41
|
+
});
|
|
42
|
+
load_handleClientEntrypoint = clientEntrypointHandler.load_handleClientEntrypoint;
|
|
43
|
+
if (projectType === "tanstack-start" && isBuild) {
|
|
44
|
+
const tanstackStartClientOutputHandler = createHandleTanstackStartClientOutput({
|
|
45
|
+
resolvedConfig,
|
|
46
|
+
getClientEntrypointSource: clientEntrypointHandler.getClientEntrypointSource
|
|
47
|
+
});
|
|
48
|
+
resolveId_handleTanstackStartClientOutput = tanstackStartClientOutputHandler.resolveId;
|
|
49
|
+
load_handleTanstackStartClientOutput = tanstackStartClientOutputHandler.load;
|
|
50
|
+
buildStart_handleTanstackStartClientOutput = tanstackStartClientOutputHandler.buildStart;
|
|
51
|
+
generateBundle_handleTanstackStartClientOutput =
|
|
52
|
+
tanstackStartClientOutputHandler.generateBundle;
|
|
53
|
+
tanstackStartApplicationEntryBuildMarker =
|
|
54
|
+
tanstackStartClientOutputHandler.applicationEntryBuildMarker;
|
|
55
|
+
}
|
|
34
56
|
load_handleServerEntrypoint = createHandleServerEntrypoint({
|
|
35
57
|
resolvedConfig,
|
|
36
58
|
projectType
|
|
@@ -50,12 +72,32 @@ export function oidcSpa(params = {}) {
|
|
|
50
72
|
}
|
|
51
73
|
return transformed;
|
|
52
74
|
},
|
|
75
|
+
resolveId(id) {
|
|
76
|
+
return resolveId_handleTanstackStartClientOutput?.(id) ?? null;
|
|
77
|
+
},
|
|
78
|
+
buildStart() {
|
|
79
|
+
buildStart_handleTanstackStartClientOutput?.call(this);
|
|
80
|
+
},
|
|
53
81
|
async load(id) {
|
|
82
|
+
{
|
|
83
|
+
const r = load_handleTanstackStartClientOutput?.(id) ?? null;
|
|
84
|
+
if (r !== null) {
|
|
85
|
+
return r;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
54
88
|
{
|
|
55
89
|
assert(load_handleClientEntrypoint !== undefined);
|
|
90
|
+
const doUseOriginalEntrypoint = projectType === "tanstack-start" &&
|
|
91
|
+
isBuild &&
|
|
92
|
+
(this.environment?.name ??
|
|
93
|
+
"client") === "client";
|
|
56
94
|
const r = await load_handleClientEntrypoint({
|
|
57
95
|
id,
|
|
58
|
-
pluginContext: this
|
|
96
|
+
pluginContext: this,
|
|
97
|
+
doUseOriginalEntrypoint,
|
|
98
|
+
buildMarker: doUseOriginalEntrypoint
|
|
99
|
+
? tanstackStartApplicationEntryBuildMarker
|
|
100
|
+
: undefined
|
|
59
101
|
});
|
|
60
102
|
if (r !== null) {
|
|
61
103
|
return r;
|
|
@@ -72,6 +114,12 @@ export function oidcSpa(params = {}) {
|
|
|
72
114
|
}
|
|
73
115
|
}
|
|
74
116
|
return null;
|
|
117
|
+
},
|
|
118
|
+
generateBundle: {
|
|
119
|
+
order: "pre",
|
|
120
|
+
async handler(options, bundle) {
|
|
121
|
+
await generateBundle_handleTanstackStartClientOutput?.call(this, options, bundle);
|
|
122
|
+
}
|
|
75
123
|
}
|
|
76
124
|
};
|
|
77
125
|
return plugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.mjs","sourceRoot":"","sources":["../../src/vite-plugin/vite-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,OAAO,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,4BAA4B,EAAE,MAAM,0BAA0B,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAC;AACpF,OAAO,EAAE,cAAc,EAAoB,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"vite-plugin.mjs","sourceRoot":"","sources":["../../src/vite-plugin/vite-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAE/C,OAAO,EAAE,4BAA4B,EA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AAc,EAAE;YACZ,KAAK,EAAE,KAAK;YACZ,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM;gBACzB,MAAM,8CAA8C,EAAE,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;YACtF,CAAC;SACJ;KACJ,CAAC;IAEF,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
package/package.json
CHANGED
|
@@ -43,30 +43,10 @@ export function createHandleClientEntrypoint(params: {
|
|
|
43
43
|
projectType
|
|
44
44
|
});
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const { id, pluginContext } = params;
|
|
51
|
-
const { path: rawPath, queryParams } = splitId(id);
|
|
52
|
-
|
|
53
|
-
const normalizedRequestPath = normalizeRequestPath(rawPath);
|
|
54
|
-
const isMatch =
|
|
55
|
-
normalizedRequestPath && normalizedRequestPath === entryResolution.normalizedPath;
|
|
56
|
-
|
|
57
|
-
if (!isMatch) {
|
|
58
|
-
return null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const isOriginalRequest = queryParams.getAll(ORIGINAL_QUERY_PARAM).includes("true");
|
|
62
|
-
|
|
63
|
-
if (isOriginalRequest) {
|
|
64
|
-
entryResolution.watchFiles.forEach(file => pluginContext.addWatchFile(file));
|
|
65
|
-
return fs.readFile(entryResolution.absolutePath, "utf8");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
entryResolution.watchFiles.forEach(file => pluginContext.addWatchFile(file));
|
|
69
|
-
|
|
46
|
+
function getClientEntrypointSource(params: {
|
|
47
|
+
applicationEntrypointImportSpecifier: string;
|
|
48
|
+
}): string {
|
|
49
|
+
const { applicationEntrypointImportSpecifier } = params;
|
|
70
50
|
const { browserRuntimeFreeze, tokenSubstitution, DPoP, sessionRestorationMethod } =
|
|
71
51
|
oidcSpaVitePluginParams ?? {};
|
|
72
52
|
|
|
@@ -94,8 +74,7 @@ export function createHandleClientEntrypoint(params: {
|
|
|
94
74
|
`});`,
|
|
95
75
|
``,
|
|
96
76
|
`if (shouldLoadApp) {`,
|
|
97
|
-
|
|
98
|
-
`import("./${path.basename(entryResolution.absolutePath)}?${ORIGINAL_QUERY_PARAM}=true");`,
|
|
77
|
+
`import(${JSON.stringify(applicationEntrypointImportSpecifier)});`,
|
|
99
78
|
`}`
|
|
100
79
|
].join("\n");
|
|
101
80
|
|
|
@@ -141,7 +120,42 @@ export function createHandleClientEntrypoint(params: {
|
|
|
141
120
|
}
|
|
142
121
|
}
|
|
143
122
|
|
|
144
|
-
|
|
123
|
+
async function load_handleClientEntrypoint(params: {
|
|
124
|
+
id: string;
|
|
125
|
+
pluginContext: PluginContext;
|
|
126
|
+
doUseOriginalEntrypoint: boolean;
|
|
127
|
+
buildMarker?: string;
|
|
128
|
+
}): Promise<null | string> {
|
|
129
|
+
const { id, pluginContext, doUseOriginalEntrypoint, buildMarker } = params;
|
|
130
|
+
const { path: rawPath, queryParams } = splitId(id);
|
|
131
|
+
|
|
132
|
+
const normalizedRequestPath = normalizeRequestPath(rawPath);
|
|
133
|
+
const isMatch =
|
|
134
|
+
normalizedRequestPath && normalizedRequestPath === entryResolution.normalizedPath;
|
|
135
|
+
|
|
136
|
+
if (!isMatch) {
|
|
137
|
+
return null;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const isOriginalRequest =
|
|
141
|
+
doUseOriginalEntrypoint || queryParams.getAll(ORIGINAL_QUERY_PARAM).includes("true");
|
|
142
|
+
|
|
143
|
+
if (isOriginalRequest) {
|
|
144
|
+
entryResolution.watchFiles.forEach(file => pluginContext.addWatchFile(file));
|
|
145
|
+
const originalSource = await fs.readFile(entryResolution.absolutePath, "utf8");
|
|
146
|
+
return buildMarker === undefined ? originalSource : `${buildMarker}\n${originalSource}`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
entryResolution.watchFiles.forEach(file => pluginContext.addWatchFile(file));
|
|
150
|
+
|
|
151
|
+
return getClientEntrypointSource({
|
|
152
|
+
applicationEntrypointImportSpecifier: `./${path.basename(
|
|
153
|
+
entryResolution.absolutePath
|
|
154
|
+
)}?${ORIGINAL_QUERY_PARAM}=true`
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return { load_handleClientEntrypoint, getClientEntrypointSource };
|
|
145
159
|
}
|
|
146
160
|
|
|
147
161
|
function resolveEntryForProject({
|
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import type { ResolvedConfig, Rollup } from "vite";
|
|
6
|
+
|
|
7
|
+
const BOOTSTRAP_ENTRY_ID = "virtual:oidc-spa/tanstack-start-client-bootstrap";
|
|
8
|
+
const RESOLVED_BOOTSTRAP_ENTRY_ID = `\0${BOOTSTRAP_ENTRY_ID}`;
|
|
9
|
+
const APPLICATION_ENTRY_PLACEHOLDER = "oidc-spa:tanstack-start-application-entry";
|
|
10
|
+
|
|
11
|
+
type PluginContextWithEnvironment = Rollup.PluginContext & {
|
|
12
|
+
environment?: {
|
|
13
|
+
name?: string;
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type MutableOutputChunk = {
|
|
18
|
+
map: Rollup.SourceMap | null;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
type OutputChunkWithViteMetadata = {
|
|
22
|
+
viteMetadata?: {
|
|
23
|
+
importedAssets: Set<string>;
|
|
24
|
+
importedCss: Set<string>;
|
|
25
|
+
__modules?: Rollup.OutputChunk["modules"];
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export function createHandleTanstackStartClientOutput(params: {
|
|
30
|
+
resolvedConfig: ResolvedConfig;
|
|
31
|
+
getClientEntrypointSource: (params: { applicationEntrypointImportSpecifier: string }) => string;
|
|
32
|
+
}) {
|
|
33
|
+
const { resolvedConfig, getClientEntrypointSource } = params;
|
|
34
|
+
|
|
35
|
+
const bootstrapSource = getClientEntrypointSource({
|
|
36
|
+
applicationEntrypointImportSpecifier: APPLICATION_ENTRY_PLACEHOLDER
|
|
37
|
+
});
|
|
38
|
+
const applicationEntryBuildMarker = getApplicationEntryBuildMarker({ bootstrapSource });
|
|
39
|
+
|
|
40
|
+
function resolveId(id: string): null | string | { id: string; external: true } {
|
|
41
|
+
if (id === BOOTSTRAP_ENTRY_ID) {
|
|
42
|
+
return RESOLVED_BOOTSTRAP_ENTRY_ID;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (id === APPLICATION_ENTRY_PLACEHOLDER) {
|
|
46
|
+
return { id, external: true };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function load(id: string): null | string {
|
|
53
|
+
return id === RESOLVED_BOOTSTRAP_ENTRY_ID ? bootstrapSource : null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function buildStart(this: Rollup.PluginContext): void {
|
|
57
|
+
if (!isClientEnvironment({ pluginContext: this, resolvedConfig })) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// This keeps the bootstrap independent from the application graph. The
|
|
62
|
+
// temporary entry is finalized and removed before TanStack captures it.
|
|
63
|
+
this.emitFile({
|
|
64
|
+
type: "chunk",
|
|
65
|
+
id: BOOTSTRAP_ENTRY_ID,
|
|
66
|
+
name: "oidc-spa-bootstrap",
|
|
67
|
+
preserveSignature: false
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function generateBundle(
|
|
72
|
+
this: Rollup.PluginContext,
|
|
73
|
+
_options: Rollup.NormalizedOutputOptions,
|
|
74
|
+
bundle: Rollup.OutputBundle
|
|
75
|
+
): Promise<void> {
|
|
76
|
+
if (!isClientEnvironment({ pluginContext: this, resolvedConfig })) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const bootstrapChunk = Object.values(bundle).find(
|
|
81
|
+
(output): output is Rollup.OutputChunk =>
|
|
82
|
+
output.type === "chunk" && output.moduleIds.includes(RESOLVED_BOOTSTRAP_ENTRY_ID)
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
if (bootstrapChunk === undefined) {
|
|
86
|
+
this.error("oidc-spa: The TanStack Start client bootstrap chunk was not emitted.");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const applicationEntryChunks = Object.values(bundle).filter(
|
|
90
|
+
(output): output is Rollup.OutputChunk =>
|
|
91
|
+
output.type === "chunk" && output.isEntry && output !== bootstrapChunk
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
if (applicationEntryChunks.length !== 1) {
|
|
95
|
+
this.error(
|
|
96
|
+
`oidc-spa: Expected exactly one TanStack Start client entry chunk, found ${applicationEntryChunks.length}.`
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const [entryChunk] = applicationEntryChunks;
|
|
101
|
+
|
|
102
|
+
assertBootstrapSynchronousGraphIsIsolated({
|
|
103
|
+
pluginContext: this,
|
|
104
|
+
bundle,
|
|
105
|
+
bootstrapChunk,
|
|
106
|
+
applicationEntryChunk: entryChunk
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const applicationEntryFileName = getApplicationEntryFileName({
|
|
110
|
+
entryFileName: entryChunk.fileName,
|
|
111
|
+
bundle
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
for (const output of Object.values(bundle)) {
|
|
115
|
+
if (output.type !== "chunk") {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
rewriteChunkEntryReferences({
|
|
120
|
+
chunk: output,
|
|
121
|
+
previousEntryFileName: entryChunk.fileName,
|
|
122
|
+
applicationEntryFileName
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const applicationEntryCode = entryChunk.code;
|
|
127
|
+
const applicationEntryMap = entryChunk.map;
|
|
128
|
+
const outputHash = createHash("sha256")
|
|
129
|
+
.update(applicationEntryCode)
|
|
130
|
+
.update("\0")
|
|
131
|
+
.update(bootstrapChunk.code)
|
|
132
|
+
.digest("base64url")
|
|
133
|
+
.slice(0, 12);
|
|
134
|
+
const finalizedBootstrapFileName = addFileNameSuffix({
|
|
135
|
+
fileName: bootstrapChunk.fileName,
|
|
136
|
+
suffix: outputHash
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
const finalizedBootstrapCode = replaceApplicationEntryPlaceholder({
|
|
140
|
+
code: bootstrapChunk.code,
|
|
141
|
+
applicationEntryImportSpecifier: toRelativeImportSpecifier({
|
|
142
|
+
importerFileName: finalizedBootstrapFileName,
|
|
143
|
+
importedFileName: applicationEntryFileName
|
|
144
|
+
})
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
delete bundle[bootstrapChunk.fileName];
|
|
148
|
+
|
|
149
|
+
this.emitFile({
|
|
150
|
+
type: "prebuilt-chunk",
|
|
151
|
+
fileName: finalizedBootstrapFileName,
|
|
152
|
+
code: finalizedBootstrapCode,
|
|
153
|
+
exports: bootstrapChunk.exports
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
this.emitFile({
|
|
157
|
+
type: "prebuilt-chunk",
|
|
158
|
+
fileName: applicationEntryFileName,
|
|
159
|
+
code: applicationEntryCode,
|
|
160
|
+
exports: entryChunk.exports,
|
|
161
|
+
map:
|
|
162
|
+
applicationEntryMap === null
|
|
163
|
+
? undefined
|
|
164
|
+
: {
|
|
165
|
+
...applicationEntryMap,
|
|
166
|
+
file: path.posix.basename(applicationEntryFileName)
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
for (const fileName of [finalizedBootstrapFileName, applicationEntryFileName]) {
|
|
171
|
+
initializeViteMetadataForPrebuiltChunk({ bundle, fileName });
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const bootstrapImportSpecifier = toRelativeImportSpecifier({
|
|
175
|
+
importerFileName: entryChunk.fileName,
|
|
176
|
+
importedFileName: finalizedBootstrapFileName
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
entryChunk.code = `import ${JSON.stringify(bootstrapImportSpecifier)};\n`;
|
|
180
|
+
|
|
181
|
+
const mutableEntryChunk = entryChunk as unknown as MutableOutputChunk;
|
|
182
|
+
mutableEntryChunk.map = null;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return { resolveId, load, buildStart, generateBundle, applicationEntryBuildMarker };
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function initializeViteMetadataForPrebuiltChunk(params: {
|
|
189
|
+
bundle: Rollup.OutputBundle;
|
|
190
|
+
fileName: string;
|
|
191
|
+
}): void {
|
|
192
|
+
const { bundle, fileName } = params;
|
|
193
|
+
const output = bundle[fileName];
|
|
194
|
+
|
|
195
|
+
if (output === undefined || output.type !== "chunk") {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const outputWithViteMetadata = output as unknown as OutputChunkWithViteMetadata;
|
|
200
|
+
|
|
201
|
+
if (outputWithViteMetadata.viteMetadata !== undefined) {
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Rollup exposes prebuilt chunks emitted during generateBundle immediately,
|
|
206
|
+
// after Vite's renderChunk metadata initializer has already run.
|
|
207
|
+
outputWithViteMetadata.viteMetadata = {
|
|
208
|
+
importedAssets: new Set(),
|
|
209
|
+
importedCss: new Set(),
|
|
210
|
+
__modules: output.modules
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function getApplicationEntryBuildMarker(params: { bootstrapSource: string }): string {
|
|
215
|
+
const { bootstrapSource } = params;
|
|
216
|
+
const packageVersion = findOidcSpaPackageVersion();
|
|
217
|
+
|
|
218
|
+
const fingerprint = createHash("sha256")
|
|
219
|
+
.update(packageVersion)
|
|
220
|
+
.update("\0")
|
|
221
|
+
.update(bootstrapSource)
|
|
222
|
+
.digest("hex")
|
|
223
|
+
.slice(0, 16);
|
|
224
|
+
|
|
225
|
+
// This property read survives tree-shaking and executes only after the
|
|
226
|
+
// security bootstrap elects to load the application.
|
|
227
|
+
return `globalThis[${JSON.stringify(`__oidcSpaBuild_${fingerprint}`)}];`;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function findOidcSpaPackageVersion(): string {
|
|
231
|
+
let directory = path.dirname(fileURLToPath(import.meta.url));
|
|
232
|
+
|
|
233
|
+
while (true) {
|
|
234
|
+
const packageJsonPath = path.join(directory, "package.json");
|
|
235
|
+
|
|
236
|
+
if (existsSync(packageJsonPath)) {
|
|
237
|
+
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf8")) as {
|
|
238
|
+
name?: unknown;
|
|
239
|
+
version?: unknown;
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
if (packageJson.name === "oidc-spa" && typeof packageJson.version === "string") {
|
|
243
|
+
return packageJson.version;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const parentDirectory = path.dirname(directory);
|
|
248
|
+
|
|
249
|
+
if (parentDirectory === directory) {
|
|
250
|
+
throw new Error("oidc-spa: Could not read the package version for the build marker.");
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
directory = parentDirectory;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function assertBootstrapSynchronousGraphIsIsolated(params: {
|
|
258
|
+
pluginContext: Rollup.PluginContext;
|
|
259
|
+
bundle: Rollup.OutputBundle;
|
|
260
|
+
bootstrapChunk: Rollup.OutputChunk;
|
|
261
|
+
applicationEntryChunk: Rollup.OutputChunk;
|
|
262
|
+
}): void {
|
|
263
|
+
const { pluginContext, bundle, bootstrapChunk, applicationEntryChunk } = params;
|
|
264
|
+
const allowedModuleIds = new Set<string>();
|
|
265
|
+
const pendingModuleIds = [RESOLVED_BOOTSTRAP_ENTRY_ID];
|
|
266
|
+
|
|
267
|
+
while (pendingModuleIds.length !== 0) {
|
|
268
|
+
const moduleId = pendingModuleIds.pop();
|
|
269
|
+
|
|
270
|
+
if (moduleId === undefined || allowedModuleIds.has(moduleId)) {
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
allowedModuleIds.add(moduleId);
|
|
275
|
+
|
|
276
|
+
const moduleInfo = pluginContext.getModuleInfo(moduleId);
|
|
277
|
+
|
|
278
|
+
if (moduleInfo === null) {
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
pendingModuleIds.push(...moduleInfo.importedIds);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
const chunksByFileName = new Map(
|
|
286
|
+
Object.values(bundle)
|
|
287
|
+
.filter((output): output is Rollup.OutputChunk => output.type === "chunk")
|
|
288
|
+
.map(chunk => [chunk.fileName, chunk])
|
|
289
|
+
);
|
|
290
|
+
const pendingChunks = [bootstrapChunk];
|
|
291
|
+
const visitedChunkFileNames = new Set<string>();
|
|
292
|
+
|
|
293
|
+
while (pendingChunks.length !== 0) {
|
|
294
|
+
const chunk = pendingChunks.pop();
|
|
295
|
+
|
|
296
|
+
if (chunk === undefined || visitedChunkFileNames.has(chunk.fileName)) {
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
visitedChunkFileNames.add(chunk.fileName);
|
|
301
|
+
|
|
302
|
+
if (chunk === applicationEntryChunk) {
|
|
303
|
+
throw new Error(
|
|
304
|
+
"oidc-spa: TanStack Start placed the application entry in the synchronous bootstrap graph."
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
const unexpectedModuleId = chunk.moduleIds.find(
|
|
309
|
+
moduleId => !allowedModuleIds.has(moduleId) && !isViteRuntimeModule(moduleId)
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
if (unexpectedModuleId !== undefined) {
|
|
313
|
+
throw new Error(
|
|
314
|
+
`oidc-spa: TanStack Start placed an application module in the synchronous bootstrap graph: ${unexpectedModuleId}`
|
|
315
|
+
);
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
for (const importedFileName of chunk.imports) {
|
|
319
|
+
const importedChunk = chunksByFileName.get(importedFileName);
|
|
320
|
+
|
|
321
|
+
if (importedChunk !== undefined) {
|
|
322
|
+
pendingChunks.push(importedChunk);
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function isViteRuntimeModule(moduleId: string): boolean {
|
|
329
|
+
return (
|
|
330
|
+
moduleId.startsWith("\0vite/") ||
|
|
331
|
+
moduleId.startsWith("\0rolldown/") ||
|
|
332
|
+
moduleId.startsWith("\0commonjsHelpers") ||
|
|
333
|
+
moduleId.includes("vite/preload-helper")
|
|
334
|
+
);
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function addFileNameSuffix(params: { fileName: string; suffix: string }): string {
|
|
338
|
+
const { fileName, suffix } = params;
|
|
339
|
+
const extension = path.posix.extname(fileName);
|
|
340
|
+
if (extension === "") {
|
|
341
|
+
return `${fileName}-${suffix}`;
|
|
342
|
+
}
|
|
343
|
+
return `${fileName.slice(0, -extension.length)}-${suffix}${extension}`;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function isClientEnvironment(params: {
|
|
347
|
+
pluginContext: Rollup.PluginContext;
|
|
348
|
+
resolvedConfig: ResolvedConfig;
|
|
349
|
+
}): boolean {
|
|
350
|
+
const { pluginContext, resolvedConfig } = params;
|
|
351
|
+
const environmentName = (pluginContext as PluginContextWithEnvironment).environment?.name;
|
|
352
|
+
|
|
353
|
+
if (environmentName !== undefined) {
|
|
354
|
+
return environmentName === "client";
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
return !resolvedConfig.build.ssr;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function getApplicationEntryFileName(params: {
|
|
361
|
+
entryFileName: string;
|
|
362
|
+
bundle: Rollup.OutputBundle;
|
|
363
|
+
}): string {
|
|
364
|
+
const { entryFileName, bundle } = params;
|
|
365
|
+
const directory = path.posix.dirname(entryFileName);
|
|
366
|
+
const basename = path.posix.basename(entryFileName);
|
|
367
|
+
|
|
368
|
+
for (let index = 0; index < basename.length; index++) {
|
|
369
|
+
if (basename[index] !== "-") {
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
const candidateBasename = `${basename.slice(0, index)}_${basename.slice(index + 1)}`;
|
|
374
|
+
const candidate = path.posix.join(directory === "." ? "" : directory, candidateBasename);
|
|
375
|
+
|
|
376
|
+
if (bundle[candidate] === undefined) {
|
|
377
|
+
return candidate;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
for (let index = 0; index < basename.length; index++) {
|
|
382
|
+
if (basename[index] === "_") {
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
const candidateBasename = `${basename.slice(0, index)}_${basename.slice(index + 1)}`;
|
|
387
|
+
const candidate = path.posix.join(directory === "." ? "" : directory, candidateBasename);
|
|
388
|
+
|
|
389
|
+
if (bundle[candidate] === undefined) {
|
|
390
|
+
return candidate;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
throw new Error(`oidc-spa: Could not allocate an application entry beside "${entryFileName}".`);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function rewriteChunkEntryReferences(params: {
|
|
398
|
+
chunk: Rollup.OutputChunk;
|
|
399
|
+
previousEntryFileName: string;
|
|
400
|
+
applicationEntryFileName: string;
|
|
401
|
+
}): void {
|
|
402
|
+
const { chunk, previousEntryFileName, applicationEntryFileName } = params;
|
|
403
|
+
const previousRelativeSpecifier = toRelativeImportSpecifier({
|
|
404
|
+
importerFileName: chunk.fileName,
|
|
405
|
+
importedFileName: previousEntryFileName
|
|
406
|
+
});
|
|
407
|
+
const applicationRelativeSpecifier = toRelativeImportSpecifier({
|
|
408
|
+
importerFileName: chunk.fileName,
|
|
409
|
+
importedFileName: applicationEntryFileName
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
const replacements = new Map([
|
|
413
|
+
[previousEntryFileName, applicationEntryFileName],
|
|
414
|
+
[previousRelativeSpecifier, applicationRelativeSpecifier]
|
|
415
|
+
]);
|
|
416
|
+
|
|
417
|
+
for (const [from, to] of replacements) {
|
|
418
|
+
if (from === to) {
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
if (from.length !== to.length) {
|
|
423
|
+
throw new Error("oidc-spa: Internal entry rewrite changed generated code offsets.");
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
chunk.code = chunk.code.split(from).join(to);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function replaceApplicationEntryPlaceholder(params: {
|
|
431
|
+
code: string;
|
|
432
|
+
applicationEntryImportSpecifier: string;
|
|
433
|
+
}): string {
|
|
434
|
+
const { code, applicationEntryImportSpecifier } = params;
|
|
435
|
+
const occurrences = code.split(APPLICATION_ENTRY_PLACEHOLDER).length - 1;
|
|
436
|
+
|
|
437
|
+
if (occurrences !== 1) {
|
|
438
|
+
throw new Error(
|
|
439
|
+
`oidc-spa: Expected one application entry placeholder in the generated bootstrap, found ${occurrences}.`
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
return code.replace(APPLICATION_ENTRY_PLACEHOLDER, applicationEntryImportSpecifier);
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
function toRelativeImportSpecifier(params: {
|
|
447
|
+
importerFileName: string;
|
|
448
|
+
importedFileName: string;
|
|
449
|
+
}): string {
|
|
450
|
+
const { importerFileName, importedFileName } = params;
|
|
451
|
+
const relativePath = path.posix.relative(path.posix.dirname(importerFileName), importedFileName);
|
|
452
|
+
return relativePath.startsWith(".") ? relativePath : `./${relativePath}`;
|
|
453
|
+
}
|
|
@@ -6,6 +6,7 @@ import { createHandleServerEntrypoint } from "./handleServerEntrypoint";
|
|
|
6
6
|
import { manageOptimizedDeps } from "./manageOptimizedDeps";
|
|
7
7
|
import { transformCreateFileRoute } from "./transformTanstackRouterCreateFileRoute";
|
|
8
8
|
import { getProjectType, type ProjectType } from "./projectType";
|
|
9
|
+
import { createHandleTanstackStartClientOutput } from "./handleTanstackStartClientOutput";
|
|
9
10
|
|
|
10
11
|
export type OidcSpaVitePluginParams = {
|
|
11
12
|
/** See: https://docs.oidc-spa.dev/v/v10/security-features/browser-runtime-freeze */
|
|
@@ -67,11 +68,25 @@ export function oidcSpa(params: OidcSpaVitePluginParams = {}) {
|
|
|
67
68
|
let load_handleClientEntrypoint:
|
|
68
69
|
| ReturnType<typeof createHandleClientEntrypoint>["load_handleClientEntrypoint"]
|
|
69
70
|
| undefined = undefined;
|
|
71
|
+
let resolveId_handleTanstackStartClientOutput:
|
|
72
|
+
| ReturnType<typeof createHandleTanstackStartClientOutput>["resolveId"]
|
|
73
|
+
| undefined = undefined;
|
|
74
|
+
let load_handleTanstackStartClientOutput:
|
|
75
|
+
| ReturnType<typeof createHandleTanstackStartClientOutput>["load"]
|
|
76
|
+
| undefined = undefined;
|
|
77
|
+
let buildStart_handleTanstackStartClientOutput:
|
|
78
|
+
| ReturnType<typeof createHandleTanstackStartClientOutput>["buildStart"]
|
|
79
|
+
| undefined = undefined;
|
|
80
|
+
let generateBundle_handleTanstackStartClientOutput:
|
|
81
|
+
| ReturnType<typeof createHandleTanstackStartClientOutput>["generateBundle"]
|
|
82
|
+
| undefined = undefined;
|
|
83
|
+
let tanstackStartApplicationEntryBuildMarker: string | undefined = undefined;
|
|
70
84
|
let load_handleServerEntrypoint:
|
|
71
85
|
| ReturnType<typeof createHandleServerEntrypoint>["load_handleServerEntrypoint"]
|
|
72
86
|
| undefined = undefined;
|
|
73
87
|
|
|
74
88
|
let projectType: ProjectType | undefined = undefined;
|
|
89
|
+
let isBuild = false;
|
|
75
90
|
|
|
76
91
|
const plugin: Plugin = {
|
|
77
92
|
name: "oidc-spa",
|
|
@@ -90,15 +105,33 @@ export function oidcSpa(params: OidcSpaVitePluginParams = {}) {
|
|
|
90
105
|
return userConfig;
|
|
91
106
|
},
|
|
92
107
|
configResolved(resolvedConfig) {
|
|
108
|
+
isBuild = resolvedConfig.command === "build";
|
|
93
109
|
projectType = getProjectType({
|
|
94
110
|
pluginNames: resolvedConfig.plugins.map(({ name }) => name)
|
|
95
111
|
});
|
|
96
112
|
|
|
97
|
-
|
|
113
|
+
const clientEntrypointHandler = createHandleClientEntrypoint({
|
|
98
114
|
oidcSpaVitePluginParams: params,
|
|
99
115
|
resolvedConfig,
|
|
100
116
|
projectType
|
|
101
|
-
})
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
load_handleClientEntrypoint = clientEntrypointHandler.load_handleClientEntrypoint;
|
|
120
|
+
|
|
121
|
+
if (projectType === "tanstack-start" && isBuild) {
|
|
122
|
+
const tanstackStartClientOutputHandler = createHandleTanstackStartClientOutput({
|
|
123
|
+
resolvedConfig,
|
|
124
|
+
getClientEntrypointSource: clientEntrypointHandler.getClientEntrypointSource
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
resolveId_handleTanstackStartClientOutput = tanstackStartClientOutputHandler.resolveId;
|
|
128
|
+
load_handleTanstackStartClientOutput = tanstackStartClientOutputHandler.load;
|
|
129
|
+
buildStart_handleTanstackStartClientOutput = tanstackStartClientOutputHandler.buildStart;
|
|
130
|
+
generateBundle_handleTanstackStartClientOutput =
|
|
131
|
+
tanstackStartClientOutputHandler.generateBundle;
|
|
132
|
+
tanstackStartApplicationEntryBuildMarker =
|
|
133
|
+
tanstackStartClientOutputHandler.applicationEntryBuildMarker;
|
|
134
|
+
}
|
|
102
135
|
|
|
103
136
|
load_handleServerEntrypoint = createHandleServerEntrypoint({
|
|
104
137
|
resolvedConfig,
|
|
@@ -123,13 +156,37 @@ export function oidcSpa(params: OidcSpaVitePluginParams = {}) {
|
|
|
123
156
|
|
|
124
157
|
return transformed;
|
|
125
158
|
},
|
|
159
|
+
resolveId(id) {
|
|
160
|
+
return resolveId_handleTanstackStartClientOutput?.(id) ?? null;
|
|
161
|
+
},
|
|
162
|
+
buildStart() {
|
|
163
|
+
buildStart_handleTanstackStartClientOutput?.call(this);
|
|
164
|
+
},
|
|
126
165
|
async load(id) {
|
|
166
|
+
{
|
|
167
|
+
const r = load_handleTanstackStartClientOutput?.(id) ?? null;
|
|
168
|
+
|
|
169
|
+
if (r !== null) {
|
|
170
|
+
return r;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
127
174
|
{
|
|
128
175
|
assert(load_handleClientEntrypoint !== undefined);
|
|
129
176
|
|
|
177
|
+
const doUseOriginalEntrypoint =
|
|
178
|
+
projectType === "tanstack-start" &&
|
|
179
|
+
isBuild &&
|
|
180
|
+
((this as typeof this & { environment?: { name?: string } }).environment?.name ??
|
|
181
|
+
"client") === "client";
|
|
182
|
+
|
|
130
183
|
const r = await load_handleClientEntrypoint({
|
|
131
184
|
id,
|
|
132
|
-
pluginContext: this
|
|
185
|
+
pluginContext: this,
|
|
186
|
+
doUseOriginalEntrypoint,
|
|
187
|
+
buildMarker: doUseOriginalEntrypoint
|
|
188
|
+
? tanstackStartApplicationEntryBuildMarker
|
|
189
|
+
: undefined
|
|
133
190
|
});
|
|
134
191
|
|
|
135
192
|
if (r !== null) {
|
|
@@ -149,8 +206,13 @@ export function oidcSpa(params: OidcSpaVitePluginParams = {}) {
|
|
|
149
206
|
return r;
|
|
150
207
|
}
|
|
151
208
|
}
|
|
152
|
-
|
|
153
209
|
return null;
|
|
210
|
+
},
|
|
211
|
+
generateBundle: {
|
|
212
|
+
order: "pre",
|
|
213
|
+
async handler(options, bundle) {
|
|
214
|
+
await generateBundle_handleTanstackStartClientOutput?.call(this, options, bundle);
|
|
215
|
+
}
|
|
154
216
|
}
|
|
155
217
|
};
|
|
156
218
|
|