Skip to content

Commit 966c0ae

Browse files
why520crazyalan-agius4
authored andcommitted
fix(@angular-devkit/core): transform path using getSystemPath for NodeJsAsyncHost's exists method
1 parent cc68b07 commit 966c0ae

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

packages/angular_devkit/core/node/host.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,13 @@ export class NodeJsAsyncHost implements virtualFs.Host<Stats> {
136136
}
137137

138138
exists(path: Path): Observable<boolean> {
139-
return observableFrom(exists(path));
139+
return observableFrom(exists(getSystemPath(path)));
140140
}
141141

142142
isDirectory(path: Path): Observable<boolean> {
143143
return this.stat(path).pipe(map((stat) => stat.isDirectory()));
144144
}
145+
145146
isFile(path: Path): Observable<boolean> {
146147
return this.stat(path).pipe(map((stat) => stat.isFile()));
147148
}
@@ -267,6 +268,7 @@ export class NodeJsSyncHost implements virtualFs.Host<Stats> {
267268
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
268269
return this.stat(path)!.pipe(map((stat) => stat.isDirectory()));
269270
}
271+
270272
isFile(path: Path): Observable<boolean> {
271273
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
272274
return this.stat(path)!.pipe(map((stat) => stat.isFile()));

packages/angular_devkit/core/node/host_spec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,17 @@ describe('NodeJsAsyncHost', () => {
3030
root = temp.mkdirSync('core-node-spec-');
3131
host = new virtualFs.ScopedHost(new NodeJsAsyncHost(), normalize(root));
3232
});
33+
3334
afterEach((done) => host.delete(normalize('/')).toPromise().then(done, done.fail));
3435

36+
it('should get correct result for exists', async () => {
37+
let isExists = await host.exists(normalize('not-found')).toPromise();
38+
expect(isExists).toBe(false);
39+
await host.write(normalize('not-found'), virtualFs.stringToFileBuffer('content')).toPromise();
40+
isExists = await host.exists(normalize('not-found')).toPromise();
41+
expect(isExists).toBe(true);
42+
});
43+
3544
linuxOnlyIt(
3645
'can watch',
3746
(done) => {

0 commit comments

Comments
 (0)