@nx/react-native 20.2.1 → 20.2.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/package.json +7 -7
- package/src/generators/application/files/app/.babelrc.js.template +1 -1
- package/src/generators/application/files/app/tsconfig.app.json.template +11 -1
- package/src/generators/component/component.js +12 -20
- package/src/generators/component/files/js/__fileName__.__ext__ +28 -0
- package/src/generators/component/files/{__fileName__.tsx__tmpl__ → ts/__fileName__.__ext__} +6 -6
- package/src/generators/component/files/ts/__fileName__.spec.__ext__ +11 -0
- package/src/generators/component/lib/normalize-options.d.ts +4 -1
- package/src/generators/component/lib/normalize-options.js +6 -16
- package/src/generators/component/schema.d.ts +4 -0
- package/src/generators/component/schema.json +8 -4
- package/src/generators/library/files/lib/tsconfig.lib.json.template +11 -1
- package/src/generators/web-configuration/files/base-vite/.babelrc.js.template +1 -1
- package/src/generators/web-configuration/files/base-webpack/.babelrc.js.template +1 -1
- /package/src/generators/component/files/{__fileName__.spec.tsx__tmpl__ → js/__fileName__.spec.__ext__} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/react-native",
|
|
3
|
-
"version": "20.2.
|
|
3
|
+
"version": "20.2.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,12 +36,12 @@
|
|
|
36
36
|
"node-fetch": "^2.6.7",
|
|
37
37
|
"tsconfig-paths": "^4.1.2",
|
|
38
38
|
"tslib": "^2.3.0",
|
|
39
|
-
"@nx/devkit": "20.2.
|
|
40
|
-
"@nx/jest": "20.2.
|
|
41
|
-
"@nx/js": "20.2.
|
|
42
|
-
"@nx/eslint": "20.2.
|
|
43
|
-
"@nx/react": "20.2.
|
|
44
|
-
"@nx/workspace": "20.2.
|
|
39
|
+
"@nx/devkit": "20.2.2",
|
|
40
|
+
"@nx/jest": "20.2.2",
|
|
41
|
+
"@nx/js": "20.2.2",
|
|
42
|
+
"@nx/eslint": "20.2.2",
|
|
43
|
+
"@nx/react": "20.2.2",
|
|
44
|
+
"@nx/workspace": "20.2.2"
|
|
45
45
|
},
|
|
46
46
|
"executors": "./executors.json",
|
|
47
47
|
"ng-update": {
|
|
@@ -5,6 +5,16 @@
|
|
|
5
5
|
"types": ["node"]
|
|
6
6
|
},
|
|
7
7
|
"files": ["<%= offsetFromRoot %>node_modules/@nx/react-native/typings/svg.d.ts"],
|
|
8
|
-
"exclude": [
|
|
8
|
+
"exclude": [
|
|
9
|
+
"src/**/*.test.ts",
|
|
10
|
+
"src/**/*.spec.ts",
|
|
11
|
+
"src/**/*.test.tsx",
|
|
12
|
+
"src/**/*.spec.tsx",
|
|
13
|
+
"src/**/*.test.js",
|
|
14
|
+
"src/**/*.spec.js",
|
|
15
|
+
"src/**/*.test.jsx",
|
|
16
|
+
"src/**/*.spec.jsx",
|
|
17
|
+
"src/test-setup.ts"
|
|
18
|
+
],
|
|
9
19
|
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.js", "src/**/*.jsx"]
|
|
10
20
|
}
|
|
@@ -13,21 +13,12 @@ async function reactNativeComponentGenerator(host, schema) {
|
|
|
13
13
|
await (0, devkit_1.formatFiles)(host);
|
|
14
14
|
}
|
|
15
15
|
function createComponentFiles(host, options) {
|
|
16
|
-
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, '
|
|
16
|
+
(0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, 'files', options.fileExtensionType), options.directory, {
|
|
17
17
|
...options,
|
|
18
|
-
|
|
18
|
+
ext: options.fileExtension,
|
|
19
19
|
});
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (options.skipTests && /.*spec.tsx/.test(c.path)) {
|
|
23
|
-
deleteFile = true;
|
|
24
|
-
}
|
|
25
|
-
if (deleteFile) {
|
|
26
|
-
host.delete(c.path);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
if (options.js) {
|
|
30
|
-
(0, devkit_1.toJS)(host);
|
|
20
|
+
if (options.skipTests) {
|
|
21
|
+
host.delete((0, devkit_1.joinPathFragments)(options.directory, `${options.fileName}.spec.${options.fileExtension}`));
|
|
31
22
|
}
|
|
32
23
|
}
|
|
33
24
|
let tsModule;
|
|
@@ -38,14 +29,15 @@ function addExportsToBarrel(host, options) {
|
|
|
38
29
|
const workspace = (0, devkit_1.getProjects)(host);
|
|
39
30
|
const isApp = workspace.get(options.projectName).projectType === 'application';
|
|
40
31
|
if (options.export && !isApp) {
|
|
41
|
-
const indexFilePath = (0, devkit_1.joinPathFragments)(options.projectSourceRoot, options.js ? 'index.js' : 'index.ts');
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const indexSourceFile = tsModule.createSourceFile(indexFilePath, indexSource, tsModule.ScriptTarget.Latest, true);
|
|
45
|
-
const relativePathFromIndex = getRelativeImportToFile(indexFilePath, options.filePath);
|
|
46
|
-
const changes = (0, devkit_1.applyChangesToString)(indexSource, (0, add_import_1.addImport)(indexSourceFile, `export * from '${relativePathFromIndex}';`));
|
|
47
|
-
host.write(indexFilePath, changes);
|
|
32
|
+
const indexFilePath = (0, devkit_1.joinPathFragments)(options.projectSourceRoot, options.fileExtensionType === 'js' ? 'index.js' : 'index.ts');
|
|
33
|
+
if (!host.exists(indexFilePath)) {
|
|
34
|
+
return;
|
|
48
35
|
}
|
|
36
|
+
const indexSource = host.read(indexFilePath, 'utf-8');
|
|
37
|
+
const indexSourceFile = tsModule.createSourceFile(indexFilePath, indexSource, tsModule.ScriptTarget.Latest, true);
|
|
38
|
+
const relativePathFromIndex = getRelativeImportToFile(indexFilePath, options.filePath);
|
|
39
|
+
const changes = (0, devkit_1.applyChangesToString)(indexSource, (0, add_import_1.addImport)(indexSourceFile, `export * from '${relativePathFromIndex}';`));
|
|
40
|
+
host.write(indexFilePath, changes);
|
|
49
41
|
}
|
|
50
42
|
}
|
|
51
43
|
function getRelativeImportToFile(indexPath, filePath) {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
<%_ if (classComponent) { _%>
|
|
2
|
+
import { Component } from 'react';
|
|
3
|
+
<%_ } else { _%>
|
|
4
|
+
import React from 'react';
|
|
5
|
+
<%_ } _%>
|
|
6
|
+
import { View, Text } from 'react-native';
|
|
7
|
+
|
|
8
|
+
<%_ if (classComponent) { _%>
|
|
9
|
+
export class <%= className %> extends Component {
|
|
10
|
+
render() {
|
|
11
|
+
return (
|
|
12
|
+
<View>
|
|
13
|
+
<Text>Welcome to <%= name %>!</Text>
|
|
14
|
+
</View>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
<%_ } else { _%>
|
|
19
|
+
export function <%= className %>(props) {
|
|
20
|
+
return (
|
|
21
|
+
<View>
|
|
22
|
+
<Text>Welcome to <%= name %>!</Text>
|
|
23
|
+
</View>
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
<%_ } _%>
|
|
27
|
+
|
|
28
|
+
export default <%= className %>;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
<% if (classComponent) { %>
|
|
1
|
+
<%_ if (classComponent) { _%>
|
|
2
2
|
import { Component } from 'react';
|
|
3
|
-
<% } else { %>
|
|
3
|
+
<%_ } else { _%>
|
|
4
4
|
import React from 'react';
|
|
5
|
-
<% } %>
|
|
5
|
+
<%_ } _%>
|
|
6
6
|
import { View, Text } from 'react-native';
|
|
7
7
|
|
|
8
8
|
/* eslint-disable-next-line */
|
|
9
9
|
export interface <%= className %>Props {
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
<% if (classComponent) { %>
|
|
12
|
+
<%_ if (classComponent) { _%>
|
|
13
13
|
export class <%= className %> extends Component<<%= className %>Props> {
|
|
14
14
|
render() {
|
|
15
15
|
return (
|
|
@@ -19,7 +19,7 @@ export class <%= className %> extends Component<<%= className %>Props> {
|
|
|
19
19
|
);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
-
<% } else { %>
|
|
22
|
+
<%_ } else { _%>
|
|
23
23
|
export function <%= className %>(props: <%= className %>Props) {
|
|
24
24
|
return (
|
|
25
25
|
<View>
|
|
@@ -27,6 +27,6 @@ export function <%= className %>(props: <%= className %>Props) {
|
|
|
27
27
|
</View>
|
|
28
28
|
);
|
|
29
29
|
}
|
|
30
|
-
<% } %>
|
|
30
|
+
<%_ } _%>
|
|
31
31
|
|
|
32
32
|
export default <%= className %>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { render } from '@testing-library/react-native';
|
|
3
|
+
|
|
4
|
+
import <%= className %> from './<%= fileName %>';
|
|
5
|
+
|
|
6
|
+
describe('<%= className %>', () => {
|
|
7
|
+
it('should render successfully', () => {
|
|
8
|
+
const { root } = render(< <%= className %> />);
|
|
9
|
+
expect(root).toBeTruthy();
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { Tree } from '@nx/devkit';
|
|
2
|
+
import { type FileExtensionType } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
|
|
2
3
|
import { Schema } from '../schema';
|
|
3
|
-
export interface NormalizedSchema extends Schema {
|
|
4
|
+
export interface NormalizedSchema extends Omit<Schema, 'js'> {
|
|
4
5
|
directory: string;
|
|
5
6
|
projectSourceRoot: string;
|
|
6
7
|
fileName: string;
|
|
7
8
|
className: string;
|
|
8
9
|
filePath: string;
|
|
10
|
+
fileExtension: string;
|
|
11
|
+
fileExtensionType: FileExtensionType;
|
|
9
12
|
projectName: string;
|
|
10
13
|
}
|
|
11
14
|
export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
|
|
@@ -4,12 +4,13 @@ exports.normalizeOptions = normalizeOptions;
|
|
|
4
4
|
const devkit_1 = require("@nx/devkit");
|
|
5
5
|
const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
|
|
6
6
|
async function normalizeOptions(host, options) {
|
|
7
|
-
const { artifactName: name, directory, fileName, filePath, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
|
|
7
|
+
const { artifactName: name, directory, fileName, filePath, fileExtension, fileExtensionType, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
|
|
8
8
|
path: options.path,
|
|
9
9
|
name: options.name,
|
|
10
|
-
|
|
10
|
+
allowedFileExtensions: ['js', 'jsx', 'ts', 'tsx'],
|
|
11
|
+
fileExtension: options.js ? 'js' : 'tsx',
|
|
12
|
+
js: options.js,
|
|
11
13
|
});
|
|
12
|
-
assertValidOptions({ name, directory });
|
|
13
14
|
const project = (0, devkit_1.getProjects)(host).get(projectName);
|
|
14
15
|
const { className } = (0, devkit_1.names)(name);
|
|
15
16
|
const { sourceRoot: projectSourceRoot, projectType } = project;
|
|
@@ -24,20 +25,9 @@ async function normalizeOptions(host, options) {
|
|
|
24
25
|
className,
|
|
25
26
|
fileName,
|
|
26
27
|
filePath,
|
|
28
|
+
fileExtension,
|
|
29
|
+
fileExtensionType,
|
|
27
30
|
projectSourceRoot,
|
|
28
31
|
projectName,
|
|
29
32
|
};
|
|
30
33
|
}
|
|
31
|
-
function assertValidOptions(options) {
|
|
32
|
-
const slashes = ['/', '\\'];
|
|
33
|
-
slashes.forEach((s) => {
|
|
34
|
-
if (options.name.indexOf(s) !== -1) {
|
|
35
|
-
const [name, ...rest] = options.name.split(s).reverse();
|
|
36
|
-
let suggestion = rest.map((x) => x.toLowerCase()).join(s);
|
|
37
|
-
if (options.directory) {
|
|
38
|
-
suggestion = `${options.directory}${s}${suggestion}`;
|
|
39
|
-
}
|
|
40
|
-
throw new Error(`Found "${s}" in the component name. Did you mean to use the --path option (e.g. \`nx g c ${suggestion}/${name} \`)?`);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
}
|
|
@@ -7,5 +7,9 @@ export interface Schema {
|
|
|
7
7
|
skipTests?: boolean;
|
|
8
8
|
export?: boolean;
|
|
9
9
|
classComponent?: boolean;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @deprecated Provide the full file path including the file extension in the `path` option. This option will be removed in Nx v21.
|
|
13
|
+
*/
|
|
10
14
|
js?: boolean;
|
|
11
15
|
}
|
|
@@ -8,11 +8,15 @@
|
|
|
8
8
|
"examples": [
|
|
9
9
|
{
|
|
10
10
|
"description": "Generate a component with the exported symbol matching the file name. It results in the component `Foo` at `mylib/src/lib/foo.tsx`",
|
|
11
|
-
"command": "nx g @nx/react-native:component mylib/src/lib/foo"
|
|
11
|
+
"command": "nx g @nx/react-native:component mylib/src/lib/foo.tsx"
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
14
|
"description": "Generate a component with the exported symbol different from the file name. It results in the component `Custom` at `mylib/src/lib/foo.tsx`",
|
|
15
|
-
"command": "nx g @nx/react-native:component mylib/src/lib/foo --name=custom"
|
|
15
|
+
"command": "nx g @nx/react-native:component mylib/src/lib/foo.tsx --name=custom"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
"description": "Generate a component without providing the file extension. It results in the component `Foo` at `mylib/src/lib/foo.tsx`",
|
|
19
|
+
"command": "nx g @nx/react-native:component mylib/src/lib/foo"
|
|
16
20
|
},
|
|
17
21
|
{
|
|
18
22
|
"description": "Generate a class component at `mylib/src/lib/foo.tsx`",
|
|
@@ -22,7 +26,7 @@
|
|
|
22
26
|
"properties": {
|
|
23
27
|
"path": {
|
|
24
28
|
"type": "string",
|
|
25
|
-
"description": "The file path to the component
|
|
29
|
+
"description": "The file path to the component. Relative to the current working directory.",
|
|
26
30
|
"$default": {
|
|
27
31
|
"$source": "argv",
|
|
28
32
|
"index": 0
|
|
@@ -36,7 +40,7 @@
|
|
|
36
40
|
"js": {
|
|
37
41
|
"type": "boolean",
|
|
38
42
|
"description": "Generate JavaScript files rather than TypeScript files.",
|
|
39
|
-
"
|
|
43
|
+
"x-deprecated": "Provide the full file path including the file extension in the `path` option. This option will be removed in Nx v21."
|
|
40
44
|
},
|
|
41
45
|
"skipTests": {
|
|
42
46
|
"type": "boolean",
|
|
@@ -4,6 +4,16 @@
|
|
|
4
4
|
"outDir": "<%= offsetFromRoot %>dist/out-tsc",
|
|
5
5
|
"types": ["node"]
|
|
6
6
|
},
|
|
7
|
-
"exclude": [
|
|
7
|
+
"exclude": [
|
|
8
|
+
"src/**/*.test.ts",
|
|
9
|
+
"src/**/*.spec.ts",
|
|
10
|
+
"src/**/*.test.tsx",
|
|
11
|
+
"src/**/*.spec.tsx",
|
|
12
|
+
"src/**/*.test.js",
|
|
13
|
+
"src/**/*.spec.js",
|
|
14
|
+
"src/**/*.test.jsx",
|
|
15
|
+
"src/**/*.spec.jsx",
|
|
16
|
+
"src/test-setup.ts"
|
|
17
|
+
],
|
|
8
18
|
"include": ["src/**/*.js", "src/**/*.jsx", "src/**/*.ts", "src/**/*.tsx"]
|
|
9
19
|
}
|
|
File without changes
|