Skip to content

Commit 4e81f57

Browse files
hanslZhicheng Wang
authored and
Zhicheng Wang
committed
fix(@angular/cli): remove unneeded dependencies (angular#4473)
1 parent 1f187b1 commit 4e81f57

File tree

3 files changed

+61
-21
lines changed

3 files changed

+61
-21
lines changed

packages/@angular/cli/lib/ast-tools/ast-utils.ts

+61-16
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import * as ts from 'typescript';
22
import * as fs from 'fs';
3-
import {Symbols} from '@angular/tsc-wrapped/src/symbols';
4-
import {
5-
isMetadataImportedSymbolReferenceExpression,
6-
isMetadataModuleReferenceExpression
7-
} from '@angular/tsc-wrapped';
83
import {Change, InsertChange, NoopChange, MultiChange} from './change';
94
import {findNodes} from './node';
105
import {insertImport} from './route-utils';
@@ -105,9 +100,64 @@ export function getContentOfKeyLiteral(source: ts.SourceFile, node: ts.Node): st
105100
}
106101

107102

103+
104+
function _angularImportsFromNode(node: ts.ImportDeclaration,
105+
sourceFile: ts.SourceFile): {[name: string]: string} {
106+
const ms = node.moduleSpecifier;
107+
let modulePath: string | null = null;
108+
switch (ms.kind) {
109+
case ts.SyntaxKind.StringLiteral:
110+
modulePath = (ms as ts.StringLiteral).text;
111+
break;
112+
default:
113+
return {};
114+
}
115+
116+
if (!modulePath.startsWith('@angular/')) {
117+
return {};
118+
}
119+
120+
if (node.importClause) {
121+
if (node.importClause.name) {
122+
// This is of the form `import Name from 'path'`. Ignore.
123+
return {};
124+
} else if (node.importClause.namedBindings) {
125+
const nb = node.importClause.namedBindings;
126+
if (nb.kind == ts.SyntaxKind.NamespaceImport) {
127+
// This is of the form `import * as name from 'path'`. Return `name.`.
128+
return {
129+
[(nb as ts.NamespaceImport).name.text + '.']: modulePath
130+
};
131+
} else {
132+
// This is of the form `import {a,b,c} from 'path'`
133+
const namedImports = nb as ts.NamedImports;
134+
135+
return namedImports.elements
136+
.map((is: ts.ImportSpecifier) => is.propertyName ? is.propertyName.text : is.name.text)
137+
.reduce((acc: {[name: string]: string}, curr: string) => {
138+
acc[curr] = modulePath;
139+
return acc;
140+
}, {});
141+
}
142+
}
143+
} else {
144+
// This is of the form `import 'path';`. Nothing to do.
145+
return {};
146+
}
147+
}
148+
149+
108150
export function getDecoratorMetadata(source: ts.SourceFile, identifier: string,
109151
module: string): Observable<ts.Node> {
110-
const symbols = new Symbols(source as any);
152+
const angularImports: {[name: string]: string}
153+
= findNodes(source, ts.SyntaxKind.ImportDeclaration)
154+
.map((node: ts.ImportDeclaration) => _angularImportsFromNode(node, source))
155+
.reduce((acc: {[name: string]: string}, current: {[name: string]: string}) => {
156+
for (const key of Object.keys(current)) {
157+
acc[key] = current[key];
158+
}
159+
return acc;
160+
}, {});
111161

112162
return getSourceNodes(source)
113163
.filter(node => {
@@ -118,10 +168,8 @@ export function getDecoratorMetadata(source: ts.SourceFile, identifier: string,
118168
.filter(expr => {
119169
if (expr.expression.kind == ts.SyntaxKind.Identifier) {
120170
const id = <ts.Identifier>expr.expression;
121-
const metaData = symbols.resolve(id.getFullText(source));
122-
if (isMetadataImportedSymbolReferenceExpression(metaData)) {
123-
return metaData.name == identifier && metaData.module == module;
124-
}
171+
return id.getFullText(source) == identifier
172+
&& angularImports[id.getFullText(source)] === module;
125173
} else if (expr.expression.kind == ts.SyntaxKind.PropertyAccessExpression) {
126174
// This covers foo.NgModule when importing * as foo.
127175
const paExpr = <ts.PropertyAccessExpression>expr.expression;
@@ -130,12 +178,9 @@ export function getDecoratorMetadata(source: ts.SourceFile, identifier: string,
130178
return false;
131179
}
132180

133-
const id = paExpr.name;
134-
const moduleId = <ts.Identifier>paExpr.expression;
135-
const moduleMetaData = symbols.resolve(moduleId.getFullText(source));
136-
if (isMetadataModuleReferenceExpression(moduleMetaData)) {
137-
return moduleMetaData.module == module && id.getFullText(source) == identifier;
138-
}
181+
const id = paExpr.name.text;
182+
const moduleId = (<ts.Identifier>paExpr.expression).getText(source);
183+
return id === identifier && (angularImports[moduleId + '.'] === module);
139184
}
140185
return false;
141186
})

packages/@angular/cli/lib/cli/index.js

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// Prevent the dependency validation from tripping because we don't import these. We need
44
// it as a peer dependency of @angular/core.
55
// require('zone.js')
6-
// require('rxjs')
76

87

98
// This file hooks up on require calls to transpile TypeScript.

packages/@angular/cli/package.json

-4
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
},
2727
"homepage": "https://github.com/angular/angular-cli",
2828
"dependencies": {
29-
"@angular/compiler": "^2.3.1",
30-
"@angular/compiler-cli": "^2.3.1",
31-
"@angular/core": "^2.3.1",
32-
"@angular/tsc-wrapped": "^0.5.0",
3329
"@ngtools/json-schema": "^1.0.0",
3430
"@ngtools/webpack": "^1.2.3",
3531
"async": "^2.1.4",

0 commit comments

Comments
 (0)