Skip to content

Commit

Permalink
Merge pull request #22419 from storybookjs/fix/dont-upgrade-nx
Browse files Browse the repository at this point in the history
fix(upgrade): dont upgrade nx packages
  • Loading branch information
ndelangen authored May 22, 2023
2 parents 28f8733 + 4a25d3d commit 1853caa
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
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

0 comments on commit 1853caa

Please sign in to comment.