@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
@@ -11,6 +11,10 @@ import {
11
11
  } from '../sync-deps/sync-deps.impl';
12
12
  import { writeFileSync } from 'fs-extra';
13
13
 
14
+ /**
15
+ * TODO (@xiongemi): remove this function in v19.
16
+ * @deprecated Going to use the default react storybook target. Use @nx/react:storybook executor instead.
17
+ */
14
18
  export default async function* reactNativeStorybookExecutor(
15
19
  options: ReactNativeStorybookOptions,
16
20
  context: ExecutorContext
@@ -28,21 +32,15 @@ export default async function* reactNativeStorybookExecutor(
28
32
  if (fileExists(packageJsonPath))
29
33
  displayNewlyAddedDepsMessage(
30
34
  context.projectName,
31
- await syncDeps(
32
- context.projectName,
33
- projectRoot,
34
- context.root,
35
- context.projectGraph,
36
- [
37
- `@storybook/react-native`,
38
- '@storybook/addon-ondevice-actions',
39
- '@storybook/addon-ondevice-backgrounds',
40
- '@storybook/addon-ondevice-controls',
41
- '@storybook/addon-ondevice-notes',
42
- '@react-native-async-storage/async-storage',
43
- 'react-native-safe-area-context',
44
- ]
45
- )
35
+ await syncDeps(projectRoot, context.root, [
36
+ `@storybook/react-native`,
37
+ '@storybook/addon-ondevice-actions',
38
+ '@storybook/addon-ondevice-backgrounds',
39
+ '@storybook/addon-ondevice-controls',
40
+ '@storybook/addon-ondevice-notes',
41
+ '@react-native-async-storage/async-storage',
42
+ 'react-native-safe-area-context',
43
+ ])
46
44
  );
47
45
 
48
46
  runCliStorybook(context.root, options);
@@ -1,8 +1,8 @@
1
- import { ExecutorContext, ProjectGraph } from '@nx/devkit';
1
+ import { ExecutorContext } from '@nx/devkit';
2
2
  import { ReactNativeSyncDepsOptions } from './schema';
3
3
  export interface ReactNativeSyncDepsOutput {
4
4
  success: boolean;
5
5
  }
6
6
  export default function syncDepsExecutor(options: ReactNativeSyncDepsOptions, context: ExecutorContext): AsyncGenerator<ReactNativeSyncDepsOutput>;
7
- export declare function syncDeps(projectName: string, projectRoot: string, workspaceRoot: string, projectGraph: ProjectGraph, include?: string[], exclude?: string[]): Promise<string[]>;
7
+ export declare function syncDeps(projectRoot: string, workspaceRoot: string, include?: string[], exclude?: string[]): Promise<string[]>;
8
8
  export declare function displayNewlyAddedDepsMessage(projectName: string, deps: string[]): void;
@@ -4,10 +4,9 @@ exports.displayNewlyAddedDepsMessage = exports.syncDeps = void 0;
4
4
  const path_1 = require("path");
5
5
  const chalk = require("chalk");
6
6
  const devkit_1 = require("@nx/devkit");
7
- const find_all_npm_dependencies_1 = require("../../utils/find-all-npm-dependencies");
8
7
  async function* syncDepsExecutor(options, context) {
9
8
  const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
10
- displayNewlyAddedDepsMessage(context.projectName, await syncDeps(context.projectName, projectRoot, context.root, context.projectGraph, typeof options.include === 'string'
9
+ displayNewlyAddedDepsMessage(context.projectName, await syncDeps(projectRoot, context.root, typeof options.include === 'string'
11
10
  ? options.include.split(',')
12
11
  : options.include, typeof options.exclude === 'string'
13
12
  ? options.exclude.split(',')
@@ -15,8 +14,11 @@ async function* syncDepsExecutor(options, context) {
15
14
  yield { success: true };
16
15
  }
17
16
  exports.default = syncDepsExecutor;
18
- async function syncDeps(projectName, projectRoot, workspaceRoot, projectGraph, include = [], exclude = []) {
19
- let npmDeps = (0, find_all_npm_dependencies_1.findAllNpmDependencies)(projectGraph, projectName);
17
+ async function syncDeps(projectRoot, workspaceRoot, include = [], exclude = []) {
18
+ const workspacePackageJsonPath = (0, path_1.join)(workspaceRoot, 'package.json');
19
+ const workspacePackageJson = (0, devkit_1.readJsonFile)(workspacePackageJsonPath);
20
+ let npmDeps = Object.keys(workspacePackageJson.dependencies || {});
21
+ let npmDevdeps = Object.keys(workspacePackageJson.devDependencies || {});
20
22
  const packageJsonPath = (0, path_1.join)(workspaceRoot, projectRoot, 'package.json');
21
23
  const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
22
24
  const newDeps = [];
@@ -31,13 +33,26 @@ async function syncDeps(projectName, projectRoot, workspaceRoot, projectGraph, i
31
33
  if (exclude && exclude.length) {
32
34
  npmDeps = npmDeps.filter((dep) => !exclude.includes(dep));
33
35
  }
36
+ if (!packageJson.devDependencies) {
37
+ packageJson.devDependencies = {};
38
+ }
39
+ if (!packageJson.dependencies) {
40
+ packageJson.dependencies = {};
41
+ }
34
42
  npmDeps.forEach((dep) => {
35
- if (!packageJson.dependencies[dep]) {
43
+ if (!packageJson.dependencies[dep] && !packageJson.devDependencies[dep]) {
36
44
  packageJson.dependencies[dep] = '*';
37
45
  newDeps.push(dep);
38
46
  updated = true;
39
47
  }
40
48
  });
49
+ npmDevdeps.forEach((dep) => {
50
+ if (!packageJson.dependencies[dep] && !packageJson.devDependencies[dep]) {
51
+ packageJson.devDependencies[dep] = '*';
52
+ newDeps.push(dep);
53
+ updated = true;
54
+ }
55
+ });
41
56
  if (updated) {
42
57
  (0, devkit_1.writeJsonFile)(packageJsonPath, packageJson);
43
58
  }
@@ -3,13 +3,10 @@ import * as chalk from 'chalk';
3
3
  import {
4
4
  ExecutorContext,
5
5
  logger,
6
- ProjectGraph,
7
6
  readJsonFile,
8
7
  writeJsonFile,
9
8
  } from '@nx/devkit';
10
9
 
11
- import { findAllNpmDependencies } from '../../utils/find-all-npm-dependencies';
12
-
13
10
  import { ReactNativeSyncDepsOptions } from './schema';
14
11
 
15
12
  export interface ReactNativeSyncDepsOutput {
@@ -25,10 +22,8 @@ export default async function* syncDepsExecutor(
25
22
  displayNewlyAddedDepsMessage(
26
23
  context.projectName,
27
24
  await syncDeps(
28
- context.projectName,
29
25
  projectRoot,
30
26
  context.root,
31
- context.projectGraph,
32
27
  typeof options.include === 'string'
33
28
  ? options.include.split(',')
34
29
  : options.include,
@@ -42,14 +37,16 @@ export default async function* syncDepsExecutor(
42
37
  }
43
38
 
44
39
  export async function syncDeps(
45
- projectName: string,
46
40
  projectRoot: string,
47
41
  workspaceRoot: string,
48
- projectGraph: ProjectGraph,
49
42
  include: string[] = [],
50
43
  exclude: string[] = []
51
44
  ): Promise<string[]> {
52
- let npmDeps = findAllNpmDependencies(projectGraph, projectName);
45
+ const workspacePackageJsonPath = join(workspaceRoot, 'package.json');
46
+ const workspacePackageJson = readJsonFile(workspacePackageJsonPath);
47
+ let npmDeps = Object.keys(workspacePackageJson.dependencies || {});
48
+ let npmDevdeps = Object.keys(workspacePackageJson.devDependencies || {});
49
+
53
50
  const packageJsonPath = join(workspaceRoot, projectRoot, 'package.json');
54
51
  const packageJson = readJsonFile(packageJsonPath);
55
52
  const newDeps = [];
@@ -67,13 +64,27 @@ export async function syncDeps(
67
64
  npmDeps = npmDeps.filter((dep) => !exclude.includes(dep));
68
65
  }
69
66
 
67
+ if (!packageJson.devDependencies) {
68
+ packageJson.devDependencies = {};
69
+ }
70
+ if (!packageJson.dependencies) {
71
+ packageJson.dependencies = {};
72
+ }
73
+
70
74
  npmDeps.forEach((dep) => {
71
- if (!packageJson.dependencies[dep]) {
75
+ if (!packageJson.dependencies[dep] && !packageJson.devDependencies[dep]) {
72
76
  packageJson.dependencies[dep] = '*';
73
77
  newDeps.push(dep);
74
78
  updated = true;
75
79
  }
76
80
  });
81
+ npmDevdeps.forEach((dep) => {
82
+ if (!packageJson.dependencies[dep] && !packageJson.devDependencies[dep]) {
83
+ packageJson.devDependencies[dep] = '*';
84
+ newDeps.push(dep);
85
+ updated = true;
86
+ }
87
+ });
77
88
 
78
89
  if (updated) {
79
90
  writeJsonFile(packageJsonPath, packageJson);
@@ -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
+ }
@@ -3,18 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.reactNativeApplicationGeneratorInternal = exports.reactNativeApplicationGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const js_1 = require("@nx/js");
6
- const symlink_task_1 = require("../../utils/symlink-task");
6
+ const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
7
7
  const add_linting_1 = require("../../utils/add-linting");
8
8
  const add_jest_1 = require("../../utils/add-jest");
9
9
  const chmod_android_gradle_files_1 = require("../../utils/chmod-android-gradle-files");
10
10
  const pod_install_task_1 = require("../../utils/pod-install-task");
11
+ const web_configuration_1 = require("../web-configuration/web-configuration");
11
12
  const normalize_options_1 = require("./lib/normalize-options");
12
13
  const init_1 = require("../init/init");
13
14
  const add_project_1 = require("./lib/add-project");
14
15
  const create_application_files_1 = require("./lib/create-application-files");
15
- const add_detox_1 = require("./lib/add-detox");
16
+ const add_e2e_1 = require("./lib/add-e2e");
16
17
  const ensure_dependencies_1 = require("../../utils/ensure-dependencies");
17
- const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
18
+ const sync_deps_impl_1 = require("../../executors/sync-deps/sync-deps.impl");
18
19
  async function reactNativeApplicationGenerator(host, schema) {
19
20
  return await reactNativeApplicationGeneratorInternal(host, {
20
21
  projectNameAndRootFormat: 'derived',
@@ -47,16 +48,29 @@ async function reactNativeApplicationGeneratorInternal(host, schema) {
47
48
  tasks.push(lintTask);
48
49
  const jestTask = await (0, add_jest_1.addJest)(host, options.unitTestRunner, options.projectName, options.appProjectRoot, options.js, options.skipPackageJson);
49
50
  tasks.push(jestTask);
50
- const detoxTask = await (0, add_detox_1.addDetox)(host, options);
51
- tasks.push(detoxTask);
52
- const symlinkTask = (0, symlink_task_1.runSymlink)(host.root, options.appProjectRoot);
53
- tasks.push(symlinkTask);
51
+ const webTask = await (0, web_configuration_1.webConfigurationGenerator)(host, {
52
+ ...options,
53
+ project: options.name,
54
+ skipFormat: true,
55
+ });
56
+ tasks.push(webTask);
57
+ const e2eTask = await (0, add_e2e_1.addE2e)(host, options);
58
+ tasks.push(e2eTask);
54
59
  const chmodTaskGradlewTask = (0, chmod_android_gradle_files_1.chmodAndroidGradlewFilesTask)((0, devkit_1.joinPathFragments)(host.root, options.androidProjectRoot));
55
60
  tasks.push(chmodTaskGradlewTask);
56
61
  const podInstallTask = (0, pod_install_task_1.runPodInstall)((0, devkit_1.joinPathFragments)(host.root, options.iosProjectRoot));
57
62
  if (options.install) {
63
+ await (0, sync_deps_impl_1.syncDeps)(options.appProjectRoot, host.root);
58
64
  tasks.push(podInstallTask);
59
65
  }
66
+ else {
67
+ devkit_1.output.log({
68
+ title: 'Skip `pod install`',
69
+ bodyLines: [
70
+ `run 'nx run ${options.name}:pod-install' to install native modules before running iOS app`,
71
+ ],
72
+ });
73
+ }
60
74
  if (!options.skipFormat) {
61
75
  await (0, devkit_1.formatFiles)(host);
62
76
  }
@@ -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,6 +105,8 @@ describe('app', () => {
88
105
  e2eTestRunner: 'none',
89
106
  install: false,
90
107
  projectNameAndRootFormat: 'as-provided',
108
+ unitTestRunner: 'jest',
109
+ bundler: 'vite',
91
110
  });
92
111
  const targets = readProjectConfiguration(appTree, 'my-app').targets;
93
112
  expect(targets.test).toBeDefined();
@@ -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
+ };
@@ -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
+ }