Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

Commit 2e2a647

Browse files
committed
fix(watch): make default watch fail-to-start timeout configurable so it works more reliably on slow
make default watch fail-to-start timeout configurable so it works more reliably on slow machin closes #772
1 parent 1dedc53 commit 2e2a647

File tree

5 files changed

+21
-7
lines changed

5 files changed

+21
-7
lines changed

src/util/config.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ describe('config', () => {
101101
expect(fakeConfig[Constants.ENV_BAIL_ON_LINT_ERROR]).toBeFalsy();
102102
expect(fakeConfig[Constants.ENV_ENABLE_LINT]).toEqual('true');
103103
expect(fakeConfig[Constants.ENV_DISABLE_LOGGING]).toBeFalsy();
104+
expect(fakeConfig[Constants.ENV_START_WATCH_TIMEOUT]).toEqual('3000');
104105

105106
expect(fakeConfig[Constants.ENV_ACTION_SHEET_CONTROLLER_CLASSNAME]).toEqual('ActionSheetController');
106107
expect(fakeConfig[Constants.ENV_ACTION_SHEET_CONTROLLER_PATH]).toEqual(join(context.ionicAngularDir, 'components', 'action-sheet', 'action-sheet-controller.js'));

src/util/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ export function generateContext(context?: BuildContext): BuildContext {
197197
setProcessEnvVar(Constants.ENV_DISABLE_LOGGING, disableLogging);
198198
Logger.debug(`disableLogging set to ${disableLogging}`);
199199

200+
const startWatchTimeout = getConfigValue(context, '--startWatchTimeout', null, Constants.ENV_START_WATCH_TIMEOUT, Constants.ENV_START_WATCH_TIMEOUT.toLowerCase(), '3000');
201+
setProcessEnvVar(Constants.ENV_START_WATCH_TIMEOUT, startWatchTimeout);
202+
Logger.debug(`startWatchTimeout set to ${startWatchTimeout}`);
203+
200204
/* Provider Path Stuff */
201205
setProcessEnvVar(Constants.ENV_ACTION_SHEET_CONTROLLER_CLASSNAME, 'ActionSheetController');
202206
setProcessEnvVar(Constants.ENV_ACTION_SHEET_CONTROLLER_PATH, join(context.ionicAngularDir, 'components', 'action-sheet', 'action-sheet-controller.js'));

src/util/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export const ENV_GLOB_UTIL = 'IONIC_GLOB_UTIL';
3939
export const ENV_CLEAN_BEFORE_COPY = 'IONIC_CLEAN_BEFORE_COPY';
4040
export const ENV_CLOSURE_JAR = 'IONIC_CLOSURE_JAR';
4141
export const ENV_READ_CONFIG_JSON = 'IONIC_READ_CONFIG_JSON';
42-
4342
export const ENV_OUTPUT_JS_FILE_NAME = 'IONIC_OUTPUT_JS_FILE_NAME';
4443
export const ENV_OUTPUT_CSS_FILE_NAME = 'IONIC_OUTPUT_CSS_FILE_NAME';
4544
export const ENV_WEBPACK_FACTORY = 'IONIC_WEBPACK_FACTORY';
@@ -50,6 +49,7 @@ export const ENV_BAIL_ON_LINT_ERROR = 'IONIC_BAIL_ON_LINT_ERROR';
5049
export const ENV_BUILD_TO_ES5 = 'IONIC_BUILD_TO_ES5';
5150
export const ENV_ENABLE_LINT = 'IONIC_ENABLE_LINT';
5251
export const ENV_DISABLE_LOGGING = 'IONIC_DISABLE_LOGGING';
52+
export const ENV_START_WATCH_TIMEOUT = 'IONIC_START_WATCH_TIMEOUT';
5353

5454
export const ENV_PRINT_ORIGINAL_DEPENDENCY_TREE = 'IONIC_PRINT_ORIGINAL_DEPENDENCY_TREE';
5555
export const ENV_PRINT_MODIFIED_DEPENDENCY_TREE = 'IONIC_PRINT_MODIFIED_DEPENDENCY_TREE';

src/util/helpers.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,11 @@ export function generateRandomHexString(numCharacters: number) {
265265
return randomBytes(Math.ceil(numCharacters / 2)).toString('hex').slice(0, numCharacters);
266266
}
267267

268+
export function getIntPropertyValue(propertyName: string) {
269+
const result = process.env[propertyName];
270+
return parseInt(result, 0);
271+
}
272+
268273
export function getBooleanPropertyValue(propertyName: string) {
269274
const result = process.env[propertyName];
270275
return result === 'true';

src/watch.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
import { extname, join, normalize, resolve as pathResolve } from 'path';
2+
3+
import * as chokidar from 'chokidar';
4+
15
import * as buildTask from './build';
26
import { copyUpdate as copyUpdateHandler} from './copy';
3-
import { BuildContext, BuildState, ChangedFile, TaskInfo } from './util/interfaces';
4-
import { BuildError } from './util/errors';
7+
import { Logger } from './logger/logger';
58
import { canRunTranspileUpdate } from './transpile';
69
import { fillConfigDefaults, getUserConfigFile, replacePathVars } from './util/config';
7-
import { extname, join, normalize, resolve as pathResolve } from 'path';
8-
import { Logger } from './logger/logger';
9-
import * as chokidar from 'chokidar';
10+
import * as Constants from './util/constants';
11+
import { BuildError } from './util/errors';
12+
import { getIntPropertyValue } from './util/helpers';
13+
import { BuildContext, BuildState, ChangedFile, TaskInfo } from './util/interfaces';
1014

1115

1216
// https://github.com/paulmillr/chokidar
@@ -77,7 +81,7 @@ function startWatcher(name: string, watcher: Watcher, context: BuildContext) {
7781
filesWatchedString = watcher.paths.join(', ');
7882
}
7983
reject(new BuildError(`A watch configured to watch the following paths failed to start. It likely that a file referenced does not exist: ${filesWatchedString}`));
80-
}, 3000);
84+
}, getIntPropertyValue(Constants.ENV_START_WATCH_TIMEOUT));
8185
prepareWatcher(context, watcher);
8286

8387
if (!watcher.paths) {

0 commit comments

Comments
 (0)