forked from angular/angular
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(ngcc): cache parsed tsconfig between runs (angular#37417)
This commit will store a cached copy of the parsed tsconfig that can be reused if the tsconfig path is the same. This will improve the ngcc "noop" case, where there is no processing to do, when the entry-points have already been processed. Previously we were parsing this config every time we checked for entry-points to process, which can take up to seconds in some cases. Resolves angular#36882 PR Close angular#37417
- Loading branch information
1 parent
2021ad1
commit 6e7bd93
Showing
4 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.io/license | ||
*/ | ||
|
||
import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system'; | ||
import {runInEachFileSystem} from '@angular/compiler-cli/src/ngtsc/file_system/testing'; | ||
|
||
import {clearTsConfigCache, getSharedSetup, NgccOptions} from '../src/ngcc_options'; | ||
|
||
import {MockLogger} from './helpers/mock_logger'; | ||
|
||
|
||
runInEachFileSystem(() => { | ||
let fs: FileSystem; | ||
let _abs: typeof absoluteFrom; | ||
let projectPath: AbsoluteFsPath; | ||
|
||
beforeEach(() => { | ||
fs = getFileSystem(); | ||
_abs = absoluteFrom; | ||
projectPath = _abs('/project'); | ||
}); | ||
|
||
describe('getSharedSetup()', () => { | ||
let pathToProjectTsConfig: AbsoluteFsPath; | ||
let pathToCustomTsConfig: AbsoluteFsPath; | ||
|
||
beforeEach(() => { | ||
clearTsConfigCache(); | ||
pathToProjectTsConfig = fs.resolve(projectPath, 'tsconfig.json'); | ||
fs.ensureDir(fs.dirname(pathToProjectTsConfig)); | ||
fs.writeFile(pathToProjectTsConfig, '{"files": ["src/index.ts"]}'); | ||
pathToCustomTsConfig = _abs('/path/to/tsconfig.json'); | ||
fs.ensureDir(fs.dirname(pathToCustomTsConfig)); | ||
fs.writeFile(pathToCustomTsConfig, '{"files": ["custom/index.ts"]}'); | ||
}); | ||
|
||
it('should load the tsconfig.json at the project root if tsConfigPath is `undefined`', () => { | ||
const setup = getSharedSetup({...createOptions()}); | ||
expect(setup.tsConfigPath).toBeUndefined(); | ||
expect(setup.tsConfig?.rootNames).toEqual([fs.resolve(projectPath, 'src/index.ts')]); | ||
}); | ||
|
||
it('should load a specific tsconfig.json if tsConfigPath is a string', () => { | ||
const setup = getSharedSetup({...createOptions(), tsConfigPath: pathToCustomTsConfig}); | ||
expect(setup.tsConfigPath).toEqual(pathToCustomTsConfig); | ||
expect(setup.tsConfig?.rootNames).toEqual([_abs('/path/to/custom/index.ts')]); | ||
}); | ||
|
||
it('should not load a tsconfig.json if tsConfigPath is `null`', () => { | ||
const setup = getSharedSetup({...createOptions(), tsConfigPath: null}); | ||
expect(setup.tsConfigPath).toBe(null); | ||
expect(setup.tsConfig).toBe(null); | ||
}); | ||
}); | ||
|
||
/** | ||
* This function creates an object that contains the minimal required properties for NgccOptions. | ||
*/ | ||
function createOptions(): NgccOptions { | ||
return { | ||
async: false, | ||
basePath: fs.resolve(projectPath, 'node_modules'), | ||
propertiesToConsider: ['es2015'], | ||
compileAllFormats: false, | ||
createNewEntryPointFormats: false, | ||
logger: new MockLogger(), | ||
fileSystem: getFileSystem(), | ||
errorOnFailedEntryPoint: true, | ||
enableI18nLegacyMessageIdFormat: true, | ||
invalidateEntryPointManifest: false, | ||
}; | ||
} | ||
}); |