diff --git a/packages/compiler-cli/src/ngtsc/file_system/src/cached_file_system.ts b/packages/compiler-cli/src/ngtsc/file_system/src/cached_file_system.ts index a141dc5550..7b083ab7c1 100644 --- a/packages/compiler-cli/src/ngtsc/file_system/src/cached_file_system.ts +++ b/packages/compiler-cli/src/ngtsc/file_system/src/cached_file_system.ts @@ -74,11 +74,6 @@ export class CachedFileSystem implements FileSystem { this.existsCache.set(to, true); } - mkdir(path: AbsoluteFsPath): void { - this.delegate.mkdir(path); - this.existsCache.set(path, true); - } - ensureDir(path: AbsoluteFsPath): void { this.delegate.ensureDir(path); while (!this.isRoot(path)) { diff --git a/packages/compiler-cli/src/ngtsc/file_system/src/invalid_file_system.ts b/packages/compiler-cli/src/ngtsc/file_system/src/invalid_file_system.ts index 86023671a7..fcc7cc2034 100644 --- a/packages/compiler-cli/src/ngtsc/file_system/src/invalid_file_system.ts +++ b/packages/compiler-cli/src/ngtsc/file_system/src/invalid_file_system.ts @@ -27,7 +27,6 @@ export class InvalidFileSystem implements FileSystem { extname(path: AbsoluteFsPath|PathSegment): string { throw makeError(); } copyFile(from: AbsoluteFsPath, to: AbsoluteFsPath): void { throw makeError(); } moveFile(from: AbsoluteFsPath, to: AbsoluteFsPath): void { throw makeError(); } - mkdir(path: AbsoluteFsPath): void { throw makeError(); } ensureDir(path: AbsoluteFsPath): void { throw makeError(); } isCaseSensitive(): boolean { throw makeError(); } resolve(...paths: string[]): AbsoluteFsPath { throw makeError(); } 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 627a75d5d2..940afcb2cf 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 @@ -28,7 +28,6 @@ export class NodeJSFileSystem implements FileSystem { pwd(): AbsoluteFsPath { return this.normalize(process.cwd()) as AbsoluteFsPath; } copyFile(from: AbsoluteFsPath, to: AbsoluteFsPath): void { fs.copyFileSync(from, to); } moveFile(from: AbsoluteFsPath, to: AbsoluteFsPath): void { fs.renameSync(from, to); } - mkdir(path: AbsoluteFsPath): void { fs.mkdirSync(path); } ensureDir(path: AbsoluteFsPath): void { const parents: AbsoluteFsPath[] = []; while (!this.isRoot(path) && !this.exists(path)) { @@ -73,7 +72,7 @@ export class NodeJSFileSystem implements FileSystem { private safeMkdir(path: AbsoluteFsPath): void { try { - this.mkdir(path); + fs.mkdirSync(path); } catch (err) { // Ignore the error, if the path already exists and points to a directory. // Re-throw otherwise. diff --git a/packages/compiler-cli/src/ngtsc/file_system/src/types.ts b/packages/compiler-cli/src/ngtsc/file_system/src/types.ts index 40cf6a6f87..a037459f1a 100644 --- a/packages/compiler-cli/src/ngtsc/file_system/src/types.ts +++ b/packages/compiler-cli/src/ngtsc/file_system/src/types.ts @@ -46,7 +46,6 @@ export interface FileSystem { extname(path: AbsoluteFsPath|PathSegment): string; copyFile(from: AbsoluteFsPath, to: AbsoluteFsPath): void; moveFile(from: AbsoluteFsPath, to: AbsoluteFsPath): void; - mkdir(path: AbsoluteFsPath): void; ensureDir(path: AbsoluteFsPath): void; isCaseSensitive(): boolean; isRoot(path: AbsoluteFsPath): boolean; diff --git a/packages/compiler-cli/src/ngtsc/file_system/test/cached_file_system_spec.ts b/packages/compiler-cli/src/ngtsc/file_system/test/cached_file_system_spec.ts index 9bf2a7ccfa..d817045c57 100644 --- a/packages/compiler-cli/src/ngtsc/file_system/test/cached_file_system_spec.ts +++ b/packages/compiler-cli/src/ngtsc/file_system/test/cached_file_system_spec.ts @@ -234,22 +234,6 @@ describe('CachedFileSystem', () => { }); }); - describe('mkdir()', () => { - it('should call delegate', () => { - const spy = spyOn(delegate, 'mkdir'); - fs.mkdir(xyzPath); - expect(spy).toHaveBeenCalledWith(xyzPath); - }); - - it('should update the "exists" cache', () => { - spyOn(delegate, 'mkdir'); - const existsSpy = spyOn(delegate, 'exists'); - fs.mkdir(xyzPath); - expect(fs.exists(xyzPath)).toEqual(true); - expect(existsSpy).not.toHaveBeenCalled(); - }); - }); - describe('ensureDir()', () => { it('should call delegate', () => { const ensureDirSpy = spyOn(delegate, 'ensureDir'); 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 b1e6109cd0..34fe48dfd6 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 @@ -105,14 +105,6 @@ describe('NodeJSFileSystem', () => { }); }); - describe('mkdir()', () => { - it('should delegate to fs.mkdirSync()', () => { - const spy = spyOn(realFs, 'mkdirSync'); - fs.mkdir(xyzPath); - expect(spy).toHaveBeenCalledWith(xyzPath); - }); - }); - describe('ensureDir()', () => { it('should call exists() and fs.mkdir()', () => { const aPath = absoluteFrom('/a'); diff --git a/packages/compiler-cli/src/ngtsc/file_system/testing/src/mock_file_system.ts b/packages/compiler-cli/src/ngtsc/file_system/testing/src/mock_file_system.ts index a19aa08eab..5f7cbbbe71 100644 --- a/packages/compiler-cli/src/ngtsc/file_system/testing/src/mock_file_system.ts +++ b/packages/compiler-cli/src/ngtsc/file_system/testing/src/mock_file_system.ts @@ -96,10 +96,21 @@ export abstract class MockFileSystem implements FileSystem { delete folder[name]; } - mkdir(path: AbsoluteFsPath): void { this.ensureFolders(this._fileTree, this.splitPath(path)); } - ensureDir(path: AbsoluteFsPath): void { - this.ensureFolders(this._fileTree, this.splitPath(path)); + const segments = this.splitPath(path); + let current: Folder = this._fileTree; + + // Convert the root folder to a canonical empty string `''` (on Windows it would be `'C:'`). + segments[0] = ''; + for (const segment of segments) { + if (isFile(current[segment])) { + throw new Error(`Folder already exists as a file.`); + } + if (!current[segment]) { + current[segment] = {}; + } + current = current[segment] as Folder; + } } isRoot(path: AbsoluteFsPath): boolean { return this.dirname(path) === path; } @@ -173,21 +184,6 @@ export abstract class MockFileSystem implements FileSystem { const file = segments.pop() !; return [path.substring(0, path.length - file.length - 1) as AbsoluteFsPath, file]; } - - protected ensureFolders(current: Folder, segments: string[]): Folder { - // Convert the root folder to a canonical empty string `""` (on Windows it would be `C:`). - segments[0] = ''; - for (const segment of segments) { - if (isFile(current[segment])) { - throw new Error(`Folder already exists as a file.`); - } - if (!current[segment]) { - current[segment] = {}; - } - current = current[segment] as Folder; - } - return current; - } } export interface FindResult { path: AbsoluteFsPath;