Skip to content

Commit

Permalink
(feat) add --preserveWatchOutput option to svelte-check (#1715)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
odinhb committed Nov 14, 2022
1 parent 0513c64 commit 6bd57b0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/svelte-check/README.md
Expand Up @@ -55,6 +55,7 @@ Usage:
| `--workspace <path>` | Path to your workspace. All subdirectories except node_modules and those listed in `--ignore` are checked |
| `--output <human\|human-verbose\|machine>` |
| `--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 <path>` | 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 <path1,path2>` | 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 |
Expand Down
1 change: 1 addition & 0 deletions packages/svelte-check/src/index.ts
Expand Up @@ -163,6 +163,7 @@ function instantiateWriter(opts: SvelteCheckCliOptions): Writer {
process.stdout,
opts.outputFormat === 'human-verbose',
opts.watch,
!opts.preserveWatchOutput,
filter
);
} else {
Expand Down
3 changes: 3 additions & 0 deletions packages/svelte-check/src/options.ts
Expand Up @@ -6,6 +6,7 @@ export interface SvelteCheckCliOptions {
workspaceUri: URI;
outputFormat: OutputFormat;
watch: boolean;
preserveWatchOutput: boolean;
tsconfig?: string;
filePathsToIgnore: string[];
failOnWarnings: boolean;
Expand Down Expand Up @@ -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.'
Expand Down Expand Up @@ -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'],
Expand Down
3 changes: 2 additions & 1 deletion packages/svelte-check/src/writers.ts
Expand Up @@ -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);
Expand Down

0 comments on commit 6bd57b0

Please sign in to comment.