Skip to content

Commit 193c9b0

Browse files
authored
Merge pull request #98 from storybookjs/fix/ignore-local-addons
fix(no-uninstalled-addons): ignore local addons
2 parents fa6290d + 29d633d commit 193c9b0

File tree

2 files changed

+19
-28
lines changed

2 files changed

+19
-28
lines changed

lib/rules/no-uninstalled-addons.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,12 @@ export = createStorybookRule({
6262

6363
type IsAddonInstalled = (addon: string, installedAddons: string[]) => boolean
6464
const isAddonInstalled: IsAddonInstalled = (addon, installedAddons) => {
65-
// cleanup /register or /preset from registered addon
66-
const addonName = addon.replace(/\/register$/, '').replace(/\/preset$/, '')
65+
// cleanup /register or /preset + file extension from registered addon
66+
const addonName = addon
67+
.replace(/\.[mc]?js$/, '')
68+
.replace(/\/register$/, '')
69+
.replace(/\/preset$/, '')
70+
6771
return installedAddons.includes(addonName)
6872
}
6973

@@ -73,6 +77,8 @@ export = createStorybookRule({
7377
) => false | { name: string }[]
7478
const areThereAddonsNotInstalled: AreThereAddonsNotInstalled = (addons, installedSbAddons) => {
7579
const result = addons
80+
// remove local addons (e.g. ./my-addon/register.js)
81+
.filter((addon) => !addon.startsWith('.'))
7682
.filter((addon) => !isAddonInstalled(addon, installedSbAddons))
7783
.map((addon) => ({ name: addon }))
7884
return result.length ? result : false

tests/lib/rules/no-uninstalled-addons.test.ts

+11-26
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,13 @@ jest.mock('fs', () => ({
1616
...jest.requireActual('fs'),
1717
readFileSync: () => `
1818
{
19-
"name": "react-repro",
20-
"version": "1.0.0",
21-
"main": "index.js",
22-
"license": "MIT",
23-
"dependencies": {
24-
"react": "^18.2.0",
25-
"react-dom": "^18.2.0"
26-
},
27-
"packageManager": "[email protected]",
2819
"devDependencies": {
29-
"@babel/core": "^7.18.5",
30-
"@mdx-js/react": "^1.6.22",
31-
"@storybook/addon-actions": "^6.5.9",
32-
"@storybook/addon-docs": "^6.5.9",
3320
"@storybook/addon-essentials": "^6.5.9",
3421
"@storybook/addon-interactions": "^6.5.9",
3522
"@storybook/preset-create-react-app": "^6.5.9",
3623
"@storybook/addon-links": "^6.5.9",
37-
"@storybook/builder-webpack4": "^6.5.9",
38-
"@storybook/manager-webpack4": "^6.5.9",
39-
"@storybook/react": "^6.5.9",
40-
"@storybook/testing-library": "^0.0.13",
4124
"storybook-addon-valid-addon": "0.0.1",
42-
"addon-without-the-prefix": "^0.0.1",
43-
"babel-loader": "^8.2.5",
44-
"prop-types": "^15.8.1"
25+
"addon-without-the-prefix": "^0.0.1"
4526
}
4627
}
4728
`,
@@ -52,11 +33,6 @@ jest.mock('fs', () => ({
5233
//------------------------------------------------------------------------------
5334

5435
ruleTester.run('no-uninstalled-addons', rule, {
55-
/**
56-
* This is an example test for a rule that reports an error in case a named export is called 'wrong'
57-
* Use https://eslint.org/docs/developer-guide/working-with-rules for Eslint API
58-
* And delete this entire comment block
59-
*/
6036
valid: [
6137
`
6238
export default {
@@ -112,6 +88,14 @@ ruleTester.run('no-uninstalled-addons', rule, {
11288
]
11389
}
11490
`,
91+
`
92+
module.exports = {
93+
addons: [
94+
"../my-local-addon",
95+
"../my-local-addon/index.cjs",
96+
]
97+
}
98+
`,
11599
`
116100
module.exports = {
117101
addons: [
@@ -124,7 +108,7 @@ ruleTester.run('no-uninstalled-addons', rule, {
124108
name: "addon-without-the-prefix",
125109
},
126110
{
127-
name: "storybook-addon-valid-addon/register",
111+
name: "storybook-addon-valid-addon/register.js",
128112
},
129113
]
130114
}
@@ -279,6 +263,7 @@ ruleTester.run('no-uninstalled-addons', rule, {
279263
{
280264
code: `
281265
export const addons = [
266+
"../my-local-addon",
282267
"@storybook/addon-links",
283268
"@storybook/addon-essentials",
284269
"@storybook/addon-interactions",

0 commit comments

Comments
 (0)