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