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

Commit

Permalink
fix(watch): make default watch fail-to-start timeout configurable so …
Browse files Browse the repository at this point in the history
…it works more reliably on slow

make default watch fail-to-start timeout configurable so it works more reliably on slow machin

closes #772
  • Loading branch information
danbucholtz committed Feb 23, 2017
1 parent 1dedc53 commit 2e2a647
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/util/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ describe('config', () => {
expect(fakeConfig[Constants.ENV_BAIL_ON_LINT_ERROR]).toBeFalsy();
expect(fakeConfig[Constants.ENV_ENABLE_LINT]).toEqual('true');
expect(fakeConfig[Constants.ENV_DISABLE_LOGGING]).toBeFalsy();
expect(fakeConfig[Constants.ENV_START_WATCH_TIMEOUT]).toEqual('3000');

expect(fakeConfig[Constants.ENV_ACTION_SHEET_CONTROLLER_CLASSNAME]).toEqual('ActionSheetController');
expect(fakeConfig[Constants.ENV_ACTION_SHEET_CONTROLLER_PATH]).toEqual(join(context.ionicAngularDir, 'components', 'action-sheet', 'action-sheet-controller.js'));
Expand Down
4 changes: 4 additions & 0 deletions src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ export function generateContext(context?: BuildContext): BuildContext {
setProcessEnvVar(Constants.ENV_DISABLE_LOGGING, disableLogging);
Logger.debug(`disableLogging set to ${disableLogging}`);

const startWatchTimeout = getConfigValue(context, '--startWatchTimeout', null, Constants.ENV_START_WATCH_TIMEOUT, Constants.ENV_START_WATCH_TIMEOUT.toLowerCase(), '3000');
setProcessEnvVar(Constants.ENV_START_WATCH_TIMEOUT, startWatchTimeout);
Logger.debug(`startWatchTimeout set to ${startWatchTimeout}`);

/* Provider Path Stuff */
setProcessEnvVar(Constants.ENV_ACTION_SHEET_CONTROLLER_CLASSNAME, 'ActionSheetController');
setProcessEnvVar(Constants.ENV_ACTION_SHEET_CONTROLLER_PATH, join(context.ionicAngularDir, 'components', 'action-sheet', 'action-sheet-controller.js'));
Expand Down
2 changes: 1 addition & 1 deletion src/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export const ENV_GLOB_UTIL = 'IONIC_GLOB_UTIL';
export const ENV_CLEAN_BEFORE_COPY = 'IONIC_CLEAN_BEFORE_COPY';
export const ENV_CLOSURE_JAR = 'IONIC_CLOSURE_JAR';
export const ENV_READ_CONFIG_JSON = 'IONIC_READ_CONFIG_JSON';

export const ENV_OUTPUT_JS_FILE_NAME = 'IONIC_OUTPUT_JS_FILE_NAME';
export const ENV_OUTPUT_CSS_FILE_NAME = 'IONIC_OUTPUT_CSS_FILE_NAME';
export const ENV_WEBPACK_FACTORY = 'IONIC_WEBPACK_FACTORY';
Expand All @@ -50,6 +49,7 @@ export const ENV_BAIL_ON_LINT_ERROR = 'IONIC_BAIL_ON_LINT_ERROR';
export const ENV_BUILD_TO_ES5 = 'IONIC_BUILD_TO_ES5';
export const ENV_ENABLE_LINT = 'IONIC_ENABLE_LINT';
export const ENV_DISABLE_LOGGING = 'IONIC_DISABLE_LOGGING';
export const ENV_START_WATCH_TIMEOUT = 'IONIC_START_WATCH_TIMEOUT';

export const ENV_PRINT_ORIGINAL_DEPENDENCY_TREE = 'IONIC_PRINT_ORIGINAL_DEPENDENCY_TREE';
export const ENV_PRINT_MODIFIED_DEPENDENCY_TREE = 'IONIC_PRINT_MODIFIED_DEPENDENCY_TREE';
Expand Down
5 changes: 5 additions & 0 deletions src/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,11 @@ export function generateRandomHexString(numCharacters: number) {
return randomBytes(Math.ceil(numCharacters / 2)).toString('hex').slice(0, numCharacters);
}

export function getIntPropertyValue(propertyName: string) {
const result = process.env[propertyName];
return parseInt(result, 0);
}

export function getBooleanPropertyValue(propertyName: string) {
const result = process.env[propertyName];
return result === 'true';
Expand Down
16 changes: 10 additions & 6 deletions src/watch.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { extname, join, normalize, resolve as pathResolve } from 'path';

import * as chokidar from 'chokidar';

import * as buildTask from './build';
import { copyUpdate as copyUpdateHandler} from './copy';
import { BuildContext, BuildState, ChangedFile, TaskInfo } from './util/interfaces';
import { BuildError } from './util/errors';
import { Logger } from './logger/logger';
import { canRunTranspileUpdate } from './transpile';
import { fillConfigDefaults, getUserConfigFile, replacePathVars } from './util/config';
import { extname, join, normalize, resolve as pathResolve } from 'path';
import { Logger } from './logger/logger';
import * as chokidar from 'chokidar';
import * as Constants from './util/constants';
import { BuildError } from './util/errors';
import { getIntPropertyValue } from './util/helpers';
import { BuildContext, BuildState, ChangedFile, TaskInfo } from './util/interfaces';


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

if (!watcher.paths) {
Expand Down

0 comments on commit 2e2a647

Please sign in to comment.