Skip to content

Commit deff72c

Browse files
committed
fix(deps): add skipNodeModulesBundle dep subpath e2e tests and fix docs
- Add e2e tests for skipNodeModulesBundle resolving dep subpaths (file and folder) - Remove incorrect "skip resolving" wording from docs (it resolves but skips bundling) - Fix typo in anchor: #deps-skipnodemodulebundle → #deps-skipnodemodulesbundle
1 parent 31e90c1 commit deff72c

File tree

9 files changed

+94
-21
lines changed

9 files changed

+94
-21
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`, `peerDepe
3333

3434
**Key options:**
3535

36-
| Option | What it does |
37-
| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
38-
| [`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. |
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`. |
36+
| Option | What it does |
37+
| ------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
38+
| [`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. |
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-skipnodemodulesbundle) | Skip bundling everything from `node_modules`. |
4242

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

docs/options/dependencies.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default defineConfig({
3838

3939
### `deps.skipNodeModulesBundle`
4040

41-
If you want to **skip resolving and bundling all dependencies from `node_modules`**, you can enable `skipNodeModulesBundle`:
41+
If you want to **skip bundling all dependencies from `node_modules`**, you can enable `skipNodeModulesBundle`:
4242

4343
```ts [tsdown.config.ts]
4444
import { defineConfig } from 'tsdown'
@@ -50,7 +50,7 @@ export default defineConfig({
5050
})
5151
```
5252

53-
This will prevent `tsdown` from parsing and bundling any dependencies from `node_modules`, regardless of how they are referenced in your code.
53+
This will prevent `tsdown` from bundling any dependencies from `node_modules`, regardless of how they are referenced in your code.
5454

5555
::: warning
5656
`skipNodeModulesBundle` cannot be used together with `alwaysBundle`. These options are mutually exclusive.
@@ -155,7 +155,7 @@ The following top-level options are deprecated. Please migrate to the `deps` nam
155155
- Use `deps.onlyBundle` to whitelist dependencies allowed to be bundled, and throw an error for any others.
156156
- Use `deps.neverBundle` to mark specific dependencies as external.
157157
- Use `deps.alwaysBundle` to force specific dependencies to be bundled.
158-
- Use `deps.skipNodeModulesBundle` to skip resolving and bundling all dependencies from `node_modules`.
158+
- Use `deps.skipNodeModulesBundle` to skip bundling all dependencies from `node_modules`.
159159
- **Declaration Files**:
160160
- The bundling logic for declaration files is now the same as for JavaScript.
161161
- Use `resolver: 'tsc'` for better compatibility with complex third-party types.

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-
| [`deps.onlyBundle`](../options/dependencies.md#deps-onlybundle) | 允许打包的依赖白名单。任何不在列表中的依赖如果出现在 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` 的内容。 |
36+
| 选项 | 说明 |
37+
| ------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
38+
| [`deps.onlyBundle`](../options/dependencies.md#deps-onlybundle) | 允许打包的依赖白名单。任何不在列表中的依赖如果出现在 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-skipnodemodulesbundle) | 跳过打包所有来自 `node_modules` 的内容。 |
4242

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

docs/zh-CN/options/dependencies.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default defineConfig({
3838

3939
### `deps.skipNodeModulesBundle`
4040

41-
如果您希望**跳过解析和打包所有来自 `node_modules` 的依赖**,可以启用 `skipNodeModulesBundle`
41+
如果您希望**跳过打包所有来自 `node_modules` 的依赖**,可以启用 `skipNodeModulesBundle`
4242

4343
```ts [tsdown.config.ts]
4444
import { defineConfig } from 'tsdown'
@@ -50,7 +50,7 @@ export default defineConfig({
5050
})
5151
```
5252

53-
这样,无论您的代码如何引用,`tsdown` 都不会解析或打包任何来自 `node_modules` 的依赖。
53+
这样,无论您的代码如何引用,`tsdown` 都不会打包任何来自 `node_modules` 的依赖。
5454

5555
::: warning
5656
`skipNodeModulesBundle` 不能与 `alwaysBundle` 一起使用,这两个选项互斥。
@@ -155,7 +155,7 @@ export default defineConfig({
155155
- 使用 `deps.onlyBundle` 设置允许被打包的依赖白名单,不在列表中的依赖会触发错误。
156156
- 使用 `deps.neverBundle` 将特定依赖标记为外部依赖。
157157
- 使用 `deps.alwaysBundle` 强制将特定依赖打包。
158-
- 使用 `deps.skipNodeModulesBundle` 跳过解析和打包所有来自 `node_modules` 的依赖。
158+
- 使用 `deps.skipNodeModulesBundle` 跳过打包所有来自 `node_modules` 的依赖。
159159
- **声明文件**
160160
- 声明文件的打包逻辑与 JavaScript 保持一致。
161161
- 使用 `resolver: 'tsc'` 可提升复杂第三方类型的兼容性。

skills/tsdown/references/option-dependencies.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default defineConfig({
9898

9999
### `deps.skipNodeModulesBundle`
100100

101-
Skip resolving and bundling ALL node_modules:
101+
Skip bundling ALL node_modules:
102102

103103
```ts
104104
export default defineConfig({
@@ -109,7 +109,7 @@ export default defineConfig({
109109
})
110110
```
111111

112-
**Result:** No dependencies from node_modules are parsed or bundled.
112+
**Result:** No dependencies from node_modules are bundled.
113113

114114
**Note:** Cannot be used together with `alwaysBundle`.
115115

src/features/deps.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ export function DepsPlugin(
309309
resolved &&
310310
(resolved.external || RE_NODE_MODULES.test(resolved.id))
311311
) {
312-
return true
312+
const resolvedDep = await resolveDepSubpath(id, resolved)
313+
return resolvedDep ? [true, resolvedDep] : true
313314
}
314315

315316
if (deps) {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## index.mjs
2+
3+
```mjs
4+
import { lt } from "my-dep/functions/lt.js";
5+
export { lt };
6+
7+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## index.mjs
2+
3+
```mjs
4+
import { folder } from "my-dep/folder/index.js";
5+
export { folder };
6+
7+
```

tests/e2e.test.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,64 @@ describe('resolve dep subpath without exports field', () => {
10321032

10331033
expect(fileMap['index.mjs']).toContain('my-dep/folder/index.js')
10341034
})
1035+
1036+
test('skipNodeModulesBundle dep/file should resolve to dep/file.js', async (context) => {
1037+
const node_modules = {
1038+
'node_modules/my-dep/package.json': JSON.stringify({
1039+
name: 'my-dep',
1040+
version: '1.0.0',
1041+
main: 'index.js',
1042+
}),
1043+
'node_modules/my-dep/index.js': `export const main = 1`,
1044+
'node_modules/my-dep/functions/lt.js': `export const lt = () => {}`,
1045+
}
1046+
1047+
const { fileMap } = await testBuild({
1048+
context,
1049+
files: {
1050+
...node_modules,
1051+
'index.ts': `export { lt } from 'my-dep/functions/lt'`,
1052+
'package.json': JSON.stringify({
1053+
name: 'test-pkg',
1054+
version: '1.0.0',
1055+
}),
1056+
},
1057+
options: {
1058+
deps: { skipNodeModulesBundle: true },
1059+
},
1060+
})
1061+
1062+
expect(fileMap['index.mjs']).toContain('my-dep/functions/lt.js')
1063+
})
1064+
1065+
test('skipNodeModulesBundle dep/folder should resolve to dep/folder/index.js', async (context) => {
1066+
const node_modules = {
1067+
'node_modules/my-dep/package.json': JSON.stringify({
1068+
name: 'my-dep',
1069+
version: '1.0.0',
1070+
main: 'index.js',
1071+
}),
1072+
'node_modules/my-dep/index.js': `export const main = 1`,
1073+
'node_modules/my-dep/folder/index.js': `export const folder = 42`,
1074+
}
1075+
1076+
const { fileMap } = await testBuild({
1077+
context,
1078+
files: {
1079+
...node_modules,
1080+
'index.ts': `export { folder } from 'my-dep/folder'`,
1081+
'package.json': JSON.stringify({
1082+
name: 'test-pkg',
1083+
version: '1.0.0',
1084+
}),
1085+
},
1086+
options: {
1087+
deps: { skipNodeModulesBundle: true },
1088+
},
1089+
})
1090+
1091+
expect(fileMap['index.mjs']).toContain('my-dep/folder/index.js')
1092+
})
10351093
})
10361094

10371095
test('.node file bundle', async (context) => {

0 commit comments

Comments
 (0)