From 2da45e629dbf8c2e3b83c369381e261741b619b1 Mon Sep 17 00:00:00 2001 From: Tobias Bosch Date: Thu, 10 Aug 2017 14:46:42 -0700 Subject: [PATCH] fix(tsc-wrapped): make `test.sh tools` run the tsc-wrapped tests again (#18683) --- tools/cjs-jasmine/index-tools.ts | 11 +++++------ tools/tsc-watch/index.ts | 4 ++-- tools/tsc-watch/tsc_watch.ts | 19 +++++++++++++------ 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/tools/cjs-jasmine/index-tools.ts b/tools/cjs-jasmine/index-tools.ts index b584b66c37..77c68d70b6 100644 --- a/tools/cjs-jasmine/index-tools.ts +++ b/tools/cjs-jasmine/index-tools.ts @@ -23,9 +23,9 @@ require('zone.js/dist/fake-async-test.js'); var jrunner = new JasmineRunner(); (global as any)['jasmine'] = jrunner.jasmine; require('zone.js/dist/jasmine-patch.js'); -var toolsDir = process.cwd() + '/dist/tools'; -function toolsDirRequire(moduleId: string) { - return require(path.join(toolsDir, moduleId)); +var rootDir = process.cwd(); +function rootDirRequire(moduleId: string) { + return require(path.join(rootDir, moduleId)); } // Tun on full stack traces in errors to help debugging @@ -40,9 +40,8 @@ if (globsIndex < 0) { args = process.argv.slice(globsIndex + 1); } -var specFiles = args.map(function(globstr: string) { return glob.sync(globstr, {cwd: toolsDir}); }) +var specFiles = args.map(function(globstr: string) { return glob.sync(globstr, {cwd: rootDir}); }) .reduce((specFiles: string[], paths: string[]) => specFiles.concat(paths), []); - jasmine.DEFAULT_TIMEOUT_INTERVAL = 100; jrunner.configureDefaultReporter({showColors: process.argv.indexOf('--no-color') === -1}); @@ -50,5 +49,5 @@ jrunner.configureDefaultReporter({showColors: process.argv.indexOf('--no-color') jrunner.onComplete(function(passed: boolean) { process.exit(passed ? 0 : 1); }); jrunner.projectBaseDir = path.resolve(__dirname, '../../'); jrunner.specDir = ''; -specFiles.forEach((file: string) => { toolsDirRequire(file); }); +specFiles.forEach((file: string) => { rootDirRequire(file); }); jrunner.execute(); diff --git a/tools/tsc-watch/index.ts b/tools/tsc-watch/index.ts index 1e6e6d5a57..d3e1e44f39 100644 --- a/tools/tsc-watch/index.ts +++ b/tools/tsc-watch/index.ts @@ -96,10 +96,10 @@ if (platform == 'node') { } else if (platform == 'tools') { tscWatch = new TscWatch(Object.assign( { - tsconfig: 'tools/tsconfig.json', + tsconfig: ['tools/tsconfig.json', 'packages/tsc-wrapped/tsconfig.json'], onChangeCmds: [[ 'node', 'dist/tools/cjs-jasmine/index-tools', '--', - '@angular/tsc-wrapped/**/*{_,.}spec.js' + 'dist/all/@angular/tsc-wrapped/**/*{_,.}spec.js' ]] }, BaseConfig)); diff --git a/tools/tsc-watch/tsc_watch.ts b/tools/tsc-watch/tsc_watch.ts index 541549ed5b..5143b6bd93 100644 --- a/tools/tsc-watch/tsc_watch.ts +++ b/tools/tsc-watch/tsc_watch.ts @@ -22,7 +22,7 @@ export const TSC = normalize('node_modules/.bin/tsc') + (/^win/.test(platform()) export type Command = (stdIn: any, stdErr: any) => Promise; export class TscWatch { - private tsconfig: string; + private tsconfig: string[]; private start: string|RegExp; private error: string|RegExp; private complete: string|RegExp; @@ -33,13 +33,13 @@ export class TscWatch { private runOnce: boolean = false; constructor({tsconfig, start, error, complete, onStartCmds = null, onChangeCmds = null}: { - tsconfig: string, + tsconfig: string | string[], error: string|RegExp, start: string, complete: string, onStartCmds?: Array, onChangeCmds?: Array }) { console.log('Watching:', tsconfig, 'in', process.cwd()); - this.tsconfig = tsconfig; + this.tsconfig = Array.isArray(tsconfig) ? tsconfig : [tsconfig]; this.start = start; this.error = error; this.complete = complete; @@ -48,10 +48,17 @@ export class TscWatch { } watch() { - const args = [TSC, '--emitDecoratorMetadata', '--project', this.tsconfig]; - if (!this.runOnce) args.push('--watch'); const tsc = - this.runCmd(args, {}, (d) => this.consumeLine(d, false), (d) => this.consumeLine(d, true)); + Promise + .all(this.tsconfig.map(tsconfig => { + const args = [TSC, '--emitDecoratorMetadata', '--project', tsconfig]; + if (!this.runOnce) args.push('--watch'); + return this.runCmd( + args, {}, (d) => this.consumeLine(d, false), (d) => this.consumeLine(d, true)); + })) + .then( + exitCodes => + exitCodes.reduce((prevValue, currValue) => Math.max(prevValue, currValue), 0)); if (this.runOnce) { tsc.then(() => this.triggerCmds(), code => process.exit(code)); }