Skip to content

Commit 9125378

Browse files
scagoodaladdin-add
authored andcommitted
chore: Demo with only enhanced-resolve
1 parent 3028059 commit 9125378

File tree

3 files changed

+14
-46
lines changed

3 files changed

+14
-46
lines changed

lib/util/check-existence.js

+4-40
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
*/
55
"use strict"
66

7-
const path = require("path")
8-
const exists = require("./exists")
97
const getAllowModules = require("./get-allow-modules")
10-
const isTypescript = require("./is-typescript")
11-
const { convertJsExtensionToTs } = require("../util/map-typescript-extension")
128

139
/**
1410
* Reports a missing file from ImportTarget
@@ -41,49 +37,17 @@ function markMissing(context, target) {
4137
* @returns {void}
4238
*/
4339
exports.checkExistence = function checkExistence(context, targets) {
40+
/** @type {Set<string | undefined>} */
4441
const allowed = new Set(getAllowModules(context))
4542

46-
target: for (const target of targets) {
47-
if (
48-
target.moduleName != null &&
49-
!allowed.has(target.moduleName) &&
50-
target.filePath == null
51-
) {
52-
markMissing(context, target)
53-
continue
54-
}
55-
56-
if (
57-
target.moduleName != null ||
58-
target.filePath == null ||
59-
exists(target.filePath)
60-
) {
43+
for (const target of targets) {
44+
if (allowed.has(target.moduleName)) {
6145
continue
6246
}
6347

64-
if (isTypescript(context) === false) {
48+
if (target.resolveError != null) {
6549
markMissing(context, target)
66-
continue
6750
}
68-
69-
const parsed = path.parse(target.filePath)
70-
const pathWithoutExt = path.resolve(parsed.dir, parsed.name)
71-
72-
const reversedExtensions = convertJsExtensionToTs(
73-
context,
74-
target.filePath,
75-
parsed.ext
76-
)
77-
78-
for (const reversedExtension of reversedExtensions) {
79-
const reversedPath = pathWithoutExt + reversedExtension
80-
81-
if (exists(reversedPath)) {
82-
continue target
83-
}
84-
}
85-
86-
markMissing(context, target)
8751
}
8852
}
8953

lib/util/import-target.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,18 @@ module.exports = class ImportTarget {
293293
extensionAlias = getTypescriptExtensionMap(this.context).backward
294294
}
295295

296-
const requireResolve = resolver.create.sync({
296+
/** @type {import('enhanced-resolve').ResolveOptionsOptionalFS} */
297+
this.resolverConfig = {
297298
conditionNames,
298299
extensions,
299300
mainFields,
300301
mainFiles,
301302

302303
extensionAlias,
303304
alias,
304-
})
305+
}
306+
307+
const requireResolve = resolver.create.sync(this.resolverConfig)
305308

306309
const cwd = this.context.settings?.cwd ?? process.cwd()
307310
for (const directory of this.getPaths()) {

tests/lib/rules/no-missing-import.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ ruleTester.run("no-missing-import", rule, {
7878
filename: fixture("test.js"),
7979
code: "import a from './a.js';",
8080
},
81-
{
82-
filename: fixture("test.ts"),
83-
code: "import a from './a.js';",
84-
},
81+
// I dont think this should resolve, as it wont after a standard `tsc`
82+
// {
83+
// filename: fixture("test.ts"),
84+
// code: "import a from './a.js';",
85+
// },
8586
{
8687
filename: fixture("test.ts"),
8788
code: "import a from './d.js';",

0 commit comments

Comments
 (0)