@payloadcms/tanstack-start 4.0.0-internal.a0ef1b8 → 4.0.0-internal.fa345ef

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.
Files changed (127) hide show
  1. package/LICENSE.md +1 -1
  2. package/dist/elements/RouterAdapter/index.d.ts.map +1 -1
  3. package/dist/elements/RouterAdapter/index.js +38 -15
  4. package/dist/elements/RouterAdapter/index.js.map +1 -1
  5. package/dist/exports/client.d.ts +4 -0
  6. package/dist/exports/client.d.ts.map +1 -1
  7. package/dist/exports/client.js +4 -0
  8. package/dist/exports/client.js.map +1 -1
  9. package/dist/exports/layouts.d.ts +1 -0
  10. package/dist/exports/layouts.d.ts.map +1 -1
  11. package/dist/exports/layouts.js +1 -0
  12. package/dist/exports/layouts.js.map +1 -1
  13. package/dist/exports/server.d.ts +2 -1
  14. package/dist/exports/server.d.ts.map +1 -1
  15. package/dist/exports/server.js +2 -1
  16. package/dist/exports/server.js.map +1 -1
  17. package/dist/exports/vite.d.ts +12 -2
  18. package/dist/exports/vite.d.ts.map +1 -1
  19. package/dist/exports/vite.js +8 -1
  20. package/dist/exports/vite.js.map +1 -1
  21. package/dist/index.d.ts +1 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +1 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/layouts/Root/getLayoutData.d.ts.map +1 -1
  26. package/dist/layouts/Root/getLayoutData.js +36 -0
  27. package/dist/layouts/Root/getLayoutData.js.map +1 -1
  28. package/dist/layouts/Root/index.d.ts +9 -2
  29. package/dist/layouts/Root/index.d.ts.map +1 -1
  30. package/dist/layouts/Root/index.js.map +1 -1
  31. package/dist/layouts/Root/withPayloadRoot.d.ts +65 -0
  32. package/dist/layouts/Root/withPayloadRoot.d.ts.map +1 -0
  33. package/dist/layouts/Root/withPayloadRoot.js +92 -0
  34. package/dist/layouts/Root/withPayloadRoot.js.map +1 -0
  35. package/dist/routes/adminRoutes.d.ts +111 -0
  36. package/dist/routes/adminRoutes.d.ts.map +1 -0
  37. package/dist/routes/adminRoutes.js +108 -0
  38. package/dist/routes/adminRoutes.js.map +1 -0
  39. package/dist/routes/apiRoute.d.ts +29 -0
  40. package/dist/routes/apiRoute.d.ts.map +1 -0
  41. package/dist/routes/apiRoute.js +38 -0
  42. package/dist/routes/apiRoute.js.map +1 -0
  43. package/dist/routes/layoutRoute.d.ts +26 -0
  44. package/dist/routes/layoutRoute.d.ts.map +1 -0
  45. package/dist/routes/layoutRoute.js +57 -0
  46. package/dist/routes/layoutRoute.js.map +1 -0
  47. package/dist/utilities/handleAPIRoute.d.ts +11 -0
  48. package/dist/utilities/handleAPIRoute.d.ts.map +1 -0
  49. package/dist/utilities/handleAPIRoute.js +17 -0
  50. package/dist/utilities/handleAPIRoute.js.map +1 -0
  51. package/dist/utilities/importMap.server.d.ts +4 -5
  52. package/dist/utilities/importMap.server.d.ts.map +1 -1
  53. package/dist/utilities/importMap.server.js +5 -6
  54. package/dist/utilities/importMap.server.js.map +1 -1
  55. package/dist/utilities/loadAdminPage.d.ts +54 -0
  56. package/dist/utilities/loadAdminPage.d.ts.map +1 -0
  57. package/dist/utilities/loadAdminPage.js +230 -0
  58. package/dist/utilities/loadAdminPage.js.map +1 -0
  59. package/dist/utilities/loadLayoutData.d.ts +15 -0
  60. package/dist/utilities/loadLayoutData.d.ts.map +1 -0
  61. package/dist/utilities/loadLayoutData.js +23 -0
  62. package/dist/utilities/loadLayoutData.js.map +1 -0
  63. package/dist/utilities/serializeForRsc.d.ts.map +1 -1
  64. package/dist/utilities/serializeForRsc.js +17 -0
  65. package/dist/utilities/serializeForRsc.js.map +1 -1
  66. package/dist/utilities/serverFunctionClient.d.ts +29 -0
  67. package/dist/utilities/serverFunctionClient.d.ts.map +1 -0
  68. package/dist/utilities/serverFunctionClient.js +109 -0
  69. package/dist/utilities/serverFunctionClient.js.map +1 -0
  70. package/dist/vite/config/external.d.ts +26 -0
  71. package/dist/vite/config/external.d.ts.map +1 -0
  72. package/dist/vite/config/external.js +57 -0
  73. package/dist/vite/config/external.js.map +1 -0
  74. package/dist/vite/config/optimizeDeps.d.ts +25 -0
  75. package/dist/vite/config/optimizeDeps.d.ts.map +1 -0
  76. package/dist/vite/config/optimizeDeps.js +123 -0
  77. package/dist/vite/config/optimizeDeps.js.map +1 -0
  78. package/dist/vite/index.d.ts +49 -0
  79. package/dist/vite/index.d.ts.map +1 -0
  80. package/dist/vite/{plugin.js → index.js} +57 -47
  81. package/dist/vite/index.js.map +1 -0
  82. package/dist/vite/workarounds/clientModuleResolution.d.ts.map +1 -0
  83. package/dist/vite/workarounds/clientModuleResolution.js.map +1 -0
  84. package/dist/vite/workarounds/devTransforms.d.ts +19 -0
  85. package/dist/vite/workarounds/devTransforms.d.ts.map +1 -0
  86. package/dist/vite/{plugins → workarounds}/devTransforms.js +13 -2
  87. package/dist/vite/workarounds/devTransforms.js.map +1 -0
  88. package/dist/vite/workarounds/reactDomServerInRsc.d.ts.map +1 -0
  89. package/dist/vite/workarounds/reactDomServerInRsc.js.map +1 -0
  90. package/dist/vite/workarounds/stripDistStyleImports.d.ts.map +1 -0
  91. package/dist/vite/workarounds/stripDistStyleImports.js +140 -0
  92. package/dist/vite/workarounds/stripDistStyleImports.js.map +1 -0
  93. package/dist/vite/workarounds/wrapCjsForClient.d.ts.map +1 -0
  94. package/dist/vite/workarounds/wrapCjsForClient.js.map +1 -0
  95. package/package.json +10 -12
  96. package/dist/@types/assets.d.js +0 -2
  97. package/dist/@types/assets.d.js.map +0 -1
  98. package/dist/auth/switchLanguage.d.ts +0 -6
  99. package/dist/auth/switchLanguage.d.ts.map +0 -1
  100. package/dist/auth/switchLanguage.js +0 -11
  101. package/dist/auth/switchLanguage.js.map +0 -1
  102. package/dist/vite/constants.d.ts +0 -37
  103. package/dist/vite/constants.d.ts.map +0 -1
  104. package/dist/vite/constants.js +0 -129
  105. package/dist/vite/constants.js.map +0 -1
  106. package/dist/vite/plugin.d.ts +0 -38
  107. package/dist/vite/plugin.d.ts.map +0 -1
  108. package/dist/vite/plugin.js.map +0 -1
  109. package/dist/vite/plugins/clientModuleResolution.d.ts.map +0 -1
  110. package/dist/vite/plugins/clientModuleResolution.js.map +0 -1
  111. package/dist/vite/plugins/devTransforms.d.ts +0 -8
  112. package/dist/vite/plugins/devTransforms.d.ts.map +0 -1
  113. package/dist/vite/plugins/devTransforms.js.map +0 -1
  114. package/dist/vite/plugins/reactDomServerInRsc.d.ts.map +0 -1
  115. package/dist/vite/plugins/reactDomServerInRsc.js.map +0 -1
  116. package/dist/vite/plugins/stripDistStyleImports.d.ts.map +0 -1
  117. package/dist/vite/plugins/stripDistStyleImports.js +0 -89
  118. package/dist/vite/plugins/stripDistStyleImports.js.map +0 -1
  119. package/dist/vite/plugins/wrapCjsForClient.d.ts.map +0 -1
  120. package/dist/vite/plugins/wrapCjsForClient.js.map +0 -1
  121. /package/dist/vite/{plugins → workarounds}/clientModuleResolution.d.ts +0 -0
  122. /package/dist/vite/{plugins → workarounds}/clientModuleResolution.js +0 -0
  123. /package/dist/vite/{plugins → workarounds}/reactDomServerInRsc.d.ts +0 -0
  124. /package/dist/vite/{plugins → workarounds}/reactDomServerInRsc.js +0 -0
  125. /package/dist/vite/{plugins → workarounds}/stripDistStyleImports.d.ts +0 -0
  126. /package/dist/vite/{plugins → workarounds}/wrapCjsForClient.d.ts +0 -0
  127. /package/dist/vite/{plugins → workarounds}/wrapCjsForClient.js +0 -0
@@ -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;AAuBxC;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,wBAAwB,IAAI,YAAY,CAmDvD"}
@@ -1,89 +0,0 @@
1
- const STYLE_EXTENSION_RE = /\.(?:s?css|less)$/i;
2
- /**
3
- * Static `import './foo.css'` (or .scss/.less) — top-level only.
4
- * Captures the entire statement so we can replace it with an empty line.
5
- *
6
- * Matches:
7
- * import './foo.css';
8
- * import "../bar.scss"
9
- * import './baz.less' ;
10
- */ const STATIC_STYLE_IMPORT_RE = /^[ \t]*import\s+['"][^'"]+\.(?:s?css|less)['"]\s*(?:;[ \t]*)?$/gm;
11
- /**
12
- * Monorepo Payload package source, e.g. `…/packages/ui/src/…`. In the
13
- * core-dev / test setup Payload packages resolve to their workspace `src`
14
- * (not a published `dist`), so the `dist/` rule below doesn't cover them and
15
- * their `.css` side-effect imports survive into the SSR/RSC graph.
16
- */ const PAYLOAD_PKG_SRC_RE = /\/packages\/[^/]+\/src\//;
17
- /**
18
- * Stops Vite (and the underlying Node ESM loader) from trying to load
19
- * SCSS/CSS/LESS during SSR/RSC when the importer lives inside a built
20
- * `dist/` directory or when the specifier is a bare package name.
21
- *
22
- * We do this two ways, because either layer can fail:
23
- *
24
- * 1. `resolveId` redirects style specifiers to a virtual empty module —
25
- * handles cases where Vite asks us to resolve them.
26
- * 2. `transform` strips top-level `import './x.css'` statements out of any
27
- * JS/TS file living under `node_modules/.../dist/` for non-client envs.
28
- * This is the bulletproof path for prod-packed `@payloadcms/ui` (and
29
- * similar) dependencies that get pre-bundled by Vite's SSR/RSC dep
30
- * optimizer (esbuild). Esbuild preserves `.css` import statements as-is,
31
- * and Node's native ESM loader then crashes with
32
- * `Unknown file extension ".css"`. Removing them at the source avoids
33
- * that entirely.
34
- */ export function ssrStripDistStyleImports() {
35
- return {
36
- name: 'payload:ssr-strip-dist-style-imports',
37
- enforce: 'pre',
38
- load (id) {
39
- if (id === '\0ssr-empty-style') {
40
- return '';
41
- }
42
- },
43
- resolveId (id, importer, options) {
44
- const isServerEnv = options?.ssr || this.environment && this.environment.name !== 'client';
45
- if (!isServerEnv) {
46
- return;
47
- }
48
- if (!STYLE_EXTENSION_RE.test(id)) {
49
- return;
50
- }
51
- if (importer && (/\/dist\//.test(importer) || PAYLOAD_PKG_SRC_RE.test(importer))) {
52
- return '\0ssr-empty-style';
53
- }
54
- if (/^@?[a-z]/.test(id) && !id.startsWith('.') && !id.startsWith('/')) {
55
- return '\0ssr-empty-style';
56
- }
57
- },
58
- transform (code, id) {
59
- const isServerEnv = this.environment && this.environment.name !== 'client';
60
- if (!isServerEnv) {
61
- return;
62
- }
63
- // Only touch Payload dependency files: published `node_modules/.../dist/`
64
- // builds, or workspace `…/packages/<pkg>/src/…` sources in the core-dev /
65
- // test setup. Don't strip from the consumer's own app source — devs may
66
- // legitimately want SSR-rendered <link>s from their own CSS imports.
67
- const isPayloadDistFile = /\/node_modules\//.test(id) && /\/dist\//.test(id);
68
- const isPayloadSrcFile = PAYLOAD_PKG_SRC_RE.test(id);
69
- if (!isPayloadDistFile && !isPayloadSrcFile) {
70
- return;
71
- }
72
- if (!/\.[mc]?[jt]sx?$/.test(id)) {
73
- return;
74
- }
75
- if (!STATIC_STYLE_IMPORT_RE.test(code)) {
76
- STATIC_STYLE_IMPORT_RE.lastIndex = 0;
77
- return;
78
- }
79
- STATIC_STYLE_IMPORT_RE.lastIndex = 0;
80
- const stripped = code.replace(STATIC_STYLE_IMPORT_RE, '');
81
- return {
82
- code: stripped,
83
- map: null
84
- };
85
- }
86
- };
87
- }
88
-
89
- //# sourceMappingURL=stripDistStyleImports.js.map
@@ -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 * 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 isServerEnv =\n options?.ssr || ((this as any).environment && (this as any).environment.name !== 'client')\n if (!isServerEnv) {\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 isServerEnv = (this as any).environment && (this as any).environment.name !== 'client'\n if (!isServerEnv) {\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 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","ssrStripDistStyleImports","name","enforce","load","id","resolveId","importer","options","isServerEnv","ssr","environment","test","startsWith","transform","code","isPayloadDistFile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ACN,uBAAuBa,IAAI,CAACG,OAAO;gBACtChB,uBAAuBmB,SAAS,GAAG;gBACnC;YACF;YACAnB,uBAAuBmB,SAAS,GAAG;YACnC,MAAMC,WAAWJ,KAAKK,OAAO,CAACrB,wBAAwB;YACtD,OAAO;gBAAEgB,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,IAAIA,SAASC,KAAK;gBAChB;YACF;YAEA,IAAI,CAACF,GAAGG,QAAQ,CAAC,qBAAqBH,GAAGG,QAAQ,CAAC,yBAAyB;gBACzE;YACF;YAEA,MAAMC,UAAUJ,GAAGK,OAAO,CAAC,SAAS;YACpC,IAAI,CAACD,QAAQE,QAAQ,CAAC,UAAU,CAACF,QAAQE,QAAQ,CAAC,SAAS;gBACzD;YACF;YAEA,IAAIP,KAAKI,QAAQ,CAAC,cAAcJ,KAAKI,QAAQ,CAAC,YAAY;gBACxD;YACF;YAEA,IACE,CAACJ,KAAKI,QAAQ,CAAC,qBACf,CAACJ,KAAKI,QAAQ,CAAC,eACf,CAACJ,KAAKI,QAAQ,CAAC,kCACf;gBACA;YACF;YAEA,MAAMI,eAAeC,kBAAkBT;YACvC,MAAMU,QAAQC,OAAOC,IAAI,CAACJ;YAE1B,MAAMK,sBAAsBC,2BAA2Bd;YACvD,MAAMe,YAAYL,MAAMM,MAAM,CAAC,CAACpB,OAAS,CAACiB,oBAAoBI,GAAG,CAACrB;YAElE,uEAAuE;YACvE,sEAAsE;YACtE,2EAA2E;YAC3E,MAAMsB,oBAAoB,CAACL,oBAAoBI,GAAG,CAAC;YAEnD,MAAME,UAAU;gBACd,CAAC,6B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