Skip to content

Commit d5b8015

Browse files
authored
fix(exports): scope inlined dependencies to configs with exports (#1040)
1 parent 2471598 commit d5b8015

2 files changed

Lines changed: 40 additions & 4 deletions

File tree

src/features/pkg/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,9 @@ export async function bundleDone(
8080
}
8181

8282
const chunks: ChunksByFormat = {}
83-
const inlinedDeps = mergeInlinedDeps(ctx.bundles)
84-
for (const bundle of ctx.bundles) {
85-
if (!bundle.config.exports) continue
86-
83+
const exportsBundles = ctx.bundles.filter((bundle) => bundle.config.exports)
84+
const inlinedDeps = mergeInlinedDeps(exportsBundles)
85+
for (const bundle of exportsBundles) {
8786
chunks[bundle.config.format] ||= []
8887
chunks[bundle.config.format]!.push(...bundle.chunks)
8988
}

tests/e2e.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,43 @@ describe('deps', () => {
538538
)
539539
expect(pkg.inlinedDependencies).toBeUndefined()
540540
})
541+
542+
test('should not include inlined deps from configs without exports', async (context) => {
543+
const { testDir } = await testBuild({
544+
context,
545+
files: {
546+
...node_modules,
547+
'index.ts': `export { lib } from 'my-lib'`,
548+
'standalone.ts': `import { lib } from 'my-lib'\nconsole.log(lib)`,
549+
'package.json': JSON.stringify({
550+
name: 'test-pkg',
551+
version: '1.0.0',
552+
dependencies: { 'my-lib': '1.2.3' },
553+
}),
554+
'tsdown.config.ts': `export default [
555+
{ entry: ['index.ts'], format: ['esm'], exports: true, dts: false },
556+
{
557+
entry: ['standalone.ts'],
558+
format: ['cjs'],
559+
outDir: 'dist/standalone',
560+
dts: false,
561+
deps: { alwaysBundle: [/.*/] },
562+
},
563+
]`,
564+
},
565+
options: {
566+
entry: undefined,
567+
config: 'tsdown.config.ts',
568+
dts: false,
569+
},
570+
snapshot: false,
571+
})
572+
573+
const pkg = JSON.parse(
574+
await readFile(path.join(testDir, 'package.json'), 'utf8'),
575+
)
576+
expect(pkg.inlinedDependencies).toBeUndefined()
577+
})
541578
})
542579
})
543580

0 commit comments

Comments
 (0)