Skip to content

fix(@angular/cli): remove unneeded dependencies #4473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 61 additions & 16 deletions packages/@angular/cli/lib/ast-tools/ast-utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import * as ts from 'typescript';
import * as fs from 'fs';
import {Symbols} from '@angular/tsc-wrapped/src/symbols';
import {
isMetadataImportedSymbolReferenceExpression,
isMetadataModuleReferenceExpression
} from '@angular/tsc-wrapped';
import {Change, InsertChange, NoopChange, MultiChange} from './change';
import {findNodes} from './node';
import {insertImport} from './route-utils';
Expand Down Expand Up @@ -105,9 +100,64 @@ export function getContentOfKeyLiteral(source: ts.SourceFile, node: ts.Node): st
}



function _angularImportsFromNode(node: ts.ImportDeclaration,
sourceFile: ts.SourceFile): {[name: string]: string} {
const ms = node.moduleSpecifier;
let modulePath: string | null = null;
switch (ms.kind) {
case ts.SyntaxKind.StringLiteral:
modulePath = (ms as ts.StringLiteral).text;
break;
default:
return {};
}

if (!modulePath.startsWith('@angular/')) {
return {};
}

if (node.importClause) {
if (node.importClause.name) {
// This is of the form `import Name from 'path'`. Ignore.
return {};
} else if (node.importClause.namedBindings) {
const nb = node.importClause.namedBindings;
if (nb.kind == ts.SyntaxKind.NamespaceImport) {
// This is of the form `import * as name from 'path'`. Return `name.`.
return {
[(nb as ts.NamespaceImport).name.text + '.']: modulePath
};
} else {
// This is of the form `import {a,b,c} from 'path'`
const namedImports = nb as ts.NamedImports;

return namedImports.elements
.map((is: ts.ImportSpecifier) => is.propertyName ? is.propertyName.text : is.name.text)
.reduce((acc: {[name: string]: string}, curr: string) => {
acc[curr] = modulePath;
return acc;
}, {});
}
}
} else {
// This is of the form `import 'path';`. Nothing to do.
return {};
}
}


export function getDecoratorMetadata(source: ts.SourceFile, identifier: string,
module: string): Observable<ts.Node> {
const symbols = new Symbols(source as any);
const angularImports: {[name: string]: string}
= findNodes(source, ts.SyntaxKind.ImportDeclaration)
.map((node: ts.ImportDeclaration) => _angularImportsFromNode(node, source))
.reduce((acc: {[name: string]: string}, current: {[name: string]: string}) => {
for (const key of Object.keys(current)) {
acc[key] = current[key];
}
return acc;
}, {});

return getSourceNodes(source)
.filter(node => {
Expand All @@ -118,10 +168,8 @@ export function getDecoratorMetadata(source: ts.SourceFile, identifier: string,
.filter(expr => {
if (expr.expression.kind == ts.SyntaxKind.Identifier) {
const id = <ts.Identifier>expr.expression;
const metaData = symbols.resolve(id.getFullText(source));
if (isMetadataImportedSymbolReferenceExpression(metaData)) {
return metaData.name == identifier && metaData.module == module;
}
return id.getFullText(source) == identifier
&& angularImports[id.getFullText(source)] === module;
} else if (expr.expression.kind == ts.SyntaxKind.PropertyAccessExpression) {
// This covers foo.NgModule when importing * as foo.
const paExpr = <ts.PropertyAccessExpression>expr.expression;
Expand All @@ -130,12 +178,9 @@ export function getDecoratorMetadata(source: ts.SourceFile, identifier: string,
return false;
}

const id = paExpr.name;
const moduleId = <ts.Identifier>paExpr.expression;
const moduleMetaData = symbols.resolve(moduleId.getFullText(source));
if (isMetadataModuleReferenceExpression(moduleMetaData)) {
return moduleMetaData.module == module && id.getFullText(source) == identifier;
}
const id = paExpr.name.text;
const moduleId = (<ts.Identifier>paExpr.expression).getText(source);
return id === identifier && (angularImports[moduleId + '.'] === module);
}
return false;
})
Expand Down
1 change: 0 additions & 1 deletion packages/@angular/cli/lib/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// Prevent the dependency validation from tripping because we don't import these. We need
// it as a peer dependency of @angular/core.
// require('zone.js')
// require('rxjs')


// This file hooks up on require calls to transpile TypeScript.
Expand Down
4 changes: 0 additions & 4 deletions packages/@angular/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@
},
"homepage": "https://github.com/angular/angular-cli",
"dependencies": {
"@angular/compiler": "^2.3.1",
"@angular/compiler-cli": "^2.3.1",
"@angular/core": "^2.3.1",
"@angular/tsc-wrapped": "^0.5.0",
"@ngtools/json-schema": "^1.0.0",
"@ngtools/webpack": "^1.2.3",
"async": "^2.1.4",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're dropping @angular/core shouldn't you also drop the recently added rxjs dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Expand Down