Skip to content

Commit

Permalink
fix: local addons not resolved (#661)
Browse files Browse the repository at this point in the history
* fix: local addons not resolved

* v8.4.4-alpha.0
  • Loading branch information
dannyhw authored Dec 28, 2024
1 parent eacb2e3 commit d33440a
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('preview-local-addon');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log('register-local-addon');
1 change: 1 addition & 0 deletions examples/expo-example/.storybook/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const main: StorybookConfig = {
'@storybook/addon-ondevice-actions',
'@storybook/addon-ondevice-notes',
'storybook-addon-deep-controls',
'./local-addon-example',
],
reactNative: {
playFn: false,
Expand Down
2 changes: 2 additions & 0 deletions examples/expo-example/.storybook/storybook.requires.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import "@storybook/addon-ondevice-backgrounds/register";
import "@storybook/addon-ondevice-actions/register";
import "@storybook/addon-ondevice-notes/register";
import "storybook-addon-deep-controls/register";
import "./local-addon-example/register";

const normalizedStories = [
{
Expand Down Expand Up @@ -60,6 +61,7 @@ const annotations = [
require("@storybook/react-native/preview"),
require("@storybook/addon-ondevice-actions/preview"),
require("storybook-addon-deep-controls/preview"),
require("./local-addon-example/preview"),
];

global.STORIES = normalizedStories;
Expand Down
14 changes: 7 additions & 7 deletions examples/expo-example/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "expo-example",
"version": "8.4.3",
"version": "8.4.4-alpha.0",
"private": true,
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -28,19 +28,19 @@
"@storybook/addon-essentials": "^8.4.2",
"@storybook/addon-interactions": "^8.4.2",
"@storybook/addon-links": "^8.4.2",
"@storybook/addon-ondevice-actions": "^8.4.3",
"@storybook/addon-ondevice-backgrounds": "^8.4.3",
"@storybook/addon-ondevice-controls": "^8.4.3",
"@storybook/addon-ondevice-notes": "^8.4.3",
"@storybook/addon-ondevice-actions": "^8.4.4-alpha.0",
"@storybook/addon-ondevice-backgrounds": "^8.4.4-alpha.0",
"@storybook/addon-ondevice-controls": "^8.4.4-alpha.0",
"@storybook/addon-ondevice-notes": "^8.4.4-alpha.0",
"@storybook/addon-react-native-server": "0.0.6",
"@storybook/addon-react-native-web": "^0.0.26",
"@storybook/addon-webpack5-compiler-babel": "^3.0.3",
"@storybook/blocks": "^8.4.2",
"@storybook/builder-webpack5": "^8.4.2",
"@storybook/global": "^5.0.0",
"@storybook/react": "^8.4.2",
"@storybook/react-native": "^8.4.3",
"@storybook/react-native-theming": "^8.4.3",
"@storybook/react-native": "^8.4.4-alpha.0",
"@storybook/react-native-theming": "^8.4.4-alpha.0",
"@storybook/react-webpack5": "^8.4.2",
"@storybook/test": "^8.4.2",
"expo": "~52.0.11",
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"npmClient": "yarn",
"registry": "https://registry.npmjs.org",
"version": "8.4.3"
"version": "8.4.4-alpha.0"
}
2 changes: 1 addition & 1 deletion packages/ondevice-actions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storybook/addon-ondevice-actions",
"version": "8.4.3",
"version": "8.4.4-alpha.0",
"description": "Action Logger addon for react-native storybook",
"keywords": [
"storybook"
Expand Down
4 changes: 2 additions & 2 deletions packages/ondevice-backgrounds/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storybook/addon-ondevice-backgrounds",
"version": "8.4.3",
"version": "8.4.4-alpha.0",
"description": "A react-native storybook addon to show different backgrounds for your preview",
"keywords": [
"addon",
Expand Down Expand Up @@ -33,7 +33,7 @@
},
"dependencies": {
"@storybook/core": "^8.4.2",
"@storybook/react-native-theming": "^8.4.3"
"@storybook/react-native-theming": "^8.4.4-alpha.0"
},
"devDependencies": {
"typescript": "^5.3.3"
Expand Down
6 changes: 3 additions & 3 deletions packages/ondevice-controls/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storybook/addon-ondevice-controls",
"version": "8.4.3",
"version": "8.4.4-alpha.0",
"description": "Display storybook controls on your device.",
"keywords": [
"addon",
Expand Down Expand Up @@ -32,8 +32,8 @@
"dependencies": {
"@storybook/addon-controls": "^8.4.2",
"@storybook/core": "^8.4.2",
"@storybook/react-native-theming": "^8.4.3",
"@storybook/react-native-ui": "^8.4.3",
"@storybook/react-native-theming": "^8.4.4-alpha.0",
"@storybook/react-native-ui": "^8.4.4-alpha.0",
"deep-equal": "^1.0.1",
"prop-types": "^15.7.2",
"react-native-modal-datetime-picker": "^14.0.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/ondevice-notes/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storybook/addon-ondevice-notes",
"version": "8.4.3",
"version": "8.4.4-alpha.0",
"description": "Write notes for your react-native Storybook stories.",
"keywords": [
"addon",
Expand Down Expand Up @@ -30,7 +30,7 @@
},
"dependencies": {
"@storybook/core": "^8.4.2",
"@storybook/react-native-theming": "^8.4.3",
"@storybook/react-native-theming": "^8.4.4-alpha.0",
"react-native-markdown-display": "^7.0.2"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native-theming/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storybook/react-native-theming",
"version": "8.4.3",
"version": "8.4.4-alpha.0",
"description": "A wrapper library around emotion 11 to provide theming support for react-native storybook",
"keywords": [
"react",
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storybook/react-native-ui",
"version": "8.4.3",
"version": "8.4.4-alpha.0",
"description": "ui components for react native storybook",
"keywords": [
"react",
Expand Down Expand Up @@ -60,7 +60,7 @@
"dependencies": {
"@storybook/core": "^8.4.2",
"@storybook/react": "^8.4.2",
"@storybook/react-native-theming": "^8.4.3",
"@storybook/react-native-theming": "^8.4.4-alpha.0",
"fuse.js": "^7.0.0",
"memoizerific": "^1.11.3",
"polished": "^4.3.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/react-native/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@storybook/react-native",
"version": "8.4.3",
"version": "8.4.4-alpha.0",
"description": "A better way to develop React Native Components for your app",
"keywords": [
"react",
Expand Down Expand Up @@ -49,8 +49,8 @@
"@storybook/csf": "^0.1.1",
"@storybook/global": "^5.0.0",
"@storybook/react": "^8.4.2",
"@storybook/react-native-theming": "^8.4.3",
"@storybook/react-native-ui": "^8.4.3",
"@storybook/react-native-theming": "^8.4.4-alpha.0",
"@storybook/react-native-ui": "^8.4.4-alpha.0",
"chokidar": "^3.5.1",
"commander": "^8.2.0",
"dedent": "^1.5.1",
Expand Down
13 changes: 12 additions & 1 deletion packages/react-native/scripts/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function getPreviewExists({ configPath }) {
return !!getFilePathExtension({ configPath }, 'preview');
}

function resolveAddonFile(addon, file, extensions = ['js', 'mjs', 'ts']) {
function resolveAddonFile(addon, file, extensions = ['js', 'mjs', 'ts'], configPath) {
try {
const basePath = `${addon}/${file}`;

Expand All @@ -77,6 +77,17 @@ function resolveAddonFile(addon, file, extensions = ['js', 'mjs', 'ts']) {
} catch (error) {}
}

// attempt to resolve as a relative path for local addons
if (addon.startsWith('./') || addon.startsWith('../')) {
try {
const extension = getFilePathExtension({ configPath }, `${addon}/${file}`);

if (extension) {
return `${addon}/${file}`;
}
} catch (error) {}
}

return null;
}

Expand Down
14 changes: 12 additions & 2 deletions packages/react-native/scripts/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ function generate({ configPath, absolute = false, useJs = false }) {
let registerAddons = '';

for (const addon of main.addons) {
const registerPath = resolveAddonFile(addon, 'register', ['js', 'mjs', 'jsx', 'ts', 'tsx']);
const registerPath = resolveAddonFile(
addon,
'register',
['js', 'mjs', 'jsx', 'ts', 'tsx'],
configPath
);

if (registerPath) {
registerAddons += `import "${registerPath}";\n`;
Expand All @@ -62,7 +67,12 @@ function generate({ configPath, absolute = false, useJs = false }) {
const enhancers = [docTools];

for (const addon of main.addons) {
const previewPath = resolveAddonFile(addon, 'preview', ['js', 'mjs', 'jsx', 'ts', 'tsx']);
const previewPath = resolveAddonFile(
addon,
'preview',
['js', 'mjs', 'jsx', 'ts', 'tsx'],
configPath
);

if (previewPath) {
enhancers.push(`require('${previewPath}')`);
Expand Down
40 changes: 20 additions & 20 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5124,7 +5124,7 @@ __metadata:
languageName: node
linkType: hard

"@storybook/addon-ondevice-actions@npm:^8.4.3, @storybook/addon-ondevice-actions@workspace:packages/ondevice-actions":
"@storybook/addon-ondevice-actions@npm:^8.4.4-alpha.0, @storybook/addon-ondevice-actions@workspace:packages/ondevice-actions":
version: 0.0.0-use.local
resolution: "@storybook/addon-ondevice-actions@workspace:packages/ondevice-actions"
dependencies:
Expand All @@ -5139,27 +5139,27 @@ __metadata:
languageName: unknown
linkType: soft

"@storybook/addon-ondevice-backgrounds@npm:^8.4.3, @storybook/addon-ondevice-backgrounds@workspace:packages/ondevice-backgrounds":
"@storybook/addon-ondevice-backgrounds@npm:^8.4.4-alpha.0, @storybook/addon-ondevice-backgrounds@workspace:packages/ondevice-backgrounds":
version: 0.0.0-use.local
resolution: "@storybook/addon-ondevice-backgrounds@workspace:packages/ondevice-backgrounds"
dependencies:
"@storybook/core": "npm:^8.4.2"
"@storybook/react-native-theming": "npm:^8.4.3"
"@storybook/react-native-theming": "npm:^8.4.4-alpha.0"
typescript: "npm:^5.3.3"
peerDependencies:
react: "*"
react-native: "*"
languageName: unknown
linkType: soft

"@storybook/addon-ondevice-controls@npm:^8.4.3, @storybook/addon-ondevice-controls@workspace:packages/ondevice-controls":
"@storybook/addon-ondevice-controls@npm:^8.4.4-alpha.0, @storybook/addon-ondevice-controls@workspace:packages/ondevice-controls":
version: 0.0.0-use.local
resolution: "@storybook/addon-ondevice-controls@workspace:packages/ondevice-controls"
dependencies:
"@storybook/addon-controls": "npm:^8.4.2"
"@storybook/core": "npm:^8.4.2"
"@storybook/react-native-theming": "npm:^8.4.3"
"@storybook/react-native-ui": "npm:^8.4.3"
"@storybook/react-native-theming": "npm:^8.4.4-alpha.0"
"@storybook/react-native-ui": "npm:^8.4.4-alpha.0"
cross-env: "npm:^7.0.3"
deep-equal: "npm:^1.0.1"
prop-types: "npm:^15.7.2"
Expand All @@ -5176,12 +5176,12 @@ __metadata:
languageName: unknown
linkType: soft

"@storybook/addon-ondevice-notes@npm:^8.4.3, @storybook/addon-ondevice-notes@workspace:packages/ondevice-notes":
"@storybook/addon-ondevice-notes@npm:^8.4.4-alpha.0, @storybook/addon-ondevice-notes@workspace:packages/ondevice-notes":
version: 0.0.0-use.local
resolution: "@storybook/addon-ondevice-notes@workspace:packages/ondevice-notes"
dependencies:
"@storybook/core": "npm:^8.4.2"
"@storybook/react-native-theming": "npm:^8.4.3"
"@storybook/react-native-theming": "npm:^8.4.4-alpha.0"
react-native-markdown-display: "npm:^7.0.2"
typescript: "npm:^5.3.3"
peerDependencies:
Expand Down Expand Up @@ -5490,7 +5490,7 @@ __metadata:
languageName: node
linkType: hard

"@storybook/react-native-theming@npm:^8.4.3, @storybook/react-native-theming@workspace:packages/react-native-theming":
"@storybook/react-native-theming@npm:^8.4.4-alpha.0, @storybook/react-native-theming@workspace:packages/react-native-theming":
version: 0.0.0-use.local
resolution: "@storybook/react-native-theming@workspace:packages/react-native-theming"
dependencies:
Expand All @@ -5504,13 +5504,13 @@ __metadata:
languageName: unknown
linkType: soft

"@storybook/react-native-ui@npm:^8.4.3, @storybook/react-native-ui@workspace:packages/react-native-ui":
"@storybook/react-native-ui@npm:^8.4.4-alpha.0, @storybook/react-native-ui@workspace:packages/react-native-ui":
version: 0.0.0-use.local
resolution: "@storybook/react-native-ui@workspace:packages/react-native-ui"
dependencies:
"@storybook/core": "npm:^8.4.2"
"@storybook/react": "npm:^8.4.2"
"@storybook/react-native-theming": "npm:^8.4.3"
"@storybook/react-native-theming": "npm:^8.4.4-alpha.0"
"@types/jest": "npm:^29.4.3"
"@types/react": "npm:~18.3.12"
babel-jest: "npm:^29.7.0"
Expand All @@ -5534,16 +5534,16 @@ __metadata:
languageName: unknown
linkType: soft

"@storybook/react-native@npm:^8.4.3, @storybook/react-native@workspace:packages/react-native":
"@storybook/react-native@npm:^8.4.4-alpha.0, @storybook/react-native@workspace:packages/react-native":
version: 0.0.0-use.local
resolution: "@storybook/react-native@workspace:packages/react-native"
dependencies:
"@storybook/core": "npm:^8.4.2"
"@storybook/csf": "npm:^0.1.1"
"@storybook/global": "npm:^5.0.0"
"@storybook/react": "npm:^8.4.2"
"@storybook/react-native-theming": "npm:^8.4.3"
"@storybook/react-native-ui": "npm:^8.4.3"
"@storybook/react-native-theming": "npm:^8.4.4-alpha.0"
"@storybook/react-native-ui": "npm:^8.4.4-alpha.0"
"@types/jest": "npm:^29.4.3"
"@types/react": "npm:~18.3.12"
babel-jest: "npm:^29.7.0"
Expand Down Expand Up @@ -9975,19 +9975,19 @@ __metadata:
"@storybook/addon-essentials": "npm:^8.4.2"
"@storybook/addon-interactions": "npm:^8.4.2"
"@storybook/addon-links": "npm:^8.4.2"
"@storybook/addon-ondevice-actions": "npm:^8.4.3"
"@storybook/addon-ondevice-backgrounds": "npm:^8.4.3"
"@storybook/addon-ondevice-controls": "npm:^8.4.3"
"@storybook/addon-ondevice-notes": "npm:^8.4.3"
"@storybook/addon-ondevice-actions": "npm:^8.4.4-alpha.0"
"@storybook/addon-ondevice-backgrounds": "npm:^8.4.4-alpha.0"
"@storybook/addon-ondevice-controls": "npm:^8.4.4-alpha.0"
"@storybook/addon-ondevice-notes": "npm:^8.4.4-alpha.0"
"@storybook/addon-react-native-server": "npm:0.0.6"
"@storybook/addon-react-native-web": "npm:^0.0.26"
"@storybook/addon-webpack5-compiler-babel": "npm:^3.0.3"
"@storybook/blocks": "npm:^8.4.2"
"@storybook/builder-webpack5": "npm:^8.4.2"
"@storybook/global": "npm:^5.0.0"
"@storybook/react": "npm:^8.4.2"
"@storybook/react-native": "npm:^8.4.3"
"@storybook/react-native-theming": "npm:^8.4.3"
"@storybook/react-native": "npm:^8.4.4-alpha.0"
"@storybook/react-native-theming": "npm:^8.4.4-alpha.0"
"@storybook/react-webpack5": "npm:^8.4.2"
"@storybook/test": "npm:^8.4.2"
"@testing-library/react-native": "npm:12.4.3"
Expand Down

0 comments on commit d33440a

Please sign in to comment.