build(broccoli): Clean-up TypeScript build
The TypeScript parser now only references files that are in broccoli trees. Closes #7941
This commit is contained in:
parent
85c1927993
commit
f371c9066d
|
@ -58,7 +58,6 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin {
|
||||||
private genInternalTypings: boolean = false;
|
private genInternalTypings: boolean = false;
|
||||||
|
|
||||||
static includeExtensions = ['.ts'];
|
static includeExtensions = ['.ts'];
|
||||||
static excludeExtensions = ['.d.ts'];
|
|
||||||
|
|
||||||
constructor(public inputPath: string, public cachePath: string, public options) {
|
constructor(public inputPath: string, public cachePath: string, public options) {
|
||||||
if (options.rootFilePaths) {
|
if (options.rootFilePaths) {
|
||||||
|
@ -83,11 +82,7 @@ class DiffingTSCompiler implements DiffingBroccoliPlugin {
|
||||||
this.genInternalTypings = false;
|
this.genInternalTypings = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: the above turns rootDir set to './' into an empty string - looks like a tsc bug
|
this.tsOpts.rootDir = inputPath;
|
||||||
// check back when we upgrade to 1.7.x
|
|
||||||
if (this.tsOpts.rootDir === '') {
|
|
||||||
this.tsOpts.rootDir = './';
|
|
||||||
}
|
|
||||||
this.tsOpts.outDir = this.cachePath;
|
this.tsOpts.outDir = this.cachePath;
|
||||||
|
|
||||||
this.tsServiceHost = new CustomLanguageServiceHost(this.tsOpts, this.rootFilePaths,
|
this.tsServiceHost = new CustomLanguageServiceHost(this.tsOpts, this.rootFilePaths,
|
||||||
|
@ -331,7 +326,9 @@ class CustomLanguageServiceHost implements ts.LanguageServiceHost {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
getScriptFileNames(): string[] { return this.fileNames; }
|
getScriptFileNames(): string[] {
|
||||||
|
return this.fileNames.map(f => path.join(this.treeInputPath, f));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
getScriptVersion(fileName: string): string {
|
getScriptVersion(fileName: string): string {
|
||||||
|
@ -339,46 +336,24 @@ class CustomLanguageServiceHost implements ts.LanguageServiceHost {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method is called quite a bit to lookup 3 kinds of paths:
|
|
||||||
* 1/ files in the fileRegistry
|
|
||||||
* - these are the files in our project that we are watching for changes
|
|
||||||
* - in the future we could add caching for these files and invalidate the cache when
|
|
||||||
* the file is changed lazily during lookup
|
|
||||||
* 2/ .d.ts and library files not in the fileRegistry
|
|
||||||
* - these are not our files, they come from tsd or typescript itself
|
|
||||||
* - these files change only rarely but since we need them very rarely, it's not worth the
|
|
||||||
* cache invalidation hassle to cache them
|
|
||||||
* 3/ bogus paths that typescript compiler tries to lookup during import resolution
|
|
||||||
* - these paths are tricky to cache since files come and go and paths that was bogus in the
|
|
||||||
* past might not be bogus later
|
|
||||||
*
|
|
||||||
* In the initial experiments the impact of this caching was insignificant (single digit %) and
|
|
||||||
* not worth the potential issues with stale cache records.
|
|
||||||
*/
|
|
||||||
getScriptSnapshot(tsFilePath: string): ts.IScriptSnapshot {
|
getScriptSnapshot(tsFilePath: string): ts.IScriptSnapshot {
|
||||||
let absoluteTsFilePath;
|
// TypeScript seems to request lots of bogus paths during import path lookup and resolution,
|
||||||
|
// so we we just return undefined when the path is not correct.
|
||||||
|
|
||||||
if (tsFilePath == this.defaultLibFilePath || path.isAbsolute(tsFilePath)) {
|
// Ensure it is in the input tree or a lib.d.ts file.
|
||||||
absoluteTsFilePath = tsFilePath;
|
if (!startsWith(tsFilePath, this.treeInputPath) && !tsFilePath.match(/\/lib(\..*)*.d\.ts$/)) {
|
||||||
} else if (this.compilerOptions.moduleResolution === ts.ModuleResolutionKind.NodeJs &&
|
if (fs.existsSync(tsFilePath)) {
|
||||||
tsFilePath.match(/^node_modules/)) {
|
console.log('Rejecting', tsFilePath, '. File is not in the input tree.');
|
||||||
absoluteTsFilePath = path.resolve(tsFilePath);
|
}
|
||||||
} else if (tsFilePath.match(/^rxjs/)) {
|
|
||||||
absoluteTsFilePath = path.resolve('node_modules', tsFilePath);
|
|
||||||
} else if (tsFilePath.match(/^node_modules/)) {
|
|
||||||
absoluteTsFilePath = path.resolve('node_modules/../', tsFilePath);
|
|
||||||
} else {
|
|
||||||
absoluteTsFilePath = path.join(this.treeInputPath, tsFilePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (!fs.existsSync(absoluteTsFilePath)) {
|
|
||||||
// TypeScript seems to request lots of bogus paths during import path lookup and resolution,
|
|
||||||
// so we we just return undefined when the path is not correct.
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
return ts.ScriptSnapshot.fromString(fs.readFileSync(absoluteTsFilePath, FS_OPTS));
|
|
||||||
|
// Ensure it exists
|
||||||
|
if (!fs.existsSync(tsFilePath)) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ts.ScriptSnapshot.fromString(fs.readFileSync(tsFilePath, FS_OPTS));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -402,6 +377,10 @@ function clone<T>(object: T): T {
|
||||||
return <T>result;
|
return <T>result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function startsWith(str: string, substring: string): boolean {
|
||||||
|
return str.substring(0, substring.length) === substring;
|
||||||
|
}
|
||||||
|
|
||||||
function endsWith(str: string, substring: string): boolean {
|
function endsWith(str: string, substring: string): boolean {
|
||||||
return str.indexOf(substring, str.length - substring.length) !== -1;
|
return str.indexOf(substring, str.length - substring.length) !== -1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,13 +113,18 @@ module.exports = function makeBrowserTree(options, destinationPath) {
|
||||||
{include: ['**/**'], exclude: ['e2e_test/**'], destDir: '/benchpress/'});
|
{include: ['**/**'], exclude: ['e2e_test/**'], destDir: '/benchpress/'});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let externalTypings =
|
||||||
|
new Funnel('node_modules', {include: ['rxjs/**/*.d.ts', 'zone.js/**/*.d.ts']});
|
||||||
|
|
||||||
|
|
||||||
var modulesTree = mergeTrees([
|
var modulesTree = mergeTrees([
|
||||||
angular2Tree,
|
angular2Tree,
|
||||||
benchmarksTree,
|
benchmarksTree,
|
||||||
benchmarksExternalTree,
|
benchmarksExternalTree,
|
||||||
payloadTestsTree,
|
payloadTestsTree,
|
||||||
playgroundTree,
|
playgroundTree,
|
||||||
benchpressTree
|
benchpressTree,
|
||||||
|
externalTypings,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
var es6PolyfillTypings =
|
var es6PolyfillTypings =
|
||||||
|
|
|
@ -30,20 +30,28 @@ module.exports = function makeNodeTree(projects, destinationPath) {
|
||||||
'angular2/src/upgrade/**',
|
'angular2/src/upgrade/**',
|
||||||
'angular2/upgrade.ts',
|
'angular2/upgrade.ts',
|
||||||
'angular2/platform/testing/**',
|
'angular2/platform/testing/**',
|
||||||
|
'angular2/manual_typings/**',
|
||||||
|
'angular2/typings/**'
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
let ambientTypings = [
|
let externalTypings = [
|
||||||
'angular2/typings/hammerjs/hammerjs.d.ts',
|
'angular2/typings/hammerjs/hammerjs.d.ts',
|
||||||
'angular2/typings/node/node.d.ts',
|
'angular2/typings/node/node.d.ts',
|
||||||
'node_modules/zone.js/dist/zone.js.d.ts',
|
|
||||||
'angular2/manual_typings/globals.d.ts',
|
'angular2/manual_typings/globals.d.ts',
|
||||||
'angular2/typings/es6-collections/es6-collections.d.ts',
|
'angular2/typings/es6-collections/es6-collections.d.ts',
|
||||||
'angular2/typings/es6-promise/es6-promise.d.ts'
|
'angular2/typings/es6-promise/es6-promise.d.ts'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let externalTypingsTree = new Funnel('modules', {files: externalTypings});
|
||||||
|
|
||||||
|
let packageTypings =
|
||||||
|
new Funnel('node_modules', {include: ['rxjs/**/*.d.ts', 'zone.js/**/*.d.ts']});
|
||||||
|
|
||||||
|
let compileSrcContext = mergeTrees([srcTree, externalTypingsTree, packageTypings]);
|
||||||
|
|
||||||
// Compile the sources and generate the @internal .d.ts
|
// Compile the sources and generate the @internal .d.ts
|
||||||
let compiledSrcTreeWithInternals = compileTree(srcTree, true, ambientTypings);
|
let compiledSrcTreeWithInternals = compileTree(compileSrcContext, true, []);
|
||||||
|
|
||||||
var testTree = new Funnel('modules', {
|
var testTree = new Funnel('modules', {
|
||||||
include: [
|
include: [
|
||||||
|
@ -71,6 +79,8 @@ module.exports = function makeNodeTree(projects, destinationPath) {
|
||||||
'angular2/test/platform/xhr_impl_spec.ts',
|
'angular2/test/platform/xhr_impl_spec.ts',
|
||||||
'angular2/test/platform/browser/**/*.ts',
|
'angular2/test/platform/browser/**/*.ts',
|
||||||
'angular2/test/common/forms/**',
|
'angular2/test/common/forms/**',
|
||||||
|
'angular2/manual_typings/**',
|
||||||
|
'angular2/typings/**',
|
||||||
|
|
||||||
// we call browser's bootstrap
|
// we call browser's bootstrap
|
||||||
'angular2/test/router/route_config/route_config_spec.ts',
|
'angular2/test/router/route_config/route_config_spec.ts',
|
||||||
|
@ -92,12 +102,17 @@ module.exports = function makeNodeTree(projects, destinationPath) {
|
||||||
let srcPrivateDeclarations =
|
let srcPrivateDeclarations =
|
||||||
new Funnel(compiledSrcTreeWithInternals, {srcDir: INTERNAL_TYPINGS_PATH});
|
new Funnel(compiledSrcTreeWithInternals, {srcDir: INTERNAL_TYPINGS_PATH});
|
||||||
|
|
||||||
testTree = mergeTrees([testTree, srcPrivateDeclarations]);
|
let testAmbients = [
|
||||||
|
|
||||||
let compiledTestTree = compileTree(testTree, false, ambientTypings.concat([
|
|
||||||
'angular2/typings/jasmine/jasmine.d.ts',
|
'angular2/typings/jasmine/jasmine.d.ts',
|
||||||
'angular2/typings/angular-protractor/angular-protractor.d.ts',
|
'angular2/typings/angular-protractor/angular-protractor.d.ts',
|
||||||
]));
|
'angular2/typings/selenium-webdriver/selenium-webdriver.d.ts'
|
||||||
|
];
|
||||||
|
let testAmbientsTree = new Funnel('modules', {files: testAmbients});
|
||||||
|
|
||||||
|
testTree = mergeTrees(
|
||||||
|
[testTree, srcPrivateDeclarations, testAmbientsTree, externalTypingsTree, packageTypings]);
|
||||||
|
|
||||||
|
let compiledTestTree = compileTree(testTree, false, []);
|
||||||
|
|
||||||
// Merge the compiled sources and tests
|
// Merge the compiled sources and tests
|
||||||
let compiledSrcTree =
|
let compiledSrcTree =
|
||||||
|
|
Loading…
Reference in New Issue