Skip to content

Commit e705892

Browse files
authored
Update VueProgram.ts
1 parent 909ddf8 commit e705892

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

src/VueProgram.ts

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,33 @@ class VueProgram {
3838
*/
3939
public static resolveNonTsModuleName(moduleName: string, containingFile: string, basedir: string, options: ts.CompilerOptions) {
4040
const baseUrl = options.baseUrl ? options.baseUrl : basedir;
41-
const wildcard = options.wildcard ? options.wildcard : '@';
42-
const pattern = options.paths ? options.paths[`${wildcard}/*`] : undefined;
43-
const substitution = pattern ? options.paths[`${wildcard}/*`][0].replace('*', '') : 'src';
44-
const isWildcard = moduleName.substr(0, 2) === `${wildcard}/`;
45-
const isRelative = !path.isAbsolute(moduleName);
46-
47-
if (isWildcard) {
48-
moduleName = path.resolve(baseUrl, substitution, moduleName.substr(2));
49-
} else if (isRelative) {
50-
moduleName = path.resolve(path.dirname(containingFile), moduleName);
51-
}
52-
53-
return moduleName;
41+
const discartedSymbols = ['.', '..', '/'];
42+
let wildcards = [];
43+
Object.keys(options.paths).forEach(path => {
44+
const pathSymbol = path[0];
45+
if (!discartedSymbols.includes(pathSymbol) && !wildcards.includes(pathSymbol)) {
46+
wildcards.push(pathSymbol);
47+
}
48+
});
49+
50+
const isRelative = !path.isAbsolute(moduleName);
51+
let correctWildcard;
52+
53+
wildcards.forEach(wildcard => {
54+
if (moduleName.substr(0, 2) === `${wildcard}/`) {
55+
correctWildcard = wildcard;
56+
}
57+
});
58+
59+
if (correctWildcard) {
60+
const pattern = options.paths ? options.paths[`${correctWildcard}/*`] : undefined;
61+
const substitution = pattern ? options.paths[`${correctWildcard}/*`][0].replace('*', '') : 'src';
62+
moduleName = path.resolve(baseUrl, substitution, moduleName.substr(2));
63+
}
64+
else if (isRelative) {
65+
moduleName = path.resolve(path.dirname(containingFile), moduleName);
66+
}
67+
return moduleName;
5468
}
5569

5670
public static isVue(filePath: string) {

0 commit comments

Comments
 (0)