@nx/expo 20.2.1 → 20.3.0-beta.0

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/expo",
3
- "version": "20.2.1",
3
+ "version": "20.3.0-beta.0",
4
4
  "private": false,
5
5
  "description": "The Expo Plugin for Nx contains executors and generators for managing and developing an expo application within your workspace. For example, you can directly build for different target platforms as well as generate projects and publish your code.",
6
6
  "keywords": [
@@ -28,13 +28,13 @@
28
28
  "main": "./index",
29
29
  "types": "index.d.ts",
30
30
  "dependencies": {
31
- "@nx/devkit": "20.2.1",
32
- "@nx/eslint": "20.2.1",
33
- "@nx/jest": "20.2.1",
34
- "@nx/js": "20.2.1",
35
- "@nx/react": "20.2.1",
36
- "@nx/web": "20.2.1",
37
- "@nx/webpack": "20.2.1",
31
+ "@nx/devkit": "20.3.0-beta.0",
32
+ "@nx/eslint": "20.3.0-beta.0",
33
+ "@nx/jest": "20.3.0-beta.0",
34
+ "@nx/js": "20.3.0-beta.0",
35
+ "@nx/react": "20.3.0-beta.0",
36
+ "@nx/web": "20.3.0-beta.0",
37
+ "@nx/webpack": "20.3.0-beta.0",
38
38
  "enhanced-resolve": "^5.8.3",
39
39
  "metro-config": "~0.80.4",
40
40
  "metro-resolver": "~0.80.4",
@@ -5,6 +5,16 @@
5
5
  "types": ["node"]
6
6
  },
7
7
  "files": ["<%= offsetFromRoot %>node_modules/@nx/expo/typings/svg.d.ts"],
8
- "exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.spec.tsx", "src/test-setup.ts"],
8
+ "exclude": [
9
+ "**/*.test.ts",
10
+ "**/*.spec.ts",
11
+ "**/*.test.tsx",
12
+ "**/*.spec.tsx",
13
+ "**/*.test.js",
14
+ "**/*.spec.js",
15
+ "**/*.test.jsx",
16
+ "**/*.spec.jsx",
17
+ "src/test-setup.ts"
18
+ ],
9
19
  "include": ["**/*.ts", "**/*.tsx", "**/*.js", "**/*.jsx"]
10
20
  }
@@ -15,35 +15,27 @@ async function expoComponentGenerator(host, schema) {
15
15
  }
16
16
  }
17
17
  function createComponentFiles(host, options) {
18
- (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files'), options.directory, {
18
+ (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, './files', options.fileExtensionType), options.directory, {
19
19
  ...options,
20
- tmpl: '',
20
+ ext: options.fileExtension,
21
21
  });
22
- for (const c of host.listChanges()) {
23
- let deleteFile = false;
24
- if (options.skipTests && /.*spec.tsx/.test(c.path)) {
25
- deleteFile = true;
26
- }
27
- if (deleteFile) {
28
- host.delete(c.path);
29
- }
30
- }
31
- if (options.js) {
32
- (0, devkit_1.toJS)(host);
22
+ if (options.skipTests) {
23
+ host.delete((0, devkit_1.joinPathFragments)(options.directory, `${options.fileName}.spec.${options.fileExtension}`));
33
24
  }
34
25
  }
35
26
  function addExportsToBarrel(host, options) {
36
27
  const workspace = (0, devkit_1.getProjects)(host);
37
28
  const isApp = workspace.get(options.projectName).projectType === 'application';
38
29
  if (options.export && !isApp) {
39
- const indexFilePath = (0, devkit_1.joinPathFragments)(options.projectSourceRoot, options.js ? 'index.js' : 'index.ts');
40
- const indexSource = host.read(indexFilePath, 'utf-8');
41
- if (indexSource !== null) {
42
- const indexSourceFile = ts.createSourceFile(indexFilePath, indexSource, ts.ScriptTarget.Latest, true);
43
- const relativePathFromIndex = getRelativeImportToFile(indexFilePath, options.filePath);
44
- const changes = (0, devkit_1.applyChangesToString)(indexSource, (0, add_import_1.addImport)(indexSourceFile, `export * from '${relativePathFromIndex}';`));
45
- host.write(indexFilePath, changes);
30
+ const indexFilePath = (0, devkit_1.joinPathFragments)(options.projectSourceRoot, options.fileExtensionType === 'js' ? 'index.js' : 'index.ts');
31
+ if (!host.exists(indexFilePath)) {
32
+ return;
46
33
  }
34
+ const indexSource = host.read(indexFilePath, 'utf-8');
35
+ const indexSourceFile = ts.createSourceFile(indexFilePath, indexSource, ts.ScriptTarget.Latest, true);
36
+ const relativePathFromIndex = getRelativeImportToFile(indexFilePath, options.filePath);
37
+ const changes = (0, devkit_1.applyChangesToString)(indexSource, (0, add_import_1.addImport)(indexSourceFile, `export * from '${relativePathFromIndex}';`));
38
+ host.write(indexFilePath, changes);
47
39
  }
48
40
  }
49
41
  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,6 +1,5 @@
1
1
  import React from 'react';
2
2
  import { render } from '@testing-library/react-native';
3
-
4
3
  import <%= className %> from './<%= fileName %>';
5
4
 
6
5
  describe('<%= 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,10 @@
1
+ import React from 'react';
2
+ import { render } from '@testing-library/react-native';
3
+ import <%= className %> from './<%= fileName %>';
4
+
5
+ describe('<%= className %>', () => {
6
+ it('should render successfully', () => {
7
+ const { root } = render(< <%= className %> />);
8
+ expect(root).toBeTruthy();
9
+ });
10
+ });
@@ -1,9 +1,12 @@
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;
8
+ fileExtension: string;
9
+ fileExtensionType: FileExtensionType;
7
10
  className: string;
8
11
  filePath: string;
9
12
  projectName: string;
@@ -4,13 +4,15 @@ 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, fileName, filePath, directory, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
7
+ const { artifactName: name, fileName, fileExtension, fileExtensionType, filePath, directory, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
8
8
  name: options.name,
9
9
  path: options.path,
10
- fileExtension: 'tsx',
10
+ allowedFileExtensions: ['js', 'jsx', 'ts', 'tsx'],
11
+ fileExtension: options.js ? 'js' : 'tsx',
12
+ js: options.js,
11
13
  });
12
- const project = (0, devkit_1.getProjects)(host).get(projectName);
13
14
  const { className } = (0, devkit_1.names)(name);
15
+ const project = (0, devkit_1.getProjects)(host).get(projectName);
14
16
  const { sourceRoot: projectSourceRoot, projectType } = project;
15
17
  if (options.export && projectType === 'application') {
16
18
  devkit_1.logger.warn(`The "--export" option should not be used with applications and will do nothing.`);
@@ -22,6 +24,8 @@ async function normalizeOptions(host, options) {
22
24
  directory,
23
25
  className,
24
26
  fileName,
27
+ fileExtension,
28
+ fileExtensionType,
25
29
  filePath,
26
30
  projectSourceRoot,
27
31
  projectName,
@@ -4,9 +4,13 @@
4
4
  export interface Schema {
5
5
  path: string;
6
6
  name?: string;
7
- skipFormat: boolean; // default is false
8
- skipTests: boolean; // default is false
9
- export: boolean; // default is false
10
- classComponent: boolean; // default is false
11
- js: boolean; // default is false
7
+ skipFormat?: boolean;
8
+ skipTests?: boolean;
9
+ export?: boolean;
10
+ classComponent?: boolean;
11
+
12
+ /**
13
+ * @deprecated Provide the full file path including the file extension in the `path` option. This option will be removed in Nx v21.
14
+ */
15
+ js?: boolean;
12
16
  }
@@ -7,11 +7,15 @@
7
7
  "examples": [
8
8
  {
9
9
  "description": "Generate a component with the exported symbol matching the file name. It results in the component `Foo` at `mylib/src/foo.tsx`",
10
- "command": "nx g @nx/expo:component mylib/src/foo"
10
+ "command": "nx g @nx/expo:component mylib/src/foo.tsx"
11
11
  },
12
12
  {
13
13
  "description": "Generate a component with the exported symbol different from the file name. It results in the component `Custom` at `mylib/src/foo.tsx`",
14
- "command": "nx g @nx/expo:component mylib/src/foo --name=custom"
14
+ "command": "nx g @nx/expo:component mylib/src/foo.tsx --name=custom"
15
+ },
16
+ {
17
+ "description": "Generate a component without the providing the file extension. It results in the component `Foo` at `mylib/src/foo.tsx`",
18
+ "command": "nx g @nx/expo:component mylib/src/foo"
15
19
  },
16
20
  {
17
21
  "description": "Generate a class component at `mylib/src/foo.tsx`",
@@ -21,7 +25,7 @@
21
25
  "properties": {
22
26
  "path": {
23
27
  "type": "string",
24
- "description": "The file path to the component without the file extension. Relative to the current working directory.",
28
+ "description": "The file path to the component. Relative to the current working directory.",
25
29
  "$default": {
26
30
  "$source": "argv",
27
31
  "index": 0
@@ -35,7 +39,7 @@
35
39
  "js": {
36
40
  "type": "boolean",
37
41
  "description": "Generate JavaScript files rather than TypeScript files.",
38
- "default": false
42
+ "x-deprecated": "Provide the full file path including the file extension in the `path` option. This option will be removed in Nx v21."
39
43
  },
40
44
  "skipFormat": {
41
45
  "description": "Skip formatting files.",
@@ -4,6 +4,16 @@
4
4
  "outDir": "<%= offsetFromRoot %>dist/out-tsc",
5
5
  "types": ["node"]
6
6
  },
7
- "exclude": ["**/*.spec.ts", "**/*.spec.tsx", "src/test-setup.ts"],
7
+ "exclude": [
8
+ "**/*.test.ts",
9
+ "**/*.spec.ts",
10
+ "**/*.test.tsx",
11
+ "**/*.spec.tsx",
12
+ "**/*.test.js",
13
+ "**/*.spec.js",
14
+ "**/*.test.jsx",
15
+ "**/*.spec.jsx",
16
+ "src/test-setup.ts"
17
+ ],
8
18
  "include": ["**/*.js", "**/*.jsx", "**/*.ts", "**/*.tsx"]
9
19
  }