@nx/react-native 18.0.0-beta.1 → 18.0.0-beta.3

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.
Files changed (161) hide show
  1. package/.eslintrc.json +6 -1
  2. package/executors.json +5 -0
  3. package/generators.json +12 -11
  4. package/migrations.json +73 -1
  5. package/package.json +10 -15
  6. package/plugins/metro-resolver.js +4 -1
  7. package/plugins/plugin.d.ts +2 -0
  8. package/plugins/plugin.js +12 -1
  9. package/plugins/with-nx-metro.js +6 -2
  10. package/src/executors/build-android/build-android.impl.js +1 -5
  11. package/src/executors/build-android/build-android.impl.ts +1 -5
  12. package/src/executors/bundle/schema.d.ts +1 -1
  13. package/src/executors/ensure-symlink/ensure-symlink.impl.d.ts +4 -0
  14. package/src/executors/ensure-symlink/ensure-symlink.impl.js +4 -0
  15. package/src/executors/ensure-symlink/ensure-symlink.impl.ts +4 -0
  16. package/src/executors/run-android/run-android.impl.js +4 -16
  17. package/src/executors/run-android/run-android.impl.ts +8 -17
  18. package/src/executors/run-ios/run-ios.impl.js +4 -16
  19. package/src/executors/run-ios/run-ios.impl.ts +9 -18
  20. package/src/executors/start/schema.d.ts +1 -1
  21. package/src/executors/start/start.impl.js +11 -26
  22. package/src/executors/start/start.impl.ts +14 -28
  23. package/src/executors/storybook/storybook.impl.d.ts +4 -0
  24. package/src/executors/storybook/storybook.impl.js +8 -1
  25. package/src/executors/storybook/storybook.impl.ts +16 -5
  26. package/src/executors/sync-deps/sync-deps.impl.d.ts +3 -2
  27. package/src/executors/sync-deps/sync-deps.impl.js +28 -11
  28. package/src/executors/sync-deps/sync-deps.impl.ts +45 -19
  29. package/src/executors/upgrade/schema.d.ts +1 -0
  30. package/src/executors/upgrade/schema.json +11 -0
  31. package/src/executors/upgrade/upgrade.impl.d.ts +13 -0
  32. package/src/executors/upgrade/upgrade.impl.js +47 -0
  33. package/src/executors/upgrade/upgrade.impl.ts +64 -0
  34. package/src/generators/application/application.js +27 -8
  35. package/src/generators/application/application.spec.ts +29 -2
  36. package/src/generators/application/files/app/.babelrc.js.template +23 -0
  37. package/src/generators/application/files/app/android/app/build.gradle.template +12 -28
  38. package/src/generators/application/files/app/android/app/src/debug/AndroidManifest.xml.template +2 -6
  39. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainActivity.kt.template +22 -0
  40. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.kt.template +45 -0
  41. package/src/generators/application/files/app/android/build.gradle.template +7 -20
  42. package/src/generators/application/files/app/android/gradle/wrapper/gradle-wrapper.properties +2 -1
  43. package/src/generators/application/files/app/android/gradle.properties +0 -3
  44. package/src/generators/application/files/app/android/gradlew.template +12 -7
  45. package/src/generators/application/files/app/android/settings.gradle.template +2 -2
  46. package/src/generators/application/files/app/ios/Podfile.template +0 -7
  47. package/src/generators/application/files/app/ios/__className__/AppDelegate.mm.template +5 -0
  48. package/src/generators/application/files/app/ios/__className__/Info.plist.template +5 -8
  49. package/src/generators/application/files/app/ios/__className__.xcodeproj/project.pbxproj.template +11 -33
  50. package/src/generators/application/files/app/metro.config.js.template +0 -4
  51. package/src/generators/application/files/app/src/app/App.tsx.template +29 -2
  52. package/src/generators/application/lib/add-e2e.d.ts +3 -0
  53. package/src/generators/application/lib/add-e2e.js +47 -0
  54. package/src/generators/application/lib/add-project.js +13 -17
  55. package/src/generators/application/lib/normalize-options.d.ts +4 -0
  56. package/src/generators/application/lib/normalize-options.js +9 -3
  57. package/src/generators/application/lib/normalize-options.spec.ts +53 -5
  58. package/src/generators/application/schema.d.ts +5 -3
  59. package/src/generators/application/schema.json +13 -5
  60. package/src/generators/component-story/component-story.d.ts +5 -8
  61. package/src/generators/component-story/component-story.js +8 -69
  62. package/src/generators/component-story/schema.d.ts +1 -0
  63. package/src/generators/component-story/schema.json +10 -2
  64. package/src/generators/init/init.d.ts +1 -0
  65. package/src/generators/init/init.js +14 -7
  66. package/src/generators/init/init.spec.ts +6 -2
  67. package/src/generators/init/schema.d.ts +1 -0
  68. package/src/generators/library/files/lib/.babelrc.js.template +21 -0
  69. package/src/generators/library/lib/normalize-options.js +1 -0
  70. package/src/generators/library/library.js +2 -1
  71. package/src/generators/library/library.spec.ts +12 -41
  72. package/src/generators/library/schema.d.ts +1 -0
  73. package/src/generators/library/schema.json +1 -1
  74. package/src/generators/stories/schema.d.ts +2 -0
  75. package/src/generators/stories/schema.json +14 -1
  76. package/src/generators/stories/stories.d.ts +5 -2
  77. package/src/generators/stories/stories.js +7 -50
  78. package/src/generators/storybook-configuration/configuration.d.ts +7 -2
  79. package/src/generators/storybook-configuration/configuration.js +15 -48
  80. package/src/generators/storybook-configuration/schema.d.ts +4 -2
  81. package/src/generators/storybook-configuration/schema.json +21 -11
  82. package/src/generators/upgrade-native/lib/normalize-options.d.ts +1 -1
  83. package/src/generators/upgrade-native/schema.d.ts +1 -1
  84. package/src/generators/upgrade-native/schema.json +2 -2
  85. package/src/generators/upgrade-native/upgrade-native.d.ts +2 -0
  86. package/src/generators/upgrade-native/upgrade-native.js +3 -0
  87. package/src/generators/web-configuration/files/base-vite/.babelrc.js.template +23 -0
  88. package/src/generators/web-configuration/files/base-vite/index.html__tmpl__ +15 -0
  89. package/src/generators/web-configuration/files/base-vite/public/favicon.ico +0 -0
  90. package/src/generators/web-configuration/files/base-vite/src/assets/.gitkeep +0 -0
  91. package/src/generators/web-configuration/files/base-vite/src/main-web.tsx__tmpl__ +9 -0
  92. package/src/generators/web-configuration/files/base-vite/vite.config.ts__tmpl__ +82 -0
  93. package/src/generators/web-configuration/files/base-webpack/.babelrc.js.template +23 -0
  94. package/src/generators/web-configuration/files/base-webpack/src/assets/.gitkeep +0 -0
  95. package/src/generators/web-configuration/files/base-webpack/src/favicon.ico +0 -0
  96. package/src/generators/web-configuration/files/base-webpack/src/index.html__tmpl__ +14 -0
  97. package/src/generators/web-configuration/files/base-webpack/src/main-web.tsx__tmpl__ +9 -0
  98. package/src/generators/web-configuration/files/base-webpack/webpack.config.js__tmpl__ +77 -0
  99. package/src/generators/web-configuration/lib/normalize-schema.d.ts +17 -0
  100. package/src/generators/web-configuration/lib/normalize-schema.js +16 -0
  101. package/src/generators/web-configuration/lib/webpack-targets.d.ts +7 -0
  102. package/src/generators/web-configuration/lib/webpack-targets.js +75 -0
  103. package/src/generators/web-configuration/schema.d.ts +6 -0
  104. package/src/generators/web-configuration/schema.json +42 -0
  105. package/src/generators/web-configuration/web-configuration.d.ts +12 -0
  106. package/src/generators/web-configuration/web-configuration.js +85 -0
  107. package/src/migrations/update-16-6-0/update-metro-config.js +0 -4
  108. package/src/migrations/update-16-9-0/remove-types-react-native.js +2 -9
  109. package/src/migrations/update-18-0-0/add-upgrade-target.d.ts +6 -0
  110. package/src/migrations/update-18-0-0/add-upgrade-target.js +33 -0
  111. package/src/migrations/update-18-0-0/add-web-configuration.d.ts +8 -0
  112. package/src/migrations/update-18-0-0/add-web-configuration.js +33 -0
  113. package/src/migrations/update-18-0-0/add-web-configuration.spec.ts +39 -0
  114. package/src/migrations/update-18-0-0/change-storybook-targets.d.ts +5 -0
  115. package/src/migrations/update-18-0-0/change-storybook-targets.js +57 -0
  116. package/src/migrations/update-18-0-0/remove-block-list.d.ts +6 -0
  117. package/src/migrations/update-18-0-0/remove-block-list.js +26 -0
  118. package/src/migrations/update-18-0-0/remove-block-list.spec.ts +68 -0
  119. package/src/migrations/update-18-0-0/remove-metro.d.ts +14 -0
  120. package/src/migrations/update-18-0-0/remove-metro.js +29 -0
  121. package/src/migrations/update-18-0-0/remove-symlink-target.d.ts +6 -0
  122. package/src/migrations/update-18-0-0/remove-symlink-target.js +30 -0
  123. package/src/migrations/update-18-0-0/remove-symlink-target.spec.ts +40 -0
  124. package/src/utils/add-jest.d.ts +1 -1
  125. package/src/utils/add-jest.js +13 -1
  126. package/src/utils/add-linting.d.ts +1 -0
  127. package/src/utils/add-linting.js +1 -0
  128. package/src/utils/add-linting.spec.ts +2 -4
  129. package/src/utils/ensure-dependencies.js +2 -6
  130. package/src/utils/testing-generators.js +1 -0
  131. package/src/utils/versions.d.ts +9 -12
  132. package/src/utils/versions.js +10 -13
  133. package/src/generators/application/files/app/android/app/src/debug/java/com/__lowerCaseName__/ReactNativeFlipper.java.template +0 -75
  134. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainActivity.java.template +0 -32
  135. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.java.template +0 -62
  136. package/src/generators/application/files/app/android/app/src/release/java/com/__lowerCaseName__/ReactNativeFlipper.java.template +0 -20
  137. package/src/generators/application/files/app/babel.config.json.template +0 -10
  138. package/src/generators/application/lib/add-detox.d.ts +0 -3
  139. package/src/generators/application/lib/add-detox.js +0 -23
  140. package/src/generators/component-story/component-story.spec.ts +0 -427
  141. package/src/generators/component-story/files/__componentFileName__.stories.__fileExt__ +0 -32
  142. package/src/generators/library/files/lib/babel.config.json.template +0 -19
  143. package/src/generators/stories/stories-app.spec.ts +0 -128
  144. package/src/generators/stories/stories-lib.spec.ts +0 -105
  145. package/src/generators/storybook-configuration/configuration.spec.ts +0 -135
  146. package/src/generators/storybook-configuration/files/app/storybook.ts.template +0 -9
  147. package/src/generators/storybook-configuration/files/app/toggle-storybook.tsx.template +0 -74
  148. package/src/generators/storybook-configuration/files/root/story-loader.ts.template +0 -5
  149. package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.d.ts +0 -6
  150. package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.js +0 -25
  151. package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.spec.ts +0 -161
  152. package/src/generators/storybook-configuration/lib/create-storybook-files.d.ts +0 -6
  153. package/src/generators/storybook-configuration/lib/create-storybook-files.js +0 -42
  154. package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.d.ts +0 -7
  155. package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.js +0 -29
  156. package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.spec.ts +0 -65
  157. package/src/utils/find-all-npm-dependencies.d.ts +0 -2
  158. package/src/utils/find-all-npm-dependencies.js +0 -25
  159. package/src/utils/find-all-npm-dependencies.spec.ts +0 -95
  160. package/src/utils/symlink-task.d.ts +0 -2
  161. package/src/utils/symlink-task.js +0 -18
@@ -20,6 +20,7 @@ describe('lib', () => {
20
20
  unitTestRunner: 'jest',
21
21
  strict: true,
22
22
  projectNameAndRootFormat: 'as-provided',
23
+ addPlugin: true,
23
24
  };
24
25
 
25
26
  beforeEach(() => {
@@ -28,17 +29,6 @@ describe('lib', () => {
28
29
  });
29
30
 
30
31
  describe('not nested', () => {
31
- it('should update project.json', async () => {
32
- await libraryGenerator(appTree, { ...defaultSchema, tags: 'one,two' });
33
- const projectConfiguration = readProjectConfiguration(appTree, 'my-lib');
34
- expect(projectConfiguration.root).toEqual('my-lib');
35
- expect(projectConfiguration.targets.build).toBeUndefined();
36
- expect(projectConfiguration.targets.lint).toEqual({
37
- executor: '@nx/eslint:lint',
38
- });
39
- expect(projectConfiguration.tags).toEqual(['one', 'two']);
40
- });
41
-
42
32
  it('should update root tsconfig.base.json', async () => {
43
33
  await libraryGenerator(appTree, defaultSchema);
44
34
  const tsconfigJson = readJson(appTree, '/tsconfig.base.json');
@@ -145,19 +135,6 @@ describe('lib', () => {
145
135
  });
146
136
  });
147
137
 
148
- it('should update project.json', async () => {
149
- await libraryGenerator(appTree, {
150
- ...defaultSchema,
151
- directory: 'my-dir',
152
- });
153
- const projectConfiguration = readProjectConfiguration(appTree, 'my-lib');
154
-
155
- expect(projectConfiguration.root).toEqual('my-dir');
156
- expect(projectConfiguration.targets.lint).toEqual({
157
- executor: '@nx/eslint:lint',
158
- });
159
- });
160
-
161
138
  it('should update root tsconfig.base.json', async () => {
162
139
  await libraryGenerator(appTree, {
163
140
  ...defaultSchema,
@@ -229,11 +206,6 @@ describe('lib', () => {
229
206
 
230
207
  expect(appTree.exists('my-lib/tsconfig.spec.json')).toBeFalsy();
231
208
  expect(appTree.exists('my-lib/jest.config.ts')).toBeFalsy();
232
- const projectConfiguration = readProjectConfiguration(appTree, 'my-lib');
233
- expect(projectConfiguration.targets.test).toBeUndefined();
234
- expect(projectConfiguration.targets.lint).toMatchObject({
235
- executor: '@nx/eslint:lint',
236
- });
237
209
  });
238
210
 
239
211
  it('should generate test configuration', async () => {
@@ -277,22 +249,21 @@ describe('lib', () => {
277
249
  moduleNameMapper: {
278
250
  '\\\\.svg$': '@nx/react-native/plugins/jest/svg-mock',
279
251
  },
252
+ transform: {
253
+ '^.+.(js|ts|tsx)$': [
254
+ 'babel-jest',
255
+ {
256
+ configFile: __dirname + '/.babelrc.js',
257
+ },
258
+ ],
259
+ '^.+.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$': require.resolve(
260
+ 'react-native/jest/assetFileTransformer.js'
261
+ ),
262
+ },
280
263
  coverageDirectory: '../coverage/my-lib',
281
264
  };
282
265
  "
283
266
  `);
284
- const projectConfiguration = readProjectConfiguration(appTree, 'my-lib');
285
- expect(projectConfiguration.targets.test).toMatchInlineSnapshot(`
286
- {
287
- "executor": "@nx/jest:jest",
288
- "options": {
289
- "jestConfig": "my-lib/jest.config.ts",
290
- },
291
- "outputs": [
292
- "{workspaceRoot}/coverage/{projectRoot}",
293
- ],
294
- }
295
- `);
296
267
  });
297
268
  });
298
269
 
@@ -21,4 +21,5 @@ export interface Schema {
21
21
  strict?: boolean;
22
22
  setParserOptionsProject?: boolean;
23
23
  skipPackageJson?: boolean; //default is false
24
+ addPlugin?: boolean;
24
25
  }
@@ -36,7 +36,7 @@
36
36
  "linter": {
37
37
  "description": "The tool to use for running lint checks.",
38
38
  "type": "string",
39
- "enum": ["eslint"],
39
+ "enum": ["eslint", "none"],
40
40
  "default": "eslint"
41
41
  },
42
42
  "unitTestRunner": {
@@ -1,5 +1,7 @@
1
1
  export interface StorybookStoriesSchema {
2
2
  project: string;
3
+ interactionTests?: boolean;
4
+ js?: boolean;
3
5
  ignorePaths?: string[];
4
6
  skipFormat?: boolean;
5
7
  }
@@ -14,7 +14,20 @@
14
14
  "$source": "projectName",
15
15
  "index": 0
16
16
  },
17
- "x-prompt": "For which project do you want to generate stories?"
17
+ "x-prompt": "For which project do you want to generate stories?",
18
+ "x-priority": "important"
19
+ },
20
+ "interactionTests": {
21
+ "type": "boolean",
22
+ "description": "Set up Storybook interaction tests.",
23
+ "x-prompt": "Do you want to set up Storybook interaction tests?",
24
+ "x-priority": "important",
25
+ "default": true
26
+ },
27
+ "js": {
28
+ "type": "boolean",
29
+ "description": "Generate JavaScript files rather than TypeScript files.",
30
+ "default": false
18
31
  },
19
32
  "ignorePaths": {
20
33
  "type": "array",
@@ -1,5 +1,8 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import { StorybookStoriesSchema } from './schema';
3
- export declare function createAllStories(tree: Tree, projectName: string, ignorePaths?: string[]): Promise<void>;
4
- export declare function storiesGenerator(host: Tree, schema: StorybookStoriesSchema): Promise<void>;
3
+ /**
4
+ * @deprecated This would be a direct pass through to @nx/react:stories generator.
5
+ * TODO (@xiongemi): remove this generator for v19
6
+ */
7
+ export declare function storiesGenerator(host: Tree, schema: StorybookStoriesSchema): Promise<import("@nx/devkit").GeneratorCallback>;
5
8
  export default storiesGenerator;
@@ -1,56 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.storiesGenerator = exports.createAllStories = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- const path_1 = require("path");
6
- const component_story_1 = require("../component-story/component-story");
7
- const stories_1 = require("@nx/react/src/generators/stories/stories");
8
- const minimatch_1 = require("minimatch");
9
- const versions_1 = require("../../utils/versions");
10
- async function createAllStories(tree, projectName, ignorePaths) {
11
- (0, devkit_1.ensurePackage)('@nx/storybook', versions_1.nxVersion);
12
- const { isTheFileAStory } = await Promise.resolve().then(() => require('@nx/storybook/src/utils/utilities'));
13
- const projects = (0, devkit_1.getProjects)(tree);
14
- const projectConfiguration = projects.get(projectName);
15
- const { sourceRoot } = projectConfiguration;
16
- const projectPath = await (0, stories_1.projectRootPath)(tree, projectConfiguration);
17
- let componentPaths = [];
18
- (0, devkit_1.visitNotIgnoredFiles)(tree, projectPath, (path) => {
19
- if (ignorePaths?.some((pattern) => (0, minimatch_1.minimatch)(path, pattern)))
20
- return;
21
- if ((path.endsWith('.tsx') && !path.endsWith('.spec.tsx')) ||
22
- (path.endsWith('.js') && !path.endsWith('.spec.js')) ||
23
- (path.endsWith('.jsx') && !path.endsWith('.spec.jsx'))) {
24
- // Check if file is NOT a story (either ts/tsx or js/jsx)
25
- if (!isTheFileAStory(tree, path)) {
26
- // Since the file is not a story
27
- // Let's see if the .stories.* file exists
28
- const ext = path.slice(path.lastIndexOf('.'));
29
- const storyPath = `${path.split(ext)[0]}.stories${ext}`;
30
- if (!tree.exists(storyPath)) {
31
- componentPaths.push(path);
32
- }
33
- }
34
- }
35
- });
36
- await Promise.all(componentPaths.map(async (componentPath) => {
37
- const relativeCmpDir = componentPath.replace((0, path_1.join)(sourceRoot, '/'), '');
38
- if (!(0, stories_1.containsComponentDeclaration)(tree, componentPath)) {
39
- return;
40
- }
41
- await (0, component_story_1.default)(tree, {
42
- componentPath: relativeCmpDir,
43
- project: projectName,
44
- skipFormat: true,
45
- });
46
- }));
47
- }
48
- exports.createAllStories = createAllStories;
3
+ exports.storiesGenerator = void 0;
4
+ const react_1 = require("@nx/react");
5
+ /**
6
+ * @deprecated This would be a direct pass through to @nx/react:stories generator.
7
+ * TODO (@xiongemi): remove this generator for v19
8
+ */
49
9
  async function storiesGenerator(host, schema) {
50
- await createAllStories(host, schema.project, schema.ignorePaths);
51
- if (!schema.skipFormat) {
52
- await (0, devkit_1.formatFiles)(host);
53
- }
10
+ return (0, react_1.storiesGenerator)(host, schema);
54
11
  }
55
12
  exports.storiesGenerator = storiesGenerator;
56
13
  exports.default = storiesGenerator;
@@ -1,4 +1,9 @@
1
- import { GeneratorCallback, Tree } from '@nx/devkit';
1
+ import { Tree } from '@nx/devkit';
2
2
  import { StorybookConfigureSchema } from './schema';
3
- export declare function storybookConfigurationGenerator(host: Tree, schema: StorybookConfigureSchema): Promise<GeneratorCallback>;
3
+ export declare function storybookConfigurationGenerator(tree: Tree, schema: StorybookConfigureSchema): Promise<import("@nx/devkit").GeneratorCallback>;
4
+ /**
5
+ * This would be a direct pass through to @nx/react:storybook-configuration generator.
6
+ * @TODO (@xiongemi): remove this generator for v19
7
+ */
8
+ export declare function storybookConfigurationGeneratorInternal(host: Tree, schema: StorybookConfigureSchema): Promise<import("@nx/devkit").GeneratorCallback>;
4
9
  export default storybookConfigurationGenerator;
@@ -1,56 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.storybookConfigurationGenerator = void 0;
3
+ exports.storybookConfigurationGeneratorInternal = exports.storybookConfigurationGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const versions_1 = require("../../utils/versions");
6
- const stories_1 = require("../stories/stories");
7
- const add_resolver_main_fields_to_metro_config_1 = require("./lib/add-resolver-main-fields-to-metro-config");
8
- const create_storybook_files_1 = require("./lib/create-storybook-files");
9
- const replace_app_import_with_storybook_toggle_1 = require("./lib/replace-app-import-with-storybook-toggle");
10
- async function generateStories(host, schema) {
11
- await (0, stories_1.default)(host, {
12
- project: schema.name,
13
- ignorePaths: schema.ignorePaths,
14
- skipFormat: true,
5
+ const react_1 = require("@nx/react");
6
+ function storybookConfigurationGenerator(tree, schema) {
7
+ return storybookConfigurationGeneratorInternal(tree, {
8
+ addPlugin: false,
9
+ ...schema,
15
10
  });
16
11
  }
17
- async function storybookConfigurationGenerator(host, schema) {
18
- const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/storybook', versions_1.nxVersion);
19
- const installTask = await configurationGenerator(host, {
20
- project: schema.name,
21
- uiFramework: '@storybook/react-native',
22
- configureCypress: false,
23
- js: false,
24
- linter: schema.linter,
25
- standaloneConfig: schema.standaloneConfig,
26
- tsConfiguration: schema.tsConfiguration,
27
- skipFormat: true,
28
- });
29
- const installRequiredPackagesTask = await (0, devkit_1.addDependenciesToPackageJson)(host, {}, {
30
- '@react-native-async-storage/async-storage': versions_1.reactNativeAsyncStorageVersion,
31
- 'react-native-safe-area-context': versions_1.reactNativeSafeAreaContextVersion,
32
- });
33
- addStorybookTask(host, schema.name);
34
- (0, create_storybook_files_1.createStorybookFiles)(host, schema);
35
- (0, replace_app_import_with_storybook_toggle_1.replaceAppImportWithStorybookToggle)(host, schema);
36
- (0, add_resolver_main_fields_to_metro_config_1.addResolverMainFieldsToMetroConfig)(host, schema);
37
- if (schema.generateStories) {
38
- await generateStories(host, schema);
39
- }
40
- await (0, devkit_1.formatFiles)(host);
41
- return (0, devkit_1.runTasksInSerial)(installTask, installRequiredPackagesTask);
42
- }
43
12
  exports.storybookConfigurationGenerator = storybookConfigurationGenerator;
44
- function addStorybookTask(host, projectName) {
45
- const projectConfig = (0, devkit_1.readProjectConfiguration)(host, projectName);
46
- projectConfig.targets['storybook'] = {
47
- executor: '@nx/react-native:storybook',
48
- options: {
49
- searchDir: [projectConfig.sourceRoot],
50
- outputFile: './.storybook/story-loader.js',
51
- pattern: '**/*.stories.@(js|jsx|ts|tsx|md)',
52
- },
53
- };
54
- (0, devkit_1.updateProjectConfiguration)(host, projectName, projectConfig);
13
+ /**
14
+ * This would be a direct pass through to @nx/react:storybook-configuration generator.
15
+ * @TODO (@xiongemi): remove this generator for v19
16
+ */
17
+ async function storybookConfigurationGeneratorInternal(host, schema) {
18
+ devkit_1.logger.warn(`Please run 'nx run @nx/react:storybook-configuration ${schema.project}' instead.`);
19
+ schema.addPlugin ??= process.env.NX_ADD_PLUGINS !== 'false';
20
+ return (0, react_1.storybookConfigurationGenerator)(host, schema);
55
21
  }
22
+ exports.storybookConfigurationGeneratorInternal = storybookConfigurationGeneratorInternal;
56
23
  exports.default = storybookConfigurationGenerator;
@@ -1,11 +1,13 @@
1
1
  import { Linter } from '@nx/eslint';
2
2
 
3
3
  export interface StorybookConfigureSchema {
4
- name: string;
4
+ project: string;
5
+ interactionTests?: boolean;
5
6
  generateStories?: boolean;
6
7
  js?: boolean;
7
8
  tsConfiguration?: boolean;
8
9
  linter?: Linter;
9
- standaloneConfig?: boolean;
10
10
  ignorePaths?: string[];
11
+ configureStaticServe?: boolean;
12
+ addPlugin?: boolean;
11
13
  }
@@ -6,24 +6,40 @@
6
6
  "description": "Set up Storybook for a React-Native app or library.",
7
7
  "type": "object",
8
8
  "properties": {
9
- "name": {
9
+ "project": {
10
10
  "type": "string",
11
- "aliases": ["project", "projectName"],
11
+ "aliases": ["name", "projectName"],
12
12
  "description": "Project for which to generate Storybook configuration.",
13
13
  "$default": {
14
14
  "$source": "argv",
15
15
  "index": 0
16
16
  },
17
17
  "x-prompt": "For which project do you want to generate Storybook configuration?",
18
- "x-dropdown": "projects"
18
+ "x-dropdown": "projects",
19
+ "x-priority": "important"
20
+ },
21
+ "interactionTests": {
22
+ "type": "boolean",
23
+ "description": "Set up Storybook interaction tests.",
24
+ "x-prompt": "Do you want to set up Storybook interaction tests?",
25
+ "x-priority": "important",
26
+ "alias": ["configureTestRunner"],
27
+ "default": true
19
28
  },
20
29
  "generateStories": {
21
30
  "type": "boolean",
22
- "description": "Automatically generate *.stories.ts files for components declared in this project?",
31
+ "description": "Automatically generate `*.stories.ts` files for components declared in this project?",
23
32
  "x-prompt": "Automatically generate *.stories.ts files for components declared in this project?",
24
33
  "default": true,
25
34
  "x-priority": "important"
26
35
  },
36
+ "configureStaticServe": {
37
+ "type": "boolean",
38
+ "description": "Specifies whether to configure a static file server target for serving storybook. Helpful for speeding up CI build/test times.",
39
+ "x-prompt": "Configure a static file server for the storybook instance?",
40
+ "default": true,
41
+ "x-priority": "important"
42
+ },
27
43
  "js": {
28
44
  "type": "boolean",
29
45
  "description": "Generate JavaScript story files rather than TypeScript story files.",
@@ -40,12 +56,6 @@
40
56
  "enum": ["eslint"],
41
57
  "default": "eslint"
42
58
  },
43
- "standaloneConfig": {
44
- "description": "Split the project configuration into `<projectRoot>/project.json` rather than including it inside `workspace.json`.",
45
- "type": "boolean",
46
- "default": true,
47
- "x-deprecated": "Nx only supports standaloneConfig"
48
- },
49
59
  "ignorePaths": {
50
60
  "type": "array",
51
61
  "description": "Paths to ignore when looking for components.",
@@ -65,5 +75,5 @@
65
75
  ]
66
76
  }
67
77
  },
68
- "required": ["name"]
78
+ "required": ["project"]
69
79
  }
@@ -6,7 +6,7 @@ export interface NormalizedSchema {
6
6
  lowerCaseName: string;
7
7
  entryFile: string;
8
8
  entryFileIos: string;
9
- e2eTestRunner: 'detox' | 'none';
9
+ e2eTestRunner: 'cypress' | 'playwright' | 'detox' | 'none';
10
10
  offsetFromRoot: string;
11
11
  }
12
12
  export declare function normalizeOptions(options: UpgradeNativeConfigureSchema, appProjectRoot: string): NormalizedSchema;
@@ -4,6 +4,6 @@ export interface UpgradeNativeConfigureSchema {
4
4
  name: string;
5
5
  displayName?: string;
6
6
  js: boolean; // default is false
7
- e2eTestRunner: 'detox' | 'none'; // default is detox
7
+ e2eTestRunner: 'cypress' | 'playwright' | 'detox' | 'none'; // default is cypress
8
8
  install: boolean; // default is true
9
9
  }
@@ -27,8 +27,8 @@
27
27
  "e2eTestRunner": {
28
28
  "description": "Adds the specified e2e test runner.",
29
29
  "type": "string",
30
- "enum": ["detox", "none"],
31
- "default": "detox"
30
+ "enum": ["cypress", "playwright", "detox", "none"],
31
+ "default": "cypress"
32
32
  },
33
33
  "install": {
34
34
  "type": "boolean",
@@ -1,4 +1,6 @@
1
1
  /**
2
+ * @deprecated use `nx run @nx/react-native:upgrade` instead.
3
+ * TODO (@xiongemi): remove this generator for nx v19
2
4
  * This function is a destructive command that replace React Native iOS and Android code with latest.
3
5
  * It would replace the Android and iOS folder entirely.
4
6
  */
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
  /**
3
+ * @deprecated use `nx run @nx/react-native:upgrade` instead.
4
+ * TODO (@xiongemi): remove this generator for nx v19
3
5
  * This function is a destructive command that replace React Native iOS and Android code with latest.
4
6
  * It would replace the Android and iOS folder entirely.
5
7
  */
@@ -11,6 +13,7 @@ const pod_install_task_1 = require("../../utils/pod-install-task");
11
13
  const chmod_android_gradle_files_1 = require("../../utils/chmod-android-gradle-files");
12
14
  const create_native_files_1 = require("./lib/create-native-files");
13
15
  async function reactNativeUpgradeNativeGenerator(host, schema) {
16
+ devkit_1.logger.warn(`Please run 'nx run @nx/react-native:upgrade ${schema.name}' instead.`);
14
17
  const { projectType, root: appProjectRoot } = (0, devkit_1.readProjectConfiguration)(host, schema.name);
15
18
  const iosProjectRoot = (0, devkit_1.joinPathFragments)(host.root, appProjectRoot, 'ios');
16
19
  const androidProjectRoot = (0, devkit_1.joinPathFragments)(host.root, appProjectRoot, 'android');
@@ -0,0 +1,23 @@
1
+ module.exports = function (api) {
2
+ api.cache(true);
3
+
4
+ if (
5
+ process.env.NX_TASK_TARGET_TARGET === 'build' ||
6
+ process.env.NX_TASK_TARGET_TARGET.includes('storybook')
7
+ ) {
8
+ return {
9
+ presets: [
10
+ [
11
+ '@nx/react/babel',
12
+ {
13
+ runtime: 'automatic',
14
+ },
15
+ ],
16
+ ],
17
+ };
18
+ }
19
+
20
+ return {
21
+ presets: [['module:@react-native/babel-preset', { "useTransformReactJSX": true }]],
22
+ };
23
+ };
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en" style="height: 100%">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title><%= className %></title>
6
+ <base href="/" />
7
+
8
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
9
+ <link rel="icon" type="image/x-icon" href="/favicon.ico" />
10
+ </head>
11
+ <body style="height:100%">
12
+ <div id="root" style="display: flex; height: 100%"></div>
13
+ <script type="module" src="/src/main-web.tsx"></script>
14
+ </body>
15
+ </html>
@@ -0,0 +1,9 @@
1
+ import { StrictMode } from 'react';
2
+ import * as ReactDOM from 'react-dom/client';
3
+
4
+ import App from './app/App';
5
+
6
+ const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
7
+ root.render(
8
+ <StrictMode><App /></StrictMode>
9
+ );
@@ -0,0 +1,82 @@
1
+ import { defineConfig } from 'vite';
2
+ import react from '@vitejs/plugin-react';
3
+ import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
4
+ import * as esbuild from 'esbuild';
5
+ import { readFileSync } from 'fs';
6
+
7
+ const extensions = [
8
+ '.mjs',
9
+ '.web.tsx',
10
+ '.tsx',
11
+ '.web.ts',
12
+ '.ts',
13
+ '.web.jsx',
14
+ '.jsx',
15
+ '.web.js',
16
+ '.js',
17
+ '.css',
18
+ '.json',
19
+ ];
20
+
21
+ const rollupPlugin = (matchers: RegExp[]) => ({
22
+ name: 'js-in-jsx',
23
+ load(id: string) {
24
+ if (matchers.some((matcher) => matcher.test(id)) && id.endsWith('.js')) {
25
+ const file = readFileSync(id, { encoding: 'utf-8' });
26
+ return esbuild.transformSync(file, { loader: 'jsx', jsx: 'automatic' });
27
+ }
28
+ },
29
+ });
30
+
31
+ export default defineConfig({
32
+ root: __dirname,
33
+ cacheDir: '../../node_modules/.vite/<%= fileName %>',
34
+ define: {
35
+ global: 'window',
36
+ },
37
+
38
+ resolve: {
39
+ extensions,
40
+ alias: {
41
+ 'react-native': 'react-native-web',
42
+ },
43
+ },
44
+
45
+ build: {
46
+ reportCompressedSize: true,
47
+ commonjsOptions: { transformMixedEsModules: true },
48
+ outDir: '../../dist/apps/<%= fileName %>/web',
49
+ rollupOptions: {
50
+ plugins: [rollupPlugin([/react-native-vector-icons/])],
51
+ },
52
+ },
53
+
54
+ server: {
55
+ port: 4200,
56
+ host: 'localhost',
57
+ fs: {
58
+ // Allow serving files from one level up to the project root
59
+ allow: ['..'],
60
+ },
61
+ },
62
+
63
+ preview: {
64
+ port: 4300,
65
+ host: 'localhost',
66
+ },
67
+
68
+ optimizeDeps: {
69
+ esbuildOptions: {
70
+ resolveExtensions: extensions,
71
+ jsx: 'automatic',
72
+ loader: { '.js': 'jsx' },
73
+ },
74
+ },
75
+
76
+ plugins: [react(), nxViteTsPaths()],
77
+
78
+ // Uncomment this if you are using workers.
79
+ // worker: {
80
+ // plugins: [ nxViteTsPaths() ],
81
+ // },
82
+ });
@@ -0,0 +1,23 @@
1
+ module.exports = function (api) {
2
+ api.cache(true);
3
+
4
+ if (
5
+ process.env.NX_TASK_TARGET_TARGET === 'build' ||
6
+ process.env.NX_TASK_TARGET_TARGET.includes('storybook')
7
+ ) {
8
+ return {
9
+ presets: [
10
+ [
11
+ '@nx/react/babel',
12
+ {
13
+ runtime: 'automatic',
14
+ },
15
+ ],
16
+ ],
17
+ };
18
+ }
19
+
20
+ return {
21
+ presets: [['module:@react-native/babel-preset', { "useTransformReactJSX": true }]],
22
+ };
23
+ };
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en" style="height: 100%">
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title><%= className %></title>
6
+ <base href="/" />
7
+
8
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
9
+ <link rel="icon" type="image/x-icon" href="favicon.ico" />
10
+ </head>
11
+ <body style="height:100%">
12
+ <div id="root" style="display: flex; height: 100%"></div>
13
+ </body>
14
+ </html>
@@ -0,0 +1,9 @@
1
+ import { StrictMode } from 'react';
2
+ import * as ReactDOM from 'react-dom/client';
3
+
4
+ import App from './app/App';
5
+
6
+ const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);
7
+ root.render(
8
+ <StrictMode><App /></StrictMode>
9
+ );