-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26228 from storybookjs/valentin/create-automigrat…
…ion-for-postcss-addon Automigrations: Create addon-postcss automigration
- Loading branch information
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { addonPostCSS } from './addon-postcss'; | ||
import type { StorybookConfig } from '@storybook/types'; | ||
import type { JsPackageManager } from '@storybook/core-common'; | ||
import { expect, describe, it } from 'vitest'; | ||
|
||
const checkAddonPostCSS = async ({ | ||
packageManager, | ||
mainConfig = {}, | ||
storybookVersion = '7.0.0', | ||
}: { | ||
packageManager?: Partial<JsPackageManager>; | ||
mainConfig?: Partial<StorybookConfig>; | ||
storybookVersion?: string; | ||
}) => { | ||
return addonPostCSS.check({ | ||
packageManager: packageManager as any, | ||
storybookVersion, | ||
mainConfig: mainConfig as any, | ||
}); | ||
}; | ||
|
||
describe('check function', () => { | ||
it('should return { hasAddonPostcss: true } if @storybook/addon-postcss is found', async () => { | ||
await expect( | ||
checkAddonPostCSS({ | ||
mainConfig: { | ||
addons: ['@storybook/addon-postcss'], | ||
}, | ||
}) | ||
).resolves.toEqual({ hasAddonPostcss: true }); | ||
}); | ||
|
||
it('should return null if @storybook/addon-postcss is not found', async () => { | ||
await expect( | ||
checkAddonPostCSS({ | ||
mainConfig: { | ||
addons: [], | ||
}, | ||
}) | ||
).resolves.toBeNull(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import chalk from 'chalk'; | ||
import { dedent } from 'ts-dedent'; | ||
import type { Fix } from '../types'; | ||
import { getAddonNames } from '../helpers/mainConfigFile'; | ||
|
||
interface AddonPostcssRunOptions { | ||
hasAddonPostcss: boolean; | ||
} | ||
|
||
export const addonPostCSS: Fix<AddonPostcssRunOptions> = { | ||
id: 'addon-postcss', | ||
|
||
versionRange: ['<7', '>=7'], | ||
|
||
promptType: 'notification', | ||
|
||
async check({ mainConfig }) { | ||
const addons = getAddonNames(mainConfig); | ||
const hasAddonPostcss = !!addons.find((addon) => addon.includes('@storybook/addon-postcss')); | ||
|
||
if (!hasAddonPostcss) { | ||
return null; | ||
} | ||
|
||
return { hasAddonPostcss: true }; | ||
}, | ||
|
||
prompt() { | ||
return dedent` | ||
${chalk.bold( | ||
'Attention' | ||
)}: We've detected that you're using the following package which are incompatible with Storybook 8 and beyond: | ||
- ${chalk.cyan(`@storybook/addon-postcss`)} | ||
Please migrate to ${chalk.cyan( | ||
`@storybook/addon-styling-webpack` | ||
)} once you're done upgrading. | ||
`; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters