Skip to content

Commit d7271e8

Browse files
committed
fix(cli): wizard addArrayProp should not add double comma
1 parent f397380 commit d7271e8

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

packages/cli/src/_test_/config-editor.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,20 @@ export const config: Config = {
272272
expect(result).toContain('sass()');
273273
});
274274

275+
it('does not introduce a double comma when the last property already has a trailing comma', async () => {
276+
mockConfig(`export const config: Config = {
277+
namespace: 'MyLib',
278+
outputTargets: [{ type: 'loader-bundle' }],
279+
};
280+
`);
281+
const editor = await openStencilConfig(CONFIG_PATH);
282+
editor.addPlugin('sass()');
283+
await editor.save();
284+
285+
const result = savedText();
286+
expect(result).not.toContain(',,');
287+
});
288+
275289
it('supports plugin with options', async () => {
276290
mockConfig(`export const config: Config = {
277291
namespace: 'MyLib',

packages/cli/src/wizard/config-editor.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,9 @@ export async function openStencilConfig(configPath: string): Promise<StencilConf
156156
if (lastProp) {
157157
let insertPos = lastProp.getEnd();
158158
const trailingComma = text.slice(insertPos).match(/^\s*,/);
159+
const separator = trailingComma ? '' : ',';
159160
if (trailingComma) insertPos += trailingComma[0].length;
160-
text = `${text.slice(0, insertPos)},\n${propIndent}${newProp}${text.slice(insertPos)}`;
161+
text = `${text.slice(0, insertPos)}${separator}\n${propIndent}${newProp}${text.slice(insertPos)}`;
161162
} else {
162163
// Empty config object
163164
const insertPos = configObj.getEnd() - 1; // before }

0 commit comments

Comments
 (0)