Skip to content

Commit

Permalink
chore: Simplify check-existence
Browse files Browse the repository at this point in the history
  • Loading branch information
scagood committed Mar 20, 2024
1 parent 139e76b commit 0b44073
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions lib/util/check-existence.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function markMissing(context, target) {
exports.checkExistence = function checkExistence(context, targets) {
const allowed = new Set(getAllowModules(context))

for (const target of targets) {
target: for (const target of targets) {
if (
target.moduleName != null &&
!allowed.has(target.moduleName) &&
Expand All @@ -50,34 +50,37 @@ exports.checkExistence = function checkExistence(context, targets) {
continue
}

if (target.moduleName != null) {
if (
target.moduleName != null ||
target.filePath == null ||
exists(target.filePath)
) {
continue
}

let missingFile =
target.filePath == null ? false : !exists(target.filePath)
if (isTypescript(context) === false) {
markMissing(context, target)
continue
}

if (target.filePath != null && isTypescript(context)) {
const parsed = path.parse(target.filePath)
const pathWithoutExt = path.resolve(parsed.dir, parsed.name)
const parsed = path.parse(target.filePath)
const pathWithoutExt = path.resolve(parsed.dir, parsed.name)

const reversedExts = convertJsExtensionToTs(
context,
target.filePath,
parsed.ext
)
const reversedPaths = reversedExts.map(
reversedExt => pathWithoutExt + reversedExt
)
missingFile = reversedPaths.every(
reversedPath =>
target.moduleName == null && !exists(reversedPath)
)
}
const reversedExtensions = convertJsExtensionToTs(
context,
target.filePath,
parsed.ext
)

if (missingFile) {
markMissing(context, target)
for (const reversedExtension of reversedExtensions) {
const reversedPath = pathWithoutExt + reversedExtension

if (exists(reversedPath)) {
continue target
}
}

markMissing(context, target)
}
}

Expand Down

0 comments on commit 0b44073

Please sign in to comment.