@nx/react-native 18.0.0-beta.1 → 18.0.0-canary.20240201-8762c38

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 (149) hide show
  1. package/.eslintrc.json +6 -1
  2. package/executors.json +5 -0
  3. package/generators.json +10 -9
  4. package/migrations.json +73 -1
  5. package/package.json +10 -15
  6. package/plugins/metro-resolver.js +4 -1
  7. package/plugins/with-nx-metro.js +6 -2
  8. package/src/executors/build-android/build-android.impl.js +1 -5
  9. package/src/executors/build-android/build-android.impl.ts +1 -5
  10. package/src/executors/bundle/schema.d.ts +1 -1
  11. package/src/executors/ensure-symlink/ensure-symlink.impl.d.ts +4 -0
  12. package/src/executors/ensure-symlink/ensure-symlink.impl.js +4 -0
  13. package/src/executors/ensure-symlink/ensure-symlink.impl.ts +4 -0
  14. package/src/executors/run-android/run-android.impl.js +4 -16
  15. package/src/executors/run-android/run-android.impl.ts +8 -17
  16. package/src/executors/run-ios/run-ios.impl.js +4 -16
  17. package/src/executors/run-ios/run-ios.impl.ts +9 -18
  18. package/src/executors/start/schema.d.ts +1 -1
  19. package/src/executors/start/start.impl.js +11 -26
  20. package/src/executors/start/start.impl.ts +14 -28
  21. package/src/executors/storybook/storybook.impl.d.ts +4 -0
  22. package/src/executors/storybook/storybook.impl.js +5 -1
  23. package/src/executors/storybook/storybook.impl.ts +13 -15
  24. package/src/executors/sync-deps/sync-deps.impl.d.ts +2 -2
  25. package/src/executors/sync-deps/sync-deps.impl.js +20 -5
  26. package/src/executors/sync-deps/sync-deps.impl.ts +20 -9
  27. package/src/executors/upgrade/schema.d.ts +1 -0
  28. package/src/executors/upgrade/schema.json +11 -0
  29. package/src/executors/upgrade/upgrade.impl.d.ts +13 -0
  30. package/src/executors/upgrade/upgrade.impl.js +47 -0
  31. package/src/executors/upgrade/upgrade.impl.ts +64 -0
  32. package/src/generators/application/application.js +21 -7
  33. package/src/generators/application/application.spec.ts +27 -0
  34. package/src/generators/application/files/app/.babelrc.js.template +23 -0
  35. package/src/generators/application/files/app/android/app/build.gradle.template +12 -28
  36. package/src/generators/application/files/app/android/app/src/debug/AndroidManifest.xml.template +2 -6
  37. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainActivity.kt.template +22 -0
  38. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.kt.template +45 -0
  39. package/src/generators/application/files/app/android/build.gradle.template +7 -20
  40. package/src/generators/application/files/app/android/gradle/wrapper/gradle-wrapper.properties +2 -1
  41. package/src/generators/application/files/app/android/gradle.properties +0 -3
  42. package/src/generators/application/files/app/android/gradlew.template +12 -7
  43. package/src/generators/application/files/app/android/settings.gradle.template +2 -2
  44. package/src/generators/application/files/app/ios/Podfile.template +0 -7
  45. package/src/generators/application/files/app/ios/__className__/AppDelegate.mm.template +5 -0
  46. package/src/generators/application/files/app/ios/__className__/Info.plist.template +5 -8
  47. package/src/generators/application/files/app/ios/__className__.xcodeproj/project.pbxproj.template +11 -33
  48. package/src/generators/application/files/app/metro.config.js.template +0 -4
  49. package/src/generators/application/files/app/src/app/App.tsx.template +5 -2
  50. package/src/generators/application/lib/add-e2e.d.ts +3 -0
  51. package/src/generators/application/lib/add-e2e.js +47 -0
  52. package/src/generators/application/lib/add-project.js +13 -17
  53. package/src/generators/application/lib/normalize-options.d.ts +4 -0
  54. package/src/generators/application/lib/normalize-options.js +8 -3
  55. package/src/generators/application/lib/normalize-options.spec.ts +48 -5
  56. package/src/generators/application/schema.d.ts +4 -3
  57. package/src/generators/application/schema.json +13 -5
  58. package/src/generators/component-story/component-story.d.ts +5 -8
  59. package/src/generators/component-story/component-story.js +8 -69
  60. package/src/generators/component-story/schema.d.ts +1 -0
  61. package/src/generators/component-story/schema.json +10 -2
  62. package/src/generators/init/init.js +0 -3
  63. package/src/generators/library/files/lib/.babelrc.js.template +21 -0
  64. package/src/generators/library/library.spec.ts +11 -0
  65. package/src/generators/library/schema.json +1 -1
  66. package/src/generators/stories/schema.d.ts +2 -0
  67. package/src/generators/stories/schema.json +14 -1
  68. package/src/generators/stories/stories.d.ts +5 -2
  69. package/src/generators/stories/stories.js +7 -50
  70. package/src/generators/storybook-configuration/configuration.d.ts +6 -2
  71. package/src/generators/storybook-configuration/configuration.js +7 -48
  72. package/src/generators/storybook-configuration/schema.d.ts +3 -2
  73. package/src/generators/storybook-configuration/schema.json +21 -11
  74. package/src/generators/upgrade-native/lib/normalize-options.d.ts +1 -1
  75. package/src/generators/upgrade-native/schema.d.ts +1 -1
  76. package/src/generators/upgrade-native/schema.json +2 -2
  77. package/src/generators/upgrade-native/upgrade-native.d.ts +2 -0
  78. package/src/generators/upgrade-native/upgrade-native.js +3 -0
  79. package/src/generators/web-configuration/files/base-vite/.babelrc.js.template +23 -0
  80. package/src/generators/web-configuration/files/base-vite/index.html__tmpl__ +15 -0
  81. package/src/generators/web-configuration/files/base-vite/public/favicon.ico +0 -0
  82. package/src/generators/web-configuration/files/base-vite/src/assets/.gitkeep +0 -0
  83. package/src/generators/web-configuration/files/base-vite/src/main-web.tsx__tmpl__ +9 -0
  84. package/src/generators/web-configuration/files/base-vite/vite.config.ts__tmpl__ +82 -0
  85. package/src/generators/web-configuration/files/base-webpack/.babelrc.js.template +23 -0
  86. package/src/generators/web-configuration/files/base-webpack/src/assets/.gitkeep +0 -0
  87. package/src/generators/web-configuration/files/base-webpack/src/favicon.ico +0 -0
  88. package/src/generators/web-configuration/files/base-webpack/src/index.html__tmpl__ +14 -0
  89. package/src/generators/web-configuration/files/base-webpack/src/main-web.tsx__tmpl__ +9 -0
  90. package/src/generators/web-configuration/files/base-webpack/webpack.config.js__tmpl__ +77 -0
  91. package/src/generators/web-configuration/lib/normalize-schema.d.ts +17 -0
  92. package/src/generators/web-configuration/lib/normalize-schema.js +16 -0
  93. package/src/generators/web-configuration/lib/webpack-targets.d.ts +7 -0
  94. package/src/generators/web-configuration/lib/webpack-targets.js +75 -0
  95. package/src/generators/web-configuration/schema.d.ts +6 -0
  96. package/src/generators/web-configuration/schema.json +42 -0
  97. package/src/generators/web-configuration/web-configuration.d.ts +12 -0
  98. package/src/generators/web-configuration/web-configuration.js +85 -0
  99. package/src/migrations/update-16-6-0/update-metro-config.js +0 -4
  100. package/src/migrations/update-16-9-0/remove-types-react-native.js +2 -9
  101. package/src/migrations/update-18-0-0/add-upgrade-target.d.ts +6 -0
  102. package/src/migrations/update-18-0-0/add-upgrade-target.js +33 -0
  103. package/src/migrations/update-18-0-0/add-web-configuration.d.ts +8 -0
  104. package/src/migrations/update-18-0-0/add-web-configuration.js +33 -0
  105. package/src/migrations/update-18-0-0/add-web-configuration.spec.ts +39 -0
  106. package/src/migrations/update-18-0-0/change-storybook-targets.d.ts +5 -0
  107. package/src/migrations/update-18-0-0/change-storybook-targets.js +57 -0
  108. package/src/migrations/update-18-0-0/remove-block-list.d.ts +6 -0
  109. package/src/migrations/update-18-0-0/remove-block-list.js +26 -0
  110. package/src/migrations/update-18-0-0/remove-block-list.spec.ts +68 -0
  111. package/src/migrations/update-18-0-0/remove-metro.d.ts +14 -0
  112. package/src/migrations/update-18-0-0/remove-metro.js +29 -0
  113. package/src/migrations/update-18-0-0/remove-symlink-target.d.ts +6 -0
  114. package/src/migrations/update-18-0-0/remove-symlink-target.js +30 -0
  115. package/src/migrations/update-18-0-0/remove-symlink-target.spec.ts +40 -0
  116. package/src/utils/add-jest.js +11 -0
  117. package/src/utils/ensure-dependencies.js +2 -6
  118. package/src/utils/testing-generators.js +1 -0
  119. package/src/utils/versions.d.ts +9 -12
  120. package/src/utils/versions.js +10 -13
  121. package/src/generators/application/files/app/android/app/src/debug/java/com/__lowerCaseName__/ReactNativeFlipper.java.template +0 -75
  122. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainActivity.java.template +0 -32
  123. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.java.template +0 -62
  124. package/src/generators/application/files/app/android/app/src/release/java/com/__lowerCaseName__/ReactNativeFlipper.java.template +0 -20
  125. package/src/generators/application/files/app/babel.config.json.template +0 -10
  126. package/src/generators/application/lib/add-detox.d.ts +0 -3
  127. package/src/generators/application/lib/add-detox.js +0 -23
  128. package/src/generators/component-story/component-story.spec.ts +0 -427
  129. package/src/generators/component-story/files/__componentFileName__.stories.__fileExt__ +0 -32
  130. package/src/generators/library/files/lib/babel.config.json.template +0 -19
  131. package/src/generators/stories/stories-app.spec.ts +0 -128
  132. package/src/generators/stories/stories-lib.spec.ts +0 -105
  133. package/src/generators/storybook-configuration/configuration.spec.ts +0 -135
  134. package/src/generators/storybook-configuration/files/app/storybook.ts.template +0 -9
  135. package/src/generators/storybook-configuration/files/app/toggle-storybook.tsx.template +0 -74
  136. package/src/generators/storybook-configuration/files/root/story-loader.ts.template +0 -5
  137. package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.d.ts +0 -6
  138. package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.js +0 -25
  139. package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.spec.ts +0 -161
  140. package/src/generators/storybook-configuration/lib/create-storybook-files.d.ts +0 -6
  141. package/src/generators/storybook-configuration/lib/create-storybook-files.js +0 -42
  142. package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.d.ts +0 -7
  143. package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.js +0 -29
  144. package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.spec.ts +0 -65
  145. package/src/utils/find-all-npm-dependencies.d.ts +0 -2
  146. package/src/utils/find-all-npm-dependencies.js +0 -25
  147. package/src/utils/find-all-npm-dependencies.spec.ts +0 -95
  148. package/src/utils/symlink-task.d.ts +0 -2
  149. package/src/utils/symlink-task.js +0 -18
@@ -18,11 +18,14 @@ describe('Normalize Options', () => {
18
18
  e2eTestRunner: 'none',
19
19
  install: false,
20
20
  projectNameAndRootFormat: 'as-provided',
21
+ unitTestRunner: 'none',
22
+ bundler: 'vite',
21
23
  };
22
24
  const options = await normalizeOptions(appTree, schema);
23
25
  expect(options).toEqual({
24
26
  androidProjectRoot: 'my-app/android',
25
27
  appProjectRoot: 'my-app',
28
+ fileName: 'my-app',
26
29
  className: 'MyApp',
27
30
  displayName: 'MyApp',
28
31
  iosProjectRoot: 'my-app/ios',
@@ -34,8 +37,12 @@ describe('Normalize Options', () => {
34
37
  linter: Linter.EsLint,
35
38
  entryFile: 'src/main.tsx',
36
39
  e2eTestRunner: 'none',
37
- unitTestRunner: 'jest',
40
+ unitTestRunner: 'none',
38
41
  install: false,
42
+ bundler: 'vite',
43
+ rootProject: false,
44
+ e2eProjectName: 'my-app-e2e',
45
+ e2eProjectRoot: 'my-app-e2e',
39
46
  });
40
47
  });
41
48
 
@@ -45,12 +52,16 @@ describe('Normalize Options', () => {
45
52
  e2eTestRunner: 'none',
46
53
  install: false,
47
54
  projectNameAndRootFormat: 'as-provided',
55
+ linter: Linter.None,
56
+ unitTestRunner: 'none',
57
+ bundler: 'vite',
48
58
  };
49
59
  const options = await normalizeOptions(appTree, schema);
50
60
  expect(options).toEqual({
51
61
  androidProjectRoot: 'myApp/android',
52
62
  appProjectRoot: 'myApp',
53
63
  className: 'MyApp',
64
+ fileName: 'my-app',
54
65
  displayName: 'MyApp',
55
66
  iosProjectRoot: 'myApp/ios',
56
67
  lowerCaseName: 'myapp',
@@ -60,8 +71,13 @@ describe('Normalize Options', () => {
60
71
  projectNameAndRootFormat: 'as-provided',
61
72
  entryFile: 'src/main.tsx',
62
73
  e2eTestRunner: 'none',
63
- unitTestRunner: 'jest',
74
+ unitTestRunner: 'none',
64
75
  install: false,
76
+ bundler: 'vite',
77
+ linter: Linter.None,
78
+ rootProject: false,
79
+ e2eProjectName: 'my-app-e2e',
80
+ e2eProjectRoot: 'myApp-e2e',
65
81
  });
66
82
  });
67
83
 
@@ -72,12 +88,16 @@ describe('Normalize Options', () => {
72
88
  e2eTestRunner: 'none',
73
89
  install: false,
74
90
  projectNameAndRootFormat: 'as-provided',
91
+ linter: Linter.None,
92
+ unitTestRunner: 'none',
93
+ bundler: 'vite',
75
94
  };
76
95
  const options = await normalizeOptions(appTree, schema);
77
96
  expect(options).toEqual({
78
97
  androidProjectRoot: 'directory/my-app/android',
79
98
  appProjectRoot: 'directory/my-app',
80
99
  className: 'MyApp',
100
+ fileName: 'my-app',
81
101
  displayName: 'MyApp',
82
102
  iosProjectRoot: 'directory/my-app/ios',
83
103
  lowerCaseName: 'myapp',
@@ -88,8 +108,13 @@ describe('Normalize Options', () => {
88
108
  projectNameAndRootFormat: 'as-provided',
89
109
  entryFile: 'src/main.tsx',
90
110
  e2eTestRunner: 'none',
91
- unitTestRunner: 'jest',
111
+ unitTestRunner: 'none',
92
112
  install: false,
113
+ bundler: 'vite',
114
+ linter: Linter.None,
115
+ rootProject: false,
116
+ e2eProjectName: 'my-app-e2e',
117
+ e2eProjectRoot: 'directory/my-app-e2e',
93
118
  });
94
119
  });
95
120
 
@@ -99,12 +124,16 @@ describe('Normalize Options', () => {
99
124
  e2eTestRunner: 'none',
100
125
  install: false,
101
126
  projectNameAndRootFormat: 'as-provided',
127
+ linter: Linter.None,
128
+ unitTestRunner: 'none',
129
+ bundler: 'vite',
102
130
  };
103
131
  const options = await normalizeOptions(appTree, schema);
104
132
  expect(options).toEqual({
105
133
  androidProjectRoot: 'directory/my-app/android',
106
134
  appProjectRoot: 'directory/my-app',
107
135
  className: 'DirectoryMyApp',
136
+ fileName: 'directory/my-app',
108
137
  displayName: 'DirectoryMyApp',
109
138
  iosProjectRoot: 'directory/my-app/ios',
110
139
  lowerCaseName: 'directorymyapp',
@@ -114,8 +143,13 @@ describe('Normalize Options', () => {
114
143
  projectNameAndRootFormat: 'as-provided',
115
144
  entryFile: 'src/main.tsx',
116
145
  e2eTestRunner: 'none',
117
- unitTestRunner: 'jest',
146
+ unitTestRunner: 'none',
118
147
  install: false,
148
+ bundler: 'vite',
149
+ linter: Linter.None,
150
+ rootProject: false,
151
+ e2eProjectName: 'directory/my-app-e2e',
152
+ e2eProjectRoot: 'directory/my-app-e2e',
119
153
  });
120
154
  });
121
155
 
@@ -126,12 +160,16 @@ describe('Normalize Options', () => {
126
160
  e2eTestRunner: 'none',
127
161
  install: false,
128
162
  projectNameAndRootFormat: 'as-provided',
163
+ linter: Linter.None,
164
+ unitTestRunner: 'none',
165
+ bundler: 'vite',
129
166
  };
130
167
  const options = await normalizeOptions(appTree, schema);
131
168
  expect(options).toEqual({
132
169
  androidProjectRoot: 'my-app/android',
133
170
  appProjectRoot: 'my-app',
134
171
  className: 'MyApp',
172
+ fileName: 'my-app',
135
173
  displayName: 'My App',
136
174
  iosProjectRoot: 'my-app/ios',
137
175
  lowerCaseName: 'myapp',
@@ -141,8 +179,13 @@ describe('Normalize Options', () => {
141
179
  projectNameAndRootFormat: 'as-provided',
142
180
  entryFile: 'src/main.tsx',
143
181
  e2eTestRunner: 'none',
144
- unitTestRunner: 'jest',
182
+ unitTestRunner: 'none',
145
183
  install: false,
184
+ bundler: 'vite',
185
+ linter: Linter.None,
186
+ rootProject: false,
187
+ e2eProjectName: 'my-app-e2e',
188
+ e2eProjectRoot: 'my-app-e2e',
146
189
  });
147
190
  });
148
191
  });
@@ -9,13 +9,14 @@ export interface Schema {
9
9
  directory?: string;
10
10
  projectNameAndRootFormat?: ProjectNameAndRootFormat;
11
11
  tags?: string;
12
- unitTestRunner?: 'jest' | 'none';
12
+ unitTestRunner: 'jest' | 'none'; // default is jest
13
13
  pascalCaseFiles?: boolean;
14
14
  classComponent?: boolean;
15
15
  js?: boolean;
16
- linter?: Linter;
16
+ linter: Linter;
17
17
  setParserOptionsProject?: boolean;
18
- e2eTestRunner?: 'detox' | 'none';
18
+ e2eTestRunner: 'cypress' | 'playwright' | 'detox' | 'none'; // default is cypress
19
+ bundler: 'webpack' | 'vite'; // default is webpack
19
20
  install: boolean; // default is true
20
21
  skipPackageJson?: boolean; //default is false
21
22
  }
@@ -48,7 +48,7 @@
48
48
  "linter": {
49
49
  "description": "The tool to use for running lint checks.",
50
50
  "type": "string",
51
- "enum": ["eslint"],
51
+ "enum": ["eslint", "none"],
52
52
  "default": "eslint"
53
53
  },
54
54
  "unitTestRunner": {
@@ -75,20 +75,28 @@
75
75
  "e2eTestRunner": {
76
76
  "description": "Adds the specified e2e test runner.",
77
77
  "type": "string",
78
- "enum": ["detox", "none"],
79
- "default": "detox"
78
+ "enum": ["cypress", "playwright", "detox", "none"],
79
+ "default": "cypress"
80
80
  },
81
81
  "install": {
82
82
  "type": "boolean",
83
83
  "description": "Runs `pod install` for native modules before building iOS app.",
84
- "default": true,
85
- "x-priority": "internal"
84
+ "x-prompt": "Run 'pod install' for native modules?",
85
+ "default": true
86
86
  },
87
87
  "skipPackageJson": {
88
88
  "description": "Do not add dependencies to `package.json`.",
89
89
  "type": "boolean",
90
90
  "default": false,
91
91
  "x-priority": "internal"
92
+ },
93
+ "bundler": {
94
+ "description": "The bundler to use.",
95
+ "type": "string",
96
+ "enum": ["vite", "webpack"],
97
+ "x-prompt": "Which bundler do you want to use to build the application?",
98
+ "default": "webpack",
99
+ "x-priority": "important"
92
100
  }
93
101
  },
94
102
  "required": []
@@ -1,11 +1,8 @@
1
1
  import { Tree } from '@nx/devkit';
2
- import type * as ts from 'typescript';
3
- export interface CreateComponentStoriesFileSchema {
4
- project: string;
5
- componentPath: string;
6
- skipFormat?: boolean;
7
- }
8
- export declare function createComponentStoriesFile(host: Tree, { project, componentPath }: CreateComponentStoriesFileSchema): void;
9
- export declare function findPropsAndGenerateFile(host: Tree, sourceFile: ts.SourceFile, cmpDeclaration: ts.Node, componentDirectory: string, name: string, isPlainJs: boolean, fileExt: string, fromNodeArray?: boolean): void;
2
+ import { CreateComponentStoriesFileSchema } from './schema';
3
+ /**
4
+ * @deprecated This would be a direct pass through to @nx/react:component-story generator.
5
+ * TODO (@xiongemi): remove this generator for v19
6
+ */
10
7
  export declare function componentStoryGenerator(host: Tree, schema: CreateComponentStoriesFileSchema): Promise<void>;
11
8
  export default componentStoryGenerator;
@@ -1,76 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.componentStoryGenerator = exports.findPropsAndGenerateFile = exports.createComponentStoriesFile = void 0;
3
+ exports.componentStoryGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const ast_utils_1 = require("@nx/react/src/utils/ast-utils");
6
- const component_props_1 = require("@nx/react/src/utils/component-props");
7
- const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
8
- let tsModule;
9
- function createComponentStoriesFile(host, { project, componentPath }) {
10
- if (!tsModule) {
11
- tsModule = (0, ensure_typescript_1.ensureTypescript)();
12
- }
13
- const proj = (0, devkit_1.getProjects)(host).get(project);
14
- const sourceRoot = proj.sourceRoot;
15
- const componentFilePath = (0, devkit_1.joinPathFragments)(sourceRoot, componentPath);
16
- const componentDirectory = componentFilePath.replace(componentFilePath.slice(componentFilePath.lastIndexOf('/')), '');
17
- const isPlainJs = componentFilePath.endsWith('.jsx') || componentFilePath.endsWith('.js');
18
- let fileExt = 'tsx';
19
- if (componentFilePath.endsWith('.jsx')) {
20
- fileExt = 'jsx';
21
- }
22
- else if (componentFilePath.endsWith('.js')) {
23
- fileExt = 'js';
24
- }
25
- const componentFileName = componentFilePath
26
- .slice(componentFilePath.lastIndexOf('/') + 1)
27
- .replace('.tsx', '')
28
- .replace('.jsx', '')
29
- .replace('.js', '');
30
- const name = componentFileName;
31
- const contents = host.read(componentFilePath, 'utf-8');
32
- if (contents === null) {
33
- throw new Error(`Failed to read ${componentFilePath}`);
34
- }
35
- const sourceFile = tsModule.createSourceFile(componentFilePath, contents, tsModule.ScriptTarget.Latest, true);
36
- const cmpDeclaration = (0, ast_utils_1.getComponentNode)(sourceFile);
37
- if (!cmpDeclaration) {
38
- const componentNodes = (0, ast_utils_1.findExportDeclarationsForJsx)(sourceFile);
39
- if (componentNodes?.length) {
40
- componentNodes.forEach((declaration) => {
41
- findPropsAndGenerateFile(host, sourceFile, declaration, componentDirectory, name, isPlainJs, fileExt, componentNodes.length > 1);
42
- });
43
- }
44
- else {
45
- throw new Error(`Could not find any React Native component in file ${componentFilePath}`);
46
- }
47
- }
48
- else {
49
- findPropsAndGenerateFile(host, sourceFile, cmpDeclaration, componentDirectory, name, isPlainJs, fileExt);
50
- }
51
- }
52
- exports.createComponentStoriesFile = createComponentStoriesFile;
53
- function findPropsAndGenerateFile(host, sourceFile, cmpDeclaration, componentDirectory, name, isPlainJs, fileExt, fromNodeArray) {
54
- const { propsTypeName, props, argTypes } = (0, component_props_1.getDefaultsForComponent)(sourceFile, cmpDeclaration);
55
- (0, devkit_1.generateFiles)(host, (0, devkit_1.joinPathFragments)(__dirname, './files'), (0, devkit_1.normalizePath)(componentDirectory), {
56
- componentFileName: fromNodeArray
57
- ? `${name}--${cmpDeclaration.name.text}`
58
- : name,
59
- componentImportFileName: name,
60
- propsTypeName,
61
- props,
62
- argTypes,
63
- componentName: cmpDeclaration.name.text,
64
- isPlainJs,
65
- fileExt,
66
- });
67
- }
68
- exports.findPropsAndGenerateFile = findPropsAndGenerateFile;
5
+ const react_1 = require("@nx/react");
6
+ /**
7
+ * @deprecated This would be a direct pass through to @nx/react:component-story generator.
8
+ * TODO (@xiongemi): remove this generator for v19
9
+ */
69
10
  async function componentStoryGenerator(host, schema) {
70
- createComponentStoriesFile(host, schema);
71
- if (!schema.skipFormat) {
72
- await (0, devkit_1.formatFiles)(host);
73
- }
11
+ devkit_1.logger.warn(`Please run 'nx run @nx/react:component-story ${schema.project}' instead.`);
12
+ return (0, react_1.componentStoryGenerator)(host, schema);
74
13
  }
75
14
  exports.componentStoryGenerator = componentStoryGenerator;
76
15
  exports.default = componentStoryGenerator;
@@ -1,5 +1,6 @@
1
1
  export interface CreateComponentStoriesFileSchema {
2
2
  project: string;
3
3
  componentPath: string;
4
+ interactionTests?: boolean;
4
5
  skipFormat?: boolean;
5
6
  }
@@ -15,19 +15,27 @@
15
15
  "$source": "projectName",
16
16
  "index": 0
17
17
  },
18
- "x-prompt": "What's the name of the project where the component lives?"
18
+ "x-prompt": "What's name of the project where the component lives?",
19
+ "x-priority": "important"
19
20
  },
20
21
  "componentPath": {
21
22
  "type": "string",
22
23
  "description": "Relative path to the component file from the library root.",
23
24
  "examples": ["lib/components"],
24
- "x-prompt": "What's path of the component relative to the project's lib root?"
25
+ "x-prompt": "What's path of the component relative to the project's lib root?",
26
+ "x-priority": "important"
25
27
  },
26
28
  "skipFormat": {
27
29
  "description": "Skip formatting files.",
28
30
  "type": "boolean",
29
31
  "default": false,
30
32
  "x-priority": "internal"
33
+ },
34
+ "interactionTests": {
35
+ "type": "boolean",
36
+ "description": "Set up Storybook interaction tests.",
37
+ "default": true,
38
+ "x-priority": "important"
31
39
  }
32
40
  },
33
41
  "required": ["project", "componentPath"]
@@ -32,9 +32,6 @@ function updateDependencies(host, schema) {
32
32
  'react-native': versions_1.reactNativeVersion,
33
33
  }, {
34
34
  '@nx/react-native': versions_1.nxVersion,
35
- '@react-native-community/cli': versions_1.reactNativeCommunityCli,
36
- '@react-native-community/cli-platform-android': versions_1.reactNativeCommunityCliAndroid,
37
- '@react-native-community/cli-platform-ios': versions_1.reactNativeCommunityCliIos,
38
35
  }, undefined, schema.keepExistingVersions);
39
36
  }
40
37
  exports.updateDependencies = updateDependencies;
@@ -0,0 +1,21 @@
1
+ module.exports = function (api) {
2
+ api.cache(true);
3
+
4
+ return {
5
+ presets: [
6
+ [
7
+ '@nx/react/babel',
8
+ {
9
+ runtime: 'automatic',
10
+ useBuiltIns: 'usage',
11
+ },
12
+ ],
13
+ ],
14
+ plugins: [],
15
+ env: {
16
+ test: {
17
+ presets: [['module:@react-native/babel-preset', { "useTransformReactJSX": true }]],
18
+ },
19
+ },
20
+ };
21
+ };
@@ -277,6 +277,17 @@ describe('lib', () => {
277
277
  moduleNameMapper: {
278
278
  '\\\\.svg$': '@nx/react-native/plugins/jest/svg-mock',
279
279
  },
280
+ transform: {
281
+ '^.+.(js|ts|tsx)$': [
282
+ 'babel-jest',
283
+ {
284
+ configFile: __dirname + '/.babelrc.js',
285
+ },
286
+ ],
287
+ '^.+.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$': require.resolve(
288
+ 'react-native/jest/assetFileTransformer.js'
289
+ ),
290
+ },
280
291
  coverageDirectory: '../coverage/my-lib',
281
292
  };
282
293
  "
@@ -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,8 @@
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
+ /**
4
+ * This would be a direct pass through to @nx/react:storybook-configuration generator.
5
+ * @TODO (@xiongemi): remove this generator for v19
6
+ */
7
+ export declare function storybookConfigurationGenerator(host: Tree, schema: StorybookConfigureSchema): Promise<import("@nx/devkit").GeneratorCallback>;
4
8
  export default storybookConfigurationGenerator;
@@ -2,55 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  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,
15
- });
16
- }
5
+ const react_1 = require("@nx/react");
6
+ /**
7
+ * This would be a direct pass through to @nx/react:storybook-configuration generator.
8
+ * @TODO (@xiongemi): remove this generator for v19
9
+ */
17
10
  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);
11
+ devkit_1.logger.warn(`Please run 'nx run @nx/react:storybook-configuration ${schema.project}' instead.`);
12
+ return (0, react_1.storybookConfigurationGenerator)(host, schema);
42
13
  }
43
14
  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);
55
- }
56
15
  exports.default = storybookConfigurationGenerator;
@@ -1,11 +1,12 @@
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;
11
12
  }