Skip to content

Commit

Permalink
fix: fallback to node resolver if module not found (#3)
Browse files Browse the repository at this point in the history
* fix: fallback to node resolver if module not found

* chore: release

* chore: add renovate, required checks job
  • Loading branch information
noahnu authored Mar 24, 2024
1 parent ee214c7 commit 86624cf
Show file tree
Hide file tree
Showing 7 changed files with 106 additions and 13 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,17 @@ jobs:

- name: Post Preview
uses: monoweave/github-action-preview@95e30cfa4b8dfb69cb8d18050ef05a207c6f8551 # v1.1.0

required_checks:
name: Required Checks
needs:
- prepare
- build
- lint
- test
runs-on: ubuntu-latest
if: always()
steps:
- name: Fail on error
if: contains(needs.*.result, 'failure') || cancelled()
run: exit 1
45 changes: 45 additions & 0 deletions .github/workflows/renovate.json5
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
$schema: "https://docs.renovatebot.com/renovate-schema.json",
prConcurrentLimit: 2,
semanticCommits: "enabled",
semanticCommitType: "chore",
semanticCommitScope: "deps",
rangeStrategy: "bump",
rebaseWhen: "behind-base-branch",
separateMajorMinor: true,
separateMinorPatch: false,
stabilityDays: 21,
internalChecksFilter: "strict",
dependencyDashboard: true,
timezone: "America/Toronto",
addLabels: ["dependencies"],
automergeType: "pr",
automergeStrategy: "squash",
postUpdateOptions: ["yarnDedupeHighest"],
packageRules: [
{
groupName: "3rd Party Dependencies (Patch/Minor)",
matchManagers: ["npm"],
excludePackagePrefixes: ["@yarnpkg/"],
matchUpdateTypes: ["patch", "minor"],
matchCurrentVersion: "!/^0/",
addLabels: ["automerge"],
automerge: true,
},
{
groupName: "GitHub Actions",
matchManagers: ["github-actions"],
matchUpdateTypes: ["patch", "minor"],
matchCurrentVersion: "!/^0/",
addLabels: ["automerge"],
automerge: true,
},
{
description: "Ignore Engines Field",
matchPackageNames: ["node"],
matchManagers: ["npm"],
matchDepTypes: ["engines"],
enabled: false,
},
],
}
4 changes: 4 additions & 0 deletions .monoweave/1c5de174.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"@noahnu/eslint-import-resolver-require": patch
---
Fallback to eslint-import-resolver-node if module not found.
8 changes: 7 additions & 1 deletion packages/eslint-import-resolver-require/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@
"lib"
],
"devDependencies": {
"@types/debug": "^4.1.12",
"@types/eslint": "^8.44.3",
"@types/jest": "^29.5.5",
"@types/node": "^18.15.11",
"eslint": "^8.50.0"
"eslint": "^8.50.0",
"eslint-plugin-import": "^2.29.1"
},
"dependencies": {
"debug": "^4.3.4",
"eslint-import-resolver-node": "^0.3.9"
},
"peerDependencies": {
"eslint-plugin-import": ">= 2.0.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
declare module 'eslint-import-resolver-node' {
export const resolve: (
source: string,
file: string,
config: unknown,
) => { found: true; path: string | null } | { found: false }
}
19 changes: 16 additions & 3 deletions packages/eslint-import-resolver-require/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import { builtinModules } from 'module'
import path from 'path'

import debug from 'debug'
import { resolve as resolveNode } from 'eslint-import-resolver-node'

const log = debug('eslint-import-resolver-require')

const builtins = new Set(builtinModules)

const resolve = (source: string, file: string) => {
type Resolver = (
source: string,
file: string,
config: unknown,
) => { found: true; path: string | null } | { found: false }

const resolve: Resolver = (source: string, file: string, config: unknown) => {
if (builtins.has(source)) {
return { found: true }
return { found: true, path: null }
}

try {
Expand All @@ -16,7 +27,9 @@ const resolve = (source: string, file: string) => {
}
return { found: true, path: moduleId }
} catch (err) {
return { found: false }
log('falling back to eslint-import-resolver-node due to error', err)
// Fallback to eslint-import-resolver-node plugin
return resolveNode(source, file, config)
}
}

Expand Down
22 changes: 13 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1354,10 +1354,14 @@ __metadata:
version: 0.0.0-use.local
resolution: "@noahnu/eslint-import-resolver-require@workspace:packages/eslint-import-resolver-require"
dependencies:
"@types/debug": "npm:^4.1.12"
"@types/eslint": "npm:^8.44.3"
"@types/jest": "npm:^29.5.5"
"@types/node": "npm:^18.15.11"
debug: "npm:^4.3.4"
eslint: "npm:^8.50.0"
eslint-import-resolver-node: "npm:^0.3.9"
eslint-plugin-import: "npm:^2.29.1"
peerDependencies:
eslint-plugin-import: ">= 2.0.0"
languageName: unknown
Expand Down Expand Up @@ -4554,9 +4558,9 @@ __metadata:
languageName: node
linkType: hard

"eslint-plugin-import@npm:^2.29.0":
version: 2.29.0
resolution: "eslint-plugin-import@npm:2.29.0"
"eslint-plugin-import@npm:^2.29.0, eslint-plugin-import@npm:^2.29.1":
version: 2.29.1
resolution: "eslint-plugin-import@npm:2.29.1"
dependencies:
array-includes: "npm:^3.1.7"
array.prototype.findlastindex: "npm:^1.2.3"
Expand All @@ -4574,10 +4578,10 @@ __metadata:
object.groupby: "npm:^1.0.1"
object.values: "npm:^1.1.7"
semver: "npm:^6.3.1"
tsconfig-paths: "npm:^3.14.2"
tsconfig-paths: "npm:^3.15.0"
peerDependencies:
eslint: ^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8
checksum: 10c0/761a4e1fbc2cd318e62350bed4c448f8b11ed83091d6bb7776f096556363a09debd9922b39fd2714c895edc9aaea82e08e684eb632283f880c58a91e4bae6733
checksum: 10c0/5f35dfbf4e8e67f741f396987de9504ad125c49f4144508a93282b4ea0127e052bde65ab6def1f31b6ace6d5d430be698333f75bdd7dca3bc14226c92a083196
languageName: node
linkType: hard

Expand Down Expand Up @@ -9247,15 +9251,15 @@ __metadata:
languageName: node
linkType: hard

"tsconfig-paths@npm:^3.14.2":
version: 3.14.2
resolution: "tsconfig-paths@npm:3.14.2"
"tsconfig-paths@npm:^3.15.0":
version: 3.15.0
resolution: "tsconfig-paths@npm:3.15.0"
dependencies:
"@types/json5": "npm:^0.0.29"
json5: "npm:^1.0.2"
minimist: "npm:^1.2.6"
strip-bom: "npm:^3.0.0"
checksum: 10c0/fdc92bb7b18b31c0e76f8ec4f98d07236b09590fd6578e587ad024792c8b2235d65125a8fd007fa47a84400f84ceccbf33f24e5198d953249e7204f4cef3517c
checksum: 10c0/5b4f301a2b7a3766a986baf8fc0e177eb80bdba6e396792ff92dc23b5bca8bb279fc96517dcaaef63a3b49bebc6c4c833653ec58155780bc906bdbcf7dda0ef5
languageName: node
linkType: hard

Expand Down

0 comments on commit 86624cf

Please sign in to comment.