From d8a87bcced01c0b78dabffef15bb5966c08216c6 Mon Sep 17 00:00:00 2001 From: mizdra Date: Sat, 5 Feb 2022 18:01:11 +0900 Subject: [PATCH 1/7] deps: yarn add resolve-global --- package.json | 1 + yarn.lock | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/package.json b/package.json index 7186eed9..865b9266 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "is-installed-globally": "^0.4.0", "node-pager": "^0.3.6", "ora": "^6.0.1", + "resolve-global": "^1.0.0", "terminal-link": "^3.0.0", "yargs": "^16.2.0" }, diff --git a/yarn.lock b/yarn.lock index 10f998e8..7a2c2a13 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1891,6 +1891,13 @@ glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4: once "^1.3.0" path-is-absolute "^1.0.0" +global-dirs@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/global-dirs/-/global-dirs-0.1.1.tgz#b319c0dd4607f353f3be9cca4c72fc148c49f445" + integrity sha1-sxnA3UYH81PzvpzKTHL8FIxJ9EU= + dependencies: + ini "^1.3.4" + global-dirs@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/global-dirs/-/global-dirs-3.0.0.tgz#70a76fe84ea315ab37b1f5576cbde7d48ef72686" @@ -2061,6 +2068,11 @@ ini@2.0.0: resolved "https://registry.yarnpkg.com/ini/-/ini-2.0.0.tgz#e5fd556ecdd5726be978fa1001862eacb0a94bc5" integrity sha512-7PnF4oN3CvZF23ADhA5wRaYEQpJ8qygSkbtTXWBeXWXmEVRXK+1ITciHWwHhsjv1TmW0MgacIv6hEi5pX5NQdA== +ini@^1.3.4: + version "1.3.8" + resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c" + integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew== + internal-slot@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/internal-slot/-/internal-slot-1.0.3.tgz#7347e307deeea2faac2ac6205d4bc7d34967f59c" @@ -3344,6 +3356,13 @@ resolve-from@^5.0.0: resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69" integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw== +resolve-global@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/resolve-global/-/resolve-global-1.0.0.tgz#a2a79df4af2ca3f49bf77ef9ddacd322dad19255" + integrity sha512-zFa12V4OLtT5XUX/Q4VLvTfBf+Ok0SPc1FNGM/z9ctUdiU618qwKpWnd0CHs3+RqROfyEg/DhuHbMWYqcgljEw== + dependencies: + global-dirs "^0.1.1" + resolve.exports@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/resolve.exports/-/resolve.exports-1.1.0.tgz#5ce842b94b05146c0e03076985d1d0e7e48c90c9" From 7978d98f78bd5fdf0874b99e23b46e7ed5c26222 Mon Sep 17 00:00:00 2001 From: mizdra Date: Sat, 5 Feb 2022 18:29:12 +0900 Subject: [PATCH 2/7] deps: yarn add resolve-from --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index 865b9266..df3c3589 100644 --- a/package.json +++ b/package.json @@ -61,6 +61,7 @@ "is-installed-globally": "^0.4.0", "node-pager": "^0.3.6", "ora": "^6.0.1", + "resolve-from": "^5.0.0", "resolve-global": "^1.0.0", "terminal-link": "^3.0.0", "yargs": "^16.2.0" From 957e94261e35ff103b0f35cba1c7775ab435dd4a Mon Sep 17 00:00:00 2001 From: mizdra Date: Sat, 5 Feb 2022 18:09:02 +0900 Subject: [PATCH 3/7] fix: allow codeframe formatter during global installation --- src/core.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/core.ts b/src/core.ts index 8461a547..dd5b5072 100644 --- a/src/core.ts +++ b/src/core.ts @@ -1,6 +1,12 @@ import { tmpdir } from 'os'; import { join } from 'path'; import { ESLint } from 'eslint'; +// eslint-disable-next-line @typescript-eslint/no-require-imports +import isInstalledGlobally = require('is-installed-globally'); +// eslint-disable-next-line @typescript-eslint/no-require-imports +import resolveFrom = require('resolve-from'); +// eslint-disable-next-line @typescript-eslint/no-require-imports +import resolveGlobal = require('resolve-global'); import { format } from './formatter/index.js'; import { eslintInteractivePlugin, @@ -77,7 +83,16 @@ export class Core { */ async formatResultDetails(results: ESLint.LintResult[], ruleIds: (string | null)[]): Promise { const eslint = new ESLint(this.baseOptions); - const formatter = await eslint.loadFormatter(this.config.formatterName ?? 'codeframe'); + const formatterName = this.config.formatterName ?? 'codeframe'; + + // When eslint-interactive is installed globally, eslint-codeframe-formatter will also be installed globally. + // On the other hand, `eslint.loadFormatter` cannot load the globally installed formatter by name. So here it loads them by path. + const resolvedFormatterNameOrPath = + isInstalledGlobally && formatterName === 'codeframe' + ? resolveFrom(resolveGlobal('@mizdra/eslint-interactive'), 'eslint-codeframe-formatter') + : formatterName; + + const formatter = await eslint.loadFormatter(resolvedFormatterNameOrPath); return formatter.format(filterResultsByRuleId(results, ruleIds)); } From 7260200f0aae6025165279c4b3a4b1f0c58ea6f9 Mon Sep 17 00:00:00 2001 From: mizdra Date: Sat, 5 Feb 2022 18:10:21 +0900 Subject: [PATCH 4/7] refactor: refactor settings --- .gitignore | 3 ++- e2e-test/global-installation/.gitignore | 1 - 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index dd7858f6..a3759e41 100644 --- a/.gitignore +++ b/.gitignore @@ -60,4 +60,5 @@ Cargo.lock /.cache .netlify *.tsbuildinfo -/fixtures-tmp \ No newline at end of file +/fixtures-tmp +mizdra-eslint-interactive-*.tgz diff --git a/e2e-test/global-installation/.gitignore b/e2e-test/global-installation/.gitignore index 6b618b37..6903b57a 100644 --- a/e2e-test/global-installation/.gitignore +++ b/e2e-test/global-installation/.gitignore @@ -1,2 +1 @@ -/mizdra-eslint-interactive-*.tgz /package-lock.json \ No newline at end of file From e02a74b1257a26dc504a222fe1719c6387fbafc8 Mon Sep 17 00:00:00 2001 From: mizdra Date: Sat, 5 Feb 2022 18:11:25 +0900 Subject: [PATCH 5/7] refactor: remove unused workaround --- e2e-test/global-installation/test.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/e2e-test/global-installation/test.sh b/e2e-test/global-installation/test.sh index 123a2919..ad53c9a8 100755 --- a/e2e-test/global-installation/test.sh +++ b/e2e-test/global-installation/test.sh @@ -7,9 +7,6 @@ npm install -g $(ls mizdra-eslint-interactive-*.tgz) ## install peerDeps manually npm install -g eslint@$(cat ../../node_modules/eslint/package.json | jq -r .version) -## workaround for https://github.com/mizdra/eslint-interactive/issues/133 -npm install source-map-support - # Test cases From 8d3472f5ba62991d37b6538dce5f5952f698fcd3 Mon Sep 17 00:00:00 2001 From: mizdra Date: Sat, 5 Feb 2022 19:37:05 +0900 Subject: [PATCH 6/7] fix: use `import.meta.resolve` --- bin/eslint-interactive.js | 2 +- src/core.ts | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bin/eslint-interactive.js b/bin/eslint-interactive.js index d74628bf..839bf7dc 100755 --- a/bin/eslint-interactive.js +++ b/bin/eslint-interactive.js @@ -1,4 +1,4 @@ -#!/usr/bin/env -S node --enable-source-maps --unhandled-rejections=strict +#!/usr/bin/env -S node --enable-source-maps --unhandled-rejections=strict --experimental-import-meta-resolve import { run } from '../dist/index.js'; diff --git a/src/core.ts b/src/core.ts index dd5b5072..6c1f9e28 100644 --- a/src/core.ts +++ b/src/core.ts @@ -1,12 +1,9 @@ import { tmpdir } from 'os'; import { join } from 'path'; +import { fileURLToPath } from 'url'; import { ESLint } from 'eslint'; // eslint-disable-next-line @typescript-eslint/no-require-imports import isInstalledGlobally = require('is-installed-globally'); -// eslint-disable-next-line @typescript-eslint/no-require-imports -import resolveFrom = require('resolve-from'); -// eslint-disable-next-line @typescript-eslint/no-require-imports -import resolveGlobal = require('resolve-global'); import { format } from './formatter/index.js'; import { eslintInteractivePlugin, @@ -85,11 +82,18 @@ export class Core { const eslint = new ESLint(this.baseOptions); const formatterName = this.config.formatterName ?? 'codeframe'; - // When eslint-interactive is installed globally, eslint-codeframe-formatter will also be installed globally. + // When eslint-interactive is installed globally, eslint-formatter-codeframe will also be installed globally. // On the other hand, `eslint.loadFormatter` cannot load the globally installed formatter by name. So here it loads them by path. const resolvedFormatterNameOrPath = isInstalledGlobally && formatterName === 'codeframe' - ? resolveFrom(resolveGlobal('@mizdra/eslint-interactive'), 'eslint-codeframe-formatter') + ? fileURLToPath( + // @ts-expect-error + await import.meta.resolve( + 'eslint-formatter-codeframe', + // @ts-expect-error + await import.meta.resolve('@mizdra/eslint-interactive'), + ), + ) : formatterName; const formatter = await eslint.loadFormatter(resolvedFormatterNameOrPath); From 1151733d35316810eb59876f6b1b29ea9fe3e7a0 Mon Sep 17 00:00:00 2001 From: mizdra Date: Sat, 5 Feb 2022 19:37:41 +0900 Subject: [PATCH 7/7] deps: yarn remove resolve-from resolve-global --- package.json | 2 -- yarn.lock | 19 ------------------- 2 files changed, 21 deletions(-) diff --git a/package.json b/package.json index df3c3589..7186eed9 100644 --- a/package.json +++ b/package.json @@ -61,8 +61,6 @@ "is-installed-globally": "^0.4.0", "node-pager": "^0.3.6", "ora": "^6.0.1", - "resolve-from": "^5.0.0", - "resolve-global": "^1.0.0", "terminal-link": "^3.0.0", "yargs": "^16.2.0" }, diff --git a/yarn.lock b/yarn.lock index 7a2c2a13..10f998e8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1891,13 +1891,6 @@ glob@^7.1.1, glob@^7.1.2, glob@^7.1.3, glob@^7.1.4: once "^1.3.0" path-is-absolute "^1.0.0" -global-dirs@^0.1.1: - version "0.1.1" - resolved "https://registry.yarnpkg.com/global-dirs/-/global-dirs-0.1.1.tgz#b319c0dd4607f353f3be9cca4c72fc148c49f445" - integrity sha1-sxnA3UYH81PzvpzKTHL8FIxJ9EU= - dependencies: - ini "^1.3.4" - global-dirs@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/global-dirs/-/global-dirs-3.0.0.tgz#70a76fe84ea315ab37b1f5576cbde7d48ef72686" @@ -2068,11 +2061,6 @@ ini@2.0.0: resolved "https://registry.yarnpkg.com/ini/-/ini-2.0.0.tgz#e5fd556ecdd5726be978fa1001862eacb0a94bc5" integrity sha512-7PnF4oN3CvZF23ADhA5wRaYEQpJ8qygSkbtTXWBeXWXmEVRXK+1ITciHWwHhsjv1TmW0MgacIv6hEi5pX5NQdA== -ini@^1.3.4: - version "1.3.8" - resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c" - integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew== - internal-slot@^1.0.3: version "1.0.3" resolved "https://registry.yarnpkg.com/internal-slot/-/internal-slot-1.0.3.tgz#7347e307deeea2faac2ac6205d4bc7d34967f59c" @@ -3356,13 +3344,6 @@ resolve-from@^5.0.0: resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69" integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw== -resolve-global@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/resolve-global/-/resolve-global-1.0.0.tgz#a2a79df4af2ca3f49bf77ef9ddacd322dad19255" - integrity sha512-zFa12V4OLtT5XUX/Q4VLvTfBf+Ok0SPc1FNGM/z9ctUdiU618qwKpWnd0CHs3+RqROfyEg/DhuHbMWYqcgljEw== - dependencies: - global-dirs "^0.1.1" - resolve.exports@^1.1.0: version "1.1.0" resolved "https://registry.yarnpkg.com/resolve.exports/-/resolve.exports-1.1.0.tgz#5ce842b94b05146c0e03076985d1d0e7e48c90c9"