Skip to content

Commit 30bbdbb

Browse files
clydinpull[bot]
authored andcommitted
refactor(@ngtools/webpack): remove direct rxjs dependency
1 parent 7dcd2ed commit 30bbdbb

File tree

4 files changed

+40
-73
lines changed

4 files changed

+40
-73
lines changed

packages/ngtools/webpack/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ ts_library(
4242
"@npm//@types/webpack",
4343
"@npm//@types/webpack-sources",
4444
"@npm//enhanced-resolve",
45-
"@npm//rxjs",
4645
"@npm//typescript",
4746
"@npm//webpack",
4847
"@npm//webpack-sources",

packages/ngtools/webpack/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"dependencies": {
2424
"@angular-devkit/core": "0.0.0",
2525
"enhanced-resolve": "4.3.0",
26-
"rxjs": "6.6.2",
2726
"webpack-sources": "1.4.3"
2827
},
2928
"peerDependencies": {

packages/ngtools/webpack/src/angular_compiler_plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ import {
8080
NodeWatchFileSystemInterface,
8181
NormalModuleFactoryRequest,
8282
} from './webpack';
83-
import { WebpackInputHost } from './webpack-input-host';
83+
import { createWebpackInputHost } from './webpack-input-host';
8484

8585
export class AngularCompilerPlugin {
8686
private _options: AngularCompilerPluginOptions;
@@ -741,7 +741,7 @@ export class AngularCompilerPlugin {
741741
watchFileSystem: NodeWatchFileSystemInterface,
742742
};
743743

744-
let host: virtualFs.Host<fs.Stats> = this._options.host || new WebpackInputHost(
744+
let host: virtualFs.Host<fs.Stats> = this._options.host || createWebpackInputHost(
745745
compilerWithFileSystems.inputFileSystem,
746746
);
747747

packages/ngtools/webpack/src/webpack-input-host.ts

Lines changed: 38 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -5,92 +5,61 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { Path, PathFragment, fragment, getSystemPath, virtualFs } from '@angular-devkit/core';
8+
import { PathFragment, fragment, getSystemPath, virtualFs } from '@angular-devkit/core';
99
import { Stats } from 'fs';
10-
import { Observable, throwError } from 'rxjs';
11-
import { map } from 'rxjs/operators';
1210
import { InputFileSystem } from 'webpack';
1311

1412
// Host is used instead of ReadonlyHost due to most decorators only supporting Hosts
15-
export class WebpackInputHost implements virtualFs.Host<Stats> {
13+
export function createWebpackInputHost(inputFileSystem: InputFileSystem) {
14+
return virtualFs.createSyncHost<Stats>({
15+
write() {
16+
throw new Error('Not supported.');
17+
},
1618

17-
constructor(public readonly inputFileSystem: InputFileSystem) { }
19+
delete() {
20+
throw new Error('Not supported.');
21+
},
1822

19-
get capabilities(): virtualFs.HostCapabilities {
20-
return { synchronous: true };
21-
}
23+
rename() {
24+
throw new Error('Not supported.');
25+
},
2226

23-
write(_path: Path, _content: virtualFs.FileBufferLike) {
24-
return throwError(new Error('Not supported.'));
25-
}
27+
read(path): virtualFs.FileBuffer {
28+
const data = inputFileSystem.readFileSync(getSystemPath(path));
2629

27-
delete(_path: Path) {
28-
return throwError(new Error('Not supported.'));
29-
}
30+
return new Uint8Array(data).buffer as ArrayBuffer;
31+
},
3032

31-
rename(_from: Path, _to: Path) {
32-
return throwError(new Error('Not supported.'));
33-
}
33+
list(path): PathFragment[] {
34+
// readdirSync exists but is not in the Webpack typings
35+
const names: string[] = ((inputFileSystem as unknown) as {
36+
readdirSync: (path: string) => string[];
37+
}).readdirSync(getSystemPath(path));
3438

35-
read(path: Path): Observable<virtualFs.FileBuffer> {
36-
return new Observable(obs => {
37-
// TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
38-
// fixed.
39-
try {
40-
const data = this.inputFileSystem.readFileSync(getSystemPath(path));
41-
obs.next(new Uint8Array(data).buffer as ArrayBuffer);
42-
obs.complete();
43-
} catch (e) {
44-
obs.error(e);
45-
}
46-
});
47-
}
39+
return names.map((name) => fragment(name));
40+
},
4841

49-
list(path: Path): Observable<PathFragment[]> {
50-
return new Observable(obs => {
51-
// TODO: remove this try+catch when issue https://github.com/ReactiveX/rxjs/issues/3740 is
52-
// fixed.
53-
try {
54-
// tslint:disable-next-line:no-any
55-
const names: string[] = (this.inputFileSystem as any).readdirSync(getSystemPath(path));
56-
obs.next(names.map(name => fragment(name)));
57-
obs.complete();
58-
} catch (err) {
59-
obs.error(err);
60-
}
61-
});
62-
}
63-
64-
exists(path: Path): Observable<boolean> {
65-
return this.stat(path).pipe(map(stats => stats != null));
66-
}
42+
exists(path): boolean {
43+
return !!this.stat(path);
44+
},
6745

68-
isDirectory(path: Path): Observable<boolean> {
69-
return this.stat(path).pipe(map(stats => stats != null && stats.isDirectory()));
70-
}
46+
isDirectory(path): boolean {
47+
return this.stat(path)?.isDirectory() ?? false;
48+
},
7149

72-
isFile(path: Path): Observable<boolean> {
73-
return this.stat(path).pipe(map(stats => stats != null && stats.isFile()));
74-
}
50+
isFile(path): boolean {
51+
return this.stat(path)?.isFile() ?? false;
52+
},
7553

76-
stat(path: Path): Observable<Stats | null> {
77-
return new Observable(obs => {
54+
stat(path): Stats | null {
7855
try {
79-
const stats = this.inputFileSystem.statSync(getSystemPath(path));
80-
obs.next(stats);
81-
obs.complete();
56+
return inputFileSystem.statSync(getSystemPath(path));
8257
} catch (e) {
8358
if (e.code === 'ENOENT') {
84-
obs.next(null);
85-
obs.complete();
86-
} else {
87-
obs.error(e);
59+
return null;
8860
}
61+
throw e;
8962
}
90-
});
91-
}
92-
93-
watch(_path: Path, _options?: virtualFs.HostWatchOptions): null {
94-
return null;
95-
}
63+
},
64+
});
9665
}

0 commit comments

Comments
 (0)