@storybook/react-native 8.4.0-alpha.0 → 8.4.0-rc.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/babel.config.js CHANGED
@@ -1,4 +1,4 @@
1
1
  // note this file is used by jest to make it not shit itself
2
2
  module.exports = {
3
- presets: ['module:metro-react-native-babel-preset'],
3
+ presets: ['module:@react-native/babel-preset'],
4
4
  };
@@ -68,13 +68,31 @@ var require_common = __commonJS({
68
68
  function getPreviewExists({ configPath }) {
69
69
  return !!getFilePathExtension({ configPath }, "preview");
70
70
  }
71
+ function resolveAddonFile(addon, file, extensions = ["js", "mjs", "ts"]) {
72
+ try {
73
+ const basePath = path2.join(addon, file);
74
+ require.resolve(basePath);
75
+ return basePath;
76
+ } catch (error) {
77
+ }
78
+ for (const ext of extensions) {
79
+ try {
80
+ const filePath = path2.join(addon, `${file}.${ext}`);
81
+ require.resolve(filePath);
82
+ return filePath;
83
+ } catch (error) {
84
+ }
85
+ }
86
+ return null;
87
+ }
71
88
  module2.exports = {
72
89
  toRequireContext,
73
90
  requireUncached,
74
91
  getFilePathExtension,
75
92
  getMain,
76
93
  ensureRelativePathHasDot,
77
- getPreviewExists
94
+ getPreviewExists,
95
+ resolveAddonFile
78
96
  };
79
97
  }
80
98
  });
@@ -86,7 +104,8 @@ var require_generate = __commonJS({
86
104
  toRequireContext,
87
105
  ensureRelativePathHasDot,
88
106
  getMain,
89
- getPreviewExists
107
+ getPreviewExists,
108
+ resolveAddonFile
90
109
  } = require_common();
91
110
  var { normalizeStories, globToRegexp } = require("@storybook/core/common");
92
111
  var fs = require("fs");
@@ -118,9 +137,23 @@ var require_generate = __commonJS({
118
137
  req: require.context('${pathToStory}', ${r}, ${m})
119
138
  }`;
120
139
  });
121
- const registerAddons = main.addons?.map((addon) => `import "${addon}/register";`).join("\n");
122
- const doctools = 'require("@storybook/react-native/preview")';
123
- const enhancer = main.addons?.includes("@storybook/addon-ondevice-actions") ? "require('@storybook/addon-actions/preview')" : "";
140
+ let registerAddons = "";
141
+ for (const addon of main.addons) {
142
+ const registerPath = resolveAddonFile(addon, "register", ["js", "mjs", "jsx", "ts", "tsx"]);
143
+ if (registerPath) {
144
+ registerAddons += `import "${registerPath}";
145
+ `;
146
+ }
147
+ }
148
+ const docTools = 'require("@storybook/react-native/preview")';
149
+ const enhancers = [docTools];
150
+ for (const addon of main.addons) {
151
+ const previewPath = resolveAddonFile(addon, "preview", ["js", "mjs", "jsx", "ts", "tsx"]);
152
+ if (previewPath) {
153
+ enhancers.push(`require('${previewPath}')`);
154
+ continue;
155
+ }
156
+ }
124
157
  let options = "";
125
158
  let optionsVar = "";
126
159
  const reactNativeOptions = main.reactNative;
@@ -129,7 +162,10 @@ var require_generate = __commonJS({
129
162
  options = "options";
130
163
  }
131
164
  const previewExists = getPreviewExists({ configPath });
132
- const annotations = `[${previewExists ? "require('./preview')," : ""}${doctools}, ${enhancer}]`;
165
+ if (previewExists) {
166
+ enhancers.unshift("require('./preview')");
167
+ }
168
+ const annotations = `[${enhancers.join(", ")}]`;
133
169
  const globalTypes = `
134
170
  declare global {
135
171
  var view: ReturnType<typeof start>;
package/jest.config.js CHANGED
@@ -5,5 +5,9 @@ const config = {
5
5
  moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
6
6
  transformIgnorePatterns: ['node_modules/(?!react-native|@react-native)'],
7
7
  setupFilesAfterEnv: ['<rootDir>/../../node_modules/react-native-gesture-handler/jestSetup.js'],
8
+ transform: {
9
+ '^.+\\.(js)$': ['babel-jest', { plugins: ['babel-plugin-syntax-hermes-parser'] }],
10
+ '^.+\\.(ts|tsx)$': 'babel-jest',
11
+ },
8
12
  };
9
13
  module.exports = config;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/react-native",
3
- "version": "8.4.0-alpha.0",
3
+ "version": "8.4.0-rc.0",
4
4
  "description": "A better way to develop React Native Components for your app",
5
5
  "keywords": [
6
6
  "react",
@@ -41,15 +41,16 @@
41
41
  "dev": "npx --yes tsx buildscripts/gendtsdev.ts && tsup --watch",
42
42
  "prepare": "rm -rf dist/ && tsup",
43
43
  "test": "jest",
44
- "test:ci": "jest"
44
+ "test:ci": "jest",
45
+ "test:update": "jest --updateSnapshot"
45
46
  },
46
47
  "dependencies": {
47
- "@storybook/core": "^8.4.0-beta.0",
48
+ "@storybook/core": "^8.4.0",
48
49
  "@storybook/csf": "^0.1.1",
49
50
  "@storybook/global": "^5.0.0",
50
- "@storybook/react": "^8.4.0-beta.0",
51
- "@storybook/react-native-theming": "^8.4.0-alpha.0",
52
- "@storybook/react-native-ui": "^8.4.0-alpha.0",
51
+ "@storybook/react": "^8.4.0",
52
+ "@storybook/react-native-theming": "^8.4.0-rc.0",
53
+ "@storybook/react-native-ui": "^8.4.0-rc.0",
53
54
  "chokidar": "^3.5.1",
54
55
  "commander": "^8.2.0",
55
56
  "dedent": "^1.5.1",
@@ -59,7 +60,7 @@
59
60
  "react-native-swipe-gestures": "^1.0.5",
60
61
  "react-native-url-polyfill": "^2.0.0",
61
62
  "setimmediate": "^1.0.5",
62
- "storybook": "^8.4.0-beta.0",
63
+ "storybook": "^8.4.0",
63
64
  "type-fest": "~2.19",
64
65
  "util": "^0.12.4",
65
66
  "ws": "^8.18.0"
@@ -67,17 +68,20 @@
67
68
  "devDependencies": {
68
69
  "@types/jest": "^29.4.3",
69
70
  "@types/react": "~18.3.12",
70
- "babel-jest": "^29.4.3",
71
- "jest": "29.7.0",
71
+ "babel-jest": "^29.7.0",
72
+ "babel-plugin-syntax-hermes-parser": "^0.25.0",
73
+ "jest": "^29.7.0",
72
74
  "jotai": "^2.6.2",
73
- "react-test-renderer": "18.2.0",
75
+ "react": "18.3.1",
76
+ "react-native": "0.76.1",
77
+ "react-test-renderer": "^18.3.1",
74
78
  "tsup": "^7.2.0",
75
79
  "typescript": "^5.3.3"
76
80
  },
77
81
  "peerDependencies": {
78
82
  "@gorhom/bottom-sheet": ">=4",
79
83
  "react": "*",
80
- "react-native": ">=0.57.0",
84
+ "react-native": ">=0.72.0",
81
85
  "react-native-gesture-handler": ">=2",
82
86
  "react-native-safe-area-context": "*"
83
87
  },
@@ -87,5 +91,5 @@
87
91
  "publishConfig": {
88
92
  "access": "public"
89
93
  },
90
- "gitHead": "11531d9d55c0c933feb61d507595da80becb0b4a"
94
+ "gitHead": "abd58c20c9280c03482f879c0dd4471ccdc3432a"
91
95
  }
@@ -11,6 +11,7 @@ import "@storybook/addon-ondevice-controls/register";
11
11
  import "@storybook/addon-ondevice-backgrounds/register";
12
12
  import "@storybook/addon-ondevice-actions/register";
13
13
 
14
+
14
15
  const normalizedStories = [{
15
16
  titlePrefix: "",
16
17
  directory: "./scripts/mocks/file-extensions",
@@ -27,7 +28,7 @@ import "@storybook/addon-ondevice-actions/register";
27
28
  }
28
29
 
29
30
 
30
- const annotations = [require('./preview'),require("@storybook/react-native/preview"), require('@storybook/addon-actions/preview')];
31
+ const annotations = [require('./preview'), require("@storybook/react-native/preview"), require('@storybook/addon-ondevice-actions/preview')];
31
32
 
32
33
  global.STORIES = normalizedStories;
33
34
 
@@ -61,6 +62,7 @@ import "@storybook/addon-ondevice-controls/register";
61
62
  import "@storybook/addon-ondevice-backgrounds/register";
62
63
  import "@storybook/addon-ondevice-actions/register";
63
64
 
65
+
64
66
  const normalizedStories = [{
65
67
  titlePrefix: "ComponentsPrefix",
66
68
  directory: "./scripts/mocks/configuration-objects/components",
@@ -77,7 +79,7 @@ import "@storybook/addon-ondevice-actions/register";
77
79
  }
78
80
 
79
81
 
80
- const annotations = [require('./preview'),require("@storybook/react-native/preview"), require('@storybook/addon-actions/preview')];
82
+ const annotations = [require('./preview'), require("@storybook/react-native/preview"), require('@storybook/addon-ondevice-actions/preview')];
81
83
 
82
84
  global.STORIES = normalizedStories;
83
85
 
@@ -111,6 +113,7 @@ import "@storybook/addon-ondevice-controls/register";
111
113
  import "@storybook/addon-ondevice-backgrounds/register";
112
114
  import "@storybook/addon-ondevice-actions/register";
113
115
 
116
+
114
117
  const normalizedStories = [{
115
118
  titlePrefix: "",
116
119
  directory: "./scripts/mocks/all-config-files",
@@ -127,7 +130,7 @@ import "@storybook/addon-ondevice-actions/register";
127
130
  }
128
131
 
129
132
 
130
- const annotations = [require('./preview'),require("@storybook/react-native/preview"), require('@storybook/addon-actions/preview')];
133
+ const annotations = [require('./preview'), require("@storybook/react-native/preview"), require('@storybook/addon-ondevice-actions/preview')];
131
134
 
132
135
  global.STORIES = normalizedStories;
133
136
 
@@ -161,6 +164,7 @@ import "@storybook/addon-ondevice-controls/register";
161
164
  import "@storybook/addon-ondevice-backgrounds/register";
162
165
  import "@storybook/addon-ondevice-actions/register";
163
166
 
167
+
164
168
  const normalizedStories = [{
165
169
  titlePrefix: "",
166
170
  directory: "./scripts/mocks/no-preview",
@@ -177,7 +181,7 @@ import "@storybook/addon-ondevice-actions/register";
177
181
  }
178
182
 
179
183
 
180
- const annotations = [require("@storybook/react-native/preview"), require('@storybook/addon-actions/preview')];
184
+ const annotations = [require("@storybook/react-native/preview"), require('@storybook/addon-ondevice-actions/preview')];
181
185
 
182
186
  global.STORIES = normalizedStories;
183
187
 
@@ -211,6 +215,7 @@ import "@storybook/addon-ondevice-controls/register";
211
215
  import "@storybook/addon-ondevice-backgrounds/register";
212
216
  import "@storybook/addon-ondevice-actions/register";
213
217
 
218
+
214
219
  const normalizedStories = [{
215
220
  titlePrefix: "",
216
221
  directory: "./scripts/mocks/all-config-files",
@@ -222,7 +227,7 @@ import "@storybook/addon-ondevice-actions/register";
222
227
 
223
228
 
224
229
 
225
- const annotations = [require('./preview'),require("@storybook/react-native/preview"), require('@storybook/addon-actions/preview')];
230
+ const annotations = [require('./preview'), require("@storybook/react-native/preview"), require('@storybook/addon-ondevice-actions/preview')];
226
231
 
227
232
  global.STORIES = normalizedStories;
228
233
 
package/scripts/common.js CHANGED
@@ -58,6 +58,28 @@ function getPreviewExists({ configPath }) {
58
58
  return !!getFilePathExtension({ configPath }, 'preview');
59
59
  }
60
60
 
61
+ function resolveAddonFile(addon, file, extensions = ['js', 'mjs', 'ts']) {
62
+ try {
63
+ const basePath = path.join(addon, file);
64
+
65
+ require.resolve(basePath);
66
+
67
+ return basePath;
68
+ } catch (error) {}
69
+
70
+ for (const ext of extensions) {
71
+ try {
72
+ const filePath = path.join(addon, `${file}.${ext}`);
73
+
74
+ require.resolve(filePath);
75
+
76
+ return filePath;
77
+ } catch (error) {}
78
+ }
79
+
80
+ return null;
81
+ }
82
+
61
83
  module.exports = {
62
84
  toRequireContext,
63
85
  requireUncached,
@@ -65,4 +87,5 @@ module.exports = {
65
87
  getMain,
66
88
  ensureRelativePathHasDot,
67
89
  getPreviewExists,
90
+ resolveAddonFile,
68
91
  };
@@ -3,6 +3,7 @@ const {
3
3
  ensureRelativePathHasDot,
4
4
  getMain,
5
5
  getPreviewExists,
6
+ resolveAddonFile,
6
7
  } = require('./common');
7
8
  const { normalizeStories, globToRegexp } = require('@storybook/core/common');
8
9
  const fs = require('fs');
@@ -46,14 +47,28 @@ function generate({ configPath, absolute = false, useJs = false }) {
46
47
  }`;
47
48
  });
48
49
 
49
- const registerAddons = main.addons?.map((addon) => `import "${addon}/register";`).join('\n');
50
+ let registerAddons = '';
50
51
 
51
- const doctools = 'require("@storybook/react-native/preview")';
52
+ for (const addon of main.addons) {
53
+ const registerPath = resolveAddonFile(addon, 'register', ['js', 'mjs', 'jsx', 'ts', 'tsx']);
52
54
 
53
- // TODO: implement presets or something similar
54
- const enhancer = main.addons?.includes('@storybook/addon-ondevice-actions')
55
- ? "require('@storybook/addon-actions/preview')"
56
- : '';
55
+ if (registerPath) {
56
+ registerAddons += `import "${registerPath}";\n`;
57
+ }
58
+ }
59
+
60
+ const docTools = 'require("@storybook/react-native/preview")';
61
+
62
+ const enhancers = [docTools];
63
+
64
+ for (const addon of main.addons) {
65
+ const previewPath = resolveAddonFile(addon, 'preview', ['js', 'mjs', 'jsx', 'ts', 'tsx']);
66
+
67
+ if (previewPath) {
68
+ enhancers.push(`require('${previewPath}')`);
69
+ continue;
70
+ }
71
+ }
57
72
 
58
73
  let options = '';
59
74
  let optionsVar = '';
@@ -66,7 +81,11 @@ function generate({ configPath, absolute = false, useJs = false }) {
66
81
 
67
82
  const previewExists = getPreviewExists({ configPath });
68
83
 
69
- const annotations = `[${previewExists ? "require('./preview')," : ''}${doctools}, ${enhancer}]`;
84
+ if (previewExists) {
85
+ enhancers.unshift("require('./preview')");
86
+ }
87
+
88
+ const annotations = `[${enhancers.join(', ')}]`;
70
89
 
71
90
  const globalTypes = `
72
91
  declare global {