From 6bd57b018c7ae37b9bbdb4d7a9393be115c96c4f Mon Sep 17 00:00:00 2001 From: Odin <49036561+odinhb@users.noreply.github.com> Date: Mon, 14 Nov 2022 09:51:59 +0000 Subject: [PATCH] (feat) add --preserveWatchOutput option to svelte-check (#1715) Context: I am trying to add svelte to our application, which has previously been using tsc to typecheck our codebase, (and esbuild to build). tsc and svelte-check were both annoying when run from a process manager, such as overmind, which runs multiple cli tools/watchers etc in the same terminal. This is because they by default clear the screen periodically, which blows away useful information from other tools. tsc supports --preserveWatchOutput, so I added the same flag to svelte-check. --- packages/svelte-check/README.md | 1 + packages/svelte-check/src/index.ts | 1 + packages/svelte-check/src/options.ts | 3 +++ packages/svelte-check/src/writers.ts | 3 ++- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/svelte-check/README.md b/packages/svelte-check/README.md index 6ca0d249a..61ff73f74 100644 --- a/packages/svelte-check/README.md +++ b/packages/svelte-check/README.md @@ -55,6 +55,7 @@ Usage: | `--workspace ` | Path to your workspace. All subdirectories except node_modules and those listed in `--ignore` are checked | | `--output ` | | `--watch` | Will not exit after one pass but keep watching files for changes and rerun diagnostics | +| `--preserveWatchOutput` | Do not clear the screen in watch mode | | `--tsconfig ` | Pass a path to a tsconfig or jsconfig file. The path can be relative to the workspace path or absolute. Doing this means that only files matched by the files/include/exclude pattern of the config file are diagnosed. It also means that errors from TypeScript and JavaScript files are reported. | | `--ignore ` | Files/folders to ignore - relative to workspace root, comma-separated, inside quotes. Example: `--ignore "dist,build"`. When used in conjunction with `--tsconfig`, this will only have effect on the files watched, not on the files that are diagnosed, which is then determined by the `tsconfig.json` | | `--fail-on-warnings` | Will also exit with error code when there are warnings | diff --git a/packages/svelte-check/src/index.ts b/packages/svelte-check/src/index.ts index 48039816c..0c71742f9 100644 --- a/packages/svelte-check/src/index.ts +++ b/packages/svelte-check/src/index.ts @@ -163,6 +163,7 @@ function instantiateWriter(opts: SvelteCheckCliOptions): Writer { process.stdout, opts.outputFormat === 'human-verbose', opts.watch, + !opts.preserveWatchOutput, filter ); } else { diff --git a/packages/svelte-check/src/options.ts b/packages/svelte-check/src/options.ts index 548a2343b..eeeb89753 100644 --- a/packages/svelte-check/src/options.ts +++ b/packages/svelte-check/src/options.ts @@ -6,6 +6,7 @@ export interface SvelteCheckCliOptions { workspaceUri: URI; outputFormat: OutputFormat; watch: boolean; + preserveWatchOutput: boolean; tsconfig?: string; filePathsToIgnore: string[]; failOnWarnings: boolean; @@ -34,6 +35,7 @@ export function parseOptions(cb: (opts: SvelteCheckCliOptions) => any) { 'Will not exit after one pass but keep watching files for changes and rerun diagnostics', false ) + .option('--preserveWatchOutput', 'Do not clear the screen in watch mode', false) .option( '--tsconfig', 'Pass a path to a tsconfig or jsconfig file. The path can be relative to the workspace path or absolute. Doing this means that only files matched by the files/include/exclude pattern of the config file are diagnosed. It also means that errors from TypeScript and JavaScript files are reported.' @@ -72,6 +74,7 @@ export function parseOptions(cb: (opts: SvelteCheckCliOptions) => any) { workspaceUri, outputFormat: getOutputFormat(opts), watch: !!opts.watch, + preserveWatchOutput: !!opts.preserveWatchOutput, tsconfig: getTsconfig(opts, workspaceUri.fsPath), filePathsToIgnore: getFilepathsToIgnore(opts), failOnWarnings: !!opts['fail-on-warnings'], diff --git a/packages/svelte-check/src/writers.ts b/packages/svelte-check/src/writers.ts index dd28fcedb..33c7f1f75 100644 --- a/packages/svelte-check/src/writers.ts +++ b/packages/svelte-check/src/writers.ts @@ -24,11 +24,12 @@ export class HumanFriendlyWriter implements Writer { private stream: Writable, private isVerbose = true, private isWatchMode = false, + private clearScreen = true, private diagnosticFilter: DiagnosticFilter = DEFAULT_FILTER ) {} start(workspaceDir: string) { - if (process.stdout.isTTY && this.isWatchMode) { + if (process.stdout.isTTY && this.isWatchMode && this.clearScreen) { // Clear screen const blank = '\n'.repeat(process.stdout.rows); this.stream.write(blank);