@nx/react-native 17.0.3 → 17.0.4

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 (181) hide show
  1. package/.eslintrc.json +7 -1
  2. package/LICENSE +1 -1
  3. package/README.md +9 -4
  4. package/executors.json +5 -0
  5. package/generators.json +12 -11
  6. package/migrations.json +126 -0
  7. package/package.json +11 -15
  8. package/plugin.d.ts +1 -0
  9. package/plugin.js +6 -0
  10. package/plugins/metro-resolver.js +4 -1
  11. package/plugins/plugin.d.ts +14 -0
  12. package/plugins/plugin.js +162 -0
  13. package/plugins/with-nx-metro.js +6 -2
  14. package/src/executors/build-android/build-android.impl.js +2 -6
  15. package/src/executors/build-android/build-android.impl.ts +2 -6
  16. package/src/executors/build-android/schema.json +1 -1
  17. package/src/executors/build-ios/schema.json +1 -1
  18. package/src/executors/bundle/schema.d.ts +1 -1
  19. package/src/executors/bundle/schema.json +1 -1
  20. package/src/executors/ensure-symlink/ensure-symlink.impl.d.ts +4 -0
  21. package/src/executors/ensure-symlink/ensure-symlink.impl.js +4 -0
  22. package/src/executors/ensure-symlink/ensure-symlink.impl.ts +4 -0
  23. package/src/executors/ensure-symlink/schema.json +1 -1
  24. package/src/executors/pod-install/schema.json +1 -1
  25. package/src/executors/run-android/run-android.impl.js +5 -17
  26. package/src/executors/run-android/run-android.impl.ts +9 -18
  27. package/src/executors/run-android/schema.json +1 -1
  28. package/src/executors/run-ios/run-ios.impl.js +4 -16
  29. package/src/executors/run-ios/run-ios.impl.ts +9 -18
  30. package/src/executors/run-ios/schema.json +1 -1
  31. package/src/executors/start/schema.d.ts +1 -1
  32. package/src/executors/start/schema.json +1 -1
  33. package/src/executors/start/start.impl.js +11 -26
  34. package/src/executors/start/start.impl.ts +14 -28
  35. package/src/executors/storybook/storybook.impl.d.ts +4 -0
  36. package/src/executors/storybook/storybook.impl.js +15 -2
  37. package/src/executors/storybook/storybook.impl.ts +26 -7
  38. package/src/executors/sync-deps/schema.d.ts +1 -0
  39. package/src/executors/sync-deps/schema.json +6 -1
  40. package/src/executors/sync-deps/sync-deps.impl.d.ts +2 -1
  41. package/src/executors/sync-deps/sync-deps.impl.js +33 -11
  42. package/src/executors/sync-deps/sync-deps.impl.ts +57 -18
  43. package/src/executors/upgrade/schema.d.ts +1 -0
  44. package/src/executors/upgrade/schema.json +11 -0
  45. package/src/executors/upgrade/upgrade.impl.d.ts +13 -0
  46. package/src/executors/upgrade/upgrade.impl.js +47 -0
  47. package/src/executors/upgrade/upgrade.impl.ts +64 -0
  48. package/src/generators/application/application.js +52 -8
  49. package/src/generators/application/application.spec.ts +29 -2
  50. package/src/generators/application/files/app/.babelrc.js.template +23 -0
  51. package/src/generators/application/files/app/Gemfile.template +2 -1
  52. package/src/generators/application/files/app/android/app/build.gradle.template +12 -28
  53. package/src/generators/application/files/app/android/app/src/debug/AndroidManifest.xml.template +2 -6
  54. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainActivity.kt.template +22 -0
  55. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.kt.template +45 -0
  56. package/src/generators/application/files/app/android/build.gradle.template +7 -20
  57. package/src/generators/application/files/app/android/gradle/wrapper/gradle-wrapper.properties +2 -1
  58. package/src/generators/application/files/app/android/gradle.properties +0 -3
  59. package/src/generators/application/files/app/android/gradlew.template +12 -7
  60. package/src/generators/application/files/app/android/settings.gradle.template +2 -2
  61. package/src/generators/application/files/app/ios/Podfile.template +0 -7
  62. package/src/generators/application/files/app/ios/__className__/AppDelegate.mm.template +5 -0
  63. package/src/generators/application/files/app/ios/__className__/Info.plist.template +5 -8
  64. package/src/generators/application/files/app/ios/__className__.xcodeproj/project.pbxproj.template +11 -33
  65. package/src/generators/application/files/app/metro.config.js.template +1 -5
  66. package/src/generators/application/files/app/src/app/App.tsx.template +50 -13
  67. package/src/generators/application/lib/add-e2e.d.ts +3 -0
  68. package/src/generators/application/lib/add-e2e.js +46 -0
  69. package/src/generators/application/lib/add-project.js +18 -18
  70. package/src/generators/application/lib/normalize-options.d.ts +7 -0
  71. package/src/generators/application/lib/normalize-options.js +35 -3
  72. package/src/generators/application/lib/normalize-options.spec.ts +70 -7
  73. package/src/generators/application/schema.d.ts +5 -3
  74. package/src/generators/application/schema.json +14 -6
  75. package/src/generators/component/files/__fileName__.tsx__tmpl__ +1 -1
  76. package/src/generators/component/schema.d.ts +3 -3
  77. package/src/generators/component/schema.json +4 -4
  78. package/src/generators/component-story/component-story.d.ts +5 -8
  79. package/src/generators/component-story/component-story.js +8 -69
  80. package/src/generators/component-story/schema.d.ts +1 -0
  81. package/src/generators/component-story/schema.json +11 -3
  82. package/src/generators/init/init.d.ts +2 -1
  83. package/src/generators/init/init.js +55 -56
  84. package/src/generators/init/init.spec.ts +7 -6
  85. package/src/generators/init/schema.d.ts +3 -3
  86. package/src/generators/init/schema.json +13 -18
  87. package/src/generators/library/files/lib/.babelrc.js.template +21 -0
  88. package/src/generators/library/lib/normalize-options.js +5 -0
  89. package/src/generators/library/library.js +48 -38
  90. package/src/generators/library/library.spec.ts +12 -60
  91. package/src/generators/library/schema.d.ts +1 -0
  92. package/src/generators/library/schema.json +2 -2
  93. package/src/generators/stories/schema.d.ts +2 -0
  94. package/src/generators/stories/schema.json +15 -2
  95. package/src/generators/stories/stories.d.ts +5 -2
  96. package/src/generators/stories/stories.js +7 -50
  97. package/src/generators/storybook-configuration/configuration.d.ts +7 -2
  98. package/src/generators/storybook-configuration/configuration.js +18 -48
  99. package/src/generators/storybook-configuration/schema.d.ts +4 -2
  100. package/src/generators/storybook-configuration/schema.json +22 -12
  101. package/src/generators/upgrade-native/lib/normalize-options.d.ts +1 -1
  102. package/src/generators/upgrade-native/schema.d.ts +1 -1
  103. package/src/generators/upgrade-native/schema.json +3 -3
  104. package/src/generators/upgrade-native/upgrade-native.d.ts +2 -0
  105. package/src/generators/upgrade-native/upgrade-native.js +3 -0
  106. package/src/generators/web-configuration/files/base-vite/.babelrc.js.template +23 -0
  107. package/src/generators/web-configuration/files/base-vite/index.html__tmpl__ +15 -0
  108. package/src/generators/web-configuration/files/base-vite/public/favicon.ico +0 -0
  109. package/src/generators/web-configuration/files/base-vite/src/assets/.gitkeep +0 -0
  110. package/src/generators/web-configuration/files/base-vite/src/main-web.tsx__tmpl__ +9 -0
  111. package/src/generators/web-configuration/files/base-vite/vite.config.ts__tmpl__ +82 -0
  112. package/src/generators/web-configuration/files/base-webpack/.babelrc.js.template +23 -0
  113. package/src/generators/web-configuration/files/base-webpack/src/assets/.gitkeep +0 -0
  114. package/src/generators/web-configuration/files/base-webpack/src/favicon.ico +0 -0
  115. package/src/generators/web-configuration/files/base-webpack/src/index.html__tmpl__ +14 -0
  116. package/src/generators/web-configuration/files/base-webpack/src/main-web.tsx__tmpl__ +9 -0
  117. package/src/generators/web-configuration/files/base-webpack/webpack.config.js__tmpl__ +77 -0
  118. package/src/generators/web-configuration/lib/normalize-schema.d.ts +17 -0
  119. package/src/generators/web-configuration/lib/normalize-schema.js +16 -0
  120. package/src/generators/web-configuration/lib/webpack-targets.d.ts +7 -0
  121. package/src/generators/web-configuration/lib/webpack-targets.js +75 -0
  122. package/src/generators/web-configuration/schema.d.ts +6 -0
  123. package/src/generators/web-configuration/schema.json +42 -0
  124. package/src/generators/web-configuration/web-configuration.d.ts +12 -0
  125. package/src/generators/web-configuration/web-configuration.js +87 -0
  126. package/src/migrations/update-16-6-0/update-metro-config.js +1 -5
  127. package/src/migrations/update-16-9-0/remove-types-react-native.js +2 -9
  128. package/src/migrations/update-18-0-0/add-upgrade-target.d.ts +6 -0
  129. package/src/migrations/update-18-0-0/add-upgrade-target.js +33 -0
  130. package/src/migrations/update-18-0-0/add-web-configuration.d.ts +8 -0
  131. package/src/migrations/update-18-0-0/add-web-configuration.js +33 -0
  132. package/src/migrations/update-18-0-0/add-web-configuration.spec.ts +39 -0
  133. package/src/migrations/update-18-0-0/change-storybook-targets.d.ts +5 -0
  134. package/src/migrations/update-18-0-0/change-storybook-targets.js +57 -0
  135. package/src/migrations/update-18-0-0/remove-block-list.d.ts +6 -0
  136. package/src/migrations/update-18-0-0/remove-block-list.js +28 -0
  137. package/src/migrations/update-18-0-0/remove-block-list.spec.ts +68 -0
  138. package/src/migrations/update-18-0-0/remove-metro.d.ts +14 -0
  139. package/src/migrations/update-18-0-0/remove-metro.js +29 -0
  140. package/src/migrations/update-18-0-0/remove-symlink-target.d.ts +6 -0
  141. package/src/migrations/update-18-0-0/remove-symlink-target.js +30 -0
  142. package/src/migrations/update-18-0-0/remove-symlink-target.spec.ts +40 -0
  143. package/src/utils/add-jest.d.ts +1 -1
  144. package/src/utils/add-jest.js +13 -1
  145. package/src/utils/add-linting.d.ts +1 -0
  146. package/src/utils/add-linting.js +1 -1
  147. package/src/utils/add-linting.spec.ts +4 -6
  148. package/src/utils/chmod-android-gradle-files.js +6 -2
  149. package/src/utils/ensure-dependencies.d.ts +2 -0
  150. package/src/utils/ensure-dependencies.js +30 -0
  151. package/src/utils/find-all-npm-dependencies.js +5 -3
  152. package/src/utils/find-all-npm-dependencies.spec.ts +17 -9
  153. package/src/utils/testing-generators.js +1 -0
  154. package/src/utils/versions.d.ts +10 -13
  155. package/src/utils/versions.js +11 -14
  156. package/src/generators/application/files/app/android/app/src/debug/java/com/__lowerCaseName__/ReactNativeFlipper.java.template +0 -75
  157. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainActivity.java.template +0 -32
  158. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.java.template +0 -62
  159. package/src/generators/application/files/app/android/app/src/release/java/com/__lowerCaseName__/ReactNativeFlipper.java.template +0 -20
  160. package/src/generators/application/files/app/babel.config.json.template +0 -3
  161. package/src/generators/application/lib/add-detox.d.ts +0 -3
  162. package/src/generators/application/lib/add-detox.js +0 -23
  163. package/src/generators/component-story/component-story.spec.ts +0 -428
  164. package/src/generators/component-story/files/__componentFileName__.stories.__fileExt__ +0 -32
  165. package/src/generators/library/files/lib/babel.config.json.template +0 -17
  166. package/src/generators/stories/stories-app.spec.ts +0 -128
  167. package/src/generators/stories/stories-lib.spec.ts +0 -105
  168. package/src/generators/storybook-configuration/configuration.spec.ts +0 -135
  169. package/src/generators/storybook-configuration/files/app/storybook.ts.template +0 -9
  170. package/src/generators/storybook-configuration/files/app/toggle-storybook.tsx.template +0 -74
  171. package/src/generators/storybook-configuration/files/root/story-loader.ts.template +0 -5
  172. package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.d.ts +0 -6
  173. package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.js +0 -25
  174. package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.spec.ts +0 -161
  175. package/src/generators/storybook-configuration/lib/create-storybook-files.d.ts +0 -6
  176. package/src/generators/storybook-configuration/lib/create-storybook-files.js +0 -42
  177. package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.d.ts +0 -7
  178. package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.js +0 -29
  179. package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.spec.ts +0 -65
  180. package/src/utils/symlink-task.d.ts +0 -2
  181. package/src/utils/symlink-task.js +0 -18
@@ -2,15 +2,16 @@ import { join } from 'path';
2
2
  import * as chalk from 'chalk';
3
3
  import {
4
4
  ExecutorContext,
5
- logger,
6
5
  ProjectGraph,
6
+ logger,
7
+ readCachedProjectGraph,
7
8
  readJsonFile,
8
9
  writeJsonFile,
9
10
  } from '@nx/devkit';
10
11
 
11
- import { findAllNpmDependencies } from '../../utils/find-all-npm-dependencies';
12
-
13
12
  import { ReactNativeSyncDepsOptions } from './schema';
13
+ import { findAllNpmDependencies } from '../../utils/find-all-npm-dependencies';
14
+ import { PackageJson } from 'nx/src/utils/package-json';
14
15
 
15
16
  export interface ReactNativeSyncDepsOutput {
16
17
  success: boolean;
@@ -22,19 +23,31 @@ export default async function* syncDepsExecutor(
22
23
  ): AsyncGenerator<ReactNativeSyncDepsOutput> {
23
24
  const projectRoot =
24
25
  context.projectsConfigurations.projects[context.projectName].root;
26
+
27
+ const workspacePackageJsonPath = join(context.root, 'package.json');
28
+ const projectPackageJsonPath = join(
29
+ context.root,
30
+ projectRoot,
31
+ 'package.json'
32
+ );
33
+
34
+ const workspacePackageJson = readJsonFile(workspacePackageJsonPath);
35
+ const projectPackageJson = readJsonFile(projectPackageJsonPath);
25
36
  displayNewlyAddedDepsMessage(
26
37
  context.projectName,
27
38
  await syncDeps(
28
39
  context.projectName,
29
- projectRoot,
30
- context.root,
40
+ projectPackageJson,
41
+ projectPackageJsonPath,
42
+ workspacePackageJson,
31
43
  context.projectGraph,
32
44
  typeof options.include === 'string'
33
45
  ? options.include.split(',')
34
46
  : options.include,
35
47
  typeof options.exclude === 'string'
36
48
  ? options.exclude.split(',')
37
- : options.exclude
49
+ : options.exclude,
50
+ options.all
38
51
  )
39
52
  );
40
53
 
@@ -43,20 +56,26 @@ export default async function* syncDepsExecutor(
43
56
 
44
57
  export async function syncDeps(
45
58
  projectName: string,
46
- projectRoot: string,
47
- workspaceRoot: string,
48
- projectGraph: ProjectGraph,
59
+ projectPackageJson: PackageJson,
60
+ projectPackageJsonPath: string,
61
+ workspacePackageJson: PackageJson,
62
+ projectGraph: ProjectGraph = readCachedProjectGraph(),
49
63
  include: string[] = [],
50
- exclude: string[] = []
64
+ exclude: string[] = [],
65
+ all: boolean = false
51
66
  ): Promise<string[]> {
52
- let npmDeps = findAllNpmDependencies(projectGraph, projectName);
53
- const packageJsonPath = join(workspaceRoot, projectRoot, 'package.json');
54
- const packageJson = readJsonFile(packageJsonPath);
67
+ let npmDeps = all
68
+ ? Object.keys(workspacePackageJson.dependencies || {})
69
+ : findAllNpmDependencies(projectGraph, projectName);
70
+ let npmDevdeps = all
71
+ ? Object.keys(workspacePackageJson.devDependencies || {})
72
+ : [];
73
+
55
74
  const newDeps = [];
56
75
  let updated = false;
57
76
 
58
- if (!packageJson.dependencies) {
59
- packageJson.dependencies = {};
77
+ if (!projectPackageJson.dependencies) {
78
+ projectPackageJson.dependencies = {};
60
79
  updated = true;
61
80
  }
62
81
 
@@ -67,16 +86,36 @@ export async function syncDeps(
67
86
  npmDeps = npmDeps.filter((dep) => !exclude.includes(dep));
68
87
  }
69
88
 
89
+ if (!projectPackageJson.devDependencies) {
90
+ projectPackageJson.devDependencies = {};
91
+ }
92
+ if (!projectPackageJson.dependencies) {
93
+ projectPackageJson.dependencies = {};
94
+ }
95
+
70
96
  npmDeps.forEach((dep) => {
71
- if (!packageJson.dependencies[dep]) {
72
- packageJson.dependencies[dep] = '*';
97
+ if (
98
+ !projectPackageJson.dependencies[dep] &&
99
+ !projectPackageJson.devDependencies[dep]
100
+ ) {
101
+ projectPackageJson.dependencies[dep] = '*';
102
+ newDeps.push(dep);
103
+ updated = true;
104
+ }
105
+ });
106
+ npmDevdeps.forEach((dep) => {
107
+ if (
108
+ !projectPackageJson.dependencies[dep] &&
109
+ !projectPackageJson.devDependencies[dep]
110
+ ) {
111
+ projectPackageJson.devDependencies[dep] = '*';
73
112
  newDeps.push(dep);
74
113
  updated = true;
75
114
  }
76
115
  });
77
116
 
78
117
  if (updated) {
79
- writeJsonFile(packageJsonPath, packageJson);
118
+ writeJsonFile(projectPackageJsonPath, projectPackageJson);
80
119
  }
81
120
 
82
121
  return newDeps;
@@ -0,0 +1 @@
1
+ export interface UpgradeExecutorSchema {}
@@ -0,0 +1,11 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "version": 2,
4
+ "cli": "nx",
5
+ "$id": "NxReactNativeUpgrade",
6
+ "title": "React Native Upgrade Executor",
7
+ "description": "Upgrade React Native code for project.",
8
+ "type": "object",
9
+ "properties": {},
10
+ "required": []
11
+ }
@@ -0,0 +1,13 @@
1
+ /// <reference types="node" />
2
+ import { ExecutorContext } from '@nx/devkit';
3
+ import { ChildProcess } from 'child_process';
4
+ import { UpgradeExecutorSchema } from './schema';
5
+ export interface ReactNativeUpgradeOutput {
6
+ success: boolean;
7
+ }
8
+ /**
9
+ * This executor is equivalent to `npx react-native upgrade`.
10
+ * https://github.com/react-native-community/cli/blob/main/packages/cli/src/commands/upgrade/upgrade.ts
11
+ */
12
+ export default function upgradeExecutor(options: UpgradeExecutorSchema, context: ExecutorContext): AsyncGenerator<ReactNativeUpgradeOutput>;
13
+ export declare function runCliUpgrade(workspaceRoot: string, projectRoot: string): Promise<ChildProcess>;
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.runCliUpgrade = void 0;
4
+ const path_1 = require("path");
5
+ const child_process_1 = require("child_process");
6
+ /**
7
+ * This executor is equivalent to `npx react-native upgrade`.
8
+ * https://github.com/react-native-community/cli/blob/main/packages/cli/src/commands/upgrade/upgrade.ts
9
+ */
10
+ async function* upgradeExecutor(options, context) {
11
+ const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
12
+ await runCliUpgrade(context.root, projectRoot);
13
+ yield { success: true };
14
+ }
15
+ exports.default = upgradeExecutor;
16
+ function runCliUpgrade(workspaceRoot, projectRoot) {
17
+ return new Promise((resolve, reject) => {
18
+ const childProcess = (0, child_process_1.fork)(require.resolve('react-native/cli.js'), ['upgrade'], {
19
+ stdio: 'inherit',
20
+ cwd: (0, path_1.resolve)(workspaceRoot, projectRoot),
21
+ env: process.env,
22
+ });
23
+ /**
24
+ * Ensure the child process is killed when the parent exits
25
+ */
26
+ const processExitListener = (signal) => () => {
27
+ childProcess.kill(signal);
28
+ process.exit();
29
+ };
30
+ process.once('exit', (signal) => childProcess.kill(signal));
31
+ process.once('SIGTERM', processExitListener);
32
+ process.once('SIGINT', processExitListener);
33
+ process.once('SIGQUIT', processExitListener);
34
+ childProcess.on('error', (err) => {
35
+ reject(err);
36
+ });
37
+ childProcess.on('exit', (code) => {
38
+ if (code === 0) {
39
+ resolve(childProcess);
40
+ }
41
+ else {
42
+ reject(code);
43
+ }
44
+ });
45
+ });
46
+ }
47
+ exports.runCliUpgrade = runCliUpgrade;
@@ -0,0 +1,64 @@
1
+ import { ExecutorContext } from '@nx/devkit';
2
+ import { resolve as pathResolve } from 'path';
3
+ import { ChildProcess, fork } from 'child_process';
4
+
5
+ import { UpgradeExecutorSchema } from './schema';
6
+
7
+ export interface ReactNativeUpgradeOutput {
8
+ success: boolean;
9
+ }
10
+
11
+ /**
12
+ * This executor is equivalent to `npx react-native upgrade`.
13
+ * https://github.com/react-native-community/cli/blob/main/packages/cli/src/commands/upgrade/upgrade.ts
14
+ */
15
+ export default async function* upgradeExecutor(
16
+ options: UpgradeExecutorSchema,
17
+ context: ExecutorContext
18
+ ): AsyncGenerator<ReactNativeUpgradeOutput> {
19
+ const projectRoot =
20
+ context.projectsConfigurations.projects[context.projectName].root;
21
+
22
+ await runCliUpgrade(context.root, projectRoot);
23
+ yield { success: true };
24
+ }
25
+
26
+ export function runCliUpgrade(
27
+ workspaceRoot: string,
28
+ projectRoot: string
29
+ ): Promise<ChildProcess> {
30
+ return new Promise<ChildProcess>((resolve, reject) => {
31
+ const childProcess = fork(
32
+ require.resolve('react-native/cli.js'),
33
+ ['upgrade'],
34
+ {
35
+ stdio: 'inherit',
36
+ cwd: pathResolve(workspaceRoot, projectRoot),
37
+ env: process.env,
38
+ }
39
+ );
40
+
41
+ /**
42
+ * Ensure the child process is killed when the parent exits
43
+ */
44
+ const processExitListener = (signal?: number | NodeJS.Signals) => () => {
45
+ childProcess.kill(signal);
46
+ process.exit();
47
+ };
48
+ process.once('exit', (signal) => childProcess.kill(signal));
49
+ process.once('SIGTERM', processExitListener);
50
+ process.once('SIGINT', processExitListener);
51
+ process.once('SIGQUIT', processExitListener);
52
+
53
+ childProcess.on('error', (err) => {
54
+ reject(err);
55
+ });
56
+ childProcess.on('exit', (code) => {
57
+ if (code === 0) {
58
+ resolve(childProcess);
59
+ } else {
60
+ reject(code);
61
+ }
62
+ });
63
+ });
64
+ }
@@ -2,17 +2,23 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.reactNativeApplicationGeneratorInternal = exports.reactNativeApplicationGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const symlink_task_1 = require("../../utils/symlink-task");
5
+ const js_1 = require("@nx/js");
6
+ const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
6
7
  const add_linting_1 = require("../../utils/add-linting");
7
8
  const add_jest_1 = require("../../utils/add-jest");
8
9
  const chmod_android_gradle_files_1 = require("../../utils/chmod-android-gradle-files");
10
+ const pod_install_task_1 = require("../../utils/pod-install-task");
11
+ const web_configuration_1 = require("../web-configuration/web-configuration");
9
12
  const normalize_options_1 = require("./lib/normalize-options");
10
13
  const init_1 = require("../init/init");
11
14
  const add_project_1 = require("./lib/add-project");
12
15
  const create_application_files_1 = require("./lib/create-application-files");
13
- const add_detox_1 = require("./lib/add-detox");
16
+ const add_e2e_1 = require("./lib/add-e2e");
17
+ const ensure_dependencies_1 = require("../../utils/ensure-dependencies");
18
+ const sync_deps_impl_1 = require("../../executors/sync-deps/sync-deps.impl");
14
19
  async function reactNativeApplicationGenerator(host, schema) {
15
20
  return await reactNativeApplicationGeneratorInternal(host, {
21
+ addPlugin: false,
16
22
  projectNameAndRootFormat: 'derived',
17
23
  ...schema,
18
24
  });
@@ -20,9 +26,19 @@ async function reactNativeApplicationGenerator(host, schema) {
20
26
  exports.reactNativeApplicationGenerator = reactNativeApplicationGenerator;
21
27
  async function reactNativeApplicationGeneratorInternal(host, schema) {
22
28
  const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
29
+ const tasks = [];
30
+ const jsInitTask = await (0, js_1.initGenerator)(host, {
31
+ ...schema,
32
+ skipFormat: true,
33
+ });
34
+ tasks.push(jsInitTask);
35
+ const initTask = await (0, init_1.default)(host, { ...options, skipFormat: true });
36
+ tasks.push(initTask);
37
+ if (!options.skipPackageJson) {
38
+ tasks.push((0, ensure_dependencies_1.ensureDependencies)(host));
39
+ }
23
40
  (0, create_application_files_1.createApplicationFiles)(host, options);
24
41
  (0, add_project_1.addProject)(host, options);
25
- const initTask = await (0, init_1.default)(host, { ...options, skipFormat: true });
26
42
  const lintTask = await (0, add_linting_1.addLinting)(host, {
27
43
  ...options,
28
44
  projectRoot: options.appProjectRoot,
@@ -30,14 +46,42 @@ async function reactNativeApplicationGeneratorInternal(host, schema) {
30
46
  (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
31
47
  ],
32
48
  });
33
- const jestTask = await (0, add_jest_1.addJest)(host, options.unitTestRunner, options.projectName, options.appProjectRoot, options.js, options.skipPackageJson);
34
- const detoxTask = await (0, add_detox_1.addDetox)(host, options);
35
- const symlinkTask = (0, symlink_task_1.runSymlink)(host.root, options.appProjectRoot);
36
- const chmodTaskGradlew = (0, chmod_android_gradle_files_1.chmodAndroidGradlewFilesTask)((0, devkit_1.joinPathFragments)(host.root, options.androidProjectRoot));
49
+ tasks.push(lintTask);
50
+ const jestTask = await (0, add_jest_1.addJest)(host, options.unitTestRunner, options.projectName, options.appProjectRoot, options.js, options.skipPackageJson, options.addPlugin);
51
+ tasks.push(jestTask);
52
+ const webTask = await (0, web_configuration_1.webConfigurationGenerator)(host, {
53
+ ...options,
54
+ project: options.name,
55
+ skipFormat: true,
56
+ });
57
+ tasks.push(webTask);
58
+ const e2eTask = await (0, add_e2e_1.addE2e)(host, options);
59
+ tasks.push(e2eTask);
60
+ const chmodTaskGradlewTask = (0, chmod_android_gradle_files_1.chmodAndroidGradlewFilesTask)((0, devkit_1.joinPathFragments)(host.root, options.androidProjectRoot));
61
+ tasks.push(chmodTaskGradlewTask);
62
+ const podInstallTask = (0, pod_install_task_1.runPodInstall)((0, devkit_1.joinPathFragments)(host.root, options.iosProjectRoot));
63
+ if (options.install) {
64
+ const projectPackageJsonPath = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json');
65
+ const workspacePackageJson = (0, devkit_1.readJson)(host, 'package.json');
66
+ const projectPackageJson = (0, devkit_1.readJson)(host, projectPackageJsonPath);
67
+ await (0, sync_deps_impl_1.syncDeps)(options.name, projectPackageJson, projectPackageJsonPath, workspacePackageJson);
68
+ tasks.push(podInstallTask);
69
+ }
70
+ else {
71
+ devkit_1.output.log({
72
+ title: 'Skip `pod install`',
73
+ bodyLines: [
74
+ `run 'nx run ${options.name}:pod-install' to install native modules before running iOS app`,
75
+ ],
76
+ });
77
+ }
37
78
  if (!options.skipFormat) {
38
79
  await (0, devkit_1.formatFiles)(host);
39
80
  }
40
- return (0, devkit_1.runTasksInSerial)(initTask, lintTask, jestTask, detoxTask, symlinkTask, chmodTaskGradlew);
81
+ tasks.push(() => {
82
+ (0, log_show_project_command_1.logShowProjectCommand)(options.projectName);
83
+ });
84
+ return (0, devkit_1.runTasksInSerial)(...tasks);
41
85
  }
42
86
  exports.reactNativeApplicationGeneratorInternal = reactNativeApplicationGeneratorInternal;
43
87
  exports.default = reactNativeApplicationGenerator;
@@ -24,6 +24,8 @@ describe('app', () => {
24
24
  e2eTestRunner: 'none',
25
25
  install: false,
26
26
  projectNameAndRootFormat: 'as-provided',
27
+ unitTestRunner: 'none',
28
+ bundler: 'vite',
27
29
  });
28
30
  const projects = getProjects(appTree);
29
31
 
@@ -39,6 +41,8 @@ describe('app', () => {
39
41
  e2eTestRunner: 'none',
40
42
  install: false,
41
43
  projectNameAndRootFormat: 'as-provided',
44
+ unitTestRunner: 'none',
45
+ bundler: 'vite',
42
46
  });
43
47
 
44
48
  const projectConfiguration = readProjectConfiguration(appTree, 'my-app');
@@ -55,6 +59,8 @@ describe('app', () => {
55
59
  e2eTestRunner: 'none',
56
60
  install: false,
57
61
  projectNameAndRootFormat: 'as-provided',
62
+ unitTestRunner: 'jest',
63
+ bundler: 'vite',
58
64
  });
59
65
  expect(appTree.exists('my-app/src/app/App.tsx')).toBeTruthy();
60
66
  expect(appTree.exists('my-app/src/main.tsx')).toBeTruthy();
@@ -74,6 +80,17 @@ describe('app', () => {
74
80
  moduleNameMapper: {
75
81
  '\\\\.svg$': '@nx/react-native/plugins/jest/svg-mock',
76
82
  },
83
+ transform: {
84
+ '^.+.(js|ts|tsx)$': [
85
+ 'babel-jest',
86
+ {
87
+ configFile: __dirname + '/.babelrc.js',
88
+ },
89
+ ],
90
+ '^.+.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$': require.resolve(
91
+ 'react-native/jest/assetFileTransformer.js'
92
+ ),
93
+ },
77
94
  coverageDirectory: '../coverage/my-app',
78
95
  };
79
96
  "
@@ -88,9 +105,11 @@ describe('app', () => {
88
105
  e2eTestRunner: 'none',
89
106
  install: false,
90
107
  projectNameAndRootFormat: 'as-provided',
108
+ unitTestRunner: 'jest',
109
+ bundler: 'vite',
91
110
  });
92
- const targets = readProjectConfiguration(appTree, 'my-app').targets;
93
- expect(targets.test).toBeDefined();
111
+
112
+ expect(appTree.exists('my-app/jest.config.ts')).toBeTruthy();
94
113
  });
95
114
 
96
115
  it('should extend from root tsconfig.json when no tsconfig.base.json', async () => {
@@ -103,6 +122,8 @@ describe('app', () => {
103
122
  e2eTestRunner: 'none',
104
123
  install: false,
105
124
  projectNameAndRootFormat: 'as-provided',
125
+ unitTestRunner: 'none',
126
+ bundler: 'vite',
106
127
  });
107
128
 
108
129
  const tsconfig = readJson(appTree, 'my-app/tsconfig.json');
@@ -118,6 +139,8 @@ describe('app', () => {
118
139
  e2eTestRunner: 'detox',
119
140
  install: false,
120
141
  projectNameAndRootFormat: 'as-provided',
142
+ bundler: 'vite',
143
+ unitTestRunner: 'none',
121
144
  });
122
145
 
123
146
  const projects = getProjects(appTree);
@@ -168,6 +191,8 @@ describe('app', () => {
168
191
  e2eTestRunner: 'detox',
169
192
  install: false,
170
193
  projectNameAndRootFormat: 'as-provided',
194
+ bundler: 'vite',
195
+ unitTestRunner: 'none',
171
196
  });
172
197
 
173
198
  const projects = getProjects(appTree);
@@ -223,6 +248,8 @@ describe('app', () => {
223
248
  install: false,
224
249
  skipPackageJson: true,
225
250
  projectNameAndRootFormat: 'as-provided',
251
+ unitTestRunner: 'none',
252
+ bundler: 'webpack',
226
253
  });
227
254
 
228
255
  expect(readJson(appTree, 'package.json')).toEqual(packageJsonBefore);
@@ -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
+ };
@@ -3,4 +3,5 @@ source 'https://rubygems.org'
3
3
  # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version
4
4
  ruby ">= 2.6.10"
5
5
 
6
- gem 'cocoapods', '~> 1.12'
6
+ gem 'cocoapods', '~> 1.13'
7
+ gem 'activesupport', '>= 6.1.7.3', '< 7.1.0'
@@ -1,4 +1,5 @@
1
1
  apply plugin: "com.android.application"
2
+ apply plugin: "org.jetbrains.kotlin.android"
2
3
  apply plugin: "com.facebook.react"
3
4
 
4
5
  /**
@@ -9,12 +10,12 @@ react {
9
10
  /* Folders */
10
11
  // The root of your project, i.e. where "package.json" lives. Default is '..'
11
12
  // root = file("../")
12
- // The folder where the react-native NPM package is. Default is ../node_modules/react-native
13
- // reactNativeDir = file("../node_modules/react-native")
14
- // The folder where the react-native Codegen package is. Default is ../node_modules/@react-native/codegen
15
- // codegenDir = file("../node_modules/@react-native/codegen")
16
- // The cli.js file which is the React Native CLI entrypoint. Default is ../node_modules/react-native/cli.js
17
- // cliFile = file("../node_modules/react-native/cli.js")
13
+ // The folder where the react-native NPM package is. Default is <%= offsetFromRoot %>../../node_modules/react-native
14
+ reactNativeDir = file("<%= offsetFromRoot %>../../node_modules/react-native")
15
+ // The folder where the react-native Codegen package is. Default is <%= offsetFromRoot %>../../node_modules/@react-native/codegen
16
+ codegenDir = file("<%= offsetFromRoot %>../../node_modules/@react-native/codegen")
17
+ // The cli.js file which is the React Native CLI entrypoint. Default is <%= offsetFromRoot %>../../node_modules/react-native/cli.js
18
+ cliFile = file("<%= offsetFromRoot %>../../node_modules/react-native/cli.js")
18
19
 
19
20
  /* Variants */
20
21
  // The list of variants to that are debuggable. For those we're going to
@@ -36,7 +37,7 @@ react {
36
37
  // bundleAssetName = "MyApplication.android.bundle"
37
38
  //
38
39
  // The entry file for bundle generation. Default is 'index.android.js' or 'index.js'
39
- // entryFile = file("../js/MyApplication.android.js")
40
+ entryFile = file("../../<%= entryFile %>")
40
41
  //
41
42
  // A list of extra flags to pass to the 'bundle' commands.
42
43
  // See https://github.com/react-native-community/cli/blob/main/docs/commands.md#bundle
@@ -48,7 +49,6 @@ react {
48
49
  //
49
50
  // The list of flags to pass to the Hermes compiler. By default is "-O", "-output-source-map"
50
51
  // hermesFlags = ["-O", "-output-source-map"]
51
- entryFile = file("../../<%= entryFile %>")
52
52
  }
53
53
 
54
54
  /**
@@ -71,8 +71,8 @@ def jscFlavor = 'org.webkit:android-jsc:+'
71
71
 
72
72
  android {
73
73
  ndkVersion rootProject.ext.ndkVersion
74
-
75
- compileSdkVersion rootProject.ext.compileSdkVersion
74
+ buildToolsVersion rootProject.ext.buildToolsVersion
75
+ compileSdk rootProject.ext.compileSdkVersion
76
76
 
77
77
  namespace "com.<%= lowerCaseName %>"
78
78
  defaultConfig {
@@ -81,10 +81,6 @@ android {
81
81
  targetSdkVersion rootProject.ext.targetSdkVersion
82
82
  versionCode 1
83
83
  versionName "1.0"
84
- <% if (e2eTestRunner === 'detox') { %>
85
- testBuildType System.getProperty('testBuildType', 'debug')
86
- testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
87
- <% } %>
88
84
  }
89
85
  signingConfigs {
90
86
  debug {
@@ -104,27 +100,15 @@ android {
104
100
  signingConfig signingConfigs.debug
105
101
  minifyEnabled enableProguardInReleaseBuilds
106
102
  proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
107
- <% if (e2eTestRunner === 'detox') { %>
108
- proguardFile "${rootProject.projectDir}/../node_modules/detox/android/detox/proguard-rules-app.pro"
109
- <% } %>
110
103
  }
111
104
  }
112
105
  }
113
106
 
114
107
  dependencies {
115
- <% if (e2eTestRunner === 'detox') { %>
116
- androidTestImplementation('com.wix:detox:+')
117
- implementation 'androidx.appcompat:appcompat:1.1.0'
118
- <% } %>
119
108
  // The version of react-native is set by the React Native Gradle Plugin
120
109
  implementation("com.facebook.react:react-android")
110
+ implementation("com.facebook.react:flipper-integration")
121
111
 
122
- debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
123
- debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
124
- exclude group:'com.squareup.okhttp3', module:'okhttp'
125
- }
126
-
127
- debugImplementation("com.facebook.flipper:flipper-fresco-plugin:${FLIPPER_VERSION}")
128
112
  if (hermesEnabled.toBoolean()) {
129
113
  implementation("com.facebook.react:hermes-android")
130
114
  } else {
@@ -132,4 +116,4 @@ dependencies {
132
116
  }
133
117
  }
134
118
 
135
- apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
119
+ apply from: file("<%= offsetFromRoot %>../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project)
@@ -2,13 +2,9 @@
2
2
  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
3
  xmlns:tools="http://schemas.android.com/tools">
4
4
 
5
- <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
6
-
7
5
  <application
8
6
  android:usesCleartextTraffic="true"
9
7
  tools:targetApi="28"
10
- tools:ignore="GoogleAppIndexingWarning"
11
- android:networkSecurityConfig="@xml/network_security_config">
12
- <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" android:exported="false" />
13
- </application>
8
+ android:networkSecurityConfig="@xml/network_security_config"
9
+ tools:ignore="GoogleAppIndexingWarning"/>
14
10
  </manifest>
@@ -0,0 +1,22 @@
1
+ package com.<%= lowerCaseName %>
2
+
3
+ import com.facebook.react.ReactActivity
4
+ import com.facebook.react.ReactActivityDelegate
5
+ import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.fabricEnabled
6
+ import com.facebook.react.defaults.DefaultReactActivityDelegate
7
+
8
+ class MainActivity : ReactActivity() {
9
+
10
+ /**
11
+ * Returns the name of the main component registered from JavaScript. This is used to schedule
12
+ * rendering of the component.
13
+ */
14
+ override fun getMainComponentName(): String = "<%= className %>"
15
+
16
+ /**
17
+ * Returns the instance of the [ReactActivityDelegate]. We use [DefaultReactActivityDelegate]
18
+ * which allows you to enable New Architecture with a single boolean flags [fabricEnabled]
19
+ */
20
+ override fun createReactActivityDelegate(): ReactActivityDelegate =
21
+ DefaultReactActivityDelegate(this, mainComponentName, fabricEnabled)
22
+ }