Skip to content

Commit 7f50966

Browse files
committed
feat: rename dependency options to deps namespace
Rename flat dependency options to a nested `deps` config namespace: - `external` → `deps.neverBundle` - `noExternal` → `deps.alwaysBundle` - `inlineOnly` → `deps.onlyAllowBundle` - `skipNodeModulesBundle` → `deps.skipNodeModulesBundle` Old options are deprecated but still work with warnings. CLI flag `--external` renamed to `--deps.never-bundle`.
1 parent d8ca26f commit 7f50966

30 files changed

+648
-306
lines changed

docs/guide/how-it-works.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ When you publish a library, your consumers install its `dependencies` and `peerD
3333

3434
**Key options:**
3535

36-
| Option | What it does |
37-
| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
38-
| [`inlineOnly`](../options/dependencies.md#strict-inline-control-with-inlineonly) | 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. |
39-
| [`external`](../options/dependencies.md#external) | Explicitly mark additional packages as external (never bundled). |
40-
| [`noExternal`](../options/dependencies.md#noexternal) | Force specific packages to be bundled, even if they're in `dependencies`. |
41-
| [`skipNodeModulesBundle`](../options/dependencies.md#skipping-node-modules-bundling) | Skip resolving and bundling everything from `node_modules`. |
36+
| Option | What it does |
37+
| ------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
38+
| [`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. |
39+
| [`deps.neverBundle`](../options/dependencies.md#deps-neverbundle) | Explicitly mark additional packages as external (never bundled). |
40+
| [`deps.alwaysBundle`](../options/dependencies.md#deps-alwaysbundle) | Force specific packages to be bundled, even if they're in `dependencies`. |
41+
| [`deps.skipNodeModulesBundle`](../options/dependencies.md#deps-skipnodemodulebundle) | Skip resolving and bundling everything from `node_modules`. |
4242

4343
See [Dependencies](../options/dependencies.md) for details.
4444

docs/options/dependencies.md

Lines changed: 63 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Dependencies
22

3-
When bundling with `tsdown`, dependencies are handled intelligently to ensure your library remains lightweight and easy to consume. Heres how `tsdown` processes different types of dependencies and how you can customize this behavior.
3+
When bundling with `tsdown`, dependencies are handled intelligently to ensure your library remains lightweight and easy to consume. Here's how `tsdown` processes different types of dependencies and how you can customize this behavior.
44

55
## Default Behavior
66

@@ -18,71 +18,96 @@ By default, `tsdown` **does not bundle dependencies** listed in your `package.js
1818

1919
In other words, only the `devDependencies` and phantom dependencies that are actually referenced in your project will be included in the bundle.
2020

21-
## Skipping Node Modules Bundling
21+
## The `deps` Option
2222

23-
If you want to **skip resolving and bundling all dependencies from `node_modules`**, you can enable the `skipNodeModulesBundle` option in your configuration:
23+
All dependency-related options are configured under the `deps` field:
2424

25-
```ts
25+
```ts [tsdown.config.ts]
26+
import { defineConfig } from 'tsdown'
27+
28+
export default defineConfig({
29+
deps: {
30+
neverBundle: ['lodash', /^@my-scope\//],
31+
alwaysBundle: ['some-package'],
32+
onlyAllowBundle: ['cac', 'bumpp'],
33+
skipNodeModulesBundle: true,
34+
},
35+
})
36+
```
37+
38+
### `deps.skipNodeModulesBundle`
39+
40+
If you want to **skip resolving and bundling all dependencies from `node_modules`**, you can enable `skipNodeModulesBundle`:
41+
42+
```ts [tsdown.config.ts]
2643
import { defineConfig } from 'tsdown'
2744

2845
export default defineConfig({
29-
skipNodeModulesBundle: true,
46+
deps: {
47+
skipNodeModulesBundle: true,
48+
},
3049
})
3150
```
3251

3352
This will prevent `tsdown` from parsing and bundling any dependencies from `node_modules`, regardless of how they are referenced in your code.
3453

35-
## Strict Inline Control with `inlineOnly`
54+
::: warning
55+
`skipNodeModulesBundle` cannot be used together with `alwaysBundle`. These options are mutually exclusive.
56+
:::
57+
58+
### `deps.onlyAllowBundle`
3659

37-
The `inlineOnly` 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.
60+
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.
3861

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

4265
export default defineConfig({
43-
inlineOnly: ['cac', 'bumpp'],
66+
deps: {
67+
onlyAllowBundle: ['cac', 'bumpp'],
68+
},
4469
})
4570
```
4671

4772
In this example, only `cac` and `bumpp` are allowed to be bundled. If any other `node_modules` dependency is imported, tsdown will throw an error with a message indicating which dependency was unexpectedly bundled and which files imported it.
4873

49-
### Behavior
74+
#### Behavior
5075

51-
- **`inlineOnly` 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.
52-
- **`inlineOnly` is `false`**: All warnings and checks about bundled dependencies are suppressed.
53-
- **`inlineOnly` is not set** (default): A warning is shown if any `node_modules` dependencies are bundled, suggesting you add the `inlineOnly` option or set it to `false` to suppress warnings.
76+
- **`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.
77+
- **`onlyAllowBundle` is `false`**: All warnings and checks about bundled dependencies are suppressed.
78+
- **`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.
5479

5580
::: tip
56-
Make sure to include all required sub-dependencies in the `inlineOnly` list as well, not just the top-level packages you directly import.
81+
Make sure to include all required sub-dependencies in the `onlyAllowBundle` list as well, not just the top-level packages you directly import.
5782
:::
5883

59-
## Customizing Dependency Handling
60-
61-
`tsdown` provides two options to override the default behavior:
62-
63-
### `external`
84+
### `deps.neverBundle`
6485

65-
The `external` option allows you to explicitly mark certain dependencies as external, ensuring they are not bundled into your library. For example:
86+
The `neverBundle` option allows you to explicitly mark certain dependencies as external, ensuring they are not bundled into your library. For example:
6687

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

7091
export default defineConfig({
71-
external: ['lodash', /^@my-scope\//],
92+
deps: {
93+
neverBundle: ['lodash', /^@my-scope\//],
94+
},
7295
})
7396
```
7497

7598
In this example, `lodash` and all packages under the `@my-scope` namespace will be treated as external.
7699

77-
### `noExternal`
100+
### `deps.alwaysBundle`
78101

79-
The `noExternal` option allows you to force certain dependencies to be bundled, even if they are listed in `dependencies` or `peerDependencies`. For example:
102+
The `alwaysBundle` option allows you to force certain dependencies to be bundled, even if they are listed in `dependencies` or `peerDependencies`. For example:
80103

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

84107
export default defineConfig({
85-
noExternal: ['some-package'],
108+
deps: {
109+
alwaysBundle: ['some-package'],
110+
},
86111
})
87112
```
88113

@@ -108,16 +133,27 @@ export default defineConfig({
108133
})
109134
```
110135

136+
## Migration from Deprecated Options
137+
138+
The following top-level options are deprecated. Please migrate to the `deps` namespace:
139+
140+
| Deprecated Option | New Option |
141+
|---|---|
142+
| `external` | `deps.neverBundle` |
143+
| `noExternal` | `deps.alwaysBundle` |
144+
| `inlineOnly` | `deps.onlyAllowBundle` |
145+
| `skipNodeModulesBundle` | `deps.skipNodeModulesBundle` |
146+
111147
## Summary
112148

113149
- **Default Behavior**:
114150
- `dependencies` and `peerDependencies` are treated as external and not bundled.
115151
- `devDependencies` and phantom dependencies are only bundled if they are actually used in your code.
116152
- **Customization**:
117-
- Use `inlineOnly` to whitelist dependencies allowed to be bundled, and throw an error for any others.
118-
- Use `external` to mark specific dependencies as external.
119-
- Use `noExternal` to force specific dependencies to be bundled.
120-
- Use `skipNodeModulesBundle` to skip resolving and bundling all dependencies from `node_modules`.
153+
- Use `deps.onlyAllowBundle` to whitelist dependencies allowed to be bundled, and throw an error for any others.
154+
- Use `deps.neverBundle` to mark specific dependencies as external.
155+
- Use `deps.alwaysBundle` to force specific dependencies to be bundled.
156+
- Use `deps.skipNodeModulesBundle` to skip resolving and bundling all dependencies from `node_modules`.
121157
- **Declaration Files**:
122158
- The bundling logic for declaration files is now the same as for JavaScript.
123159
- Use `resolver: 'tsc'` for better compatibility with complex third-party types.

docs/reference/cli.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,26 @@ Clean the output directory before building. This removes all files in the output
6868

6969
See also [Cleaning](../options/cleaning.md).
7070

71-
## `--external <module>`
71+
## `--deps.never-bundle <module>`
7272

7373
Mark a module as external. This prevents the specified module from being included in the bundle.
7474

7575
See also [Dependencies](../options/dependencies.md).
7676

77+
## `--deps.skip-node-modules-bundle`
78+
79+
Skip resolving and bundling all dependencies from `node_modules`.
80+
81+
See also [Dependencies](../options/dependencies.md).
82+
83+
## `--external <module>` {#external}
84+
85+
::: warning Deprecated
86+
Use `--deps.never-bundle` instead.
87+
:::
88+
89+
Alias for `--deps.never-bundle`.
90+
7791
## `--minify`
7892

7993
Enable minification of the output bundle to reduce file size. Minification removes unnecessary characters and optimizes the code for production.

docs/zh-CN/guide/how-it-works.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ tsdown 读取你的 `package.json` 和 `tsconfig.json` 来推断合理的默认
3333

3434
**主要选项:**
3535

36-
| 选项 | 说明 |
37-
| ------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------- |
38-
| [`inlineOnly`](../options/dependencies.md#strict-inline-control-with-inlineonly) | 允许打包的依赖白名单。任何不在列表中的依赖如果出现在 bundle 中将触发错误。适用于防止大型项目中的意外内联。 |
39-
| [`external`](../options/dependencies.md#external) | 显式将额外的包标记为外部依赖(不打包)。 |
40-
| [`noExternal`](../options/dependencies.md#noexternal) | 强制打包特定的包,即使它们在 `dependencies` 中。 |
41-
| [`skipNodeModulesBundle`](../options/dependencies.md#skipping-node-modules-bundling) | 跳过解析和打包所有来自 `node_modules` 的内容。 |
36+
| 选项 | 说明 |
37+
| ------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
38+
| [`deps.onlyAllowBundle`](../options/dependencies.md#deps-onlyallowbundle) | 允许打包的依赖白名单。任何不在列表中的依赖如果出现在 bundle 中将触发错误。适用于防止大型项目中的意外内联。 |
39+
| [`deps.neverBundle`](../options/dependencies.md#deps-neverbundle) | 显式将额外的包标记为外部依赖(不打包)。 |
40+
| [`deps.alwaysBundle`](../options/dependencies.md#deps-alwaysbundle) | 强制打包特定的包,即使它们在 `dependencies` 中。 |
41+
| [`deps.skipNodeModulesBundle`](../options/dependencies.md#deps-skipnodemodulebundle) | 跳过解析和打包所有来自 `node_modules` 的内容。 |
4242

4343
详见[依赖](../options/dependencies.md)
4444

0 commit comments

Comments
 (0)