@odg/eslint-config 3.2.8 → 3.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lint.mjs +76 -2
  2. package/package.json +3 -3
package/lint.mjs CHANGED
@@ -1,11 +1,85 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  import { spawn } from "node:child_process";
4
- import { resolve } from "node:path";
4
+ import { access, readdir } from "node:fs/promises";
5
+ import { join, resolve } from "node:path";
5
6
  import process from "node:process";
6
7
 
7
8
  const USER_ARGUMENTS_START_INDEX = 2;
8
- const eslintCliPath = resolve(process.cwd(), "node_modules/eslint/bin/eslint.js");
9
+
10
+ async function fileExists(filePath) {
11
+ try {
12
+ await access(filePath);
13
+
14
+ return true;
15
+ } catch {
16
+ return false;
17
+ }
18
+ }
19
+
20
+ async function checkCwdEslint() {
21
+ const cwdNodeModulesEslint = resolve(process.cwd(), "node_modules/eslint/bin/eslint.js");
22
+
23
+ if (await fileExists(cwdNodeModulesEslint)) {
24
+ return cwdNodeModulesEslint;
25
+ }
26
+
27
+ return null;
28
+ }
29
+
30
+ async function checkLocalEslint() {
31
+ // eslint-disable-next-line id-denylist
32
+ const packageDirectory = import.meta.dirname;
33
+ const localNodeModulesEslint = resolve(packageDirectory, "node_modules/eslint/bin/eslint.js");
34
+
35
+ if (await fileExists(localNodeModulesEslint)) {
36
+ return localNodeModulesEslint;
37
+ }
38
+
39
+ return null;
40
+ }
41
+
42
+ async function checkPnpmEslint() {
43
+ const pnpmStoreDirectory = resolve(process.cwd(), "node_modules/.store");
44
+
45
+ if (!await fileExists(pnpmStoreDirectory)) {
46
+ return null;
47
+ }
48
+
49
+ // eslint-disable-next-line security/detect-non-literal-fs-filename
50
+ const eslintStorePaths = await readdir(pnpmStoreDirectory);
51
+
52
+ for (const eslintStorePath of eslintStorePaths) {
53
+ if (!eslintStorePath.startsWith("eslint-")) continue;
54
+
55
+ const eslintCliPath = join(pnpmStoreDirectory, eslintStorePath, "package/bin/eslint.js");
56
+
57
+ if (await fileExists(eslintCliPath)) {
58
+ return eslintCliPath;
59
+ }
60
+ }
61
+
62
+ return null;
63
+ }
64
+
65
+ async function getEslintCliPath() {
66
+ const cwd = await checkCwdEslint();
67
+
68
+ if (cwd) return cwd;
69
+
70
+ const local = await checkLocalEslint();
71
+
72
+ if (local) return local;
73
+
74
+ const pnpm = await checkPnpmEslint();
75
+
76
+ if (pnpm) return pnpm;
77
+
78
+ process.stderr.write("Could not find ESLint binary. Install dependencies or check Yarn linker configuration.\n");
79
+ process.exit(1);
80
+ }
81
+
82
+ const eslintCliPath = await getEslintCliPath();
9
83
  const eslintArguments = process.argv.slice(USER_ARGUMENTS_START_INDEX);
10
84
 
11
85
  const eslintProcess = spawn(process.execPath, [ eslintCliPath, ...eslintArguments ], {
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@odg/eslint-config",
3
- "version": "3.2.8",
3
+ "version": "3.2.10",
4
4
  "description": "Linter for JavaScript And Typescript project",
5
5
  "type": "module",
6
6
  "main": "index.mjs",
7
7
  "types": "index.d.ts",
8
8
  "bin": {
9
- "odg:lint": "./lint.mjs"
9
+ "odg-lint": "./lint.mjs"
10
10
  },
11
11
  "exports": {
12
12
  ".": {
@@ -18,7 +18,7 @@
18
18
  "scripts": {
19
19
  "lint": "eslint",
20
20
  "lint:fix": "eslint --fix",
21
- "odg:lint": "eslint"
21
+ "odg-lint": "node lint.mjs"
22
22
  },
23
23
  "engines": {
24
24
  "node": ">=24.0.0"