Skip to content

Commit

Permalink
fix(react): skip adding comma to config when adding remote to host if… (
Browse files Browse the repository at this point in the history
  • Loading branch information
torurz authored and jaysoo committed Dec 12, 2023
1 parent d0173c4 commit 84c3fd6
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions packages/react/src/module-federation/ast-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,41 @@ describe('addRemoteToConfig', () => {

expect(result).toEqual(sourceCode);
});

it('should not add comma if the existing array has a trailing comma', async () => {
const sourceCode = stripIndents`
module.exports = {
name: 'shell',
remotes: [
'app1',
'app2',
]
};
`;

const source = ts.createSourceFile(
'/module-federation.config.js',
sourceCode,
ts.ScriptTarget.Latest,
true
);

const result = applyChangesToString(
sourceCode,
addRemoteToConfig(source, 'new-app')
);

expect(result).toEqual(stripIndents`
module.exports = {
name: 'shell',
remotes: [
'app1',
'app2',
'new-app',
]
};
`);
});
});

describe('addRemoteDefinition', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/module-federation/ast-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function addRemoteToConfig(
const lastElement =
arrayExpression.elements[arrayExpression.elements.length - 1];
return [
lastElement
lastElement && !arrayExpression.elements.hasTrailingComma
? {
type: ChangeType.Insert,
index: lastElement.end,
Expand Down

0 comments on commit 84c3fd6

Please sign in to comment.