This PR updates the build process to generate a single
`dist/index.bundled.d.ts` file that bundles all `payload` package types.
Having one bundled declaration file makes it easy to load types into the
Monaco editor (e.g. for the new Code block), enabling full type
completion for the `payload` package.
## Example
```ts
BlocksFeature({
blocks: [
CodeBlock({
slug: 'PayloadCode',
languages: {
ts: 'TypeScript',
},
typescript: {
fetchTypes: [
{
filePath: 'file:///node_modules/payload/index.d.ts',
url: 'https://unpkg.com/payload@3.59.0-internal.e247081/dist/index.bundled.d.ts', // <= download bundled .d.ts
},
],
paths: {
payload: ['file:///node_modules/payload/index.d.ts'],
},
typeRoots: ['node_modules/@types', 'node_modules/payload'],
},
}),
],
}),
```
<img width="1506" height="866" alt="Screenshot 2025-10-01 at 12 38
54@2x"
src="https://github.com/user-attachments/assets/135b9b69-058a-42b9-afa0-daa328f64f38"
/>
---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
- https://app.asana.com/0/0/1211524241290884
47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
import dts from 'rollup-plugin-dts'
|
|
import path from 'node:path'
|
|
|
|
import { builtinModules } from 'node:module'
|
|
|
|
const WHITELIST = ['ts-essentials', 'croner', '@payloadcms/translations'] // <-- only these get bundled
|
|
|
|
/**
|
|
* One-step DTS bundle:
|
|
* - Input from your TS source entry
|
|
* - Output to a single dist/index.bundled.d.ts
|
|
* - respectExternal: true -> aggressively inline third-party .d.ts (helps with ts-essentials)
|
|
*/
|
|
export default [
|
|
{
|
|
input: 'src/index.ts',
|
|
output: { file: 'dist/index.bundled.d.ts', format: 'es' },
|
|
plugins: [
|
|
dts({
|
|
tsconfig: './tsconfig.bundletypes.json',
|
|
respectExternal: true,
|
|
compilerOptions: {},
|
|
}),
|
|
],
|
|
|
|
/**
|
|
* Externalize all non-whitelisted packages and Node builtins.
|
|
* If we bundle all packages, this script runs out of memory.
|
|
*/
|
|
external: (id) => {
|
|
// 1) Always keep Node builtins external
|
|
if (builtinModules.includes(id) || builtinModules.includes(id.replace(/^node:/, '')))
|
|
return true
|
|
|
|
// 2) Keep virtual/internal rollup ids external just in case
|
|
if (id.startsWith('\0')) return true
|
|
|
|
// 3) Never externalize *local* files (we want our own .d.ts bundled)
|
|
if (id.startsWith('.') || path.isAbsolute(id)) return false
|
|
|
|
// 4) Bundle only whitelisted packages (opt-in)
|
|
const isWhitelisted = WHITELIST.some((p) => id === p || id.startsWith(`${p}/`))
|
|
return !isWhitelisted // everything else is external
|
|
},
|
|
},
|
|
]
|