Skip to content

Commit b09f3b4

Browse files
Merge pull request #276 from angular/master
Update to nodejs rules
2 parents 2f537c8 + 3afdab2 commit b09f3b4

File tree

13 files changed

+132
-80
lines changed

13 files changed

+132
-80
lines changed

packages/angular/cli/commands/config-impl.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ const validCliPaths = new Map<string, ((arg: string) => JsonValue)>([
8686
* by the path. For example, a path of "a[3].foo.bar[2]" would give you a fragment array of
8787
* ["a", 3, "foo", "bar", 2].
8888
* @param path The JSON string to parse.
89-
* @returns {string[]} The fragments for the string.
89+
* @returns {(string|number)[]} The fragments for the string.
9090
* @private
9191
*/
92-
function parseJsonPath(path: string): string[] {
92+
function parseJsonPath(path: string): (string|number)[] {
9393
const fragments = (path || '').split(/\./g);
94-
const result: string[] = [];
94+
const result: (string|number)[] = [];
9595

9696
while (fragments.length > 0) {
9797
const fragment = fragments.shift();
@@ -106,12 +106,15 @@ function parseJsonPath(path: string): string[] {
106106

107107
result.push(match[1]);
108108
if (match[2]) {
109-
const indices = match[2].slice(1, -1).split('][');
109+
const indices = match[2]
110+
.slice(1, -1)
111+
.split('][')
112+
.map(x => /^\d$/.test(x) ? +x : x.replace(/\"|\'/g, ''));
110113
result.push(...indices);
111114
}
112115
}
113116

114-
return result.filter(fragment => !!fragment);
117+
return result.filter(fragment => fragment != null);
115118
}
116119

117120
function getValueFromPath<T extends JsonArray | JsonObject>(

packages/angular/cli/commands/generate-impl.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
// tslint:disable:no-global-tslint-disable no-any
109
import { terminal } from '@angular-devkit/core';
1110
import { Arguments, SubCommandDescription } from '../models/interface';
1211
import { SchematicCommand } from '../models/schematic-command';
@@ -18,10 +17,12 @@ export class GenerateCommand extends SchematicCommand<GenerateCommandSchema> {
1817
longSchematicName: string|undefined;
1918

2019
async initialize(options: GenerateCommandSchema & Arguments) {
21-
await super.initialize(options);
22-
2320
// Fill up the schematics property of the command description.
2421
const [collectionName, schematicName] = this.parseSchematicInfo(options);
22+
this.collectionName = collectionName;
23+
this.schematicName = schematicName;
24+
25+
await super.initialize(options);
2526

2627
const collection = this.getCollection(collectionName);
2728
const subcommands: { [name: string]: SubCommandDescription } = {};
@@ -60,15 +61,13 @@ export class GenerateCommand extends SchematicCommand<GenerateCommandSchema> {
6061
}
6162

6263
public async run(options: GenerateCommandSchema & Arguments) {
63-
const [collectionName, schematicName] = this.parseSchematicInfo(options);
64-
65-
if (!schematicName || !collectionName) {
64+
if (!this.schematicName || !this.collectionName) {
6665
return this.printHelp(options);
6766
}
6867

6968
return this.runSchematic({
70-
collectionName,
71-
schematicName,
69+
collectionName: this.collectionName,
70+
schematicName: this.schematicName,
7271
schematicOptions: options['--'] || [],
7372
debug: !!options.debug || false,
7473
dryRun: !!options.dryRun || false,

packages/angular/cli/commands/new-impl.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,25 @@ export class NewCommand extends SchematicCommand<NewCommandSchema> {
1616
public readonly allowMissingWorkspace = true;
1717
schematicName = 'ng-new';
1818

19-
public async run(options: NewCommandSchema & Arguments) {
20-
let collectionName: string;
19+
async initialize(options: NewCommandSchema & Arguments) {
2120
if (options.collection) {
22-
collectionName = options.collection;
21+
this.collectionName = options.collection;
2322
} else {
24-
collectionName = this.parseCollectionName(options);
23+
this.collectionName = this.parseCollectionName(options);
2524
}
2625

26+
return super.initialize(options);
27+
}
28+
29+
public async run(options: NewCommandSchema & Arguments) {
2730
// Register the version of the CLI in the registry.
2831
const packageJson = require('../package.json');
2932
const version = packageJson.version;
3033

3134
this._workflow.registry.addSmartDefaultProvider('ng-cli-version', () => version);
3235

3336
return this.runSchematic({
34-
collectionName: collectionName,
37+
collectionName: this.collectionName,
3538
schematicName: this.schematicName,
3639
schematicOptions: options['--'] || [],
3740
debug: !!options.debug,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88
import {
9-
analytics,
109
experimental,
1110
json,
1211
logging,
@@ -76,7 +75,8 @@ export abstract class SchematicCommand<
7675
private _workspace: experimental.workspace.Workspace;
7776
protected _workflow: NodeWorkflow;
7877

79-
protected collectionName = '@schematics/angular';
78+
private readonly defaultCollectionName = '@schematics/angular';
79+
protected collectionName = this.defaultCollectionName;
8080
protected schematicName?: string;
8181

8282
constructor(
@@ -373,7 +373,7 @@ export abstract class SchematicCommand<
373373
}
374374
}
375375

376-
return this.collectionName;
376+
return this.defaultCollectionName;
377377
}
378378

379379
protected async runSchematic(options: RunSchematicOptions) {
@@ -400,7 +400,7 @@ export abstract class SchematicCommand<
400400
schematicName = schematic.description.name;
401401

402402
// TODO: Remove warning check when 'targets' is default
403-
if (collectionName !== this.collectionName) {
403+
if (collectionName !== this.defaultCollectionName) {
404404
const [ast, configPath] = getWorkspaceRaw('local');
405405
if (ast) {
406406
const projectsKeyValue = ast.properties.find(p => p.key.value === 'projects');

packages/angular_devkit/architect/testing/index2.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/angular_devkit/build_angular/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"circular-dependency-plugin": "5.0.2",
2020
"clean-css": "4.2.1",
2121
"copy-webpack-plugin": "5.0.3",
22-
"core-js": "3.1.2",
22+
"core-js": "3.1.3",
2323
"file-loader": "3.0.1",
2424
"glob": "7.1.4",
2525
"istanbul-instrumenter-loader": "3.0.1",
@@ -28,7 +28,7 @@
2828
"less-loader": "5.0.0",
2929
"license-webpack-plugin": "2.1.1",
3030
"loader-utils": "1.2.3",
31-
"mini-css-extract-plugin": "0.6.0",
31+
"mini-css-extract-plugin": "0.7.0",
3232
"minimatch": "3.0.4",
3333
"parse5": "4.0.0",
3434
"open": "6.3.0",
@@ -47,7 +47,7 @@
4747
"stylus": "0.54.5",
4848
"stylus-loader": "3.0.2",
4949
"tree-kill": "1.2.1",
50-
"terser-webpack-plugin": "1.2.4",
50+
"terser-webpack-plugin": "1.3.0",
5151
"webpack": "4.32.2",
5252
"webpack-dev-middleware": "3.7.0",
5353
"webpack-dev-server": "3.4.1",

packages/schematics/angular/collection.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"description": "Generate a library project for Angular."
103103
},
104104
"webWorker": {
105-
"aliases": ["web-worker", "worker"],
105+
"aliases": ["web-worker"],
106106
"factory": "./web-worker",
107107
"schema": "./web-worker/schema.json",
108108
"description": "Create a Web Worker."

packages/schematics/angular/migrations/update-8/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { updatePackageJson, updateTsLintConfig } from './codelyzer-5';
1212
import { updateES5Projects } from './differential-loading';
1313
import { dropES2015Polyfills } from './drop-es6-polyfills';
1414
import { removeAngularHttp } from './remove-angular-http';
15-
import { updateBuilders } from './update-builders';
15+
import { updateDependencies } from './update-dependencies';
1616

1717
export { updateLazyModulePaths } from './update-lazy-module-paths';
1818

@@ -23,7 +23,7 @@ export default function(): Rule {
2323
updatePackageJson(),
2424
dropES2015Polyfills(),
2525
updateES5Projects(),
26-
updateBuilders(),
26+
updateDependencies(),
2727
removeAngularHttp(),
2828
(tree, context) => {
2929
const packageChanges = tree.actions.some(a => a.path.endsWith('/package.json'));

packages/schematics/angular/migrations/update-8/update-builders.ts renamed to packages/schematics/angular/migrations/update-8/update-dependencies.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { Tree } from '@angular-devkit/schematics';
99
import { addPackageJsonDependency, getPackageJsonDependency } from '../../utility/dependencies';
1010
import { latestVersions } from '../../utility/latest-versions';
1111

12-
export function updateBuilders() {
12+
export function updateDependencies() {
1313
return (host: Tree) => {
1414
let current = getPackageJsonDependency(host, '@angular-devkit/build-angular');
1515
if (current && current.version !== latestVersions.DevkitBuildAngular) {
@@ -49,5 +49,20 @@ export function updateBuilders() {
4949
},
5050
);
5151
}
52+
53+
// FIXME: change to ^2.3.2 as soon as it's released with the pr208 fix
54+
const webAnimationsJsVersion = 'github:angular/web-animations-js#release_pr208';
55+
current = getPackageJsonDependency(host, 'web-animations-js');
56+
if (current && current.version !== webAnimationsJsVersion) {
57+
addPackageJsonDependency(
58+
host,
59+
{
60+
type: current.type,
61+
name: 'web-animations-js',
62+
version: webAnimationsJsVersion,
63+
overwrite: true,
64+
},
65+
);
66+
}
5267
};
5368
}

renovate.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"webpack-subresource-integrity"
2424
],
2525
"packageFiles": [
26+
"WORKSPACE",
2627
"package.json",
2728
"packages/**/package.json",
2829
"tests/legacy-cli/e2e/ng-snapshot/package.json"

tests/legacy-cli/e2e/tests/commands/config/config-get.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,17 @@ export default function() {
1919
throw new Error(`Expected "true", received "${JSON.stringify(stdout)}".`);
2020
}
2121
})
22-
.then(() => ng('config', 'schematics.@schematics/angular.component.inlineStyle', 'false'));
22+
.then(() => ng('config', 'schematics.@schematics/angular.component.inlineStyle', 'false'))
23+
.then(() => ng('config', `projects.test-project.architect.build.options.assets[0]`))
24+
.then(({ stdout }) => {
25+
if (!stdout.includes('src/favicon.ico')) {
26+
throw new Error(`Expected "src/favicon.ico", received "${JSON.stringify(stdout)}".`);
27+
}
28+
})
29+
.then(() => ng('config', `projects["test-project"].architect.build.options.assets[0]`))
30+
.then(({ stdout }) => {
31+
if (!stdout.includes('src/favicon.ico')) {
32+
throw new Error(`Expected "src/favicon.ico", received "${JSON.stringify(stdout)}".`);
33+
}
34+
});
2335
}

tests/legacy-cli/e2e/tests/generate/help-output.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default function() {
2222
"factory": "./fake",
2323
"description": "Fake schematic",
2424
"schema": "./fake-schema.json"
25-
}
25+
},
2626
}
2727
}`,
2828
[join(genRoot, 'fake-schema.json')]: `
@@ -94,6 +94,33 @@ export default function() {
9494
if (!/opt-a[\s\S]*opt-b[\s\S]*opt-c/.test(stdout)) {
9595
throw new Error('Help signature options are incorrect.');
9696
}
97+
})
98+
99+
// should print all the available schematics in a collection
100+
// when a collection has more than 1 schematic
101+
.then(() => writeMultipleFiles({
102+
[join(genRoot, 'collection.json')]: `
103+
{
104+
"schematics": {
105+
"fake": {
106+
"factory": "./fake",
107+
"description": "Fake schematic",
108+
"schema": "./fake-schema.json"
109+
},
110+
"fake-two": {
111+
"factory": "./fake",
112+
"description": "Fake schematic",
113+
"schema": "./fake-schema.json"
114+
},
115+
}
116+
}`,
117+
}))
118+
.then(() => ng('generate', '--help'))
119+
.then(({stdout}) => {
120+
if (!/Collection \"fake-schematics\" \(default\):[\s\S]*fake[\s\S]*fake-two/.test(stdout)) {
121+
throw new Error(
122+
`Help result is wrong, it didn't contain all the schematics.`);
123+
}
97124
});
98125

99126
}

0 commit comments

Comments
 (0)