From fc4741f638b7680546d81e4570f9eac7eb36c12b Mon Sep 17 00:00:00 2001 From: Pete Bacon Darwin Date: Wed, 6 May 2020 22:07:06 +0100 Subject: [PATCH] fix(compiler-cli): `isCaseSensitive()` returns correct value (#36859) Previously this method was returning the exact opposite value than the correct one. Also, calling `this.exists()` causes an infinite recursions, so the actual file-system `fs.existsSync()` method is used to ascertain the case-sensitivity of the file-system. PR Close #36859 --- .../file_system/src/node_js_file_system.ts | 4 +++- .../test/node_js_file_system_spec.ts | 23 ++++++++++++------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/compiler-cli/src/ngtsc/file_system/src/node_js_file_system.ts b/packages/compiler-cli/src/ngtsc/file_system/src/node_js_file_system.ts index 2a1a41a7b5..9e50a8e494 100644 --- a/packages/compiler-cli/src/ngtsc/file_system/src/node_js_file_system.ts +++ b/packages/compiler-cli/src/ngtsc/file_system/src/node_js_file_system.ts @@ -68,7 +68,9 @@ export class NodeJSFileSystem implements FileSystem { } isCaseSensitive(): boolean { if (this._caseSensitive === undefined) { - this._caseSensitive = this.exists(togglePathCase(__filename)); + // Note the use of the real file-system is intentional: + // `this.exists()` relies upon `isCaseSensitive()` so that would cause an infinite recursion. + this._caseSensitive = !fs.existsSync(togglePathCase(__filename)); } return this._caseSensitive; } diff --git a/packages/compiler-cli/src/ngtsc/file_system/test/node_js_file_system_spec.ts b/packages/compiler-cli/src/ngtsc/file_system/test/node_js_file_system_spec.ts index eca3261239..2e15f6b646 100644 --- a/packages/compiler-cli/src/ngtsc/file_system/test/node_js_file_system_spec.ts +++ b/packages/compiler-cli/src/ngtsc/file_system/test/node_js_file_system_spec.ts @@ -153,14 +153,6 @@ describe('NodeJSFileSystem', () => { expect(mkdirCalls).toEqual([xPath, xyPath, xyzPath]); }); - describe('removeDeep()', () => { - it('should delegate to fsExtra.remove()', () => { - const spy = spyOn(fsExtra, 'removeSync'); - fs.removeDeep(abcPath); - expect(spy).toHaveBeenCalledWith(abcPath); - }); - }); - it('should not fail if a directory (that did not exist before) does exist when trying to create it', () => { let abcPathExists = false; @@ -228,4 +220,19 @@ describe('NodeJSFileSystem', () => { expect(isDirectorySpy).toHaveBeenCalledTimes(1); }); }); + + describe('removeDeep()', () => { + it('should delegate to fsExtra.remove()', () => { + const spy = spyOn(fsExtra, 'removeSync'); + fs.removeDeep(abcPath); + expect(spy).toHaveBeenCalledWith(abcPath); + }); + }); + + describe('isCaseSensitive()', () => { + it('should return true if the FS is case-sensitive', () => { + const isCaseSensitive = !realFs.existsSync(__filename.toUpperCase()); + expect(fs.isCaseSensitive()).toEqual(isCaseSensitive); + }); + }); });