@payloadcms/tanstack-start 4.0.0-internal.5214550 → 4.0.0-internal.543da65
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/vite/importProtection.d.ts.map +1 -1
- package/dist/vite/importProtection.js +2 -6
- package/dist/vite/importProtection.js.map +1 -1
- package/dist/vite/index.d.ts +28 -10
- package/dist/vite/index.d.ts.map +1 -1
- package/dist/vite/index.js +32 -23
- package/dist/vite/index.js.map +1 -1
- package/dist/vite/workarounds/devTransforms.d.ts.map +1 -1
- package/dist/vite/workarounds/devTransforms.js +5 -0
- package/dist/vite/workarounds/devTransforms.js.map +1 -1
- package/dist/vite/workarounds/stubPrettierInClient.d.ts +5 -13
- package/dist/vite/workarounds/stubPrettierInClient.d.ts.map +1 -1
- package/dist/vite/workarounds/stubPrettierInClient.js +8 -15
- package/dist/vite/workarounds/stubPrettierInClient.js.map +1 -1
- package/package.json +14 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"importProtection.d.ts","sourceRoot":"","sources":["../../src/vite/importProtection.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAoB7D,CAAA;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"importProtection.d.ts","sourceRoot":"","sources":["../../src/vite/importProtection.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,0BAA0B,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAoB7D,CAAA;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,GAAG,IAAI,CAoC9E;AAED,eAAO,MAAM,sCAAsC,EAAE,MAAM,EAAsC,CAAA"}
|
|
@@ -30,12 +30,8 @@ import { builtinModules } from 'node:module';
|
|
|
30
30
|
* to permit even when they appear to cross a server/client boundary.
|
|
31
31
|
*/ export function onImportProtectionViolation(violation) {
|
|
32
32
|
const info = violation;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// (installed and linked/monorepo) so a host's own `.client.*` files stay
|
|
36
|
-
// protected.
|
|
37
|
-
const payloadClientFile = /@payloadcms\/|\/packages\/(?:ui|richtext-lexical|richtext-slate|plugin-[^/]+)\//;
|
|
38
|
-
if (info.envType === 'server' && info.resolved?.includes('.client.') && payloadClientFile.test(info.resolved)) {
|
|
33
|
+
const allowedClientFileImporters = /\/richtext-lexical\/.*\/exports\/client\/|\/tanstack-start\/.*\/views\/AdminView|\/ui\//;
|
|
34
|
+
if (info.envType === 'server' && info.resolved?.includes('.client.') && allowedClientFileImporters.test(info.importer)) {
|
|
39
35
|
return false;
|
|
40
36
|
}
|
|
41
37
|
if (info.importer.includes('/richtext-lexical/') && info.importer.includes('/field/Diff/')) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/vite/importProtection.ts"],"sourcesContent":["import { builtinModules } from 'node:module'\n\n/**\n * Specifiers that must never appear in the client module graph. These are the\n * server-only Payload entry points plus Node.js built-ins and a handful of\n * Node-only npm packages that Payload pulls in transitively.\n */\nexport const serverOnlyClientSpecifiers: Array<RegExp | string> = [\n /^node:/,\n new RegExp(`^(${builtinModules.join('|')})(\\\\/|$)`),\n '@payload-config',\n /^@payloadcms\\/next\\/rsc/,\n /^@payloadcms\\/richtext-lexical\\/rsc/,\n /^@payloadcms\\/richtext-slate\\/rsc/,\n '@payloadcms/ui/server',\n /^@payloadcms\\/tanstack-start\\/(layouts|rsc|server|views\\/server)/,\n 'sharp',\n 'busboy',\n 'croner',\n 'pino',\n 'pino-pretty',\n 'prompts',\n 'ws',\n 'undici',\n 'get-tsconfig',\n /^file-type/,\n /^react-dom\\/server/,\n]\n\n/**\n * Allowlist callback for the `tanstackStart` plugin's import-protection. These\n * are the legitimate cross-environment imports in our monorepo that we want\n * to permit even when they appear to cross a server/client boundary.\n */\nexport function onImportProtectionViolation(violation: unknown): boolean | void {\n const info = violation as {\n envType: 'client' | 'server'\n importer: string\n resolved?: string\n }\n\n
|
|
1
|
+
{"version":3,"sources":["../../src/vite/importProtection.ts"],"sourcesContent":["import { builtinModules } from 'node:module'\n\n/**\n * Specifiers that must never appear in the client module graph. These are the\n * server-only Payload entry points plus Node.js built-ins and a handful of\n * Node-only npm packages that Payload pulls in transitively.\n */\nexport const serverOnlyClientSpecifiers: Array<RegExp | string> = [\n /^node:/,\n new RegExp(`^(${builtinModules.join('|')})(\\\\/|$)`),\n '@payload-config',\n /^@payloadcms\\/next\\/rsc/,\n /^@payloadcms\\/richtext-lexical\\/rsc/,\n /^@payloadcms\\/richtext-slate\\/rsc/,\n '@payloadcms/ui/server',\n /^@payloadcms\\/tanstack-start\\/(layouts|rsc|server|views\\/server)/,\n 'sharp',\n 'busboy',\n 'croner',\n 'pino',\n 'pino-pretty',\n 'prompts',\n 'ws',\n 'undici',\n 'get-tsconfig',\n /^file-type/,\n /^react-dom\\/server/,\n]\n\n/**\n * Allowlist callback for the `tanstackStart` plugin's import-protection. These\n * are the legitimate cross-environment imports in our monorepo that we want\n * to permit even when they appear to cross a server/client boundary.\n */\nexport function onImportProtectionViolation(violation: unknown): boolean | void {\n const info = violation as {\n envType: 'client' | 'server'\n importer: string\n resolved?: string\n }\n\n const allowedClientFileImporters =\n /\\/richtext-lexical\\/.*\\/exports\\/client\\/|\\/tanstack-start\\/.*\\/views\\/AdminView|\\/ui\\//\n\n if (\n info.envType === 'server' &&\n info.resolved?.includes('.client.') &&\n allowedClientFileImporters.test(info.importer)\n ) {\n return false\n }\n\n if (info.importer.includes('/richtext-lexical/') && info.importer.includes('/field/Diff/')) {\n return false\n }\n\n if (info.importer.includes('/packages/payload/') || info.importer.includes('/payload/dist/')) {\n return false\n }\n\n if (\n info.importer.includes('@payloadcms/ui') &&\n (info.importer.includes('/exports/rsc/') || info.importer.includes('/rsc/index'))\n ) {\n return false\n }\n\n if (info.envType === 'server' && info.importer.includes('vite-rsc/client-references')) {\n return false\n }\n}\n\nexport const defaultImportProtectionIgnoreImporters: RegExp[] = [/^src\\/importMap\\.js(?:\\?.*)?$/]\n"],"names":["builtinModules","serverOnlyClientSpecifiers","RegExp","join","onImportProtectionViolation","violation","info","allowedClientFileImporters","envType","resolved","includes","test","importer","defaultImportProtectionIgnoreImporters"],"mappings":"AAAA,SAASA,cAAc,QAAQ,cAAa;AAE5C;;;;CAIC,GACD,OAAO,MAAMC,6BAAqD;IAChE;IACA,IAAIC,OAAO,CAAC,EAAE,EAAEF,eAAeG,IAAI,CAAC,KAAK,QAAQ,CAAC;IAClD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAED;;;;CAIC,GACD,OAAO,SAASC,4BAA4BC,SAAkB;IAC5D,MAAMC,OAAOD;IAMb,MAAME,6BACJ;IAEF,IACED,KAAKE,OAAO,KAAK,YACjBF,KAAKG,QAAQ,EAAEC,SAAS,eACxBH,2BAA2BI,IAAI,CAACL,KAAKM,QAAQ,GAC7C;QACA,OAAO;IACT;IAEA,IAAIN,KAAKM,QAAQ,CAACF,QAAQ,CAAC,yBAAyBJ,KAAKM,QAAQ,CAACF,QAAQ,CAAC,iBAAiB;QAC1F,OAAO;IACT;IAEA,IAAIJ,KAAKM,QAAQ,CAACF,QAAQ,CAAC,yBAAyBJ,KAAKM,QAAQ,CAACF,QAAQ,CAAC,mBAAmB;QAC5F,OAAO;IACT;IAEA,IACEJ,KAAKM,QAAQ,CAACF,QAAQ,CAAC,qBACtBJ,CAAAA,KAAKM,QAAQ,CAACF,QAAQ,CAAC,oBAAoBJ,KAAKM,QAAQ,CAACF,QAAQ,CAAC,aAAY,GAC/E;QACA,OAAO;IACT;IAEA,IAAIJ,KAAKE,OAAO,KAAK,YAAYF,KAAKM,QAAQ,CAACF,QAAQ,CAAC,+BAA+B;QACrF,OAAO;IACT;AACF;AAEA,OAAO,MAAMG,yCAAmD;IAAC;CAAgC,CAAA"}
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ import rsc from '@vitejs/plugin-rsc';
|
|
|
5
5
|
export type WithPayloadOptions = {
|
|
6
6
|
/** Extra import-protection `ignoreImporters` patterns for the TanStack Start plugin. */
|
|
7
7
|
additionalIgnoreImporters?: RegExp[];
|
|
8
|
+
/** Route id of Payload's admin layout, eager-loaded instead of code-split. Defaults to `'/_payload'`. */
|
|
9
|
+
adminRouteId?: string;
|
|
10
|
+
/** Extra globs exempted from the `.client.*` SSR denial (beyond the default node_modules exemption). */
|
|
11
|
+
clientDenialExcludeFiles?: string[];
|
|
8
12
|
/** Path to the user's `payload.config.ts` (required) */
|
|
9
13
|
payloadConfigPath: string;
|
|
10
14
|
/** TanStack router routes directory relative to `srcDirectory`. Defaults to `'app'` */
|
|
@@ -23,13 +27,15 @@ export type PayloadPluginOptions = {
|
|
|
23
27
|
tanstackStart: NonNullable<Parameters<typeof tanstackStart>[0]>;
|
|
24
28
|
};
|
|
25
29
|
export type WithPayloadBuilderContext = {
|
|
26
|
-
/** Payload's base Vite config; `plugins` holds Payload's workaround plugins only. */
|
|
27
|
-
config: UserConfig;
|
|
28
30
|
env: ConfigEnv;
|
|
29
31
|
/** Options to pass to the `viteReact`/`rsc`/`tanstackStart` factories you import. */
|
|
30
32
|
pluginOptions: PayloadPluginOptions;
|
|
31
33
|
};
|
|
32
|
-
/**
|
|
34
|
+
/**
|
|
35
|
+
* Returns the extra Vite config — the plugins you instantiate plus any overrides.
|
|
36
|
+
* `withPayload` deep-merges it onto Payload's base config, so you don't spread or
|
|
37
|
+
* merge the base yourself.
|
|
38
|
+
*/
|
|
33
39
|
export type WithPayloadBuilder = (context: WithPayloadBuilderContext) => UserConfig;
|
|
34
40
|
/**
|
|
35
41
|
* Vite config helper for Payload + TanStack Start; the counterpart to Next.js'
|
|
@@ -38,28 +44,28 @@ export type WithPayloadBuilder = (context: WithPayloadBuilderContext) => UserCon
|
|
|
38
44
|
* Zero-config — Payload instantiates the RSC, React, and TanStack Start plugins:
|
|
39
45
|
*
|
|
40
46
|
* ```ts
|
|
41
|
-
* export default withPayload({ payloadConfigPath: './src/payload.config.ts' })
|
|
47
|
+
* export default withPayload(undefined, { payloadConfigPath: './src/payload.config.ts' })
|
|
42
48
|
* ```
|
|
43
49
|
*
|
|
44
50
|
* Guest mode — pass a `build` callback to instantiate them yourself (one copy of
|
|
45
|
-
* each; `@vitejs/plugin-rsc` is a hard singleton)
|
|
51
|
+
* each; `@vitejs/plugin-rsc` is a hard singleton). Return only your additions;
|
|
52
|
+
* `withPayload` deep-merges them onto Payload's base config:
|
|
46
53
|
*
|
|
47
54
|
* ```ts
|
|
48
55
|
* export default withPayload(
|
|
49
|
-
* {
|
|
50
|
-
* ({ config, pluginOptions }) => ({
|
|
51
|
-
* ...config,
|
|
56
|
+
* ({ pluginOptions }) => ({
|
|
52
57
|
* plugins: [
|
|
53
|
-
* ...config.plugins,
|
|
54
58
|
* rsc(pluginOptions.rsc),
|
|
55
59
|
* tanstackStart(pluginOptions.tanstackStart),
|
|
56
60
|
* viteReact(pluginOptions.react),
|
|
57
61
|
* ],
|
|
62
|
+
* // ...other config options
|
|
58
63
|
* }),
|
|
64
|
+
* { payloadConfigPath: './src/payload.config.ts' },
|
|
59
65
|
* )
|
|
60
66
|
* ```
|
|
61
67
|
*/
|
|
62
|
-
export declare function withPayload(
|
|
68
|
+
export declare function withPayload(build: undefined | WithPayloadBuilder, options: WithPayloadOptions): UserConfigFnObject;
|
|
63
69
|
/** `@vitejs/plugin-rsc` options for Payload: `serverHandler: false` (TanStack owns the handler). */
|
|
64
70
|
export declare function payloadRscOptions(): NonNullable<Parameters<typeof rsc>[0]>;
|
|
65
71
|
/** `@vitejs/plugin-react` options for Payload: transform every `.[jt]sx?` file. */
|
|
@@ -67,6 +73,18 @@ export declare function payloadReactOptions(): NonNullable<Parameters<typeof vit
|
|
|
67
73
|
export type PayloadTanstackStartOptionsArgs = {
|
|
68
74
|
/** Additional import-protection `ignoreImporters` patterns. */
|
|
69
75
|
additionalIgnoreImporters?: RegExp[];
|
|
76
|
+
/**
|
|
77
|
+
* Route id of Payload's admin layout route, eager-loaded (not code-split) so it
|
|
78
|
+
* hydrates on first paint. It and its children skip splitting; host routes keep
|
|
79
|
+
* TanStack's default. Defaults to `'/_payload'` (the `_payload.tsx` convention).
|
|
80
|
+
*/
|
|
81
|
+
adminRouteId?: string;
|
|
82
|
+
/**
|
|
83
|
+
* Extra globs exempted from TanStack's `.client.*` SSR denial, on top of the
|
|
84
|
+
* default node_modules exemption. Needed only when Payload's own `.client.*`
|
|
85
|
+
* files resolve outside node_modules (e.g. the monorepo's `packages` sources).
|
|
86
|
+
*/
|
|
87
|
+
clientDenialExcludeFiles?: string[];
|
|
70
88
|
/** TanStack router routes directory relative to `srcDirectory`. Defaults to `'app'`. */
|
|
71
89
|
routesDirectory?: string;
|
|
72
90
|
/** TanStack source directory. Defaults to `'src'`. */
|
package/dist/vite/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAwB,UAAU,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/vite/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAwB,UAAU,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAA;AAI3F,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAA;AACjE,OAAO,SAAS,MAAM,sBAAsB,CAAA;AAC5C,OAAO,GAAG,MAAM,oBAAoB,CAAA;AA0DpC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,wFAAwF;IACxF,yBAAyB,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BAAgB,mBAAmB,IAAI,WAAW,CAAC,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAElF;AAED,MAAM,MAAM,+BAA+B,GAAG;IAC5C,+DAA+D;IAC/D,yBAAyB,CAAC,EAAE,MAAM,EAAE,CAAA;IACpC;;;;OAIG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAA;IACnC,wFAAwF;IACxF,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,sDAAsD;IACtD,YAAY,CAAC,EAAE,MAAM,CAAA;CACtB,CAAA;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,IAAI,GAAE,+BAAoC,GACzC,WAAW,CAAC,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAwClD"}
|
package/dist/vite/index.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// Optional peers, not deps: `plugin-rsc` is a singleton, so bundling our own copy
|
|
2
|
+
// alongside the host's would load two instances and crash.
|
|
1
3
|
import { tanstackStart } from '@tanstack/react-start/plugin/vite';
|
|
2
4
|
import viteReact from '@vitejs/plugin-react';
|
|
3
5
|
import rsc from '@vitejs/plugin-rsc';
|
|
@@ -54,28 +56,28 @@ import { wrapCjsForClient } from './workarounds/wrapCjsForClient.js';
|
|
|
54
56
|
* Zero-config — Payload instantiates the RSC, React, and TanStack Start plugins:
|
|
55
57
|
*
|
|
56
58
|
* ```ts
|
|
57
|
-
* export default withPayload({ payloadConfigPath: './src/payload.config.ts' })
|
|
59
|
+
* export default withPayload(undefined, { payloadConfigPath: './src/payload.config.ts' })
|
|
58
60
|
* ```
|
|
59
61
|
*
|
|
60
62
|
* Guest mode — pass a `build` callback to instantiate them yourself (one copy of
|
|
61
|
-
* each; `@vitejs/plugin-rsc` is a hard singleton)
|
|
63
|
+
* each; `@vitejs/plugin-rsc` is a hard singleton). Return only your additions;
|
|
64
|
+
* `withPayload` deep-merges them onto Payload's base config:
|
|
62
65
|
*
|
|
63
66
|
* ```ts
|
|
64
67
|
* export default withPayload(
|
|
65
|
-
* {
|
|
66
|
-
* ({ config, pluginOptions }) => ({
|
|
67
|
-
* ...config,
|
|
68
|
+
* ({ pluginOptions }) => ({
|
|
68
69
|
* plugins: [
|
|
69
|
-
* ...config.plugins,
|
|
70
70
|
* rsc(pluginOptions.rsc),
|
|
71
71
|
* tanstackStart(pluginOptions.tanstackStart),
|
|
72
72
|
* viteReact(pluginOptions.react),
|
|
73
73
|
* ],
|
|
74
|
+
* // ...other config options
|
|
74
75
|
* }),
|
|
76
|
+
* { payloadConfigPath: './src/payload.config.ts' },
|
|
75
77
|
* )
|
|
76
78
|
* ```
|
|
77
|
-
*/ export function withPayload(
|
|
78
|
-
const { additionalIgnoreImporters = [], payloadConfigPath, routesDirectory = 'app', silenceDependencyWarnings = true, srcDirectory = 'src', vite } = options;
|
|
79
|
+
*/ export function withPayload(build, options) {
|
|
80
|
+
const { additionalIgnoreImporters = [], adminRouteId, clientDenialExcludeFiles = [], payloadConfigPath, routesDirectory = 'app', silenceDependencyWarnings = true, srcDirectory = 'src', vite } = options;
|
|
79
81
|
return (env)=>{
|
|
80
82
|
const base = {
|
|
81
83
|
build: {
|
|
@@ -167,16 +169,17 @@ import { wrapCjsForClient } from './workarounds/wrapCjsForClient.js';
|
|
|
167
169
|
rsc: payloadRscOptions(),
|
|
168
170
|
tanstackStart: payloadTanstackStartOptions({
|
|
169
171
|
additionalIgnoreImporters,
|
|
172
|
+
adminRouteId,
|
|
173
|
+
clientDenialExcludeFiles,
|
|
170
174
|
routesDirectory,
|
|
171
175
|
srcDirectory
|
|
172
176
|
})
|
|
173
177
|
};
|
|
174
178
|
if (build) {
|
|
175
|
-
return applyDependencyWarningSuppression(build({
|
|
176
|
-
config: base,
|
|
179
|
+
return applyDependencyWarningSuppression(mergeConfig(base, build({
|
|
177
180
|
env,
|
|
178
181
|
pluginOptions
|
|
179
|
-
}), silenceDependencyWarnings);
|
|
182
|
+
})), silenceDependencyWarnings);
|
|
180
183
|
}
|
|
181
184
|
base.plugins = [
|
|
182
185
|
...base.plugins,
|
|
@@ -204,11 +207,8 @@ import { wrapCjsForClient } from './workarounds/wrapCjsForClient.js';
|
|
|
204
207
|
* code-splitting). TanStack Start is one-per-app, so a host that already runs it
|
|
205
208
|
* should merge these into its single `tanstackStart` call.
|
|
206
209
|
*/ export function payloadTanstackStartOptions(args = {}) {
|
|
207
|
-
const { additionalIgnoreImporters = [], routesDirectory = 'app', srcDirectory = 'src' } = args;
|
|
210
|
+
const { additionalIgnoreImporters = [], adminRouteId = '/_payload', clientDenialExcludeFiles = [], routesDirectory = 'app', srcDirectory = 'src' } = args;
|
|
208
211
|
return {
|
|
209
|
-
// No `server` rule: keep TanStack's default `.client.*` SSR protection for
|
|
210
|
-
// host files. Payload's own `.client.*` are exempted in
|
|
211
|
-
// `onImportProtectionViolation`.
|
|
212
212
|
importProtection: {
|
|
213
213
|
client: {
|
|
214
214
|
excludeFiles: [],
|
|
@@ -222,17 +222,26 @@ import { wrapCjsForClient } from './workarounds/wrapCjsForClient.js';
|
|
|
222
222
|
'**/*'
|
|
223
223
|
],
|
|
224
224
|
mockAccess: 'warn',
|
|
225
|
-
onViolation: onImportProtectionViolation
|
|
225
|
+
onViolation: onImportProtectionViolation,
|
|
226
|
+
// Payload's `.client.*` components are React Client Components that must be
|
|
227
|
+
// server-rendered during SSR; TanStack's default `**/*.client.*` server
|
|
228
|
+
// denial would mock and crash them. All such files live in `@payloadcms/*`
|
|
229
|
+
// packages, so keep the denial (host `.client.*` files still get it) and
|
|
230
|
+
// just exempt Payload's — `node_modules` covers published installs.
|
|
231
|
+
server: {
|
|
232
|
+
excludeFiles: [
|
|
233
|
+
'**/node_modules/**',
|
|
234
|
+
...clientDenialExcludeFiles
|
|
235
|
+
]
|
|
236
|
+
}
|
|
226
237
|
},
|
|
227
|
-
// Disable per-route code-splitting so route components ship in the initial
|
|
228
|
-
// bundle and hydrate on first paint — otherwise the admin renders but isn't
|
|
229
|
-
// interactive until each lazy `?tsr-split=` chunk lands. `defaultBehavior:
|
|
230
|
-
// []` is the knob the splitter actually honours; `autoCodeSplitting: false`
|
|
231
|
-
// is a belt-and-braces signal (the plugin's schema strips it).
|
|
232
238
|
router: {
|
|
233
|
-
autoCodeSplitting: false,
|
|
234
239
|
codeSplittingOptions: {
|
|
235
|
-
|
|
240
|
+
// Eager-load only Payload's admin routes so they hydrate on first paint —
|
|
241
|
+
// a split admin renders but isn't interactive until its lazy `?tsr-split=`
|
|
242
|
+
// chunk lands. Returning `[]` disables splitting for a route; `undefined`
|
|
243
|
+
// lets host routes keep TanStack's default per-route splitting.
|
|
244
|
+
splitBehavior: ({ routeId })=>routeId === adminRouteId || routeId.startsWith(`${adminRouteId}/`) ? [] : undefined
|
|
236
245
|
},
|
|
237
246
|
// Ignore generated importMap files and colocated `*.functions.ts` modules
|
|
238
247
|
// (they define `createServerFn`s, not routes).
|
package/dist/vite/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/vite/index.ts"],"sourcesContent":["import type { ConfigEnv, Logger, PluginOption, UserConfig, UserConfigFnObject } from 'vite'\n\nimport { tanstackStart } from '@tanstack/react-start/plugin/vite'\nimport viteReact from '@vitejs/plugin-react'\nimport rsc from '@vitejs/plugin-rsc'\nimport path from 'node:path'\nimport { createLogger, mergeConfig } from 'vite'\n\nimport { payloadNoExternalPatterns, ssrExternalPackages } from './config/external.js'\nimport { optimizeDepsExcludeDefaults, optimizeDepsIncludeDefaults } from './config/optimizeDeps.js'\nimport { payloadScssImporters } from './config/scss.js'\nimport {\n defaultImportProtectionIgnoreImporters,\n onImportProtectionViolation,\n serverOnlyClientSpecifiers,\n} from './importProtection.js'\nimport { clientModuleResolution } from './workarounds/clientModuleResolution.js'\nimport { payloadDevTransforms } from './workarounds/devTransforms.js'\nimport { reactDomServerInRsc } from './workarounds/reactDomServerInRsc.js'\nimport { ssrStripDistStyleImports } from './workarounds/stripDistStyleImports.js'\nimport { stubPrettierInClient } from './workarounds/stubPrettierInClient.js'\nimport { wrapCjsForClient } from './workarounds/wrapCjsForClient.js'\n\n/**\n * Vite dependency warnings Payload consumers can't act on: third-party packages\n * ship sourcemaps whose original sources aren't published, so Vite warns on\n * every one. Suppressed by default (see `silenceDependencyWarnings`).\n */\nconst suppressibleWarningPatterns = ['points to missing source files', 'Sourcemap for']\n\n/**\n * Wraps a Vite logger so warnings matching {@link suppressibleWarningPatterns}\n * are dropped. Mutates and returns the given logger (or a fresh default one).\n */\nfunction withQuietedDependencyWarnings(existing?: Logger): Logger {\n const logger = existing ?? createLogger()\n const shouldSuppress = (msg: unknown): boolean =>\n typeof msg === 'string' && suppressibleWarningPatterns.some((pattern) => msg.includes(pattern))\n\n const baseWarn = logger.warn.bind(logger)\n const baseWarnOnce = logger.warnOnce.bind(logger)\n logger.warn = (msg, options) => {\n if (!shouldSuppress(msg)) {\n baseWarn(msg, options)\n }\n }\n logger.warnOnce = (msg, options) => {\n if (!shouldSuppress(msg)) {\n baseWarnOnce(msg, options)\n }\n }\n return logger\n}\n\n/** Applies dependency-warning suppression to a config in place when enabled. */\nfunction applyDependencyWarningSuppression(config: UserConfig, enabled: boolean): UserConfig {\n if (enabled) {\n config.customLogger = withQuietedDependencyWarnings(config.customLogger)\n }\n return config\n}\n\nexport type WithPayloadOptions = {\n /** Extra import-protection `ignoreImporters` patterns for the TanStack Start plugin. */\n additionalIgnoreImporters?: RegExp[]\n /** Path to the user's `payload.config.ts` (required) */\n payloadConfigPath: string\n /** TanStack router routes directory relative to `srcDirectory`. Defaults to `'app'` */\n routesDirectory?: string\n /** Silence Vite warnings about third-party dependency sourcemaps. Defaults to `true`. */\n silenceDependencyWarnings?: boolean\n /** TanStack source directory. Defaults to `'src'` */\n srcDirectory?: string\n /** Extra Vite config deep-merged over the Payload defaults. Ignored in `build` mode. */\n vite?: UserConfig\n}\n\n/** The options Payload's admin requires for each third-party plugin. */\nexport type PayloadPluginOptions = {\n react: NonNullable<Parameters<typeof viteReact>[0]>\n rsc: NonNullable<Parameters<typeof rsc>[0]>\n tanstackStart: NonNullable<Parameters<typeof tanstackStart>[0]>\n}\n\nexport type WithPayloadBuilderContext = {\n /** Payload's base Vite config; `plugins` holds Payload's workaround plugins only. */\n config: UserConfig\n env: ConfigEnv\n /** Options to pass to the `viteReact`/`rsc`/`tanstackStart` factories you import. */\n pluginOptions: PayloadPluginOptions\n}\n\n/** Assembles the final Vite config from Payload's base config and plugin options. */\nexport type WithPayloadBuilder = (context: WithPayloadBuilderContext) => UserConfig\n\n/**\n * Vite config helper for Payload + TanStack Start; the counterpart to Next.js'\n * `withPayload`.\n *\n * Zero-config — Payload instantiates the RSC, React, and TanStack Start plugins:\n *\n * ```ts\n * export default withPayload({ payloadConfigPath: './src/payload.config.ts' })\n * ```\n *\n * Guest mode — pass a `build` callback to instantiate them yourself (one copy of\n * each; `@vitejs/plugin-rsc` is a hard singleton):\n *\n * ```ts\n * export default withPayload(\n * { payloadConfigPath: './src/payload.config.ts' },\n * ({ config, pluginOptions }) => ({\n * ...config,\n * plugins: [\n * ...config.plugins,\n * rsc(pluginOptions.rsc),\n * tanstackStart(pluginOptions.tanstackStart),\n * viteReact(pluginOptions.react),\n * ],\n * }),\n * )\n * ```\n */\nexport function withPayload(\n options: WithPayloadOptions,\n build?: WithPayloadBuilder,\n): UserConfigFnObject {\n const {\n additionalIgnoreImporters = [],\n payloadConfigPath,\n routesDirectory = 'app',\n silenceDependencyWarnings = true,\n srcDirectory = 'src',\n vite,\n } = options\n\n return (env) => {\n const base: UserConfig = {\n build: {\n cssMinify: 'esbuild',\n },\n css: {\n preprocessorOptions: {\n scss: {\n importers: payloadScssImporters,\n silenceDeprecations: ['import', 'global-builtin'],\n } as any,\n },\n },\n define: {\n global: 'globalThis',\n },\n environments: {\n rsc: {\n build: { rollupOptions: { external: ssrExternalPackages } },\n resolve: { noExternal: payloadNoExternalPatterns },\n },\n ssr: {\n build: { rollupOptions: { external: ssrExternalPackages } },\n resolve: { noExternal: payloadNoExternalPatterns },\n },\n } as any,\n optimizeDeps: {\n exclude: optimizeDepsExcludeDefaults,\n include: optimizeDepsIncludeDefaults,\n },\n // Payload's internal workaround plugins only. The RSC, TanStack Start, and\n // React plugins are appended below (default form) or by the consumer's\n // `build` callback (guest form).\n plugins: [\n clientModuleResolution(),\n wrapCjsForClient(),\n ssrStripDistStyleImports(),\n reactDomServerInRsc(),\n stubPrettierInClient(),\n payloadDevTransforms(),\n ],\n resolve: {\n alias: [{ find: '@payload-config', replacement: path.resolve(payloadConfigPath) }],\n dedupe: [\n 'react',\n 'react-dom',\n 'scheduler',\n '@payloadcms/ui',\n '@payloadcms/richtext-lexical',\n ],\n extensions: ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json'],\n tsconfigPaths: true,\n } as any,\n ssr: {\n external: ssrExternalPackages,\n noExternal: payloadNoExternalPatterns,\n },\n }\n\n const pluginOptions: PayloadPluginOptions = {\n react: payloadReactOptions(),\n rsc: payloadRscOptions(),\n tanstackStart: payloadTanstackStartOptions({\n additionalIgnoreImporters,\n routesDirectory,\n srcDirectory,\n }),\n }\n\n if (build) {\n return applyDependencyWarningSuppression(\n build({ config: base, env, pluginOptions }),\n silenceDependencyWarnings,\n )\n }\n\n base.plugins = [\n ...(base.plugins as PluginOption[]),\n rsc(pluginOptions.rsc),\n tanstackStart(pluginOptions.tanstackStart),\n viteReact(pluginOptions.react),\n ]\n\n const merged = vite ? mergeConfig(base, vite) : base\n\n return applyDependencyWarningSuppression(merged, silenceDependencyWarnings)\n }\n}\n\n/** `@vitejs/plugin-rsc` options for Payload: `serverHandler: false` (TanStack owns the handler). */\nexport function payloadRscOptions(): NonNullable<Parameters<typeof rsc>[0]> {\n return { serverHandler: false }\n}\n\n/** `@vitejs/plugin-react` options for Payload: transform every `.[jt]sx?` file. */\nexport function payloadReactOptions(): NonNullable<Parameters<typeof viteReact>[0]> {\n return { exclude: [], include: /\\.[jt]sx?$/ }\n}\n\nexport type PayloadTanstackStartOptionsArgs = {\n /** Additional import-protection `ignoreImporters` patterns. */\n additionalIgnoreImporters?: RegExp[]\n /** TanStack router routes directory relative to `srcDirectory`. Defaults to `'app'`. */\n routesDirectory?: string\n /** TanStack source directory. Defaults to `'src'`. */\n srcDirectory?: string\n}\n\n/**\n * The `tanstackStart` options Payload's admin requires (import-protection and\n * code-splitting). TanStack Start is one-per-app, so a host that already runs it\n * should merge these into its single `tanstackStart` call.\n */\nexport function payloadTanstackStartOptions(\n args: PayloadTanstackStartOptionsArgs = {},\n): NonNullable<Parameters<typeof tanstackStart>[0]> {\n const { additionalIgnoreImporters = [], routesDirectory = 'app', srcDirectory = 'src' } = args\n\n return {\n // No `server` rule: keep TanStack's default `.client.*` SSR protection for\n // host files. Payload's own `.client.*` are exempted in\n // `onImportProtectionViolation`.\n importProtection: {\n client: { excludeFiles: [], specifiers: serverOnlyClientSpecifiers },\n ignoreImporters: [...defaultImportProtectionIgnoreImporters, ...additionalIgnoreImporters],\n include: ['**/*'],\n mockAccess: 'warn',\n onViolation: onImportProtectionViolation,\n },\n // Disable per-route code-splitting so route components ship in the initial\n // bundle and hydrate on first paint — otherwise the admin renders but isn't\n // interactive until each lazy `?tsr-split=` chunk lands. `defaultBehavior:\n // []` is the knob the splitter actually honours; `autoCodeSplitting: false`\n // is a belt-and-braces signal (the plugin's schema strips it).\n router: {\n autoCodeSplitting: false,\n codeSplittingOptions: { defaultBehavior: [] },\n // Ignore generated importMap files and colocated `*.functions.ts` modules\n // (they define `createServerFn`s, not routes).\n routeFileIgnorePattern: 'importMap\\\\.(?:js|server\\\\.ts)$|\\\\.functions\\\\.',\n routesDirectory,\n } as any,\n rsc: { enabled: true },\n srcDirectory,\n }\n}\n"],"names":["tanstackStart","viteReact","rsc","path","createLogger","mergeConfig","payloadNoExternalPatterns","ssrExternalPackages","optimizeDepsExcludeDefaults","optimizeDepsIncludeDefaults","payloadScssImporters","defaultImportProtectionIgnoreImporters","onImportProtectionViolation","serverOnlyClientSpecifiers","clientModuleResolution","payloadDevTransforms","reactDomServerInRsc","ssrStripDistStyleImports","stubPrettierInClient","wrapCjsForClient","suppressibleWarningPatterns","withQuietedDependencyWarnings","existing","logger","shouldSuppress","msg","some","pattern","includes","baseWarn","warn","bind","baseWarnOnce","warnOnce","options","applyDependencyWarningSuppression","config","enabled","customLogger","withPayload","build","additionalIgnoreImporters","payloadConfigPath","routesDirectory","silenceDependencyWarnings","srcDirectory","vite","env","base","cssMinify","css","preprocessorOptions","scss","importers","silenceDeprecations","define","global","environments","rollupOptions","external","resolve","noExternal","ssr","optimizeDeps","exclude","include","plugins","alias","find","replacement","dedupe","extensions","tsconfigPaths","pluginOptions","react","payloadReactOptions","payloadRscOptions","payloadTanstackStartOptions","merged","serverHandler","args","importProtection","client","excludeFiles","specifiers","ignoreImporters","mockAccess","onViolation","router","autoCodeSplitting","codeSplittingOptions","defaultBehavior","routeFileIgnorePattern"],"mappings":"AAEA,SAASA,aAAa,QAAQ,oCAAmC;AACjE,OAAOC,eAAe,uBAAsB;AAC5C,OAAOC,SAAS,qBAAoB;AACpC,OAAOC,UAAU,YAAW;AAC5B,SAASC,YAAY,EAAEC,WAAW,QAAQ,OAAM;AAEhD,SAASC,yBAAyB,EAAEC,mBAAmB,QAAQ,uBAAsB;AACrF,SAASC,2BAA2B,EAAEC,2BAA2B,QAAQ,2BAA0B;AACnG,SAASC,oBAAoB,QAAQ,mBAAkB;AACvD,SACEC,sCAAsC,EACtCC,2BAA2B,EAC3BC,0BAA0B,QACrB,wBAAuB;AAC9B,SAASC,sBAAsB,QAAQ,0CAAyC;AAChF,SAASC,oBAAoB,QAAQ,iCAAgC;AACrE,SAASC,mBAAmB,QAAQ,uCAAsC;AAC1E,SAASC,wBAAwB,QAAQ,yCAAwC;AACjF,SAASC,oBAAoB,QAAQ,wCAAuC;AAC5E,SAASC,gBAAgB,QAAQ,oCAAmC;A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OAAO;QAAEX,SAAS,EAAE;QAAEC,SAAS;IAAa;AAC9C;AAWA;;;;CAIC,GACD,OAAO,SAASY,4BACdG,OAAwC,CAAC,CAAC;IAE1C,MAAM,EAAEvC,4BAA4B,EAAE,EAAEE,kBAAkB,KAAK,EAAEE,eAAe,KAAK,EAAE,GAAGmC;IAE1F,OAAO;QACL,2EAA2E;QAC3E,wDAAwD;QACxD,iCAAiC;QACjCC,kBAAkB;YAChBC,QAAQ;gBAAEC,cAAc,EAAE;gBAAEC,YAAYvE;YAA2B;YACnEwE,iBAAiB;mBAAI1E;mBAA2C8B;aAA0B;YAC1FwB,SAAS;gBAAC;aAAO;YACjBqB,YAAY;YACZC,aAAa3E;QACf;QACA,2EAA2E;QAC3E,4EAA4E;QAC5E,2EAA2E;QAC3E,4EAA4E;QAC5E,+DAA+D;QAC/D4E,QAAQ;YACNC,mBAAmB;YACnBC,sBAAsB;gBAAEC,iBAAiB,EAAE;YAAC;YAC5C,0EAA0E;YAC1E,+CAA+C;YAC/CC,wBAAwB;YACxBjD;QACF;QACAzC,KAAK;YAAEmC,SAAS;QAAK;QACrBQ;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/vite/index.ts"],"sourcesContent":["import type { ConfigEnv, Logger, PluginOption, UserConfig, UserConfigFnObject } from 'vite'\n\n// Optional peers, not deps: `plugin-rsc` is a singleton, so bundling our own copy\n// alongside the host's would load two instances and crash.\nimport { tanstackStart } from '@tanstack/react-start/plugin/vite'\nimport viteReact from '@vitejs/plugin-react'\nimport rsc from '@vitejs/plugin-rsc'\nimport path from 'node:path'\nimport { createLogger, mergeConfig } from 'vite'\n\nimport { payloadNoExternalPatterns, ssrExternalPackages } from './config/external.js'\nimport { optimizeDepsExcludeDefaults, optimizeDepsIncludeDefaults } from './config/optimizeDeps.js'\nimport { payloadScssImporters } from './config/scss.js'\nimport {\n defaultImportProtectionIgnoreImporters,\n onImportProtectionViolation,\n serverOnlyClientSpecifiers,\n} from './importProtection.js'\nimport { clientModuleResolution } from './workarounds/clientModuleResolution.js'\nimport { payloadDevTransforms } from './workarounds/devTransforms.js'\nimport { reactDomServerInRsc } from './workarounds/reactDomServerInRsc.js'\nimport { ssrStripDistStyleImports } from './workarounds/stripDistStyleImports.js'\nimport { stubPrettierInClient } from './workarounds/stubPrettierInClient.js'\nimport { wrapCjsForClient } from './workarounds/wrapCjsForClient.js'\n\n/**\n * Vite dependency warnings Payload consumers can't act on: third-party packages\n * ship sourcemaps whose original sources aren't published, so Vite warns on\n * every one. Suppressed by default (see `silenceDependencyWarnings`).\n */\nconst suppressibleWarningPatterns = ['points to missing source files', 'Sourcemap for']\n\n/**\n * Wraps a Vite logger so warnings matching {@link suppressibleWarningPatterns}\n * are dropped. Mutates and returns the given logger (or a fresh default one).\n */\nfunction withQuietedDependencyWarnings(existing?: Logger): Logger {\n const logger = existing ?? createLogger()\n const shouldSuppress = (msg: unknown): boolean =>\n typeof msg === 'string' && suppressibleWarningPatterns.some((pattern) => msg.includes(pattern))\n\n const baseWarn = logger.warn.bind(logger)\n const baseWarnOnce = logger.warnOnce.bind(logger)\n logger.warn = (msg, options) => {\n if (!shouldSuppress(msg)) {\n baseWarn(msg, options)\n }\n }\n logger.warnOnce = (msg, options) => {\n if (!shouldSuppress(msg)) {\n baseWarnOnce(msg, options)\n }\n }\n return logger\n}\n\n/** Applies dependency-warning suppression to a config in place when enabled. */\nfunction applyDependencyWarningSuppression(config: UserConfig, enabled: boolean): UserConfig {\n if (enabled) {\n config.customLogger = withQuietedDependencyWarnings(config.customLogger)\n }\n return config\n}\n\nexport type WithPayloadOptions = {\n /** Extra import-protection `ignoreImporters` patterns for the TanStack Start plugin. */\n additionalIgnoreImporters?: RegExp[]\n /** Route id of Payload's admin layout, eager-loaded instead of code-split. Defaults to `'/_payload'`. */\n adminRouteId?: string\n /** Extra globs exempted from the `.client.*` SSR denial (beyond the default node_modules exemption). */\n clientDenialExcludeFiles?: string[]\n /** Path to the user's `payload.config.ts` (required) */\n payloadConfigPath: string\n /** TanStack router routes directory relative to `srcDirectory`. Defaults to `'app'` */\n routesDirectory?: string\n /** Silence Vite warnings about third-party dependency sourcemaps. Defaults to `true`. */\n silenceDependencyWarnings?: boolean\n /** TanStack source directory. Defaults to `'src'` */\n srcDirectory?: string\n /** Extra Vite config deep-merged over the Payload defaults. Ignored in `build` mode. */\n vite?: UserConfig\n}\n\n/** The options Payload's admin requires for each third-party plugin. */\nexport type PayloadPluginOptions = {\n react: NonNullable<Parameters<typeof viteReact>[0]>\n rsc: NonNullable<Parameters<typeof rsc>[0]>\n tanstackStart: NonNullable<Parameters<typeof tanstackStart>[0]>\n}\n\nexport type WithPayloadBuilderContext = {\n env: ConfigEnv\n /** Options to pass to the `viteReact`/`rsc`/`tanstackStart` factories you import. */\n pluginOptions: PayloadPluginOptions\n}\n\n/**\n * Returns the extra Vite config — the plugins you instantiate plus any overrides.\n * `withPayload` deep-merges it onto Payload's base config, so you don't spread or\n * merge the base yourself.\n */\nexport type WithPayloadBuilder = (context: WithPayloadBuilderContext) => UserConfig\n\n/**\n * Vite config helper for Payload + TanStack Start; the counterpart to Next.js'\n * `withPayload`.\n *\n * Zero-config — Payload instantiates the RSC, React, and TanStack Start plugins:\n *\n * ```ts\n * export default withPayload(undefined, { payloadConfigPath: './src/payload.config.ts' })\n * ```\n *\n * Guest mode — pass a `build` callback to instantiate them yourself (one copy of\n * each; `@vitejs/plugin-rsc` is a hard singleton). Return only your additions;\n * `withPayload` deep-merges them onto Payload's base config:\n *\n * ```ts\n * export default withPayload(\n * ({ pluginOptions }) => ({\n * plugins: [\n * rsc(pluginOptions.rsc),\n * tanstackStart(pluginOptions.tanstackStart),\n * viteReact(pluginOptions.react),\n * ],\n * // ...other config options\n * }),\n * { payloadConfigPath: './src/payload.config.ts' },\n * )\n * ```\n */\nexport function withPayload(\n build: undefined | WithPayloadBuilder,\n options: WithPayloadOptions,\n): UserConfigFnObject {\n const {\n additionalIgnoreImporters = [],\n adminRouteId,\n clientDenialExcludeFiles = [],\n payloadConfigPath,\n routesDirectory = 'app',\n silenceDependencyWarnings = true,\n srcDirectory = 'src',\n vite,\n } = options\n\n return (env) => {\n const base: UserConfig = {\n build: {\n cssMinify: 'esbuild',\n },\n css: {\n preprocessorOptions: {\n scss: {\n importers: payloadScssImporters,\n silenceDeprecations: ['import', 'global-builtin'],\n } as any,\n },\n },\n define: {\n global: 'globalThis',\n },\n environments: {\n rsc: {\n build: { rollupOptions: { external: ssrExternalPackages } },\n resolve: { noExternal: payloadNoExternalPatterns },\n },\n ssr: {\n build: { rollupOptions: { external: ssrExternalPackages } },\n resolve: { noExternal: payloadNoExternalPatterns },\n },\n } as any,\n optimizeDeps: {\n exclude: optimizeDepsExcludeDefaults,\n include: optimizeDepsIncludeDefaults,\n },\n // Payload's internal workaround plugins only. The RSC, TanStack Start, and\n // React plugins are appended below (default form) or by the consumer's\n // `build` callback (guest form).\n plugins: [\n clientModuleResolution(),\n wrapCjsForClient(),\n ssrStripDistStyleImports(),\n reactDomServerInRsc(),\n stubPrettierInClient(),\n payloadDevTransforms(),\n ],\n resolve: {\n alias: [{ find: '@payload-config', replacement: path.resolve(payloadConfigPath) }],\n dedupe: [\n 'react',\n 'react-dom',\n 'scheduler',\n '@payloadcms/ui',\n '@payloadcms/richtext-lexical',\n ],\n extensions: ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json'],\n tsconfigPaths: true,\n } as any,\n ssr: {\n external: ssrExternalPackages,\n noExternal: payloadNoExternalPatterns,\n },\n }\n\n const pluginOptions: PayloadPluginOptions = {\n react: payloadReactOptions(),\n rsc: payloadRscOptions(),\n tanstackStart: payloadTanstackStartOptions({\n additionalIgnoreImporters,\n adminRouteId,\n clientDenialExcludeFiles,\n routesDirectory,\n srcDirectory,\n }),\n }\n\n if (build) {\n return applyDependencyWarningSuppression(\n mergeConfig(base, build({ env, pluginOptions })),\n silenceDependencyWarnings,\n )\n }\n\n base.plugins = [\n ...(base.plugins as PluginOption[]),\n rsc(pluginOptions.rsc),\n tanstackStart(pluginOptions.tanstackStart),\n viteReact(pluginOptions.react),\n ]\n\n const merged = vite ? mergeConfig(base, vite) : base\n\n return applyDependencyWarningSuppression(merged, silenceDependencyWarnings)\n }\n}\n\n/** `@vitejs/plugin-rsc` options for Payload: `serverHandler: false` (TanStack owns the handler). */\nexport function payloadRscOptions(): NonNullable<Parameters<typeof rsc>[0]> {\n return { serverHandler: false }\n}\n\n/** `@vitejs/plugin-react` options for Payload: transform every `.[jt]sx?` file. */\nexport function payloadReactOptions(): NonNullable<Parameters<typeof viteReact>[0]> {\n return { exclude: [], include: /\\.[jt]sx?$/ }\n}\n\nexport type PayloadTanstackStartOptionsArgs = {\n /** Additional import-protection `ignoreImporters` patterns. */\n additionalIgnoreImporters?: RegExp[]\n /**\n * Route id of Payload's admin layout route, eager-loaded (not code-split) so it\n * hydrates on first paint. It and its children skip splitting; host routes keep\n * TanStack's default. Defaults to `'/_payload'` (the `_payload.tsx` convention).\n */\n adminRouteId?: string\n /**\n * Extra globs exempted from TanStack's `.client.*` SSR denial, on top of the\n * default node_modules exemption. Needed only when Payload's own `.client.*`\n * files resolve outside node_modules (e.g. the monorepo's `packages` sources).\n */\n clientDenialExcludeFiles?: string[]\n /** TanStack router routes directory relative to `srcDirectory`. Defaults to `'app'`. */\n routesDirectory?: string\n /** TanStack source directory. Defaults to `'src'`. */\n srcDirectory?: string\n}\n\n/**\n * The `tanstackStart` options Payload's admin requires (import-protection and\n * code-splitting). TanStack Start is one-per-app, so a host that already runs it\n * should merge these into its single `tanstackStart` call.\n */\nexport function payloadTanstackStartOptions(\n args: PayloadTanstackStartOptionsArgs = {},\n): NonNullable<Parameters<typeof tanstackStart>[0]> {\n const {\n additionalIgnoreImporters = [],\n adminRouteId = '/_payload',\n clientDenialExcludeFiles = [],\n routesDirectory = 'app',\n srcDirectory = 'src',\n } = args\n\n return {\n importProtection: {\n client: { excludeFiles: [], specifiers: serverOnlyClientSpecifiers },\n ignoreImporters: [...defaultImportProtectionIgnoreImporters, ...additionalIgnoreImporters],\n include: ['**/*'],\n mockAccess: 'warn',\n onViolation: onImportProtectionViolation,\n // Payload's `.client.*` components are React Client Components that must be\n // server-rendered during SSR; TanStack's default `**/*.client.*` server\n // denial would mock and crash them. All such files live in `@payloadcms/*`\n // packages, so keep the denial (host `.client.*` files still get it) and\n // just exempt Payload's — `node_modules` covers published installs.\n server: { excludeFiles: ['**/node_modules/**', ...clientDenialExcludeFiles] },\n },\n router: {\n codeSplittingOptions: {\n // Eager-load only Payload's admin routes so they hydrate on first paint —\n // a split admin renders but isn't interactive until its lazy `?tsr-split=`\n // chunk lands. Returning `[]` disables splitting for a route; `undefined`\n // lets host routes keep TanStack's default per-route splitting.\n splitBehavior: ({ routeId }: { routeId: string }) =>\n routeId === adminRouteId || routeId.startsWith(`${adminRouteId}/`) ? [] : undefined,\n },\n // Ignore generated importMap files and colocated `*.functions.ts` modules\n // (they define `createServerFn`s, not routes).\n routeFileIgnorePattern: 'importMap\\\\.(?:js|server\\\\.ts)$|\\\\.functions\\\\.',\n routesDirectory,\n } as any,\n rsc: { enabled: true },\n srcDirectory,\n }\n}\n"],"names":["tanstackStart","viteReact","rsc","path","createLogger","mergeConfig","payloadNoExternalPatterns","ssrExternalPackages","optimizeDepsExcludeDefaults","optimizeDepsIncludeDefaults","payloadScssImporters","defaultImportProtectionIgnoreImporters","onImportProtectionViolation","serverOnlyClientSpecifiers","clientModuleResolution","payloadDevTransforms","reactDomServerInRsc","ssrStripDistStyleImports","stubPrettierInClient","wrapCjsForClient","suppressibleWarningPatterns","withQuietedDependencyWarnings","existing","logger","shouldSuppress","msg","some","pattern","includes","baseWarn","warn","bind","baseWarnOnce","warnOnce","options","applyDependencyWarningSuppression","config","enabled","customLogger","withPayload","build","additionalIgnoreImporters","adminRouteId","clientDenialExcludeFiles","payloadConfigPath","routesDirectory","silenceDependencyWarnings","srcDirectory","vite","env","base","cssMinify","css","preprocessorOptions","scss","importers","silenceDeprecations","define","global","environments","rollupOptions","external","resolve","noExternal","ssr","optimizeDeps","exclude","include","plugins","alias","find","replacement","dedupe","extensions","tsconfigPaths","pluginOptions","react","payloadReactOptions","payloadRscOptions","payloadTanstackStartOptions","merged","serverHandler","args","importProtection","client","excludeFiles","specifiers","ignoreImporters","mockAccess","onViolation","server","router","codeSplittingOptions","splitBehavior","routeId","startsWith","undefined","routeFileIgnorePattern"],"mappings":"AAEA,kFAAkF;AAClF,2DAA2D;AAC3D,SAASA,aAAa,QAAQ,oCAAmC;AACjE,OAAOC,eAAe,uBAAsB;AAC5C,OAAOC,SAAS,qBAAoB;AACpC,OAAOC,UAAU,YAAW;AAC5B,SAASC,YAAY,EAAEC,WAAW,QAAQ,OAAM;AAEhD,SAASC,yBAAyB,EAAEC,mBAAmB,QAAQ,uBAAsB;AACrF,SAASC,2BAA2B,EAAEC,2BAA2B,QAAQ,2BAA0B;AACnG,SAASC,oBAAoB,QAAQ,mBAAkB;AACvD,SACEC,sCAAsC,EACtCC,2BAA2B,EAC3BC,0BAA0B,QACrB,wBAAuB;AAC9B,SAASC,sBAAsB,QAAQ,0CAAyC;AAChF,SAASC,oBAAoB,QAAQ,iCAAgC;AACrE,SAASC,mBAAmB,QAAQ,uCAAsC;AAC1E,SAASC,wBAAwB,QAAQ,yCAAwC;AACjF,SAASC,oBAAoB,QAAQ,wCAAuC;AAC5E,SAASC,gBAAgB,QAAQ,oCAAmC;AAEpE;;;;CAIC,GACD,MAAMC,8BAA8B;IAAC;IAAkC;CAAgB;AAEvF;;;CAGC,GACD,SAASC,8BAA8BC,QAAiB;IACtD,MAAMC,SAASD,YAAYlB;IAC3B,MAAMoB,iBAAiB,CAACC,MACtB,OAAOA,QAAQ,YAAYL,4BAA4BM,IAAI,CAAC,CAACC,UAAYF,IAAIG,QAAQ,CAACD;IAExF,MAAME,WAAWN,OAAOO,IAAI,CAACC,IAAI,CAACR;IAClC,MAAMS,eAAeT,OAAOU,QAAQ,CAACF,IAAI,CAACR;IAC1CA,OAAOO,IAAI,G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YAAYzE;YAA2B;YACnE0E,iBAAiB;mBAAI5E;mBAA2C8B;aAA0B;YAC1F0B,SAAS;gBAAC;aAAO;YACjBqB,YAAY;YACZC,aAAa7E;YACb,4EAA4E;YAC5E,wEAAwE;YACxE,2EAA2E;YAC3E,yEAAyE;YACzE,oEAAoE;YACpE8E,QAAQ;gBAAEL,cAAc;oBAAC;uBAAyB1C;iBAAyB;YAAC;QAC9E;QACAgD,QAAQ;YACNC,sBAAsB;gBACpB,0EAA0E;gBAC1E,2EAA2E;gBAC3E,0EAA0E;gBAC1E,gEAAgE;gBAChEC,eAAe,CAAC,EAAEC,OAAO,EAAuB,GAC9CA,YAAYpD,gBAAgBoD,QAAQC,UAAU,CAAC,GAAGrD,aAAa,CAAC,CAAC,IAAI,EAAE,GAAGsD;YAC9E;YACA,0EAA0E;YAC1E,+CAA+C;YAC/CC,wBAAwB;YACxBpD;QACF;QACA3C,KAAK;YAAEmC,SAAS;QAAK;QACrBU;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devTransforms.d.ts","sourceRoot":"","sources":["../../../src/vite/workarounds/devTransforms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,IAAI,YAAY,
|
|
1
|
+
{"version":3,"file":"devTransforms.d.ts","sourceRoot":"","sources":["../../../src/vite/workarounds/devTransforms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,IAAI,YAAY,CAgEnD"}
|
|
@@ -38,6 +38,11 @@ window.__vite_plugin_react_preamble_installed__ = true
|
|
|
38
38
|
return chunk;
|
|
39
39
|
}
|
|
40
40
|
const str = typeof chunk === 'string' ? chunk : Buffer.isBuffer(chunk) ? chunk.toString() : chunk instanceof Uint8Array ? Buffer.from(chunk).toString() : null;
|
|
41
|
+
// Skip if a host already injected the preamble — a second copy breaks HMR.
|
|
42
|
+
if (str && str.includes('__vite_plugin_react_preamble_installed__')) {
|
|
43
|
+
injected = true;
|
|
44
|
+
return chunk;
|
|
45
|
+
}
|
|
41
46
|
if (str && str.includes('</head>')) {
|
|
42
47
|
injected = true;
|
|
43
48
|
return str.replace('</head>', `${devScripts}</head>`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/vite/workarounds/devTransforms.ts"],"sourcesContent":["import type { PluginOption } from 'vite'\n\n/**\n * Dev-time transforms:\n * - Replaces `process.cwd()` with `\"/\"` in client code (non-SSR, non-prebundled)\n * - Injects Vite HMR + React Refresh preamble into SSR-rendered HTML (dev only)\n *\n * The preamble is injected just before `</head>`, *after* everything React\n * renders into the head. React 19 treats `<meta>`/`<link>`/`<style>`/`<title>`\n * as hoistable resources it matches by key (position-tolerant), but a\n * non-hoistable inline `<script type=\"module\">` placed *before* React's first\n * rendered head node makes hydration position-match that script against a\n * `<style>`/`<meta>` and throw — discarding the whole tree client-side, which\n * aborts in-flight server-function fetches and intermittently breaks drawers,\n * forms, and navigation. Appending after React's head content keeps the\n * preamble out of that positional comparison while still running before the\n * body's app-entry module.\n */\nexport function payloadDevTransforms(): PluginOption {\n const devScripts = `<script type=\"module\" src=\"/@vite/client\"></script>\n<script type=\"module\">\nimport RefreshRuntime from \"/@react-refresh\"\nRefreshRuntime.injectIntoGlobalHook(window)\nwindow.$RefreshReg$ = () => {}\nwindow.$RefreshSig$ = () => (type) => type\nwindow.__vite_plugin_react_preamble_installed__ = true\n</script>`\n\n return {\n name: 'payload:dev-transforms',\n configureServer(server) {\n server.middlewares.use((_req, res, next) => {\n let injected = false\n const origWrite = res.write\n const origEnd = res.end\n\n function tryInject(chunk: any): any {\n if (injected || chunk == null) {\n return chunk\n }\n const ct = res.getHeader('content-type')\n if (typeof ct !== 'string' || !ct.includes('text/html')) {\n return chunk\n }\n const str =\n typeof chunk === 'string'\n ? chunk\n : Buffer.isBuffer(chunk)\n ? chunk.toString()\n : chunk instanceof Uint8Array\n ? Buffer.from(chunk).toString()\n : null\n if (str && str.includes('</head>')) {\n injected = true\n return str.replace('</head>', `${devScripts}</head>`)\n }\n return chunk\n }\n\n res.write = function (this: any, chunk: any, encodingOrCb?: any, cb?: any) {\n return origWrite.call(this, tryInject(chunk), encodingOrCb, cb)\n } as typeof res.write\n res.end = function (this: any, chunk?: any, encodingOrCb?: any, cb?: any) {\n return origEnd.call(this, tryInject(chunk), encodingOrCb, cb)\n } as typeof res.end\n next()\n })\n },\n transform(code, id, options) {\n if (options?.ssr) {\n return\n }\n if (code.includes('process.cwd') && !id.includes('node_modules/.vite')) {\n return code.replace(/process\\.cwd\\(\\)/g, '\"/\"')\n }\n },\n }\n}\n"],"names":["payloadDevTransforms","devScripts","name","configureServer","server","middlewares","use","_req","res","next","injected","origWrite","write","origEnd","end","tryInject","chunk","ct","getHeader","includes","str","Buffer","isBuffer","toString","Uint8Array","from","replace","encodingOrCb","cb","call","transform","code","id","options","ssr"],"mappings":"AAEA;;;;;;;;;;;;;;;CAeC,GACD,OAAO,SAASA;IACd,MAAMC,aAAa,CAAC;;;;;;;SAOb,CAAC;IAER,OAAO;QACLC,MAAM;QACNC,iBAAgBC,MAAM;YACpBA,OAAOC,WAAW,CAACC,GAAG,CAAC,CAACC,MAAMC,KAAKC;gBACjC,IAAIC,WAAW;gBACf,MAAMC,YAAYH,IAAII,KAAK;gBAC3B,MAAMC,UAAUL,IAAIM,GAAG;gBAEvB,SAASC,UAAUC,KAAU;oBAC3B,IAAIN,YAAYM,SAAS,MAAM;wBAC7B,OAAOA;oBACT;oBACA,MAAMC,KAAKT,IAAIU,SAAS,CAAC;oBACzB,IAAI,OAAOD,OAAO,YAAY,CAACA,GAAGE,QAAQ,CAAC,cAAc;wBACvD,OAAOH;oBACT;oBACA,MAAMI,MACJ,OAAOJ,UAAU,WACbA,QACAK,OAAOC,QAAQ,CAACN,SACdA,MAAMO,QAAQ,KACdP,iBAAiBQ,aACfH,OAAOI,IAAI,CAACT,OAAOO,QAAQ,KAC3B;oBACV,IAAIH,OAAOA,IAAID,QAAQ,CAAC,YAAY;wBAClCT,WAAW;wBACX,OAAOU,IAAIM,OAAO,CAAC,WAAW,GAAGzB,WAAW,OAAO,CAAC;oBACtD;oBACA,OAAOe;gBACT;gBAEAR,IAAII,KAAK,GAAG,SAAqBI,KAAU,EAAEW,YAAkB,EAAEC,EAAQ;oBACvE,OAAOjB,UAAUkB,IAAI,CAAC,IAAI,EAAEd,UAAUC,QAAQW,cAAcC;gBAC9D;gBACApB,IAAIM,GAAG,GAAG,SAAqBE,KAAW,EAAEW,YAAkB,EAAEC,EAAQ;oBACtE,OAAOf,QAAQgB,IAAI,CAAC,IAAI,EAAEd,UAAUC,QAAQW,cAAcC;gBAC5D;gBACAnB;YACF;QACF;QACAqB,WAAUC,IAAI,EAAEC,EAAE,EAAEC,OAAO;YACzB,IAAIA,SAASC,KAAK;gBAChB;YACF;YACA,IAAIH,KAAKZ,QAAQ,CAAC,kBAAkB,CAACa,GAAGb,QAAQ,CAAC,uBAAuB;gBACtE,OAAOY,KAAKL,OAAO,CAAC,qBAAqB;YAC3C;QACF;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../src/vite/workarounds/devTransforms.ts"],"sourcesContent":["import type { PluginOption } from 'vite'\n\n/**\n * Dev-time transforms:\n * - Replaces `process.cwd()` with `\"/\"` in client code (non-SSR, non-prebundled)\n * - Injects Vite HMR + React Refresh preamble into SSR-rendered HTML (dev only)\n *\n * The preamble is injected just before `</head>`, *after* everything React\n * renders into the head. React 19 treats `<meta>`/`<link>`/`<style>`/`<title>`\n * as hoistable resources it matches by key (position-tolerant), but a\n * non-hoistable inline `<script type=\"module\">` placed *before* React's first\n * rendered head node makes hydration position-match that script against a\n * `<style>`/`<meta>` and throw — discarding the whole tree client-side, which\n * aborts in-flight server-function fetches and intermittently breaks drawers,\n * forms, and navigation. Appending after React's head content keeps the\n * preamble out of that positional comparison while still running before the\n * body's app-entry module.\n */\nexport function payloadDevTransforms(): PluginOption {\n const devScripts = `<script type=\"module\" src=\"/@vite/client\"></script>\n<script type=\"module\">\nimport RefreshRuntime from \"/@react-refresh\"\nRefreshRuntime.injectIntoGlobalHook(window)\nwindow.$RefreshReg$ = () => {}\nwindow.$RefreshSig$ = () => (type) => type\nwindow.__vite_plugin_react_preamble_installed__ = true\n</script>`\n\n return {\n name: 'payload:dev-transforms',\n configureServer(server) {\n server.middlewares.use((_req, res, next) => {\n let injected = false\n const origWrite = res.write\n const origEnd = res.end\n\n function tryInject(chunk: any): any {\n if (injected || chunk == null) {\n return chunk\n }\n const ct = res.getHeader('content-type')\n if (typeof ct !== 'string' || !ct.includes('text/html')) {\n return chunk\n }\n const str =\n typeof chunk === 'string'\n ? chunk\n : Buffer.isBuffer(chunk)\n ? chunk.toString()\n : chunk instanceof Uint8Array\n ? Buffer.from(chunk).toString()\n : null\n // Skip if a host already injected the preamble — a second copy breaks HMR.\n if (str && str.includes('__vite_plugin_react_preamble_installed__')) {\n injected = true\n return chunk\n }\n if (str && str.includes('</head>')) {\n injected = true\n return str.replace('</head>', `${devScripts}</head>`)\n }\n return chunk\n }\n\n res.write = function (this: any, chunk: any, encodingOrCb?: any, cb?: any) {\n return origWrite.call(this, tryInject(chunk), encodingOrCb, cb)\n } as typeof res.write\n res.end = function (this: any, chunk?: any, encodingOrCb?: any, cb?: any) {\n return origEnd.call(this, tryInject(chunk), encodingOrCb, cb)\n } as typeof res.end\n next()\n })\n },\n transform(code, id, options) {\n if (options?.ssr) {\n return\n }\n if (code.includes('process.cwd') && !id.includes('node_modules/.vite')) {\n return code.replace(/process\\.cwd\\(\\)/g, '\"/\"')\n }\n },\n }\n}\n"],"names":["payloadDevTransforms","devScripts","name","configureServer","server","middlewares","use","_req","res","next","injected","origWrite","write","origEnd","end","tryInject","chunk","ct","getHeader","includes","str","Buffer","isBuffer","toString","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BAC5D;gBACAnB;YACF;QACF;QACAqB,WAAUC,IAAI,EAAEC,EAAE,EAAEC,OAAO;YACzB,IAAIA,SAASC,KAAK;gBAChB;YACF;YACA,IAAIH,KAAKZ,QAAQ,CAAC,kBAAkB,CAACa,GAAGb,QAAQ,CAAC,uBAAuB;gBACtE,OAAOY,KAAKL,OAAO,CAAC,qBAAqB;YAC3C;QACF;IACF;AACF"}
|
|
@@ -2,20 +2,12 @@ import type { PluginOption } from 'vite';
|
|
|
2
2
|
/**
|
|
3
3
|
* Stubs `prettier` in the CLIENT bundle only.
|
|
4
4
|
*
|
|
5
|
-
* `payload`'s barrel transitively pulls `
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* still drags `prettier`'s `index.cjs` in — where it fails to parse as ESM and
|
|
10
|
-
* breaks the client build.
|
|
5
|
+
* `payload`'s barrel transitively pulls `json-schema-to-typescript` → `prettier`
|
|
6
|
+
* (CommonJS) into the client graph. That path is type-gen only and never runs in
|
|
7
|
+
* the browser, but the bundler still drags in `prettier`'s `index.cjs`, which
|
|
8
|
+
* fails to parse as ESM and breaks the client build. SSR/RSC keep real prettier.
|
|
11
9
|
*
|
|
12
|
-
*
|
|
13
|
-
* only. SSR/RSC keep the real `prettier` (there `json-schema-to-typescript`
|
|
14
|
-
* stays external and resolves it from `node_modules`), and the `prettier` CLI /
|
|
15
|
-
* `payload generate:types` are unaffected.
|
|
16
|
-
*
|
|
17
|
-
* Delete this once `payload`'s barrel no longer reaches the type-gen path from
|
|
18
|
-
* the client-reachable export graph.
|
|
10
|
+
* Delete once `payload`'s barrel no longer reaches type-gen from the client graph.
|
|
19
11
|
*/
|
|
20
12
|
export declare function stubPrettierInClient(): PluginOption;
|
|
21
13
|
//# sourceMappingURL=stubPrettierInClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stubPrettierInClient.d.ts","sourceRoot":"","sources":["../../../src/vite/workarounds/stubPrettierInClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC
|
|
1
|
+
{"version":3,"file":"stubPrettierInClient.d.ts","sourceRoot":"","sources":["../../../src/vite/workarounds/stubPrettierInClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC;;;;;;;;;GASG;AACH,wBAAgB,oBAAoB,IAAI,YAAY,CAqBnD"}
|
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Stubs `prettier` in the CLIENT bundle only.
|
|
3
3
|
*
|
|
4
|
-
* `payload`'s barrel transitively pulls `
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* still drags `prettier`'s `index.cjs` in — where it fails to parse as ESM and
|
|
9
|
-
* breaks the client build.
|
|
4
|
+
* `payload`'s barrel transitively pulls `json-schema-to-typescript` → `prettier`
|
|
5
|
+
* (CommonJS) into the client graph. That path is type-gen only and never runs in
|
|
6
|
+
* the browser, but the bundler still drags in `prettier`'s `index.cjs`, which
|
|
7
|
+
* fails to parse as ESM and breaks the client build. SSR/RSC keep real prettier.
|
|
10
8
|
*
|
|
11
|
-
*
|
|
12
|
-
* only. SSR/RSC keep the real `prettier` (there `json-schema-to-typescript`
|
|
13
|
-
* stays external and resolves it from `node_modules`), and the `prettier` CLI /
|
|
14
|
-
* `payload generate:types` are unaffected.
|
|
15
|
-
*
|
|
16
|
-
* Delete this once `payload`'s barrel no longer reaches the type-gen path from
|
|
17
|
-
* the client-reachable export graph.
|
|
9
|
+
* Delete once `payload`'s barrel no longer reaches type-gen from the client graph.
|
|
18
10
|
*/ export function stubPrettierInClient() {
|
|
19
11
|
const RESOLVED_ID = '\0payload:prettier-client-stub';
|
|
20
12
|
return {
|
|
@@ -25,11 +17,12 @@
|
|
|
25
17
|
return 'export const format = (source) => source;\nexport default { format };';
|
|
26
18
|
}
|
|
27
19
|
},
|
|
28
|
-
resolveId (id,
|
|
20
|
+
resolveId (id, importer, options) {
|
|
29
21
|
if (options?.ssr) {
|
|
30
22
|
return;
|
|
31
23
|
}
|
|
32
|
-
|
|
24
|
+
// Only stub the type-gen import; leave a host's own client `prettier` alone.
|
|
25
|
+
if (id === 'prettier' && importer?.includes('json-schema-to-typescript')) {
|
|
33
26
|
return RESOLVED_ID;
|
|
34
27
|
}
|
|
35
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/vite/workarounds/stubPrettierInClient.ts"],"sourcesContent":["import type { PluginOption } from 'vite'\n\n/**\n * Stubs `prettier` in the CLIENT bundle only.\n *\n * `payload`'s barrel transitively pulls `
|
|
1
|
+
{"version":3,"sources":["../../../src/vite/workarounds/stubPrettierInClient.ts"],"sourcesContent":["import type { PluginOption } from 'vite'\n\n/**\n * Stubs `prettier` in the CLIENT bundle only.\n *\n * `payload`'s barrel transitively pulls `json-schema-to-typescript` → `prettier`\n * (CommonJS) into the client graph. That path is type-gen only and never runs in\n * the browser, but the bundler still drags in `prettier`'s `index.cjs`, which\n * fails to parse as ESM and breaks the client build. SSR/RSC keep real prettier.\n *\n * Delete once `payload`'s barrel no longer reaches type-gen from the client graph.\n */\nexport function stubPrettierInClient(): PluginOption {\n const RESOLVED_ID = '\\0payload:prettier-client-stub'\n\n return {\n name: 'payload:stub-prettier-in-client',\n enforce: 'pre',\n load(id) {\n if (id === RESOLVED_ID) {\n return 'export const format = (source) => source;\\nexport default { format };'\n }\n },\n resolveId(id, importer, options) {\n if (options?.ssr) {\n return\n }\n // Only stub the type-gen import; leave a host's own client `prettier` alone.\n if (id === 'prettier' && importer?.includes('json-schema-to-typescript')) {\n return RESOLVED_ID\n }\n },\n }\n}\n"],"names":["stubPrettierInClient","RESOLVED_ID","name","enforce","load","id","resolveId","importer","options","ssr","includes"],"mappings":"AAEA;;;;;;;;;CASC,GACD,OAAO,SAASA;IACd,MAAMC,cAAc;IAEpB,OAAO;QACLC,MAAM;QACNC,SAAS;QACTC,MAAKC,EAAE;YACL,IAAIA,OAAOJ,aAAa;gBACtB,OAAO;YACT;QACF;QACAK,WAAUD,EAAE,EAAEE,QAAQ,EAAEC,OAAO;YAC7B,IAAIA,SAASC,KAAK;gBAChB;YACF;YACA,6EAA6E;YAC7E,IAAIJ,OAAO,cAAcE,UAAUG,SAAS,8BAA8B;gBACxE,OAAOT;YACT;QACF;IACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/tanstack-start",
|
|
3
|
-
"version": "4.0.0-internal.
|
|
3
|
+
"version": "4.0.0-internal.543da65",
|
|
4
4
|
"description": "TanStack Start framework adapter for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -57,32 +57,39 @@
|
|
|
57
57
|
"dist"
|
|
58
58
|
],
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@vitejs/plugin-react": "^6.0.0",
|
|
61
|
-
"@vitejs/plugin-rsc": "^0.5.21",
|
|
62
60
|
"qs-esm": "^7.0.2",
|
|
63
|
-
"@payloadcms/translations": "4.0.0-internal.
|
|
64
|
-
"@payloadcms/ui": "4.0.0-internal.
|
|
61
|
+
"@payloadcms/translations": "4.0.0-internal.543da65",
|
|
62
|
+
"@payloadcms/ui": "4.0.0-internal.543da65"
|
|
65
63
|
},
|
|
66
64
|
"devDependencies": {
|
|
67
65
|
"@tanstack/react-router": "^1.120.0",
|
|
68
66
|
"@tanstack/react-start": "^1.168.26",
|
|
69
67
|
"@types/react": "^19.0.0",
|
|
70
68
|
"@types/react-dom": "^19.0.0",
|
|
69
|
+
"@vitejs/plugin-react": "^6.0.0",
|
|
71
70
|
"@vitejs/plugin-rsc": "^0.5.21",
|
|
72
71
|
"react": "^19.0.0",
|
|
73
72
|
"react-dom": "^19.0.0",
|
|
74
73
|
"vite": ">=8.0.0",
|
|
75
|
-
"payload": "4.0.0-internal.
|
|
74
|
+
"payload": "4.0.0-internal.543da65"
|
|
76
75
|
},
|
|
77
76
|
"peerDependencies": {
|
|
78
77
|
"@tanstack/react-router": "^1.120.0",
|
|
79
78
|
"@tanstack/react-start": "^1.168.26",
|
|
79
|
+
"@vitejs/plugin-react": "^6.0.0",
|
|
80
|
+
"@vitejs/plugin-rsc": "^0.5.21",
|
|
80
81
|
"react": "^19.0.0",
|
|
81
82
|
"react-dom": "^19.0.0",
|
|
82
83
|
"vite": ">=8.0.0",
|
|
83
|
-
"payload": "4.0.0-internal.
|
|
84
|
+
"payload": "4.0.0-internal.543da65"
|
|
84
85
|
},
|
|
85
86
|
"peerDependenciesMeta": {
|
|
87
|
+
"@vitejs/plugin-react": {
|
|
88
|
+
"optional": true
|
|
89
|
+
},
|
|
90
|
+
"@vitejs/plugin-rsc": {
|
|
91
|
+
"optional": true
|
|
92
|
+
},
|
|
86
93
|
"vite": {
|
|
87
94
|
"optional": true
|
|
88
95
|
}
|