Skip to content

Commit 19b9557

Browse files
authored
fix: allow addon config objects (#664)
* fix: allow addon config objects * fix
1 parent 706461f commit 19b9557

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

examples/expo-example/.storybook/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const main: StorybookConfig = {
1717
// '../components/**/*.storiesof.?(ts|tsx|js|jsx)',
1818
],
1919
addons: [
20-
'@storybook/addon-ondevice-controls',
20+
{ name: '@storybook/addon-ondevice-controls' },
2121
'@storybook/addon-ondevice-backgrounds',
2222
'@storybook/addon-ondevice-actions',
2323
'@storybook/addon-ondevice-notes',

packages/react-native/scripts/common.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ function getPreviewExists({ configPath }) {
5959
}
6060

6161
function resolveAddonFile(addon, file, extensions = ['js', 'mjs', 'ts'], configPath) {
62+
if (!addon || typeof addon !== 'string') return null;
63+
6264
try {
6365
const basePath = `${addon}/${file}`;
6466

@@ -91,6 +93,16 @@ function resolveAddonFile(addon, file, extensions = ['js', 'mjs', 'ts'], configP
9193
return null;
9294
}
9395

96+
function getAddonName(addon) {
97+
if (typeof addon === 'string') return addon;
98+
99+
if (typeof addon === 'object' && addon.name && typeof addon.name === 'string') return addon.name;
100+
101+
console.error('Invalid addon configuration', addon);
102+
103+
return null;
104+
}
105+
94106
module.exports = {
95107
toRequireContext,
96108
requireUncached,
@@ -99,4 +111,5 @@ module.exports = {
99111
ensureRelativePathHasDot,
100112
getPreviewExists,
101113
resolveAddonFile,
114+
getAddonName,
102115
};

packages/react-native/scripts/generate.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const {
44
getMain,
55
getPreviewExists,
66
resolveAddonFile,
7+
getAddonName,
78
} = require('./common');
89
const { normalizeStories, globToRegexp } = require('@storybook/core/common');
910
const fs = require('fs');
@@ -51,7 +52,7 @@ function generate({ configPath, absolute = false, useJs = false }) {
5152

5253
for (const addon of main.addons) {
5354
const registerPath = resolveAddonFile(
54-
addon,
55+
getAddonName(addon),
5556
'register',
5657
['js', 'mjs', 'jsx', 'ts', 'tsx'],
5758
configPath
@@ -68,7 +69,7 @@ function generate({ configPath, absolute = false, useJs = false }) {
6869

6970
for (const addon of main.addons) {
7071
const previewPath = resolveAddonFile(
71-
addon,
72+
getAddonName(addon),
7273
'preview',
7374
['js', 'mjs', 'jsx', 'ts', 'tsx'],
7475
configPath

packages/react-native/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ export { start, prepareStories, getProjectAnnotations, updateView } from './Star
66

77
export interface StorybookConfig {
88
stories: StorybookConfigBase['stories'];
9-
addons: string[];
9+
addons: Array<string | { name: string; options?: Record<string, any> }>;
1010
reactNative?: ReactNativeOptions;
1111
}

0 commit comments

Comments
 (0)