Skip to content

Commit e4a9650

Browse files
authored
fix(core): make sure sharedGlobals is referenced in default namedInputs (#27813)
1 parent 72432d6 commit e4a9650

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

packages/workspace/src/generators/ci-workflow/ci-workflow.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,34 @@ describe('CI Workflow generator', () => {
244244
'{workspaceRoot}/.gitlab-ci.yml',
245245
]);
246246
});
247+
248+
it('should add workflow files to namedInputs.sharedGlobals and update default', async () => {
249+
await ciWorkflowGenerator(tree, { ci: 'github', name: 'CI' });
250+
251+
const nxJson = readJson(tree, 'nx.json');
252+
expect(nxJson.namedInputs.sharedGlobals).toEqual([
253+
'{workspaceRoot}/.github/workflows/ci.yml',
254+
]);
255+
expect(nxJson.namedInputs.default).toEqual(['sharedGlobals']);
256+
});
257+
258+
it('should append sharedGlobals to existing default namedInput', async () => {
259+
// Set up initial nx.json with existing default namedInput
260+
const initialNxJson = readJson(tree, 'nx.json');
261+
initialNxJson.namedInputs = {
262+
default: ['existing'],
263+
};
264+
writeJson(tree, 'nx.json', initialNxJson);
265+
266+
await ciWorkflowGenerator(tree, { ci: 'github', name: 'CI' });
267+
268+
const updatedNxJson = readJson(tree, 'nx.json');
269+
expect(updatedNxJson.namedInputs.sharedGlobals).toEqual([
270+
'{workspaceRoot}/.github/workflows/ci.yml',
271+
]);
272+
expect(updatedNxJson.namedInputs.default).toEqual([
273+
'existing',
274+
'sharedGlobals',
275+
]);
276+
});
247277
});

packages/workspace/src/generators/ci-workflow/ci-workflow.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,4 +125,14 @@ function addWorkflowFileToSharedGlobals(
125125
nxJson.namedInputs ??= {};
126126
nxJson.namedInputs.sharedGlobals ??= [];
127127
nxJson.namedInputs.sharedGlobals.push(input);
128+
129+
// Ensure 'default' named input exists and includes 'sharedGlobals'
130+
if (!nxJson.namedInputs.default) {
131+
nxJson.namedInputs.default = ['sharedGlobals'];
132+
} else if (
133+
Array.isArray(nxJson.namedInputs.default) &&
134+
!nxJson.namedInputs.default.includes('sharedGlobals')
135+
) {
136+
nxJson.namedInputs.default.push('sharedGlobals');
137+
}
128138
}

0 commit comments

Comments
 (0)