Skip to content

Commit acda023

Browse files
committed
feat: add array support to project config handling
1 parent 105f477 commit acda023

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

lib/services/project-config-service.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ export default {
255255
this.writeDefaultConfig(this.projectHelper.projectDir);
256256
}
257257

258-
if (typeof value === "object") {
258+
if (!Array.isArray(value) && typeof value === "object") {
259259
let allSuccessful = true;
260260

261261
for (const prop of this.flattenObjectToPaths(value)) {
@@ -298,7 +298,7 @@ export default {
298298
this.$logger.error(`Failed to update config.` + error);
299299
} finally {
300300
// verify config is updated correctly
301-
if (this.getValue(key) !== value) {
301+
if (!Array.isArray(this.getValue(key)) && this.getValue(key) !== value) {
302302
this.$logger.error(
303303
`${EOL}Failed to update ${
304304
hasTSConfig ? CONFIG_FILE_NAME_TS : CONFIG_FILE_NAME_JS
@@ -465,7 +465,15 @@ You may add \`nsconfig.json\` to \`.gitignore\` as the CLI will regenerate it as
465465
): Array<{ key: string; value: any }> {
466466
const toPath = (key: any) => [basePath, key].filter(Boolean).join(".");
467467
return Object.keys(obj).reduce((all: any, key) => {
468-
if (typeof obj[key] === "object") {
468+
if (Array.isArray(obj[key])) {
469+
return [
470+
...all,
471+
{
472+
key: toPath(key),
473+
value: obj[key], // Preserve arrays as they are
474+
},
475+
];
476+
} else if (typeof obj[key] === "object" && obj[key] !== null) {
469477
return [...all, ...this.flattenObjectToPaths(obj[key], toPath(key))];
470478
}
471479
return [

lib/tools/config-manipulation/config-transformer.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export type SupportedConfigValues =
2121
| string
2222
| number
2323
| boolean
24-
| { [key: string]: SupportedConfigValues };
24+
| { [key: string]: SupportedConfigValues }
25+
| any[];
2526

2627
export interface IConfigTransformer {
2728
/**
@@ -167,11 +168,18 @@ export class ConfigTransformer implements IConfigTransformer {
167168
return this.addProperty(key, value, this.getDefaultExportValue());
168169
}
169170

170-
private createInitializer(value: SupportedConfigValues | {}): string {
171+
private createInitializer(value: SupportedConfigValues): any {
171172
if (typeof value === "string") {
172173
return `'${value}'`;
173174
} else if (typeof value === "number" || typeof value === "boolean") {
174175
return `${value}`;
176+
} else if (Array.isArray(value)) {
177+
return `[${value.map((v) => this.createInitializer(v)).join(", ")}]`;
178+
} else if (typeof value === "object" && value !== null) {
179+
const properties = Object.entries(value)
180+
.map(([key, val]) => `${key}: ${this.createInitializer(val)}`)
181+
.join(", ");
182+
return `{ ${properties} }`;
175183
}
176184
return `{}`;
177185
}

0 commit comments

Comments
 (0)