@nx/react-native 17.2.8 → 17.3.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.
package/README.md CHANGED
@@ -1,4 +1,9 @@
1
- <p style="text-align: center;"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx.png" width="600" alt="Nx - Smart, Fast and Extensible Build System"></p>
1
+ <p style="text-align: center;">
2
+ <picture>
3
+ <source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-dark.svg">
4
+ <img alt="Nx - Smart Monorepos · Fast CI" src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-light.svg" width="100%">
5
+ </picture>
6
+ </p>
2
7
 
3
8
  <div style="text-align: center;">
4
9
 
@@ -15,9 +20,9 @@
15
20
 
16
21
  <hr>
17
22
 
18
- # Nx: Smart, Fast and Extensible Build System
23
+ # Nx: Smart Monorepos · Fast CI
19
24
 
20
- Nx is a next generation build system with first class monorepo support and powerful integrations.
25
+ Nx is a build system with built-in tooling and advanced CI capabilities. It helps you maintain and scale monorepos, both locally and on CI.
21
26
 
22
27
  This package is a [React Native plugin for Nx](https://nx.dev/packages/react-native).
23
28
 
@@ -59,5 +64,5 @@ npx nx@latest init
59
64
  - [Blog Posts About Nx](https://blog.nrwl.io/nx/home)
60
65
 
61
66
  <p style="text-align: center;"><a href="https://nx.dev/#learning-materials" target="_blank" rel="noreferrer"><img src="https://raw.githubusercontent.com/nrwl/nx/master/images/nx-courses-and-videos.svg"
62
- width="100%" alt="Nx - Smart, Fast and Extensible Build System"></a></p>
67
+ width="100%" alt="Nx - Smart Monorepos · Fast CI"></a></p>
63
68
 
package/migrations.json CHANGED
@@ -546,6 +546,15 @@
546
546
  "alwaysAddToPackageJson": false
547
547
  }
548
548
  }
549
+ },
550
+ "17.3.0": {
551
+ "version": "17.3.0-beta.3",
552
+ "packages": {
553
+ "@types/node": {
554
+ "version": "18.16.9",
555
+ "alwaysAddToPackageJson": false
556
+ }
557
+ }
549
558
  }
550
559
  }
551
560
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/react-native",
3
- "version": "17.2.8",
3
+ "version": "17.3.0-beta.2",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for React Native contains generators for managing React Native applications and libraries within an Nx workspace. It provides: \n\n-Integration with libraries such as Jest, Detox, and Storybook.\n-Scaffolding for creating buildable libraries that can be published to npm.\n-Utilities for automatic workspace refactoring.",
6
6
  "keywords": [
@@ -36,14 +36,14 @@
36
36
  "node-fetch": "^2.6.7",
37
37
  "tsconfig-paths": "^4.1.2",
38
38
  "tslib": "^2.3.0",
39
- "@nx/detox": "17.2.8",
40
- "@nx/devkit": "17.2.8",
41
- "@nx/jest": "17.2.8",
42
- "@nx/js": "17.2.8",
43
- "@nx/eslint": "17.2.8",
44
- "@nx/react": "17.2.8",
45
- "@nx/workspace": "17.2.8",
46
- "@nrwl/react-native": "17.2.8"
39
+ "@nx/detox": "17.3.0-beta.2",
40
+ "@nx/devkit": "17.3.0-beta.2",
41
+ "@nx/jest": "17.3.0-beta.2",
42
+ "@nx/js": "17.3.0-beta.2",
43
+ "@nx/eslint": "17.3.0-beta.2",
44
+ "@nx/react": "17.3.0-beta.2",
45
+ "@nx/workspace": "17.3.0-beta.2",
46
+ "@nrwl/react-native": "17.3.0-beta.2"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "react-native": ">= 0.72.0 < 0.73.0"
package/plugin.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { createNodes, ReactNativePluginOptions } from './plugins/plugin';
package/plugin.js ADDED
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNodes = void 0;
4
+ var plugin_1 = require("./plugins/plugin");
5
+ Object.defineProperty(exports, "createNodes", { enumerable: true, get: function () { return plugin_1.createNodes; } });
@@ -0,0 +1,11 @@
1
+ import { CreateDependencies, CreateNodes } from '@nx/devkit';
2
+ export interface ReactNativePluginOptions {
3
+ startTargetName?: string;
4
+ runIosTargetName?: string;
5
+ runAndroidTargetName?: string;
6
+ buildIosTargetName?: string;
7
+ buildAndroidTargetName?: string;
8
+ bundleTargetName?: string;
9
+ }
10
+ export declare const createDependencies: CreateDependencies;
11
+ export declare const createNodes: CreateNodes<ReactNativePluginOptions>;
@@ -0,0 +1,142 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createNodes = exports.createDependencies = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const path_1 = require("path");
6
+ const js_1 = require("@nx/js");
7
+ const get_named_inputs_1 = require("@nx/devkit/src/utils/get-named-inputs");
8
+ const fs_1 = require("fs");
9
+ const calculate_hash_for_create_nodes_1 = require("@nx/devkit/src/utils/calculate-hash-for-create-nodes");
10
+ const cache_directory_1 = require("nx/src/utils/cache-directory");
11
+ const cachePath = (0, path_1.join)(cache_directory_1.projectGraphCacheDirectory, 'react-native.hash');
12
+ const targetsCache = (0, fs_1.existsSync)(cachePath) ? readTargetsCache() : {};
13
+ const calculatedTargets = {};
14
+ function readTargetsCache() {
15
+ return (0, devkit_1.readJsonFile)(cachePath);
16
+ }
17
+ function writeTargetsToCache(targets) {
18
+ (0, devkit_1.writeJsonFile)(cachePath, targets);
19
+ }
20
+ const createDependencies = () => {
21
+ writeTargetsToCache(calculatedTargets);
22
+ return [];
23
+ };
24
+ exports.createDependencies = createDependencies;
25
+ exports.createNodes = [
26
+ '**/app.{json,config.js}',
27
+ (configFilePath, options, context) => {
28
+ options = normalizeOptions(options);
29
+ const projectRoot = (0, path_1.dirname)(configFilePath);
30
+ // Do not create a project if package.json or project.json or metro.config.js isn't there.
31
+ const siblingFiles = (0, fs_1.readdirSync)((0, path_1.join)(context.workspaceRoot, projectRoot));
32
+ if (!siblingFiles.includes('package.json') ||
33
+ !siblingFiles.includes('project.json') ||
34
+ !siblingFiles.includes('metro.config.js')) {
35
+ return {};
36
+ }
37
+ const appConfig = getAppConfig(configFilePath, context);
38
+ if (appConfig.expo) {
39
+ return {};
40
+ }
41
+ const hash = (0, calculate_hash_for_create_nodes_1.calculateHashForCreateNodes)(projectRoot, options, context, [
42
+ (0, js_1.getLockFileName)((0, devkit_1.detectPackageManager)(context.workspaceRoot)),
43
+ ]);
44
+ const targets = targetsCache[hash]
45
+ ? targetsCache[hash]
46
+ : buildReactNativeTargets(projectRoot, options, context);
47
+ calculatedTargets[hash] = targets;
48
+ return {
49
+ projects: {
50
+ [projectRoot]: {
51
+ targets,
52
+ },
53
+ },
54
+ };
55
+ },
56
+ ];
57
+ function buildReactNativeTargets(projectRoot, options, context) {
58
+ const namedInputs = (0, get_named_inputs_1.getNamedInputs)(projectRoot, context);
59
+ const targets = {
60
+ [options.startTargetName]: {
61
+ command: `react-native start`,
62
+ options: { cwd: projectRoot },
63
+ },
64
+ [options.runIosTargetName]: {
65
+ command: `react-native run-ios`,
66
+ options: { cwd: projectRoot },
67
+ },
68
+ [options.runAndroidTargetName]: {
69
+ command: `react-native run-android`,
70
+ options: { cwd: projectRoot },
71
+ },
72
+ [options.buildIosTargetName]: {
73
+ command: `react-native build-ios`,
74
+ options: { cwd: projectRoot },
75
+ cache: true,
76
+ dependsOn: [`^${options.buildIosTargetName}`],
77
+ inputs: getInputs(namedInputs),
78
+ outputs: [getOutputs(projectRoot, 'ios/build/Build/Products')],
79
+ },
80
+ [options.buildAndroidTargetName]: {
81
+ command: `react-native build-android`,
82
+ options: { cwd: projectRoot },
83
+ cache: true,
84
+ dependsOn: [`^${options.buildAndroidTargetName}`],
85
+ inputs: getInputs(namedInputs),
86
+ outputs: [getOutputs(projectRoot, 'android/app/build/outputs')],
87
+ },
88
+ [options.bundleTargetName]: {
89
+ command: `react-native bundle`,
90
+ options: { cwd: projectRoot },
91
+ dependsOn: [`^${options.bundleTargetName}`],
92
+ inputs: getInputs(namedInputs),
93
+ },
94
+ };
95
+ return targets;
96
+ }
97
+ function getAppConfig(configFilePath, context) {
98
+ const resolvedPath = (0, path_1.join)(context.workspaceRoot, configFilePath);
99
+ let module = load(resolvedPath);
100
+ return module.default ?? module;
101
+ }
102
+ function getInputs(namedInputs) {
103
+ return [
104
+ ...('production' in namedInputs
105
+ ? ['default', '^production']
106
+ : ['default', '^default']),
107
+ {
108
+ externalDependencies: ['react-native'],
109
+ },
110
+ ];
111
+ }
112
+ function getOutputs(projectRoot, dir) {
113
+ if (projectRoot === '.') {
114
+ return `{projectRoot}/${dir}`;
115
+ }
116
+ else {
117
+ return `{workspaceRoot}/${projectRoot}/${dir}`;
118
+ }
119
+ }
120
+ /**
121
+ * Load the module after ensuring that the require cache is cleared.
122
+ */
123
+ function load(path) {
124
+ // Clear cache if the path is in the cache
125
+ if (require.cache[path]) {
126
+ for (const k of Object.keys(require.cache)) {
127
+ delete require.cache[k];
128
+ }
129
+ }
130
+ // Then require
131
+ return require(path);
132
+ }
133
+ function normalizeOptions(options) {
134
+ options ??= {};
135
+ options.startTargetName ??= 'start';
136
+ options.runIosTargetName ??= 'run-ios';
137
+ options.runAndroidTargetName ??= 'run-android';
138
+ options.buildIosTargetName ??= 'build-ios';
139
+ options.buildAndroidTargetName ??= 'build-android';
140
+ options.bundleTargetName ??= 'bundle';
141
+ return options;
142
+ }
@@ -20,9 +20,9 @@ async function reactNativeApplicationGenerator(host, schema) {
20
20
  exports.reactNativeApplicationGenerator = reactNativeApplicationGenerator;
21
21
  async function reactNativeApplicationGeneratorInternal(host, schema) {
22
22
  const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
23
+ const initTask = await (0, init_1.default)(host, { ...options, skipFormat: true });
23
24
  (0, create_application_files_1.createApplicationFiles)(host, options);
24
25
  (0, add_project_1.addProject)(host, options);
25
- const initTask = await (0, init_1.default)(host, { ...options, skipFormat: true });
26
26
  const lintTask = await (0, add_linting_1.addLinting)(host, {
27
27
  ...options,
28
28
  projectRoot: options.appProjectRoot,
@@ -3,11 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addProject = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  function addProject(host, options) {
6
+ const nxJson = (0, devkit_1.readNxJson)(host);
7
+ const hasPlugin = nxJson.plugins?.some((p) => typeof p === 'string'
8
+ ? p === '@nx/react-native/plugin'
9
+ : p.plugin === '@nx/react-native/plugin');
6
10
  const project = {
7
11
  root: options.appProjectRoot,
8
12
  sourceRoot: `${options.appProjectRoot}/src`,
9
13
  projectType: 'application',
10
- targets: { ...getTargets(options) },
14
+ targets: hasPlugin ? {} : getTargets(options),
11
15
  tags: options.parsedTags,
12
16
  };
13
17
  (0, devkit_1.addProjectConfiguration)(host, options.projectName, {
@@ -31,6 +31,9 @@ async function reactNativeInitGenerator(host, schema) {
31
31
  });
32
32
  tasks.push(detoxTask);
33
33
  }
34
+ if (process.env.NX_PCV3 === 'true') {
35
+ addPlugin(host);
36
+ }
34
37
  if (!schema.skipFormat) {
35
38
  await (0, devkit_1.formatFiles)(host);
36
39
  }
@@ -76,4 +79,27 @@ exports.updateDependencies = updateDependencies;
76
79
  function moveDependency(host) {
77
80
  return (0, devkit_1.removeDependenciesFromPackageJson)(host, ['@nx/react-native'], []);
78
81
  }
82
+ function addPlugin(host) {
83
+ const nxJson = (0, devkit_1.readNxJson)(host);
84
+ nxJson.plugins ??= [];
85
+ for (const plugin of nxJson.plugins) {
86
+ if (typeof plugin === 'string'
87
+ ? plugin === '@nx/react-native/plugin'
88
+ : plugin.plugin === '@nx/react-native/plugin') {
89
+ return;
90
+ }
91
+ }
92
+ nxJson.plugins.push({
93
+ plugin: '@nx/react-native/plugin',
94
+ options: {
95
+ startTargetName: 'start',
96
+ bundleTargetName: 'bundle',
97
+ runIosTargetName: 'run-ios',
98
+ runAndroidTargetName: 'run-android',
99
+ buildIosTargetName: 'build-ios',
100
+ buildAndroidTargetName: 'build-android',
101
+ },
102
+ });
103
+ (0, devkit_1.updateNxJson)(host, nxJson);
104
+ }
79
105
  exports.default = reactNativeInitGenerator;
@@ -35,7 +35,6 @@ describe('lib', () => {
35
35
  expect(projectConfiguration.targets.build).toBeUndefined();
36
36
  expect(projectConfiguration.targets.lint).toEqual({
37
37
  executor: '@nx/eslint:lint',
38
- outputs: ['{options.outputFile}'],
39
38
  });
40
39
  expect(projectConfiguration.tags).toEqual(['one', 'two']);
41
40
  });
@@ -156,7 +155,6 @@ describe('lib', () => {
156
155
  expect(projectConfiguration.root).toEqual('my-dir');
157
156
  expect(projectConfiguration.targets.lint).toEqual({
158
157
  executor: '@nx/eslint:lint',
159
- outputs: ['{options.outputFile}'],
160
158
  });
161
159
  });
162
160
 
@@ -235,7 +233,6 @@ describe('lib', () => {
235
233
  expect(projectConfiguration.targets.test).toBeUndefined();
236
234
  expect(projectConfiguration.targets.lint).toMatchObject({
237
235
  executor: '@nx/eslint:lint',
238
- outputs: ['{options.outputFile}'],
239
236
  });
240
237
  });
241
238
 
@@ -1,6 +1,6 @@
1
1
  export declare const nxVersion: any;
2
2
  export declare const reactNativeVersion = "0.72.6";
3
- export declare const typesNodeVersion = "18.14.4";
3
+ export declare const typesNodeVersion = "18.16.9";
4
4
  export declare const metroVersion = "0.76.8";
5
5
  export declare const reactNativeMetroConfigVersion = "^0.72.11";
6
6
  export declare const reactNativeCommunityCli = "11.3.7";
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.reactNativeSafeAreaContextVersion = exports.reactNativeAsyncStorageVersion = exports.babelRuntimeVersion = exports.reactNativeSvgVersion = exports.reactNativeSvgTransformerVersion = exports.jestReactNativeVersion = exports.testingLibraryJestNativeVersion = exports.testingLibraryReactNativeVersion = exports.typesReactVersion = exports.reactTestRendererVersion = exports.reactDomVersion = exports.reactVersion = exports.reactNativeCommunityCliAndroid = exports.reactNativeCommunityCliIos = exports.reactNativeCommunityCli = exports.reactNativeMetroConfigVersion = exports.metroVersion = exports.typesNodeVersion = exports.reactNativeVersion = exports.nxVersion = void 0;
4
4
  exports.nxVersion = require('../../package.json').version;
5
5
  exports.reactNativeVersion = '0.72.6';
6
- exports.typesNodeVersion = '18.14.4';
6
+ exports.typesNodeVersion = '18.16.9';
7
7
  exports.metroVersion = '0.76.8';
8
8
  exports.reactNativeMetroConfigVersion = '^0.72.11';
9
9
  exports.reactNativeCommunityCli = '11.3.7';