Skip to content

Commit

Permalink
Support for aliases with jest extension
Browse files Browse the repository at this point in the history
  • Loading branch information
mrodal committed Sep 15, 2019
1 parent ab4b43a commit 820ca4d
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,24 @@ function resolveComponent(currentSource, currPath, aliases) {
let baseRelPathParts = baseRelPath.split(/[\/\\]/);

// If there's a matching alias, use it. If not, use the context path
let matchingAlias = Object.keys(aliases).find(k => baseRelPathParts[0] === k);
// __fromJest is a flag inserted on vue-inheritance-loader-jest
if(aliases['__fromJest']){
var matchingAlias = Object.keys(aliases).find(k => {
let regex = new RegExp(k);
return regex.test(baseRelPath);
});
}else{
var matchingAlias = Object.keys(aliases).find(k => baseRelPathParts[0] === k);
}

if (matchingAlias) {
baseRelPathParts.shift();
baseRelPath = baseRelPathParts.join('/');
var baseAbsPath = path.join(aliases[matchingAlias], baseRelPath);
if(aliases['__fromJest']){
var baseAbsPath = baseRelPath.replace(new RegExp(matchingAlias), aliases[matchingAlias])
}else{
baseRelPathParts.shift();
baseRelPath = baseRelPathParts.join('/');
var baseAbsPath = path.join(aliases[matchingAlias], baseRelPath);
}
} else {
var baseAbsPath = path.join(currPath, baseRelPath);
}
Expand Down

0 comments on commit 820ca4d

Please sign in to comment.