Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(upgrade): dont upgrade nx packages #22419

Merged
merged 2 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion code/lib/cli/src/upgrade.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { addExtraFlags, getStorybookVersion, isCorePackage } from './upgrade';
import {
addExtraFlags,
addNxPackagesToReject,
getStorybookVersion,
isCorePackage,
} from './upgrade';

describe.each([
['│ │ │ ├── @babel/code-frame@7.10.3 deduped', null],
Expand Down Expand Up @@ -29,6 +34,8 @@ describe.each([
['@storybook/preset-create-react-app', false],
['@storybook/linter-config', false],
['@storybook/design-system', false],
['@nx/storybook', false],
['@nrwl/storybook', false],
])('isCorePackage', (input, output) => {
it(`${input}`, () => {
expect(isCorePackage(input)).toEqual(output);
Expand Down Expand Up @@ -70,3 +77,33 @@ describe('extra flags', () => {
).toEqual([]);
});
});

describe('addNxPackagesToReject', () => {
it('reject exists and is in regex pattern', () => {
const flags = ['--reject', '/preset-create-react-app/', '--some-flag', 'hello'];
expect(addNxPackagesToReject(flags)).toMatchObject([
'--reject',
'/(preset-create-react-app|@nrwl/storybook|@nx/storybook)/',
'--some-flag',
'hello',
]);
});
it('reject exists and is in unknown pattern', () => {
const flags = ['--some-flag', 'hello', '--reject', '@storybook/preset-create-react-app'];
expect(addNxPackagesToReject(flags)).toMatchObject([
'--some-flag',
'hello',
'--reject',
'@storybook/preset-create-react-app,@nrwl/storybook,@nx/storybook',
]);
});
it('reject does not exist', () => {
const flags = ['--some-flag', 'hello'];
expect(addNxPackagesToReject(flags)).toMatchObject([
'--some-flag',
'hello',
'--reject',
'@nrwl/storybook,@nx/storybook',
]);
});
});
25 changes: 25 additions & 0 deletions code/lib/cli/src/upgrade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const excludeList = [
'@storybook/test-runner',
'@storybook/testing-library',
'@storybook/testing-react',
'@nrwl/storybook',
'@nx/storybook',
];
export const isCorePackage = (pkg: string) =>
pkg.startsWith('@storybook/') &&
Expand Down Expand Up @@ -135,6 +137,28 @@ export const addExtraFlags = (
);
};

export const addNxPackagesToReject = (flags: string[]) => {
const newFlags = [...flags];
const index = flags.indexOf('--reject');
if (index > -1) {
// Try to understand if it's in the format of a regex pattern
if (newFlags[index + 1].endsWith('/') && newFlags[index + 1].startsWith('/')) {
// Remove last and first slash so that I can add the parentheses
newFlags[index + 1] = newFlags[index + 1].substring(1, newFlags[index + 1].length - 1);
newFlags[index + 1] = `/(${newFlags[index + 1]}|@nrwl/storybook|@nx/storybook)/`;
} else {
// Adding the two packages as comma-separated values
// If the existing rejects are in regex format, they will be ignored.
// Maybe we need to find a more robust way to treat rejects?
newFlags[index + 1] = `${newFlags[index + 1]},@nrwl/storybook,@nx/storybook`;
}
} else {
newFlags.push('--reject');
newFlags.push('@nrwl/storybook,@nx/storybook');
}
return newFlags;
};

export interface UpgradeOptions {
tag: string;
prerelease: boolean;
Expand Down Expand Up @@ -190,6 +214,7 @@ export const doUpgrade = async ({
flags.push('--target');
flags.push(target);
flags = addExtraFlags(EXTRA_FLAGS, flags, await packageManager.retrievePackageJson());
flags = addNxPackagesToReject(flags);
const check = spawnSync('npx', ['npm-check-updates@latest', '/storybook/', ...flags], {
stdio: 'pipe',
shell: true,
Expand Down