@nx/react-native 17.0.3 → 17.0.5

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
@@ -1,79 +1,78 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateDependencies = exports.reactNativeInitGenerator = void 0;
3
+ exports.updateDependencies = exports.reactNativeInitGeneratorInternal = exports.reactNativeInitGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
- const jest_1 = require("@nx/jest");
6
- const detox_1 = require("@nx/detox");
7
- const versions_1 = require("@nx/react/src/utils/versions");
8
- const js_1 = require("@nx/js");
9
- const versions_2 = require("../../utils/versions");
5
+ const update_package_scripts_1 = require("@nx/devkit/src/utils/update-package-scripts");
6
+ const plugin_1 = require("../../../plugins/plugin");
7
+ const versions_1 = require("../../utils/versions");
10
8
  const add_git_ignore_entry_1 = require("./lib/add-git-ignore-entry");
11
- async function reactNativeInitGenerator(host, schema) {
9
+ function reactNativeInitGenerator(host, schema) {
10
+ return reactNativeInitGeneratorInternal(host, {
11
+ addPlugin: false,
12
+ ...schema,
13
+ });
14
+ }
15
+ exports.reactNativeInitGenerator = reactNativeInitGenerator;
16
+ async function reactNativeInitGeneratorInternal(host, schema) {
12
17
  (0, add_git_ignore_entry_1.addGitIgnoreEntry)(host);
18
+ const nxJson = (0, devkit_1.readNxJson)(host);
19
+ const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
20
+ nxJson.useInferencePlugins !== false;
21
+ schema.addPlugin ??= addPluginDefault;
22
+ if (schema.addPlugin) {
23
+ addPlugin(host);
24
+ }
13
25
  const tasks = [];
14
- tasks.push(await (0, js_1.initGenerator)(host, {
15
- ...schema,
16
- skipFormat: true,
17
- }));
18
26
  if (!schema.skipPackageJson) {
19
- const installTask = updateDependencies(host);
20
27
  tasks.push(moveDependency(host));
21
- tasks.push(installTask);
28
+ tasks.push(updateDependencies(host, schema));
22
29
  }
23
- if (!schema.unitTestRunner || schema.unitTestRunner === 'jest') {
24
- const jestTask = await (0, jest_1.jestInitGenerator)(host, schema);
25
- tasks.push(jestTask);
26
- }
27
- if (!schema.e2eTestRunner || schema.e2eTestRunner === 'detox') {
28
- const detoxTask = await (0, detox_1.detoxInitGenerator)(host, {
29
- ...schema,
30
- skipFormat: true,
31
- });
32
- tasks.push(detoxTask);
30
+ if (schema.updatePackageScripts) {
31
+ await (0, update_package_scripts_1.updatePackageScripts)(host, plugin_1.createNodes);
33
32
  }
34
33
  if (!schema.skipFormat) {
35
34
  await (0, devkit_1.formatFiles)(host);
36
35
  }
37
36
  return (0, devkit_1.runTasksInSerial)(...tasks);
38
37
  }
39
- exports.reactNativeInitGenerator = reactNativeInitGenerator;
40
- function updateDependencies(host) {
41
- const isPnpm = (0, devkit_1.detectPackageManager)(host.root) === 'pnpm';
38
+ exports.reactNativeInitGeneratorInternal = reactNativeInitGeneratorInternal;
39
+ function updateDependencies(host, schema) {
42
40
  return (0, devkit_1.addDependenciesToPackageJson)(host, {
43
- react: versions_2.reactVersion,
44
- 'react-dom': versions_2.reactDomVersion,
45
- 'react-native': versions_2.reactNativeVersion,
41
+ react: versions_1.reactVersion,
42
+ 'react-dom': versions_1.reactDomVersion,
43
+ 'react-native': versions_1.reactNativeVersion,
46
44
  }, {
47
- '@nx/react-native': versions_2.nxVersion,
48
- '@types/node': versions_2.typesNodeVersion,
49
- '@types/react': versions_2.typesReactVersion,
50
- '@react-native/metro-config': versions_2.reactNativeMetroConfigVersion,
51
- '@react-native-community/cli': versions_2.reactNativeCommunityCli,
52
- '@react-native-community/cli-platform-android': versions_2.reactNativeCommunityCliAndroid,
53
- '@react-native-community/cli-platform-ios': versions_2.reactNativeCommunityCliIos,
54
- '@testing-library/react-native': versions_2.testingLibraryReactNativeVersion,
55
- '@testing-library/jest-native': versions_2.testingLibraryJestNativeVersion,
56
- 'jest-react-native': versions_2.jestReactNativeVersion,
57
- metro: versions_2.metroVersion,
58
- 'metro-config': versions_2.metroVersion,
59
- 'metro-resolver': versions_2.metroVersion,
60
- 'metro-babel-register': versions_2.metroVersion,
61
- 'metro-react-native-babel-preset': versions_2.metroVersion,
62
- 'metro-react-native-babel-transformer': versions_2.metroVersion,
63
- 'react-test-renderer': versions_2.reactTestRendererVersion,
64
- 'react-native-svg-transformer': versions_2.reactNativeSvgTransformerVersion,
65
- 'react-native-svg': versions_2.reactNativeSvgVersion,
66
- '@babel/preset-react': versions_1.babelPresetReactVersion,
67
- '@babel/core': versions_1.babelCoreVersion,
68
- ...(isPnpm
69
- ? {
70
- '@babel/runtime': versions_2.babelRuntimeVersion, // @babel/runtime is used by react-native-svg
71
- }
72
- : {}),
73
- });
45
+ '@nx/react-native': versions_1.nxVersion,
46
+ }, undefined, schema.keepExistingVersions);
74
47
  }
75
48
  exports.updateDependencies = updateDependencies;
76
49
  function moveDependency(host) {
77
50
  return (0, devkit_1.removeDependenciesFromPackageJson)(host, ['@nx/react-native'], []);
78
51
  }
52
+ function addPlugin(host) {
53
+ const nxJson = (0, devkit_1.readNxJson)(host);
54
+ nxJson.plugins ??= [];
55
+ for (const plugin of nxJson.plugins) {
56
+ if (typeof plugin === 'string'
57
+ ? plugin === '@nx/react-native/plugin'
58
+ : plugin.plugin === '@nx/react-native/plugin') {
59
+ return;
60
+ }
61
+ }
62
+ nxJson.plugins.push({
63
+ plugin: '@nx/react-native/plugin',
64
+ options: {
65
+ startTargetName: 'start',
66
+ podInstallTargetName: 'pod-install',
67
+ bundleTargetName: 'bundle',
68
+ runIosTargetName: 'run-ios',
69
+ runAndroidTargetName: 'run-android',
70
+ buildIosTargetName: 'build-ios',
71
+ buildAndroidTargetName: 'build-android',
72
+ syncDepsTargetName: 'sync-deps',
73
+ upgradeTargetname: 'upgrade',
74
+ },
75
+ });
76
+ (0, devkit_1.updateNxJson)(host, nxJson);
77
+ }
79
78
  exports.default = reactNativeInitGenerator;
@@ -1,5 +1,4 @@
1
- import { NxJsonConfiguration } from '@nx/devkit';
2
- import { Tree, readJson, updateJson } from '@nx/devkit';
1
+ import { Tree, readJson } from '@nx/devkit';
3
2
  import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
4
3
  import { reactNativeInitGenerator } from './init';
5
4
 
@@ -12,12 +11,12 @@ describe('init', () => {
12
11
  });
13
12
 
14
13
  it('should add react native dependencies', async () => {
15
- await reactNativeInitGenerator(tree, { e2eTestRunner: 'none' });
14
+ await reactNativeInitGenerator(tree, {
15
+ addPlugin: true,
16
+ });
16
17
  const packageJson = readJson(tree, 'package.json');
17
18
  expect(packageJson.dependencies['react']).toBeDefined();
18
19
  expect(packageJson.dependencies['react-native']).toBeDefined();
19
- expect(packageJson.devDependencies['@types/node']).toBeDefined();
20
- expect(packageJson.devDependencies['@types/react']).toBeDefined();
21
20
  });
22
21
 
23
22
  it('should add .gitignore entries for React native files and directories', async () => {
@@ -27,7 +26,9 @@ describe('init', () => {
27
26
  /node_modules
28
27
  `
29
28
  );
30
- await reactNativeInitGenerator(tree, { e2eTestRunner: 'none' });
29
+ await reactNativeInitGenerator(tree, {
30
+ addPlugin: true,
31
+ });
31
32
 
32
33
  const content = tree.read('/.gitignore').toString();
33
34
 
@@ -1,7 +1,7 @@
1
1
  export interface Schema {
2
- unitTestRunner?: 'jest' | 'none';
3
2
  skipFormat?: boolean;
4
- e2eTestRunner?: 'detox' | 'none';
5
3
  skipPackageJson?: boolean; //default is false
6
- js?: boolean;
4
+ keepExistingVersions?: boolean; //default is false
5
+ updatePackageScripts?: boolean;
6
+ addPlugin?: boolean;
7
7
  }
@@ -1,39 +1,34 @@
1
1
  {
2
2
  "cli": "nx",
3
3
  "$id": "NxReactNativeInit",
4
- "$schema": "http://json-schema.org/schema",
4
+ "$schema": "https://json-schema.org/schema",
5
5
  "title": "Add Nx React Native Schematics",
6
6
  "description": "Add Nx React native schematics.",
7
7
  "type": "object",
8
8
  "properties": {
9
- "unitTestRunner": {
10
- "description": "Adds the specified unit test runner.",
11
- "type": "string",
12
- "enum": ["jest", "none"],
13
- "default": "jest"
14
- },
15
9
  "skipFormat": {
16
10
  "description": "Skip formatting files.",
17
11
  "type": "boolean",
18
12
  "default": false,
19
13
  "x-priority": "internal"
20
14
  },
21
- "e2eTestRunner": {
22
- "description": "Adds the specified E2E test runner.",
23
- "type": "string",
24
- "enum": ["detox", "none"],
25
- "default": "detox"
26
- },
27
- "js": {
28
- "type": "boolean",
29
- "default": false,
30
- "description": "Use JavaScript instead of TypeScript"
31
- },
32
15
  "skipPackageJson": {
33
16
  "description": "Do not add dependencies to `package.json`.",
34
17
  "type": "boolean",
35
18
  "default": false,
36
19
  "x-priority": "internal"
20
+ },
21
+ "keepExistingVersions": {
22
+ "type": "boolean",
23
+ "x-priority": "internal",
24
+ "description": "Keep existing dependencies versions",
25
+ "default": false
26
+ },
27
+ "updatePackageScripts": {
28
+ "type": "boolean",
29
+ "x-priority": "internal",
30
+ "description": "Update `package.json` scripts with inferred targets",
31
+ "default": false
37
32
  }
38
33
  },
39
34
  "required": []
@@ -0,0 +1,21 @@
1
+ module.exports = function (api) {
2
+ api.cache(true);
3
+
4
+ return {
5
+ presets: [
6
+ [
7
+ '@nx/react/babel',
8
+ {
9
+ runtime: 'automatic',
10
+ useBuiltIns: 'usage',
11
+ },
12
+ ],
13
+ ],
14
+ plugins: [],
15
+ env: {
16
+ test: {
17
+ presets: [['module:@react-native/babel-preset', { "useTransformReactJSX": true }]],
18
+ },
19
+ },
20
+ };
21
+ };
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = void 0;
4
+ const devkit_1 = require("@nx/devkit");
4
5
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
5
6
  async function normalizeOptions(host, options) {
6
7
  const { projectName, names: projectNames, projectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
@@ -11,6 +12,10 @@ async function normalizeOptions(host, options) {
11
12
  projectNameAndRootFormat: options.projectNameAndRootFormat,
12
13
  callingGenerator: '@nx/react-native:library',
13
14
  });
15
+ const nxJson = (0, devkit_1.readNxJson)(host);
16
+ const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
17
+ nxJson.useInferencePlugins !== false;
18
+ options.addPlugin ??= addPluginDefault;
14
19
  const parsedTags = options.tags
15
20
  ? options.tags.split(',').map((s) => s.trim())
16
21
  : [];
@@ -8,8 +8,11 @@ const add_linting_1 = require("../../utils/add-linting");
8
8
  const add_jest_1 = require("../../utils/add-jest");
9
9
  const versions_1 = require("../../utils/versions");
10
10
  const normalize_options_1 = require("./lib/normalize-options");
11
+ const ensure_dependencies_1 = require("../../utils/ensure-dependencies");
12
+ const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
11
13
  async function reactNativeLibraryGenerator(host, schema) {
12
14
  return await reactNativeLibraryGeneratorInternal(host, {
15
+ addPlugin: false,
13
16
  projectNameAndRootFormat: 'derived',
14
17
  ...schema,
15
18
  });
@@ -21,12 +24,16 @@ async function reactNativeLibraryGeneratorInternal(host, schema) {
21
24
  throw new Error(`For publishable libs you have to provide a proper "--importPath" which needs to be a valid npm package name (e.g. my-awesome-lib or @myorg/my-lib)`);
22
25
  }
23
26
  const tasks = [];
24
- const initTask = await (0, init_1.default)(host, {
25
- ...options,
27
+ const jsInitTask = await (0, js_1.initGenerator)(host, {
28
+ ...schema,
26
29
  skipFormat: true,
27
- e2eTestRunner: 'none',
28
30
  });
31
+ tasks.push(jsInitTask);
32
+ const initTask = await (0, init_1.default)(host, { ...options, skipFormat: true });
29
33
  tasks.push(initTask);
34
+ if (!options.skipPackageJson) {
35
+ tasks.push((0, ensure_dependencies_1.ensureDependencies)(host));
36
+ }
30
37
  const addProjectTask = await addProject(host, options);
31
38
  if (addProjectTask) {
32
39
  tasks.push(addProjectTask);
@@ -40,7 +47,7 @@ async function reactNativeLibraryGeneratorInternal(host, schema) {
40
47
  ],
41
48
  });
42
49
  tasks.push(lintTask);
43
- const jestTask = await (0, add_jest_1.addJest)(host, options.unitTestRunner, options.name, options.projectRoot, options.js, options.skipPackageJson);
50
+ const jestTask = await (0, add_jest_1.addJest)(host, options.unitTestRunner, options.name, options.projectRoot, options.js, options.skipPackageJson, options.addPlugin);
44
51
  tasks.push(jestTask);
45
52
  if (options.publishable || options.buildable) {
46
53
  updateLibPackageNpmScope(host, options);
@@ -53,49 +60,52 @@ async function reactNativeLibraryGeneratorInternal(host, schema) {
53
60
  if (!options.skipFormat) {
54
61
  await (0, devkit_1.formatFiles)(host);
55
62
  }
63
+ tasks.push(() => {
64
+ (0, log_show_project_command_1.logShowProjectCommand)(options.name);
65
+ });
56
66
  return (0, devkit_1.runTasksInSerial)(...tasks);
57
67
  }
58
68
  exports.reactNativeLibraryGeneratorInternal = reactNativeLibraryGeneratorInternal;
59
69
  async function addProject(host, options) {
60
- const targets = {};
61
- let task;
62
- if (options.publishable || options.buildable) {
63
- const { rollupInitGenerator } = (0, devkit_1.ensurePackage)('@nx/rollup', versions_1.nxVersion);
64
- const external = [
65
- 'react/jsx-runtime',
66
- 'react-native',
67
- 'react',
68
- 'react-dom',
69
- ];
70
- targets.build = {
71
- executor: '@nx/rollup:rollup',
72
- outputs: ['{options.outputPath}'],
73
- options: {
74
- outputPath: `dist/${options.projectRoot}`,
75
- tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
76
- project: `${options.projectRoot}/package.json`,
77
- entryFile: maybeJs(options, `${options.projectRoot}/src/index.ts`),
78
- external,
79
- rollupConfig: `@nx/react/plugins/bundle-rollup`,
80
- assets: [
81
- {
82
- glob: `${options.projectRoot}/README.md`,
83
- input: '.',
84
- output: '.',
85
- },
86
- ],
87
- },
88
- };
89
- task = await rollupInitGenerator(host, { ...options, skipFormat: true });
90
- }
91
- (0, devkit_1.addProjectConfiguration)(host, options.name, {
70
+ const project = {
92
71
  root: options.projectRoot,
93
72
  sourceRoot: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src'),
94
73
  projectType: 'library',
95
74
  tags: options.parsedTags,
96
- targets,
75
+ targets: {},
76
+ };
77
+ (0, devkit_1.addProjectConfiguration)(host, options.name, project);
78
+ if (!options.publishable && !options.buildable) {
79
+ return () => { };
80
+ }
81
+ const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rollup', versions_1.nxVersion);
82
+ const rollupConfigTask = await configurationGenerator(host, {
83
+ ...options,
84
+ project: options.name,
85
+ skipFormat: true,
97
86
  });
98
- return task;
87
+ const external = ['react/jsx-runtime', 'react-native', 'react', 'react-dom'];
88
+ project.targets.build = {
89
+ executor: '@nx/rollup:rollup',
90
+ outputs: ['{options.outputPath}'],
91
+ options: {
92
+ outputPath: `dist/${options.projectRoot}`,
93
+ tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
94
+ project: `${options.projectRoot}/package.json`,
95
+ entryFile: maybeJs(options, `${options.projectRoot}/src/index.ts`),
96
+ external,
97
+ rollupConfig: `@nx/react/plugins/bundle-rollup`,
98
+ assets: [
99
+ {
100
+ glob: `${options.projectRoot}/README.md`,
101
+ input: '.',
102
+ output: '.',
103
+ },
104
+ ],
105
+ },
106
+ };
107
+ (0, devkit_1.updateProjectConfiguration)(host, options.name, project);
108
+ return rollupConfigTask;
99
109
  }
100
110
  function updateTsConfig(tree, options) {
101
111
  (0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.json'), (json) => {
@@ -20,6 +20,7 @@ describe('lib', () => {
20
20
  unitTestRunner: 'jest',
21
21
  strict: true,
22
22
  projectNameAndRootFormat: 'as-provided',
23
+ addPlugin: true,
23
24
  };
24
25
 
25
26
  beforeEach(() => {
@@ -28,21 +29,6 @@ describe('lib', () => {
28
29
  });
29
30
 
30
31
  describe('not nested', () => {
31
- it('should update project.json', async () => {
32
- await libraryGenerator(appTree, { ...defaultSchema, tags: 'one,two' });
33
- const projectConfiguration = readProjectConfiguration(appTree, 'my-lib');
34
- expect(projectConfiguration.root).toEqual('my-lib');
35
- expect(projectConfiguration.targets.build).toBeUndefined();
36
- expect(projectConfiguration.targets.lint).toEqual({
37
- executor: '@nx/eslint:lint',
38
- outputs: ['{options.outputFile}'],
39
- options: {
40
- lintFilePatterns: ['my-lib/**/*.{ts,tsx,js,jsx}'],
41
- },
42
- });
43
- expect(projectConfiguration.tags).toEqual(['one', 'two']);
44
- });
45
-
46
32
  it('should update root tsconfig.base.json', async () => {
47
33
  await libraryGenerator(appTree, defaultSchema);
48
34
  const tsconfigJson = readJson(appTree, '/tsconfig.base.json');
@@ -149,23 +135,6 @@ describe('lib', () => {
149
135
  });
150
136
  });
151
137
 
152
- it('should update project.json', async () => {
153
- await libraryGenerator(appTree, {
154
- ...defaultSchema,
155
- directory: 'my-dir',
156
- });
157
- const projectConfiguration = readProjectConfiguration(appTree, 'my-lib');
158
-
159
- expect(projectConfiguration.root).toEqual('my-dir');
160
- expect(projectConfiguration.targets.lint).toEqual({
161
- executor: '@nx/eslint:lint',
162
- outputs: ['{options.outputFile}'],
163
- options: {
164
- lintFilePatterns: ['my-dir/**/*.{ts,tsx,js,jsx}'],
165
- },
166
- });
167
- });
168
-
169
138
  it('should update root tsconfig.base.json', async () => {
170
139
  await libraryGenerator(appTree, {
171
140
  ...defaultSchema,
@@ -237,15 +206,6 @@ describe('lib', () => {
237
206
 
238
207
  expect(appTree.exists('my-lib/tsconfig.spec.json')).toBeFalsy();
239
208
  expect(appTree.exists('my-lib/jest.config.ts')).toBeFalsy();
240
- const projectConfiguration = readProjectConfiguration(appTree, 'my-lib');
241
- expect(projectConfiguration.targets.test).toBeUndefined();
242
- expect(projectConfiguration.targets.lint).toMatchObject({
243
- executor: '@nx/eslint:lint',
244
- options: {
245
- lintFilePatterns: ['my-lib/**/*.{ts,tsx,js,jsx}'],
246
- },
247
- outputs: ['{options.outputFile}'],
248
- });
249
209
  });
250
210
 
251
211
  it('should generate test configuration', async () => {
@@ -289,29 +249,21 @@ describe('lib', () => {
289
249
  moduleNameMapper: {
290
250
  '\\\\.svg$': '@nx/react-native/plugins/jest/svg-mock',
291
251
  },
252
+ transform: {
253
+ '^.+.(js|ts|tsx)$': [
254
+ 'babel-jest',
255
+ {
256
+ configFile: __dirname + '/.babelrc.js',
257
+ },
258
+ ],
259
+ '^.+.(bmp|gif|jpg|jpeg|mp4|png|psd|svg|webp)$': require.resolve(
260
+ 'react-native/jest/assetFileTransformer.js'
261
+ ),
262
+ },
292
263
  coverageDirectory: '../coverage/my-lib',
293
264
  };
294
265
  "
295
266
  `);
296
- const projectConfiguration = readProjectConfiguration(appTree, 'my-lib');
297
- expect(projectConfiguration.targets.test).toMatchInlineSnapshot(`
298
- {
299
- "configurations": {
300
- "ci": {
301
- "ci": true,
302
- "codeCoverage": true,
303
- },
304
- },
305
- "executor": "@nx/jest:jest",
306
- "options": {
307
- "jestConfig": "my-lib/jest.config.ts",
308
- "passWithNoTests": true,
309
- },
310
- "outputs": [
311
- "{workspaceRoot}/coverage/{projectRoot}",
312
- ],
313
- }
314
- `);
315
267
  });
316
268
  });
317
269
 
@@ -21,4 +21,5 @@ export interface Schema {
21
21
  strict?: boolean;
22
22
  setParserOptionsProject?: boolean;
23
23
  skipPackageJson?: boolean; //default is false
24
+ addPlugin?: boolean;
24
25
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "cli": "nx",
3
3
  "$id": "NxReactNativeLibrary",
4
- "$schema": "http://json-schema.org/schema",
4
+ "$schema": "https://json-schema.org/schema",
5
5
  "title": "Create a React Native Library for Nx",
6
6
  "description": "Create a React Native Library for Nx.",
7
7
  "type": "object",
@@ -36,7 +36,7 @@
36
36
  "linter": {
37
37
  "description": "The tool to use for running lint checks.",
38
38
  "type": "string",
39
- "enum": ["eslint"],
39
+ "enum": ["eslint", "none"],
40
40
  "default": "eslint"
41
41
  },
42
42
  "unitTestRunner": {
@@ -1,5 +1,7 @@
1
1
  export interface StorybookStoriesSchema {
2
2
  project: string;
3
+ interactionTests?: boolean;
4
+ js?: boolean;
3
5
  ignorePaths?: string[];
4
6
  skipFormat?: boolean;
5
7
  }
@@ -1,5 +1,5 @@
1
1
  {
2
- "$schema": "http://json-schema.org/schema",
2
+ "$schema": "https://json-schema.org/schema",
3
3
  "cli": "nx",
4
4
  "$id": "NxReactNativeStorybookStories",
5
5
  "title": "Generate React Native Storybook stories",
@@ -14,7 +14,20 @@
14
14
  "$source": "projectName",
15
15
  "index": 0
16
16
  },
17
- "x-prompt": "For which project do you want to generate stories?"
17
+ "x-prompt": "For which project do you want to generate stories?",
18
+ "x-priority": "important"
19
+ },
20
+ "interactionTests": {
21
+ "type": "boolean",
22
+ "description": "Set up Storybook interaction tests.",
23
+ "x-prompt": "Do you want to set up Storybook interaction tests?",
24
+ "x-priority": "important",
25
+ "default": true
26
+ },
27
+ "js": {
28
+ "type": "boolean",
29
+ "description": "Generate JavaScript files rather than TypeScript files.",
30
+ "default": false
18
31
  },
19
32
  "ignorePaths": {
20
33
  "type": "array",
@@ -1,5 +1,8 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import { StorybookStoriesSchema } from './schema';
3
- export declare function createAllStories(tree: Tree, projectName: string, ignorePaths?: string[]): Promise<void>;
4
- export declare function storiesGenerator(host: Tree, schema: StorybookStoriesSchema): Promise<void>;
3
+ /**
4
+ * @deprecated This would be a direct pass through to @nx/react:stories generator.
5
+ * TODO (@xiongemi): remove this generator for v19
6
+ */
7
+ export declare function storiesGenerator(host: Tree, schema: StorybookStoriesSchema): Promise<import("@nx/devkit").GeneratorCallback>;
5
8
  export default storiesGenerator;
@@ -1,56 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.storiesGenerator = exports.createAllStories = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- const path_1 = require("path");
6
- const component_story_1 = require("../component-story/component-story");
7
- const stories_1 = require("@nx/react/src/generators/stories/stories");
8
- const minimatch = require("minimatch");
9
- const versions_1 = require("../../utils/versions");
10
- async function createAllStories(tree, projectName, ignorePaths) {
11
- (0, devkit_1.ensurePackage)('@nx/storybook', versions_1.nxVersion);
12
- const { isTheFileAStory } = await Promise.resolve().then(() => require('@nx/storybook/src/utils/utilities'));
13
- const projects = (0, devkit_1.getProjects)(tree);
14
- const projectConfiguration = projects.get(projectName);
15
- const { sourceRoot } = projectConfiguration;
16
- const projectPath = await (0, stories_1.projectRootPath)(tree, projectConfiguration);
17
- let componentPaths = [];
18
- (0, devkit_1.visitNotIgnoredFiles)(tree, projectPath, (path) => {
19
- if (ignorePaths?.some((pattern) => minimatch(path, pattern)))
20
- return;
21
- if ((path.endsWith('.tsx') && !path.endsWith('.spec.tsx')) ||
22
- (path.endsWith('.js') && !path.endsWith('.spec.js')) ||
23
- (path.endsWith('.jsx') && !path.endsWith('.spec.jsx'))) {
24
- // Check if file is NOT a story (either ts/tsx or js/jsx)
25
- if (!isTheFileAStory(tree, path)) {
26
- // Since the file is not a story
27
- // Let's see if the .stories.* file exists
28
- const ext = path.slice(path.lastIndexOf('.'));
29
- const storyPath = `${path.split(ext)[0]}.stories${ext}`;
30
- if (!tree.exists(storyPath)) {
31
- componentPaths.push(path);
32
- }
33
- }
34
- }
35
- });
36
- await Promise.all(componentPaths.map(async (componentPath) => {
37
- const relativeCmpDir = componentPath.replace((0, path_1.join)(sourceRoot, '/'), '');
38
- if (!(0, stories_1.containsComponentDeclaration)(tree, componentPath)) {
39
- return;
40
- }
41
- await (0, component_story_1.default)(tree, {
42
- componentPath: relativeCmpDir,
43
- project: projectName,
44
- skipFormat: true,
45
- });
46
- }));
47
- }
48
- exports.createAllStories = createAllStories;
3
+ exports.storiesGenerator = void 0;
4
+ const react_1 = require("@nx/react");
5
+ /**
6
+ * @deprecated This would be a direct pass through to @nx/react:stories generator.
7
+ * TODO (@xiongemi): remove this generator for v19
8
+ */
49
9
  async function storiesGenerator(host, schema) {
50
- await createAllStories(host, schema.project, schema.ignorePaths);
51
- if (!schema.skipFormat) {
52
- await (0, devkit_1.formatFiles)(host);
53
- }
10
+ return (0, react_1.storiesGenerator)(host, schema);
54
11
  }
55
12
  exports.storiesGenerator = storiesGenerator;
56
13
  exports.default = storiesGenerator;
@@ -1,4 +1,9 @@
1
- import { GeneratorCallback, Tree } from '@nx/devkit';
1
+ import { Tree } from '@nx/devkit';
2
2
  import { StorybookConfigureSchema } from './schema';
3
- export declare function storybookConfigurationGenerator(host: Tree, schema: StorybookConfigureSchema): Promise<GeneratorCallback>;
3
+ export declare function storybookConfigurationGenerator(tree: Tree, schema: StorybookConfigureSchema): Promise<import("@nx/devkit").GeneratorCallback>;
4
+ /**
5
+ * This would be a direct pass through to @nx/react:storybook-configuration generator.
6
+ * @TODO (@xiongemi): remove this generator for v19
7
+ */
8
+ export declare function storybookConfigurationGeneratorInternal(host: Tree, schema: StorybookConfigureSchema): Promise<import("@nx/devkit").GeneratorCallback>;
4
9
  export default storybookConfigurationGenerator;