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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/.eslintrc.json +6 -1
  2. package/executors.json +5 -0
  3. package/generators.json +12 -11
  4. package/migrations.json +73 -1
  5. package/package.json +10 -15
  6. package/plugins/metro-resolver.js +4 -1
  7. package/plugins/plugin.d.ts +2 -0
  8. package/plugins/plugin.js +12 -1
  9. package/plugins/with-nx-metro.js +6 -2
  10. package/src/executors/build-android/build-android.impl.js +1 -5
  11. package/src/executors/build-android/build-android.impl.ts +1 -5
  12. package/src/executors/bundle/schema.d.ts +1 -1
  13. package/src/executors/ensure-symlink/ensure-symlink.impl.d.ts +4 -0
  14. package/src/executors/ensure-symlink/ensure-symlink.impl.js +4 -0
  15. package/src/executors/ensure-symlink/ensure-symlink.impl.ts +4 -0
  16. package/src/executors/run-android/run-android.impl.js +4 -16
  17. package/src/executors/run-android/run-android.impl.ts +8 -17
  18. package/src/executors/run-ios/run-ios.impl.js +4 -16
  19. package/src/executors/run-ios/run-ios.impl.ts +9 -18
  20. package/src/executors/start/schema.d.ts +1 -1
  21. package/src/executors/start/start.impl.js +11 -26
  22. package/src/executors/start/start.impl.ts +14 -28
  23. package/src/executors/storybook/storybook.impl.d.ts +4 -0
  24. package/src/executors/storybook/storybook.impl.js +8 -1
  25. package/src/executors/storybook/storybook.impl.ts +16 -5
  26. package/src/executors/sync-deps/sync-deps.impl.d.ts +3 -2
  27. package/src/executors/sync-deps/sync-deps.impl.js +28 -11
  28. package/src/executors/sync-deps/sync-deps.impl.ts +45 -19
  29. package/src/executors/upgrade/schema.d.ts +1 -0
  30. package/src/executors/upgrade/schema.json +11 -0
  31. package/src/executors/upgrade/upgrade.impl.d.ts +13 -0
  32. package/src/executors/upgrade/upgrade.impl.js +47 -0
  33. package/src/executors/upgrade/upgrade.impl.ts +64 -0
  34. package/src/generators/application/application.js +27 -8
  35. package/src/generators/application/application.spec.ts +29 -2
  36. package/src/generators/application/files/app/.babelrc.js.template +23 -0
  37. package/src/generators/application/files/app/android/app/build.gradle.template +12 -28
  38. package/src/generators/application/files/app/android/app/src/debug/AndroidManifest.xml.template +2 -6
  39. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainActivity.kt.template +22 -0
  40. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.kt.template +45 -0
  41. package/src/generators/application/files/app/android/build.gradle.template +7 -20
  42. package/src/generators/application/files/app/android/gradle/wrapper/gradle-wrapper.properties +2 -1
  43. package/src/generators/application/files/app/android/gradle.properties +0 -3
  44. package/src/generators/application/files/app/android/gradlew.template +12 -7
  45. package/src/generators/application/files/app/android/settings.gradle.template +2 -2
  46. package/src/generators/application/files/app/ios/Podfile.template +0 -7
  47. package/src/generators/application/files/app/ios/__className__/AppDelegate.mm.template +5 -0
  48. package/src/generators/application/files/app/ios/__className__/Info.plist.template +5 -8
  49. package/src/generators/application/files/app/ios/__className__.xcodeproj/project.pbxproj.template +11 -33
  50. package/src/generators/application/files/app/metro.config.js.template +0 -4
  51. package/src/generators/application/files/app/src/app/App.tsx.template +29 -2
  52. package/src/generators/application/lib/add-e2e.d.ts +3 -0
  53. package/src/generators/application/lib/add-e2e.js +47 -0
  54. package/src/generators/application/lib/add-project.js +13 -17
  55. package/src/generators/application/lib/normalize-options.d.ts +4 -0
  56. package/src/generators/application/lib/normalize-options.js +9 -3
  57. package/src/generators/application/lib/normalize-options.spec.ts +53 -5
  58. package/src/generators/application/schema.d.ts +5 -3
  59. package/src/generators/application/schema.json +13 -5
  60. package/src/generators/component-story/component-story.d.ts +5 -8
  61. package/src/generators/component-story/component-story.js +8 -69
  62. package/src/generators/component-story/schema.d.ts +1 -0
  63. package/src/generators/component-story/schema.json +10 -2
  64. package/src/generators/init/init.d.ts +1 -0
  65. package/src/generators/init/init.js +14 -7
  66. package/src/generators/init/init.spec.ts +6 -2
  67. package/src/generators/init/schema.d.ts +1 -0
  68. package/src/generators/library/files/lib/.babelrc.js.template +21 -0
  69. package/src/generators/library/lib/normalize-options.js +1 -0
  70. package/src/generators/library/library.js +2 -1
  71. package/src/generators/library/library.spec.ts +12 -41
  72. package/src/generators/library/schema.d.ts +1 -0
  73. package/src/generators/library/schema.json +1 -1
  74. package/src/generators/stories/schema.d.ts +2 -0
  75. package/src/generators/stories/schema.json +14 -1
  76. package/src/generators/stories/stories.d.ts +5 -2
  77. package/src/generators/stories/stories.js +7 -50
  78. package/src/generators/storybook-configuration/configuration.d.ts +7 -2
  79. package/src/generators/storybook-configuration/configuration.js +15 -48
  80. package/src/generators/storybook-configuration/schema.d.ts +4 -2
  81. package/src/generators/storybook-configuration/schema.json +21 -11
  82. package/src/generators/upgrade-native/lib/normalize-options.d.ts +1 -1
  83. package/src/generators/upgrade-native/schema.d.ts +1 -1
  84. package/src/generators/upgrade-native/schema.json +2 -2
  85. package/src/generators/upgrade-native/upgrade-native.d.ts +2 -0
  86. package/src/generators/upgrade-native/upgrade-native.js +3 -0
  87. package/src/generators/web-configuration/files/base-vite/.babelrc.js.template +23 -0
  88. package/src/generators/web-configuration/files/base-vite/index.html__tmpl__ +15 -0
  89. package/src/generators/web-configuration/files/base-vite/public/favicon.ico +0 -0
  90. package/src/generators/web-configuration/files/base-vite/src/assets/.gitkeep +0 -0
  91. package/src/generators/web-configuration/files/base-vite/src/main-web.tsx__tmpl__ +9 -0
  92. package/src/generators/web-configuration/files/base-vite/vite.config.ts__tmpl__ +82 -0
  93. package/src/generators/web-configuration/files/base-webpack/.babelrc.js.template +23 -0
  94. package/src/generators/web-configuration/files/base-webpack/src/assets/.gitkeep +0 -0
  95. package/src/generators/web-configuration/files/base-webpack/src/favicon.ico +0 -0
  96. package/src/generators/web-configuration/files/base-webpack/src/index.html__tmpl__ +14 -0
  97. package/src/generators/web-configuration/files/base-webpack/src/main-web.tsx__tmpl__ +9 -0
  98. package/src/generators/web-configuration/files/base-webpack/webpack.config.js__tmpl__ +77 -0
  99. package/src/generators/web-configuration/lib/normalize-schema.d.ts +17 -0
  100. package/src/generators/web-configuration/lib/normalize-schema.js +16 -0
  101. package/src/generators/web-configuration/lib/webpack-targets.d.ts +7 -0
  102. package/src/generators/web-configuration/lib/webpack-targets.js +75 -0
  103. package/src/generators/web-configuration/schema.d.ts +6 -0
  104. package/src/generators/web-configuration/schema.json +42 -0
  105. package/src/generators/web-configuration/web-configuration.d.ts +12 -0
  106. package/src/generators/web-configuration/web-configuration.js +85 -0
  107. package/src/migrations/update-16-6-0/update-metro-config.js +0 -4
  108. package/src/migrations/update-16-9-0/remove-types-react-native.js +2 -9
  109. package/src/migrations/update-18-0-0/add-upgrade-target.d.ts +6 -0
  110. package/src/migrations/update-18-0-0/add-upgrade-target.js +33 -0
  111. package/src/migrations/update-18-0-0/add-web-configuration.d.ts +8 -0
  112. package/src/migrations/update-18-0-0/add-web-configuration.js +33 -0
  113. package/src/migrations/update-18-0-0/add-web-configuration.spec.ts +39 -0
  114. package/src/migrations/update-18-0-0/change-storybook-targets.d.ts +5 -0
  115. package/src/migrations/update-18-0-0/change-storybook-targets.js +57 -0
  116. package/src/migrations/update-18-0-0/remove-block-list.d.ts +6 -0
  117. package/src/migrations/update-18-0-0/remove-block-list.js +26 -0
  118. package/src/migrations/update-18-0-0/remove-block-list.spec.ts +68 -0
  119. package/src/migrations/update-18-0-0/remove-metro.d.ts +14 -0
  120. package/src/migrations/update-18-0-0/remove-metro.js +29 -0
  121. package/src/migrations/update-18-0-0/remove-symlink-target.d.ts +6 -0
  122. package/src/migrations/update-18-0-0/remove-symlink-target.js +30 -0
  123. package/src/migrations/update-18-0-0/remove-symlink-target.spec.ts +40 -0
  124. package/src/utils/add-jest.d.ts +1 -1
  125. package/src/utils/add-jest.js +13 -1
  126. package/src/utils/add-linting.d.ts +1 -0
  127. package/src/utils/add-linting.js +1 -0
  128. package/src/utils/add-linting.spec.ts +2 -4
  129. package/src/utils/ensure-dependencies.js +2 -6
  130. package/src/utils/testing-generators.js +1 -0
  131. package/src/utils/versions.d.ts +9 -12
  132. package/src/utils/versions.js +10 -13
  133. package/src/generators/application/files/app/android/app/src/debug/java/com/__lowerCaseName__/ReactNativeFlipper.java.template +0 -75
  134. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainActivity.java.template +0 -32
  135. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.java.template +0 -62
  136. package/src/generators/application/files/app/android/app/src/release/java/com/__lowerCaseName__/ReactNativeFlipper.java.template +0 -20
  137. package/src/generators/application/files/app/babel.config.json.template +0 -10
  138. package/src/generators/application/lib/add-detox.d.ts +0 -3
  139. package/src/generators/application/lib/add-detox.js +0 -23
  140. package/src/generators/component-story/component-story.spec.ts +0 -427
  141. package/src/generators/component-story/files/__componentFileName__.stories.__fileExt__ +0 -32
  142. package/src/generators/library/files/lib/babel.config.json.template +0 -19
  143. package/src/generators/stories/stories-app.spec.ts +0 -128
  144. package/src/generators/stories/stories-lib.spec.ts +0 -105
  145. package/src/generators/storybook-configuration/configuration.spec.ts +0 -135
  146. package/src/generators/storybook-configuration/files/app/storybook.ts.template +0 -9
  147. package/src/generators/storybook-configuration/files/app/toggle-storybook.tsx.template +0 -74
  148. package/src/generators/storybook-configuration/files/root/story-loader.ts.template +0 -5
  149. package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.d.ts +0 -6
  150. package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.js +0 -25
  151. package/src/generators/storybook-configuration/lib/add-resolver-main-fields-to-metro-config.spec.ts +0 -161
  152. package/src/generators/storybook-configuration/lib/create-storybook-files.d.ts +0 -6
  153. package/src/generators/storybook-configuration/lib/create-storybook-files.js +0 -42
  154. package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.d.ts +0 -7
  155. package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.js +0 -29
  156. package/src/generators/storybook-configuration/lib/replace-app-import-with-storybook-toggle.spec.ts +0 -65
  157. package/src/utils/find-all-npm-dependencies.d.ts +0 -2
  158. package/src/utils/find-all-npm-dependencies.js +0 -25
  159. package/src/utils/find-all-npm-dependencies.spec.ts +0 -95
  160. package/src/utils/symlink-task.d.ts +0 -2
  161. package/src/utils/symlink-task.js +0 -18
@@ -16,27 +16,12 @@ export default async function* startExecutor(
16
16
  const projectRoot =
17
17
  context.projectsConfigurations.projects[context.projectName].root;
18
18
 
19
- const startProcess = await runCliStart(context.root, projectRoot, options);
19
+ await runCliStart(context.root, projectRoot, options);
20
20
 
21
21
  yield {
22
22
  port: options.port,
23
23
  success: true,
24
24
  };
25
-
26
- if (!startProcess) {
27
- return;
28
- }
29
- await new Promise<void>((resolve) => {
30
- const processExitListener = (signal?: number | NodeJS.Signals) => () => {
31
- startProcess.kill(signal);
32
- resolve();
33
- process.exit();
34
- };
35
- process.once('exit', (signal) => startProcess.kill(signal));
36
- process.once('SIGTERM', processExitListener);
37
- process.once('SIGINT', processExitListener);
38
- process.once('SIGQUIT', processExitListener);
39
- });
40
25
  }
41
26
 
42
27
  /*
@@ -61,7 +46,9 @@ export async function runCliStart(
61
46
  return await startAsync(workspaceRoot, projectRoot, options);
62
47
  } catch (error) {
63
48
  logger.error(
64
- `Failed to start the packager server. Error details: ${error.message}`
49
+ `Failed to start the packager server. Error details: ${
50
+ error.message ?? error
51
+ }`
65
52
  );
66
53
  throw error;
67
54
  }
@@ -80,20 +67,10 @@ function startAsync(
80
67
  {
81
68
  cwd: pathResolve(workspaceRoot, projectRoot),
82
69
  env: process.env,
83
- stdio: ['inherit', 'pipe', 'pipe', 'ipc'],
70
+ stdio: 'inherit',
84
71
  }
85
72
  );
86
73
 
87
- childProcess.stdout.on('data', (data) => {
88
- process.stdout.write(data);
89
- if (data.toString().includes('reload the app')) {
90
- resolve(childProcess);
91
- }
92
- });
93
- childProcess.stderr.on('data', (data) => {
94
- process.stderr.write(data);
95
- });
96
-
97
74
  childProcess.on('error', (err) => {
98
75
  reject(err);
99
76
  });
@@ -104,6 +81,15 @@ function startAsync(
104
81
  reject(code);
105
82
  }
106
83
  });
84
+
85
+ const processExitListener = (signal?: number | NodeJS.Signals) => () => {
86
+ childProcess.kill(signal);
87
+ process.exit();
88
+ };
89
+ process.once('exit', (signal) => childProcess.kill(signal));
90
+ process.once('SIGTERM', processExitListener);
91
+ process.once('SIGINT', processExitListener);
92
+ process.once('SIGQUIT', processExitListener);
107
93
  });
108
94
  }
109
95
 
@@ -1,5 +1,9 @@
1
1
  import { ExecutorContext } from '@nx/devkit';
2
2
  import { ReactNativeStorybookOptions } from './schema';
3
+ /**
4
+ * TODO (@xiongemi): remove this function in v19.
5
+ * @deprecated Going to use the default react storybook target. Use @nx/react:storybook executor instead.
6
+ */
3
7
  export default function reactNativeStorybookExecutor(options: ReactNativeStorybookOptions, context: ExecutorContext): AsyncGenerator<{
4
8
  success: boolean;
5
9
  }>;
@@ -8,13 +8,20 @@ const chalk = require("chalk");
8
8
  const glob_1 = require("glob");
9
9
  const sync_deps_impl_1 = require("../sync-deps/sync-deps.impl");
10
10
  const fs_extra_1 = require("fs-extra");
11
+ /**
12
+ * TODO (@xiongemi): remove this function in v19.
13
+ * @deprecated Going to use the default react storybook target. Use @nx/react:storybook executor instead.
14
+ */
11
15
  async function* reactNativeStorybookExecutor(options, context) {
12
16
  const projectRoot = context.projectsConfigurations.projects[context.projectName].root;
13
17
  devkit_1.logger.info(`${chalk.bold.cyan('info')} To see your Storybook stories on the device, you should start your mobile app for the <platform> of your choice (typically ios or android).`);
14
18
  // add storybook addons to app's package.json
15
19
  const packageJsonPath = (0, path_1.join)(context.root, projectRoot, 'package.json');
20
+ const workspacePackageJsonPath = (0, path_1.join)(context.root, 'package.json');
21
+ const workspacePackageJson = (0, devkit_1.readJsonFile)(workspacePackageJsonPath);
22
+ const projectPackageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
16
23
  if ((0, fileutils_1.fileExists)(packageJsonPath))
17
- (0, sync_deps_impl_1.displayNewlyAddedDepsMessage)(context.projectName, await (0, sync_deps_impl_1.syncDeps)(context.projectName, projectRoot, context.root, context.projectGraph, [
24
+ (0, sync_deps_impl_1.displayNewlyAddedDepsMessage)(context.projectName, await (0, sync_deps_impl_1.syncDeps)(projectPackageJson, packageJsonPath, workspacePackageJson, [
18
25
  `@storybook/react-native`,
19
26
  '@storybook/addon-ondevice-actions',
20
27
  '@storybook/addon-ondevice-backgrounds',
@@ -1,5 +1,5 @@
1
1
  import { join } from 'path';
2
- import { ExecutorContext, logger } from '@nx/devkit';
2
+ import { ExecutorContext, logger, readJsonFile } from '@nx/devkit';
3
3
  import { fileExists } from '@nx/workspace/src/utilities/fileutils';
4
4
  import * as chalk from 'chalk';
5
5
  import { sync as globSync } from 'glob';
@@ -10,7 +10,12 @@ import {
10
10
  syncDeps,
11
11
  } from '../sync-deps/sync-deps.impl';
12
12
  import { writeFileSync } from 'fs-extra';
13
+ import { PackageJson } from 'nx/src/utils/package-json';
13
14
 
15
+ /**
16
+ * TODO (@xiongemi): remove this function in v19.
17
+ * @deprecated Going to use the default react storybook target. Use @nx/react:storybook executor instead.
18
+ */
14
19
  export default async function* reactNativeStorybookExecutor(
15
20
  options: ReactNativeStorybookOptions,
16
21
  context: ExecutorContext
@@ -25,14 +30,20 @@ export default async function* reactNativeStorybookExecutor(
25
30
 
26
31
  // add storybook addons to app's package.json
27
32
  const packageJsonPath = join(context.root, projectRoot, 'package.json');
33
+ const workspacePackageJsonPath = join(context.root, 'package.json');
34
+
35
+ const workspacePackageJson = readJsonFile<PackageJson>(
36
+ workspacePackageJsonPath
37
+ );
38
+ const projectPackageJson = readJsonFile<PackageJson>(packageJsonPath);
39
+
28
40
  if (fileExists(packageJsonPath))
29
41
  displayNewlyAddedDepsMessage(
30
42
  context.projectName,
31
43
  await syncDeps(
32
- context.projectName,
33
- projectRoot,
34
- context.root,
35
- context.projectGraph,
44
+ projectPackageJson,
45
+ packageJsonPath,
46
+ workspacePackageJson,
36
47
  [
37
48
  `@storybook/react-native`,
38
49
  '@storybook/addon-ondevice-actions',
@@ -1,8 +1,9 @@
1
- import { ExecutorContext, ProjectGraph } from '@nx/devkit';
1
+ import { ExecutorContext } from '@nx/devkit';
2
2
  import { ReactNativeSyncDepsOptions } from './schema';
3
+ import { PackageJson } from 'nx/src/utils/package-json';
3
4
  export interface ReactNativeSyncDepsOutput {
4
5
  success: boolean;
5
6
  }
6
7
  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[]>;
8
+ export declare function syncDeps(projectPackageJson: PackageJson, projectPackageJsonPath: string, workspacePackageJson: PackageJson, include?: string[], exclude?: string[]): Promise<string[]>;
8
9
  export declare function displayNewlyAddedDepsMessage(projectName: string, deps: string[]): void;
@@ -4,10 +4,13 @@ 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
+ const workspacePackageJsonPath = (0, path_1.join)(context.root, 'package.json');
10
+ const projectPackageJsonPath = (0, path_1.join)(context.root, projectRoot, 'package.json');
11
+ const workspacePackageJson = (0, devkit_1.readJsonFile)(workspacePackageJsonPath);
12
+ const projectPackageJson = (0, devkit_1.readJsonFile)(projectPackageJsonPath);
13
+ displayNewlyAddedDepsMessage(context.projectName, await syncDeps(projectPackageJson, projectPackageJsonPath, workspacePackageJson, typeof options.include === 'string'
11
14
  ? options.include.split(',')
12
15
  : options.include, typeof options.exclude === 'string'
13
16
  ? options.exclude.split(',')
@@ -15,14 +18,13 @@ async function* syncDepsExecutor(options, context) {
15
18
  yield { success: true };
16
19
  }
17
20
  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);
20
- const packageJsonPath = (0, path_1.join)(workspaceRoot, projectRoot, 'package.json');
21
- const packageJson = (0, devkit_1.readJsonFile)(packageJsonPath);
21
+ async function syncDeps(projectPackageJson, projectPackageJsonPath, workspacePackageJson, include = [], exclude = []) {
22
+ let npmDeps = Object.keys(workspacePackageJson.dependencies || {});
23
+ let npmDevdeps = Object.keys(workspacePackageJson.devDependencies || {});
22
24
  const newDeps = [];
23
25
  let updated = false;
24
- if (!packageJson.dependencies) {
25
- packageJson.dependencies = {};
26
+ if (!projectPackageJson.dependencies) {
27
+ projectPackageJson.dependencies = {};
26
28
  updated = true;
27
29
  }
28
30
  if (include && include.length) {
@@ -31,15 +33,30 @@ 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 (!projectPackageJson.devDependencies) {
37
+ projectPackageJson.devDependencies = {};
38
+ }
39
+ if (!projectPackageJson.dependencies) {
40
+ projectPackageJson.dependencies = {};
41
+ }
34
42
  npmDeps.forEach((dep) => {
35
- if (!packageJson.dependencies[dep]) {
36
- packageJson.dependencies[dep] = '*';
43
+ if (!projectPackageJson.dependencies[dep] &&
44
+ !projectPackageJson.devDependencies[dep]) {
45
+ projectPackageJson.dependencies[dep] = '*';
46
+ newDeps.push(dep);
47
+ updated = true;
48
+ }
49
+ });
50
+ npmDevdeps.forEach((dep) => {
51
+ if (!projectPackageJson.dependencies[dep] &&
52
+ !projectPackageJson.devDependencies[dep]) {
53
+ projectPackageJson.devDependencies[dep] = '*';
37
54
  newDeps.push(dep);
38
55
  updated = true;
39
56
  }
40
57
  });
41
58
  if (updated) {
42
- (0, devkit_1.writeJsonFile)(packageJsonPath, packageJson);
59
+ (0, devkit_1.writeJsonFile)(projectPackageJsonPath, projectPackageJson);
43
60
  }
44
61
  return newDeps;
45
62
  }
@@ -3,14 +3,12 @@ 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';
11
+ import { PackageJson } from 'nx/src/utils/package-json';
14
12
 
15
13
  export interface ReactNativeSyncDepsOutput {
16
14
  success: boolean;
@@ -22,13 +20,22 @@ export default async function* syncDepsExecutor(
22
20
  ): AsyncGenerator<ReactNativeSyncDepsOutput> {
23
21
  const projectRoot =
24
22
  context.projectsConfigurations.projects[context.projectName].root;
23
+
24
+ const workspacePackageJsonPath = join(context.root, 'package.json');
25
+ const projectPackageJsonPath = join(
26
+ context.root,
27
+ projectRoot,
28
+ 'package.json'
29
+ );
30
+
31
+ const workspacePackageJson = readJsonFile(workspacePackageJsonPath);
32
+ const projectPackageJson = readJsonFile(projectPackageJsonPath);
25
33
  displayNewlyAddedDepsMessage(
26
34
  context.projectName,
27
35
  await syncDeps(
28
- context.projectName,
29
- projectRoot,
30
- context.root,
31
- context.projectGraph,
36
+ projectPackageJson,
37
+ projectPackageJsonPath,
38
+ workspacePackageJson,
32
39
  typeof options.include === 'string'
33
40
  ? options.include.split(',')
34
41
  : options.include,
@@ -42,21 +49,20 @@ export default async function* syncDepsExecutor(
42
49
  }
43
50
 
44
51
  export async function syncDeps(
45
- projectName: string,
46
- projectRoot: string,
47
- workspaceRoot: string,
48
- projectGraph: ProjectGraph,
52
+ projectPackageJson: PackageJson,
53
+ projectPackageJsonPath: string,
54
+ workspacePackageJson: PackageJson,
49
55
  include: string[] = [],
50
56
  exclude: string[] = []
51
57
  ): Promise<string[]> {
52
- let npmDeps = findAllNpmDependencies(projectGraph, projectName);
53
- const packageJsonPath = join(workspaceRoot, projectRoot, 'package.json');
54
- const packageJson = readJsonFile(packageJsonPath);
58
+ let npmDeps = Object.keys(workspacePackageJson.dependencies || {});
59
+ let npmDevdeps = Object.keys(workspacePackageJson.devDependencies || {});
60
+
55
61
  const newDeps = [];
56
62
  let updated = false;
57
63
 
58
- if (!packageJson.dependencies) {
59
- packageJson.dependencies = {};
64
+ if (!projectPackageJson.dependencies) {
65
+ projectPackageJson.dependencies = {};
60
66
  updated = true;
61
67
  }
62
68
 
@@ -67,16 +73,36 @@ export async function syncDeps(
67
73
  npmDeps = npmDeps.filter((dep) => !exclude.includes(dep));
68
74
  }
69
75
 
76
+ if (!projectPackageJson.devDependencies) {
77
+ projectPackageJson.devDependencies = {};
78
+ }
79
+ if (!projectPackageJson.dependencies) {
80
+ projectPackageJson.dependencies = {};
81
+ }
82
+
70
83
  npmDeps.forEach((dep) => {
71
- if (!packageJson.dependencies[dep]) {
72
- packageJson.dependencies[dep] = '*';
84
+ if (
85
+ !projectPackageJson.dependencies[dep] &&
86
+ !projectPackageJson.devDependencies[dep]
87
+ ) {
88
+ projectPackageJson.dependencies[dep] = '*';
89
+ newDeps.push(dep);
90
+ updated = true;
91
+ }
92
+ });
93
+ npmDevdeps.forEach((dep) => {
94
+ if (
95
+ !projectPackageJson.dependencies[dep] &&
96
+ !projectPackageJson.devDependencies[dep]
97
+ ) {
98
+ projectPackageJson.devDependencies[dep] = '*';
73
99
  newDeps.push(dep);
74
100
  updated = true;
75
101
  }
76
102
  });
77
103
 
78
104
  if (updated) {
79
- writeJsonFile(packageJsonPath, packageJson);
105
+ writeJsonFile(projectPackageJsonPath, projectPackageJson);
80
106
  }
81
107
 
82
108
  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
+ }
@@ -3,20 +3,22 @@ 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, {
21
+ addPlugin: false,
20
22
  projectNameAndRootFormat: 'derived',
21
23
  ...schema,
22
24
  });
@@ -45,18 +47,35 @@ async function reactNativeApplicationGeneratorInternal(host, schema) {
45
47
  ],
46
48
  });
47
49
  tasks.push(lintTask);
48
- const jestTask = await (0, add_jest_1.addJest)(host, options.unitTestRunner, options.projectName, options.appProjectRoot, options.js, options.skipPackageJson);
50
+ const jestTask = await (0, add_jest_1.addJest)(host, options.unitTestRunner, options.projectName, options.appProjectRoot, options.js, options.skipPackageJson, options.addPlugin);
49
51
  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);
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);
54
60
  const chmodTaskGradlewTask = (0, chmod_android_gradle_files_1.chmodAndroidGradlewFilesTask)((0, devkit_1.joinPathFragments)(host.root, options.androidProjectRoot));
55
61
  tasks.push(chmodTaskGradlewTask);
56
62
  const podInstallTask = (0, pod_install_task_1.runPodInstall)((0, devkit_1.joinPathFragments)(host.root, options.iosProjectRoot));
57
63
  if (options.install) {
64
+ const workspacePackageJsonPath = (0, devkit_1.joinPathFragments)('package.json');
65
+ const projectPackageJsonPath = (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json');
66
+ const workspacePackageJson = (0, devkit_1.readJson)(host, workspacePackageJsonPath);
67
+ const projectPackageJson = (0, devkit_1.readJson)(host, projectPackageJsonPath);
68
+ await (0, sync_deps_impl_1.syncDeps)(projectPackageJson, projectPackageJsonPath, workspacePackageJson);
58
69
  tasks.push(podInstallTask);
59
70
  }
71
+ else {
72
+ devkit_1.output.log({
73
+ title: 'Skip `pod install`',
74
+ bodyLines: [
75
+ `run 'nx run ${options.name}:pod-install' to install native modules before running iOS app`,
76
+ ],
77
+ });
78
+ }
60
79
  if (!options.skipFormat) {
61
80
  await (0, devkit_1.formatFiles)(host);
62
81
  }
@@ -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);