From a619b46c14b0ab6f3c7013eed43675af491c5bd8 Mon Sep 17 00:00:00 2001 From: mizdra Date: Sat, 4 Feb 2023 19:14:43 +0900 Subject: [PATCH 1/2] feat: support pager for windows --- src/action/print-result-details.ts | 2 +- src/cli/pager.ts | 34 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 src/cli/pager.ts diff --git a/src/action/print-result-details.ts b/src/action/print-result-details.ts index d5791bc1..08204c32 100644 --- a/src/action/print-result-details.ts +++ b/src/action/print-result-details.ts @@ -1,6 +1,6 @@ import { Remote } from 'comlink'; import { ESLint } from 'eslint'; -import pager from 'node-pager'; +import { pager } from '../cli/pager.js'; import { promptToInputDisplayMode } from '../cli/prompt.js'; import { SerializableCore } from '../core-worker.js'; diff --git a/src/cli/pager.ts b/src/cli/pager.ts new file mode 100644 index 00000000..92426401 --- /dev/null +++ b/src/cli/pager.ts @@ -0,0 +1,34 @@ +import { spawnSync } from 'child_process'; +import { writeFile } from 'fs/promises'; +import { join } from 'path'; +import { getCacheDir } from '../util/cache.js'; + +const PAGER_CONTENT_FILE_PATH = join(getCacheDir(), 'pager-content.txt'); + +export async function pager(content: string): Promise { + if (process.platform == 'win32') { + return pagerForWindows(content); + } else { + return pagerForPOSIX(content); + } +} + +async function pagerForWindows(content: string): Promise { + await writeFile(PAGER_CONTENT_FILE_PATH, content, 'utf-8'); + try { + spawnSync('more', [PAGER_CONTENT_FILE_PATH], { shell: true, stdio: 'inherit' }); + } catch (e) { + console.error('Failed to execute `more` command. Please install `more` command.'); + throw e; + } +} + +async function pagerForPOSIX(content: string): Promise { + await writeFile(PAGER_CONTENT_FILE_PATH, content, 'utf-8'); + try { + spawnSync('less', ['-R', PAGER_CONTENT_FILE_PATH], { shell: true, stdio: 'inherit' }); + } catch (e) { + console.error('Failed to execute `less` command. Please install `less` command.'); + throw e; + } +} From 0984804e82106fd70968716a6c798d888c36d5d8 Mon Sep 17 00:00:00 2001 From: mizdra Date: Sat, 4 Feb 2023 19:15:19 +0900 Subject: [PATCH 2/2] deps: uninstall node-pager --- package.json | 1 - pnpm-lock.yaml | 26 +++++++++++--------------- src/typings/node-pager.d.ts | 4 ---- 3 files changed, 11 insertions(+), 20 deletions(-) delete mode 100644 src/typings/node-pager.d.ts diff --git a/package.json b/package.json index 9b2aa08a..17b64ee9 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,6 @@ "estraverse": "^5.3.0", "find-cache-dir": "^4.0.0", "is-installed-globally": "^0.4.0", - "node-pager": "^0.3.6", "ora": "^6.1.2", "table": "^6.8.1", "terminal-link": "^3.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 57ceccaa..b9df93c6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -33,7 +33,6 @@ specifiers: is-installed-globally: ^0.4.0 jest: ^29.0.1 jest-mock-process: ^2.0.0 - node-pager: ^0.3.6 npm-run-all: ^4.1.5 ora: ^6.1.2 prettier: 2.7.1 @@ -54,7 +53,6 @@ dependencies: estraverse: 5.3.0 find-cache-dir: 4.0.0 is-installed-globally: 0.4.0 - node-pager: 0.3.6 ora: 6.1.2 table: 6.8.1 terminal-link: 3.0.0 @@ -1386,6 +1384,7 @@ packages: /balanced-match/1.0.0: resolution: {integrity: sha512-9Y0g0Q8rmSt+H33DfKv7FOc3v+iRI+o1lbzt8jGcIosYW37IIW/2XVYq5NPdmaD5NQ59Nk26Kl/vZbwW9Fr8vg==} + dev: true /base64-js/1.5.1: resolution: {integrity: sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==} @@ -1418,6 +1417,7 @@ packages: dependencies: balanced-match: 1.0.0 concat-map: 0.0.1 + dev: true /braces/3.0.2: resolution: {integrity: sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==} @@ -1583,6 +1583,7 @@ packages: /concat-map/0.0.1: resolution: {integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=} + dev: true /convert-source-map/1.8.0: resolution: {integrity: sha512-+OQdjP49zViI/6i7nIJpA8rAl4sV/JdPfU9nZs3VqOwGIgizICvuN2ru6fMd+4llL0tar18UYJXfZ/TWtmhUjA==} @@ -2166,6 +2167,7 @@ packages: /fs.realpath/1.0.0: resolution: {integrity: sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==} + dev: true /fsevents/2.3.2: resolution: {integrity: sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==} @@ -2241,6 +2243,7 @@ packages: minimatch: 3.0.4 once: 1.4.0 path-is-absolute: 1.0.1 + dev: true /glob/7.2.3: resolution: {integrity: sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==} @@ -2372,6 +2375,7 @@ packages: dependencies: once: 1.4.0 wrappy: 1.0.2 + dev: true /inherits/2.0.4: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} @@ -3189,6 +3193,7 @@ packages: resolution: {integrity: sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==} dependencies: brace-expansion: 1.1.11 + dev: true /minimatch/3.1.2: resolution: {integrity: sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==} @@ -3228,12 +3233,6 @@ packages: resolution: {integrity: sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==} dev: true - /node-pager/0.3.6: - resolution: {integrity: sha512-BXfo1Cgho1FPwjNxZuCfar79hih3LUmye4cih30UbuROksiat6mS8PgRzFEaVtQu+kVkwz13blIB0R7IuI2PDw==} - dependencies: - tmp: 0.2.1 - dev: false - /node-releases/2.0.6: resolution: {integrity: sha512-PiVXnNuFm5+iYkLBNeq5211hvO38y63T0i2KKh2KnUs3RpzJ+JtODFjkD8yjLwnDkTYF1eKXheUwdssR+NRZdg==} dev: true @@ -3307,6 +3306,7 @@ packages: resolution: {integrity: sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==} dependencies: wrappy: 1.0.2 + dev: true /onetime/5.1.2: resolution: {integrity: sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==} @@ -3450,6 +3450,7 @@ packages: /path-is-absolute/1.0.1: resolution: {integrity: sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==} engines: {node: '>=0.10.0'} + dev: true /path-key/2.0.1: resolution: {integrity: sha512-fEHGKCSmUSDPv4uoj8AlD+joPlq3peND+HRYyxFz4KPw4z926S/b8rIuFs2FYJg3BwsxJf6A9/3eIdLaYC+9Dw==} @@ -3651,6 +3652,7 @@ packages: hasBin: true dependencies: glob: 7.1.6 + dev: true /run-parallel/1.2.0: resolution: {integrity: sha512-5l4VyZR86LZ/lDxZTR6jqL8AFE2S0IFLMP26AbjsLVADxHdhB/c0GUsH+y39UfCi3dzz8OlQuPmnaJOMoDHQBA==} @@ -3962,13 +3964,6 @@ packages: resolution: {integrity: sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==} dev: true - /tmp/0.2.1: - resolution: {integrity: sha512-76SUhtfqR2Ijn+xllcI5P1oyannHNHByD80W1q447gU3mp9G9PSpGdWmjUOHRDPiHYacIk66W7ubDTuPF3BEtQ==} - engines: {node: '>=8.17.0'} - dependencies: - rimraf: 3.0.2 - dev: false - /tmpl/1.0.5: resolution: {integrity: sha512-3f0uOEAQwIqGuWW2MVzYg8fV/QNnc/IpuJNG837rLuczAaLVHslWHZQj4IGiEl5Hs3kkbhwL9Ab7Hrsmuj+Smw==} dev: true @@ -4178,6 +4173,7 @@ packages: /wrappy/1.0.2: resolution: {integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=} + dev: true /write-file-atomic/4.0.1: resolution: {integrity: sha512-nSKUxgAbyioruk6hU87QzVbY279oYT6uiwgDoujth2ju4mJ+TZau7SQBhtbTmUyuNYTuXnSyRn66FV0+eCgcrQ==} diff --git a/src/typings/node-pager.d.ts b/src/typings/node-pager.d.ts deleted file mode 100644 index fc903992..00000000 --- a/src/typings/node-pager.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -declare module 'node-pager' { - // eslint-disable-next-line import/no-default-export - export default function pager(str: string): Promise; -}