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

Get rid of alternate screen and simplify screen clearing #2942

Merged
merged 1 commit into from Jun 16, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 0 additions & 42 deletions bin/src/run/alternateScreen.ts

This file was deleted.

17 changes: 17 additions & 0 deletions bin/src/run/resetScreen.ts
@@ -0,0 +1,17 @@
import { stderr } from '../logging';

const CLEAR_SCREEN = '\u001Bc';

export function getResetScreen(clearScreen: boolean) {
if (clearScreen) {
return (heading: string) => stderr(CLEAR_SCREEN + heading);
}

let firstRun = true;
return (heading: string) => {
if (firstRun) {
stderr(heading);
firstRun = false;
}
};
}
23 changes: 3 additions & 20 deletions bin/src/run/watch.ts
Expand Up @@ -15,9 +15,9 @@ import {
import mergeOptions, { GenericConfigObject } from '../../../src/utils/mergeOptions';
import relativeId from '../../../src/utils/relativeId';
import { handleError, stderr } from '../logging';
import alternateScreen from './alternateScreen';
import batchWarnings from './batchWarnings';
import loadConfigFile from './loadConfigFile';
import { getResetScreen } from './resetScreen';
import { printTimings } from './timings';

interface WatchEvent {
Expand All @@ -41,19 +41,13 @@ export default function watch(
silent = false
) {
const isTTY = Boolean(process.stderr.isTTY);

const warnings = batchWarnings();

let processConfigsErr: any;
const initialConfigs = processConfigs(configs);

const clearScreen = initialConfigs.every(
config => (config.watch as WatcherOptions).clearScreen !== false
);

const screen = alternateScreen(isTTY && clearScreen);
screen.open();

const resetScreen = getResetScreen(isTTY && clearScreen);
let watcher: Watcher;
let configWatcher: Watcher;

Expand All @@ -78,26 +72,16 @@ export default function watch(
message: merged.optionError
});

if (
(merged.inputOptions as RollupWatchOptions).watch &&
((merged.inputOptions as RollupWatchOptions).watch as WatcherOptions).clearScreen === false
) {
processConfigsErr = stderr;
}

return result;
});
}

function start(configs: RollupWatchOptions[]) {
const screenWriter = processConfigsErr || screen.reset;

watcher = rollup.watch(configs);

watcher.on('event', (event: WatchEvent) => {
switch (event.code) {
case 'FATAL':
screen.close();
handleError(event.error as RollupError, true);
process.exit(1);
break;
Expand All @@ -109,7 +93,7 @@ export default function watch(

case 'START':
if (!silent) {
screenWriter(tc.underline(`rollup v${rollup.VERSION}`));
resetScreen(tc.underline(`rollup v${rollup.VERSION}`));
}
break;

Expand Down Expand Up @@ -171,7 +155,6 @@ export default function watch(
// removing a non-existent listener is a no-op
process.stdin.removeListener('end', close);

screen.close();
if (watcher) watcher.close();

if (configWatcher) configWatcher.close();
Expand Down
69 changes: 23 additions & 46 deletions package-lock.json

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

9 changes: 4 additions & 5 deletions package.json
Expand Up @@ -72,7 +72,6 @@
"acorn-import-meta": "^1.0.0",
"acorn-jsx": "^5.0.1",
"acorn-walk": "^6.1.1",
"ansi-escapes": "^4.2.0",
"buble": "^0.19.7",
"chokidar": "^2.1.6",
"console-group": "^0.3.3",
Expand All @@ -89,7 +88,7 @@
"immutable": "^4.0.0-rc.12",
"is-reference": "^1.1.2",
"istanbul": "^0.4.5",
"lint-staged": "^8.2.0",
"lint-staged": "^8.2.1",
"locate-character": "^2.0.5",
"magic-string": "^0.25.2",
"markdownlint-cli": "^0.17.0",
Expand All @@ -102,12 +101,12 @@
"remap-istanbul": "^0.13.0",
"require-relative": "^0.8.7",
"requirejs": "^2.3.6",
"rollup": "^1.15.1",
"rollup": "^1.15.5",
"rollup-plugin-alias": "^1.5.2",
"rollup-plugin-buble": "^0.19.6",
"rollup-plugin-commonjs": "^10.0.0",
"rollup-plugin-json": "^4.0.0",
"rollup-plugin-node-resolve": "^5.0.1",
"rollup-plugin-node-resolve": "^5.0.2",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-string": "^3.0.0",
"rollup-plugin-terser": "^5.0.0",
Expand All @@ -124,7 +123,7 @@
"tslib": "^1.10.0",
"tslint": "^5.17.0",
"turbocolor": "^2.6.1",
"typescript": "^3.5.1",
"typescript": "^3.5.2",
"url-parse": "^1.4.7"
},
"files": [
Expand Down
1 change: 0 additions & 1 deletion typings/declarations.d.ts
Expand Up @@ -6,7 +6,6 @@ declare module 'help.md' {
}

// external libs
declare module 'ansi-escapes';
declare module 'pretty-bytes';
declare module 'rollup-plugin-buble';
declare module 'signal-exit';
Expand Down