Skip to content

Commit

Permalink
Merge pull request #105 from storybookjs/fix/filter-local-addons
Browse files Browse the repository at this point in the history
no-uninstalled-addons: improve local addons filter
  • Loading branch information
yannbf authored Aug 8, 2022
2 parents 680f4be + 877f93f commit 9ba3329
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 12 additions & 1 deletion lib/rules/no-uninstalled-addons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,25 @@ export = createStorybookRule({
return installedAddons.includes(addonName)
}

const filterLocalAddons = (addon: string) => {
const isLocalAddon = (addon: string) =>
addon.startsWith('.') ||
addon.startsWith('/') ||
// for local Windows files e.g. (C: F: D:)
/\w:.*/.test(addon) ||
addon.startsWith('\\')

return !isLocalAddon(addon)
}

type AreThereAddonsNotInstalled = (
addons: string[],
installedSbAddons: string[]
) => false | { name: string }[]
const areThereAddonsNotInstalled: AreThereAddonsNotInstalled = (addons, installedSbAddons) => {
const result = addons
// remove local addons (e.g. ./my-addon/register.js)
.filter((addon) => !addon.startsWith('.'))
.filter(filterLocalAddons)
.filter((addon) => !isAddonInstalled(addon, installedSbAddons))
.map((addon) => ({ name: addon }))
return result.length ? result : false
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/rules/no-uninstalled-addons.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ ruleTester.run('no-uninstalled-addons', rule, {
addons: [
"../my-local-addon",
"../my-local-addon/index.cjs",
"/Users/foo/my-local-addon/index.js",
"/mount/foo/my-local-addon/index.js",
"C:\\Users\\foo\\my-local-addon/index.js",
"D:\\Users\\foo\\my-local-addon/index.js",
]
}
`,
Expand Down

0 comments on commit 9ba3329

Please sign in to comment.