Skip to content

Commit 3292ac6

Browse files
committed
fix(@angular/cli): Fixing set prefix issue
1 parent 3515c3b commit 3292ac6

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

packages/@angular/cli/commands/set.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ const SetCommand = Command.extend({
6464
case 'number': value = this.asNumber(rawValue); break;
6565
case 'string': value = rawValue; break;
6666

67-
default: value = JSON.parse(rawValue);
67+
default: value = parseValue(rawValue, jsonPath);
6868
}
6969

7070
config.set(jsonPath, value);
@@ -74,4 +74,12 @@ const SetCommand = Command.extend({
7474
}
7575
});
7676

77+
function parseValue(rawValue: string, path: string) {
78+
try {
79+
return JSON.parse(rawValue);
80+
} catch (error) {
81+
throw new SilentError(`No node found at path ${path}`);
82+
}
83+
}
84+
7785
export default SetCommand;

packages/@ngtools/json-schema/src/schema-class-factory.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ function _getSchemaNodeForPath<T>(rootMetaData: SchemaTreeNode<T>,
5151
let fragments = _parseJsonPath(path);
5252
// TODO: make this work with union (oneOf) schemas
5353
return fragments.reduce((md: SchemaTreeNode<any>, current: string) => {
54-
return md && md.children && md.children[current];
54+
if (md && md.children) {
55+
return md.children[current];
56+
} else if (md && md.items) {
57+
return md.items[parseInt(current, 10)];
58+
} else {
59+
return md;
60+
}
5561
}, rootMetaData);
5662
}
5763

0 commit comments

Comments
 (0)