Skip to content
This repository has been archived by the owner on Aug 16, 2022. It is now read-only.

Commit

Permalink
fix: normalize source map file path on windows (#83)
Browse files Browse the repository at this point in the history
* chore: upgrade packages, cleanup type errors

Took the opportunity to update TS to latest version, cleanup all type errors.

* fix: normalize source map file path on windows

Updated test snapshot file.
1. Sources paths was cleaned up by upgrading component-compiler-utils.
2. Styles mapping changes are due to newer version of postcss (from component-compiler-utils).
3. postcss rawResult is removed.
 * The rawResult contains ast tree which postcss always prepends current working directory to referencing file name.
 * This is a main pain point of maintaining this snapshot test.
 * The correctness of rawResult is responsibility of postcss, not vue compiler. So it's irrelevant to test it here.

This is a companion PR for vuejs/component-compiler-utils#51
  • Loading branch information
3cp authored and znck committed Feb 1, 2019
1 parent afa1cd4 commit c4bcd40
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 1,094 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"rollup-plugin-image": "^1.0.2",
"rollup-plugin-node-resolve": "^3.3.0",
"ts-jest": "^22.4.2",
"typescript": "^2.7.2",
"typescript": "^3.2.4",
"typescript-eslint-parser": "^15.0.0",
"vue": "^2.5.16",
"vue-template-compiler": "^2.5.16"
Expand All @@ -57,7 +57,7 @@
"vue-template-compiler": "*"
},
"dependencies": {
"@vue/component-compiler-utils": "^2.1.0",
"@vue/component-compiler-utils": "^2.5.2",
"clean-css": "^4.1.11",
"hash-sum": "^1.0.2",
"postcss-modules-sync": "^1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/assembler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export function assembleFromSource(
script = script || { source: 'export default {}' }
template = template || { source: '' }
let map = undefined
const mapGenerator = new SourceMapGenerator({ file: filename })
const mapGenerator = new SourceMapGenerator({ file: filename.replace(/\\/g, '/') })

const hasScopedStyle = styles.some(style => style.scoped === true)
const hasStyle = styles.some(style => style.source || style.module)
Expand Down
40 changes: 23 additions & 17 deletions src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,23 @@ export class SFCCompiler {
? hash(path.basename(filename) + source)
: hash(filename + source))

const template =
descriptor.template && this.compileTemplate(filename, descriptor.template)
const template = descriptor.template
? this.compileTemplate(filename, descriptor.template)
: undefined

const styles = descriptor.styles.map(style =>
this.compileStyle(filename, scopeId, style)
)

const { script: rawScript, customBlocks } = descriptor
const script = rawScript && {
code: rawScript.src
? this.read(rawScript.src, filename)
: rawScript.content,
map: rawScript.map
}
const script = rawScript
? {
code: rawScript.src
? this.read(rawScript.src, filename)
: rawScript.content,
map: rawScript.map
}
: undefined

return {
scopeId,
Expand Down Expand Up @@ -140,8 +143,9 @@ export class SFCCompiler {
? hash(path.basename(filename) + source)
: hash(filename + source))

const template =
descriptor.template && this.compileTemplate(filename, descriptor.template)
const template = descriptor.template
? this.compileTemplate(filename, descriptor.template)
: undefined

const styles = await Promise.all(
descriptor.styles.map(style =>
Expand All @@ -150,12 +154,14 @@ export class SFCCompiler {
)

const { script: rawScript, customBlocks } = descriptor
const script = rawScript && {
code: rawScript.src
? this.read(rawScript.src, filename)
: rawScript.content,
map: rawScript.map
}
const script = rawScript
? {
code: rawScript.src
? this.read(rawScript.src, filename)
: rawScript.content,
map: rawScript.map
}
: undefined

return {
scopeId,
Expand Down Expand Up @@ -260,7 +266,7 @@ export class SFCCompiler {
},

prepare: result => ({
media: style.attrs.media,
media: typeof style.attrs.media === 'string' ? style.attrs.media : undefined,
scoped: style.scoped,
moduleName: style.module === true ? '$style' : <any>style.module,
module: tokens,
Expand Down
Loading

0 comments on commit c4bcd40

Please sign in to comment.