Skip to content

Commit

Permalink
Merge pull request #28601 from storybookjs/yann/change-version-ranges…
Browse files Browse the repository at this point in the history
…-automigration

CLI: Make a few automigrations run on all version upgrades
  • Loading branch information
yannbf authored Jul 15, 2024
2 parents cbfe209 + 2717559 commit 4c11838
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 32 deletions.
2 changes: 1 addition & 1 deletion code/lib/cli/src/automigrate/fixes/addon-postcss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface AddonPostcssRunOptions {
export const addonPostCSS: Fix<AddonPostcssRunOptions> = {
id: 'addon-postcss',

versionRange: ['<7', '>=7'],
versionRange: ['*', '*'],

promptType: 'notification',

Expand Down
2 changes: 1 addition & 1 deletion code/lib/cli/src/automigrate/fixes/addons-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface AddonsAPIRunOptions {
export const addonsAPI: Fix<AddonsAPIRunOptions> = {
id: 'addons-api',

versionRange: ['<8', '>=8'],
versionRange: ['*', '*'],

promptType: 'notification',

Expand Down
22 changes: 1 addition & 21 deletions code/lib/cli/src/automigrate/fixes/sb-binary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,12 @@ const checkStorybookBinary = async ({

describe('storybook-binary fix', () => {
describe('sb >= 7.0', () => {
it('should no-op in NX projects', async () => {
it('should add storybook dependency if not present', async () => {
const packageManager = {
getPackageVersion: (packageName) => {
switch (packageName) {
case '@storybook/react':
return Promise.resolve('7.0.0');
case '@nrwl/storybook':
return Promise.resolve('15.7.1');
default:
return null;
}
},
retrievePackageJson: () => Promise.resolve({}),
} as Partial<JsPackageManager>;

await expect(
checkStorybookBinary({
packageManager,
})
).resolves.toBeFalsy();
});

it('should add storybook dependency if not present', async () => {
const packageManager = {
getPackageVersion: (packageName) => {
switch (packageName) {
case '@storybook/react':
return Promise.resolve('7.0.0-alpha.0');
default:
Expand Down
8 changes: 1 addition & 7 deletions code/lib/cli/src/automigrate/fixes/sb-binary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,14 @@ const logger = console;
export const sbBinary: Fix<SbBinaryRunOptions> = {
id: 'storybook-binary',

versionRange: ['<7', '>=7'],
versionRange: ['*', '*'],

async check({ packageManager, storybookVersion }) {
const packageJson = await packageManager.retrievePackageJson();

const nrwlStorybookVersion = await packageManager.getPackageVersion('@nrwl/storybook');
const sbBinaryVersion = await packageManager.getPackageVersion('sb');
const storybookBinaryVersion = await packageManager.getPackageVersion('storybook');

// Nx provides their own binary, so we don't need to do anything
if (nrwlStorybookVersion) {
return null;
}

const hasSbBinary = !!sbBinaryVersion;
const hasStorybookBinary = !!storybookBinaryVersion;

Expand Down
2 changes: 1 addition & 1 deletion code/lib/cli/src/automigrate/fixes/sb-scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const getStorybookScripts = (allScripts: NonNullable<PackageJson['scripts
export const sbScripts: Fix<SbScriptsRunOptions> = {
id: 'sb-scripts',

versionRange: ['<7', '>=7'],
versionRange: ['*', '*'],

async check({ packageManager, storybookVersion }) {
const packageJson = await packageManager.retrievePackageJson();
Expand Down
2 changes: 1 addition & 1 deletion code/lib/cli/src/automigrate/fixes/wrap-require.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ interface WrapRequireRunOptions {
export const wrapRequire: Fix<WrapRequireRunOptions> = {
id: 'wrap-require',

versionRange: ['<7.2.0-rc.0', '>=7.2.0-rc.0'],
versionRange: ['*', '*'],

async check({ packageManager, storybookVersion, mainConfigPath }) {
const isStorybookInMonorepo = await packageManager.isStorybookInMonorepo();
Expand Down

0 comments on commit 4c11838

Please sign in to comment.