From 966c0aebbc8c80d68c859a0d0ea083c9a1ccbd23 Mon Sep 17 00:00:00 2001 From: why520crazy Date: Mon, 31 May 2021 19:03:10 +0800 Subject: [PATCH] fix(@angular-devkit/core): transform path using getSystemPath for NodeJsAsyncHost's `exists` method --- packages/angular_devkit/core/node/host.ts | 4 +++- packages/angular_devkit/core/node/host_spec.ts | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/angular_devkit/core/node/host.ts b/packages/angular_devkit/core/node/host.ts index eac6e12d2746..e1879af3b514 100644 --- a/packages/angular_devkit/core/node/host.ts +++ b/packages/angular_devkit/core/node/host.ts @@ -136,12 +136,13 @@ export class NodeJsAsyncHost implements virtualFs.Host { } exists(path: Path): Observable { - return observableFrom(exists(path)); + return observableFrom(exists(getSystemPath(path))); } isDirectory(path: Path): Observable { return this.stat(path).pipe(map((stat) => stat.isDirectory())); } + isFile(path: Path): Observable { return this.stat(path).pipe(map((stat) => stat.isFile())); } @@ -267,6 +268,7 @@ export class NodeJsSyncHost implements virtualFs.Host { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return this.stat(path)!.pipe(map((stat) => stat.isDirectory())); } + isFile(path: Path): Observable { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return this.stat(path)!.pipe(map((stat) => stat.isFile())); diff --git a/packages/angular_devkit/core/node/host_spec.ts b/packages/angular_devkit/core/node/host_spec.ts index 86e653124cdc..04c666302add 100644 --- a/packages/angular_devkit/core/node/host_spec.ts +++ b/packages/angular_devkit/core/node/host_spec.ts @@ -30,8 +30,17 @@ describe('NodeJsAsyncHost', () => { root = temp.mkdirSync('core-node-spec-'); host = new virtualFs.ScopedHost(new NodeJsAsyncHost(), normalize(root)); }); + afterEach((done) => host.delete(normalize('/')).toPromise().then(done, done.fail)); + it('should get correct result for exists', async () => { + let isExists = await host.exists(normalize('not-found')).toPromise(); + expect(isExists).toBe(false); + await host.write(normalize('not-found'), virtualFs.stringToFileBuffer('content')).toPromise(); + isExists = await host.exists(normalize('not-found')).toPromise(); + expect(isExists).toBe(true); + }); + linuxOnlyIt( 'can watch', (done) => {