@@ -29,7 +29,8 @@ import {
29
29
createGetCanonicalFileName ,
30
30
getId ,
31
31
getImportedName ,
32
- normalizePath
32
+ normalizePath ,
33
+ joinPaths
33
34
} from './utils'
34
35
import { ScriptCompileContext , resolveParserPlugins } from './context'
35
36
import { ImportBinding , SFCScriptCompileOptions } from '../compileScript'
@@ -38,7 +39,7 @@ import { parse as babelParse } from '@babel/parser'
38
39
import { parse } from '../parse'
39
40
import { createCache } from '../cache'
40
41
import type TS from 'typescript'
41
- import path from 'path'
42
+ import { extname , dirname } from 'path'
42
43
43
44
/**
44
45
* TypeResolveContext is compatible with ScriptCompileContext
@@ -718,7 +719,7 @@ function importSourceToScope(
718
719
let resolved
719
720
if ( source . startsWith ( '.' ) ) {
720
721
// relative import - fast path
721
- const filename = normalizePath ( path . join ( scope . filename , '..' , source ) )
722
+ const filename = joinPaths ( scope . filename , '..' , source )
722
723
resolved = resolveExt ( filename , fs )
723
724
} else {
724
725
// module or aliased import - use full TS resolution, only supported in Node
@@ -741,9 +742,10 @@ function importSourceToScope(
741
742
resolved = resolveWithTS ( scope . filename , source , fs )
742
743
}
743
744
if ( resolved ) {
745
+ resolved = normalizePath ( resolved )
744
746
// (hmr) register dependency file on ctx
745
747
; ( ctx . deps || ( ctx . deps = new Set ( ) ) ) . add ( resolved )
746
- return fileToScope ( ctx , normalizePath ( resolved ) )
748
+ return fileToScope ( ctx , resolved )
747
749
} else {
748
750
return ctx . error (
749
751
`Failed to resolve import source ${ JSON . stringify ( source ) } .` ,
@@ -761,8 +763,8 @@ function resolveExt(filename: string, fs: FS) {
761
763
tryResolve ( filename ) ||
762
764
tryResolve ( filename + `.ts` ) ||
763
765
tryResolve ( filename + `.d.ts` ) ||
764
- tryResolve ( filename + `/ index.ts`) ||
765
- tryResolve ( filename + `/ index.d.ts`)
766
+ tryResolve ( joinPaths ( filename , ` index.ts`) ) ||
767
+ tryResolve ( joinPaths ( filename , ` index.d.ts`) )
766
768
)
767
769
}
768
770
@@ -800,7 +802,7 @@ function resolveWithTS(
800
802
const parsed = ts . parseJsonConfigFileContent (
801
803
ts . readConfigFile ( configPath , fs . readFile ) . config ,
802
804
parseConfigHost ,
803
- path . dirname ( configPath ) ,
805
+ dirname ( configPath ) ,
804
806
undefined ,
805
807
configPath
806
808
)
@@ -870,7 +872,7 @@ function parseFile(
870
872
content : string ,
871
873
parserPlugins ?: SFCScriptCompileOptions [ 'babelParserPlugins' ]
872
874
) : Statement [ ] {
873
- const ext = path . extname ( filename )
875
+ const ext = extname ( filename )
874
876
if ( ext === '.ts' || ext === '.tsx' ) {
875
877
return babelParse ( content , {
876
878
plugins : resolveParserPlugins ( ext . slice ( 1 ) , parserPlugins ) ,
0 commit comments