diff --git a/addon/ng2/blueprints/ng2/files/src/tsconfig.json b/addon/ng2/blueprints/ng2/files/src/tsconfig.json index 165ab9b6d60f..28cc5a60e546 100644 --- a/addon/ng2/blueprints/ng2/files/src/tsconfig.json +++ b/addon/ng2/blueprints/ng2/files/src/tsconfig.json @@ -9,10 +9,16 @@ "moduleResolution": "node", "noEmitOnError": true, "noImplicitAny": false, - "outDir": "../dist/", + "//outDir": "this option is used only during manual invocation of tsc usually while debugging", + "outDir": "../dist-manual/", "rootDir": ".", "sourceMap": true, "sourceRoot": "/", "target": "es5" - } + }, + + "files": [ + "app/main.ts", + "typings.d.ts" + ] } diff --git a/lib/broccoli/angular2-app.js b/lib/broccoli/angular2-app.js index 2cb6ba39a958..5968fc01785e 100644 --- a/lib/broccoli/angular2-app.js +++ b/lib/broccoli/angular2-app.js @@ -18,7 +18,17 @@ function Angular2App(defaults, options, additionalPaths) { } Angular2App.prototype.toTree = function() { - var sourceTree = 'src'; + var sourceDir = 'src'; + + var sourceTree = new Funnel('src', { + destDir: 'src' + }); + + var typingsTree = new Funnel('typings', { + include: ['browser.d.ts', 'browser/**'], + destDir: 'typings' + }); + var vendorNpmFiles = [ 'systemjs/dist/system-polyfills.js', 'systemjs/dist/system.src.js', @@ -31,28 +41,50 @@ Angular2App.prototype.toTree = function() { 'angular2/bundles/upgrade.dev.js' ]; + + if (this.options && this.options.vendorNpmFiles) { vendorNpmFiles = vendorNpmFiles.concat(this.options.vendorNpmFiles); } - var tsConfigCompilerOptions = JSON.parse(fs.readFileSync('src/tsconfig.json', 'utf-8')).compilerOptions; - tsConfigCompilerOptions.rootFilePaths = ['typings.d.ts'].concat(this.additionalPaths) - .map(function(name) { - return path.join(process.cwd(), sourceTree, name) + var tsconfig = JSON.parse(fs.readFileSync('src/tsconfig.json', 'utf-8')); + var tsConfigCompilerOptions = tsconfig.compilerOptions; + + + // TODO(i): why do we need these additional paths? remove? + tsConfigCompilerOptions.rootFilePaths = this.additionalPaths.map(function(name) { + return path.join(process.cwd(), sourceDir, name) }); - var tsTree = compileWithTypescript(sourceTree, tsConfigCompilerOptions); - var tsSrcTree = new Funnel(sourceTree, { + // TODO(i): kill rootFilePaths in broccoli-typescript and use tsconfig.json#files instead + tsConfigCompilerOptions.rootFilePaths = tsConfigCompilerOptions.rootFilePaths. + concat(tsconfig.files.map(function(p) { + // TODO(i): this is a hack - for some reason we need to prefix all paths with srcDir because + // tsc's "rootDir" doesn't take effect when resolving "files" paths + return path.join(sourceDir, p); + })); + + + var srcAndTypingsTree = mergeTrees([sourceTree, typingsTree]); + + var tsTree = compileWithTypescript(srcAndTypingsTree, tsConfigCompilerOptions); + + tsTree = new Funnel(tsTree, { + srcDir: 'src', + exclude: ['*.d.ts', 'tsconfig.json'] + }); + + var tsSrcTree = new Funnel(sourceDir, { include: ['**/*.ts'], allowEmpty: true }); - var jsTree = new Funnel(sourceTree, { + var jsTree = new Funnel(sourceDir, { include: ['**/*.js'], allowEmpty: true }); - var assetTree = new Funnel(sourceTree, { + var assetTree = new Funnel(sourceDir, { include: ['**/*.*'], exclude: ['**/*.ts', '**/*.js'], allowEmpty: true