Skip to content

Commit f341140

Browse files
authored
chore: fix beachball pre-commit after yarn v4 (#36465)
1 parent 11683ed commit f341140

3 files changed

Lines changed: 49 additions & 4 deletions

File tree

scripts/beachball/src/config.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,30 @@
1+
import { execSync } from 'child_process';
2+
13
import headlessConfig from './release-headless.config';
24
import toolsConfig from './release-tools.config';
35
import v8Config from './release-v8.config';
46
import vNextConfig from './release-vNext.config';
57
import webComponentsConfig from './release-web-components.config';
68
import { config as sharedConfig } from './shared.config';
79

10+
jest.mock('child_process', () => ({
11+
...jest.requireActual<typeof import('child_process')>('child_process'),
12+
execSync: jest.fn(),
13+
}));
14+
815
describe(`beachball configs`, () => {
916
const excludedPackagesFromReleaseProcess = ['!packages/fluentui/*'];
17+
const execSyncMock = jest.mocked(execSync);
18+
const precommit = sharedConfig.hooks.precommit;
19+
20+
if (!precommit) {
21+
throw new Error('Expected the shared Beachball config to define a precommit hook');
22+
}
23+
24+
beforeEach(() => {
25+
execSyncMock.mockReset();
26+
execSyncMock.mockReturnValue(Buffer.from(''));
27+
});
1028

1129
it(`should generate shared config`, () => {
1230
expect(sharedConfig).toEqual({
@@ -48,6 +66,30 @@ describe(`beachball configs`, () => {
4866
});
4967
});
5068

69+
it(`should normalize package dependencies and update the lockfile before committing`, () => {
70+
precommit(process.cwd());
71+
72+
expect(execSyncMock.mock.calls).toEqual([
73+
['yarn nx g @fluentui/workspace-plugin:dependency-mismatch'],
74+
['yarn nx g @fluentui/workspace-plugin:normalize-package-dependencies'],
75+
['yarn install --mode=update-lockfile'],
76+
]);
77+
});
78+
79+
it(`should log precommit finalization failures`, () => {
80+
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation();
81+
const error = new Error('dependency normalization failed');
82+
execSyncMock.mockImplementationOnce(() => {
83+
throw error;
84+
});
85+
86+
expect(() => precommit(process.cwd())).not.toThrow();
87+
expect(consoleErrorSpy).toHaveBeenCalledWith(error);
88+
expect(execSyncMock).toHaveBeenCalledTimes(1);
89+
90+
consoleErrorSpy.mockRestore();
91+
});
92+
5193
it(`should generate v8 release config`, () => {
5294
expect(v8Config.scope).toEqual(
5395
expect.arrayContaining([

scripts/beachball/src/shared.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export const config: typeof baseConfig & Required<Pick<BeachballConfig, 'changel
3333
const out = execSync(cmd);
3434
console.log(out.toString());
3535
});
36+
37+
const out = execSync('yarn install --mode=update-lockfile');
38+
console.log(out.toString());
3639
} catch (err) {
3740
console.error(err);
3841
}

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2534,7 +2534,7 @@ __metadata:
25342534
languageName: unknown
25352535
linkType: soft
25362536

2537-
"@fluentui/babel-preset-storybook-full-source@npm:^0.1.2, @fluentui/babel-preset-storybook-full-source@workspace:packages/react-components/babel-preset-storybook-full-source":
2537+
"@fluentui/babel-preset-storybook-full-source@npm:^0.1.3, @fluentui/babel-preset-storybook-full-source@workspace:packages/react-components/babel-preset-storybook-full-source":
25382538
version: 0.0.0-use.local
25392539
resolution: "@fluentui/babel-preset-storybook-full-source@workspace:packages/react-components/babel-preset-storybook-full-source"
25402540
dependencies:
@@ -5409,11 +5409,11 @@ __metadata:
54095409
languageName: unknown
54105410
linkType: soft
54115411

5412-
"@fluentui/react-storybook-addon-export-to-sandbox@npm:*, @fluentui/react-storybook-addon-export-to-sandbox@npm:^0.3.0, @fluentui/react-storybook-addon-export-to-sandbox@workspace:packages/react-components/react-storybook-addon-export-to-sandbox":
5412+
"@fluentui/react-storybook-addon-export-to-sandbox@npm:*, @fluentui/react-storybook-addon-export-to-sandbox@npm:^0.3.1, @fluentui/react-storybook-addon-export-to-sandbox@workspace:packages/react-components/react-storybook-addon-export-to-sandbox":
54135413
version: 0.0.0-use.local
54145414
resolution: "@fluentui/react-storybook-addon-export-to-sandbox@workspace:packages/react-components/react-storybook-addon-export-to-sandbox"
54155415
dependencies:
5416-
"@fluentui/babel-preset-storybook-full-source": "npm:^0.1.2"
5416+
"@fluentui/babel-preset-storybook-full-source": "npm:^0.1.3"
54175417
"@swc/helpers": "npm:^0.5.1"
54185418
babel-loader: "npm:^9.1.3"
54195419
codesandbox-import-utils: "npm:^2.2.3"
@@ -6331,7 +6331,7 @@ __metadata:
63316331
"@fluentui/react-components": "npm:^9.74.4"
63326332
"@fluentui/react-context-selector": "npm:^9.2.18"
63336333
"@fluentui/react-icons": "npm:^2.0.245"
6334-
"@fluentui/react-storybook-addon-export-to-sandbox": "npm:^0.3.0"
6334+
"@fluentui/react-storybook-addon-export-to-sandbox": "npm:^0.3.1"
63356335
"@fluentui/react-theme": "npm:^9.2.1"
63366336
"@fluentui/react-utilities": "npm:^9.26.5"
63376337
"@griffel/react": "npm:^1.5.32"

0 commit comments

Comments
 (0)