@nx/react-native 17.0.0-beta.5 → 17.0.0-beta.8

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/generators.json CHANGED
@@ -24,7 +24,7 @@
24
24
  "description": "Create a React Native library."
25
25
  },
26
26
  "component": {
27
- "factory": "./src/generators/component/component#reactNativeComponentGenerator",
27
+ "factory": "./src/generators/component/component#reactNativeComponentGeneratorInternal",
28
28
  "schema": "./src/generators/component/schema.json",
29
29
  "description": "Create a React Native component.",
30
30
  "aliases": ["c"]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/react-native",
3
- "version": "17.0.0-beta.5",
3
+ "version": "17.0.0-beta.8",
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.0.0-beta.5",
40
- "@nx/devkit": "17.0.0-beta.5",
41
- "@nx/jest": "17.0.0-beta.5",
42
- "@nx/js": "17.0.0-beta.5",
43
- "@nx/linter": "17.0.0-beta.5",
44
- "@nx/react": "17.0.0-beta.5",
45
- "@nx/workspace": "17.0.0-beta.5",
46
- "@nrwl/react-native": "17.0.0-beta.5"
39
+ "@nx/detox": "17.0.0-beta.8",
40
+ "@nx/devkit": "17.0.0-beta.8",
41
+ "@nx/jest": "17.0.0-beta.8",
42
+ "@nx/js": "17.0.0-beta.8",
43
+ "@nx/eslint": "17.0.0-beta.8",
44
+ "@nx/react": "17.0.0-beta.8",
45
+ "@nx/workspace": "17.0.0-beta.8",
46
+ "@nrwl/react-native": "17.0.0-beta.8"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "react-native": ">= 0.72.0 < 0.73.0"
@@ -5,7 +5,7 @@ import {
5
5
  readProjectConfiguration,
6
6
  } from '@nx/devkit';
7
7
  import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
8
- import { Linter } from '@nx/linter';
8
+ import { Linter } from '@nx/eslint';
9
9
  import { reactNativeApplicationGenerator } from './application';
10
10
 
11
11
  describe('app', () => {
@@ -2,14 +2,14 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addDetox = void 0;
4
4
  const detox_1 = require("@nx/detox");
5
- const linter_1 = require("@nx/linter");
5
+ const eslint_1 = require("@nx/eslint");
6
6
  async function addDetox(host, options) {
7
7
  if (options?.e2eTestRunner !== 'detox') {
8
8
  return () => { };
9
9
  }
10
10
  return (0, detox_1.detoxApplicationGenerator)(host, {
11
11
  ...options,
12
- linter: linter_1.Linter.EsLint,
12
+ linter: eslint_1.Linter.EsLint,
13
13
  e2eName: `${options.projectName}-e2e`,
14
14
  e2eDirectory: `${options.appProjectRoot}-e2e`,
15
15
  projectNameAndRootFormat: 'as-provided',
@@ -1,6 +1,6 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
3
- import { Linter } from '@nx/linter';
3
+ import { Linter } from '@nx/eslint';
4
4
  import { Schema } from '../schema';
5
5
  import { normalizeOptions } from './normalize-options';
6
6
 
@@ -1,5 +1,5 @@
1
1
  import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
- import type { Linter } from '@nx/linter';
2
+ import type { Linter } from '@nx/eslint';
3
3
 
4
4
  export interface Schema {
5
5
  name: string;
@@ -1,4 +1,5 @@
1
1
  import { Schema } from './schema';
2
2
  import { Tree } from '@nx/devkit';
3
3
  export declare function reactNativeComponentGenerator(host: Tree, schema: Schema): Promise<void>;
4
+ export declare function reactNativeComponentGeneratorInternal(host: Tree, schema: Schema): Promise<void>;
4
5
  export default reactNativeComponentGenerator;
@@ -1,21 +1,27 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.reactNativeComponentGenerator = void 0;
3
+ exports.reactNativeComponentGeneratorInternal = exports.reactNativeComponentGenerator = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const normalize_options_1 = require("./lib/normalize-options");
6
6
  const add_import_1 = require("./lib/add-import");
7
7
  const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
8
8
  const path_1 = require("path");
9
9
  async function reactNativeComponentGenerator(host, schema) {
10
+ return reactNativeComponentGeneratorInternal(host, {
11
+ nameAndDirectoryFormat: 'derived',
12
+ ...schema,
13
+ });
14
+ }
15
+ exports.reactNativeComponentGenerator = reactNativeComponentGenerator;
16
+ async function reactNativeComponentGeneratorInternal(host, schema) {
10
17
  const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
11
18
  createComponentFiles(host, options);
12
19
  addExportsToBarrel(host, options);
13
20
  await (0, devkit_1.formatFiles)(host);
14
21
  }
15
- exports.reactNativeComponentGenerator = reactNativeComponentGenerator;
22
+ exports.reactNativeComponentGeneratorInternal = reactNativeComponentGeneratorInternal;
16
23
  function createComponentFiles(host, options) {
17
- const componentDir = (0, devkit_1.joinPathFragments)(options.projectSourceRoot, options.directory);
18
- (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files'), componentDir, {
24
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files'), options.directory, {
19
25
  ...options,
20
26
  tmpl: '',
21
27
  });
@@ -44,9 +50,15 @@ function addExportsToBarrel(host, options) {
44
50
  const indexSource = host.read(indexFilePath, 'utf-8');
45
51
  if (indexSource !== null) {
46
52
  const indexSourceFile = tsModule.createSourceFile(indexFilePath, indexSource, tsModule.ScriptTarget.Latest, true);
47
- const changes = (0, devkit_1.applyChangesToString)(indexSource, (0, add_import_1.addImport)(indexSourceFile, `export * from './${options.directory}/${options.fileName}';`));
53
+ const relativePathFromIndex = getRelativeImportToFile(indexFilePath, options.filePath);
54
+ const changes = (0, devkit_1.applyChangesToString)(indexSource, (0, add_import_1.addImport)(indexSourceFile, `export * from '${relativePathFromIndex}';`));
48
55
  host.write(indexFilePath, changes);
49
56
  }
50
57
  }
51
58
  }
59
+ function getRelativeImportToFile(indexPath, filePath) {
60
+ const { name, dir } = (0, path_1.parse)(filePath);
61
+ const relativeDirToTarget = (0, path_1.relative)((0, path_1.dirname)(indexPath), dir);
62
+ return `./${(0, devkit_1.joinPathFragments)(relativeDirToTarget, name)}`;
63
+ }
52
64
  exports.default = reactNativeComponentGenerator;
@@ -4,5 +4,6 @@ export interface NormalizedSchema extends Schema {
4
4
  projectSourceRoot: string;
5
5
  fileName: string;
6
6
  className: string;
7
+ filePath: string;
7
8
  }
8
9
  export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
@@ -2,17 +2,24 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
+ const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
5
6
  async function normalizeOptions(host, options) {
6
7
  assertValidOptions(options);
7
- const { className, fileName } = (0, devkit_1.names)(options.name);
8
- const componentFileName = options.pascalCaseFiles ? className : fileName;
9
- const project = (0, devkit_1.getProjects)(host).get(options.project);
10
- if (!project) {
11
- devkit_1.logger.error(`Cannot find the ${options.project} project. Please double check the project name.`);
12
- throw new Error();
13
- }
8
+ const { artifactName: name, directory, fileName, filePath, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
9
+ artifactType: 'component',
10
+ callingGenerator: '@nx/react-native:component',
11
+ name: options.name,
12
+ directory: options.directory,
13
+ derivedDirectory: options.directory,
14
+ flat: options.flat,
15
+ nameAndDirectoryFormat: options.nameAndDirectoryFormat,
16
+ project: options.project,
17
+ fileExtension: 'tsx',
18
+ pascalCaseFile: options.pascalCaseFiles,
19
+ });
20
+ const project = (0, devkit_1.getProjects)(host).get(projectName);
21
+ const { className } = (0, devkit_1.names)(name);
14
22
  const { sourceRoot: projectSourceRoot, projectType } = project;
15
- const directory = await getDirectory(host, options);
16
23
  if (options.export && projectType === 'application') {
17
24
  devkit_1.logger.warn(`The "--export" option should not be used with applications and will do nothing.`);
18
25
  }
@@ -21,26 +28,12 @@ async function normalizeOptions(host, options) {
21
28
  ...options,
22
29
  directory,
23
30
  className,
24
- fileName: componentFileName,
31
+ fileName,
32
+ filePath,
25
33
  projectSourceRoot,
26
34
  };
27
35
  }
28
36
  exports.normalizeOptions = normalizeOptions;
29
- async function getDirectory(host, options) {
30
- const fileName = (0, devkit_1.names)(options.name).fileName;
31
- const workspace = (0, devkit_1.getProjects)(host);
32
- let baseDir;
33
- if (options.directory) {
34
- baseDir = options.directory;
35
- }
36
- else {
37
- baseDir =
38
- workspace.get(options.project).projectType === 'application'
39
- ? 'app'
40
- : 'lib';
41
- }
42
- return options.flat ? baseDir : (0, devkit_1.joinPathFragments)(baseDir, fileName);
43
- }
44
37
  function assertValidOptions(options) {
45
38
  const slashes = ['/', '\\'];
46
39
  slashes.forEach((s) => {
@@ -3,12 +3,22 @@
3
3
  */
4
4
  export interface Schema {
5
5
  name: string;
6
+ /**
7
+ * @deprecated Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v18.
8
+ */
6
9
  project: string;
7
10
  skipTests?: boolean;
8
11
  directory?: string;
9
12
  export?: boolean;
13
+ /**
14
+ * @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v18.
15
+ */
10
16
  pascalCaseFiles?: boolean;
11
17
  classComponent?: boolean;
12
18
  js?: boolean;
19
+ /**
20
+ * @deprecated Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v18.
21
+ */
13
22
  flat?: boolean;
23
+ nameAndDirectoryFormat?: 'as-provided' | 'derived';
14
24
  }
@@ -23,7 +23,7 @@
23
23
  "$default": {
24
24
  "$source": "projectName"
25
25
  },
26
- "x-prompt": "What is the name of the project for this component?"
26
+ "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. The project will be determined from the directory provided. It will be removed in Nx v18."
27
27
  },
28
28
  "name": {
29
29
  "type": "string",
@@ -46,13 +46,19 @@
46
46
  },
47
47
  "directory": {
48
48
  "type": "string",
49
- "description": "Create the component under this directory (can be nested).",
49
+ "description": "The directory at which to create the component file. When `--nameAndDirectoryFormat=as-provided`, it will be relative to the current working directory. Otherwise, it will be relative to the project root.",
50
50
  "x-priority": "important"
51
51
  },
52
+ "nameAndDirectoryFormat": {
53
+ "description": "Whether to generate the component in the directory as provided, relative to the current working directory and ignoring the project (`as-provided`) or generate it using the project and directory relative to the workspace root (`derived`).",
54
+ "type": "string",
55
+ "enum": ["as-provided", "derived"]
56
+ },
52
57
  "flat": {
53
58
  "type": "boolean",
54
59
  "description": "Create component at the source root rather than its own directory.",
55
- "default": false
60
+ "default": false,
61
+ "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v18."
56
62
  },
57
63
  "export": {
58
64
  "type": "boolean",
@@ -65,7 +71,8 @@
65
71
  "type": "boolean",
66
72
  "description": "Use pascal case component file name (e.g. `App.tsx`).",
67
73
  "alias": "P",
68
- "default": false
74
+ "default": false,
75
+ "x-deprecated": "Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v18."
69
76
  },
70
77
  "classComponent": {
71
78
  "type": "boolean",
@@ -74,5 +81,5 @@
74
81
  "default": false
75
82
  }
76
83
  },
77
- "required": ["name", "project"]
84
+ "required": ["name"]
78
85
  }
@@ -1,7 +1,7 @@
1
1
  import { getProjects, Tree, updateProjectConfiguration } from '@nx/devkit';
2
2
  import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
3
3
  import componentStoryGenerator from './component-story';
4
- import { Linter } from '@nx/linter';
4
+ import { Linter } from '@nx/eslint';
5
5
 
6
6
  import { formatFile } from '../../utils/format-file';
7
7
  import libraryGenerator from '../library/library';
@@ -75,9 +75,9 @@ describe('react-native:component-story', () => {
75
75
  appTree.write(
76
76
  'test-ui-lib/src/lib/test-ui-libplain.jsx',
77
77
  `import React from 'react';
78
-
78
+
79
79
  import './test.scss';
80
-
80
+
81
81
  export const Test = () => {
82
82
  return (
83
83
  <div>
@@ -85,8 +85,8 @@ describe('react-native:component-story', () => {
85
85
  </div>
86
86
  );
87
87
  };
88
-
89
- export default Test;
88
+
89
+ export default Test;
90
90
  `
91
91
  );
92
92
 
@@ -117,7 +117,7 @@ describe('react-native:component-story', () => {
117
117
  `import React from 'react';
118
118
 
119
119
  import { View, Text } from 'react-native';
120
-
120
+
121
121
  export function Test() {
122
122
  return (
123
123
  <View>
@@ -125,8 +125,8 @@ describe('react-native:component-story', () => {
125
125
  </View>
126
126
  );
127
127
  }
128
-
129
- export default Test;
128
+
129
+ export default Test;
130
130
  `
131
131
  );
132
132
  await componentStoryGenerator(appTree, {
@@ -178,14 +178,14 @@ describe('react-native:component-story', () => {
178
178
  `import React from 'react';
179
179
 
180
180
  export type ButtonStyle = 'default' | 'primary' | 'warning';
181
-
181
+
182
182
  export interface TestProps {
183
183
  name: string;
184
184
  displayAge: boolean;
185
185
  someAction: (e: unknown) => void;
186
186
  style: ButtonStyle;
187
187
  }
188
-
188
+
189
189
  export const Test = (props: TestProps) => {
190
190
  return (
191
191
  <div>
@@ -194,8 +194,8 @@ describe('react-native:component-story', () => {
194
194
  </div>
195
195
  );
196
196
  };
197
-
198
- export default Test;
197
+
198
+ export default Test;
199
199
  `
200
200
  );
201
201
 
@@ -337,12 +337,12 @@ describe('react-native:component-story', () => {
337
337
  appTree.write(
338
338
  cmpPath,
339
339
  `import React from 'react';
340
-
340
+
341
341
  export interface TestProps {
342
342
  name: string;
343
343
  displayAge: boolean;
344
344
  }
345
-
345
+
346
346
  ${config.src}
347
347
  `
348
348
  );
@@ -6,7 +6,7 @@ import {
6
6
  } from '@nx/devkit';
7
7
  import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
8
8
  import libraryGenerator from './library';
9
- import { Linter } from '@nx/linter';
9
+ import { Linter } from '@nx/eslint';
10
10
  import { Schema } from './schema';
11
11
 
12
12
  describe('lib', () => {
@@ -34,7 +34,7 @@ describe('lib', () => {
34
34
  expect(projectConfiguration.root).toEqual('my-lib');
35
35
  expect(projectConfiguration.targets.build).toBeUndefined();
36
36
  expect(projectConfiguration.targets.lint).toEqual({
37
- executor: '@nx/linter:eslint',
37
+ executor: '@nx/eslint:lint',
38
38
  outputs: ['{options.outputFile}'],
39
39
  options: {
40
40
  lintFilePatterns: ['my-lib/**/*.{ts,tsx,js,jsx}'],
@@ -155,7 +155,7 @@ describe('lib', () => {
155
155
 
156
156
  expect(projectConfiguration.root).toEqual('my-dir');
157
157
  expect(projectConfiguration.targets.lint).toEqual({
158
- executor: '@nx/linter:eslint',
158
+ executor: '@nx/eslint:lint',
159
159
  outputs: ['{options.outputFile}'],
160
160
  options: {
161
161
  lintFilePatterns: ['my-dir/**/*.{ts,tsx,js,jsx}'],
@@ -225,7 +225,7 @@ describe('lib', () => {
225
225
  const projectConfiguration = readProjectConfiguration(appTree, 'my-lib');
226
226
  expect(projectConfiguration.targets.test).toBeUndefined();
227
227
  expect(projectConfiguration.targets.lint).toMatchObject({
228
- executor: '@nx/linter:eslint',
228
+ executor: '@nx/eslint:lint',
229
229
  options: {
230
230
  lintFilePatterns: ['my-lib/**/*.{ts,tsx,js,jsx}'],
231
231
  },
@@ -1,5 +1,5 @@
1
1
  import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
- import type { Linter } from '@nx/linter';
2
+ import type { Linter } from '@nx/eslint';
3
3
 
4
4
  /**
5
5
  * Same as the @nx/react library schema, except it removes keys: style, component, routing, appProject
@@ -2,7 +2,7 @@ import { Tree } from '@nx/devkit';
2
2
  import storiesGenerator from './stories';
3
3
  import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
4
4
  import applicationGenerator from '../application/application';
5
- import { Linter } from '@nx/linter';
5
+ import { Linter } from '@nx/eslint';
6
6
  import { reactNativeComponentGenerator } from '../component/component';
7
7
 
8
8
  describe('react:stories for applications', () => {
@@ -2,7 +2,7 @@ import { Tree } from '@nx/devkit';
2
2
  import storiesGenerator from './stories';
3
3
  import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
4
4
  import applicationGenerator from '../application/application';
5
- import { Linter } from '@nx/linter';
5
+ import { Linter } from '@nx/eslint';
6
6
  import libraryGenerator from '../library/library';
7
7
  import reactNativeComponentGenerator from '../component/component';
8
8
 
@@ -1,6 +1,6 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
3
- import { Linter } from '@nx/linter';
3
+ import { Linter } from '@nx/eslint';
4
4
  import { logger } from '@nx/devkit';
5
5
 
6
6
  import libraryGenerator from '../library/library';
@@ -1,4 +1,4 @@
1
- import { Linter } from '@nx/linter';
1
+ import { Linter } from '@nx/eslint';
2
2
 
3
3
  export interface StorybookConfigureSchema {
4
4
  name: string;
@@ -1,4 +1,4 @@
1
- import { Linter } from '@nx/linter';
1
+ import { Linter } from '@nx/eslint';
2
2
 
3
3
  export interface UpgradeNativeConfigureSchema {
4
4
  name: string;
@@ -1,4 +1,4 @@
1
- import { Linter } from '@nx/linter';
1
+ import { Linter } from '@nx/eslint';
2
2
  import { GeneratorCallback, Tree } from '@nx/devkit';
3
3
  interface NormalizedSchema {
4
4
  linter?: Linter;
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.addLinting = void 0;
4
- const linter_1 = require("@nx/linter");
4
+ const eslint_1 = require("@nx/eslint");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const lint_1 = require("@nx/react/src/utils/lint");
7
- const eslint_file_1 = require("@nx/linter/src/generators/utils/eslint-file");
7
+ const eslint_file_1 = require("@nx/eslint/src/generators/utils/eslint-file");
8
8
  async function addLinting(host, options) {
9
- if (options.linter === linter_1.Linter.None) {
9
+ if (options.linter === eslint_1.Linter.None) {
10
10
  return () => { };
11
11
  }
12
12
  const tasks = [];
13
- const lintTask = await (0, linter_1.lintProjectGenerator)(host, {
13
+ const lintTask = await (0, eslint_1.lintProjectGenerator)(host, {
14
14
  linter: options.linter,
15
15
  project: options.projectName,
16
16
  tsConfigPaths: options.tsConfigPaths,
@@ -1,6 +1,6 @@
1
1
  import { readProjectConfiguration, Tree } from '@nx/devkit';
2
2
  import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing';
3
- import { Linter } from '@nx/linter';
3
+ import { Linter } from '@nx/eslint';
4
4
  import { libraryGenerator } from '@nx/js';
5
5
  import { addLinting } from './add-linting';
6
6
 
@@ -25,7 +25,7 @@ describe('Add Linting', () => {
25
25
  const project = readProjectConfiguration(tree, 'my-lib');
26
26
 
27
27
  expect(project.targets.lint).toBeDefined();
28
- expect(project.targets.lint.executor).toEqual('@nx/linter:eslint');
28
+ expect(project.targets.lint.executor).toEqual('@nx/eslint:lint');
29
29
  });
30
30
 
31
31
  it('should not add lint target when "none" is passed', async () => {
@@ -3,10 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createLib = exports.createApp = void 0;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const application_1 = require("../generators/application/application");
6
- const linter_1 = require("@nx/linter");
6
+ const eslint_1 = require("@nx/eslint");
7
7
  async function createApp(tree, appName) {
8
8
  await (0, application_1.default)(tree, {
9
- linter: linter_1.Linter.EsLint,
9
+ linter: eslint_1.Linter.EsLint,
10
10
  skipFormat: true,
11
11
  style: 'css',
12
12
  unitTestRunner: 'none',