@payloadcms/tanstack-start 4.0.0-internal.a0ef1b8 → 4.0.0-internal.a7ca468
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/LICENSE.md +1 -1
- package/dist/auth/login.d.ts +3 -16
- package/dist/auth/login.d.ts.map +1 -1
- package/dist/auth/login.js +6 -46
- package/dist/auth/login.js.map +1 -1
- package/dist/auth/logout.d.ts +2 -5
- package/dist/auth/logout.d.ts.map +1 -1
- package/dist/auth/logout.js +6 -47
- package/dist/auth/logout.js.map +1 -1
- package/dist/auth/refresh.d.ts +2 -4
- package/dist/auth/refresh.d.ts.map +1 -1
- package/dist/auth/refresh.js +6 -49
- package/dist/auth/refresh.js.map +1 -1
- package/dist/elements/RouterAdapter/index.d.ts.map +1 -1
- package/dist/elements/RouterAdapter/index.js +55 -16
- package/dist/elements/RouterAdapter/index.js.map +1 -1
- package/dist/exports/client.d.ts +4 -2
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +4 -2
- package/dist/exports/client.js.map +1 -1
- package/dist/exports/layouts.d.ts +2 -3
- package/dist/exports/layouts.d.ts.map +1 -1
- package/dist/exports/layouts.js +1 -1
- package/dist/exports/layouts.js.map +1 -1
- package/dist/exports/rsc.browser.d.ts +4 -1
- package/dist/exports/rsc.browser.d.ts.map +1 -1
- package/dist/exports/rsc.browser.js +4 -1
- package/dist/exports/rsc.browser.js.map +1 -1
- package/dist/exports/rsc.d.ts +0 -1
- package/dist/exports/rsc.d.ts.map +1 -1
- package/dist/exports/rsc.js +0 -1
- package/dist/exports/rsc.js.map +1 -1
- package/dist/exports/server.d.ts +4 -3
- package/dist/exports/server.d.ts.map +1 -1
- package/dist/exports/server.js +4 -3
- package/dist/exports/server.js.map +1 -1
- package/dist/exports/shared.d.ts +2 -0
- package/dist/exports/shared.d.ts.map +1 -0
- package/dist/exports/shared.js +3 -0
- package/dist/exports/shared.js.map +1 -0
- package/dist/index.d.ts +1 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/dist/layouts/Root/getLayoutData.d.ts +24 -2
- package/dist/layouts/Root/getLayoutData.d.ts.map +1 -1
- package/dist/layouts/Root/getLayoutData.js +43 -1
- package/dist/layouts/Root/getLayoutData.js.map +1 -1
- package/dist/layouts/Root/withPayloadRoot.d.ts +41 -0
- package/dist/layouts/Root/withPayloadRoot.d.ts.map +1 -0
- package/dist/layouts/Root/withPayloadRoot.js +91 -0
- package/dist/layouts/Root/withPayloadRoot.js.map +1 -0
- package/dist/node/cssLoader.d.mts +24 -2
- package/dist/node/cssLoader.d.mts.map +1 -1
- package/dist/routes/adminRoutes.d.ts +113 -0
- package/dist/routes/adminRoutes.d.ts.map +1 -0
- package/dist/routes/adminRoutes.js +102 -0
- package/dist/routes/adminRoutes.js.map +1 -0
- package/dist/routes/apiRoute.d.ts +34 -0
- package/dist/routes/apiRoute.d.ts.map +1 -0
- package/dist/routes/apiRoute.js +43 -0
- package/dist/routes/apiRoute.js.map +1 -0
- package/dist/routes/layoutRoute.d.ts +26 -0
- package/dist/routes/layoutRoute.d.ts.map +1 -0
- package/dist/routes/layoutRoute.js +58 -0
- package/dist/routes/layoutRoute.js.map +1 -0
- package/dist/utilities/devConfigReload.server.d.ts +2 -0
- package/dist/utilities/devConfigReload.server.d.ts.map +1 -0
- package/dist/utilities/devConfigReload.server.js +38 -0
- package/dist/utilities/devConfigReload.server.js.map +1 -0
- package/dist/utilities/devConfigReloadEvent.d.ts +9 -0
- package/dist/utilities/devConfigReloadEvent.d.ts.map +1 -0
- package/dist/utilities/devConfigReloadEvent.js +9 -0
- package/dist/utilities/devConfigReloadEvent.js.map +1 -0
- package/dist/utilities/getRequestLocale.d.ts.map +1 -1
- package/dist/utilities/getRequestLocale.js +1 -2
- package/dist/utilities/getRequestLocale.js.map +1 -1
- package/dist/utilities/graphqlHandler.server.d.ts.map +1 -1
- package/dist/utilities/handleAPIRoute.server.d.ts +11 -0
- package/dist/utilities/handleAPIRoute.server.d.ts.map +1 -0
- package/dist/utilities/handleAPIRoute.server.js +17 -0
- package/dist/utilities/handleAPIRoute.server.js.map +1 -0
- package/dist/utilities/handleServerFunctions.d.ts +1 -19
- package/dist/utilities/handleServerFunctions.d.ts.map +1 -1
- package/dist/utilities/handleServerFunctions.js +8 -56
- package/dist/utilities/handleServerFunctions.js.map +1 -1
- package/dist/utilities/initReq.server.d.ts +1 -0
- package/dist/utilities/initReq.server.d.ts.map +1 -1
- package/dist/utilities/initReq.server.js +3 -0
- package/dist/utilities/initReq.server.js.map +1 -1
- package/dist/utilities/loadAdminPage.d.ts +54 -0
- package/dist/utilities/loadAdminPage.d.ts.map +1 -0
- package/dist/utilities/loadAdminPage.js +231 -0
- package/dist/utilities/loadAdminPage.js.map +1 -0
- package/dist/utilities/loadLayoutData.d.ts +15 -0
- package/dist/utilities/loadLayoutData.d.ts.map +1 -0
- package/dist/utilities/loadLayoutData.js +23 -0
- package/dist/utilities/loadLayoutData.js.map +1 -0
- 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/serializeForRsc.d.ts.map +1 -1
- package/dist/utilities/serializeForRsc.js +17 -0
- package/dist/utilities/serializeForRsc.js.map +1 -1
- package/dist/utilities/serverAdapter.server.d.ts.map +1 -1
- package/dist/utilities/serverFunctionClient.d.ts +29 -0
- package/dist/utilities/serverFunctionClient.d.ts.map +1 -0
- package/dist/utilities/serverFunctionClient.js +109 -0
- package/dist/utilities/serverFunctionClient.js.map +1 -0
- package/dist/withPayload/config/external.d.ts +36 -0
- package/dist/withPayload/config/external.d.ts.map +1 -0
- package/dist/withPayload/config/external.js +82 -0
- package/dist/withPayload/config/external.js.map +1 -0
- package/dist/withPayload/config/optimizeDeps.d.ts +25 -0
- package/dist/withPayload/config/optimizeDeps.d.ts.map +1 -0
- package/dist/withPayload/config/optimizeDeps.js +123 -0
- package/dist/withPayload/config/optimizeDeps.js.map +1 -0
- package/dist/withPayload/config/scss.d.ts +14 -0
- package/dist/withPayload/config/scss.d.ts.map +1 -0
- package/dist/withPayload/config/scss.js +28 -0
- package/dist/withPayload/config/scss.js.map +1 -0
- package/dist/withPayload/devConfigReload.d.ts +14 -0
- package/dist/withPayload/devConfigReload.d.ts.map +1 -0
- package/dist/withPayload/devConfigReload.js +84 -0
- package/dist/withPayload/devConfigReload.js.map +1 -0
- package/dist/withPayload/importProtection.d.ts.map +1 -0
- package/dist/{vite → withPayload}/importProtection.js +2 -2
- package/dist/withPayload/importProtection.js.map +1 -0
- package/dist/withPayload/index.d.ts +99 -0
- package/dist/withPayload/index.d.ts.map +1 -0
- package/dist/withPayload/index.js +281 -0
- package/dist/withPayload/index.js.map +1 -0
- package/dist/withPayload/workarounds/clientModuleResolution.d.ts.map +1 -0
- package/dist/withPayload/workarounds/clientModuleResolution.js.map +1 -0
- package/dist/withPayload/workarounds/devTransforms.d.ts +19 -0
- package/dist/withPayload/workarounds/devTransforms.d.ts.map +1 -0
- package/dist/{vite/plugins → withPayload/workarounds}/devTransforms.js +18 -2
- package/dist/withPayload/workarounds/devTransforms.js.map +1 -0
- package/dist/withPayload/workarounds/reactDomServerInRsc.d.ts.map +1 -0
- package/dist/withPayload/workarounds/reactDomServerInRsc.js.map +1 -0
- package/dist/withPayload/workarounds/stripDistStyleImports.d.ts.map +1 -0
- package/dist/withPayload/workarounds/stripDistStyleImports.js +140 -0
- package/dist/withPayload/workarounds/stripDistStyleImports.js.map +1 -0
- package/dist/withPayload/workarounds/stubPrettierInClient.d.ts +13 -0
- package/dist/withPayload/workarounds/stubPrettierInClient.d.ts.map +1 -0
- package/dist/withPayload/workarounds/stubPrettierInClient.js +32 -0
- package/dist/withPayload/workarounds/stubPrettierInClient.js.map +1 -0
- package/dist/withPayload/workarounds/wrapCjsForClient.d.ts.map +1 -0
- package/dist/withPayload/workarounds/wrapCjsForClient.js.map +1 -0
- package/package.json +17 -12
- package/dist/@types/assets.d.js +0 -2
- package/dist/@types/assets.d.js.map +0 -1
- package/dist/auth/switchLanguage.d.ts +0 -6
- package/dist/auth/switchLanguage.d.ts.map +0 -1
- package/dist/auth/switchLanguage.js +0 -11
- package/dist/auth/switchLanguage.js.map +0 -1
- package/dist/elements/DocumentHeaderClient/index.d.ts +0 -16
- package/dist/elements/DocumentHeaderClient/index.d.ts.map +0 -1
- package/dist/elements/DocumentHeaderClient/index.js +0 -116
- package/dist/elements/DocumentHeaderClient/index.js.map +0 -1
- package/dist/elements/RenderComponent/index.d.ts +0 -10
- package/dist/elements/RenderComponent/index.d.ts.map +0 -1
- package/dist/elements/RenderComponent/index.js +0 -12
- package/dist/elements/RenderComponent/index.js.map +0 -1
- package/dist/exports/vite.d.ts +0 -3
- package/dist/exports/vite.d.ts.map +0 -1
- package/dist/exports/vite.js +0 -3
- package/dist/exports/vite.js.map +0 -1
- package/dist/layouts/Root/index.d.ts +0 -25
- package/dist/layouts/Root/index.d.ts.map +0 -1
- package/dist/layouts/Root/index.js +0 -51
- package/dist/layouts/Root/index.js.map +0 -1
- package/dist/rsc/renderPayloadRSC.d.ts +0 -6
- package/dist/rsc/renderPayloadRSC.d.ts.map +0 -1
- package/dist/rsc/renderPayloadRSC.js +0 -6
- package/dist/rsc/renderPayloadRSC.js.map +0 -1
- package/dist/utilities/devReloadStrategy.d.ts +0 -10
- package/dist/utilities/devReloadStrategy.d.ts.map +0 -1
- package/dist/utilities/devReloadStrategy.js +0 -27
- package/dist/utilities/devReloadStrategy.js.map +0 -1
- package/dist/utilities/getExistingAuthToken.d.ts +0 -7
- package/dist/utilities/getExistingAuthToken.d.ts.map +0 -1
- package/dist/utilities/getExistingAuthToken.js +0 -18
- package/dist/utilities/getExistingAuthToken.js.map +0 -1
- package/dist/utilities/getPreferences.d.ts +0 -10
- package/dist/utilities/getPreferences.d.ts.map +0 -1
- package/dist/utilities/getPreferences.js +0 -33
- package/dist/utilities/getPreferences.js.map +0 -1
- 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/importMap.server.d.ts +0 -9
- package/dist/utilities/importMap.server.d.ts.map +0 -1
- package/dist/utilities/importMap.server.js +0 -12
- package/dist/utilities/importMap.server.js.map +0 -1
- package/dist/utilities/serverFunctionHandlers.d.ts +0 -18
- package/dist/utilities/serverFunctionHandlers.d.ts.map +0 -1
- package/dist/utilities/serverFunctionHandlers.js +0 -17
- package/dist/utilities/serverFunctionHandlers.js.map +0 -1
- package/dist/utilities/setPayloadAuthCookie.d.ts +0 -9
- package/dist/utilities/setPayloadAuthCookie.d.ts.map +0 -1
- package/dist/utilities/setPayloadAuthCookie.js +0 -31
- package/dist/utilities/setPayloadAuthCookie.js.map +0 -1
- package/dist/vite/constants.d.ts +0 -37
- package/dist/vite/constants.d.ts.map +0 -1
- package/dist/vite/constants.js +0 -129
- package/dist/vite/constants.js.map +0 -1
- package/dist/vite/importProtection.d.ts.map +0 -1
- package/dist/vite/importProtection.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 -182
- 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 +0 -8
- 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 +0 -89
- 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 → withPayload}/importProtection.d.ts +0 -0
- /package/dist/{vite/plugins → withPayload/workarounds}/clientModuleResolution.d.ts +0 -0
- /package/dist/{vite/plugins → withPayload/workarounds}/clientModuleResolution.js +0 -0
- /package/dist/{vite/plugins → withPayload/workarounds}/reactDomServerInRsc.d.ts +0 -0
- /package/dist/{vite/plugins → withPayload/workarounds}/reactDomServerInRsc.js +0 -0
- /package/dist/{vite/plugins → withPayload/workarounds}/stripDistStyleImports.d.ts +0 -0
- /package/dist/{vite/plugins → withPayload/workarounds}/wrapCjsForClient.d.ts +0 -0
- /package/dist/{vite/plugins → withPayload/workarounds}/wrapCjsForClient.js +0 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { normalizePath } from 'vite';
|
|
3
|
+
import { PAYLOAD_CONFIG_CHANGED_EVENT } from '../utilities/devConfigReloadEvent.js';
|
|
4
|
+
/**
|
|
5
|
+
* Reloads Payload when `payload.config.ts`, or anything it imports, changes.
|
|
6
|
+
*
|
|
7
|
+
* Vite re-evaluates the config module on its own, but `getPayload` keeps
|
|
8
|
+
* serving its cached instance until a `DevReloadStrategy` marks it stale. This
|
|
9
|
+
* plugin only broadcasts the change; `devConfigReload.server.ts` subscribes
|
|
10
|
+
* from inside the server runtime and marks the instance, which `getPayload`
|
|
11
|
+
* then reloads on its next call.
|
|
12
|
+
*/ export function payloadDevConfigReload({ payloadConfigPath }) {
|
|
13
|
+
const configFile = normalizePath(path.resolve(payloadConfigPath));
|
|
14
|
+
let server;
|
|
15
|
+
// Vite runs `hotUpdate` once per environment (client, ssr, rsc) per change,
|
|
16
|
+
// sharing one timestamp; without this the notice prints three times.
|
|
17
|
+
let lastHandled = '';
|
|
18
|
+
return {
|
|
19
|
+
name: 'payload:dev-config-reload',
|
|
20
|
+
apply: 'serve',
|
|
21
|
+
configureServer (devServer) {
|
|
22
|
+
server = devServer;
|
|
23
|
+
},
|
|
24
|
+
hotUpdate ({ file, modules, timestamp }) {
|
|
25
|
+
if (!server) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const changeKey = `${file}:${timestamp}`;
|
|
29
|
+
if (changeKey === lastHandled) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!affectsPayloadConfig({
|
|
33
|
+
configFile,
|
|
34
|
+
file,
|
|
35
|
+
modules
|
|
36
|
+
})) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
lastHandled = changeKey;
|
|
40
|
+
server.config.logger.info(`payload config changed, reloading Payload (${path.basename(file)})`, {
|
|
41
|
+
timestamp: true
|
|
42
|
+
});
|
|
43
|
+
// Broadcast to every environment rather than just `this.environment`: the
|
|
44
|
+
// changed module may only be in the graph of the environment that saw it,
|
|
45
|
+
// while the Payload instance was built in another. Each environment's
|
|
46
|
+
// runtime subscribes with its own copy of `payload`, and environments with
|
|
47
|
+
// no subscriber (e.g. `client`) simply ignore the event.
|
|
48
|
+
for (const environment of Object.values(server.environments)){
|
|
49
|
+
environment.hot.send({
|
|
50
|
+
type: 'custom',
|
|
51
|
+
event: PAYLOAD_CONFIG_CHANGED_EVENT
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Whether `file` is the Payload config or something it imports. Walks *up*
|
|
59
|
+
* through importers, since the config sits at the root of that subtree.
|
|
60
|
+
*/ function affectsPayloadConfig({ configFile, file, modules }) {
|
|
61
|
+
if (normalizePath(file) === configFile) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
const seen = new Set();
|
|
65
|
+
const queue = [
|
|
66
|
+
...modules
|
|
67
|
+
];
|
|
68
|
+
while(queue.length > 0){
|
|
69
|
+
const mod = queue.pop();
|
|
70
|
+
if (seen.has(mod)) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
seen.add(mod);
|
|
74
|
+
if (mod.file && normalizePath(mod.file) === configFile) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
for (const importer of mod.importers){
|
|
78
|
+
queue.push(importer);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//# sourceMappingURL=devConfigReload.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/withPayload/devConfigReload.ts"],"sourcesContent":["import type { EnvironmentModuleNode, PluginOption, ViteDevServer } from 'vite'\n\nimport path from 'node:path'\nimport { normalizePath } from 'vite'\n\nimport { PAYLOAD_CONFIG_CHANGED_EVENT } from '../utilities/devConfigReloadEvent.js'\n\n/**\n * Reloads Payload when `payload.config.ts`, or anything it imports, changes.\n *\n * Vite re-evaluates the config module on its own, but `getPayload` keeps\n * serving its cached instance until a `DevReloadStrategy` marks it stale. This\n * plugin only broadcasts the change; `devConfigReload.server.ts` subscribes\n * from inside the server runtime and marks the instance, which `getPayload`\n * then reloads on its next call.\n */\nexport function payloadDevConfigReload({\n payloadConfigPath,\n}: {\n payloadConfigPath: string\n}): PluginOption {\n const configFile = normalizePath(path.resolve(payloadConfigPath))\n\n let server: undefined | ViteDevServer\n\n // Vite runs `hotUpdate` once per environment (client, ssr, rsc) per change,\n // sharing one timestamp; without this the notice prints three times.\n let lastHandled = ''\n\n return {\n name: 'payload:dev-config-reload',\n apply: 'serve',\n configureServer(devServer) {\n server = devServer\n },\n hotUpdate({ file, modules, timestamp }) {\n if (!server) {\n return\n }\n\n const changeKey = `${file}:${timestamp}`\n\n if (changeKey === lastHandled) {\n return\n }\n\n if (!affectsPayloadConfig({ configFile, file, modules })) {\n return\n }\n\n lastHandled = changeKey\n\n server.config.logger.info(\n `payload config changed, reloading Payload (${path.basename(file)})`,\n { timestamp: true },\n )\n\n // Broadcast to every environment rather than just `this.environment`: the\n // changed module may only be in the graph of the environment that saw it,\n // while the Payload instance was built in another. Each environment's\n // runtime subscribes with its own copy of `payload`, and environments with\n // no subscriber (e.g. `client`) simply ignore the event.\n for (const environment of Object.values(server.environments)) {\n environment.hot.send({ type: 'custom', event: PAYLOAD_CONFIG_CHANGED_EVENT })\n }\n },\n }\n}\n\n/**\n * Whether `file` is the Payload config or something it imports. Walks *up*\n * through importers, since the config sits at the root of that subtree.\n */\nfunction affectsPayloadConfig({\n configFile,\n file,\n modules,\n}: {\n configFile: string\n file: string\n modules: EnvironmentModuleNode[]\n}): boolean {\n if (normalizePath(file) === configFile) {\n return true\n }\n\n const seen = new Set<EnvironmentModuleNode>()\n const queue = [...modules]\n\n while (queue.length > 0) {\n const mod = queue.pop()!\n\n if (seen.has(mod)) {\n continue\n }\n seen.add(mod)\n\n if (mod.file && normalizePath(mod.file) === configFile) {\n return true\n }\n\n for (const importer of mod.importers) {\n queue.push(importer)\n }\n }\n\n return false\n}\n"],"names":["path","normalizePath","PAYLOAD_CONFIG_CHANGED_EVENT","payloadDevConfigReload","payloadConfigPath","configFile","resolve","server","lastHandled","name","apply","configureServer","devServer","hotUpdate","file","modules","timestamp","changeKey","affectsPayloadConfig","config","logger","info","basename","environment","Object","values","environments","hot","send","type","event","seen","Set","queue","length","mod","pop","has","add","importer","importers","push"],"mappings":"AAEA,OAAOA,UAAU,YAAW;AAC5B,SAASC,aAAa,QAAQ,OAAM;AAEpC,SAASC,4BAA4B,QAAQ,uCAAsC;AAEnF;;;;;;;;CAQC,GACD,OAAO,SAASC,uBAAuB,EACrCC,iBAAiB,EAGlB;IACC,MAAMC,aAAaJ,cAAcD,KAAKM,OAAO,CAACF;IAE9C,IAAIG;IAEJ,4EAA4E;IAC5E,qEAAqE;IACrE,IAAIC,cAAc;IAElB,OA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QACb;IACF;IAEA,OAAO;AACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"importProtection.d.ts","sourceRoot":"","sources":["../../src/withPayload/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,CAmC9E;AAED,eAAO,MAAM,sCAAsC,EAAE,MAAM,EAAsC,CAAA"}
|
|
@@ -11,7 +11,7 @@ import { builtinModules } from 'node:module';
|
|
|
11
11
|
/^@payloadcms\/richtext-lexical\/rsc/,
|
|
12
12
|
/^@payloadcms\/richtext-slate\/rsc/,
|
|
13
13
|
'@payloadcms/ui/server',
|
|
14
|
-
/^@payloadcms\/tanstack-start\/(layouts|rsc|server
|
|
14
|
+
/^@payloadcms\/tanstack-start\/(layouts|rsc|server)/,
|
|
15
15
|
'sharp',
|
|
16
16
|
'busboy',
|
|
17
17
|
'croner',
|
|
@@ -30,7 +30,7 @@ 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
|
-
const allowedClientFileImporters = /\/richtext-lexical\/.*\/exports\/client\/|\/
|
|
33
|
+
const allowedClientFileImporters = /\/richtext-lexical\/.*\/exports\/client\/|\/ui\//;
|
|
34
34
|
if (info.envType === 'server' && info.resolved?.includes('.client.') && allowedClientFileImporters.test(info.importer)) {
|
|
35
35
|
return false;
|
|
36
36
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/withPayload/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)/,\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 = /\\/richtext-lexical\\/.*\\/exports\\/client\\/|\\/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,6BAA6B;IAEnC,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"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { ConfigEnv, UserConfig, UserConfigFnObject } from 'vite';
|
|
2
|
+
import { tanstackStart } from '@tanstack/react-start/plugin/vite';
|
|
3
|
+
import viteReact from '@vitejs/plugin-react';
|
|
4
|
+
import rsc from '@vitejs/plugin-rsc';
|
|
5
|
+
export type WithPayloadOptions = {
|
|
6
|
+
/** Extra import-protection `ignoreImporters` patterns for the TanStack Start plugin. */
|
|
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[];
|
|
12
|
+
/** Path to the user's `payload.config.ts` (required) */
|
|
13
|
+
payloadConfigPath: string;
|
|
14
|
+
/** TanStack router routes directory relative to `srcDirectory`. Defaults to `'app'` */
|
|
15
|
+
routesDirectory?: string;
|
|
16
|
+
/** Silence Vite warnings about third-party dependency sourcemaps. Defaults to `true`. */
|
|
17
|
+
silenceDependencyWarnings?: boolean;
|
|
18
|
+
/** TanStack source directory. Defaults to `'src'` */
|
|
19
|
+
srcDirectory?: string;
|
|
20
|
+
/** Extra Vite config deep-merged over the Payload defaults. Ignored in `build` mode. */
|
|
21
|
+
vite?: UserConfig;
|
|
22
|
+
};
|
|
23
|
+
/** The options Payload's admin requires for each third-party plugin. */
|
|
24
|
+
export type PayloadPluginOptions = {
|
|
25
|
+
react: NonNullable<Parameters<typeof viteReact>[0]>;
|
|
26
|
+
rsc: NonNullable<Parameters<typeof rsc>[0]>;
|
|
27
|
+
tanstackStart: NonNullable<Parameters<typeof tanstackStart>[0]>;
|
|
28
|
+
};
|
|
29
|
+
export type WithPayloadBuilderContext = {
|
|
30
|
+
env: ConfigEnv;
|
|
31
|
+
/** Options to pass to the `viteReact`/`rsc`/`tanstackStart` factories you import. */
|
|
32
|
+
pluginOptions: PayloadPluginOptions;
|
|
33
|
+
};
|
|
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
|
+
*/
|
|
39
|
+
export type WithPayloadBuilder = (context: WithPayloadBuilderContext) => UserConfig;
|
|
40
|
+
/**
|
|
41
|
+
* Vite config helper for Payload + TanStack Start; the counterpart to Next.js'
|
|
42
|
+
* `withPayload`.
|
|
43
|
+
*
|
|
44
|
+
* Zero-config — Payload instantiates the RSC, React, and TanStack Start plugins:
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* export default withPayload(undefined, { payloadConfigPath: './src/payload.config.ts' })
|
|
48
|
+
* ```
|
|
49
|
+
*
|
|
50
|
+
* Guest mode — pass a `build` callback to instantiate them yourself (one copy of
|
|
51
|
+
* each; `@vitejs/plugin-rsc` is a hard singleton). Return only your additions;
|
|
52
|
+
* `withPayload` deep-merges them onto Payload's base config:
|
|
53
|
+
*
|
|
54
|
+
* ```ts
|
|
55
|
+
* export default withPayload(
|
|
56
|
+
* ({ pluginOptions }) => ({
|
|
57
|
+
* plugins: [
|
|
58
|
+
* rsc(pluginOptions.rsc),
|
|
59
|
+
* tanstackStart(pluginOptions.tanstackStart),
|
|
60
|
+
* viteReact(pluginOptions.react),
|
|
61
|
+
* ],
|
|
62
|
+
* // ...other config options
|
|
63
|
+
* }),
|
|
64
|
+
* { payloadConfigPath: './src/payload.config.ts' },
|
|
65
|
+
* )
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export declare function withPayload(build: undefined | WithPayloadBuilder, options: WithPayloadOptions): UserConfigFnObject;
|
|
69
|
+
/** `@vitejs/plugin-rsc` options for Payload: `serverHandler: false` (TanStack owns the handler). */
|
|
70
|
+
export declare function payloadRscOptions(): NonNullable<Parameters<typeof rsc>[0]>;
|
|
71
|
+
/** `@vitejs/plugin-react` options for Payload: transform every `.[jt]sx?` file. */
|
|
72
|
+
export declare function payloadReactOptions(): NonNullable<Parameters<typeof viteReact>[0]>;
|
|
73
|
+
export type PayloadTanstackStartOptionsArgs = {
|
|
74
|
+
/** Additional import-protection `ignoreImporters` patterns. */
|
|
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[];
|
|
88
|
+
/** TanStack router routes directory relative to `srcDirectory`. Defaults to `'app'`. */
|
|
89
|
+
routesDirectory?: string;
|
|
90
|
+
/** TanStack source directory. Defaults to `'src'`. */
|
|
91
|
+
srcDirectory?: string;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* The `tanstackStart` options Payload's admin requires (import-protection and
|
|
95
|
+
* code-splitting). TanStack Start is one-per-app, so a host that already runs it
|
|
96
|
+
* should merge these into its single `tanstackStart` call.
|
|
97
|
+
*/
|
|
98
|
+
export declare function payloadTanstackStartOptions(args?: PayloadTanstackStartOptionsArgs): NonNullable<Parameters<typeof tanstackStart>[0]>;
|
|
99
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/withPayload/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;AA+DpC,MAAM,MAAM,kBAAkB,GAAG;IAC/B,wFAAwF;IACxF,yBAAyB,CAAC,EAAE,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mB,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"}
|
|
@@ -0,0 +1,281 @@
|
|
|
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.
|
|
3
|
+
import { tanstackStart } from '@tanstack/react-start/plugin/vite';
|
|
4
|
+
import viteReact from '@vitejs/plugin-react';
|
|
5
|
+
import rsc from '@vitejs/plugin-rsc';
|
|
6
|
+
import path from 'node:path';
|
|
7
|
+
import { createLogger, mergeConfig } from 'vite';
|
|
8
|
+
import { buildExternalPackages, payloadNoExternalPatterns, ssrExternalPackages } from './config/external.js';
|
|
9
|
+
import { optimizeDepsExcludeDefaults, optimizeDepsIncludeDefaults } from './config/optimizeDeps.js';
|
|
10
|
+
import { payloadScssImporters } from './config/scss.js';
|
|
11
|
+
import { payloadDevConfigReload } from './devConfigReload.js';
|
|
12
|
+
import { defaultImportProtectionIgnoreImporters, onImportProtectionViolation, serverOnlyClientSpecifiers } from './importProtection.js';
|
|
13
|
+
import { clientModuleResolution } from './workarounds/clientModuleResolution.js';
|
|
14
|
+
import { payloadDevTransforms } from './workarounds/devTransforms.js';
|
|
15
|
+
import { reactDomServerInRsc } from './workarounds/reactDomServerInRsc.js';
|
|
16
|
+
import { ssrStripDistStyleImports } from './workarounds/stripDistStyleImports.js';
|
|
17
|
+
import { stubPrettierInClient } from './workarounds/stubPrettierInClient.js';
|
|
18
|
+
import { wrapCjsForClient } from './workarounds/wrapCjsForClient.js';
|
|
19
|
+
/**
|
|
20
|
+
* Vite dependency warnings Payload consumers can't act on: third-party packages
|
|
21
|
+
* ship sourcemaps whose original sources aren't published, so Vite warns on
|
|
22
|
+
* every one. Suppressed by default (see `silenceDependencyWarnings`).
|
|
23
|
+
*/ const suppressibleWarningPatterns = [
|
|
24
|
+
'points to missing source files',
|
|
25
|
+
'Sourcemap for'
|
|
26
|
+
];
|
|
27
|
+
/**
|
|
28
|
+
* Wraps a Vite logger so warnings matching {@link suppressibleWarningPatterns}
|
|
29
|
+
* are dropped. Mutates and returns the given logger (or a fresh default one).
|
|
30
|
+
*/ function withQuietedDependencyWarnings(existing) {
|
|
31
|
+
const logger = existing ?? createLogger();
|
|
32
|
+
const shouldSuppress = (msg)=>typeof msg === 'string' && suppressibleWarningPatterns.some((pattern)=>msg.includes(pattern));
|
|
33
|
+
const baseWarn = logger.warn.bind(logger);
|
|
34
|
+
const baseWarnOnce = logger.warnOnce.bind(logger);
|
|
35
|
+
logger.warn = (msg, options)=>{
|
|
36
|
+
if (!shouldSuppress(msg)) {
|
|
37
|
+
baseWarn(msg, options);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
logger.warnOnce = (msg, options)=>{
|
|
41
|
+
if (!shouldSuppress(msg)) {
|
|
42
|
+
baseWarnOnce(msg, options);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return logger;
|
|
46
|
+
}
|
|
47
|
+
/** Applies dependency-warning suppression to a config in place when enabled. */ function applyDependencyWarningSuppression(config, enabled) {
|
|
48
|
+
if (enabled) {
|
|
49
|
+
config.customLogger = withQuietedDependencyWarnings(config.customLogger);
|
|
50
|
+
}
|
|
51
|
+
return config;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Vite config helper for Payload + TanStack Start; the counterpart to Next.js'
|
|
55
|
+
* `withPayload`.
|
|
56
|
+
*
|
|
57
|
+
* Zero-config — Payload instantiates the RSC, React, and TanStack Start plugins:
|
|
58
|
+
*
|
|
59
|
+
* ```ts
|
|
60
|
+
* export default withPayload(undefined, { payloadConfigPath: './src/payload.config.ts' })
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* Guest mode — pass a `build` callback to instantiate them yourself (one copy of
|
|
64
|
+
* each; `@vitejs/plugin-rsc` is a hard singleton). Return only your additions;
|
|
65
|
+
* `withPayload` deep-merges them onto Payload's base config:
|
|
66
|
+
*
|
|
67
|
+
* ```ts
|
|
68
|
+
* export default withPayload(
|
|
69
|
+
* ({ pluginOptions }) => ({
|
|
70
|
+
* plugins: [
|
|
71
|
+
* rsc(pluginOptions.rsc),
|
|
72
|
+
* tanstackStart(pluginOptions.tanstackStart),
|
|
73
|
+
* viteReact(pluginOptions.react),
|
|
74
|
+
* ],
|
|
75
|
+
* // ...other config options
|
|
76
|
+
* }),
|
|
77
|
+
* { payloadConfigPath: './src/payload.config.ts' },
|
|
78
|
+
* )
|
|
79
|
+
* ```
|
|
80
|
+
*/ export function withPayload(build, options) {
|
|
81
|
+
const { additionalIgnoreImporters = [], adminRouteId, clientDenialExcludeFiles = [], payloadConfigPath, routesDirectory = 'app', silenceDependencyWarnings = true, srcDirectory = 'src', vite } = options;
|
|
82
|
+
return (env)=>{
|
|
83
|
+
// `pluralize` ships a UMD wrapper that throws when run through Vite's dev SSR
|
|
84
|
+
// transform, so dev serve keeps it external and lets Node require it.
|
|
85
|
+
// The production build must bundle it instead: it is reached from the
|
|
86
|
+
// force-bundled `@payloadcms/ui` / `@payloadcms/translations`, and Vite would
|
|
87
|
+
// otherwise externalize it into a client chunk as a bare specifier that pnpm
|
|
88
|
+
// can't resolve from `dist/` at runtime. Dropping it from the externals list
|
|
89
|
+
// isn't enough — Vite externalizes deps of `noExternal` packages by default,
|
|
90
|
+
// so it must be forced back in via `noExternal`.
|
|
91
|
+
const isBuild = env.command === 'build';
|
|
92
|
+
const noExternalPatterns = isBuild ? [
|
|
93
|
+
...payloadNoExternalPatterns,
|
|
94
|
+
'pluralize'
|
|
95
|
+
] : payloadNoExternalPatterns;
|
|
96
|
+
// Dev serve externalizes the server-only Node packages (including `pluralize`,
|
|
97
|
+
// whose UMD wrapper breaks under Vite's SSR transform). The prod build instead
|
|
98
|
+
// externalizes the package boundaries (`buildExternalPackages`) and drops
|
|
99
|
+
// `pluralize` so it bundles — leaving it in `ssr.external` here would win over
|
|
100
|
+
// `noExternal` and re-emit the bare specifier.
|
|
101
|
+
const ssrExternal = isBuild ? buildExternalPackages : ssrExternalPackages;
|
|
102
|
+
const base = {
|
|
103
|
+
build: {
|
|
104
|
+
cssMinify: 'esbuild'
|
|
105
|
+
},
|
|
106
|
+
css: {
|
|
107
|
+
preprocessorOptions: {
|
|
108
|
+
scss: {
|
|
109
|
+
importers: payloadScssImporters,
|
|
110
|
+
silenceDeprecations: [
|
|
111
|
+
'import',
|
|
112
|
+
'global-builtin'
|
|
113
|
+
]
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
define: {
|
|
118
|
+
global: 'globalThis'
|
|
119
|
+
},
|
|
120
|
+
environments: {
|
|
121
|
+
rsc: {
|
|
122
|
+
build: {
|
|
123
|
+
rollupOptions: {
|
|
124
|
+
external: buildExternalPackages
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
resolve: {
|
|
128
|
+
noExternal: noExternalPatterns
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
ssr: {
|
|
132
|
+
build: {
|
|
133
|
+
rollupOptions: {
|
|
134
|
+
external: buildExternalPackages
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
resolve: {
|
|
138
|
+
noExternal: noExternalPatterns
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
optimizeDeps: {
|
|
143
|
+
exclude: optimizeDepsExcludeDefaults,
|
|
144
|
+
include: optimizeDepsIncludeDefaults
|
|
145
|
+
},
|
|
146
|
+
// Payload's internal workaround plugins only. The RSC, TanStack Start, and
|
|
147
|
+
// React plugins are appended below (default form) or by the consumer's
|
|
148
|
+
// `build` callback (guest form).
|
|
149
|
+
plugins: [
|
|
150
|
+
clientModuleResolution(),
|
|
151
|
+
wrapCjsForClient(),
|
|
152
|
+
ssrStripDistStyleImports(),
|
|
153
|
+
reactDomServerInRsc(),
|
|
154
|
+
stubPrettierInClient(),
|
|
155
|
+
payloadDevTransforms(),
|
|
156
|
+
payloadDevConfigReload({
|
|
157
|
+
payloadConfigPath
|
|
158
|
+
})
|
|
159
|
+
],
|
|
160
|
+
resolve: {
|
|
161
|
+
alias: [
|
|
162
|
+
{
|
|
163
|
+
find: '@payload-config',
|
|
164
|
+
replacement: path.resolve(payloadConfigPath)
|
|
165
|
+
}
|
|
166
|
+
],
|
|
167
|
+
dedupe: [
|
|
168
|
+
'react',
|
|
169
|
+
'react-dom',
|
|
170
|
+
'scheduler',
|
|
171
|
+
'@payloadcms/ui',
|
|
172
|
+
'@payloadcms/richtext-lexical'
|
|
173
|
+
],
|
|
174
|
+
extensions: [
|
|
175
|
+
'.mjs',
|
|
176
|
+
'.js',
|
|
177
|
+
'.mts',
|
|
178
|
+
'.ts',
|
|
179
|
+
'.jsx',
|
|
180
|
+
'.tsx',
|
|
181
|
+
'.json'
|
|
182
|
+
],
|
|
183
|
+
tsconfigPaths: true
|
|
184
|
+
},
|
|
185
|
+
ssr: {
|
|
186
|
+
external: ssrExternal,
|
|
187
|
+
noExternal: noExternalPatterns
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
const pluginOptions = {
|
|
191
|
+
react: payloadReactOptions(),
|
|
192
|
+
rsc: payloadRscOptions(),
|
|
193
|
+
tanstackStart: payloadTanstackStartOptions({
|
|
194
|
+
additionalIgnoreImporters,
|
|
195
|
+
adminRouteId,
|
|
196
|
+
clientDenialExcludeFiles,
|
|
197
|
+
routesDirectory,
|
|
198
|
+
srcDirectory
|
|
199
|
+
})
|
|
200
|
+
};
|
|
201
|
+
if (build) {
|
|
202
|
+
return applyDependencyWarningSuppression(mergeConfig(base, build({
|
|
203
|
+
env,
|
|
204
|
+
pluginOptions
|
|
205
|
+
})), silenceDependencyWarnings);
|
|
206
|
+
}
|
|
207
|
+
base.plugins = [
|
|
208
|
+
...base.plugins,
|
|
209
|
+
rsc(pluginOptions.rsc),
|
|
210
|
+
tanstackStart(pluginOptions.tanstackStart),
|
|
211
|
+
viteReact(pluginOptions.react)
|
|
212
|
+
];
|
|
213
|
+
const merged = vite ? mergeConfig(base, vite) : base;
|
|
214
|
+
return applyDependencyWarningSuppression(merged, silenceDependencyWarnings);
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
/** `@vitejs/plugin-rsc` options for Payload: `serverHandler: false` (TanStack owns the handler). */ export function payloadRscOptions() {
|
|
218
|
+
return {
|
|
219
|
+
serverHandler: false
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
/** `@vitejs/plugin-react` options for Payload: transform every `.[jt]sx?` file. */ export function payloadReactOptions() {
|
|
223
|
+
return {
|
|
224
|
+
exclude: [],
|
|
225
|
+
include: /\.[jt]sx?$/
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* The `tanstackStart` options Payload's admin requires (import-protection and
|
|
230
|
+
* code-splitting). TanStack Start is one-per-app, so a host that already runs it
|
|
231
|
+
* should merge these into its single `tanstackStart` call.
|
|
232
|
+
*/ export function payloadTanstackStartOptions(args = {}) {
|
|
233
|
+
const { additionalIgnoreImporters = [], adminRouteId = '/_payload', clientDenialExcludeFiles = [], routesDirectory = 'app', srcDirectory = 'src' } = args;
|
|
234
|
+
return {
|
|
235
|
+
importProtection: {
|
|
236
|
+
client: {
|
|
237
|
+
excludeFiles: [],
|
|
238
|
+
specifiers: serverOnlyClientSpecifiers
|
|
239
|
+
},
|
|
240
|
+
ignoreImporters: [
|
|
241
|
+
...defaultImportProtectionIgnoreImporters,
|
|
242
|
+
...additionalIgnoreImporters
|
|
243
|
+
],
|
|
244
|
+
include: [
|
|
245
|
+
'**/*'
|
|
246
|
+
],
|
|
247
|
+
mockAccess: 'warn',
|
|
248
|
+
onViolation: onImportProtectionViolation,
|
|
249
|
+
// Payload's `.client.*` components are React Client Components that must be
|
|
250
|
+
// server-rendered during SSR; TanStack's default `**/*.client.*` server
|
|
251
|
+
// denial would mock and crash them. All such files live in `@payloadcms/*`
|
|
252
|
+
// packages, so keep the denial (host `.client.*` files still get it) and
|
|
253
|
+
// just exempt Payload's — `node_modules` covers published installs.
|
|
254
|
+
server: {
|
|
255
|
+
excludeFiles: [
|
|
256
|
+
'**/node_modules/**',
|
|
257
|
+
...clientDenialExcludeFiles
|
|
258
|
+
]
|
|
259
|
+
}
|
|
260
|
+
},
|
|
261
|
+
router: {
|
|
262
|
+
codeSplittingOptions: {
|
|
263
|
+
// Eager-load only Payload's admin routes so they hydrate on first paint —
|
|
264
|
+
// a split admin renders but isn't interactive until its lazy `?tsr-split=`
|
|
265
|
+
// chunk lands. Returning `[]` disables splitting for a route; `undefined`
|
|
266
|
+
// lets host routes keep TanStack's default per-route splitting.
|
|
267
|
+
splitBehavior: ({ routeId })=>routeId === adminRouteId || routeId.startsWith(`${adminRouteId}/`) ? [] : undefined
|
|
268
|
+
},
|
|
269
|
+
// Ignore generated importMap files and colocated `*.functions.ts` modules
|
|
270
|
+
// (they define `createServerFn`s, not routes).
|
|
271
|
+
routeFileIgnorePattern: 'importMap\\.(?:js|server\\.ts)$|\\.functions\\.',
|
|
272
|
+
routesDirectory
|
|
273
|
+
},
|
|
274
|
+
rsc: {
|
|
275
|
+
enabled: true
|
|
276
|
+
},
|
|
277
|
+
srcDirectory
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/withPayload/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 {\n buildExternalPackages,\n payloadNoExternalPatterns,\n ssrExternalPackages,\n} from './config/external.js'\nimport { optimizeDepsExcludeDefaults, optimizeDepsIncludeDefaults } from './config/optimizeDeps.js'\nimport { payloadScssImporters } from './config/scss.js'\nimport { payloadDevConfigReload } from './devConfigReload.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 // `pluralize` ships a UMD wrapper that throws when run through Vite's dev SSR\n // transform, so dev serve keeps it external and lets Node require it.\n // The production build must bundle it instead: it is reached from the\n // force-bundled `@payloadcms/ui` / `@payloadcms/translations`, and Vite would\n // otherwise externalize it into a client chunk as a bare specifier that pnpm\n // can't resolve from `dist/` at runtime. Dropping it from the externals list\n // isn't enough — Vite externalizes deps of `noExternal` packages by default,\n // so it must be forced back in via `noExternal`.\n const isBuild = env.command === 'build'\n const noExternalPatterns = isBuild\n ? [...payloadNoExternalPatterns, 'pluralize']\n : payloadNoExternalPatterns\n // Dev serve externalizes the server-only Node packages (including `pluralize`,\n // whose UMD wrapper breaks under Vite's SSR transform). The prod build instead\n // externalizes the package boundaries (`buildExternalPackages`) and drops\n // `pluralize` so it bundles — leaving it in `ssr.external` here would win over\n // `noExternal` and re-emit the bare specifier.\n const ssrExternal = isBuild ? buildExternalPackages : ssrExternalPackages\n\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: buildExternalPackages } },\n resolve: { noExternal: noExternalPatterns },\n },\n ssr: {\n build: { rollupOptions: { external: buildExternalPackages } },\n resolve: { noExternal: noExternalPatterns },\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 payloadDevConfigReload({ payloadConfigPath }),\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: ssrExternal,\n noExternal: noExternalPatterns,\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","buildExternalPackages","payloadNoExternalPatterns","ssrExternalPackages","optimizeDepsExcludeDefaults","optimizeDepsIncludeDefaults","payloadScssImporters","payloadDevConfigReload","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","isBuild","command","noExternalPatterns","ssrExternal","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,SACEC,qBAAqB,EACrBC,yBAAyB,EACzBC,mBAAmB,QACd,uBAAsB;AAC7B,SAASC,2BAA2B,EAAEC,2BAA2B,QAAQ,2BAA0B;AACnG,SAASC,oBAAoB,QAAQ,mBAAkB;AACvD,SAASC,sBAAsB,QAAQ,uBAAsB;AAC7D,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,YAAYpB;IAC3B,MAAMsB,iBAAiB,CAACC,MACtB,OAAOA,QAAQ,YAAYL,4BAA4BM,IAAI,CAAC,CAACC,UAAYF,IAAIG,QAAQ,CAACD;IAExF,MAAME,WAAWN,OAAOO,IAAI,CAACC,IAAI,CAACR;IAClC,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iD,QAAQtC;IACnD;AACF;AAEA,kGAAkG,GAClG,OAAO,SAASoC;IACd,OAAO;QAAEG,eAAe;IAAM;AAChC;AAEA,iFAAiF,GACjF,OAAO,SAASJ;IACd,OAAO;QAAEX,SAAS,EAAE;QAAEC,SAAS;IAAa;AAC9C;AAuBA;;;;CAIC,GACD,OAAO,SAASY,4BACdG,OAAwC,CAAC,CAAC;IAE1C,MAAM,EACJ7C,4BAA4B,EAAE,EAC9BC,eAAe,WAAW,EAC1BC,2BAA2B,EAAE,EAC7BE,kBAAkB,KAAK,EACvBE,eAAe,KAAK,EACrB,GAAGuC;IAEJ,OAAO;QACLC,kBAAkB;YAChBC,QAAQ;gBAAEC,cAAc,EAAE;gBAAEC,YAAY7E;YAA2B;YACnE8E,iBAAiB;mBAAIhF;mBAA2C8B;aAA0B;YAC1F8B,SAAS;gBAAC;aAAO;YACjBqB,YAAY;YACZC,aAAajF;YACb,4EAA4E;YAC5E,wEAAwE;YACxE,2EAA2E;YAC3E,yEAAyE;YACzE,oEAAoE;YACpEkF,QAAQ;gBAAEL,cAAc;oBAAC;uBAAyB9C;iBAAyB;YAAC;QAC9E;QACAoD,QAAQ;YACNC,sBAAsB;gBACpB,0EAA0E;gBAC1E,2EAA2E;gBAC3E,0EAA0E;gBAC1E,gEAAgE;gBAChEC,eAAe,CAAC,EAAEC,OAAO,EAAuB,GAC9CA,YAAYxD,gBAAgBwD,QAAQC,UAAU,CAAC,GAAGzD,aAAa,CAAC,CAAC,IAAI,EAAE,GAAG0D;YAC9E;YACA,0EAA0E;YAC1E,+CAA+C;YAC/CC,wBAAwB;YACxBxD;QACF;QACA7C,KAAK;YAAEqC,SAAS;QAAK;QACrBU;IACF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientModuleResolution.d.ts","sourceRoot":"","sources":["../../../src/withPayload/workarounds/clientModuleResolution.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAKxC;;;;;;;;;;GAUG;AACH,wBAAgB,sBAAsB,IAAI,YAAY,CA+ErD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/withPayload/workarounds/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,QAAQ,UAAS;AACxB,OAAOC,UAAU,YAAW;AAE5B;;;;;;;;;;CAUC,GACD,OAAO,SAASC;IACd,MAAMC,aAAa;IAEnB,MAAMC,qBAA+B;QACnC;QACA;QACA;QACA;KACD;IAED,MAAMC,oBAA8C;QAClD,wBAAwB;YAAC;YAAmB;SAA2B;QACvE,oCAAoC;YAClC;YACA;YACA;SACD;QACD,kCAAkC;YAChC;YACA;YACA;SACD;IACH;IAEA,OAAO;QACLC,MAAM;QACNC,SAAS;QACTC,MAAKC,EAAE;YACL,IAAI,CAACA,GAAGC,UAAU,C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,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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PluginOption } from 'vite';
|
|
2
|
+
/**
|
|
3
|
+
* Dev-time transforms:
|
|
4
|
+
* - Replaces `process.cwd()` with `"/"` in client code (non-SSR, non-prebundled)
|
|
5
|
+
* - Injects Vite HMR + React Refresh preamble into SSR-rendered HTML (dev only)
|
|
6
|
+
*
|
|
7
|
+
* The preamble is injected just before `</head>`, *after* everything React
|
|
8
|
+
* renders into the head. React 19 treats `<meta>`/`<link>`/`<style>`/`<title>`
|
|
9
|
+
* as hoistable resources it matches by key (position-tolerant), but a
|
|
10
|
+
* non-hoistable inline `<script type="module">` placed *before* React's first
|
|
11
|
+
* rendered head node makes hydration position-match that script against a
|
|
12
|
+
* `<style>`/`<meta>` and throw — discarding the whole tree client-side, which
|
|
13
|
+
* aborts in-flight server-function fetches and intermittently breaks drawers,
|
|
14
|
+
* forms, and navigation. Appending after React's head content keeps the
|
|
15
|
+
* preamble out of that positional comparison while still running before the
|
|
16
|
+
* body's app-entry module.
|
|
17
|
+
*/
|
|
18
|
+
export declare function payloadDevTransforms(): PluginOption;
|
|
19
|
+
//# sourceMappingURL=devTransforms.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devTransforms.d.ts","sourceRoot":"","sources":["../../../src/withPayload/workarounds/devTransforms.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAExC;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,IAAI,YAAY,CAgEnD"}
|
|
@@ -2,6 +2,17 @@
|
|
|
2
2
|
* Dev-time transforms:
|
|
3
3
|
* - Replaces `process.cwd()` with `"/"` in client code (non-SSR, non-prebundled)
|
|
4
4
|
* - Injects Vite HMR + React Refresh preamble into SSR-rendered HTML (dev only)
|
|
5
|
+
*
|
|
6
|
+
* The preamble is injected just before `</head>`, *after* everything React
|
|
7
|
+
* renders into the head. React 19 treats `<meta>`/`<link>`/`<style>`/`<title>`
|
|
8
|
+
* as hoistable resources it matches by key (position-tolerant), but a
|
|
9
|
+
* non-hoistable inline `<script type="module">` placed *before* React's first
|
|
10
|
+
* rendered head node makes hydration position-match that script against a
|
|
11
|
+
* `<style>`/`<meta>` and throw — discarding the whole tree client-side, which
|
|
12
|
+
* aborts in-flight server-function fetches and intermittently breaks drawers,
|
|
13
|
+
* forms, and navigation. Appending after React's head content keeps the
|
|
14
|
+
* preamble out of that positional comparison while still running before the
|
|
15
|
+
* body's app-entry module.
|
|
5
16
|
*/ export function payloadDevTransforms() {
|
|
6
17
|
const devScripts = `<script type="module" src="/@vite/client"></script>
|
|
7
18
|
<script type="module">
|
|
@@ -27,9 +38,14 @@ window.__vite_plugin_react_preamble_installed__ = true
|
|
|
27
38
|
return chunk;
|
|
28
39
|
}
|
|
29
40
|
const str = typeof chunk === 'string' ? chunk : Buffer.isBuffer(chunk) ? chunk.toString() : chunk instanceof Uint8Array ? Buffer.from(chunk).toString() : null;
|
|
30
|
-
if
|
|
41
|
+
// Skip if a host already injected the preamble — a second copy breaks HMR.
|
|
42
|
+
if (str && str.includes('__vite_plugin_react_preamble_installed__')) {
|
|
31
43
|
injected = true;
|
|
32
|
-
return
|
|
44
|
+
return chunk;
|
|
45
|
+
}
|
|
46
|
+
if (str && str.includes('</head>')) {
|
|
47
|
+
injected = true;
|
|
48
|
+
return str.replace('</head>', `${devScripts}</head>`);
|
|
33
49
|
}
|
|
34
50
|
return chunk;
|
|
35
51
|
}
|