@payloadcms/tanstack-start 4.0.0-internal.e387174 → 4.0.0-internal.e55ccef
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/exports/client.d.ts +1 -1
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +1 -1
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/server.d.ts +2 -2
- package/dist/exports/server.d.ts.map +1 -1
- package/dist/exports/server.js +2 -2
- package/dist/exports/server.js.map +1 -1
- package/dist/exports/vite.d.ts +2 -2
- package/dist/exports/vite.d.ts.map +1 -1
- package/dist/exports/vite.js +1 -1
- package/dist/exports/vite.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/layouts/Root/getLayoutData.d.ts.map +1 -1
- package/dist/layouts/Root/getLayoutData.js +1 -1
- package/dist/layouts/Root/getLayoutData.js.map +1 -1
- package/dist/layouts/Root/index.js +4 -2
- package/dist/layouts/Root/index.js.map +1 -1
- package/dist/layouts/Root/withPayloadRoot.d.ts +7 -31
- package/dist/layouts/Root/withPayloadRoot.d.ts.map +1 -1
- package/dist/layouts/Root/withPayloadRoot.js +33 -34
- package/dist/layouts/Root/withPayloadRoot.js.map +1 -1
- package/dist/node/cssLoader.d.mts +24 -2
- package/dist/node/cssLoader.d.mts.map +1 -1
- package/dist/routes/adminRoutes.d.ts.map +1 -1
- package/dist/routes/apiRoute.js +1 -1
- package/dist/routes/apiRoute.js.map +1 -1
- package/dist/routes/layoutRoute.d.ts.map +1 -1
- package/dist/utilities/graphqlHandler.server.d.ts.map +1 -1
- package/dist/utilities/{handleAPIRoute.d.ts → handleAPIRoute.server.d.ts} +1 -1
- package/dist/utilities/handleAPIRoute.server.d.ts.map +1 -0
- package/dist/utilities/{handleAPIRoute.js → handleAPIRoute.server.js} +1 -1
- package/dist/utilities/handleAPIRoute.server.js.map +1 -0
- package/dist/utilities/loadAdminPage.d.ts.map +1 -1
- package/dist/utilities/loadAdminPage.js +11 -2
- package/dist/utilities/loadAdminPage.js.map +1 -1
- package/dist/utilities/meta.d.ts +1 -0
- package/dist/utilities/meta.d.ts.map +1 -1
- package/dist/utilities/meta.js +2 -1
- package/dist/utilities/meta.js.map +1 -1
- package/dist/utilities/routerSearch.d.ts +40 -0
- package/dist/utilities/routerSearch.d.ts.map +1 -0
- package/dist/utilities/routerSearch.js +45 -0
- package/dist/utilities/routerSearch.js.map +1 -0
- package/dist/utilities/serverAdapter.server.d.ts.map +1 -1
- package/dist/vite/config/external.d.ts +11 -0
- package/dist/vite/config/external.d.ts.map +1 -0
- package/dist/vite/config/external.js +48 -0
- package/dist/vite/config/external.js.map +1 -0
- package/dist/vite/config/optimizeDeps.d.ts +25 -0
- package/dist/vite/config/optimizeDeps.d.ts.map +1 -0
- package/dist/vite/{constants.js → config/optimizeDeps.js} +9 -63
- package/dist/vite/config/optimizeDeps.js.map +1 -0
- package/dist/vite/config/scss.d.ts +14 -0
- package/dist/vite/config/scss.d.ts.map +1 -0
- package/dist/vite/config/scss.js +28 -0
- package/dist/vite/config/scss.js.map +1 -0
- package/dist/vite/index.d.ts +99 -0
- package/dist/vite/index.d.ts.map +1 -0
- package/dist/vite/index.js +258 -0
- package/dist/vite/index.js.map +1 -0
- package/dist/vite/workarounds/clientModuleResolution.d.ts.map +1 -0
- package/dist/vite/workarounds/clientModuleResolution.js.map +1 -0
- package/dist/vite/workarounds/devTransforms.d.ts.map +1 -0
- package/dist/vite/{plugins → workarounds}/devTransforms.js +5 -0
- package/dist/vite/workarounds/devTransforms.js.map +1 -0
- package/dist/vite/workarounds/reactDomServerInRsc.d.ts.map +1 -0
- package/dist/vite/workarounds/reactDomServerInRsc.js.map +1 -0
- package/dist/vite/workarounds/stripDistStyleImports.d.ts.map +1 -0
- package/dist/vite/workarounds/stripDistStyleImports.js.map +1 -0
- package/dist/vite/workarounds/stubPrettierInClient.d.ts +13 -0
- package/dist/vite/workarounds/stubPrettierInClient.d.ts.map +1 -0
- package/dist/vite/workarounds/stubPrettierInClient.js +32 -0
- package/dist/vite/workarounds/stubPrettierInClient.js.map +1 -0
- package/dist/vite/workarounds/wrapCjsForClient.d.ts.map +1 -0
- package/dist/vite/workarounds/wrapCjsForClient.js.map +1 -0
- package/package.json +10 -5
- package/dist/utilities/getRequestTheme.d.ts +0 -10
- package/dist/utilities/getRequestTheme.d.ts.map +0 -1
- package/dist/utilities/getRequestTheme.js +0 -25
- package/dist/utilities/getRequestTheme.js.map +0 -1
- package/dist/utilities/handleAPIRoute.d.ts.map +0 -1
- package/dist/utilities/handleAPIRoute.js.map +0 -1
- package/dist/vite/constants.d.ts +0 -42
- package/dist/vite/constants.d.ts.map +0 -1
- package/dist/vite/constants.js.map +0 -1
- package/dist/vite/plugin.d.ts +0 -38
- package/dist/vite/plugin.d.ts.map +0 -1
- package/dist/vite/plugin.js +0 -177
- package/dist/vite/plugin.js.map +0 -1
- package/dist/vite/plugins/clientModuleResolution.d.ts.map +0 -1
- package/dist/vite/plugins/clientModuleResolution.js.map +0 -1
- package/dist/vite/plugins/devTransforms.d.ts.map +0 -1
- package/dist/vite/plugins/devTransforms.js.map +0 -1
- package/dist/vite/plugins/reactDomServerInRsc.d.ts.map +0 -1
- package/dist/vite/plugins/reactDomServerInRsc.js.map +0 -1
- package/dist/vite/plugins/stripDistStyleImports.d.ts.map +0 -1
- package/dist/vite/plugins/stripDistStyleImports.js.map +0 -1
- package/dist/vite/plugins/wrapCjsForClient.d.ts.map +0 -1
- package/dist/vite/plugins/wrapCjsForClient.js.map +0 -1
- /package/dist/vite/{plugins → workarounds}/clientModuleResolution.d.ts +0 -0
- /package/dist/vite/{plugins → workarounds}/clientModuleResolution.js +0 -0
- /package/dist/vite/{plugins → workarounds}/devTransforms.d.ts +0 -0
- /package/dist/vite/{plugins → workarounds}/reactDomServerInRsc.d.ts +0 -0
- /package/dist/vite/{plugins → workarounds}/reactDomServerInRsc.js +0 -0
- /package/dist/vite/{plugins → workarounds}/stripDistStyleImports.d.ts +0 -0
- /package/dist/vite/{plugins → workarounds}/stripDistStyleImports.js +0 -0
- /package/dist/vite/{plugins → workarounds}/wrapCjsForClient.d.ts +0 -0
- /package/dist/vite/{plugins → workarounds}/wrapCjsForClient.js +0 -0
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.e55ccef",
|
|
4
4
|
"description": "TanStack Start framework adapter for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
],
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"qs-esm": "^7.0.2",
|
|
61
|
-
"@payloadcms/translations": "4.0.0-internal.
|
|
62
|
-
"@payloadcms/ui": "4.0.0-internal.
|
|
61
|
+
"@payloadcms/translations": "4.0.0-internal.e55ccef",
|
|
62
|
+
"@payloadcms/ui": "4.0.0-internal.e55ccef"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@tanstack/react-router": "^1.120.0",
|
|
@@ -67,24 +67,29 @@
|
|
|
67
67
|
"@types/react": "^19.0.0",
|
|
68
68
|
"@types/react-dom": "^19.0.0",
|
|
69
69
|
"@vitejs/plugin-react": "^6.0.0",
|
|
70
|
+
"@vitejs/plugin-rsc": "^0.5.21",
|
|
70
71
|
"react": "^19.0.0",
|
|
71
72
|
"react-dom": "^19.0.0",
|
|
72
73
|
"vite": ">=8.0.0",
|
|
73
|
-
"payload": "4.0.0-internal.
|
|
74
|
+
"payload": "4.0.0-internal.e55ccef"
|
|
74
75
|
},
|
|
75
76
|
"peerDependencies": {
|
|
76
77
|
"@tanstack/react-router": "^1.120.0",
|
|
77
78
|
"@tanstack/react-start": "^1.168.26",
|
|
78
79
|
"@vitejs/plugin-react": "^6.0.0",
|
|
80
|
+
"@vitejs/plugin-rsc": "^0.5.21",
|
|
79
81
|
"react": "^19.0.0",
|
|
80
82
|
"react-dom": "^19.0.0",
|
|
81
83
|
"vite": ">=8.0.0",
|
|
82
|
-
"payload": "4.0.0-internal.
|
|
84
|
+
"payload": "4.0.0-internal.e55ccef"
|
|
83
85
|
},
|
|
84
86
|
"peerDependenciesMeta": {
|
|
85
87
|
"@vitejs/plugin-react": {
|
|
86
88
|
"optional": true
|
|
87
89
|
},
|
|
90
|
+
"@vitejs/plugin-rsc": {
|
|
91
|
+
"optional": true
|
|
92
|
+
},
|
|
88
93
|
"vite": {
|
|
89
94
|
"optional": true
|
|
90
95
|
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { Theme } from '@payloadcms/ui';
|
|
2
|
-
import type { SanitizedConfig } from 'payload';
|
|
3
|
-
type GetRequestThemeArgs = {
|
|
4
|
-
config: SanitizedConfig;
|
|
5
|
-
cookies: Map<string, string>;
|
|
6
|
-
headers: Headers;
|
|
7
|
-
};
|
|
8
|
-
export declare function getRequestTheme({ config, cookies, headers }: GetRequestThemeArgs): Theme;
|
|
9
|
-
export {};
|
|
10
|
-
//# sourceMappingURL=getRequestTheme.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getRequestTheme.d.ts","sourceRoot":"","sources":["../../src/utilities/getRequestTheme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE9C,KAAK,mBAAmB,GAAG;IACzB,MAAM,EAAE,eAAe,CAAA;IACvB,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC5B,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAUD,wBAAgB,eAAe,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,EAAE,mBAAmB,GAAG,KAAK,CAkBxF"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
// Defined locally rather than imported from `@payloadcms/ui` (a `'use client'`
|
|
2
|
-
// barrel) because its value exports resolve to non-serializable client
|
|
3
|
-
// references in this adapter's RSC server context. `Theme` is a type-only
|
|
4
|
-
// import and is safely erased at runtime.
|
|
5
|
-
const defaultTheme = 'light';
|
|
6
|
-
const acceptedThemes = [
|
|
7
|
-
'dark',
|
|
8
|
-
'light'
|
|
9
|
-
];
|
|
10
|
-
export function getRequestTheme({ config, cookies, headers }) {
|
|
11
|
-
if (config.admin.theme !== 'all' && acceptedThemes.includes(config.admin.theme)) {
|
|
12
|
-
return config.admin.theme;
|
|
13
|
-
}
|
|
14
|
-
const themeCookie = cookies.get(`${config.cookiePrefix || 'payload'}-theme`);
|
|
15
|
-
if (themeCookie && acceptedThemes.includes(themeCookie)) {
|
|
16
|
-
return themeCookie;
|
|
17
|
-
}
|
|
18
|
-
const themeFromHeader = headers.get('Sec-CH-Prefers-Color-Scheme');
|
|
19
|
-
if (themeFromHeader && acceptedThemes.includes(themeFromHeader)) {
|
|
20
|
-
return themeFromHeader;
|
|
21
|
-
}
|
|
22
|
-
return defaultTheme;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
//# sourceMappingURL=getRequestTheme.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getRequestTheme.ts"],"sourcesContent":["import type { Theme } from '@payloadcms/ui'\nimport type { SanitizedConfig } from 'payload'\n\ntype GetRequestThemeArgs = {\n config: SanitizedConfig\n cookies: Map<string, string>\n headers: Headers\n}\n\n// Defined locally rather than imported from `@payloadcms/ui` (a `'use client'`\n// barrel) because its value exports resolve to non-serializable client\n// references in this adapter's RSC server context. `Theme` is a type-only\n// import and is safely erased at runtime.\nconst defaultTheme: Theme = 'light'\n\nconst acceptedThemes: Theme[] = ['dark', 'light']\n\nexport function getRequestTheme({ config, cookies, headers }: GetRequestThemeArgs): Theme {\n if (config.admin.theme !== 'all' && acceptedThemes.includes(config.admin.theme)) {\n return config.admin.theme\n }\n\n const themeCookie = cookies.get(`${config.cookiePrefix || 'payload'}-theme`)\n\n if (themeCookie && acceptedThemes.includes(themeCookie as Theme)) {\n return themeCookie as Theme\n }\n\n const themeFromHeader = headers.get('Sec-CH-Prefers-Color-Scheme') as Theme\n\n if (themeFromHeader && acceptedThemes.includes(themeFromHeader)) {\n return themeFromHeader\n }\n\n return defaultTheme\n}\n"],"names":["defaultTheme","acceptedThemes","getRequestTheme","config","cookies","headers","admin","theme","includes","themeCookie","get","cookiePrefix","themeFromHeader"],"mappings":"AASA,+EAA+E;AAC/E,uEAAuE;AACvE,0EAA0E;AAC1E,0CAA0C;AAC1C,MAAMA,eAAsB;AAE5B,MAAMC,iBAA0B;IAAC;IAAQ;CAAQ;AAEjD,OAAO,SAASC,gBAAgB,EAAEC,MAAM,EAAEC,OAAO,EAAEC,OAAO,EAAuB;IAC/E,IAAIF,OAAOG,KAAK,CAACC,KAAK,KAAK,SAASN,eAAeO,QAAQ,CAACL,OAAOG,KAAK,CAACC,KAAK,GAAG;QAC/E,OAAOJ,OAAOG,KAAK,CAACC,KAAK;IAC3B;IAEA,MAAME,cAAcL,QAAQM,GAAG,CAAC,GAAGP,OAAOQ,YAAY,IAAI,UAAU,MAAM,CAAC;IAE3E,IAAIF,eAAeR,eAAeO,QAAQ,CAACC,cAAuB;QAChE,OAAOA;IACT;IAEA,MAAMG,kBAAkBP,QAAQK,GAAG,CAAC;IAEpC,IAAIE,mBAAmBX,eAAeO,QAAQ,CAACI,kBAAkB;QAC/D,OAAOA;IACT;IAEA,OAAOZ;AACT"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handleAPIRoute.d.ts","sourceRoot":"","sources":["../../src/utilities/handleAPIRoute.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAI9C;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,EACnC,MAAM,EACN,OAAO,GACR,EAAE;IACD,MAAM,EAAE,eAAe,CAAA;IACvB,OAAO,EAAE,OAAO,CAAA;CACjB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAapB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/handleAPIRoute.ts"],"sourcesContent":["import type { SanitizedConfig } from 'payload'\n\nimport { handleEndpoints } from 'payload'\n\n/**\n * Routes a TanStack Start API request (`/api/*`) to Payload's REST/GraphQL\n * endpoint handler. The framework adapter wires this into the `/api/$` route's\n * server handlers, supplying the app's resolved `config`.\n */\nexport async function handleAPIRoute({\n config,\n request,\n}: {\n config: SanitizedConfig\n request: Request\n}): Promise<Response> {\n const url = new URL(request.url)\n const slugParts = url.pathname\n .replace(/^\\/api\\/?/, '')\n .split('/')\n .filter(Boolean)\n const path = slugParts.length ? `/api/${slugParts.join('/')}` : '/api'\n\n return handleEndpoints({\n config,\n path,\n request,\n })\n}\n"],"names":["handleEndpoints","handleAPIRoute","config","request","url","URL","slugParts","pathname","replace","split","filter","Boolean","path","length","join"],"mappings":"AAEA,SAASA,eAAe,QAAQ,UAAS;AAEzC;;;;CAIC,GACD,OAAO,eAAeC,eAAe,EACnCC,MAAM,EACNC,OAAO,EAIR;IACC,MAAMC,MAAM,IAAIC,IAAIF,QAAQC,GAAG;IAC/B,MAAME,YAAYF,IAAIG,QAAQ,CAC3BC,OAAO,CAAC,aAAa,IACrBC,KAAK,CAAC,KACNC,MAAM,CAACC;IACV,MAAMC,OAAON,UAAUO,MAAM,GAAG,CAAC,KAAK,EAAEP,UAAUQ,IAAI,CAAC,MAAM,GAAG;IAEhE,OAAOd,gBAAgB;QACrBE;QACAU;QACAT;IACF;AACF"}
|
package/dist/vite/constants.d.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Vite-level configuration constants used by `payloadPlugin`. Kept separate so
|
|
3
|
-
* `plugin.ts` stays focused on wiring.
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Server-only packages (Node-only or only ever used by the server bundle).
|
|
7
|
-
* These are the Vite equivalent of Next.js's `serverExternalPackages`.
|
|
8
|
-
*/
|
|
9
|
-
export declare const ssrExternalPackages: string[];
|
|
10
|
-
/**
|
|
11
|
-
* Payload packages whose source must be processed by Vite even on the server
|
|
12
|
-
* (because they are workspace `.ts` files in dev). Server-only adapters
|
|
13
|
-
* (`@payloadcms/db-*`, `@payloadcms/email-*`, `@payloadcms/next`, etc.) are
|
|
14
|
-
* intentionally not included — those should stay external on the SSR side.
|
|
15
|
-
*/
|
|
16
|
-
export declare const payloadNoExternalPatterns: Array<RegExp | string>;
|
|
17
|
-
/**
|
|
18
|
-
* The subset of `payloadNoExternalPatterns` that needs to participate in the
|
|
19
|
-
* RSC environment. Plugins and storage adapters must be included: they register
|
|
20
|
-
* custom providers/components (e.g. `plugin-multi-tenant`'s `'use client'`
|
|
21
|
-
* `TenantSelectionProvider`) that render in the RSC graph via
|
|
22
|
-
* `RenderServerComponent`. If the package stays external to RSC, `plugin-rsc`
|
|
23
|
-
* never transforms its `'use client'` modules into client references, so the
|
|
24
|
-
* component executes server-side and crashes on the first hook
|
|
25
|
-
* (`Cannot read properties of null (reading 'useState')`).
|
|
26
|
-
*/
|
|
27
|
-
export declare const payloadRscNoExternalPatterns: Array<RegExp | string>;
|
|
28
|
-
/**
|
|
29
|
-
* Packages we know contain Node-only code or top-level side effects requiring
|
|
30
|
-
* Node APIs. Excluding them from the client optimizer prevents Vite from
|
|
31
|
-
* walking into their main entries and trying to bundle server-only imports
|
|
32
|
-
* for the browser.
|
|
33
|
-
*/
|
|
34
|
-
export declare const optimizeDepsExcludeDefaults: string[];
|
|
35
|
-
/**
|
|
36
|
-
* Transitive dependencies of `@payloadcms/ui` and `payload` that need to be
|
|
37
|
-
* pre-bundled for the client. Vite's auto-discovery doesn't reliably pick
|
|
38
|
-
* these up because their parent packages are in `optimizeDeps.exclude`, so we
|
|
39
|
-
* list them explicitly using the `parent > child` syntax.
|
|
40
|
-
*/
|
|
41
|
-
export declare const optimizeDepsIncludeDefaults: string[];
|
|
42
|
-
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/vite/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,MAAM,EA0BvC,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAO5D,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,4BAA4B,EAAE,KAAK,CAAC,MAAM,GAAG,MAAM,CAO/D,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,EAAE,MAAM,EAsB/C,CAAA;AAED;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,EAAE,MAAM,EA8E/C,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/vite/constants.ts"],"sourcesContent":["/**\n * Vite-level configuration constants used by `payloadPlugin`. Kept separate so\n * `plugin.ts` stays focused on wiring.\n */\n\n/**\n * Server-only packages (Node-only or only ever used by the server bundle).\n * These are the Vite equivalent of Next.js's `serverExternalPackages`.\n */\nexport const ssrExternalPackages: string[] = [\n 'ajv',\n 'fast-uri',\n 'drizzle-kit',\n 'drizzle-kit/api',\n 'drizzle-orm',\n 'sharp',\n 'libsql',\n 'require-in-the-middle',\n 'json-schema-to-typescript',\n 'pino',\n 'pino-pretty',\n 'graphql',\n 'mongodb',\n 'mongoose',\n 'better-sqlite3',\n 'pg',\n 'pg-native',\n 'nodemailer',\n 'aws4',\n 'pluralize',\n 'console-table-printer',\n '@azure/storage-blob',\n '@aws-sdk/client-s3',\n '@aws-sdk/s3-request-presigner',\n '@google-cloud/storage',\n]\n\n/**\n * Payload packages whose source must be processed by Vite even on the server\n * (because they are workspace `.ts` files in dev). Server-only adapters\n * (`@payloadcms/db-*`, `@payloadcms/email-*`, `@payloadcms/next`, etc.) are\n * intentionally not included — those should stay external on the SSR side.\n */\nexport const payloadNoExternalPatterns: Array<RegExp | string> = [\n '@payloadcms/ui',\n '@payloadcms/translations',\n '@payloadcms/tanstack-start',\n /^@payloadcms\\/richtext-lexical/,\n /^@payloadcms\\/plugin-/,\n /^@payloadcms\\/storage-/,\n]\n\n/**\n * The subset of `payloadNoExternalPatterns` that needs to participate in the\n * RSC environment. Plugins and storage adapters must be included: they register\n * custom providers/components (e.g. `plugin-multi-tenant`'s `'use client'`\n * `TenantSelectionProvider`) that render in the RSC graph via\n * `RenderServerComponent`. If the package stays external to RSC, `plugin-rsc`\n * never transforms its `'use client'` modules into client references, so the\n * component executes server-side and crashes on the first hook\n * (`Cannot read properties of null (reading 'useState')`).\n */\nexport const payloadRscNoExternalPatterns: Array<RegExp | string> = [\n '@payloadcms/ui',\n '@payloadcms/translations',\n '@payloadcms/tanstack-start',\n /^@payloadcms\\/richtext-lexical/,\n /^@payloadcms\\/plugin-/,\n /^@payloadcms\\/storage-/,\n]\n\n/**\n * Packages we know contain Node-only code or top-level side effects requiring\n * Node APIs. Excluding them from the client optimizer prevents Vite from\n * walking into their main entries and trying to bundle server-only imports\n * for the browser.\n */\nexport const optimizeDepsExcludeDefaults: string[] = [\n 'sharp',\n '@payloadcms/ui',\n '@payloadcms/tanstack-start',\n 'payload',\n 'pino',\n 'pino-pretty',\n 'busboy',\n 'get-tsconfig',\n 'ws',\n 'croner',\n 'prompts',\n 'file-type',\n // Server-only SDKs used by `@payloadcms/storage-*` adapters. Vite\n // sometimes walks these from the main package entry while scanning\n // workspace deps, and the browser sub-bundles do not expose the\n // server-only APIs (e.g. `BlobSASPermissions`), which crashes the dev\n // server with a `MISSING_EXPORT` error before any test runs.\n '@azure/storage-blob',\n '@aws-sdk/client-s3',\n '@aws-sdk/s3-request-presigner',\n '@google-cloud/storage',\n]\n\n/**\n * Transitive dependencies of `@payloadcms/ui` and `payload` that need to be\n * pre-bundled for the client. Vite's auto-discovery doesn't reliably pick\n * these up because their parent packages are in `optimizeDeps.exclude`, so we\n * list them explicitly using the `parent > child` syntax.\n */\nexport const optimizeDepsIncludeDefaults: string[] = [\n '@payloadcms/ui > sonner',\n '@payloadcms/ui > @faceless-ui/modal',\n '@payloadcms/ui > @faceless-ui/window-info',\n '@payloadcms/ui > @faceless-ui/scroll-info',\n '@payloadcms/ui > @dnd-kit/core',\n '@payloadcms/ui > @dnd-kit/sortable',\n '@payloadcms/ui > @dnd-kit/utilities',\n '@payloadcms/ui > react-datepicker',\n '@payloadcms/ui > react-select',\n '@payloadcms/ui > react-select/creatable',\n '@payloadcms/ui > react-image-crop',\n '@payloadcms/ui > @monaco-editor/react',\n '@payloadcms/ui > date-fns',\n '@payloadcms/ui > date-fns/transpose',\n '@payloadcms/ui > @date-fns/tz/date/mini',\n '@payloadcms/ui > uuid',\n '@payloadcms/ui > use-context-selector',\n '@payloadcms/ui > bson-objectid',\n '@payloadcms/ui > dequal',\n '@payloadcms/ui > object-to-formdata',\n '@payloadcms/ui > md5',\n 'payload > deepmerge',\n 'payload > pluralize',\n // `scheduler` is a transitive dep of `react-dom`, not a direct dependency of\n // the app, so a bare `'scheduler'` specifier fails to resolve from an isolated\n // install (`test/node_modules` built with `pnpm i --ignore-workspace`), where\n // it isn't hoisted to the top level. Path it through `react-dom` so the\n // optimizer resolves the exact copy the runtime loads.\n 'react-dom > scheduler',\n // `@payloadcms/ui` (in `optimizeDeps.exclude`) ships compiled output that the\n // React Compiler rewrote to `import { c } from 'react/compiler-runtime'`.\n // Because its parent is excluded, the optimizer never crawls in to discover\n // this entry, so Vite serves `react/compiler-runtime` raw. That file is\n // CommonJS (`module.exports = require(...)`), so the named `c` export can't be\n // statically extracted and every client component throws \"does not provide an\n // export named 'c'\". Pre-bundling it lets esbuild synthesize the named export.\n 'react/compiler-runtime',\n // Transitive deps that Vite otherwise discovers *after* the initial crawl\n // (react-select pulls in @floating-ui at runtime; react-is is reached via\n // react-transition-group/prop-types; the default date-fns locale is loaded\n // through a dynamic `date-fns/locale/${key}` import). A late discovery forces\n // a full dep re-optimization mid-session, which 404s every in-flight\n // `.vite/deps/*` chunk (\"Pre-transform error: file does not exist in the\n // optimize deps directory\") and breaks the admin UI in CI cold starts.\n // Pre-bundling them keeps the first optimization pass complete.\n '@payloadcms/ui > react-select > @floating-ui/dom',\n '@payloadcms/ui > react-select > @floating-ui/dom > @floating-ui/core',\n '@payloadcms/ui > react-select > prop-types > react-is',\n '@payloadcms/ui > date-fns/locale/en-US',\n // Further late discoveries observed re-optimizing mid-run in CI cold starts\n // (see CI logs: \"✨ new dependencies optimized: @dnd-kit/modifiers / ajv /\n // dequal/lite\"). The modular dashboard pulls in `@dnd-kit/modifiers` on first\n // render; form-state diffing reaches `dequal/lite` (a distinct entry point\n // from the already-listed `dequal`); client-side field validation reaches\n // `ajv` *through `payload`* — it is `ssrExternal` server-side but still\n // bundled into the client, and must be pathed via `payload` so the optimizer\n // pre-bundles the exact copy the runtime loads.\n '@payloadcms/ui > @dnd-kit/modifiers',\n '@payloadcms/ui > dequal/lite',\n 'payload > ajv',\n // The storage client-upload suites (esp. vercel-blob) crawl part of the\n // `payload` server runtime into the client bundle and discover these late,\n // triggering several \"optimized dependencies changed. reloading\" waves that\n // reload the page mid-test (the bulk-upload drawer's Create New button /\n // dropzone vanish and the direct-to-bucket PUT never fires). Pre-bundle the\n // whole observed set so the first pass is complete.\n 'payload > undici',\n 'payload > jose',\n 'payload > dataloader',\n 'payload > path-to-regexp',\n 'payload > console-table-printer',\n 'payload > ci-info',\n 'payload > image-size',\n 'payload > image-size/fromFile',\n 'payload > ipaddr.js',\n 'payload > range-parser',\n 'payload > sanitize-filename',\n]\n"],"names":["ssrExternalPackages","payloadNoExternalPatterns","payloadRscNoExternalPatterns","optimizeDepsExcludeDefaults","optimizeDepsIncludeDefaults"],"mappings":"AAAA;;;CAGC,GAED;;;CAGC,GACD,OAAO,MAAMA,sBAAgC;IAC3C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAED;;;;;CAKC,GACD,OAAO,MAAMC,4BAAoD;IAC/D;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAED;;;;;;;;;CASC,GACD,OAAO,MAAMC,+BAAuD;IAClE;IACA;IACA;IACA;IACA;IACA;CACD,CAAA;AAED;;;;;CAKC,GACD,OAAO,MAAMC,8BAAwC;IACnD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,kEAAkE;IAClE,mEAAmE;IACnE,gEAAgE;IAChE,sEAAsE;IACtE,6DAA6D;IAC7D;IACA;IACA;IACA;CACD,CAAA;AAED;;;;;CAKC,GACD,OAAO,MAAMC,8BAAwC;IACnD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,6EAA6E;IAC7E,+EAA+E;IAC/E,8EAA8E;IAC9E,wEAAwE;IACxE,uDAAuD;IACvD;IACA,8EAA8E;IAC9E,0EAA0E;IAC1E,4EAA4E;IAC5E,wEAAwE;IACxE,+EAA+E;IAC/E,8EAA8E;IAC9E,+EAA+E;IAC/E;IACA,0EAA0E;IAC1E,0EAA0E;IAC1E,2EAA2E;IAC3E,8EAA8E;IAC9E,qEAAqE;IACrE,yEAAyE;IACzE,uEAAuE;IACvE,gEAAgE;IAChE;IACA;IACA;IACA;IACA,4EAA4E;IAC5E,0EAA0E;IAC1E,8EAA8E;IAC9E,2EAA2E;IAC3E,0EAA0E;IAC1E,wEAAwE;IACxE,6EAA6E;IAC7E,gDAAgD;IAChD;IACA;IACA;IACA,wEAAwE;IACxE,2EAA2E;IAC3E,4EAA4E;IAC5E,yEAAyE;IACzE,4EAA4E;IAC5E,oDAAoD;IACpD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAA"}
|
package/dist/vite/plugin.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { PluginOption, UserConfigFnObject } from 'vite';
|
|
2
|
-
export interface PayloadPluginOptions {
|
|
3
|
-
/** Additional resolve aliases */
|
|
4
|
-
additionalAliases?: Array<{
|
|
5
|
-
find: RegExp | string;
|
|
6
|
-
replacement: string;
|
|
7
|
-
}>;
|
|
8
|
-
/** Additional import protection ignoreImporters patterns */
|
|
9
|
-
additionalIgnoreImporters?: RegExp[];
|
|
10
|
-
/** Extra optimizeDeps.include entries */
|
|
11
|
-
additionalOptimizeDepsInclude?: string[];
|
|
12
|
-
/** Extra ssr.external entries */
|
|
13
|
-
additionalSsrExternal?: string[];
|
|
14
|
-
/** Path to the user's payload.config.ts (required) */
|
|
15
|
-
payloadConfigPath: string;
|
|
16
|
-
/** Extra Vite plugins to include */
|
|
17
|
-
plugins?: PluginOption[];
|
|
18
|
-
/** @vitejs/plugin-react instance — must be passed by consumer to ensure correct resolution */
|
|
19
|
-
reactPlugin: PluginOption;
|
|
20
|
-
/** TanStack router routes directory relative to srcDirectory. Defaults to 'app' */
|
|
21
|
-
routesDirectory?: string;
|
|
22
|
-
/** @vitejs/plugin-rsc instance — required for RSC support, must be passed by consumer */
|
|
23
|
-
rscPlugin: PluginOption;
|
|
24
|
-
/** TanStack source directory. Defaults to 'src' */
|
|
25
|
-
srcDirectory?: string;
|
|
26
|
-
/** tanstackStart from '@tanstack/react-start/plugin/vite' — must be passed by consumer to ensure correct resolution */
|
|
27
|
-
tanstackStart: typeof import('@tanstack/react-start/plugin/vite').tanstackStart;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Vite plugin for Payload + TanStack Start. The Vite-side counterpart to
|
|
31
|
-
* `withPayload` for Next.js: it configures the Vite environment so the Payload
|
|
32
|
-
* admin can run, then composes the TanStack Start plugin with two small
|
|
33
|
-
* Payload-specific workarounds (dev HMR injection, SSR style stripping). Each
|
|
34
|
-
* remaining workaround lives in its own file under `./plugins/` so it can be
|
|
35
|
-
* deleted individually once the corresponding upstream fix lands.
|
|
36
|
-
*/
|
|
37
|
-
export declare function payloadPlugin(options: PayloadPluginOptions): UserConfigFnObject;
|
|
38
|
-
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/vite/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,MAAM,CAAA;AAsB5D,MAAM,WAAW,oBAAoB;IACnC,iCAAiC;IACjC,iBAAiB,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACzE,4DAA4D;IAC5D,yBAAyB,CAAC,EAAE,MAAM,EAAE,CAAA;IACpC,yCAAyC;IACzC,6BAA6B,CAAC,EAAE,MAAM,EAAE,CAAA;IACxC,iCAAiC;IACjC,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAA;IAChC,sDAAsD;IACtD,iBAAiB,EAAE,MAAM,CAAA;IACzB,oCAAoC;IACpC,OAAO,CAAC,EAAE,YAAY,EAAE,CAAA;IACxB,8FAA8F;IAC9F,WAAW,EAAE,YAAY,CAAA;IACzB,mFAAmF;IACnF,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,yFAAyF;IACzF,SAAS,EAAE,YAAY,CAAA;IACvB,mDAAmD;IACnD,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,uHAAuH;IACvH,aAAa,EAAE,cAAc,mCAAmC,EAAE,aAAa,CAAA;CAChF;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,kBAAkB,CA+H/E"}
|
package/dist/vite/plugin.js
DELETED
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import path from 'node:path';
|
|
2
|
-
import { optimizeDepsExcludeDefaults, optimizeDepsIncludeDefaults, payloadNoExternalPatterns, payloadRscNoExternalPatterns, ssrExternalPackages } from './constants.js';
|
|
3
|
-
import { defaultImportProtectionIgnoreImporters, onImportProtectionViolation, serverOnlyClientSpecifiers } from './importProtection.js';
|
|
4
|
-
import { clientModuleResolution } from './plugins/clientModuleResolution.js';
|
|
5
|
-
import { payloadDevTransforms } from './plugins/devTransforms.js';
|
|
6
|
-
import { reactDomServerInRsc } from './plugins/reactDomServerInRsc.js';
|
|
7
|
-
import { ssrStripDistStyleImports } from './plugins/stripDistStyleImports.js';
|
|
8
|
-
import { wrapCjsForClient } from './plugins/wrapCjsForClient.js';
|
|
9
|
-
/**
|
|
10
|
-
* Vite plugin for Payload + TanStack Start. The Vite-side counterpart to
|
|
11
|
-
* `withPayload` for Next.js: it configures the Vite environment so the Payload
|
|
12
|
-
* admin can run, then composes the TanStack Start plugin with two small
|
|
13
|
-
* Payload-specific workarounds (dev HMR injection, SSR style stripping). Each
|
|
14
|
-
* remaining workaround lives in its own file under `./plugins/` so it can be
|
|
15
|
-
* deleted individually once the corresponding upstream fix lands.
|
|
16
|
-
*/ export function payloadPlugin(options) {
|
|
17
|
-
const { additionalAliases = [], additionalIgnoreImporters = [], additionalOptimizeDepsInclude = [], additionalSsrExternal = [], payloadConfigPath, plugins: extraPlugins = [], reactPlugin, routesDirectory = 'app', rscPlugin, srcDirectory = 'src', tanstackStart } = options;
|
|
18
|
-
return (_env)=>({
|
|
19
|
-
css: {
|
|
20
|
-
preprocessorOptions: {
|
|
21
|
-
scss: {
|
|
22
|
-
silenceDeprecations: [
|
|
23
|
-
'import',
|
|
24
|
-
'global-builtin'
|
|
25
|
-
]
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
},
|
|
29
|
-
define: {
|
|
30
|
-
global: 'globalThis'
|
|
31
|
-
},
|
|
32
|
-
environments: {
|
|
33
|
-
rsc: {
|
|
34
|
-
resolve: {
|
|
35
|
-
noExternal: payloadRscNoExternalPatterns
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
ssr: {
|
|
39
|
-
resolve: {
|
|
40
|
-
noExternal: payloadNoExternalPatterns
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
},
|
|
44
|
-
optimizeDeps: {
|
|
45
|
-
exclude: optimizeDepsExcludeDefaults,
|
|
46
|
-
include: [
|
|
47
|
-
...optimizeDepsIncludeDefaults,
|
|
48
|
-
...additionalOptimizeDepsInclude
|
|
49
|
-
]
|
|
50
|
-
},
|
|
51
|
-
plugins: [
|
|
52
|
-
clientModuleResolution(),
|
|
53
|
-
wrapCjsForClient(),
|
|
54
|
-
ssrStripDistStyleImports(),
|
|
55
|
-
reactDomServerInRsc(),
|
|
56
|
-
payloadDevTransforms(),
|
|
57
|
-
rscPlugin,
|
|
58
|
-
tanstackStart({
|
|
59
|
-
importProtection: {
|
|
60
|
-
client: {
|
|
61
|
-
excludeFiles: [],
|
|
62
|
-
specifiers: serverOnlyClientSpecifiers
|
|
63
|
-
},
|
|
64
|
-
ignoreImporters: [
|
|
65
|
-
...defaultImportProtectionIgnoreImporters,
|
|
66
|
-
...additionalIgnoreImporters
|
|
67
|
-
],
|
|
68
|
-
include: [
|
|
69
|
-
'**/*'
|
|
70
|
-
],
|
|
71
|
-
mockAccess: 'warn',
|
|
72
|
-
onViolation: onImportProtectionViolation,
|
|
73
|
-
// Disable TanStack Start's default `**/*.client.*` file-based denial in
|
|
74
|
-
// the SSR environment. Payload uses the `.client.tsx` filename suffix
|
|
75
|
-
// for React Client Components (with a `'use client'` directive) that
|
|
76
|
-
// MUST be server-rendered to HTML during SSR. The default rule would
|
|
77
|
-
// otherwise replace those files with an `import-protection mock` Proxy
|
|
78
|
-
// during SSR, which crashes React (TypeError: Cannot convert object to
|
|
79
|
-
// primitive value) the moment React tries to format a warning that
|
|
80
|
-
// mentions one of these components.
|
|
81
|
-
server: {
|
|
82
|
-
files: []
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
|
-
// Disable TanStack Router's automatic per-route code-splitting.
|
|
86
|
-
//
|
|
87
|
-
// With splitting enabled each route's `component` is fetched lazily
|
|
88
|
-
// via `?tsr-split=component` after the initial SSR HTML is streamed.
|
|
89
|
-
// Until that lazy chunk lands the rendered admin tree has no client
|
|
90
|
-
// React attached, so any button clicks (e.g. the
|
|
91
|
-
// `#toggle-list-filters` chevron in `<ListControls />`) hit a static
|
|
92
|
-
// DOM, the click is dropped, and once the chunk finally loads the
|
|
93
|
-
// component re-mounts with its initial `useState` instead of the
|
|
94
|
-
// toggled value. That single behaviour was the root cause of the
|
|
95
|
-
// "page renders but nothing is interactive" tanstack-start E2E
|
|
96
|
-
// failures (`#list-controls-where`, `[data-lexical-editor]`, etc.) -
|
|
97
|
-
// playwright traces show "Download the React DevTools" landing
|
|
98
|
-
// *after* the playwright click, confirming late hydration.
|
|
99
|
-
//
|
|
100
|
-
// We pass BOTH knobs because `tanstackStart`'s schema silently
|
|
101
|
-
// strips the user-supplied `autoCodeSplitting` (its `tsrConfig`
|
|
102
|
-
// does `configSchema.omit({ autoCodeSplitting: true, target: true
|
|
103
|
-
// })`) and then leaves the value `undefined` — which is fine for
|
|
104
|
-
// the conditional inside `unpluginRouterComposedFactory`, but the
|
|
105
|
-
// TanStack Start vite plugin *unconditionally* installs the router
|
|
106
|
-
// code-splitter via `tanStackRouterCodeSplitter(...)` regardless.
|
|
107
|
-
// The only knob that survives all of that and is honoured by the
|
|
108
|
-
// splitter is `router.codeSplittingOptions.defaultBehavior` — set
|
|
109
|
-
// to an empty array, the splitter still walks each `createFileRoute`
|
|
110
|
-
// file but produces no virtual `?tsr-split=...` modules, so every
|
|
111
|
-
// route component ships in the initial bundle and hydration starts
|
|
112
|
-
// immediately on first paint. We keep `autoCodeSplitting: false` as
|
|
113
|
-
// a belt-and-braces signal in case the start plugin ever stops
|
|
114
|
-
// dropping it.
|
|
115
|
-
//
|
|
116
|
-
// Eager-loading routes ships a slightly larger initial bundle but
|
|
117
|
-
// makes the admin actually interactive on first paint.
|
|
118
|
-
router: {
|
|
119
|
-
autoCodeSplitting: false,
|
|
120
|
-
codeSplittingOptions: {
|
|
121
|
-
defaultBehavior: []
|
|
122
|
-
},
|
|
123
|
-
// Exclude generated importMap files and colocated server-function
|
|
124
|
-
// modules (`*.functions.ts`). Admin form saves are dispatched via
|
|
125
|
-
// `runPayloadServerFn` (a TanStack Start `createServerFn`) rather than
|
|
126
|
-
// a hand-rolled route, so there is no longer an `api.server-function.ts`
|
|
127
|
-
// to special-case here. The `*.functions.ts` shims live next to the
|
|
128
|
-
// routes that use them (e.g. `app/_payload/*.functions.ts`); they
|
|
129
|
-
// define `createServerFn`s, not routes, so they must not be scanned.
|
|
130
|
-
routeFileIgnorePattern: 'importMap\\.(?:js|server\\.ts)$|\\.functions\\.',
|
|
131
|
-
routesDirectory
|
|
132
|
-
},
|
|
133
|
-
rsc: {
|
|
134
|
-
enabled: true
|
|
135
|
-
},
|
|
136
|
-
srcDirectory
|
|
137
|
-
}),
|
|
138
|
-
reactPlugin,
|
|
139
|
-
...extraPlugins
|
|
140
|
-
],
|
|
141
|
-
resolve: {
|
|
142
|
-
alias: [
|
|
143
|
-
{
|
|
144
|
-
find: '@payload-config',
|
|
145
|
-
replacement: path.resolve(payloadConfigPath)
|
|
146
|
-
},
|
|
147
|
-
...additionalAliases
|
|
148
|
-
],
|
|
149
|
-
dedupe: [
|
|
150
|
-
'react',
|
|
151
|
-
'react-dom',
|
|
152
|
-
'scheduler',
|
|
153
|
-
'@payloadcms/ui',
|
|
154
|
-
'@payloadcms/richtext-lexical'
|
|
155
|
-
],
|
|
156
|
-
extensions: [
|
|
157
|
-
'.mjs',
|
|
158
|
-
'.js',
|
|
159
|
-
'.mts',
|
|
160
|
-
'.ts',
|
|
161
|
-
'.jsx',
|
|
162
|
-
'.tsx',
|
|
163
|
-
'.json'
|
|
164
|
-
],
|
|
165
|
-
tsconfigPaths: true
|
|
166
|
-
},
|
|
167
|
-
ssr: {
|
|
168
|
-
external: [
|
|
169
|
-
...ssrExternalPackages,
|
|
170
|
-
...additionalSsrExternal
|
|
171
|
-
],
|
|
172
|
-
noExternal: payloadNoExternalPatterns
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
//# sourceMappingURL=plugin.js.map
|
package/dist/vite/plugin.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/vite/plugin.ts"],"sourcesContent":["import type { PluginOption, UserConfigFnObject } from 'vite'\n\nimport path from 'node:path'\n\nimport {\n optimizeDepsExcludeDefaults,\n optimizeDepsIncludeDefaults,\n payloadNoExternalPatterns,\n payloadRscNoExternalPatterns,\n ssrExternalPackages,\n} from './constants.js'\nimport {\n defaultImportProtectionIgnoreImporters,\n onImportProtectionViolation,\n serverOnlyClientSpecifiers,\n} from './importProtection.js'\nimport { clientModuleResolution } from './plugins/clientModuleResolution.js'\nimport { payloadDevTransforms } from './plugins/devTransforms.js'\nimport { reactDomServerInRsc } from './plugins/reactDomServerInRsc.js'\nimport { ssrStripDistStyleImports } from './plugins/stripDistStyleImports.js'\nimport { wrapCjsForClient } from './plugins/wrapCjsForClient.js'\n\nexport interface PayloadPluginOptions {\n /** Additional resolve aliases */\n additionalAliases?: Array<{ find: RegExp | string; replacement: string }>\n /** Additional import protection ignoreImporters patterns */\n additionalIgnoreImporters?: RegExp[]\n /** Extra optimizeDeps.include entries */\n additionalOptimizeDepsInclude?: string[]\n /** Extra ssr.external entries */\n additionalSsrExternal?: string[]\n /** Path to the user's payload.config.ts (required) */\n payloadConfigPath: string\n /** Extra Vite plugins to include */\n plugins?: PluginOption[]\n /** @vitejs/plugin-react instance — must be passed by consumer to ensure correct resolution */\n reactPlugin: PluginOption\n /** TanStack router routes directory relative to srcDirectory. Defaults to 'app' */\n routesDirectory?: string\n /** @vitejs/plugin-rsc instance — required for RSC support, must be passed by consumer */\n rscPlugin: PluginOption\n /** TanStack source directory. Defaults to 'src' */\n srcDirectory?: string\n /** tanstackStart from '@tanstack/react-start/plugin/vite' — must be passed by consumer to ensure correct resolution */\n tanstackStart: typeof import('@tanstack/react-start/plugin/vite').tanstackStart\n}\n\n/**\n * Vite plugin for Payload + TanStack Start. The Vite-side counterpart to\n * `withPayload` for Next.js: it configures the Vite environment so the Payload\n * admin can run, then composes the TanStack Start plugin with two small\n * Payload-specific workarounds (dev HMR injection, SSR style stripping). Each\n * remaining workaround lives in its own file under `./plugins/` so it can be\n * deleted individually once the corresponding upstream fix lands.\n */\nexport function payloadPlugin(options: PayloadPluginOptions): UserConfigFnObject {\n const {\n additionalAliases = [],\n additionalIgnoreImporters = [],\n additionalOptimizeDepsInclude = [],\n additionalSsrExternal = [],\n payloadConfigPath,\n plugins: extraPlugins = [],\n reactPlugin,\n routesDirectory = 'app',\n rscPlugin,\n srcDirectory = 'src',\n tanstackStart,\n } = options\n\n return (_env) => ({\n css: {\n preprocessorOptions: {\n scss: {\n silenceDeprecations: ['import', 'global-builtin'],\n } as any,\n },\n },\n define: {\n global: 'globalThis',\n },\n environments: {\n rsc: { resolve: { noExternal: payloadRscNoExternalPatterns } },\n ssr: { resolve: { noExternal: payloadNoExternalPatterns } },\n } as any,\n optimizeDeps: {\n exclude: optimizeDepsExcludeDefaults,\n include: [...optimizeDepsIncludeDefaults, ...additionalOptimizeDepsInclude],\n },\n plugins: [\n clientModuleResolution(),\n wrapCjsForClient(),\n ssrStripDistStyleImports(),\n reactDomServerInRsc(),\n payloadDevTransforms(),\n rscPlugin,\n tanstackStart({\n importProtection: {\n client: { excludeFiles: [], specifiers: serverOnlyClientSpecifiers },\n ignoreImporters: [\n ...defaultImportProtectionIgnoreImporters,\n ...additionalIgnoreImporters,\n ],\n include: ['**/*'],\n mockAccess: 'warn',\n onViolation: onImportProtectionViolation,\n // Disable TanStack Start's default `**/*.client.*` file-based denial in\n // the SSR environment. Payload uses the `.client.tsx` filename suffix\n // for React Client Components (with a `'use client'` directive) that\n // MUST be server-rendered to HTML during SSR. The default rule would\n // otherwise replace those files with an `import-protection mock` Proxy\n // during SSR, which crashes React (TypeError: Cannot convert object to\n // primitive value) the moment React tries to format a warning that\n // mentions one of these components.\n server: { files: [] },\n },\n // Disable TanStack Router's automatic per-route code-splitting.\n //\n // With splitting enabled each route's `component` is fetched lazily\n // via `?tsr-split=component` after the initial SSR HTML is streamed.\n // Until that lazy chunk lands the rendered admin tree has no client\n // React attached, so any button clicks (e.g. the\n // `#toggle-list-filters` chevron in `<ListControls />`) hit a static\n // DOM, the click is dropped, and once the chunk finally loads the\n // component re-mounts with its initial `useState` instead of the\n // toggled value. That single behaviour was the root cause of the\n // \"page renders but nothing is interactive\" tanstack-start E2E\n // failures (`#list-controls-where`, `[data-lexical-editor]`, etc.) -\n // playwright traces show \"Download the React DevTools\" landing\n // *after* the playwright click, confirming late hydration.\n //\n // We pass BOTH knobs because `tanstackStart`'s schema silently\n // strips the user-supplied `autoCodeSplitting` (its `tsrConfig`\n // does `configSchema.omit({ autoCodeSplitting: true, target: true\n // })`) and then leaves the value `undefined` — which is fine for\n // the conditional inside `unpluginRouterComposedFactory`, but the\n // TanStack Start vite plugin *unconditionally* installs the router\n // code-splitter via `tanStackRouterCodeSplitter(...)` regardless.\n // The only knob that survives all of that and is honoured by the\n // splitter is `router.codeSplittingOptions.defaultBehavior` — set\n // to an empty array, the splitter still walks each `createFileRoute`\n // file but produces no virtual `?tsr-split=...` modules, so every\n // route component ships in the initial bundle and hydration starts\n // immediately on first paint. We keep `autoCodeSplitting: false` as\n // a belt-and-braces signal in case the start plugin ever stops\n // dropping it.\n //\n // Eager-loading routes ships a slightly larger initial bundle but\n // makes the admin actually interactive on first paint.\n router: {\n autoCodeSplitting: false,\n codeSplittingOptions: { defaultBehavior: [] },\n // Exclude generated importMap files and colocated server-function\n // modules (`*.functions.ts`). Admin form saves are dispatched via\n // `runPayloadServerFn` (a TanStack Start `createServerFn`) rather than\n // a hand-rolled route, so there is no longer an `api.server-function.ts`\n // to special-case here. The `*.functions.ts` shims live next to the\n // routes that use them (e.g. `app/_payload/*.functions.ts`); they\n // define `createServerFn`s, not routes, so they must not be scanned.\n routeFileIgnorePattern: 'importMap\\\\.(?:js|server\\\\.ts)$|\\\\.functions\\\\.',\n routesDirectory,\n } as any,\n rsc: { enabled: true },\n srcDirectory,\n }),\n reactPlugin,\n ...extraPlugins,\n ],\n resolve: {\n alias: [\n { find: '@payload-config', replacement: path.resolve(payloadConfigPath) },\n ...additionalAliases,\n ],\n dedupe: ['react', 'react-dom', 'scheduler', '@payloadcms/ui', '@payloadcms/richtext-lexical'],\n extensions: ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json'],\n tsconfigPaths: true,\n } as any,\n ssr: {\n external: [...ssrExternalPackages, ...additionalSsrExternal],\n noExternal: payloadNoExternalPatterns,\n },\n })\n}\n"],"names":["path","optimizeDepsExcludeDefaults","optimizeDepsIncludeDefaults","payloadNoExternalPatterns","payloadRscNoExternalPatterns","ssrExternalPackages","defaultImportProtectionIgnoreImporters","onImportProtectionViolation","serverOnlyClientSpecifiers","clientModuleResolution","payloadDevTransforms","reactDomServerInRsc","ssrStripDistStyleImports","wrapCjsForClient","payloadPlugin","options","additionalAliases","additionalIgnoreImporters","additionalOptimizeDepsInclude","additionalSsrExternal","payloadConfigPath","plugins","extraPlugins","reactPlugin","routesDirectory","rscPlugin","srcDirectory","tanstackStart","_env","css","preprocessorOptions","scss","silenceDeprecations","define","global","environments","rsc","resolve","noExternal","ssr","optimizeDeps","exclude","include","importProtection","client","excludeFiles","specifiers","ignoreImporters","mockAccess","onViolation","server","files","router","autoCodeSplitting","codeSplittingOptions","defaultBehavior","routeFileIgnorePattern","enabled","alias","find","replacement","dedupe","extensions","tsconfigPaths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FC,YAAY;oBAAC;oBAAQ;oBAAO;oBAAQ;oBAAO;oBAAQ;oBAAQ;iBAAQ;gBACnEC,eAAe;YACjB;YACAxB,KAAK;gBACHyB,UAAU;uBAAI3D;uBAAwBc;iBAAsB;gBAC5DmB,YAAYnC;YACd;QACF,CAAA;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"clientModuleResolution.d.ts","sourceRoot":"","sources":["../../../src/vite/plugins/clientModuleResolution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAKxC;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,IAAI,YAAY,CA+ErD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/vite/plugins/clientModuleResolution.ts"],"sourcesContent":["import type { PluginOption } from 'vite'\n\nimport fs from 'node:fs'\nimport path from 'node:path'\n\n/**\n * Client-side module resolution:\n * 1. Stubs RSC modules (`@payloadcms/.../rsc`) with no-op components so the\n * Vite optimizer never tries to bundle their server implementations.\n * 2. Redirects bare `payload` imports made from user code (outside of\n * `node_modules` and our own packages) to `payload/shared`. The main\n * `payload` entry has top-level side effects requiring Node.js APIs.\n * 3. Resolves `/client` subpath exports for `@payloadcms/plugin-*` and\n * `@payloadcms/storage-*` packages when normal Vite resolution fails in\n * monorepo dev (no `dist/` built yet).\n */\nexport function clientModuleResolution(): PluginOption {\n const stubPrefix = '\\0payload:server-stub:'\n\n const serverOnlyPatterns: RegExp[] = [\n /^@payloadcms\\/richtext-lexical\\/rsc$/,\n /^@payloadcms\\/richtext-slate\\/rsc$/,\n /^@payloadcms\\/next\\/rsc$/,\n /^@payloadcms\\/tanstack-start\\/rsc$/,\n ]\n\n const serverOnlyExports: Record<string, string[]> = {\n '@payloadcms/next/rsc': ['CollectionCards', 'HierarchyTypeFieldServer'],\n '@payloadcms/richtext-lexical/rsc': [\n 'RscEntryLexicalCell',\n 'RscEntryLexicalField',\n 'LexicalDiffComponent',\n ],\n '@payloadcms/tanstack-start/rsc': [\n 'CollectionCards',\n 'HierarchyTypeFieldServer',\n 'renderPayloadComponentOnServer',\n ],\n }\n\n return {\n name: 'payload:client-module-resolution',\n enforce: 'pre',\n load(id) {\n if (!id.startsWith(stubPrefix)) {\n return\n }\n const specifier = id.slice(stubPrefix.length)\n const exports = serverOnlyExports[specifier]\n if (exports) {\n return exports.map((name) => `export const ${name} = () => null;`).join('\\n')\n }\n return `export default null;`\n },\n async resolveId(id, importer, options) {\n if (options?.ssr) {\n return\n }\n\n if (serverOnlyPatterns.some((p) => p.test(id))) {\n return stubPrefix + id\n }\n\n if (id === 'payload' && importer && !importer.includes('/node_modules/')) {\n const isPayloadPackage = /\\/packages\\/(?:payload|ui|richtext-|tanstack-start|next)\\//.test(\n importer,\n )\n if (!isPayloadPackage) {\n return this.resolve('payload/shared', importer, { ...options, skipSelf: true })\n }\n }\n\n if (/^@payloadcms\\/(?:plugin|storage)-[^/]+\\/client$/.test(id)) {\n const resolved = await this.resolve(id, importer, { ...options, skipSelf: true })\n if (resolved) {\n return resolved\n }\n const pkgName = id.replace(/\\/client$/, '')\n const pkgResolved = await this.resolve(pkgName, importer, { ...options, skipSelf: true })\n if (pkgResolved) {\n const pkgDir = path.dirname(pkgResolved.id)\n const candidates = [\n path.resolve(pkgDir, 'src', 'exports', 'client.ts'),\n path.resolve(pkgDir, 'src', 'exports', 'client.js'),\n path.resolve(pkgDir, 'dist', 'exports', 'client.js'),\n ]\n for (const candidate of candidates) {\n if (fs.existsSync(candidate)) {\n return candidate\n }\n }\n }\n }\n },\n }\n}\n"],"names":["fs","path","clientModuleResolution","stubPrefix","serverOnlyPatterns","serverOnlyExports","name","enforce","load","id","startsWith","specifier","slice","length","exports","map","join","resolveId","importer","options","ssr","some","p","test","includes","isPayloadPackage","resolve","skipSelf","resolved","pkgName","replace","pkgResolved","pkgDir","dirname","candidates","candidate","existsSync"],"mappings":"AAEA,OAAOA,QAA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AAK;gBAC/E,IAAIC,UAAU;oBACZ,OAAOA;gBACT;gBACA,MAAMC,UAAUpB,GAAGqB,OAAO,CAAC,aAAa;gBACxC,MAAMC,cAAc,MAAM,IAAI,CAACL,OAAO,CAACG,SAASX,UAAU;oBAAE,GAAGC,OAAO;oBAAEQ,UAAU;gBAAK;gBACvF,IAAII,aAAa;oBACf,MAAMC,SAAS/B,KAAKgC,OAAO,CAACF,YAAYtB,EAAE;oBAC1C,MAAMyB,aAAa;wBACjBjC,KAAKyB,OAAO,CAACM,QAAQ,OAAO,WAAW;wBACvC/B,KAAKyB,OAAO,CAACM,QAAQ,OAAO,WAAW;wBACvC/B,KAAKyB,OAAO,CAACM,QAAQ,QAAQ,WAAW;qBACzC;oBACD,KAAK,MAAMG,aAAaD,WAAY;wBAClC,IAAIlC,GAAGoC,UAAU,CAACD,YAAY;4BAC5B,OAAOA;wBACT;oBACF;gBACF;YACF;QACF;IACF;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"devTransforms.d.ts","sourceRoot":"","sources":["../../../src/vite/plugins/devTransforms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,IAAI,YAAY,CA2DnD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/vite/plugins/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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AKZ,QAAQ,CAAC,kBAAkB,CAACa,GAAGb,QAAQ,CAAC,uBAAuB;gBACtE,OAAOY,KAAKL,OAAO,CAAC,qBAAqB;YAC3C;QACF;IACF;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"reactDomServerInRsc.d.ts","sourceRoot":"","sources":["../../../src/vite/plugins/reactDomServerInRsc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAQxC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,mBAAmB,IAAI,YAAY,CAyDlD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/vite/plugins/reactDomServerInRsc.ts"],"sourcesContent":["import type { PluginOption } from 'vite'\n\nimport { createRequire } from 'node:module'\n\nconst require = createRequire(import.meta.url)\n\nconst REACT_DOM_SERVER_RE = /^react-dom\\/server(?:\\.(?:edge|node|browser))?$/\n\n/**\n * Provides a working `react-dom/server` inside the RSC environment.\n *\n * Payload's version-diff converters (`@payloadcms/richtext-lexical`'s\n * `field/Diff/converters/*` and `@payloadcms/ui`'s `Version/RenderFieldsToDiff`)\n * call `renderToStaticMarkup` while rendering a Server Component. In the RSC\n * environment Vite activates the `react-server` export condition, under which\n * every `react-dom/server*` subpath resolves to `server.react-server.js` — a\n * stub that throws `react-dom/server is not supported in React Server\n * Components`. Force-resolving past the condition isn't enough either: the\n * static renderer reads the *client* React internals\n * (`__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE`), which\n * the `react-server` build of `react` doesn't expose.\n *\n * So we pre-bundle a self-contained `react-dom/server` with client React\n * inlined (esbuild, deliberately WITHOUT the `react-server` condition) and\n * redirect `react-dom/server` to it in the RSC graph only. The bundle is fully\n * self-contained, so the RSC environment's `react-server` condition can't\n * reach into it. JSX elements created by the RSC-graph React stay renderable\n * because React identifies elements via a process-global `Symbol.for(...)`.\n *\n * Delete this once `react-dom/server` (or an equivalent static renderer) is\n * usable from the `react-server` condition without a separate bundle.\n */\nexport function reactDomServerInRsc(): PluginOption {\n const RESOLVED_ID = '\\0payload:react-dom-server-rsc'\n let bundledCode: string | undefined\n\n const buildBundle = (): string => {\n if (bundledCode !== undefined) {\n return bundledCode\n }\n // esbuild is always present as a Vite dependency. Typed loosely because it\n // isn't a direct dependency of this package.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const esbuild: any = require('esbuild')\n const result = esbuild.buildSync({\n banner: {\n // The bundled CJS React DOM server build does `require('util')` etc.\n // esbuild's ESM output otherwise emits a stub that throws \"Dynamic\n // require of ... is not supported\" inside Vite's module runner, so wire\n // up a real `require` for Node built-ins.\n js: \"import { createRequire as __pl_cr } from 'node:module';const require = __pl_cr(import.meta.url);\",\n },\n bundle: true,\n // Resolve react/react-dom to their CLIENT builds — NOT the `react-server`\n // condition the RSC environment would otherwise apply.\n conditions: ['node', 'import', 'default'],\n define: { 'process.env.NODE_ENV': JSON.stringify('production') },\n format: 'esm',\n platform: 'node',\n stdin: {\n contents: [\n \"import * as ReactDOMServer from 'react-dom/server'\",\n \"export * from 'react-dom/server'\",\n 'export default ReactDOMServer',\n ].join('\\n'),\n loader: 'js',\n resolveDir: process.cwd(),\n },\n write: false,\n })\n const code = result.outputFiles[0].text as string\n bundledCode = code\n return code\n }\n\n return {\n name: 'payload:react-dom-server-in-rsc',\n enforce: 'pre',\n load(id) {\n if (id === RESOLVED_ID) {\n return buildBundle()\n }\n },\n resolveId(id) {\n if ((this as any).environment?.name === 'rsc' && REACT_DOM_SERVER_RE.test(id)) {\n return RESOLVED_ID\n }\n },\n }\n}\n"],"names":["createRequire","require","url","REACT_DOM_SERVER_RE","reactDomServerInRsc","RESOLVED_ID","bundledCode","buildBundle","undefined","esbuild","result","buildSync","banner","js","bundle","conditions","define","JSON","stringify","format","platform","stdin","contents","join","loader","resolveDir","process","cwd","write","code","outputFiles","text","name","enforce","load","id","resolveId","environment","test"],"mappings":"AAEA,SAASA,aAAa,QAAQ,cAAa;AAE3C,MAAMC,UAAUD,cAAc,YAAYE,GAAG;AAE7C,MAAMC,sBAAsB;AAE5B;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GACD,OAAO,SAASC;IACd,MAAMC,cAAc;IACpB,IAAIC;IAEJ,MAAMC,cAAc;QAClB,IAAID,gBAAgBE,WAAW;YAC7B,OAAOF;QACT;QACA,2EAA2E;QAC3E,6CAA6C;QAC7C,8DAA8D;QAC9D,MAAMG,UAAeR,QAAQ;QAC7B,MAAMS,SAASD,QAAQE,SAAS,CAAC;YAC/BC,QAAQ;gBACN,qEAAqE;gBACrE,mEAAmE;gBACnE,wEAAwE;gBACxE,0CAA0C;gBAC1CC,IAAI;YACN;YACAC,QAAQ;YACR,0EAA0E;YAC1E,uDAAuD;YACvDC,YAAY;gBAAC;gBAAQ;gBAAU;aAAU;YACzCC,QAAQ;gBAAE,wBAAwBC,KAAKC,SAAS,CAAC;YAAc;YAC/DC,QAAQ;YACRC,UAAU;YACVC,OAAO;gBACLC,UAAU;oBACR;oBACA;oBACA;iBACD,CAACC,IAAI,CAAC;gBACPC,QAAQ;gBACRC,YAAYC,QAAQC,GAAG;YACzB;YACAC,OAAO;QACT;QACA,MAAMC,OAAOnB,OAAOoB,WAAW,CAAC,EAAE,CAACC,IAAI;QACvCzB,cAAcuB;QACd,OAAOA;IACT;IAEA,OAAO;QACLG,MAAM;QACNC,SAAS;QACTC,MAAKC,EAAE;YACL,IAAIA,OAAO9B,aAAa;gBACtB,OAAOE;YACT;QACF;QACA6B,WAAUD,EAAE;YACV,IAAI,AAAC,IAAI,CAASE,WAAW,EAAEL,SAAS,SAAS7B,oBAAoBmC,IAAI,CAACH,KAAK;gBAC7E,OAAO9B;YACT;QACF;IACF;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stripDistStyleImports.d.ts","sourceRoot":"","sources":["../../../src/vite/plugins/stripDistStyleImports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAsDxC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,IAAI,YAAY,CAyEvD"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/vite/plugins/stripDistStyleImports.ts"],"sourcesContent":["import type { PluginOption } from 'vite'\n\nconst STYLE_EXTENSION_RE = /\\.(?:s?css|less)$/i\n\n/**\n * Static `import './foo.css'` (or .scss/.less) — top-level only.\n * Captures the entire statement so we can replace it with an empty line.\n *\n * Matches:\n * import './foo.css';\n * import \"../bar.scss\"\n * import './baz.less' ;\n */\nconst STATIC_STYLE_IMPORT_RE = /^[ \\t]*import\\s+['\"][^'\"]+\\.(?:s?css|less)['\"]\\s*(?:;[ \\t]*)?$/gm\n\n/**\n * Monorepo Payload package source, e.g. `…/packages/ui/src/…`. In the\n * core-dev / test setup Payload packages resolve to their workspace `src`\n * (not a published `dist`), so the `dist/` rule below doesn't cover them and\n * their `.css` side-effect imports survive into the SSR/RSC graph.\n */\nconst PAYLOAD_PKG_SRC_RE = /\\/packages\\/[^/]+\\/src\\//\n\n/**\n * The version-diff component trees — matched in either published `dist/` or\n * workspace `src/` form. The `.css` side-effect imports of these must be\n * stripped in the RSC env (the rest of `@payloadcms/ui` must NOT be — see the\n * note in `resolveId`/`transform` below), for two reasons rooted in the same\n * `@vitejs/plugin-rsc` behaviour: it wraps every exported CSS-importing\n * component with an async CSS-collector child\n * (`__vite_rsc_wrap_css__` → `await import('virtual:vite-rsc/css?…')`).\n *\n * 1. Correctness: the diff converters render `CheckIcon` (`icons/*`) and `File`\n * (`graphics/*`) through the SYNCHRONOUS `renderToStaticMarkup` (see\n * `reactDomServerInRsc`). The async wrapper suspends, crashing that render\n * with \"A component suspended while responding to synchronous input\" and\n * taking down the entire field-diffs tree.\n * 2. Performance: the diff view (`views/Version/*` — `RenderFieldsToDiff` and\n * its per-field components, `DiffCollapser`, `SelectComparison`, the\n * `Default` template — plus the `HTMLDiff`/`FieldDiffContainer`/\n * `FieldDiffLabel` elements and lexical's `field/Diff/*`) renders dozens of\n * these wrapped components in the Flight stream. Each async CSS import\n * serializes a round-trip, ballooning the render from ~3s to ~25s and\n * blowing past the e2e waits. Stripping them collapses it back to ~3s.\n *\n * Safe because every one of these components' styles also ship in the global\n * `@payloadcms/ui/scss/app.scss` the admin imports, so dropping the per-module\n * RSC collection here changes nothing visually (verified: diff + Nav stay\n * styled). The admin `Nav` etc. are deliberately excluded — they rely on the\n * RSC collection and a broad strip leaves them unstyled.\n */\nconst DIFF_VIEW_COMPONENT_RE =\n /@payloadcms\\/ui\\/(?:dist|src)\\/(?:icons|graphics|views\\/Version|elements\\/(?:HTMLDiff|FieldDiffContainer|FieldDiffLabel))\\/|@payloadcms\\/richtext-lexical\\/(?:dist|src)\\/field\\/Diff\\//\n\n/**\n * Stops Vite (and the underlying Node ESM loader) from trying to load\n * SCSS/CSS/LESS during SSR/RSC when the importer lives inside a built\n * `dist/` directory or when the specifier is a bare package name.\n *\n * We do this two ways, because either layer can fail:\n *\n * 1. `resolveId` redirects style specifiers to a virtual empty module —\n * handles cases where Vite asks us to resolve them.\n * 2. `transform` strips top-level `import './x.css'` statements out of any\n * JS/TS file living under `node_modules/.../dist/` for non-client envs.\n * This is the bulletproof path for prod-packed `@payloadcms/ui` (and\n * similar) dependencies that get pre-bundled by Vite's SSR/RSC dep\n * optimizer (esbuild). Esbuild preserves `.css` import statements as-is,\n * and Node's native ESM loader then crashes with\n * `Unknown file extension \".css\"`. Removing them at the source avoids\n * that entirely.\n */\nexport function ssrStripDistStyleImports(): PluginOption {\n return {\n name: 'payload:ssr-strip-dist-style-imports',\n enforce: 'pre',\n load(id) {\n if (id === '\\0ssr-empty-style') {\n return ''\n }\n },\n resolveId(id, importer, options) {\n const envName = (this as any).environment?.name as string | undefined\n const isServerEnv = options?.ssr || (envName && envName !== 'client')\n if (!isServerEnv) {\n return\n }\n // Do NOT strip in the RSC environment. Server components (e.g. the admin\n // `Nav`, a non-'use client' component that `import './index.css'`) render\n // in the RSC graph, and `@vitejs/plugin-rsc` must SEE their `.css` imports\n // there to collect them as client stylesheets. Stripping them here means\n // their CSS is never emitted and the admin renders unstyled (broken nav\n // scroll/layout, etc.). The Node-side `.css` no-op is handled by\n // `cssLoader.mjs` (dev) and by Vite's CSS extraction (build), so the\n // crash this plugin guards against does not require touching the RSC env.\n if (envName === 'rsc') {\n return\n }\n if (!STYLE_EXTENSION_RE.test(id)) {\n return\n }\n if (importer && (/\\/dist\\//.test(importer) || PAYLOAD_PKG_SRC_RE.test(importer))) {\n return '\\0ssr-empty-style'\n }\n if (/^@?[a-z]/.test(id) && !id.startsWith('.') && !id.startsWith('/')) {\n return '\\0ssr-empty-style'\n }\n },\n transform(code, id) {\n const envName = (this as any).environment?.name as string | undefined\n const isServerEnv = envName && envName !== 'client'\n if (!isServerEnv) {\n return\n }\n // In the RSC env, only strip from the version-diff component trees (see\n // `DIFF_VIEW_COMPONENT_RE`). Every other server component (the admin\n // `Nav`, etc.) must keep its `.css` import so plugin-rsc can collect it —\n // see the matching note in `resolveId` above.\n if (envName === 'rsc' && !DIFF_VIEW_COMPONENT_RE.test(id)) {\n return\n }\n // Only touch Payload dependency files: published `node_modules/.../dist/`\n // builds, or workspace `…/packages/<pkg>/src/…` sources in the core-dev /\n // test setup. Don't strip from the consumer's own app source — devs may\n // legitimately want SSR-rendered <link>s from their own CSS imports.\n const isPayloadDistFile = /\\/node_modules\\//.test(id) && /\\/dist\\//.test(id)\n const isPayloadSrcFile = PAYLOAD_PKG_SRC_RE.test(id)\n if (!isPayloadDistFile && !isPayloadSrcFile) {\n return\n }\n // Allow a trailing query (`?v=…`, `?t=…`): Vite appends version/timestamp\n // queries to module ids, especially in the RSC graph, so a strict `$`\n // anchor would skip e.g. `icons/Check/index.js?v=83de8543`.\n if (!/\\.[mc]?[jt]sx?(?:$|\\?)/.test(id)) {\n return\n }\n if (!STATIC_STYLE_IMPORT_RE.test(code)) {\n STATIC_STYLE_IMPORT_RE.lastIndex = 0\n return\n }\n STATIC_STYLE_IMPORT_RE.lastIndex = 0\n const stripped = code.replace(STATIC_STYLE_IMPORT_RE, '')\n return { code: stripped, map: null }\n },\n }\n}\n"],"names":["STYLE_EXTENSION_RE","STATIC_STYLE_IMPORT_RE","PAYLOAD_PKG_SRC_RE","DIFF_VIEW_COMPONENT_RE","ssrStripDistStyleImports","name","enforce","load","id","resolveId","importer","options","envName","environment","isServerEnv","ssr","test","startsWith","transform","code","isPayloadDistFile","isPayloadSrcFile","lastIndex","stripped","replace","map"],"mappings":"AAEA,MAAMA,qBAAqB;AAE3B;;;;;;;;CAQC,GACD,MAAMC,yBAAyB;AAE/B;;;;;CAKC,GACD,MAAMC,qBAAqB;AAE3B;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2BC,GACD,MAAMC,yBACJ;AAEF;;;;;;;;;;;;;;;;;CAiBC,GACD,OAAO,SAASC;IACd,OAAO;QACLC,MAAM;QACNC,SAAS;QACTC,MAAKC,EAAE;YACL,IAAIA,OAAO,qBAAqB;gBAC9B,OAAO;YACT;QACF;QACAC,WAAUD,EAAE,EAAEE,QAAQ,EAAEC,OAAO;YAC7B,MAAMC,UAAU,AAAC,IAAI,CAASC,WAAW,EAAER;YAC3C,MAAMS,cAAcH,SAASI,OAAQH,WAAWA,YAAY;YAC5D,IAAI,CAACE,aAAa;gBAChB;YACF;YACA,yEAAyE;YACzE,0EAA0E;YAC1E,2EAA2E;YAC3E,yEAAyE;YACzE,wEAAwE;YACxE,iEAAiE;YACjE,qEAAqE;YACrE,0EAA0E;YAC1E,IAAIF,YAAY,OAAO;gBACrB;YACF;YACA,IAAI,CAACZ,mBAAmBgB,IAAI,CAACR,KAAK;gBAChC;YACF;YACA,IAAIE,YAAa,CAAA,WAAWM,IAAI,CAACN,aAAaR,mBAAmBc,IAAI,CAACN,SAAQ,GAAI;gBAChF,OAAO;YACT;YACA,IAAI,WAAWM,IAAI,CAACR,OAAO,CAACA,GAAGS,UAAU,CAAC,QAAQ,CAACT,GAAGS,UAAU,CAAC,MAAM;gBACrE,OAAO;YACT;QACF;QACAC,WAAUC,IAAI,EAAEX,EAAE;YAChB,MAAMI,UAAU,AAAC,IAAI,CAASC,WAAW,EAAER;YAC3C,MAAMS,cAAcF,WAAWA,YAAY;YAC3C,IAAI,CAACE,aAAa;gBAChB;YACF;YACA,wEAAwE;YACxE,qEAAqE;YACrE,0EAA0E;YAC1E,8CAA8C;YAC9C,IAAIF,YAAY,SAAS,CAACT,uBAAuBa,IAAI,CAACR,KAAK;gBACzD;YACF;YACA,0EAA0E;YAC1E,0EAA0E;YAC1E,wEAAwE;YACxE,qEAAqE;YACrE,MAAMY,oBAAoB,mBAAmBJ,IAAI,CAACR,OAAO,WAAWQ,IAAI,CAACR;YACzE,MAAMa,mBAAmBnB,mBAAmBc,IAAI,CAACR;YACjD,IAAI,CAACY,qBAAqB,CAACC,kBAAkB;gBAC3C;YACF;YACA,0EAA0E;YAC1E,sEAAsE;YACtE,4DAA4D;YAC5D,IAAI,CAAC,yBAAyBL,IAAI,CAACR,KAAK;gBACtC;YACF;YACA,IAAI,CAACP,uBAAuBe,IAAI,CAACG,OAAO;gBACtClB,uBAAuBqB,SAAS,GAAG;gBACnC;YACF;YACArB,uBAAuBqB,SAAS,GAAG;YACnC,MAAMC,WAAWJ,KAAKK,OAAO,CAACvB,wBAAwB;YACtD,OAAO;gBAAEkB,MAAMI;gBAAUE,KAAK;YAAK;QACrC;IACF;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wrapCjsForClient.d.ts","sourceRoot":"","sources":["../../../src/vite/plugins/wrapCjsForClient.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC;;;;;;;;;;;GAWG;AACH,wBAAgB,gBAAgB,IAAI,YAAY,CAqE/C"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/vite/plugins/wrapCjsForClient.ts"],"sourcesContent":["import type { PluginOption } from 'vite'\n\n/**\n * Wraps CJS `node_modules` files in ESM-compatible code when served to the\n * client.\n *\n * Packages in `optimizeDeps.exclude` (like `payload`, `@payloadcms/ui`) import\n * CJS dependencies that Vite serves via raw `/@fs/` URLs, bypassing\n * pre-bundling. The browser fails to parse them because they use\n * `module.exports` / `exports.X` syntax.\n *\n * This plugin detects CJS patterns in the transform phase and wraps them with\n * a CommonJS-like runtime shim so the browser can execute them as ESM.\n */\nexport function wrapCjsForClient(): PluginOption {\n return {\n name: 'payload:wrap-cjs-client',\n apply: 'serve',\n enforce: 'post',\n transform(code, id, options) {\n if (options?.ssr) {\n return\n }\n\n if (!id.includes('/node_modules/') || id.includes('/node_modules/.vite/')) {\n return\n }\n\n const cleanId = id.replace(/\\?.*$/, '')\n if (!cleanId.endsWith('.js') && !cleanId.endsWith('.cjs')) {\n return\n }\n\n if (code.includes('import ') || code.includes('export ')) {\n return\n }\n\n if (\n !code.includes('module.exports') &&\n !code.includes('exports.') &&\n !code.includes('Object.defineProperty(exports')\n ) {\n return\n }\n\n const namedExports = extractCjsExports(code)\n const names = Object.keys(namedExports)\n\n const declaredIdentifiers = extractDeclaredIdentifiers(code)\n const safeNames = names.filter((name) => !declaredIdentifiers.has(name))\n\n // If the module already declares its own top-level `require` (rare but\n // possible for hand-written CJS), skip injecting our stub so we don't\n // produce a `SyntaxError: Identifier 'require' has already been declared`.\n const injectRequireStub = !declaredIdentifiers.has('require')\n\n const wrapped = [\n `var module = { exports: {} };`,\n `var exports = module.exports;`,\n // Expose a `require` stub so UMD wrappers that gate their CJS branch on\n // `typeof require === 'function'` (e.g. pluralize) take that branch and\n // assign to our `module.exports` instead of falling through to the\n // browser-globals branch (`root.foo = ...`), which throws in strict ESM\n // because the IIFE receives `this === undefined`.\n // The stub throws on actual invocation so any module that *really* needs\n // require fails loudly instead of silently misbehaving.\n injectRequireStub\n ? `var require = function require() { throw new Error(\"require() is not available in the browser bundle\"); };`\n : ``,\n ``,\n code,\n ``,\n `var __cjs_result__ = module.exports;`,\n `export default __cjs_result__;`,\n ...safeNames.map(\n (name) =>\n `export var ${name} = typeof __cjs_result__ === 'object' && __cjs_result__ !== null ? __cjs_result__[\"${name}\"] : undefined;`,\n ),\n ].join('\\n')\n\n return { code: wrapped, map: null }\n },\n }\n}\n\nfunction extractCjsExports(code: string): Record<string, true> {\n const found: Record<string, true> = {}\n const patterns = [\n /exports\\.(\\w+)\\s*=/g,\n /exports\\[[\"'](\\w+)[\"']\\]\\s*=/g,\n /Object\\.defineProperty\\(exports,\\s*[\"'](\\w+)[\"']/g,\n ]\n for (const re of patterns) {\n let m\n while ((m = re.exec(code)) !== null) {\n const name = m[1]!\n if (name !== '__esModule' && name !== 'default') {\n found[name] = true\n }\n }\n }\n return found\n}\n\n/**\n * Detects top-level identifiers declared with class/function/var/let/const in\n * CJS code. Used to avoid re-declaring them via `export var` in the CJS\n * wrapper, which would cause `SyntaxError: Identifier has already been\n * declared` in strict mode (ESM).\n */\nfunction extractDeclaredIdentifiers(code: string): Set<string> {\n const identifiers = new Set<string>()\n const patterns = [/\\bclass\\s+(\\w+)/g, /\\bfunction\\s+(\\w+)/g, /\\b(?:var|let|const)\\s+(\\w+)/g]\n for (const re of patterns) {\n let m\n while ((m = re.exec(code)) !== null) {\n identifiers.add(m[1]!)\n }\n }\n return identifiers\n}\n"],"names":["wrapCjsForClient","name","apply","enforce","transform","code","id","options","ssr","includes","cleanId","replace","endsWith","namedExports","extractCjsExports","names","Object","keys","declaredIdentifiers","extractDeclaredIdentifiers","safeNames","filter","has","injectRequireStub","wrapped","map","join","found","patterns","re","m","exec","identifiers","Set","add"],"mappings":"AAEA;;;;;;;;;;;CAWC,GACD,OAAO,SAASA;IACd,OAAO;QACLC,MAAM;QACNC,OAAO;QACPC,SAAS;QACTC,WAAUC,IAAI,EAAEC,EAAE,EAAEC,OAAO;YACzB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AK;QACpC;IACF;AACF;AAEA,SAASX,kBAAkBT,IAAY;IACrC,MAAMsB,QAA8B,CAAC;IACrC,MAAMC,WAAW;QACf;QACA;QACA;KACD;IACD,KAAK,MAAMC,MAAMD,SAAU;QACzB,IAAIE;QACJ,MAAO,AAACA,CAAAA,IAAID,GAAGE,IAAI,CAAC1B,KAAI,MAAO,KAAM;YACnC,MAAMJ,OAAO6B,CAAC,CAAC,EAAE;YACjB,IAAI7B,SAAS,gBAAgBA,SAAS,WAAW;gBAC/C0B,KAAK,CAAC1B,KAAK,GAAG;YAChB;QACF;IACF;IACA,OAAO0B;AACT;AAEA;;;;;CAKC,GACD,SAASR,2BAA2Bd,IAAY;IAC9C,MAAM2B,cAAc,IAAIC;IACxB,MAAML,WAAW;QAAC;QAAoB;QAAuB;KAA+B;IAC5F,KAAK,MAAMC,MAAMD,SAAU;QACzB,IAAIE;QACJ,MAAO,AAACA,CAAAA,IAAID,GAAGE,IAAI,CAAC1B,KAAI,MAAO,KAAM;YACnC2B,YAAYE,GAAG,CAACJ,CAAC,CAAC,EAAE;QACtB;IACF;IACA,OAAOE;AACT"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|