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

Fix problem with printing lint results using pager in windows #259

Merged
merged 2 commits into from
Feb 4, 2023
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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 11 additions & 15 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/action/print-result-details.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
34 changes: 34 additions & 0 deletions src/cli/pager.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
if (process.platform == 'win32') {
return pagerForWindows(content);
} else {
return pagerForPOSIX(content);
}
}

async function pagerForWindows(content: string): Promise<void> {
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<void> {
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;
}
}
4 changes: 0 additions & 4 deletions src/typings/node-pager.d.ts

This file was deleted.