perf(docs-infra): avoid unnecessary I/O operation in `ng-packages-installer` (#28510)
PR Close #28510
This commit is contained in:
parent
2b9811dad4
commit
08f55b35a5
|
@ -62,7 +62,7 @@ class NgPackagesInstaller {
|
|||
* contents and acts as an indicator that dependencies have been overridden.
|
||||
*/
|
||||
installLocalDependencies() {
|
||||
if (this._checkLocalMarker() !== true || this.force) {
|
||||
if (this.force || !this._checkLocalMarker()) {
|
||||
const pathToPackageConfig = path.resolve(this.projectDir, PACKAGE_JSON);
|
||||
const packages = this._getDistPackages();
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@ describe('NgPackagesInstaller', () => {
|
|||
|
||||
beforeEach(() => {
|
||||
spyOn(installer, '_checkLocalMarker');
|
||||
spyOn(installer, '_installDeps');
|
||||
spyOn(installer, '_setLocalMarker');
|
||||
|
||||
// These are the packages that are "found" in the dist directory
|
||||
dummyNgPackages = {
|
||||
|
@ -121,12 +123,20 @@ describe('NgPackagesInstaller', () => {
|
|||
});
|
||||
|
||||
describe('when there is a local package marker', () => {
|
||||
beforeEach(() => installer._checkLocalMarker.and.returnValue(true));
|
||||
|
||||
it('should not continue processing', () => {
|
||||
installer._checkLocalMarker.and.returnValue(true);
|
||||
installer.installLocalDependencies();
|
||||
expect(installer._checkLocalMarker).toHaveBeenCalled();
|
||||
expect(installer._getDistPackages).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should continue processing (without checking for local marker) if `force` is true', () => {
|
||||
installer.force = true;
|
||||
installer.installLocalDependencies();
|
||||
expect(installer._checkLocalMarker).not.toHaveBeenCalled();
|
||||
expect(installer._getDistPackages).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when there is no local package marker', () => {
|
||||
|
@ -135,8 +145,7 @@ describe('NgPackagesInstaller', () => {
|
|||
beforeEach(() => {
|
||||
log = [];
|
||||
fs.writeFileSync.and.callFake((filePath, contents) => filePath === packageJsonPath && log.push(`writeFile: ${contents}`));
|
||||
spyOn(installer, '_installDeps').and.callFake(() => log.push('installDeps:'));
|
||||
spyOn(installer, '_setLocalMarker');
|
||||
installer._installDeps.and.callFake(() => log.push('installDeps:'));
|
||||
installer._checkLocalMarker.and.returnValue(false);
|
||||
installer.installLocalDependencies();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue