Skip to content

Commit 5af69ba

Browse files
clydinKeen Yee Liau
authored and
Keen Yee Liau
committed
refactor(@angular/cli): remove rxjs direct dependency
1 parent 2c6c398 commit 5af69ba

File tree

7 files changed

+28
-86
lines changed

7 files changed

+28
-86
lines changed

packages/angular/cli/BUILD

-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ ts_library(
2828
"//packages/angular_devkit/core:node",
2929
"//packages/angular_devkit/schematics",
3030
"//packages/angular_devkit/schematics:tools",
31-
"@rxjs",
32-
"@rxjs//operators",
3331
# @typings: es2017.object
3432
# @typings: inquirer
3533
# @typings: node

packages/angular/cli/lib/cli/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
*/
88

99
import { logging, terminal } from '@angular-devkit/core';
10-
import { filter } from 'rxjs/operators';
1110
import { runCommand } from '../../models/command-runner';
1211
import { getWorkspaceRaw } from '../../utilities/config';
1312
import { getWorkspaceDetails } from '../../utilities/project';
@@ -72,11 +71,12 @@ export default async function(options: { testing?: boolean, cliArgs: string[] })
7271
// Initialize logging.
7372
function initializeLogging(logger: logging.Logger) {
7473
return logger
75-
.pipe(filter(entry => (entry.level != 'debug')))
7674
.subscribe(entry => {
7775
let color = (x: string) => terminal.dim(terminal.white(x));
7876
let output = process.stdout;
7977
switch (entry.level) {
78+
case 'debug':
79+
return;
8080
case 'info':
8181
color = terminal.white;
8282
break;

packages/angular/cli/models/architect-command.ts

+15-21
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,11 @@
77
*/
88
import {
99
Architect,
10-
BuildEvent,
1110
BuilderConfiguration,
1211
TargetSpecifier,
1312
} from '@angular-devkit/architect';
1413
import { experimental, json, schema, tags } from '@angular-devkit/core';
1514
import { NodeJsSyncHost, createConsoleLogger } from '@angular-devkit/core/node';
16-
import { from } from 'rxjs';
17-
import { concatMap, map, tap, toArray } from 'rxjs/operators';
1815
import { parseJsonSchemaToOptions } from '../utilities/json-schema';
1916
import { BaseCommandOptions, Command } from './command';
2017
import { Arguments } from './interface';
@@ -49,7 +46,7 @@ export abstract class ArchitectCommand<
4946
this._registry = new json.schema.CoreSchemaRegistry();
5047
this._registry.addPostTransform(json.schema.transforms.addUndefinedDefaults);
5148

52-
await this._loadWorkspaceAndArchitect().toPromise();
49+
await this._loadWorkspaceAndArchitect();
5350

5451
if (!options.project && this.target) {
5552
const projectNames = this.getProjectNamesByTarget(this.target);
@@ -153,9 +150,9 @@ export abstract class ArchitectCommand<
153150
}
154151
const realBuilderConf = this._architect.getBuilderConfiguration({ ...targetSpec, overrides });
155152

156-
return this._architect.run(realBuilderConf, { logger: this._logger }).pipe(
157-
map((buildEvent: BuildEvent) => buildEvent.success ? 0 : 1),
158-
).toPromise();
153+
const result = await this._architect.run(realBuilderConf, { logger: this._logger }).toPromise();
154+
155+
return result.success ? 0 : 1;
159156
}
160157

161158
protected async runArchitectTarget(
@@ -168,12 +165,12 @@ export abstract class ArchitectCommand<
168165
if (!targetSpec.project && this.target) {
169166
// This runs each target sequentially.
170167
// Running them in parallel would jumble the log messages.
171-
return await from(this.getProjectNamesByTarget(this.target)).pipe(
172-
concatMap(project => from(this.runSingleTarget({ ...targetSpec, project }, extra))),
173-
toArray(),
174-
map(results => results.every(res => res === 0) ? 0 : 1),
175-
)
176-
.toPromise();
168+
let result = 0;
169+
for (const project of this.getProjectNamesByTarget(this.target)) {
170+
result |= await this.runSingleTarget({ ...targetSpec, project }, extra);
171+
}
172+
173+
return result;
177174
} else {
178175
return await this.runSingleTarget(targetSpec, extra);
179176
}
@@ -227,16 +224,13 @@ export abstract class ArchitectCommand<
227224
}
228225
}
229226

230-
private _loadWorkspaceAndArchitect() {
227+
private async _loadWorkspaceAndArchitect() {
231228
const workspaceLoader = new WorkspaceLoader(this._host);
232229

233-
return workspaceLoader.loadWorkspace(this.workspace.root).pipe(
234-
tap((workspace: experimental.workspace.Workspace) => this._workspace = workspace),
235-
concatMap((workspace: experimental.workspace.Workspace) => {
236-
return new Architect(workspace).loadArchitect();
237-
}),
238-
tap((architect: Architect) => this._architect = architect),
239-
);
230+
const workspace = await workspaceLoader.loadWorkspace(this.workspace.root);
231+
232+
this._workspace = workspace;
233+
this._architect = await new Architect(workspace).loadArchitect().toPromise();
240234
}
241235

242236
private _makeTargetSpecifier(commandOptions: ArchitectCommandOptions): TargetSpecifier {

packages/angular/cli/models/command-runner.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import {
1616
} from '@angular-devkit/core';
1717
import { readFileSync } from 'fs';
1818
import { dirname, join, resolve } from 'path';
19-
import { of } from 'rxjs';
2019
import { findUp } from '../utilities/find-up';
2120
import { parseJsonSchemaToCommandDescription } from '../utilities/json-schema';
2221
import { Command } from './command';
@@ -76,7 +75,7 @@ export async function runCommand(
7675
if (uri.startsWith('ng-cli://')) {
7776
const content = readFileSync(join(__dirname, '..', uri.substr('ng-cli://'.length)), 'utf-8');
7877

79-
return of(JSON.parse(content));
78+
return Promise.resolve(JSON.parse(content));
8079
} else {
8180
return null;
8281
}

packages/angular/cli/models/schematic-command.ts

+4-14
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ import {
3636
} from '@angular-devkit/schematics/tools';
3737
import * as inquirer from 'inquirer';
3838
import * as systemPath from 'path';
39-
import { take } from 'rxjs/operators';
4039
import { WorkspaceLoader } from '../models/workspace-loader';
4140
import {
4241
getPackageManager,
@@ -97,7 +96,7 @@ export abstract class SchematicCommand<
9796
}
9897

9998
public async initialize(options: T & Arguments) {
100-
this._loadWorkspace();
99+
await this._loadWorkspace();
101100
this.createWorkflow(options);
102101

103102
if (this.schematicName) {
@@ -537,28 +536,19 @@ export abstract class SchematicCommand<
537536
return parseArguments(schematicOptions, options);
538537
}
539538

540-
private _loadWorkspace() {
539+
private async _loadWorkspace() {
541540
if (this._workspace) {
542541
return;
543542
}
544543
const workspaceLoader = new WorkspaceLoader(this._host);
545544

546545
try {
547-
workspaceLoader.loadWorkspace(this.workspace.root).pipe(take(1))
548-
.subscribe(
549-
(workspace: experimental.workspace.Workspace) => this._workspace = workspace,
550-
(err: Error) => {
551-
if (!this.allowMissingWorkspace) {
552-
// Ignore missing workspace
553-
throw err;
554-
}
555-
},
556-
);
546+
this._workspace = await workspaceLoader.loadWorkspace(this.workspace.root);
557547
} catch (err) {
558548
if (!this.allowMissingWorkspace) {
559549
// Ignore missing workspace
560550
throw err;
561-
}
551+
}
562552
}
563553
}
564554
}

packages/angular/cli/models/workspace-loader.ts

+6-44
Original file line numberDiff line numberDiff line change
@@ -11,82 +11,44 @@ import {
1111
basename,
1212
dirname,
1313
experimental,
14-
join,
1514
normalize,
1615
virtualFs,
1716
} from '@angular-devkit/core';
18-
import * as fs from 'fs';
19-
import { homedir } from 'os';
20-
import { Observable, of } from 'rxjs';
21-
import { concatMap, tap } from 'rxjs/operators';
2217
import { findUp } from '../utilities/find-up';
2318

2419

25-
// TODO: error out instead of returning null when workspace cannot be found.
2620
export class WorkspaceLoader {
27-
private _workspaceCacheMap = new Map<string, experimental.workspace.Workspace>();
2821
// TODO: add remaining fallbacks.
2922
private _configFileNames = [
3023
normalize('.angular.json'),
3124
normalize('angular.json'),
3225
];
3326
constructor(private _host: virtualFs.Host) { }
3427

35-
loadGlobalWorkspace(): Observable<experimental.workspace.Workspace | null> {
36-
return this._getGlobalWorkspaceFilePath().pipe(
37-
concatMap(globalWorkspacePath => this._loadWorkspaceFromPath(globalWorkspacePath)),
38-
);
39-
}
40-
41-
loadWorkspace(projectPath?: string): Observable<experimental.workspace.Workspace | null> {
42-
return this._getProjectWorkspaceFilePath(projectPath).pipe(
43-
concatMap(globalWorkspacePath => this._loadWorkspaceFromPath(globalWorkspacePath)),
44-
);
28+
loadWorkspace(projectPath?: string): Promise<experimental.workspace.Workspace> {
29+
return this._loadWorkspaceFromPath(this._getProjectWorkspaceFilePath(projectPath));
4530
}
4631

4732
// TODO: do this with the host instead of fs.
48-
private _getProjectWorkspaceFilePath(projectPath?: string): Observable<Path | null> {
33+
private _getProjectWorkspaceFilePath(projectPath?: string): Path {
4934
// Find the workspace file, either where specified, in the Angular CLI project
5035
// (if it's in node_modules) or from the current process.
5136
const workspaceFilePath = (projectPath && findUp(this._configFileNames, projectPath))
5237
|| findUp(this._configFileNames, process.cwd())
5338
|| findUp(this._configFileNames, __dirname);
5439

5540
if (workspaceFilePath) {
56-
return of(normalize(workspaceFilePath));
41+
return normalize(workspaceFilePath);
5742
} else {
5843
throw new Error(`Local workspace file ('angular.json') could not be found.`);
5944
}
6045
}
6146

62-
// TODO: do this with the host instead of fs.
63-
private _getGlobalWorkspaceFilePath(): Observable<Path | null> {
64-
for (const fileName of this._configFileNames) {
65-
const workspaceFilePath = join(normalize(homedir()), fileName);
66-
67-
if (fs.existsSync(workspaceFilePath)) {
68-
return of(normalize(workspaceFilePath));
69-
}
70-
}
71-
72-
return of(null);
73-
}
74-
75-
private _loadWorkspaceFromPath(workspacePath: Path | null) {
76-
if (!workspacePath) {
77-
return of(null);
78-
}
79-
80-
if (this._workspaceCacheMap.has(workspacePath)) {
81-
return of(this._workspaceCacheMap.get(workspacePath) || null);
82-
}
83-
47+
private _loadWorkspaceFromPath(workspacePath: Path) {
8448
const workspaceRoot = dirname(workspacePath);
8549
const workspaceFileName = basename(workspacePath);
8650
const workspace = new experimental.workspace.Workspace(workspaceRoot, this._host);
8751

88-
return workspace.loadWorkspaceFromHost(workspaceFileName).pipe(
89-
tap(workspace => this._workspaceCacheMap.set(workspacePath, workspace)),
90-
);
52+
return workspace.loadWorkspaceFromHost(workspaceFileName).toPromise();
9153
}
9254
}

packages/angular/cli/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"@schematics/update": "0.0.0",
3434
"inquirer": "6.2.0",
3535
"opn": "5.3.0",
36-
"rxjs": "6.3.3",
3736
"semver": "5.5.1",
3837
"symbol-observable": "1.2.0"
3938
},

0 commit comments

Comments
 (0)