Skip to content

Commit f6f5d79

Browse files
alan-agius4angular-robot[bot]
authored andcommitted
fix(@angular-devkit/core): handle number like strings in workspace writer
The workspace writer previously transformed number like strings to numbers which causes failures when a project is named using a number like name. Closes #24541
1 parent 0f58a17 commit f6f5d79

File tree

3 files changed

+155
-39
lines changed

3 files changed

+155
-39
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"newProjectRoot": "projects",
5+
"projects": {
6+
"my-app": {
7+
"root": "",
8+
"projectType": "application",
9+
"prefix": "app",
10+
"schematics": {
11+
"@schematics/angular:component": {
12+
"styleext": "scss"
13+
}
14+
},
15+
"architect": {
16+
"build": {
17+
"builder": "@angular-devkit/build-angular:browser",
18+
"options": {
19+
"outputPath": "dist/my-app",
20+
"index": "src/index.html",
21+
"main": "src/main.ts",
22+
"polyfills": "src/polyfills.ts",
23+
"tsConfig": "src/tsconfig.app.json",
24+
"assets": [
25+
"src/favicon.ico",
26+
"src/assets"
27+
],
28+
"styles": [
29+
"src/styles.scss"
30+
],
31+
"scripts": []
32+
},
33+
"configurations": {
34+
"production": {
35+
"fileReplacements": [
36+
{
37+
"replace": "src/environments/environment.ts",
38+
"with": "src/environments/environment.prod.ts"
39+
}
40+
],
41+
"optimization": true,
42+
"outputHashing": "all",
43+
"sourceMap": false,
44+
"extractCss": true,
45+
"namedChunks": false,
46+
"aot": true,
47+
"extractLicenses": true,
48+
"vendorChunk": false,
49+
"buildOptimizer": true,
50+
"budgets": [
51+
{
52+
"type": "initial",
53+
"maximumWarning": "2mb",
54+
"maximumError": "5mb"
55+
}
56+
]
57+
}
58+
}
59+
},
60+
"serve": {
61+
"builder": "@angular-devkit/build-angular:dev-server",
62+
"options": {
63+
"browserTarget": "my-app:build"
64+
},
65+
"configurations": {
66+
"production": {
67+
"browserTarget": "my-app:build:production"
68+
}
69+
}
70+
},
71+
"extract-i18n": {
72+
"builder": "@angular-devkit/build-angular:extract-i18n",
73+
"options": {
74+
"browserTarget": "my-app:build"
75+
}
76+
},
77+
"test": {
78+
"builder": "@angular-devkit/build-angular:karma",
79+
"options": {
80+
"main": "src/test.ts",
81+
"polyfills": "src/polyfills.ts",
82+
"tsConfig": "src/tsconfig.spec.json",
83+
"karmaConfig": "src/karma.conf.js",
84+
"styles": [
85+
"src/styles.scss"
86+
],
87+
"scripts": [],
88+
"assets": [
89+
"src/favicon.ico",
90+
"src/assets"
91+
]
92+
}
93+
},
94+
"lint": {
95+
"builder": "@angular-devkit/build-angular:tslint",
96+
"options": {
97+
"tsConfig": [
98+
"src/tsconfig.app.json",
99+
"src/tsconfig.spec.json"
100+
],
101+
"exclude": [
102+
"**/node_modules/**"
103+
]
104+
}
105+
}
106+
}
107+
},
108+
"my-app-e2e": {
109+
"root": "e2e/",
110+
"projectType": "application",
111+
"prefix": "",
112+
"architect": {
113+
"e2e": {
114+
"builder": "@angular-devkit/build-angular:protractor",
115+
"options": {
116+
"protractorConfig": "e2e/protractor.conf.js",
117+
"devServerTarget": "my-app:serve"
118+
},
119+
"configurations": {
120+
"production": {
121+
"devServerTarget": "my-app:serve:production"
122+
}
123+
}
124+
},
125+
"lint": {
126+
"builder": "@angular-devkit/build-angular:tslint",
127+
"options": {
128+
"tsConfig": "e2e/tsconfig.e2e.json",
129+
"exclude": [
130+
"**/node_modules/**"
131+
]
132+
}
133+
}
134+
}
135+
},
136+
"1": {
137+
"root": "src"
138+
}
139+
},
140+
"defaultProject": "my-app"
141+
}

packages/angular_devkit/core/src/workspace/json/writer.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,10 @@ function updateJsonWorkspace(metadata: JsonWorkspaceMetadata): string {
156156
jsonPath[2] = 'architect';
157157
}
158158

159-
// modify
160-
const newJsonPath = jsonPath.map((v) => (isFinite(+v) ? +v : v));
161159
// TODO: `modify` re-parses the content every time.
162160
// See: https://github.com/microsoft/node-jsonc-parser/blob/35d94cd71bd48f9784453b2439262c938e21d49b/src/impl/edit.ts#L18
163161
// Ideally this should accept a string or an AST to avoid the potentially expensive repeat parsing operation.
164-
const edits = modify(content, newJsonPath, normalizeValue(value, type), {
162+
const edits = modify(content, jsonPath, normalizeValue(value, type), {
165163
formattingOptions: {
166164
insertSpaces: true,
167165
tabSize: 2,

0 commit comments

Comments
 (0)