fix(react): skip adding comma to config when adding remote to host if… (#20620)

This commit is contained in:
Tórur Zachariasen 2023-12-12 16:15:55 +01:00 committed by GitHub
parent 332b0120df
commit d55843cecf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 1 deletions

View File

@ -89,6 +89,41 @@ describe('addRemoteToConfig', () => {
expect(result).toEqual(sourceCode); 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', () => { describe('addRemoteDefinition', () => {

View File

@ -37,7 +37,7 @@ export function addRemoteToConfig(
const lastElement = const lastElement =
arrayExpression.elements[arrayExpression.elements.length - 1]; arrayExpression.elements[arrayExpression.elements.length - 1];
return [ return [
lastElement lastElement && !arrayExpression.elements.hasTrailingComma
? { ? {
type: ChangeType.Insert, type: ChangeType.Insert,
index: lastElement.end, index: lastElement.end,