mirror of
https://github.com/egoist/tsup.git
synced 2025-12-08 20:35:58 +00:00
fix: make sure sources are relative path in sourcemap, closes #603
This commit is contained in:
parent
38886519bd
commit
637ec281ab
@ -3,6 +3,7 @@
|
||||
*/
|
||||
import { JscConfig } from '@swc/core'
|
||||
import { Plugin } from 'esbuild'
|
||||
import path from 'path'
|
||||
import { Logger } from '../log'
|
||||
import { localRequire } from '../utils'
|
||||
|
||||
@ -42,13 +43,26 @@ export const swcPlugin = ({ logger }: { logger: Logger }): Plugin => {
|
||||
|
||||
const result = await swc.transformFile(args.path, {
|
||||
jsc,
|
||||
sourceMaps: 'inline',
|
||||
sourceMaps: true,
|
||||
configFile: false,
|
||||
swcrc: false,
|
||||
})
|
||||
|
||||
let code = result.code
|
||||
if (result.map) {
|
||||
const map: { sources: string[] } = JSON.parse(result.map)
|
||||
// Make sure sources are relative path
|
||||
map.sources = map.sources.map((source) => {
|
||||
return path.isAbsolute(source)
|
||||
? path.relative(path.dirname(args.path), source)
|
||||
: source
|
||||
})
|
||||
code += `//# sourceMappingURL=data:application/json;base64,${Buffer.from(
|
||||
JSON.stringify(map)
|
||||
).toString('base64')}`
|
||||
}
|
||||
return {
|
||||
contents: result.code,
|
||||
contents: code,
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
@ -819,3 +819,23 @@ test('native-node-module plugin should handle *.node(.js) import properly', asyn
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
test('proper sourcemap sources path when swc is enabled', async () => {
|
||||
const { getFileContent } = await run(
|
||||
getTestName(),
|
||||
{
|
||||
'input.ts': `export const hi = 'hi'`,
|
||||
'tsconfig.json': JSON.stringify({
|
||||
compilerOptions: {
|
||||
emitDecoratorMetadata: true,
|
||||
},
|
||||
}),
|
||||
},
|
||||
{
|
||||
entry: ['input.ts'],
|
||||
flags: ['--sourcemap'],
|
||||
}
|
||||
)
|
||||
const map = await getFileContent('dist/input.js.map')
|
||||
expect(map).toContain(`["../input.ts"]`)
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user