@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
@@ -0,0 +1,77 @@
1
+ <% if (webpackPluginOptions) { %>
2
+ const { NxWebpackPlugin } = require('@nx/webpack');
3
+ const { NxReactWebpackPlugin } = require('@nx/react');
4
+
5
+ module.exports = {
6
+ resolve: {
7
+ alias: {
8
+ 'react-native$': 'react-native-web',
9
+ },
10
+ extensions: ['.web.tsx', '.web.ts', '.web.jsx', '.web.js']
11
+ },
12
+ devServer: {
13
+ port: 4200
14
+ },
15
+ plugins: [
16
+ new NxWebpackPlugin({
17
+ tsConfig: '<%= webpackPluginOptions.tsConfig %>',
18
+ compiler: '<%= webpackPluginOptions.compiler %>',
19
+ main: '<%= webpackPluginOptions.main %>',
20
+ index: '<%= webpackPluginOptions.index %>',
21
+ outputPath: '<%= webpackPluginOptions.outputPath %>',
22
+ baseHref: '<%= webpackPluginOptions.baseHref %>',
23
+ assets: <%- JSON.stringify(webpackPluginOptions.assets) %>,
24
+ styles: <%- JSON.stringify(webpackPluginOptions.styles) %>,
25
+ outputHashing: process.env['NODE_ENV'] === 'production' ? 'all' : 'none',
26
+ optimization: process.env['NODE_ENV'] === 'production',
27
+ }),
28
+ new NxReactWebpackPlugin({
29
+ // Uncomment this line if you don't want to use SVGR
30
+ // See: https://react-svgr.com/
31
+ // svgr: false
32
+ }),
33
+ ],
34
+ };
35
+ <% } else { %>
36
+ const { composePlugins, withNx } = require('@nx/webpack');
37
+ const { withReact } = require('@nx/react');
38
+
39
+ // Nx plugins for webpack.
40
+ module.exports = composePlugins(
41
+ withNx(),
42
+ withReact({
43
+ // Uncomment this line if you don't want to use SVGR
44
+ // See: https://react-svgr.com/
45
+ // svgr: false
46
+ }),
47
+ (config) => {
48
+ // Update the webpack config as needed here.
49
+ // e.g. `config.plugins.push(new MyPlugin())`
50
+
51
+ config.resolve.alias = {
52
+ ...config.resolve.alias ?? {},
53
+ 'react-native$': 'react-native-web',
54
+ };
55
+ config.resolve.extensions = [
56
+ '.web.tsx',
57
+ '.web.ts',
58
+ '.web.jsx',
59
+ '.web.js',
60
+ ...config.resolve.extensions,
61
+ ];
62
+ config.module.rules.push({
63
+ test: /\.(js|jsx)$/,
64
+ include: /react-native-vector-icons/,
65
+ loader: 'babel-loader',
66
+ options: {
67
+ presets: [
68
+ '@babel/preset-env',
69
+ ['@babel/preset-react', { runtime: 'automatic' }],
70
+ ],
71
+ },
72
+ });
73
+
74
+ return config;
75
+ }
76
+ );
77
+ <% } %>
@@ -0,0 +1,17 @@
1
+ import { Tree } from '@nx/devkit';
2
+ import { WebConfigurationGeneratorSchema } from '../schema';
3
+ export interface NormalizedSchema extends WebConfigurationGeneratorSchema {
4
+ projectRoot: string;
5
+ fileName: string;
6
+ className: string;
7
+ }
8
+ export declare function normalizeSchema(tree: Tree, schema: WebConfigurationGeneratorSchema): {
9
+ projectRoot: string;
10
+ offsetFromRoot: string;
11
+ fileName: string;
12
+ className: string;
13
+ project: string;
14
+ bundler: "vite" | "webpack";
15
+ skipFormat?: boolean;
16
+ skipPackageJson?: boolean;
17
+ };
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeSchema = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function normalizeSchema(tree, schema) {
6
+ const project = (0, devkit_1.getProjects)(tree).get(schema.project);
7
+ const { fileName, className } = (0, devkit_1.names)(schema.project);
8
+ return {
9
+ ...schema,
10
+ projectRoot: project.root,
11
+ offsetFromRoot: (0, devkit_1.offsetFromRoot)(project.root),
12
+ fileName,
13
+ className,
14
+ };
15
+ }
16
+ exports.normalizeSchema = normalizeSchema;
@@ -0,0 +1,7 @@
1
+ import { TargetConfiguration } from '@nx/devkit';
2
+ import type { WithReactOptions } from '@nx/react';
3
+ import type { WithNxOptions } from '@nx/webpack';
4
+ import { NormalizedSchema } from './normalize-schema';
5
+ export declare function createBuildTarget(options: NormalizedSchema): TargetConfiguration;
6
+ export declare function createServeTarget(options: NormalizedSchema): TargetConfiguration;
7
+ export declare function createNxWebpackPluginOptions(options: NormalizedSchema): WithNxOptions & WithReactOptions;
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNxWebpackPluginOptions = exports.createServeTarget = exports.createBuildTarget = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ function createBuildTarget(options) {
6
+ return {
7
+ executor: '@nx/webpack:webpack',
8
+ outputs: ['{options.outputPath}'],
9
+ defaultConfiguration: 'production',
10
+ options: {
11
+ compiler: 'babel',
12
+ outputPath: (0, devkit_1.joinPathFragments)('dist', options.projectRoot != '.' ? options.projectRoot : options.project, 'web'),
13
+ index: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src/index.html'),
14
+ baseHref: '/',
15
+ main: (0, devkit_1.joinPathFragments)(options.projectRoot, `src/main-web.tsx`),
16
+ tsConfig: (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.app.json'),
17
+ assets: [
18
+ (0, devkit_1.joinPathFragments)(options.projectRoot, 'src/favicon.ico'),
19
+ (0, devkit_1.joinPathFragments)(options.projectRoot, 'src/assets'),
20
+ ],
21
+ webpackConfig: (0, devkit_1.joinPathFragments)(options.projectRoot, 'webpack.config.js'),
22
+ },
23
+ configurations: {
24
+ development: {
25
+ extractLicenses: false,
26
+ optimization: false,
27
+ sourceMap: true,
28
+ vendorChunk: true,
29
+ },
30
+ production: {
31
+ optimization: true,
32
+ outputHashing: 'all',
33
+ sourceMap: false,
34
+ namedChunks: false,
35
+ extractLicenses: true,
36
+ vendorChunk: false,
37
+ },
38
+ },
39
+ };
40
+ }
41
+ exports.createBuildTarget = createBuildTarget;
42
+ function createServeTarget(options) {
43
+ return {
44
+ executor: '@nx/webpack:dev-server',
45
+ defaultConfiguration: 'development',
46
+ options: {
47
+ buildTarget: `${options.project}:build`,
48
+ hmr: true,
49
+ },
50
+ configurations: {
51
+ development: {
52
+ buildTarget: `${options.project}:build:development`,
53
+ },
54
+ production: {
55
+ buildTarget: `${options.project}:build:production`,
56
+ hmr: false,
57
+ },
58
+ },
59
+ };
60
+ }
61
+ exports.createServeTarget = createServeTarget;
62
+ function createNxWebpackPluginOptions(options) {
63
+ return {
64
+ target: 'web',
65
+ compiler: 'babel',
66
+ outputPath: (0, devkit_1.joinPathFragments)('dist', options.projectRoot != '.' ? options.projectRoot : options.project),
67
+ index: './src/index.html',
68
+ baseHref: '/',
69
+ main: `./src/main-web.tsx`,
70
+ tsConfig: './tsconfig.app.json',
71
+ assets: ['./src/favicon.ico', './src/assets'],
72
+ styles: [],
73
+ };
74
+ }
75
+ exports.createNxWebpackPluginOptions = createNxWebpackPluginOptions;
@@ -0,0 +1,6 @@
1
+ export interface WebConfigurationGeneratorSchema {
2
+ project: string;
3
+ bundler: 'vite' | 'webpack';
4
+ skipFormat?: boolean;
5
+ skipPackageJson?: boolean; //default is false
6
+ }
@@ -0,0 +1,42 @@
1
+ {
2
+ "$schema": "http://json-schema.org/schema",
3
+ "$id": "NxReactNativeWebConfiguration",
4
+ "description": "Setup web configuration to React Native apps using react-native-web.",
5
+ "title": "Nx React Native Web configuration",
6
+ "type": "object",
7
+ "properties": {
8
+ "project": {
9
+ "type": "string",
10
+ "aliases": ["name", "projectName"],
11
+ "description": "Project for which to generate web configuration.",
12
+ "$default": {
13
+ "$source": "argv",
14
+ "index": 0
15
+ },
16
+ "x-prompt": "For which project do you want to generate web configuration?",
17
+ "x-dropdown": "projects",
18
+ "x-priority": "important"
19
+ },
20
+ "skipFormat": {
21
+ "description": "Skip formatting files.",
22
+ "type": "boolean",
23
+ "default": false,
24
+ "x-priority": "internal"
25
+ },
26
+ "skipPackageJson": {
27
+ "description": "Do not add dependencies to `package.json`.",
28
+ "type": "boolean",
29
+ "default": false,
30
+ "x-priority": "internal"
31
+ },
32
+ "bundler": {
33
+ "description": "The bundler to use.",
34
+ "type": "string",
35
+ "enum": ["vite", "webpack"],
36
+ "x-prompt": "Which bundler do you want to use to build the application?",
37
+ "default": "webpack",
38
+ "x-priority": "important"
39
+ }
40
+ },
41
+ "required": ["project", "bundler"]
42
+ }
@@ -0,0 +1,12 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ import { WebConfigurationGeneratorSchema } from './schema';
3
+ /**
4
+ * This function sets web configuration for react native apps with react-native-web.
5
+ * 1. install react-native-web
6
+ * 2. apply webpack or vite init generator
7
+ * 3. create files for webpack or vite config, index.html, assets folder, babel.config.js
8
+ * @param tree
9
+ * @param options
10
+ */
11
+ export declare function webConfigurationGenerator(tree: Tree, options: WebConfigurationGeneratorSchema): Promise<GeneratorCallback>;
12
+ export default webConfigurationGenerator;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.webConfigurationGenerator = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const has_webpack_plugin_1 = require("@nx/react/src/utils/has-webpack-plugin");
6
+ const versions_1 = require("../../utils/versions");
7
+ const normalize_schema_1 = require("./lib/normalize-schema");
8
+ const webpack_targets_1 = require("./lib/webpack-targets");
9
+ /**
10
+ * This function sets web configuration for react native apps with react-native-web.
11
+ * 1. install react-native-web
12
+ * 2. apply webpack or vite init generator
13
+ * 3. create files for webpack or vite config, index.html, assets folder, babel.config.js
14
+ * @param tree
15
+ * @param options
16
+ */
17
+ async function webConfigurationGenerator(tree, options) {
18
+ const normalizedSchema = (0, normalize_schema_1.normalizeSchema)(tree, options);
19
+ const tasks = [];
20
+ // install react-native-web
21
+ if (!options.skipPackageJson) {
22
+ const installTask = (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
23
+ 'react-native-web': versions_1.reactNativeWebVersion,
24
+ });
25
+ tasks.push(installTask);
26
+ }
27
+ // apply webpack or vite init generator
28
+ const bundlerTask = await addBundlerConfiguration(tree, normalizedSchema);
29
+ tasks.push(bundlerTask);
30
+ // create files for webpack and vite config, index.html
31
+ if (normalizedSchema.bundler === 'vite') {
32
+ (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, './files/base-vite'), normalizedSchema.projectRoot, { ...normalizedSchema, tmpl: '' });
33
+ }
34
+ else {
35
+ (0, devkit_1.generateFiles)(tree, (0, devkit_1.joinPathFragments)(__dirname, './files/base-webpack'), normalizedSchema.projectRoot, {
36
+ ...normalizedSchema,
37
+ tmpl: '',
38
+ webpackPluginOptions: (0, has_webpack_plugin_1.hasWebpackPlugin)(tree)
39
+ ? (0, webpack_targets_1.createNxWebpackPluginOptions)(normalizedSchema)
40
+ : null,
41
+ });
42
+ }
43
+ if (!options.skipFormat) {
44
+ await (0, devkit_1.formatFiles)(tree);
45
+ }
46
+ return (0, devkit_1.runTasksInSerial)(...tasks);
47
+ }
48
+ exports.webConfigurationGenerator = webConfigurationGenerator;
49
+ /**
50
+ * Add bundler configuration
51
+ * - for vite, viteConfigurationGenerator contains logics to add build and serve target
52
+ * - for webpack, need to explict add the build and serve target
53
+ */
54
+ async function addBundlerConfiguration(tree, normalizedSchema) {
55
+ if (normalizedSchema.bundler === 'vite') {
56
+ const { viteConfigurationGenerator } = (0, devkit_1.ensurePackage)('@nx/vite', versions_1.nxVersion);
57
+ const viteTask = await viteConfigurationGenerator(tree, {
58
+ uiFramework: 'react',
59
+ project: normalizedSchema.project,
60
+ newProject: true,
61
+ includeVitest: false,
62
+ compiler: 'babel',
63
+ skipFormat: true,
64
+ });
65
+ return viteTask;
66
+ }
67
+ else {
68
+ const { webpackInitGenerator } = (0, devkit_1.ensurePackage)('@nx/webpack', versions_1.nxVersion);
69
+ const webpackInitTask = await webpackInitGenerator(tree, {
70
+ skipFormat: true,
71
+ skipPackageJson: normalizedSchema.skipPackageJson,
72
+ });
73
+ if (!(0, has_webpack_plugin_1.hasWebpackPlugin)(tree)) {
74
+ const projectConfiguration = (0, devkit_1.readProjectConfiguration)(tree, normalizedSchema.project);
75
+ projectConfiguration.targets = {
76
+ ...projectConfiguration.targets,
77
+ build: (0, webpack_targets_1.createBuildTarget)(normalizedSchema),
78
+ serve: (0, webpack_targets_1.createServeTarget)(normalizedSchema),
79
+ };
80
+ (0, devkit_1.updateProjectConfiguration)(tree, normalizedSchema.project, projectConfiguration);
81
+ }
82
+ return webpackInitTask;
83
+ }
84
+ }
85
+ exports.default = webConfigurationGenerator;
@@ -31,7 +31,6 @@ const oldConfigComment = `/**
31
31
  const content = `
32
32
  const { withNxMetro } = require('@nx/react-native');
33
33
  const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
34
- const exclusionList = require('metro-config/src/defaults/exclusionList');
35
34
 
36
35
  const defaultConfig = getDefaultConfig(__dirname);
37
36
  const { assetExts, sourceExts } = defaultConfig.resolver;
@@ -49,9 +48,6 @@ const customConfig = {
49
48
  resolver: {
50
49
  assetExts: assetExts.filter((ext) => ext !== 'svg'),
51
50
  sourceExts: [...sourceExts, 'svg'],
52
- blockList: exclusionList([/^(?!.*node_modules).*\\/dist\\/.*/]),
53
- unstable_enableSymlinks: true,
54
- unstable_enablePackageExports: true,
55
51
  },
56
52
  };
57
53
 
@@ -7,14 +7,7 @@ const devkit_1 = require("@nx/devkit");
7
7
  * @returns
8
8
  */
9
9
  async function update(tree) {
10
- const packageJson = (0, devkit_1.readJson)(tree, 'package.json');
11
- if (!packageJson.devDependencies['@types/react-native'] ||
12
- !packageJson.dependencies['react-native']) {
13
- return;
14
- }
15
- (0, devkit_1.updateJson)(tree, 'package.json', (packageJson) => {
16
- delete packageJson.devDependencies['@types/react-native'];
17
- return packageJson;
18
- });
10
+ (0, devkit_1.removeDependenciesFromPackageJson)(tree, [], ['@types/react-native']);
11
+ await (0, devkit_1.formatFiles)(tree);
19
12
  }
20
13
  exports.default = update;
@@ -0,0 +1,6 @@
1
+ import { Tree } from '@nx/devkit';
2
+ /**
3
+ * Add target upgrade for react native apps
4
+ * Remove pod-install from dependsOn for all targets, it does pod-install when creating the app
5
+ */
6
+ export default function update(tree: Tree): Promise<void>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const upgrade_impl_1 = require("../../executors/upgrade/upgrade.impl");
5
+ /**
6
+ * Add target upgrade for react native apps
7
+ * Remove pod-install from dependsOn for all targets, it does pod-install when creating the app
8
+ */
9
+ async function update(tree) {
10
+ const projects = (0, devkit_1.getProjects)(tree);
11
+ for (const [name, config] of projects.entries()) {
12
+ if (config.targets?.['start']?.executor === '@nx/react-native:start') {
13
+ if (!config.targets['upgrade']) {
14
+ config.targets.upgrade = {
15
+ executor: '@nx/react-native:upgrade',
16
+ options: {},
17
+ };
18
+ await (0, upgrade_impl_1.runCliUpgrade)(devkit_1.workspaceRoot, config.root);
19
+ }
20
+ if (config.targets?.['pod-install']?.executor ===
21
+ '@nx/react-native:pod-install') {
22
+ for (const targetName in config.targets) {
23
+ if (config.targets[targetName]?.dependsOn?.length) {
24
+ config.targets[targetName].dependsOn = config.targets[targetName].dependsOn.filter((dependsOn) => dependsOn !== 'pod-install');
25
+ }
26
+ }
27
+ }
28
+ (0, devkit_1.updateProjectConfiguration)(tree, name, config);
29
+ }
30
+ }
31
+ await (0, devkit_1.formatFiles)(tree);
32
+ }
33
+ exports.default = update;
@@ -0,0 +1,8 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ /**
3
+ * Add web configuration to react native projects
4
+ * - delete the current serve target which is just a pass-through to start target
5
+ * - rename the babel.config.json to to babel-v72.config.json
6
+ * - add web confiugration, it will add .babelrc.js
7
+ */
8
+ export default function update(tree: Tree): Promise<GeneratorCallback>;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const web_configuration_1 = require("../../generators/web-configuration/web-configuration");
5
+ /**
6
+ * Add web configuration to react native projects
7
+ * - delete the current serve target which is just a pass-through to start target
8
+ * - rename the babel.config.json to to babel-v72.config.json
9
+ * - add web confiugration, it will add .babelrc.js
10
+ */
11
+ async function update(tree) {
12
+ const projects = (0, devkit_1.getProjects)(tree);
13
+ const tasks = [];
14
+ for (const [projectName, config] of projects.entries()) {
15
+ if (config.targets?.['start']?.executor === '@nx/react-native:start') {
16
+ if (config.targets['serve'] &&
17
+ config.targets['serve'].executor === 'nx:run-commands' &&
18
+ config.targets['serve'].options?.command?.startsWith('nx start')) {
19
+ delete config.targets['serve'];
20
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, config);
21
+ }
22
+ if (tree.exists((0, devkit_1.joinPathFragments)(config.root, 'babel.config.json'))) {
23
+ tree.rename((0, devkit_1.joinPathFragments)(config.root, 'babel.config.json'), (0, devkit_1.joinPathFragments)(config.root, 'babel-v72.config.json'));
24
+ }
25
+ tasks.push(await (0, web_configuration_1.default)(tree, {
26
+ project: config.name,
27
+ bundler: 'webpack',
28
+ }));
29
+ }
30
+ }
31
+ return (0, devkit_1.runTasksInSerial)(...tasks);
32
+ }
33
+ exports.default = update;
@@ -0,0 +1,39 @@
1
+ import { addProjectConfiguration, getProjects, Tree } from '@nx/devkit';
2
+ import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
3
+ import update from './add-web-configuration';
4
+
5
+ describe('add-web-configuration', () => {
6
+ let tree: Tree;
7
+
8
+ beforeEach(async () => {
9
+ tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' });
10
+ addProjectConfiguration(tree, 'product', {
11
+ root: 'apps/product',
12
+ sourceRoot: 'apps/product/src',
13
+ targets: {
14
+ start: {
15
+ executor: '@nx/react-native:start',
16
+ options: {},
17
+ },
18
+ serve: {
19
+ executor: 'nx:run-commands',
20
+ options: {
21
+ command: 'nx start product',
22
+ },
23
+ },
24
+ },
25
+ });
26
+ });
27
+
28
+ it(`should add web configuration`, async () => {
29
+ await update(tree);
30
+
31
+ tree.exists('apps/product/webpack.config.js');
32
+ getProjects(tree).forEach((project) => {
33
+ expect(project.targets['build'].executor).toEqual('@nx/webpack:webpack');
34
+ expect(project.targets['serve'].executor).toEqual(
35
+ '@nx/webpack:dev-server'
36
+ );
37
+ });
38
+ });
39
+ });
@@ -0,0 +1,5 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ /**
3
+ * Upgrade react native storybook target to use web
4
+ */
5
+ export default function changeStorybookTargets(tree: Tree): Promise<GeneratorCallback>;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ const output_1 = require("nx/src/utils/output");
5
+ const migrate_7_1 = require("@nx/storybook/src/generators/migrate-7/migrate-7");
6
+ const utilities_1 = require("@nx/storybook/src/utils/utilities");
7
+ const configuration_1 = require("@nx/react/src/generators/storybook-configuration/configuration");
8
+ /**
9
+ * Upgrade react native storybook target to use web
10
+ */
11
+ async function changeStorybookTargets(tree) {
12
+ const tasks = [];
13
+ // update the storybook target
14
+ const projects = (0, devkit_1.getProjects)(tree);
15
+ let hasStorybookTarget = false;
16
+ for (const [projectName, config] of projects.entries()) {
17
+ if (config.targets?.['storybook']?.executor === '@nx/react-native:storybook') {
18
+ hasStorybookTarget = true;
19
+ delete config.targets['storybook'];
20
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, config);
21
+ tasks.push(await (0, configuration_1.default)(tree, {
22
+ project: projectName,
23
+ }));
24
+ }
25
+ }
26
+ /**
27
+ * This just checks if Storybook is installed in the workspace.
28
+ * The thing here is that during the previous step of the migration,
29
+ * during packageJsonUpdates, Nx has already set Storybook
30
+ * to version 7, if Storybook exists in the workspace.
31
+ * So, it makes no sense here to check if the version is
32
+ * 7, because it will always be.
33
+ */
34
+ const storybookVersion = (0, utilities_1.storybookMajorVersion)();
35
+ if (!hasStorybookTarget || !storybookVersion) {
36
+ return;
37
+ }
38
+ output_1.output.log({
39
+ title: 'Migrating Storybook to v7',
40
+ bodyLines: [
41
+ `🚀 This migration will update your Storybook configuration to v7.`,
42
+ `It will call the @nx/storybook:migrate-7 generator for you.`,
43
+ `You can read more about the migration and how this generator works here:`,
44
+ `https://nx.dev/packages/storybook/generators/migrate-7`,
45
+ ],
46
+ });
47
+ tasks.push(await (0, migrate_7_1.default)(tree, { autoAcceptAllPrompts: true }));
48
+ tasks.push((0, devkit_1.removeDependenciesFromPackageJson)(tree, [], [
49
+ '@storybook/react-native',
50
+ '@storybook/addon-ondevice-actions',
51
+ '@storybook/addon-ondevice-backgrounds',
52
+ '@storybook/addon-ondevice-controls',
53
+ '@storybook/addon-ondevice-notes',
54
+ ]));
55
+ return (0, devkit_1.runTasksInSerial)(...tasks);
56
+ }
57
+ exports.default = changeStorybookTargets;
@@ -0,0 +1,6 @@
1
+ import { Tree } from '@nx/devkit';
2
+ /**
3
+ * This migration removes blockList in metro.config.js.
4
+ * It is now excluding dist folder in watchFolders in withNxMetro.
5
+ */
6
+ export default function update(tree: Tree): Promise<void>;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const devkit_1 = require("@nx/devkit");
4
+ /**
5
+ * This migration removes blockList in metro.config.js.
6
+ * It is now excluding dist folder in watchFolders in withNxMetro.
7
+ */
8
+ async function update(tree) {
9
+ const projects = (0, devkit_1.getProjects)(tree);
10
+ for (const [_, config] of projects.entries()) {
11
+ if (config.targets?.['start']?.executor === '@nx/react-native:start') {
12
+ if (tree.exists((0, devkit_1.joinPathFragments)(config.root, 'metro.config.js'))) {
13
+ let content = tree
14
+ .read((0, devkit_1.joinPathFragments)(config.root, 'metro.config.js'))
15
+ .toString();
16
+ content = content.replace(`blockList: exclusionList([/^(?!.*node_modules).*/dist/.*/]),`, '');
17
+ content = content.replace('unstable_enableSymlinks: true,', '');
18
+ content = content.replace('unstable_enablePackageExports: true,', '');
19
+ content = content.replace(`const exclusionList = require('metro-config/src/defaults/exclusionList');`, '');
20
+ tree.write((0, devkit_1.joinPathFragments)(config.root, 'metro.config.js'), content);
21
+ await (0, devkit_1.formatFiles)(tree);
22
+ }
23
+ }
24
+ }
25
+ }
26
+ exports.default = update;