Skip to content

Commit

Permalink
fix(upgrade): dont upgrade nx packages
Browse files Browse the repository at this point in the history
  • Loading branch information
mandarini committed May 5, 2023
1 parent 91b4484 commit e37fe62
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions code/lib/cli/src/upgrade.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,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
26 changes: 26 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 = (
);
};

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,8 @@ export const doUpgrade = async ({
flags.push('--target');
flags.push(target);
flags = addExtraFlags(EXTRA_FLAGS, flags, packageManager.retrievePackageJson());
flags = addNxPackagesToReject(flags);
console.log('flags', flags);
const check = spawnSync('npx', ['npm-check-updates@latest', '/storybook/', ...flags], {
stdio: 'pipe',
shell: true,
Expand Down

0 comments on commit e37fe62

Please sign in to comment.