From 80d377043f26aeaa1438591fc817adbecf6f4ee5 Mon Sep 17 00:00:00 2001 From: hyrious Date: Wed, 12 Jul 2023 11:46:36 +0800 Subject: [PATCH 1/2] fix: correct sourcemap when enabled treeshake closes #890 --- src/plugins/tree-shaking.ts | 4 ++-- test/index.test.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/plugins/tree-shaking.ts b/src/plugins/tree-shaking.ts index 935d24a6..8e3602dd 100644 --- a/src/plugins/tree-shaking.ts +++ b/src/plugins/tree-shaking.ts @@ -33,7 +33,7 @@ export const treeShakingPlugin = ({ return false }, load(id) { - if (id === info.path) return code + if (id === info.path) return { code, map: info.map } }, }, ], @@ -47,7 +47,7 @@ export const treeShakingPlugin = ({ interop: 'auto', format: this.format, file: 'out.js', - sourcemap: !!this.options.sourcemap, + sourcemap: this.options.sourcemap ? 'hidden' : false, name }) diff --git a/test/index.test.ts b/test/index.test.ts index df2c19d7..a0d17953 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -1364,3 +1364,18 @@ test('should emit a declaration file per format (type: module)', async () => { }); expect(outFiles).toEqual(['input.cjs', 'input.d.cts', 'input.d.ts', 'input.js']) }); + +test.only('should emit correct sourcemap when enabled treeshake', async () => { + const { getFileContent } = await run(getTestName(), { + 'input.ts': `if (true) function foo() { return 1 }; foo()`, + 'tsup.config.ts': ` + export default { + entry: ['src/input.ts'], + format: ['esm'], + treeshake: true, + sourcemap: true, + }`, + }) + const content = await getFileContent('dist/input.mjs'); + expect(content).not.toContain('//# sourceMappingURL=out.js.map'); +}); From 60f335f394b75942e2936ed6f2e52f6ca1d4ed8e Mon Sep 17 00:00:00 2001 From: hyrious Date: Fri, 14 Jul 2023 23:16:05 +0800 Subject: [PATCH 2/2] remove test.only() --- test/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.test.ts b/test/index.test.ts index a0d17953..f05c83d3 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -1365,7 +1365,7 @@ test('should emit a declaration file per format (type: module)', async () => { expect(outFiles).toEqual(['input.cjs', 'input.d.cts', 'input.d.ts', 'input.js']) }); -test.only('should emit correct sourcemap when enabled treeshake', async () => { +test('should emit correct sourcemap when enabled treeshake', async () => { const { getFileContent } = await run(getTestName(), { 'input.ts': `if (true) function foo() { return 1 }; foo()`, 'tsup.config.ts': `