Skip to content

Commit

Permalink
chore: Demo with only enhanced-resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
scagood committed Apr 17, 2024
1 parent a256b25 commit 33c399e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 44 deletions.
44 changes: 4 additions & 40 deletions lib/util/check-existence.js
Expand Up @@ -4,11 +4,7 @@
*/
"use strict"

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

/**
* Reports a missing file from ImportTarget
Expand Down Expand Up @@ -41,49 +37,17 @@ function markMissing(context, target) {
* @returns {void}
*/
exports.checkExistence = function checkExistence(context, targets) {
/** @type {Set<string | undefined>} */
const allowed = new Set(getAllowModules(context))

target: for (const target of targets) {
if (
target.moduleName != null &&
!allowed.has(target.moduleName) &&
target.filePath == null
) {
markMissing(context, target)
continue
}

if (
target.moduleName != null ||
target.filePath == null ||
exists(target.filePath)
) {
for (const target of targets) {
if (allowed.has(target.moduleName)) {
continue
}

if (isTypescript(context) === false) {
if (target.resolveError != null) {
markMissing(context, target)
continue
}

const parsed = path.parse(target.filePath)
const pathWithoutExt = path.resolve(parsed.dir, parsed.name)

const reversedExtensions = convertJsExtensionToTs(
context,
target.filePath,
parsed.ext
)

for (const reversedExtension of reversedExtensions) {
const reversedPath = pathWithoutExt + reversedExtension

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

markMissing(context, target)
}
}

Expand Down
10 changes: 10 additions & 0 deletions lib/util/import-target.js
Expand Up @@ -293,6 +293,16 @@ module.exports = class ImportTarget {
extensionAlias = getTypescriptExtensionMap(this.context).backward
}

this.blah = {
conditionNames,
extensions,
mainFields,
mainFiles,

extensionAlias,
alias,
}

const requireResolve = resolver.create.sync({
conditionNames,
extensions,
Expand Down
11 changes: 7 additions & 4 deletions tests/lib/rules/no-missing-import.js
Expand Up @@ -4,6 +4,8 @@
*/
"use strict"

require("node:util").inspect.defaultOptions.depth = 5

const path = require("path")
const { Linter } = require("eslint")
const { RuleTester } = require("#eslint-rule-tester")
Expand Down Expand Up @@ -78,10 +80,11 @@ ruleTester.run("no-missing-import", rule, {
filename: fixture("test.js"),
code: "import a from './a.js';",
},
{
filename: fixture("test.ts"),
code: "import a from './a.js';",
},
// I dont think this should resolve, as it wont after a standard `tsc`
// {
// filename: fixture("test.ts"),
// code: "import a from './a.js';",
// },
{
filename: fixture("test.ts"),
code: "import a from './d.js';",
Expand Down

0 comments on commit 33c399e

Please sign in to comment.