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
This commit is contained in:
Pete Bacon Darwin 2020-05-06 22:07:06 +01:00 committed by Alex Rickabaugh
parent 3f3e9b7555
commit fc4741f638
2 changed files with 18 additions and 9 deletions

View File

@ -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;
}

View File

@ -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);
});
});
});