@@ -25,7 +25,8 @@ import {
25
25
UNKNOWN_TYPE ,
26
26
createGetCanonicalFileName ,
27
27
getId ,
28
- getImportedName
28
+ getImportedName ,
29
+ normalizePath
29
30
} from './utils'
30
31
import { ScriptCompileContext , resolveParserPlugins } from './context'
31
32
import { ImportBinding , SFCScriptCompileOptions } from '../compileScript'
@@ -34,7 +35,7 @@ import { parse as babelParse } from '@babel/parser'
34
35
import { parse } from '../parse'
35
36
import { createCache } from '../cache'
36
37
import type TS from 'typescript'
37
- import { join , extname , dirname } from 'path'
38
+ import path from 'path'
38
39
39
40
/**
40
41
* TypeResolveContext is compatible with ScriptCompileContext
@@ -577,8 +578,7 @@ function resolveGlobalScope(ctx: TypeResolveContext): TypeScope[] | undefined {
577
578
throw new Error ( '[vue/compiler-sfc] globalTypeFiles requires fs access.' )
578
579
}
579
580
return ctx . options . globalTypeFiles . map ( file =>
580
- // TODO: differentiate ambient vs non-ambient module
581
- fileToScope ( file , fs , ctx . options . babelParserPlugins , true )
581
+ fileToScope ( normalizePath ( file ) , fs , ctx . options . babelParserPlugins , true )
582
582
)
583
583
}
584
584
}
@@ -616,7 +616,7 @@ function resolveTypeFromImport(
616
616
617
617
if ( source . startsWith ( '.' ) ) {
618
618
// relative import - fast path
619
- const filename = join ( containingFile , '..' , source )
619
+ const filename = path . join ( containingFile , '..' , source )
620
620
resolved = resolveExt ( filename , fs )
621
621
} else {
622
622
// module or aliased import - use full TS resolution, only supported in Node
@@ -642,6 +642,8 @@ function resolveTypeFromImport(
642
642
}
643
643
644
644
if ( resolved ) {
645
+ resolved = normalizePath ( resolved )
646
+
645
647
// (hmr) register dependency file on ctx
646
648
; ( ctx . deps || ( ctx . deps = new Set ( ) ) ) . add ( resolved )
647
649
@@ -694,7 +696,8 @@ function resolveWithTS(
694
696
let options : TS . CompilerOptions
695
697
let cache : TS . ModuleResolutionCache | undefined
696
698
if ( configPath ) {
697
- const cached = tsConfigCache . get ( configPath )
699
+ const normalizedConfigPath = normalizePath ( configPath )
700
+ const cached = tsConfigCache . get ( normalizedConfigPath )
698
701
if ( ! cached ) {
699
702
// The only case where `fs` is NOT `ts.sys` is during tests.
700
703
// parse config host requires an extra `readDirectory` method
@@ -709,7 +712,7 @@ function resolveWithTS(
709
712
const parsed = ts . parseJsonConfigFileContent (
710
713
ts . readConfigFile ( configPath , fs . readFile ) . config ,
711
714
parseConfigHost ,
712
- dirname ( configPath ) ,
715
+ path . dirname ( configPath ) ,
713
716
undefined ,
714
717
configPath
715
718
)
@@ -719,7 +722,7 @@ function resolveWithTS(
719
722
createGetCanonicalFileName ( ts . sys . useCaseSensitiveFileNames ) ,
720
723
options
721
724
)
722
- tsConfigCache . set ( configPath , { options, cache } )
725
+ tsConfigCache . set ( normalizedConfigPath , { options, cache } )
723
726
} else {
724
727
; ( { options, cache } = cached )
725
728
}
@@ -777,7 +780,7 @@ function parseFile(
777
780
content : string ,
778
781
parserPlugins ?: SFCScriptCompileOptions [ 'babelParserPlugins' ]
779
782
) : Statement [ ] {
780
- const ext = extname ( filename )
783
+ const ext = path . extname ( filename )
781
784
if ( ext === '.ts' || ext === '.tsx' ) {
782
785
return babelParse ( content , {
783
786
plugins : resolveParserPlugins ( ext . slice ( 1 ) , parserPlugins ) ,
0 commit comments