@nx/react-native 17.3.0-beta.3 → 17.3.0-beta.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/react-native",
3
- "version": "17.3.0-beta.3",
3
+ "version": "17.3.0-beta.4",
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.3.0-beta.3",
40
- "@nx/devkit": "17.3.0-beta.3",
41
- "@nx/jest": "17.3.0-beta.3",
42
- "@nx/js": "17.3.0-beta.3",
43
- "@nx/eslint": "17.3.0-beta.3",
44
- "@nx/react": "17.3.0-beta.3",
45
- "@nx/workspace": "17.3.0-beta.3",
46
- "@nrwl/react-native": "17.3.0-beta.3"
39
+ "@nx/detox": "17.3.0-beta.4",
40
+ "@nx/devkit": "17.3.0-beta.4",
41
+ "@nx/jest": "17.3.0-beta.4",
42
+ "@nx/js": "17.3.0-beta.4",
43
+ "@nx/eslint": "17.3.0-beta.4",
44
+ "@nx/react": "17.3.0-beta.4",
45
+ "@nx/workspace": "17.3.0-beta.4",
46
+ "@nrwl/react-native": "17.3.0-beta.4"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "react-native": ">= 0.72.0 < 0.73.0"
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.reactNativeApplicationGeneratorInternal = exports.reactNativeApplicationGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
+ const js_1 = require("@nx/js");
5
6
  const symlink_task_1 = require("../../utils/symlink-task");
6
7
  const add_linting_1 = require("../../utils/add-linting");
7
8
  const add_jest_1 = require("../../utils/add-jest");
@@ -11,6 +12,7 @@ const init_1 = require("../init/init");
11
12
  const add_project_1 = require("./lib/add-project");
12
13
  const create_application_files_1 = require("./lib/create-application-files");
13
14
  const add_detox_1 = require("./lib/add-detox");
15
+ const ensure_dependencies_1 = require("../../utils/ensure-dependencies");
14
16
  async function reactNativeApplicationGenerator(host, schema) {
15
17
  return await reactNativeApplicationGeneratorInternal(host, {
16
18
  projectNameAndRootFormat: 'derived',
@@ -20,7 +22,17 @@ async function reactNativeApplicationGenerator(host, schema) {
20
22
  exports.reactNativeApplicationGenerator = reactNativeApplicationGenerator;
21
23
  async function reactNativeApplicationGeneratorInternal(host, schema) {
22
24
  const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
25
+ const tasks = [];
26
+ const jsInitTask = await (0, js_1.initGenerator)(host, {
27
+ ...schema,
28
+ skipFormat: true,
29
+ });
30
+ tasks.push(jsInitTask);
23
31
  const initTask = await (0, init_1.default)(host, { ...options, skipFormat: true });
32
+ tasks.push(initTask);
33
+ if (!options.skipPackageJson) {
34
+ tasks.push((0, ensure_dependencies_1.ensureDependencies)(host));
35
+ }
24
36
  (0, create_application_files_1.createApplicationFiles)(host, options);
25
37
  (0, add_project_1.addProject)(host, options);
26
38
  const lintTask = await (0, add_linting_1.addLinting)(host, {
@@ -30,14 +42,19 @@ async function reactNativeApplicationGeneratorInternal(host, schema) {
30
42
  (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'tsconfig.app.json'),
31
43
  ],
32
44
  });
45
+ tasks.push(lintTask);
33
46
  const jestTask = await (0, add_jest_1.addJest)(host, options.unitTestRunner, options.projectName, options.appProjectRoot, options.js, options.skipPackageJson);
47
+ tasks.push(jestTask);
34
48
  const detoxTask = await (0, add_detox_1.addDetox)(host, options);
49
+ tasks.push(detoxTask);
35
50
  const symlinkTask = (0, symlink_task_1.runSymlink)(host.root, options.appProjectRoot);
36
- const chmodTaskGradlew = (0, chmod_android_gradle_files_1.chmodAndroidGradlewFilesTask)((0, devkit_1.joinPathFragments)(host.root, options.androidProjectRoot));
51
+ tasks.push(symlinkTask);
52
+ const chmodTaskGradlewTask = (0, chmod_android_gradle_files_1.chmodAndroidGradlewFilesTask)((0, devkit_1.joinPathFragments)(host.root, options.androidProjectRoot));
53
+ tasks.push(chmodTaskGradlewTask);
37
54
  if (!options.skipFormat) {
38
55
  await (0, devkit_1.formatFiles)(host);
39
56
  }
40
- return (0, devkit_1.runTasksInSerial)(initTask, lintTask, jestTask, detoxTask, symlinkTask, chmodTaskGradlew);
57
+ return (0, devkit_1.runTasksInSerial)(...tasks);
41
58
  }
42
59
  exports.reactNativeApplicationGeneratorInternal = reactNativeApplicationGeneratorInternal;
43
60
  exports.default = reactNativeApplicationGenerator;
@@ -2,37 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.updateDependencies = 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 versions_1 = require("../../utils/versions");
10
6
  const add_git_ignore_entry_1 = require("./lib/add-git-ignore-entry");
11
7
  async function reactNativeInitGenerator(host, schema) {
12
8
  (0, add_git_ignore_entry_1.addGitIgnoreEntry)(host);
9
+ if (process.env.NX_PCV3 === 'true') {
10
+ addPlugin(host);
11
+ }
13
12
  const tasks = [];
14
- tasks.push(await (0, js_1.initGenerator)(host, {
15
- ...schema,
16
- skipFormat: true,
17
- }));
18
13
  if (!schema.skipPackageJson) {
19
- const installTask = updateDependencies(host);
20
14
  tasks.push(moveDependency(host));
21
- tasks.push(installTask);
22
- }
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);
33
- }
34
- if (process.env.NX_PCV3 === 'true') {
35
- addPlugin(host);
15
+ tasks.push(updateDependencies(host));
36
16
  }
37
17
  if (!schema.skipFormat) {
38
18
  await (0, devkit_1.formatFiles)(host);
@@ -41,38 +21,15 @@ async function reactNativeInitGenerator(host, schema) {
41
21
  }
42
22
  exports.reactNativeInitGenerator = reactNativeInitGenerator;
43
23
  function updateDependencies(host) {
44
- const isPnpm = (0, devkit_1.detectPackageManager)(host.root) === 'pnpm';
45
24
  return (0, devkit_1.addDependenciesToPackageJson)(host, {
46
- react: versions_2.reactVersion,
47
- 'react-dom': versions_2.reactDomVersion,
48
- 'react-native': versions_2.reactNativeVersion,
25
+ react: versions_1.reactVersion,
26
+ 'react-dom': versions_1.reactDomVersion,
27
+ 'react-native': versions_1.reactNativeVersion,
49
28
  }, {
50
- '@nx/react-native': versions_2.nxVersion,
51
- '@types/node': versions_2.typesNodeVersion,
52
- '@types/react': versions_2.typesReactVersion,
53
- '@react-native/metro-config': versions_2.reactNativeMetroConfigVersion,
54
- '@react-native-community/cli': versions_2.reactNativeCommunityCli,
55
- '@react-native-community/cli-platform-android': versions_2.reactNativeCommunityCliAndroid,
56
- '@react-native-community/cli-platform-ios': versions_2.reactNativeCommunityCliIos,
57
- '@testing-library/react-native': versions_2.testingLibraryReactNativeVersion,
58
- '@testing-library/jest-native': versions_2.testingLibraryJestNativeVersion,
59
- 'jest-react-native': versions_2.jestReactNativeVersion,
60
- metro: versions_2.metroVersion,
61
- 'metro-config': versions_2.metroVersion,
62
- 'metro-resolver': versions_2.metroVersion,
63
- 'metro-babel-register': versions_2.metroVersion,
64
- 'metro-react-native-babel-preset': versions_2.metroVersion,
65
- 'metro-react-native-babel-transformer': versions_2.metroVersion,
66
- 'react-test-renderer': versions_2.reactTestRendererVersion,
67
- 'react-native-svg-transformer': versions_2.reactNativeSvgTransformerVersion,
68
- 'react-native-svg': versions_2.reactNativeSvgVersion,
69
- '@babel/preset-react': versions_1.babelPresetReactVersion,
70
- '@babel/core': versions_1.babelCoreVersion,
71
- ...(isPnpm
72
- ? {
73
- '@babel/runtime': versions_2.babelRuntimeVersion, // @babel/runtime is used by react-native-svg
74
- }
75
- : {}),
29
+ '@nx/react-native': versions_1.nxVersion,
30
+ '@react-native-community/cli': versions_1.reactNativeCommunityCli,
31
+ '@react-native-community/cli-platform-android': versions_1.reactNativeCommunityCliAndroid,
32
+ '@react-native-community/cli-platform-ios': versions_1.reactNativeCommunityCliIos,
76
33
  });
77
34
  }
78
35
  exports.updateDependencies = updateDependencies;
@@ -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,10 @@ 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, {});
16
15
  const packageJson = readJson(tree, 'package.json');
17
16
  expect(packageJson.dependencies['react']).toBeDefined();
18
17
  expect(packageJson.dependencies['react-native']).toBeDefined();
19
- expect(packageJson.devDependencies['@types/node']).toBeDefined();
20
- expect(packageJson.devDependencies['@types/react']).toBeDefined();
21
18
  });
22
19
 
23
20
  it('should add .gitignore entries for React native files and directories', async () => {
@@ -27,7 +24,7 @@ describe('init', () => {
27
24
  /node_modules
28
25
  `
29
26
  );
30
- await reactNativeInitGenerator(tree, { e2eTestRunner: 'none' });
27
+ await reactNativeInitGenerator(tree, {});
31
28
 
32
29
  const content = tree.read('/.gitignore').toString();
33
30
 
@@ -1,7 +1,4 @@
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;
7
4
  }
@@ -6,29 +6,12 @@
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",
@@ -8,6 +8,7 @@ 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");
11
12
  async function reactNativeLibraryGenerator(host, schema) {
12
13
  return await reactNativeLibraryGeneratorInternal(host, {
13
14
  projectNameAndRootFormat: 'derived',
@@ -21,12 +22,16 @@ async function reactNativeLibraryGeneratorInternal(host, schema) {
21
22
  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
23
  }
23
24
  const tasks = [];
24
- const initTask = await (0, init_1.default)(host, {
25
- ...options,
25
+ const jsInitTask = await (0, js_1.initGenerator)(host, {
26
+ ...schema,
26
27
  skipFormat: true,
27
- e2eTestRunner: 'none',
28
28
  });
29
+ tasks.push(jsInitTask);
30
+ const initTask = await (0, init_1.default)(host, { ...options, skipFormat: true });
29
31
  tasks.push(initTask);
32
+ if (!options.skipPackageJson) {
33
+ tasks.push((0, ensure_dependencies_1.ensureDependencies)(host));
34
+ }
30
35
  const addProjectTask = await addProject(host, options);
31
36
  if (addProjectTask) {
32
37
  tasks.push(addProjectTask);
@@ -57,45 +62,45 @@ async function reactNativeLibraryGeneratorInternal(host, schema) {
57
62
  }
58
63
  exports.reactNativeLibraryGeneratorInternal = reactNativeLibraryGeneratorInternal;
59
64
  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, {
65
+ const project = {
92
66
  root: options.projectRoot,
93
67
  sourceRoot: (0, devkit_1.joinPathFragments)(options.projectRoot, 'src'),
94
68
  projectType: 'library',
95
69
  tags: options.parsedTags,
96
- targets,
70
+ targets: {},
71
+ };
72
+ (0, devkit_1.addProjectConfiguration)(host, options.name, project);
73
+ if (!options.publishable && !options.buildable) {
74
+ return () => { };
75
+ }
76
+ const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rollup', versions_1.nxVersion);
77
+ const rollupConfigTask = await configurationGenerator(host, {
78
+ ...options,
79
+ project: options.name,
80
+ skipFormat: true,
97
81
  });
98
- return task;
82
+ const external = ['react/jsx-runtime', 'react-native', 'react', 'react-dom'];
83
+ project.targets.build = {
84
+ executor: '@nx/rollup:rollup',
85
+ outputs: ['{options.outputPath}'],
86
+ options: {
87
+ outputPath: `dist/${options.projectRoot}`,
88
+ tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
89
+ project: `${options.projectRoot}/package.json`,
90
+ entryFile: maybeJs(options, `${options.projectRoot}/src/index.ts`),
91
+ external,
92
+ rollupConfig: `@nx/react/plugins/bundle-rollup`,
93
+ assets: [
94
+ {
95
+ glob: `${options.projectRoot}/README.md`,
96
+ input: '.',
97
+ output: '.',
98
+ },
99
+ ],
100
+ },
101
+ };
102
+ (0, devkit_1.updateProjectConfiguration)(host, options.name, project);
103
+ return rollupConfigTask;
99
104
  }
100
105
  function updateTsConfig(tree, options) {
101
106
  (0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.json'), (json) => {
@@ -0,0 +1,2 @@
1
+ import { GeneratorCallback, Tree } from '@nx/devkit';
2
+ export declare function ensureDependencies(tree: Tree): GeneratorCallback;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureDependencies = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const versions_1 = require("@nx/react/src/utils/versions");
6
+ const versions_2 = require("./versions");
7
+ function ensureDependencies(tree) {
8
+ const isPnpm = (0, devkit_1.detectPackageManager)(tree.root) === 'pnpm';
9
+ return (0, devkit_1.addDependenciesToPackageJson)(tree, {}, {
10
+ '@types/node': versions_2.typesNodeVersion,
11
+ '@types/react': versions_2.typesReactVersion,
12
+ '@react-native/metro-config': versions_2.reactNativeMetroConfigVersion,
13
+ '@testing-library/react-native': versions_2.testingLibraryReactNativeVersion,
14
+ '@testing-library/jest-native': versions_2.testingLibraryJestNativeVersion,
15
+ 'jest-react-native': versions_2.jestReactNativeVersion,
16
+ metro: versions_2.metroVersion,
17
+ 'metro-config': versions_2.metroVersion,
18
+ 'metro-resolver': versions_2.metroVersion,
19
+ 'metro-babel-register': versions_2.metroVersion,
20
+ 'metro-react-native-babel-preset': versions_2.metroVersion,
21
+ 'metro-react-native-babel-transformer': versions_2.metroVersion,
22
+ 'react-test-renderer': versions_2.reactTestRendererVersion,
23
+ 'react-native-svg-transformer': versions_2.reactNativeSvgTransformerVersion,
24
+ 'react-native-svg': versions_2.reactNativeSvgVersion,
25
+ '@babel/preset-react': versions_1.babelPresetReactVersion,
26
+ '@babel/core': versions_1.babelCoreVersion,
27
+ ...(isPnpm
28
+ ? {
29
+ '@babel/runtime': versions_2.babelRuntimeVersion, // @babel/runtime is used by react-native-svg
30
+ }
31
+ : {}),
32
+ });
33
+ }
34
+ exports.ensureDependencies = ensureDependencies;