Skip to content

Commit d09d14d

Browse files
elonmitchellyyx990803
authored andcommitted
fix: generate consistent hash, fix the snapshot testing issue on windows (#1387)
1 parent 03b13a7 commit d09d14d

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

lib/loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ module.exports = function (content) {
8585
this.options.context ||
8686
process.cwd()
8787
const sourceRoot = path.dirname(path.relative(context, filePath))
88-
const shortFilePath = path.relative(context, filePath).replace(/^(\.\.[\\\/])+/, '')
88+
const shortFilePath = path.relative(context, filePath).replace(/^(\.\.[\\\/])+/, '').replace(/\\/g, '/')
8989
const moduleId = 'data-v-' + hash(isProduction ? (shortFilePath + '\n' + content) : shortFilePath)
9090

9191
let cssLoaderOptions = ''

lib/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const splitRE = /\r?\n/g
77
const emptyRE = /^(?:\/\/)?\s*$/
88

99
module.exports = (content, filename, needMap, sourceRoot, needCSSMap) => {
10-
const cacheKey = hash(filename + content)
10+
const cacheKey = hash((filename + content).replace(/\\/g, '/'))
1111
let output = cache.get(cacheKey)
1212
if (output) return output
1313
output = compiler.parseComponent(content, { pad: 'line' })

test/test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const globalConfig = {
3636
}
3737

3838
function genId (file) {
39-
return hash(path.join('test', 'fixtures', file))
39+
return hash(path.join('test', 'fixtures', file).replace(/\\/g, '/'))
4040
}
4141

4242
function bundle (options, cb, wontThrowError) {
@@ -129,7 +129,7 @@ describe('vue-loader', () => {
129129
test({
130130
entry: './test/fixtures/basic.vue'
131131
}, (window, module, rawModule) => {
132-
expect(module.__file).to.equal(path.normalize('test/fixtures/basic.vue'))
132+
expect(module.__file).to.equal(path.normalize('test/fixtures/basic.vue').replace(/\\/g, '/'))
133133
done()
134134
})
135135
})

0 commit comments

Comments
 (0)