Skip to content

Commit baf6a52

Browse files
authored
feat(server-functions-plugin): make the manifest output path configurable (#4232)
As part of the devinxi changes, the following hard-coded output path of the server functions manifest file was changed. This would have had breaking changes in the user DX for downstream frameworks building upon the `@tanstack/server-functions-plugin` package - (i.e. SolidStart). This change makes the output path of the manifest file for the `server-functions-plugin` package, configurable.
1 parent f06a29b commit baf6a52

File tree

3 files changed

+39
-5
lines changed

3 files changed

+39
-5
lines changed

packages/server-functions-plugin/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ Create a new instance of the plugin with the following options:
88

99
```ts
1010
const TanStackServerFnsPlugin = createTanStackServerFnPlugin({
11-
// This is the ID that will be available to look up and import
12-
// our server function manifest and resolve its module
11+
// This is the ID (virtual module) that will be made available to look up
12+
// and import our server function manifest and resolve its modules.
1313
manifestVirtualImportId: 'tanstack:server-fn-manifest',
1414
client: {
1515
getRuntimeCode: () =>
@@ -86,5 +86,5 @@ export const handler = async (req: Request) => {
8686
const args = await req.json()
8787

8888
return await fnModule(...args)
89-
89+
}
9090
```

packages/server-functions-plugin/src/index.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,28 @@ declare global {
2222
}
2323

2424
export type ServerFnPluginOpts = {
25+
/**
26+
* The virtual import ID that will be used to import the server function manifest.
27+
* This virtual import ID will be used in the server build to import the manifest
28+
* and its modules.
29+
*/
2530
manifestVirtualImportId: string
31+
/**
32+
* The path to the manifest file that will be created during the build process.
33+
* This file will be used to import the modules for the server functions in your
34+
* server handler.
35+
*
36+
* @default 'node_modules/.tanstack-start/server-functions-manifest.json'
37+
*/
38+
manifestOutputFilename?: string
2639
client: ServerFnPluginEnvOpts
2740
ssr: ServerFnPluginEnvOpts
2841
server: ServerFnPluginEnvOpts
2942
importer?: (fn: DirectiveFn) => Promise<any>
3043
}
3144

32-
const manifestFilename =
33-
'.tanstack-start/build/server/server-functions-manifest.json'
45+
const defaultManifestFilename =
46+
'node_modules/.tanstack-start/server-functions-manifest.json'
3447

3548
export type ServerFnPluginEnvOpts = {
3649
getRuntimeCode: () => string
@@ -71,6 +84,9 @@ export function createTanStackServerFnPlugin(opts: ServerFnPluginOpts): {
7184
)
7285
}
7386

87+
const manifestFilename =
88+
opts.manifestOutputFilename || defaultManifestFilename
89+
7490
const directive = 'use server'
7591
const directiveLabel = 'Server Function'
7692

@@ -201,7 +217,20 @@ export function createTanStackServerFnPlugin(opts: ServerFnPluginOpts): {
201217
}
202218

203219
export interface TanStackServerFnPluginEnvOpts {
220+
/**
221+
* The virtual import ID that will be used to import the server function manifest.
222+
* This virtual import ID will be used in the server build to import the manifest
223+
* and its modules.
224+
*/
204225
manifestVirtualImportId: string
226+
/**
227+
* The path to the manifest file that will be created during the build process.
228+
* This file will be used to import the modules for the server functions in your
229+
* server handler.
230+
*
231+
* @default 'node_modules/.tanstack-start/server-functions-manifest.json'
232+
*/
233+
manifestOutputFilename?: string
205234
client: {
206235
envName?: string
207236
getRuntimeCode: () => string
@@ -259,6 +288,9 @@ export function TanStackServerFnPluginEnv(
259288
)
260289
}
261290

291+
const manifestFilename =
292+
opts.manifestOutputFilename || defaultManifestFilename
293+
262294
const directive = 'use server'
263295
const directiveLabel = 'Server Function'
264296

packages/start-plugin-core/src/plugin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ export function TanStackStartVitePluginCore(
167167
// This is the ID that will be available to look up and import
168168
// our server function manifest and resolve its module
169169
manifestVirtualImportId: 'tanstack-start-server-fn-manifest:v',
170+
manifestOutputFilename:
171+
'.tanstack-start/build/server/server-functions-manifest.json',
170172
client: {
171173
getRuntimeCode: () =>
172174
`import { createClientRpc } from '@tanstack/${opts.framework}-start/server-functions-client'`,

0 commit comments

Comments
 (0)