Skip to content

Commit

Permalink
fix: high-resolution source map
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Jul 7, 2023
1 parent a6a55e7 commit f35a0da
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
7 changes: 3 additions & 4 deletions scripts/postbuild.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { basename, dirname, resolve } from 'path'
import { readFile, writeFile } from 'fs/promises'
import { fileURLToPath } from 'url'
import { basename, dirname, resolve } from 'node:path'
import { readFile, writeFile } from 'node:fs/promises'
import { fileURLToPath } from 'node:url'
import fg from 'fast-glob'

// fix cjs exports
Expand All @@ -10,7 +10,6 @@ const files = await fg('*.js', {
cwd: resolve(dirname(fileURLToPath(import.meta.url)), '../dist'),
})
for (const file of files) {
// eslint-disable-next-line no-console
console.log('[postbuild]', basename(file))
let code = await readFile(file, 'utf8')
code = code.replace('exports.default =', 'module.exports =')
Expand Down
18 changes: 9 additions & 9 deletions src/core/style.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/* eslint-disable unicorn/better-regex */

import { init, parse } from 'es-module-lexer'
import MagicString from 'magic-string'

Expand All @@ -16,7 +14,7 @@ const formatMap = {
esm: 'es',
}

const multilineCommentsRE = /\/\*\s(.|[\r\n])*?\*\//gm
const multilineCommentsRE = /\/\*\s(.|[\n\r])*?\*\//gm
const singlelineCommentsRE = /\/\/\s.*/g

function stripeComments(code: string) {
Expand All @@ -32,7 +30,7 @@ export const transformImportStyle = (
lib: string
format: FormatType
ignoreComponents: string[]
}
},
) => {
const { prefix, lib, format, ignoreComponents } = options
const statement = stripeComments(source.slice(specifier.ss, specifier.se))
Expand All @@ -51,14 +49,14 @@ export const transformImportStyle = (
if (useSource) {
styleImports.push(
`import '${lib}/${formatMap[format]}/components/${hyphenate(
component
)}/style/index'`
component,
)}/style/index'`,
)
} else {
styleImports.push(
`import '${lib}/${formatMap[format]}/components/${hyphenate(
component
)}/style/css'`
component,
)}/style/css'`,
)
}
}
Expand Down Expand Up @@ -100,6 +98,8 @@ export const transformStyle = async (source: string, options: Options) => {

return {
code: s.toString(),
map: options.sourceMap ? s.generateMap() : null,
get map() {
return s.generateMap({ hires: true, includeContent: true })
},
}
}
3 changes: 1 addition & 2 deletions tests/transform.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable unicorn/prefer-string-replace-all */
import { resolve } from 'node:path'
import glob from 'fast-glob'
import { describe, expect, it } from 'vitest'
Expand Down Expand Up @@ -42,7 +41,7 @@ describe('transform', () => {
plugin({
useSource,
ignoreComponents: ['AutoResizer'],
})
}),
)
expect(code).toMatchSnapshot()
})
Expand Down

0 comments on commit f35a0da

Please sign in to comment.