Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESLint import resolver require package #2

Merged
merged 2 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,5 @@ jobs:
steps:
- uses: noahnu/.github/.github/actions/setup-node@main

- name: Post Monodeploy Preview
uses: noahnu/.github/.github/actions/post-monodeploy-preview@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Post Preview
uses: monoweave/github-action-preview@95e30cfa4b8dfb69cb8d18050ef05a207c6f8551 # v1.1.0
4 changes: 4 additions & 0 deletions .monoweave/3407b872.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
"@noahnu/eslint-import-resolver-require": patch
---
Initial release of @noahnu/eslint-import-resolver-require.
2 changes: 1 addition & 1 deletion .yarn/sdks/eslint/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint",
"version": "8.53.0-sdk",
"version": "8.57.0-sdk",
"main": "./lib/api.js",
"type": "commonjs",
"bin": {
Expand Down
19 changes: 0 additions & 19 deletions monodeploy.config.js

This file was deleted.

11 changes: 11 additions & 0 deletions monoweave.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @ts-check

/** @type {import('@monoweave/types').MonoweaveConfigFile} */
const config = {
preset: 'monoweave/preset-manual',
maxConcurrentWrites: 1,
changesetIgnorePatterns: ['**/*.test.ts'],
commitIgnorePatterns: ['\\[skip-ci\\]'],
}

module.exports = config
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@
"workspaces": [
"packages/*"
],
"packageManager": "yarn@4.0.2",
"packageManager": "yarn@4.1.1+sha256.f3cc0eda8e5560e529c7147565b30faa43b4e472d90e8634d7134a37c7f59781",
"devDependencies": {
"@jest/types": "^29.6.3",
"@monodeploy/plugin-github": "^2.0.1",
"@monodeploy/types": "^5.0.1",
"@monoweave/plugin-github": "^2.0.7",
"@tophat/commitizen-adapter": "^1.0.2",
"@tophat/commitlint-config": "^1.0.2",
"@tophat/conventional-changelog-config": "^1.0.1",
Expand All @@ -33,7 +32,7 @@
"@types/node": "^20",
"@typescript-eslint/eslint-plugin": "^6.18.1",
"@typescript-eslint/parser": "^6.18.1",
"@yarnpkg/core": "^4.0.2",
"@yarnpkg/core": "^4.0.3",
"@yarnpkg/sdks": "^3.1.0",
"@yarnpkg/types": "^4.0.0",
"commitizen": "^4.3.0",
Expand All @@ -51,7 +50,6 @@
"jest": "^29.7.0",
"jest-junit": "^16.0.0",
"lint-staged": "^15.1.0",
"monodeploy": "^5.0.1",
"prettier": "^3.1.0",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
Expand All @@ -69,6 +67,10 @@
"types:watch": "tsc --noEmit --emitDeclarationOnly false --pretty --watch",
"workspace:build": "rm -rf $0/lib $0/.tmp && tsc -p $0/tsconfig.build.json",
"workspace:clean": "rm -rf $0/lib $0/.tmp && find $0/src -name '*.js' -type f -delete",
"release": "monodeploy --config-file monodeploy.config.js --log-level 0 --plugins @monodeploy/plugin-github"
"release": "monoweave --log-level 0 --plugins @monoweave/plugin-github"
},
"dependencies": {
"@monoweave/cli": "^1.1.0",
"@monoweave/types": "^1.1.0"
}
}
22 changes: 22 additions & 0 deletions packages/eslint-import-resolver-require/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# @noahnu/eslint-import-resolver-require

The simplest eslint import resolver plugin. All it does is expose node's require.

## Usage

```yml
# .eslintrc.yml
settings:
import/resolver: "@noahnu/eslint-import-resolver-require"
```

```js
// .eslintrc.js
module.exports = {
settings: {
'import/resolver': {
'@noahnu/eslint-import-resolver': {}
}
}
}
```
40 changes: 40 additions & 0 deletions packages/eslint-import-resolver-require/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "@noahnu/eslint-import-resolver-require",
"version": "0.0.1",
"repository": {
"type": "git",
"url": "https://github.com/noahnu/nodejs-tools.git",
"directory": "packages/eslint-import-resolver-require"
},
"license": "MIT",
"author": {
"name": "noahnu",
"email": "[email protected]",
"url": "https://noahnu.com"
},
"scripts": {
"clean": "run workspace:clean \"$(pwd)\"",
"prepack": "run workspace:build \"$(pwd)\"",
"run-local": "run -T ts-node --transpileOnly ./src/bin.ts"
},
"main": "./src/index.ts",
"publishConfig": {
"registry": "https://registry.npmjs.org/",
"access": "public",
"bin": "./lib/bin.js",
"main": "./lib/index.js",
"types": "./lib/index.d.ts"
},
"files": [
"lib"
],
"devDependencies": {
"@types/eslint": "^8.44.3",
"@types/jest": "^29.5.5",
"@types/node": "^18.15.11",
"eslint": "^8.50.0"
},
"peerDependencies": {
"eslint-plugin-import": ">= 2.0.0"
}
}
26 changes: 26 additions & 0 deletions packages/eslint-import-resolver-require/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { builtinModules } from 'module'
import path from 'path'

const builtins = new Set(builtinModules)

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

try {
let moduleId = require.resolve(source, { paths: [path.dirname(file)] })
if (process.versions.pnp && moduleId.includes('__virtual__')) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
moduleId = require('pnpapi').resolveVirtual(moduleId)
}
return { found: true, path: moduleId }
} catch (err) {
return { found: false }
}
}

export = {
interfaceVersion: 2,
resolve,
}
9 changes: 9 additions & 0 deletions packages/eslint-import-resolver-require/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "./src",
"tsBuildInfoFile": "./.tmp/.tsbuildinfo",
},
"include": ["./src"],
"exclude": ["./src/**/*.test.ts"]
}
8 changes: 8 additions & 0 deletions packages/eslint-import-resolver-require/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"declarationDir": "./lib",
"outDir": "./lib"
},
"include": ["./src"],
}
2 changes: 1 addition & 1 deletion packages/unused-files/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

<!-- MONODEPLOY:BELOW -->
<!-- MONOWEAVE:BELOW -->

## [0.0.1](https://github.com/noahnu/nodejs-tools/compare/@noahnu/[email protected]...@noahnu/[email protected]) "@noahnu/unused-files" (2024-01-15)<a name="0.0.1"></a>

Expand Down
7 changes: 7 additions & 0 deletions script/bootstrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

# shellcheck disable=SC1091
command -v nvm >/dev/null || . "${NVM_DIR:-"$HOME/.nvm"}"/nvm.sh;
nvm use --silent;

yarn;
Loading
Loading