Skip to content

fix(build): correctly compile source files against typings #306

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

Merged
merged 4 commits into from
Mar 17, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions addon/ng2/blueprints/ng2/files/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep this as ../dist as this is for tooling, more than command line usage of tsc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in a follow up commit.

"rootDir": ".",
"sourceMap": true,
"sourceRoot": "/",
"target": "es5"
}
},

"files": [
"app/main.ts",
"typings.d.ts"
]
}
50 changes: 41 additions & 9 deletions lib/broccoli/angular2-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sourceTree seems unused.

});

var typingsTree = new Funnel('typings', {
include: ['browser.d.ts', 'browser/**'],
destDir: 'typings'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this will end up in dist/typings, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no. it's available at tmp/XXX/typings during compilation but it doesn't make it into the final output.

});

var vendorNpmFiles = [
'systemjs/dist/system-polyfills.js',
'systemjs/dist/system.src.js',
Expand All @@ -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
Expand Down