Skip to content

Commit

Permalink
fix: generate sourcemap
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Aug 24, 2021
1 parent ade6f9f commit 0f8c3bf
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
"dependencies": {
"@antfu/utils": "^0.2.4",
"@rollup/pluginutils": "^4.1.1",
"magic-string": "^0.25.7",
"unplugin": "^0.0.8"
},
"devDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion src/core/transform.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import MagicString from 'magic-string'
import { ImportInfo, TransformOptions } from '../types'

const excludeRegex = [
Expand Down Expand Up @@ -41,5 +42,13 @@ export function transform(code: string, id: string, { matchRE, imports }: Transf
})
.join('')

return importStatements + code
const s = new MagicString(code)
s.prependLeft(0, importStatements)

return {
code: s.toString(),
get map() {
return s.generateMap()
},
}
}
2 changes: 1 addition & 1 deletion test/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('transform', () => {
for (const file of files) {
it(file, async() => {
const fixture = await fs.readFile(resolve(root, file), 'utf-8')
expect(transform(fixture, file, options)).toMatchSnapshot()
expect(transform(fixture, file, options).code).toMatchSnapshot()
})
}
})
Expand Down

0 comments on commit 0f8c3bf

Please sign in to comment.