-
-
Notifications
You must be signed in to change notification settings - Fork 9.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0f4ab3
commit 9f0bc7d
Showing
4 changed files
with
92 additions
and
1 deletion.
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
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,44 @@ | ||
import { addonsAPI } from './addons-api'; | ||
import type { StorybookConfig } from '@storybook/types'; | ||
import type { JsPackageManager } from '@storybook/core-common'; | ||
import { expect, describe, it } from 'vitest'; | ||
|
||
const checkAddonsAPI = async ({ | ||
packageManager, | ||
mainConfig = {}, | ||
storybookVersion = '7.0.0', | ||
}: { | ||
packageManager?: Partial<JsPackageManager>; | ||
mainConfig?: Partial<StorybookConfig>; | ||
storybookVersion?: string; | ||
}) => { | ||
return addonsAPI.check({ | ||
packageManager: packageManager as any, | ||
storybookVersion, | ||
mainConfig: mainConfig as any, | ||
}); | ||
}; | ||
|
||
describe('check function', () => { | ||
it('should return { usesAddonsAPI: true } if @storybook/addons is installed', async () => { | ||
await expect( | ||
checkAddonsAPI({ | ||
packageManager: { | ||
getAllDependencies: async () => ({ | ||
'@storybook/addons': '6.0.0', | ||
}), | ||
}, | ||
}) | ||
).resolves.toEqual({ usesAddonsAPI: true }); | ||
}); | ||
|
||
it('should return null if @storybook/addons is not installed', async () => { | ||
await expect( | ||
checkAddonsAPI({ | ||
packageManager: { | ||
getAllDependencies: async () => ({}), | ||
}, | ||
}) | ||
).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,45 @@ | ||
import chalk from 'chalk'; | ||
import { dedent } from 'ts-dedent'; | ||
import type { Fix } from '../types'; | ||
|
||
interface AddonsAPIRunOptions { | ||
usesAddonsAPI: boolean; | ||
} | ||
|
||
export const addonsAPI: Fix<AddonsAPIRunOptions> = { | ||
id: 'addons-api', | ||
|
||
versionRange: ['<8', '>=8'], | ||
|
||
promptType: 'notification', | ||
|
||
async check({ packageManager }) { | ||
const allDependencies = await packageManager.getAllDependencies(); | ||
const usesAddonsAPI = !!allDependencies['@storybook/addons']; | ||
|
||
if (!usesAddonsAPI) { | ||
return null; | ||
} | ||
|
||
return { usesAddonsAPI: true }; | ||
}, | ||
|
||
prompt() { | ||
return dedent` | ||
${chalk.bold( | ||
'Attention' | ||
)}: We've detected that you're using the following package which is removed in Storybook 8 and beyond: | ||
- ${chalk.cyan(`@storybook/addons`)} | ||
This package has been deprecated and replaced with ${chalk.cyan( | ||
`@storybook/preview-api` | ||
)} and ${chalk.cyan(`@storybook/manager-api`)}. | ||
You can find more information about the new addons API in the migration guide: | ||
${chalk.yellow( | ||
'https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#new-addons-api' | ||
)} | ||
`; | ||
}, | ||
}; |
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