Skip to content

Commit

Permalink
fix(@angular-devkit/core): transform path using getSystemPath for Nod…
Browse files Browse the repository at this point in the history
…eJsAsyncHost's `exists` method
  • Loading branch information
why520crazy authored and alan-agius4 committed Jun 2, 2021
1 parent cc68b07 commit 966c0ae
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/angular_devkit/core/node/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,13 @@ export class NodeJsAsyncHost implements virtualFs.Host<Stats> {
}

exists(path: Path): Observable<boolean> {
return observableFrom(exists(path));
return observableFrom(exists(getSystemPath(path)));
}

isDirectory(path: Path): Observable<boolean> {
return this.stat(path).pipe(map((stat) => stat.isDirectory()));
}

isFile(path: Path): Observable<boolean> {
return this.stat(path).pipe(map((stat) => stat.isFile()));
}
Expand Down Expand Up @@ -267,6 +268,7 @@ export class NodeJsSyncHost implements virtualFs.Host<Stats> {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return this.stat(path)!.pipe(map((stat) => stat.isDirectory()));
}

isFile(path: Path): Observable<boolean> {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return this.stat(path)!.pipe(map((stat) => stat.isFile()));
Expand Down
9 changes: 9 additions & 0 deletions packages/angular_devkit/core/node/host_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 966c0ae

Please sign in to comment.