File tree Expand file tree Collapse file tree 3 files changed +25
-3
lines changed
tests/legacy-cli/e2e/tests/commands/config Expand file tree Collapse file tree 3 files changed +25
-3
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ const validCliPaths = new Map<
2424
2525 [ 'cli.analytics' , undefined ] ,
2626 [ 'cli.analyticsSharing.tracking' , undefined ] ,
27- [ 'cli.analyticsSharing.uuid' , ( v ) => ( v ? `${ v } ` : uuidV4 ( ) ) ] ,
27+ [ 'cli.analyticsSharing.uuid' , ( v ) => ( v === '' ? uuidV4 ( ) : `${ v } ` ) ] ,
2828] ) ;
2929
3030/**
@@ -80,7 +80,15 @@ function normalizeValue(value: string | undefined | boolean | number): JsonValue
8080 return + valueString ;
8181 }
8282
83- return parseJson ( valueString ) ?? value ?? undefined ;
83+ try {
84+ // We use `JSON.parse` instead of `parseJson` because the latter will parse UUIDs
85+ // and convert them into a numberic entities.
86+ // Example: 73b61974-182c-48e4-b4c6-30ddf08c5c98 -> 73.
87+ // These values should never contain comments, therefore using `JSON.parse` is safe.
88+ return JSON . parse ( valueString ) ;
89+ } catch {
90+ return value ;
91+ }
8492}
8593
8694export class ConfigCommand extends Command < ConfigCommandSchema > {
Original file line number Diff line number Diff line change 7373 },
7474 "uuid" : {
7575 "description" : " Analytics sharing info universally unique identifier." ,
76- "type" : " string"
76+ "type" : " string" ,
77+ "format" : " uuid"
7778 }
7879 }
7980 }
Original file line number Diff line number Diff line change @@ -24,4 +24,17 @@ export default async function () {
2424 await ng ( 'config' , 'schematics' ) ;
2525 await ng ( 'config' , 'schematics' , 'undefined' ) ;
2626 await expectToFail ( ( ) => ng ( 'config' , 'schematics' ) ) ;
27+
28+ /**
29+ * `ng config cli.analyticsSharing.uuid ""` should generate new random user ID.
30+ * @see : https://angular.io/cli/usage-analytics-gathering#per-user-tracking
31+ */
32+ await ng ( 'config' , 'cli.analyticsSharing.uuid' , '' ) ;
33+ const { stdout : stdout4 } = await ng ( 'config' , 'cli.analyticsSharing.uuid' ) ;
34+ console . log ( stdout4 ) ;
35+ if ( ! / (?: u r n : u u i d : ) ? [ 0 - 9 a - f ] { 8 } - (?: [ 0 - 9 a - f ] { 4 } - ) { 3 } [ 0 - 9 a - f ] { 12 } / i. test ( stdout4 ) ) {
36+ throw new Error (
37+ `Expected "cli.analyticsSharing.uuid" to be a UUID, received "${ JSON . stringify ( stdout4 ) } ".` ,
38+ ) ;
39+ }
2740}
You can’t perform that action at this time.
0 commit comments