Apply import update logic for external modules

This commit is contained in:
Franck Royer 2022-06-16 15:08:19 +10:00
parent 5ca3957b39
commit 53a3f7fcbf
No known key found for this signature in database
GPG Key ID: A82ED75A8DFC50A4
1 changed files with 10 additions and 2 deletions

View File

@ -36,8 +36,16 @@ function fixImportsAtFile(filePath) {
}
const [_, importPath] = l.split(`"`);
const fullPath = path.join(filePath, "..", importPath);
const exists = fs.existsSync(fullPath);
let exists = true;
let fullPath;
if (importPath.startsWith(".")) {
fullPath = path.join(filePath, "..", importPath);
exists = fs.existsSync(fullPath);
} else {
fullPath = path.join(process.cwd(), "node_modules", importPath);
exists = fs.existsSync(fullPath);
}
if (exists === false) {
console.log("Update ", l);
return l.replace(IMPORT_REGEXP, JUST_ADD_AN_EXTENSION);