Skip to content

Commit 290309a

Browse files
authored
fix: keep JS dependencies external with emitJs (#358)
1 parent fe1cf33 commit 290309a

6 files changed

Lines changed: 19 additions & 2 deletions

File tree

‎.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
node_modules
22
!tests/fixtures/cjs-dts-dep-warning/node_modules
3+
!tests/fixtures/emit-js-untyped-dep/node_modules
34
dist
45

56
*.log

‎src/resolver.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
RE_DTS,
1010
RE_JS,
1111
RE_JSON,
12+
RE_NODE_MODULES,
1213
RE_TS,
1314
} from './filename.ts'
1415
import type { OptionsResolved } from './options.ts'
@@ -38,8 +39,9 @@ export function createDtsResolvePlugin({
3839
return (
3940
RE_TS.test(id) ||
4041
RE_JSON.test(id) ||
41-
// JS sources get declarations too with `emitJs`
42-
(emitJs && RE_JS.test(id)) ||
42+
// JS sources get declarations too with `emitJs`. Dependencies are
43+
// excluded: `generate.ts` never emits declarations for them.
44+
(emitJs && RE_JS.test(id) && !RE_NODE_MODULES.test(id)) ||
4345
languageContext.isCustomLanguageFile(id)
4446
)
4547
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from "untyped-dep"

‎tests/fixtures/emit-js-untyped-dep/node_modules/untyped-dep/index.js‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/fixtures/emit-js-untyped-dep/node_modules/untyped-dep/package.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎tests/index.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,17 @@ test('dtsOnly keeps global augmentations of side-effect imports', async () => {
305305
expect(snapshot).toContain('declare module "foobar"')
306306
})
307307

308+
test('keeps untyped JS dependencies external with emitJs', async () => {
309+
const root = path.resolve(dirname, 'fixtures/emit-js-untyped-dep')
310+
311+
const { chunks } = await rolldownBuild(
312+
[path.join(root, 'index.ts')],
313+
[dts({ emitJs: true, tsconfig: false, dtsOnly: true })],
314+
{ cwd: root },
315+
)
316+
expect(chunks[0].code).toContain('from "untyped-dep"')
317+
})
318+
308319
describe('dts input', () => {
309320
test('input array', async () => {
310321
const { snapshot, chunks } = await rolldownBuild(

0 commit comments

Comments
 (0)