Skip to content

Commit

Permalink
Check if the required module exists
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoVictor committed Oct 12, 2022
1 parent 0f8e96b commit 2a2e3ae
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions src/tsc-paths-replacer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,25 +57,15 @@ function getModulePath(moduleName: string, file: string): string | null {
return null;
}

for (const aliasPath of aliasesMap.get(alias)) {
const moduleSourcePath = path.resolve(aliasPath, relativePath);
const [exists] = getFilesFromPattern(
`${moduleSourcePath}.{js,jsx,ts,tsx,d.ts,json}`
);

if (exists) {
const fileCache = moduleCache.get(file) || {};
const relativePath = moduleName.substring(alias.length);
for (const aliasPath of aliasPaths) {
const requiredModuleFullPath = path.resolve(aliasPath, relativePath);

if (fileCache[alias]) {
return replaceSlashes(
`./${path.join(fileCache[alias], relativePath)}`
);
}

const moduleRelativePath = getModuleRelativePath(
moduleSourcePath,
file
);
const existsRequiredModule = !!findByPattern(
replaceSlashes(requiredModuleFullPath),
false
);
if (existsRequiredModule) {

fileCache[alias] = moduleRelativePath.replace(relativePath, '');
moduleCache.set(file, fileCache);
Expand Down

0 comments on commit 2a2e3ae

Please sign in to comment.