Skip to content

Commit cfa0382

Browse files
committed
fix(@angular-devkit/core): workaround for RxJS issue 3740
See ReactiveX/rxjs#3740
1 parent ce4d7af commit cfa0382

File tree

1 file changed

+60
-24
lines changed
  • packages/angular_devkit/core/node

1 file changed

+60
-24
lines changed

packages/angular_devkit/core/node/host.ts

Lines changed: 60 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -224,28 +224,40 @@ export class NodeJsSyncHost implements virtualFs.Host<fs.Stats> {
224224

225225
write(path: Path, content: virtualFs.FileBuffer): Observable<void> {
226226
return new Observable(obs => {
227-
// Create folders if necessary.
228-
const _createDir = (path: Path) => {
229-
if (fs.existsSync(getSystemPath(path))) {
230-
return;
231-
}
227+
// TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
228+
// fixed.
229+
try {
230+
// Create folders if necessary.
231+
const _createDir = (path: Path) => {
232+
if (fs.existsSync(getSystemPath(path))) {
233+
return;
234+
}
235+
_createDir(dirname(path));
236+
fs.mkdirSync(getSystemPath(path));
237+
};
232238
_createDir(dirname(path));
233-
fs.mkdirSync(getSystemPath(path));
234-
};
235-
_createDir(dirname(path));
236-
fs.writeFileSync(getSystemPath(path), new Uint8Array(content));
239+
fs.writeFileSync(getSystemPath(path), new Uint8Array(content));
237240

238-
obs.next();
239-
obs.complete();
241+
obs.next();
242+
obs.complete();
243+
} catch (err) {
244+
obs.error(err);
245+
}
240246
});
241247
}
242248

243249
read(path: Path): Observable<virtualFs.FileBuffer> {
244250
return new Observable(obs => {
245-
const buffer = fs.readFileSync(getSystemPath(path));
251+
// TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
252+
// fixed.
253+
try {
254+
const buffer = fs.readFileSync(getSystemPath(path));
246255

247-
obs.next(new Uint8Array(buffer).buffer as virtualFs.FileBuffer);
248-
obs.complete();
256+
obs.next(new Uint8Array(buffer).buffer as virtualFs.FileBuffer);
257+
obs.complete();
258+
} catch (err) {
259+
obs.error(err);
260+
}
249261
});
250262
}
251263

@@ -277,24 +289,42 @@ export class NodeJsSyncHost implements virtualFs.Host<fs.Stats> {
277289

278290
rename(from: Path, to: Path): Observable<void> {
279291
return new Observable(obs => {
280-
fs.renameSync(getSystemPath(from), getSystemPath(to));
281-
obs.next();
282-
obs.complete();
292+
// TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
293+
// fixed.
294+
try {
295+
fs.renameSync(getSystemPath(from), getSystemPath(to));
296+
obs.next();
297+
obs.complete();
298+
} catch (err) {
299+
obs.error(err);
300+
}
283301
});
284302
}
285303

286304
list(path: Path): Observable<PathFragment[]> {
287305
return new Observable(obs => {
288-
const names = fs.readdirSync(getSystemPath(path));
289-
obs.next(names.map(name => fragment(name)));
290-
obs.complete();
306+
// TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
307+
// fixed.
308+
try {
309+
const names = fs.readdirSync(getSystemPath(path));
310+
obs.next(names.map(name => fragment(name)));
311+
obs.complete();
312+
} catch (err) {
313+
obs.error(err);
314+
}
291315
});
292316
}
293317

294318
exists(path: Path): Observable<boolean> {
295319
return new Observable(obs => {
296-
obs.next(fs.existsSync(getSystemPath(path)));
297-
obs.complete();
320+
// TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
321+
// fixed.
322+
try {
323+
obs.next(fs.existsSync(getSystemPath(path)));
324+
obs.complete();
325+
} catch (err) {
326+
obs.error(err);
327+
}
298328
});
299329
}
300330

@@ -310,8 +340,14 @@ export class NodeJsSyncHost implements virtualFs.Host<fs.Stats> {
310340
// Some hosts may not support stat.
311341
stat(path: Path): Observable<virtualFs.Stats<fs.Stats>> {
312342
return new Observable(obs => {
313-
obs.next(fs.statSync(getSystemPath(path)));
314-
obs.complete();
343+
// TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
344+
// fixed.
345+
try {
346+
obs.next(fs.statSync(getSystemPath(path)));
347+
obs.complete();
348+
} catch (err) {
349+
obs.error(err);
350+
}
315351
});
316352
}
317353

0 commit comments

Comments
 (0)