Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/guide/how-it-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ When you publish a library, your consumers install its `dependencies` and `peerD

| Option | What it does |
| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`deps.onlyAllowBundle`](../options/dependencies.md#deps-onlyallowbundle) | Whitelist of dependencies allowed to be bundled. Any unlisted dependency that ends up in the bundle causes an error. Useful for catching accidental inlining in large projects. |
| [`deps.onlyBundle`](../options/dependencies.md#deps-onlybundle) | Whitelist of dependencies allowed to be bundled. Any unlisted dependency that ends up in the bundle causes an error. Useful for catching accidental inlining in large projects. |
| [`deps.neverBundle`](../options/dependencies.md#deps-neverbundle) | Explicitly mark additional packages as external (never bundled). |
| [`deps.alwaysBundle`](../options/dependencies.md#deps-alwaysbundle) | Force specific packages to be bundled, even if they're in `dependencies`. |
| [`deps.skipNodeModulesBundle`](../options/dependencies.md#deps-skipnodemodulebundle) | Skip resolving and bundling everything from `node_modules`. |
Expand Down
21 changes: 11 additions & 10 deletions docs/options/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default defineConfig({
deps: {
neverBundle: ['lodash', /^@my-scope\//],
alwaysBundle: ['some-package'],
onlyAllowBundle: ['cac', 'bumpp'],
onlyBundle: ['cac', 'bumpp'],
skipNodeModulesBundle: true,
},
})
Expand All @@ -55,16 +55,16 @@ This will prevent `tsdown` from parsing and bundling any dependencies from `node
`skipNodeModulesBundle` cannot be used together with `alwaysBundle`. These options are mutually exclusive.
:::

### `deps.onlyAllowBundle`
### `deps.onlyBundle`

The `onlyAllowBundle` option acts as a whitelist for dependencies that are allowed to be bundled from `node_modules`. If any dependency not in the list is found in the bundle, tsdown will throw an error. This is useful for preventing unexpected dependencies from being silently inlined into your output, especially in large projects.
The `onlyBundle` option acts as a whitelist for dependencies that are allowed to be bundled from `node_modules`. If any dependency not in the list is found in the bundle, tsdown will throw an error. This is useful for preventing unexpected dependencies from being silently inlined into your output, especially in large projects.

```ts [tsdown.config.ts]
import { defineConfig } from 'tsdown'

export default defineConfig({
deps: {
onlyAllowBundle: ['cac', 'bumpp'],
onlyBundle: ['cac', 'bumpp'],
},
})
```
Expand All @@ -73,12 +73,12 @@ In this example, only `cac` and `bumpp` are allowed to be bundled. If any other

#### Behavior

- **`onlyAllowBundle` is an array** (e.g., `['cac', /^my-/]`): Only dependencies matching the list are allowed to be bundled. An error is thrown for any others. Unused patterns in the list will also be reported.
- **`onlyAllowBundle` is `false`**: All warnings and checks about bundled dependencies are suppressed.
- **`onlyAllowBundle` is not set** (default): A warning is shown if any `node_modules` dependencies are bundled, suggesting you add the `onlyAllowBundle` option or set it to `false` to suppress warnings.
- **`onlyBundle` is an array** (e.g., `['cac', /^my-/]`): Only dependencies matching the list are allowed to be bundled. An error is thrown for any others. Unused patterns in the list will also be reported.
- **`onlyBundle` is `false`**: All warnings and checks about bundled dependencies are suppressed.
- **`onlyBundle` is not set** (default): A warning is shown if any `node_modules` dependencies are bundled, suggesting you add the `onlyBundle` option or set it to `false` to suppress warnings.

::: tip
Make sure to include all required sub-dependencies in the `onlyAllowBundle` list as well, not just the top-level packages you directly import.
Make sure to include all required sub-dependencies in the `onlyBundle` list as well, not just the top-level packages you directly import.
:::

### `deps.neverBundle`
Expand Down Expand Up @@ -141,7 +141,8 @@ The following top-level options are deprecated. Please migrate to the `deps` nam
| ----------------------- | ---------------------------- |
| `external` | `deps.neverBundle` |
| `noExternal` | `deps.alwaysBundle` |
| `inlineOnly` | `deps.onlyAllowBundle` |
| `inlineOnly` | `deps.onlyBundle` |
| `onlyAllowBundle` | `deps.onlyBundle` |
| `skipNodeModulesBundle` | `deps.skipNodeModulesBundle` |

## Summary
Expand All @@ -150,7 +151,7 @@ The following top-level options are deprecated. Please migrate to the `deps` nam
- `dependencies` and `peerDependencies` are treated as external and not bundled.
- `devDependencies` and phantom dependencies are only bundled if they are actually used in your code.
- **Customization**:
- Use `deps.onlyAllowBundle` to whitelist dependencies allowed to be bundled, and throw an error for any others.
- Use `deps.onlyBundle` to whitelist dependencies allowed to be bundled, and throw an error for any others.
- Use `deps.neverBundle` to mark specific dependencies as external.
- Use `deps.alwaysBundle` to force specific dependencies to be bundled.
- Use `deps.skipNodeModulesBundle` to skip resolving and bundling all dependencies from `node_modules`.
Expand Down
2 changes: 1 addition & 1 deletion docs/zh-CN/guide/how-it-works.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ tsdown 读取你的 `package.json` 和 `tsconfig.json` 来推断合理的默认

| 选项 | 说明 |
| ------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------- |
| [`deps.onlyAllowBundle`](../options/dependencies.md#deps-onlyallowbundle) | 允许打包的依赖白名单。任何不在列表中的依赖如果出现在 bundle 中将触发错误。适用于防止大型项目中的意外内联。 |
| [`deps.onlyBundle`](../options/dependencies.md#deps-onlybundle) | 允许打包的依赖白名单。任何不在列表中的依赖如果出现在 bundle 中将触发错误。适用于防止大型项目中的意外内联。 |
| [`deps.neverBundle`](../options/dependencies.md#deps-neverbundle) | 显式将额外的包标记为外部依赖(不打包)。 |
| [`deps.alwaysBundle`](../options/dependencies.md#deps-alwaysbundle) | 强制打包特定的包,即使它们在 `dependencies` 中。 |
| [`deps.skipNodeModulesBundle`](../options/dependencies.md#deps-skipnodemodulebundle) | 跳过解析和打包所有来自 `node_modules` 的内容。 |
Expand Down
21 changes: 11 additions & 10 deletions docs/zh-CN/options/dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default defineConfig({
deps: {
neverBundle: ['lodash', /^@my-scope\//],
alwaysBundle: ['some-package'],
onlyAllowBundle: ['cac', 'bumpp'],
onlyBundle: ['cac', 'bumpp'],
skipNodeModulesBundle: true,
},
})
Expand All @@ -55,16 +55,16 @@ export default defineConfig({
`skipNodeModulesBundle` 不能与 `alwaysBundle` 一起使用,这两个选项互斥。
:::

### `deps.onlyAllowBundle`
### `deps.onlyBundle`

`onlyAllowBundle` 选项作为允许从 `node_modules` 中打包的依赖白名单。如果有任何不在列表中的依赖被打包,tsdown 将抛出错误。这对于防止意外的依赖被静默内联到输出文件中非常有用,尤其是在大型项目中可能存在许多依赖的情况下。
`onlyBundle` 选项作为允许从 `node_modules` 中打包的依赖白名单。如果有任何不在列表中的依赖被打包,tsdown 将抛出错误。这对于防止意外的依赖被静默内联到输出文件中非常有用,尤其是在大型项目中可能存在许多依赖的情况下。

```ts [tsdown.config.ts]
import { defineConfig } from 'tsdown'

export default defineConfig({
deps: {
onlyAllowBundle: ['cac', 'bumpp'],
onlyBundle: ['cac', 'bumpp'],
},
})
```
Expand All @@ -73,12 +73,12 @@ export default defineConfig({

#### 行为

- **`onlyAllowBundle` 为数组**(例如 `['cac', /^my-/]`):只有匹配列表的依赖才允许被打包,其他依赖会触发错误。列表中未使用的模式也会被报告。
- **`onlyAllowBundle` 为 `false`**:抑制所有关于打包依赖的警告和检查。
- **`onlyAllowBundle` 未设置**(默认):如果有 `node_modules` 依赖被打包,会显示一条警告,建议您添加 `onlyAllowBundle` 选项或将其设置为 `false` 来抑制警告。
- **`onlyBundle` 为数组**(例如 `['cac', /^my-/]`):只有匹配列表的依赖才允许被打包,其他依赖会触发错误。列表中未使用的模式也会被报告。
- **`onlyBundle` 为 `false`**:抑制所有关于打包依赖的警告和检查。
- **`onlyBundle` 未设置**(默认):如果有 `node_modules` 依赖被打包,会显示一条警告,建议您添加 `onlyBundle` 选项或将其设置为 `false` 来抑制警告。

::: tip
请确保在 `onlyAllowBundle` 中包含所有子依赖,不仅是直接导入的顶层包。
请确保在 `onlyBundle` 中包含所有子依赖,不仅是直接导入的顶层包。
:::

### `deps.neverBundle`
Expand Down Expand Up @@ -141,7 +141,8 @@ export default defineConfig({
| ----------------------- | ---------------------------- |
| `external` | `deps.neverBundle` |
| `noExternal` | `deps.alwaysBundle` |
| `inlineOnly` | `deps.onlyAllowBundle` |
| `inlineOnly` | `deps.onlyBundle` |
| `onlyAllowBundle` | `deps.onlyBundle` |
| `skipNodeModulesBundle` | `deps.skipNodeModulesBundle` |

## 总结
Expand All @@ -150,7 +151,7 @@ export default defineConfig({
- `dependencies` 和 `peerDependencies` 被视为外部依赖,不会被打包。
- `devDependencies` 和幻影依赖只有在代码中实际使用时才会被打包。
- **自定义**:
- 使用 `deps.onlyAllowBundle` 设置允许被打包的依赖白名单,不在列表中的依赖会触发错误。
- 使用 `deps.onlyBundle` 设置允许被打包的依赖白名单,不在列表中的依赖会触发错误。
- 使用 `deps.neverBundle` 将特定依赖标记为外部依赖。
- 使用 `deps.alwaysBundle` 强制将特定依赖打包。
- 使用 `deps.skipNodeModulesBundle` 跳过解析和打包所有来自 `node_modules` 的依赖。
Expand Down
4 changes: 2 additions & 2 deletions dts.snapshot.json
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@
"CopyOptions": "type CopyOptions = Arrayable<string | CopyEntry>",
"CopyOptionsFn": "type CopyOptionsFn = (_: ResolvedConfig) => Awaitable<CopyOptions>",
"DepPlugin": "declare function DepPlugin(_: ResolvedConfig, _: TsdownBundle): Plugin",
"DepsConfig": "interface DepsConfig {\n neverBundle?: ExternalOption\n alwaysBundle?: Arrayable<string | RegExp> | NoExternalFn\n onlyAllowBundle?: Arrayable<string | RegExp> | false\n skipNodeModulesBundle?: boolean\n}",
"DepsConfig": "interface DepsConfig {\n neverBundle?: ExternalOption\n alwaysBundle?: Arrayable<string | RegExp> | NoExternalFn\n onlyBundle?: Arrayable<string | RegExp> | false\n onlyAllowBundle?: Arrayable<string | RegExp> | false\n skipNodeModulesBundle?: boolean\n}",
"DevtoolsOptions": "interface DevtoolsOptions extends NonNullable<InputOptions['devtools']> {\n ui?: boolean | Partial<StartOptions>\n clean?: boolean\n}",
"ExeOptions": "interface ExeOptions extends ExeExtensionOptions {\n seaConfig?: Omit<SeaConfig, 'main' | 'output' | 'mainFormat'>\n fileName?: string | ((_: RolldownChunk) => string)\n outDir?: string\n}",
"ExportsOptions": "interface ExportsOptions {\n devExports?: boolean | string\n packageJson?: boolean\n all?: boolean\n exclude?: (RegExp | string)[]\n legacy?: boolean\n customExports?: Record<string, any> | ((_: Record<string, any>, _: { pkg: PackageJson; chunks: ChunksByFormat; isPublish: boolean }) => Awaitable<Record<string, any>>)\n inlinedDependencies?: boolean\n}",
Expand Down Expand Up @@ -154,7 +154,7 @@
"ReportOptions": "interface ReportOptions {\n gzip?: boolean\n brotli?: boolean\n maxCompressSize?: number\n}",
"ReportPlugin": "declare function ReportPlugin(_: ResolvedConfig, _: boolean, _: boolean): Plugin",
"ResolvedConfig": "type ResolvedConfig = Overwrite<MarkPartial<Omit<UserConfig, 'workspace' | 'fromVite' | 'publicDir' | 'bundle' | 'injectStyle' | 'removeNodeProtocol' | 'external' | 'noExternal' | 'inlineOnly' | 'skipNodeModulesBundle' | 'logLevel' | 'failOnWarn' | 'customLogger' | 'envFile' | 'envPrefix'>, 'globalName' | 'inputOptions' | 'outputOptions' | 'minify' | 'define' | 'alias' | 'onSuccess' | 'outExtensions' | 'hooks' | 'copy' | 'loader' | 'name' | 'banner' | 'footer' | 'checks' | 'css'>, { entry: Record<string, string>; rawEntry?: TsdownInputOption; nameLabel: string | undefined; format: NormalizedFormat; target?: string[]; clean: string[]; pkg?: PackageJsonWithPath; nodeProtocol: 'strip' | boolean; logger: Logger; ignoreWatch: Array<string | RegExp>; deps: ResolvedDepsConfig; root: string; dts: false | DtsOptions; report: false | ReportOptions; tsconfig: false | string; exports: false | ExportsOptions; devtools: false | DevtoolsOptions; publint: false | PublintOptions; attw: false | AttwOptions; unused: false | UnusedOptions; exe: false | ExeOptions }>",
"ResolvedDepsConfig": "interface ResolvedDepsConfig {\n neverBundle?: ExternalOption\n alwaysBundle?: NoExternalFn\n onlyAllowBundle?: Array<string | RegExp> | false\n skipNodeModulesBundle: boolean\n}",
"ResolvedDepsConfig": "interface ResolvedDepsConfig {\n neverBundle?: ExternalOption\n alwaysBundle?: NoExternalFn\n onlyBundle?: Array<string | RegExp> | false\n skipNodeModulesBundle: boolean\n}",
"RolldownChunk": "type RolldownChunk = (OutputChunk | OutputAsset) & { outDir: string }",
"RolldownContext": "interface RolldownContext {\n buildOptions: BuildOptions\n}",
"SeaConfig": "interface SeaConfig {\n main?: string\n executable?: string\n output?: string\n mainFormat?: 'commonjs' | 'module'\n disableExperimentalSEAWarning?: boolean\n useSnapshot?: boolean\n useCodeCache?: boolean\n execArgv?: string[]\n execArgvExtension?: 'none' | 'env' | 'cli'\n assets?: Record<string, string>\n}",
Expand Down
2 changes: 1 addition & 1 deletion skills/tsdown/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default defineConfig({
|---------|-------|-----------|
| Never bundle | `deps: { neverBundle: ['react', /^@myorg\//] }` | [option-dependencies](references/option-dependencies.md) |
| Always bundle | `deps: { alwaysBundle: ['dep-to-bundle'] }` | [option-dependencies](references/option-dependencies.md) |
| Only allow bundle | `deps: { onlyAllowBundle: ['cac', 'bumpp'] }` - Whitelist | [option-dependencies](references/option-dependencies.md) |
| Only bundle | `deps: { onlyBundle: ['cac', 'bumpp'] }` - Whitelist | [option-dependencies](references/option-dependencies.md) |
| Skip node_modules | `deps: { skipNodeModulesBundle: true }` | [option-dependencies](references/option-dependencies.md) |
| Auto external | Automatic peer/dependency externalization | [option-dependencies](references/option-dependencies.md) |

Expand Down
11 changes: 6 additions & 5 deletions skills/tsdown/references/option-dependencies.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default defineConfig({
deps: {
neverBundle: ['react', /^@myorg\//],
alwaysBundle: ['some-package'],
onlyAllowBundle: ['cac', 'bumpp'],
onlyBundle: ['cac', 'bumpp'],
skipNodeModulesBundle: true,
},
})
Expand Down Expand Up @@ -71,15 +71,15 @@ export default defineConfig({
})
```

### `deps.onlyAllowBundle`
### `deps.onlyBundle`

Whitelist of dependencies allowed to be bundled from node_modules. Throws an error if any unlisted dependency is bundled:

```ts
export default defineConfig({
entry: ['src/index.ts'],
deps: {
onlyAllowBundle: [
onlyBundle: [
'cac', // Allow bundling cac
'bumpp', // Allow bundling bumpp
/^my-utils/, // Regex patterns supported
Expand Down Expand Up @@ -235,7 +235,8 @@ tsdown --deps.skip-node-modules-bundle
|---|---|
| `external` | `deps.neverBundle` |
| `noExternal` | `deps.alwaysBundle` |
| `inlineOnly` | `deps.onlyAllowBundle` |
| `inlineOnly` | `deps.onlyBundle` |
| `onlyAllowBundle` | `deps.onlyBundle` |
| `skipNodeModulesBundle` | `deps.skipNodeModulesBundle` |

## Examples by Use Case
Expand Down Expand Up @@ -359,7 +360,7 @@ export default defineConfig({
**Override (under `deps`):**
- `neverBundle` → Force external
- `alwaysBundle` → Force bundled
- `onlyAllowBundle` → Whitelist bundled deps
- `onlyBundle` → Whitelist bundled deps
- `skipNodeModulesBundle` → Skip all node_modules

**Declaration files:**
Expand Down
2 changes: 1 addition & 1 deletion src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export interface UserConfig {
*/
noExternal?: Arrayable<string | RegExp> | NoExternalFn
/**
* @deprecated Use `deps.onlyAllowBundle` instead.
* @deprecated Use `deps.onlyBundle` instead.
*/
inlineOnly?: Arrayable<string | RegExp> | false
/**
Expand Down
Loading
Loading