Skip to content

Commit

Permalink
fix: do not emit sourcemap for types (#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi authored Feb 8, 2025
1 parent 58a1b86 commit 334d640
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/rollup/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export async function buildInputConfig(
} as const

const hasBrowserslistConfig = !!(browserslistConfig && !hasSpecifiedTsTarget)
const sourceMap = bundleConfig.sourcemap
const swcOptions = {
jsc: {
...(!hasSpecifiedTsTarget &&
Expand All @@ -162,11 +163,11 @@ export async function buildInputConfig(
...(shouldMinify && {
minify: {
...swcMinifyOptions,
sourceMap: bundleConfig.sourcemap,
sourceMap: sourceMap,
},
}),
},
sourceMaps: bundleConfig.sourcemap,
sourceMaps: sourceMap,
inlineSourcesContent: false,
isModule: true,
...(hasBrowserslistConfig && {
Expand Down
2 changes: 1 addition & 1 deletion src/rollup/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export async function buildOutputConfigs(
interop: 'auto',
freeze: false,
strict: false,
sourcemap: bundleConfig.sourcemap,
sourcemap: bundleConfig.sourcemap && !dts,
manualChunks: createSplitChunks(
pluginContext.moduleDirectiveLayerMap,
entryFiles,
Expand Down
5 changes: 3 additions & 2 deletions test/fixtures/integration-test-template/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { describe, it } from 'vitest'
import { createJob, assertContainFiles } from '../../testing-utils'
import { createJob, getFileNamesFromDirectory } from '../../testing-utils'

describe('integration - <name>', () => {
const { distDir } = createJob({
directory: __dirname,
})
it('should work', async () => {
assertContainFiles(distDir, ['index.js'])
const files = getFileNamesFromDirectory(distDir)
// expect(files).toEqual([])
})
})
13 changes: 13 additions & 0 deletions test/integration/sourcemap-dts/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { expect, describe, it } from 'vitest'
import { createJob, getFileNamesFromDirectory } from '../../testing-utils'

describe('integration - sourcemap-dts', () => {
const { distDir } = createJob({
directory: __dirname,
args: ['--sourcemap'],
})
it('should not generate sourcemap for types', async () => {
const files = await getFileNamesFromDirectory(distDir)
expect(files).toEqual(['index.d.ts', 'index.js', 'index.js.map'])
})
})
11 changes: 11 additions & 0 deletions test/integration/sourcemap-dts/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "sourcemap-dts",
"main": "./dist/index.js",
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
}
3 changes: 3 additions & 0 deletions test/integration/sourcemap-dts/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function foo() {
return 'foo'
}
9 changes: 6 additions & 3 deletions test/testing-utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@ export { runCli } from './cli'
export { createJob } from './integration'

export async function getFileNamesFromDirectory(directory: string) {
const files = await glob(['**/*.{,c,m}js', '**/*.{,c,m}d.ts'], {
cwd: directory,
})
const files = await glob(
['**/*.{,c,m}js', '**/*.{,c,m}d.ts', '**/*.{,c,m}js.map'],
{
cwd: directory,
},
)

return files.sort().map((file) => normalizePath(file))
}
Expand Down

0 comments on commit 334d640

Please sign in to comment.