@@ -73,18 +73,15 @@ export function getRenderOptions(opts: d.PluginOptions, sourceText: string, file
73
73
if ( typeof url === 'string' ) {
74
74
if ( url . startsWith ( '~' ) ) {
75
75
try {
76
- const orgUrl = url . substr ( 1 ) ;
77
- const parts = orgUrl . split ( '/' ) ;
78
- const moduleId = parts . shift ( ) ;
79
- const filePath = parts . join ( '/' ) ;
76
+ const m = getModuleId ( url ) ;
80
77
81
- if ( moduleId ) {
78
+ if ( m . moduleId ) {
82
79
context . sys . resolveModuleId ( {
83
- moduleId,
84
- containingFile : fileName
80
+ moduleId : m . moduleId ,
81
+ containingFile : m . filePath
85
82
} ) . then ( ( resolved ) => {
86
83
if ( resolved . pkgDirPath ) {
87
- const resolvedPath = path . join ( resolved . pkgDirPath , filePath ) ;
84
+ const resolvedPath = path . join ( resolved . pkgDirPath , m . filePath ) ;
88
85
done ( {
89
86
file : context . sys . normalizePath ( resolvedPath )
90
87
} ) ;
@@ -153,6 +150,27 @@ export function normalizePath(str: string) {
153
150
return str ;
154
151
}
155
152
153
+ export function getModuleId ( orgImport : string ) {
154
+ if ( orgImport . startsWith ( '~' ) ) {
155
+ orgImport = orgImport . substring ( 1 ) ;
156
+ }
157
+ const splt = orgImport . split ( '/' ) ;
158
+ const m = {
159
+ moduleId : null as string ,
160
+ filePath : null as string ,
161
+ } ;
162
+
163
+ if ( orgImport . startsWith ( '@' ) && splt . length > 1 ) {
164
+ m . moduleId = splt . slice ( 0 , 2 ) . join ( '/' ) ;
165
+ m . filePath = splt . slice ( 2 ) . join ( '/' ) ;
166
+ } else {
167
+ m . moduleId = splt [ 0 ] ;
168
+ m . filePath = splt . slice ( 1 ) . join ( '/' ) ;
169
+ }
170
+
171
+ return m ;
172
+ } ;
173
+
156
174
const EXTENDED_PATH_REGEX = / ^ \\ \\ \? \\ / ;
157
175
const NON_ASCII_REGEX = / [ ^ \x00 - \x80 ] + / ;
158
176
const SLASH_REGEX = / \\ / g;
0 commit comments