@nx/react-native 0.0.0-pr-31222-862e973 → 0.0.0-pr-31313-387cdca

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.
Files changed (97) hide show
  1. package/.eslintrc.json +4 -0
  2. package/LICENSE +1 -1
  3. package/README.md +1 -1
  4. package/generators.json +1 -1
  5. package/migrations.json +69 -335
  6. package/package.json +8 -10
  7. package/plugin.d.ts +1 -1
  8. package/plugin.js +2 -2
  9. package/plugins/metro-resolver.js +11 -11
  10. package/plugins/plugin.d.ts +2 -2
  11. package/plugins/plugin.js +57 -34
  12. package/project.json +2 -8
  13. package/src/executors/run-android/schema.json +1 -0
  14. package/src/executors/run-ios/schema.json +1 -0
  15. package/src/executors/start/lib/is-packager-running.js +1 -2
  16. package/src/executors/start/schema.json +1 -0
  17. package/src/executors/storybook/storybook.impl.js +3 -3
  18. package/src/executors/sync-deps/sync-deps.impl.js +4 -4
  19. package/src/generators/application/application.js +24 -4
  20. package/src/generators/application/files/app/.babelrc.js.template +1 -1
  21. package/src/generators/application/files/app/Gemfile.template +4 -4
  22. package/src/generators/application/files/app/android/app/build.gradle.template +9 -8
  23. package/src/generators/application/files/app/android/app/src/main/AndroidManifest.xml.template +1 -0
  24. package/src/generators/application/files/app/android/app/src/main/java/com/__lowerCaseName__/MainApplication.kt.template +7 -6
  25. package/src/generators/application/files/app/android/build.gradle.template +4 -4
  26. package/src/generators/application/files/app/android/gradle/wrapper/gradle-wrapper.properties +1 -1
  27. package/src/generators/application/files/app/android/gradle.properties +1 -3
  28. package/src/generators/application/files/app/android/gradlew.bat +94 -92
  29. package/src/generators/application/files/app/android/gradlew.template +5 -2
  30. package/src/generators/application/files/app/android/settings.gradle.template +3 -1
  31. package/src/generators/application/files/app/tsconfig.app.json.template +11 -1
  32. package/src/generators/application/files/app/tsconfig.json.template +2 -0
  33. package/src/generators/application/lib/add-e2e.js +2 -1
  34. package/src/generators/application/lib/add-project.js +26 -3
  35. package/src/generators/application/lib/normalize-options.d.ts +3 -1
  36. package/src/generators/application/lib/normalize-options.js +9 -5
  37. package/src/generators/application/schema.d.ts +6 -5
  38. package/src/generators/application/schema.json +20 -18
  39. package/src/generators/component/component.d.ts +0 -1
  40. package/src/generators/component/component.js +20 -29
  41. package/src/generators/component/files/js/__fileName__.__ext__ +28 -0
  42. package/src/generators/component/files/{__fileName__.tsx__tmpl__ → ts/__fileName__.__ext__} +6 -6
  43. package/src/generators/component/files/ts/__fileName__.spec.__ext__ +11 -0
  44. package/src/generators/component/lib/normalize-options.d.ts +6 -1
  45. package/src/generators/component/lib/normalize-options.js +13 -26
  46. package/src/generators/component/schema.d.ts +6 -14
  47. package/src/generators/component/schema.json +26 -40
  48. package/src/generators/convert-to-inferred/convert-to-inferred.js +1 -1
  49. package/src/generators/init/init.js +1 -1
  50. package/src/generators/library/files/lib/tsconfig.json.template +2 -0
  51. package/src/generators/library/files/lib/tsconfig.lib.json.template +11 -1
  52. package/src/generators/library/lib/normalize-options.d.ts +2 -0
  53. package/src/generators/library/lib/normalize-options.js +6 -3
  54. package/src/generators/library/library.js +119 -60
  55. package/src/generators/library/schema.d.ts +3 -5
  56. package/src/generators/library/schema.json +17 -21
  57. package/src/generators/storybook-configuration/schema.json +2 -1
  58. package/src/generators/web-configuration/files/base-vite/.babelrc.js.template +1 -1
  59. package/src/generators/web-configuration/files/base-vite/vite.config.ts__tmpl__ +4 -9
  60. package/src/generators/web-configuration/files/base-webpack/.babelrc.js.template +1 -1
  61. package/src/generators/web-configuration/files/base-webpack/webpack.config.js__tmpl__ +4 -0
  62. package/src/generators/web-configuration/schema.json +1 -1
  63. package/src/generators/web-configuration/web-configuration.js +7 -0
  64. package/src/utils/add-jest.d.ts +1 -1
  65. package/src/utils/add-jest.js +2 -1
  66. package/src/utils/add-linting.js +3 -2
  67. package/src/utils/ensure-dependencies.js +2 -0
  68. package/src/utils/pod-install-task.js +6 -6
  69. package/src/utils/testing-generators.js +2 -4
  70. package/src/utils/versions.d.ts +17 -13
  71. package/src/utils/versions.js +18 -14
  72. package/src/generators/library/files/lib/package.json.template +0 -4
  73. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.d.ts +0 -2
  74. package/src/migrations/update-16-0-0-add-nx-packages/update-16-0-0-add-nx-packages.js +0 -9
  75. package/src/migrations/update-16-1-0/upgrade-storybook-6-5.d.ts +0 -6
  76. package/src/migrations/update-16-1-0/upgrade-storybook-6-5.js +0 -21
  77. package/src/migrations/update-16-6-0/add-depends-on.d.ts +0 -6
  78. package/src/migrations/update-16-6-0/add-depends-on.js +0 -63
  79. package/src/migrations/update-16-6-0/update-metro-config.d.ts +0 -6
  80. package/src/migrations/update-16-6-0/update-metro-config.js +0 -63
  81. package/src/migrations/update-16-9-0/remove-types-react-native.d.ts +0 -7
  82. package/src/migrations/update-16-9-0/remove-types-react-native.js +0 -13
  83. package/src/migrations/update-18-0-0/add-upgrade-target.d.ts +0 -6
  84. package/src/migrations/update-18-0-0/add-upgrade-target.js +0 -31
  85. package/src/migrations/update-18-0-0/add-web-configuration.d.ts +0 -8
  86. package/src/migrations/update-18-0-0/add-web-configuration.js +0 -33
  87. package/src/migrations/update-18-0-0/change-storybook-targets.d.ts +0 -5
  88. package/src/migrations/update-18-0-0/change-storybook-targets.js +0 -57
  89. package/src/migrations/update-18-0-0/remove-block-list.d.ts +0 -6
  90. package/src/migrations/update-18-0-0/remove-block-list.js +0 -28
  91. package/src/migrations/update-18-0-0/remove-metro.d.ts +0 -14
  92. package/src/migrations/update-18-0-0/remove-metro.js +0 -29
  93. package/src/migrations/update-18-0-0/remove-symlink-target.d.ts +0 -6
  94. package/src/migrations/update-18-0-0/remove-symlink-target.js +0 -30
  95. package/src/utils/format-file.d.ts +0 -1
  96. package/src/utils/format-file.js +0 -15
  97. /package/src/generators/component/files/{__fileName__.spec.tsx__tmpl__ → js/__fileName__.spec.__ext__} +0 -0
@@ -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,10 +1,15 @@
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'> {
5
+ directory: string;
4
6
  projectSourceRoot: string;
5
7
  fileName: string;
6
8
  className: string;
7
9
  filePath: string;
10
+ fileExtension: string;
11
+ fileExtensionType: FileExtensionType;
8
12
  projectName: string;
13
+ projectRoot: string;
9
14
  }
10
15
  export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
@@ -3,47 +3,34 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  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
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
6
7
  async function normalizeOptions(host, options) {
7
- assertValidOptions(options);
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',
8
+ const { artifactName: name, directory, fileName, filePath, fileExtension, fileExtensionType, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
9
+ path: options.path,
11
10
  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,
11
+ allowedFileExtensions: ['js', 'jsx', 'ts', 'tsx'],
12
+ fileExtension: options.js ? 'js' : 'tsx',
13
+ js: options.js,
19
14
  });
20
15
  const project = (0, devkit_1.getProjects)(host).get(projectName);
21
16
  const { className } = (0, devkit_1.names)(name);
22
- const { sourceRoot: projectSourceRoot, projectType } = project;
23
- if (options.export && projectType === 'application') {
17
+ const { root, sourceRoot: projectSourceRoot, projectType } = project;
18
+ if (options.export &&
19
+ (0, ts_solution_setup_1.getProjectType)(host, root, projectType) === 'application') {
24
20
  devkit_1.logger.warn(`The "--export" option should not be used with applications and will do nothing.`);
25
21
  }
26
22
  options.classComponent = options.classComponent ?? false;
27
23
  return {
28
24
  ...options,
25
+ name,
29
26
  directory,
30
27
  className,
31
28
  fileName,
32
29
  filePath,
30
+ fileExtension,
31
+ fileExtensionType,
33
32
  projectSourceRoot,
34
33
  projectName,
34
+ projectRoot: root,
35
35
  };
36
36
  }
37
- function assertValidOptions(options) {
38
- const slashes = ['/', '\\'];
39
- slashes.forEach((s) => {
40
- if (options.name.indexOf(s) !== -1) {
41
- const [name, ...rest] = options.name.split(s).reverse();
42
- let suggestion = rest.map((x) => x.toLowerCase()).join(s);
43
- if (options.directory) {
44
- suggestion = `${options.directory}${s}${suggestion}`;
45
- }
46
- throw new Error(`Found "${s}" in the component name. Did you mean to use the --directory option (e.g. \`nx g c ${name} --directory ${suggestion}\`)?`);
47
- }
48
- });
49
- }
@@ -2,23 +2,15 @@
2
2
  * Same as the @nx/react library schema, except it removes keys: style, routing, globalCss
3
3
  */
4
4
  export interface Schema {
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 v20.
8
- */
9
- project: string;
5
+ path: string;
6
+ name?: string;
10
7
  skipTests?: boolean;
11
- directory?: string;
12
8
  export?: boolean;
13
- /**
14
- * @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19.
15
- */
16
- pascalCaseFiles?: boolean;
17
9
  classComponent?: boolean;
18
- js?: boolean;
10
+ skipFormat?: boolean;
11
+
19
12
  /**
20
- * @deprecated Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19.
13
+ * @deprecated Provide the full file path including the file extension in the `path` option. This option will be removed in Nx v21.
21
14
  */
22
- flat?: boolean;
23
- nameAndDirectoryFormat?: 'as-provided' | 'derived';
15
+ js?: boolean;
24
16
  }
@@ -7,59 +7,46 @@
7
7
  "type": "object",
8
8
  "examples": [
9
9
  {
10
- "command": "nx g @nx/react-native:component my-component --project=mylib",
11
- "description": "Generate a component in the `mylib` library"
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.tsx"
12
12
  },
13
13
  {
14
- "command": "nx g @nx/react-native:component my-component --project=mylib --classComponent",
15
- "description": "Generate a class component in the `mylib` library"
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.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"
20
+ },
21
+ {
22
+ "description": "Generate a class component at `mylib/src/lib/foo.tsx`",
23
+ "command": "nx g @nx/react-native:component mylib/src/lib/foo --classComponent"
16
24
  }
17
25
  ],
18
26
  "properties": {
19
- "project": {
27
+ "path": {
20
28
  "type": "string",
21
- "description": "The name of the project.",
22
- "alias": "p",
29
+ "description": "The file path to the component. Relative to the current working directory.",
23
30
  "$default": {
24
- "$source": "projectName"
31
+ "$source": "argv",
32
+ "index": 0
25
33
  },
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 v20."
34
+ "x-prompt": "What is the component file path?"
27
35
  },
28
36
  "name": {
29
37
  "type": "string",
30
- "description": "The name of the component.",
31
- "$default": {
32
- "$source": "argv",
33
- "index": 0
34
- },
35
- "x-prompt": "What name would you like to use for the component?"
38
+ "description": "The component symbol name. Defaults to the last segment of the file path."
36
39
  },
37
40
  "js": {
38
41
  "type": "boolean",
39
42
  "description": "Generate JavaScript files rather than TypeScript files.",
40
- "default": false
43
+ "x-deprecated": "Provide the full file path including the file extension in the `path` option. This option will be removed in Nx v21."
41
44
  },
42
45
  "skipTests": {
43
46
  "type": "boolean",
44
47
  "description": "When true, does not create `spec.ts` test files for the new component.",
45
48
  "default": false
46
49
  },
47
- "directory": {
48
- "type": "string",
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
- "x-priority": "important"
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
- },
57
- "flat": {
58
- "type": "boolean",
59
- "description": "Create component at the source root rather than its own directory.",
60
- "default": false,
61
- "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19."
62
- },
63
50
  "export": {
64
51
  "type": "boolean",
65
52
  "description": "When true, the component is exported from the project `index.ts` (if it exists).",
@@ -67,19 +54,18 @@
67
54
  "default": false,
68
55
  "x-prompt": "Should this component be exported in the project?"
69
56
  },
70
- "pascalCaseFiles": {
71
- "type": "boolean",
72
- "description": "Use pascal case component file name (e.g. `App.tsx`).",
73
- "alias": "P",
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 v19."
76
- },
77
57
  "classComponent": {
78
58
  "type": "boolean",
79
59
  "alias": "C",
80
60
  "description": "Use class components instead of functional component.",
81
61
  "default": false
62
+ },
63
+ "skipFormat": {
64
+ "description": "Skip formatting files.",
65
+ "type": "boolean",
66
+ "default": false,
67
+ "x-priority": "internal"
82
68
  }
83
69
  },
84
- "required": ["name"]
70
+ "required": ["path"]
85
71
  }
@@ -11,7 +11,7 @@ const create_process_options_1 = require("./lib/create-process-options");
11
11
  async function convertToInferred(tree, options) {
12
12
  const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
13
13
  const migrationLogs = new aggregate_log_util_1.AggregatedLog();
14
- const migratedProjects = await (0, executor_to_plugin_migrator_1.migrateProjectExecutorsToPluginV1)(tree, projectGraph, '@nx/react-native/plugin', plugin_1.createNodes, {
14
+ const migratedProjects = await (0, executor_to_plugin_migrator_1.migrateProjectExecutorsToPlugin)(tree, projectGraph, '@nx/react-native/plugin', plugin_1.createNodesV2, {
15
15
  buildAndroidTargetName: 'build-android',
16
16
  buildIosTargetName: 'build-ios',
17
17
  bundleTargetName: 'bundle',
@@ -21,7 +21,7 @@ async function reactNativeInitGeneratorInternal(host, schema) {
21
21
  nxJson.useInferencePlugins !== false;
22
22
  schema.addPlugin ??= addPluginDefault;
23
23
  if (schema.addPlugin) {
24
- await (0, add_plugin_1.addPluginV1)(host, await (0, devkit_1.createProjectGraphAsync)(), '@nx/react-native/plugin', plugin_1.createNodes, {
24
+ await (0, add_plugin_1.addPlugin)(host, await (0, devkit_1.createProjectGraphAsync)(), '@nx/react-native/plugin', plugin_1.createNodesV2, {
25
25
  startTargetName: ['start', 'react-native:start', 'react-native-start'],
26
26
  upgradeTargetName: [
27
27
  'update',
@@ -1,11 +1,13 @@
1
1
  {
2
2
  "extends": "<%= rootTsConfigPath %>",
3
+ <%_ if (!isUsingTsSolutionConfig) { _%>
3
4
  "compilerOptions": {
4
5
  "jsx": "react-jsx",
5
6
  "allowJs": true,
6
7
  "esModuleInterop": true,
7
8
  "allowSyntheticDefaultImports": true
8
9
  },
10
+ <%_ } _%>
9
11
  "files": [],
10
12
  "include": [],
11
13
  "references": [
@@ -4,6 +4,16 @@
4
4
  "outDir": "<%= offsetFromRoot %>dist/out-tsc",
5
5
  "types": ["node"]
6
6
  },
7
- "exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.spec.tsx", "src/test-setup.ts"],
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
  }
@@ -4,9 +4,11 @@ export interface NormalizedSchema extends Schema {
4
4
  name: string;
5
5
  fileName: string;
6
6
  projectRoot: string;
7
+ importPath: string;
7
8
  routePath: string;
8
9
  parsedTags: string[];
9
10
  appMain?: string;
10
11
  appSourceRoot?: string;
12
+ isUsingTsSolutionConfig: boolean;
11
13
  }
12
14
  export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = normalizeOptions;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
6
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
6
7
  async function normalizeOptions(host, options) {
8
+ await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'library');
7
9
  const { projectName, names: projectNames, projectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
8
10
  name: options.name,
9
11
  projectType: 'library',
10
12
  directory: options.directory,
11
13
  importPath: options.importPath,
12
- projectNameAndRootFormat: options.projectNameAndRootFormat,
13
- callingGenerator: '@nx/react-native:library',
14
14
  });
15
15
  const nxJson = (0, devkit_1.readNxJson)(host);
16
16
  const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
@@ -19,14 +19,17 @@ async function normalizeOptions(host, options) {
19
19
  const parsedTags = options.tags
20
20
  ? options.tags.split(',').map((s) => s.trim())
21
21
  : [];
22
+ const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
22
23
  const normalized = {
23
24
  ...options,
24
25
  fileName: projectName,
25
26
  routePath: `/${projectNames.projectSimpleName}`,
26
- name: projectName,
27
+ name: isUsingTsSolutionConfig && !options.name ? importPath : projectName,
27
28
  projectRoot,
28
29
  parsedTags,
29
30
  importPath,
31
+ isUsingTsSolutionConfig,
32
+ useProjectJson: options.useProjectJson ?? !isUsingTsSolutionConfig,
30
33
  };
31
34
  return normalized;
32
35
  }
@@ -7,38 +7,47 @@ const js_1 = require("@nx/js");
7
7
  const init_1 = require("../init/init");
8
8
  const add_linting_1 = require("../../utils/add-linting");
9
9
  const add_jest_1 = require("../../utils/add-jest");
10
- const versions_1 = require("../../utils/versions");
10
+ const component_1 = require("../component/component");
11
11
  const normalize_options_1 = require("./lib/normalize-options");
12
12
  const ensure_dependencies_1 = require("../../utils/ensure-dependencies");
13
13
  const log_show_project_command_1 = require("@nx/devkit/src/utils/log-show-project-command");
14
+ const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
15
+ const sort_fields_1 = require("@nx/js/src/utils/package-json/sort-fields");
16
+ const add_rollup_build_target_1 = require("@nx/react/src/generators/library/lib/add-rollup-build-target");
17
+ const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
18
+ const path_1 = require("path");
19
+ const versions_1 = require("../../utils/versions");
14
20
  async function reactNativeLibraryGenerator(host, schema) {
15
21
  return await reactNativeLibraryGeneratorInternal(host, {
16
22
  addPlugin: false,
17
- projectNameAndRootFormat: 'derived',
23
+ useProjectJson: true,
18
24
  ...schema,
19
25
  });
20
26
  }
21
27
  async function reactNativeLibraryGeneratorInternal(host, schema) {
22
- const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
23
- if (options.publishable === true && !schema.importPath) {
24
- 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)`);
25
- }
26
28
  const tasks = [];
27
29
  const jsInitTask = await (0, js_1.initGenerator)(host, {
28
30
  ...schema,
29
31
  skipFormat: true,
30
32
  });
31
33
  tasks.push(jsInitTask);
34
+ const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
35
+ if (options.publishable === true && !schema.importPath) {
36
+ 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)`);
37
+ }
32
38
  const initTask = await (0, init_1.default)(host, { ...options, skipFormat: true });
33
39
  tasks.push(initTask);
34
40
  if (!options.skipPackageJson) {
35
41
  tasks.push((0, ensure_dependencies_1.ensureDependencies)(host));
36
42
  }
43
+ createFiles(host, options);
44
+ if (options.isUsingTsSolutionConfig) {
45
+ await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.projectRoot);
46
+ }
37
47
  const addProjectTask = await addProject(host, options);
38
48
  if (addProjectTask) {
39
49
  tasks.push(addProjectTask);
40
50
  }
41
- createFiles(host, options);
42
51
  const lintTask = await (0, add_linting_1.addLinting)(host, {
43
52
  ...options,
44
53
  projectName: options.name,
@@ -47,19 +56,38 @@ async function reactNativeLibraryGeneratorInternal(host, schema) {
47
56
  ],
48
57
  });
49
58
  tasks.push(lintTask);
50
- const jestTask = await (0, add_jest_1.addJest)(host, options.unitTestRunner, options.name, options.projectRoot, options.js, options.skipPackageJson, options.addPlugin);
59
+ const jestTask = await (0, add_jest_1.addJest)(host, options.unitTestRunner, options.name, options.projectRoot, options.js, options.skipPackageJson, options.addPlugin, 'tsconfig.lib.json');
51
60
  tasks.push(jestTask);
52
- if (options.publishable || options.buildable) {
53
- updateLibPackageNpmScope(host, options);
54
- }
55
- if (!options.skipTsConfig) {
61
+ const relativeCwd = (0, artifact_name_and_directory_utils_1.getRelativeCwd)();
62
+ const path = (0, devkit_1.joinPathFragments)(options.projectRoot, 'src/lib', options.fileName);
63
+ const componentTask = await (0, component_1.default)(host, {
64
+ path: relativeCwd ? (0, path_1.relative)(relativeCwd, path) : path,
65
+ skipTests: options.unitTestRunner === 'none',
66
+ export: true,
67
+ skipFormat: true,
68
+ js: options.js,
69
+ });
70
+ tasks.push(() => componentTask);
71
+ if (!options.skipTsConfig && !options.isUsingTsSolutionConfig) {
56
72
  (0, js_1.addTsConfigPath)(host, options.importPath, [
57
73
  (0, devkit_1.joinPathFragments)(options.projectRoot, './src', 'index.' + (options.js ? 'js' : 'ts')),
58
74
  ]);
59
75
  }
76
+ (0, ts_solution_setup_1.updateTsconfigFiles)(host, options.projectRoot, 'tsconfig.lib.json', {
77
+ jsx: 'react-jsx',
78
+ module: 'esnext',
79
+ moduleResolution: 'bundler',
80
+ }, options.linter === 'eslint'
81
+ ? ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
82
+ : undefined);
83
+ (0, sort_fields_1.sortPackageJsonFields)(host, options.projectRoot);
60
84
  if (!options.skipFormat) {
61
85
  await (0, devkit_1.formatFiles)(host);
62
86
  }
87
+ // Always run install to link packages.
88
+ if (options.isUsingTsSolutionConfig) {
89
+ tasks.push(() => (0, devkit_1.installPackagesTask)(host, true));
90
+ }
63
91
  tasks.push(() => {
64
92
  (0, log_show_project_command_1.logShowProjectCommand)(options.name);
65
93
  });
@@ -73,40 +101,67 @@ async function addProject(host, options) {
73
101
  tags: options.parsedTags,
74
102
  targets: {},
75
103
  };
76
- (0, devkit_1.addProjectConfiguration)(host, options.name, project);
77
- if (!options.publishable && !options.buildable) {
78
- return () => { };
79
- }
80
- const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rollup', versions_1.nxVersion);
81
- const rollupConfigTask = await configurationGenerator(host, {
82
- ...options,
83
- project: options.name,
84
- skipFormat: true,
85
- });
86
- const external = ['react/jsx-runtime', 'react-native', 'react', 'react-dom'];
87
- project.targets.build = {
88
- executor: '@nx/rollup:rollup',
89
- outputs: ['{options.outputPath}'],
90
- options: {
91
- outputPath: `dist/${options.projectRoot}`,
92
- tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
93
- project: `${options.projectRoot}/package.json`,
94
- entryFile: maybeJs(options, `${options.projectRoot}/src/index.ts`),
95
- external,
96
- rollupConfig: `@nx/react/plugins/bundle-rollup`,
97
- assets: [
98
- {
99
- glob: `${options.projectRoot}/README.md`,
100
- input: '.',
101
- output: '.',
102
- },
103
- ],
104
- },
104
+ let packageJson = {
105
+ name: options.importPath,
106
+ version: '0.0.1',
105
107
  };
106
- (0, devkit_1.updateProjectConfiguration)(host, options.name, project);
107
- return rollupConfigTask;
108
+ if (!options.useProjectJson) {
109
+ packageJson = {
110
+ ...packageJson,
111
+ ...determineEntryFields(options),
112
+ files: options.publishable ? ['dist', '!**/*.tsbuildinfo'] : undefined,
113
+ peerDependencies: {
114
+ react: versions_1.reactVersion,
115
+ 'react-native': versions_1.reactNativeVersion,
116
+ },
117
+ };
118
+ if (options.name !== options.importPath) {
119
+ packageJson.nx = { name: options.name };
120
+ }
121
+ if (options.parsedTags?.length) {
122
+ packageJson.nx ??= {};
123
+ packageJson.nx.tags = options.parsedTags;
124
+ }
125
+ }
126
+ else {
127
+ (0, devkit_1.addProjectConfiguration)(host, options.name, project);
128
+ }
129
+ if (!options.useProjectJson ||
130
+ options.isUsingTsSolutionConfig ||
131
+ options.publishable ||
132
+ options.buildable) {
133
+ (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), packageJson);
134
+ }
135
+ if (options.publishable || options.buildable) {
136
+ const external = new Set([
137
+ 'react/jsx-runtime',
138
+ 'react-native',
139
+ 'react',
140
+ 'react-dom',
141
+ ]);
142
+ const rollupTask = await (0, add_rollup_build_target_1.addRollupBuildTarget)(host, {
143
+ ...options,
144
+ format: ['cjs', 'esm'],
145
+ style: 'none',
146
+ js: options.js,
147
+ skipFormat: true,
148
+ }, external);
149
+ (0, devkit_1.updateJson)(host, `${options.projectRoot}/package.json`, (json) => {
150
+ json.peerDependencies = {
151
+ ...json.peerDependencies,
152
+ react: versions_1.reactVersion,
153
+ 'react-native': versions_1.reactNativeVersion,
154
+ };
155
+ return json;
156
+ });
157
+ return rollupTask;
158
+ }
159
+ return () => { };
108
160
  }
109
161
  function updateTsConfig(tree, options) {
162
+ if (options.isUsingTsSolutionConfig) {
163
+ return;
164
+ }
110
165
  (0, devkit_1.updateJson)(tree, (0, devkit_1.joinPathFragments)(options.projectRoot, 'tsconfig.json'), (json) => {
111
166
  if (options.strict) {
112
167
  json.compilerOptions = {
@@ -127,27 +182,31 @@ function createFiles(host, options) {
127
182
  offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.projectRoot),
128
183
  rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(host, options.projectRoot),
129
184
  });
130
- if (!options.publishable && !options.buildable) {
131
- host.delete(`${options.projectRoot}/package.json`);
132
- }
133
185
  if (options.js) {
134
186
  (0, devkit_1.toJS)(host);
135
187
  }
136
188
  updateTsConfig(host, options);
137
189
  }
138
- function updateLibPackageNpmScope(host, options) {
139
- return (0, devkit_1.updateJson)(host, `${options.projectRoot}/package.json`, (json) => {
140
- json.name = options.importPath;
141
- json.peerDependencies = {
142
- react: versions_1.reactVersion,
143
- 'react-native': versions_1.reactNativeVersion,
144
- };
145
- return json;
146
- });
147
- }
148
- function maybeJs(options, path) {
149
- return options.js && (path.endsWith('.ts') || path.endsWith('.tsx'))
150
- ? path.replace(/\.tsx?$/, '.js')
151
- : path;
190
+ function determineEntryFields(options) {
191
+ if (options.buildable ||
192
+ options.publishable ||
193
+ !options.isUsingTsSolutionConfig) {
194
+ // For buildable libraries, the entries are configured by the bundler (i.e. Rollup).
195
+ return undefined;
196
+ }
197
+ return {
198
+ main: options.js ? './src/index.js' : './src/index.ts',
199
+ types: options.js ? './src/index.js' : './src/index.ts',
200
+ exports: {
201
+ '.': options.js
202
+ ? './src/index.js'
203
+ : {
204
+ types: './src/index.ts',
205
+ import: './src/index.ts',
206
+ default: './src/index.ts',
207
+ },
208
+ './package.json': './package.json',
209
+ },
210
+ };
152
211
  }
153
212
  exports.default = reactNativeLibraryGenerator;
@@ -1,17 +1,14 @@
1
- import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
1
  import type { Linter, LinterType } from '@nx/eslint';
3
2
 
4
3
  /**
5
4
  * Same as the @nx/react library schema, except it removes keys: style, component, routing, appProject
6
5
  */
7
6
  export interface Schema {
8
- name: string;
9
- directory?: string;
10
- projectNameAndRootFormat?: ProjectNameAndRootFormat;
7
+ directory: string;
8
+ name?: string;
11
9
  skipTsConfig: boolean;
12
10
  skipFormat: boolean;
13
11
  tags?: string;
14
- pascalCaseFiles?: boolean;
15
12
  unitTestRunner: 'jest' | 'none';
16
13
  linter: Linter | LinterType;
17
14
  publishable?: boolean;
@@ -22,4 +19,5 @@ export interface Schema {
22
19
  setParserOptionsProject?: boolean;
23
20
  skipPackageJson?: boolean; //default is false
24
21
  addPlugin?: boolean;
22
+ useProjectJson?: boolean;
25
23
  }