@nx/react-native 0.0.0-pr-29993-f89d4dd → 0.0.0-pr-3-e51e28c

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": "0.0.0-pr-29993-f89d4dd",
3
+ "version": "0.0.0-pr-3-e51e28c",
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": [
@@ -35,12 +35,12 @@
35
35
  "picocolors": "^1.1.0",
36
36
  "tsconfig-paths": "^4.1.2",
37
37
  "tslib": "^2.3.0",
38
- "@nx/devkit": "0.0.0-pr-29993-f89d4dd",
39
- "@nx/jest": "0.0.0-pr-29993-f89d4dd",
40
- "@nx/js": "0.0.0-pr-29993-f89d4dd",
41
- "@nx/eslint": "0.0.0-pr-29993-f89d4dd",
42
- "@nx/react": "0.0.0-pr-29993-f89d4dd",
43
- "@nx/workspace": "0.0.0-pr-29993-f89d4dd"
38
+ "@nx/devkit": "0.0.0-pr-3-e51e28c",
39
+ "@nx/jest": "0.0.0-pr-3-e51e28c",
40
+ "@nx/js": "0.0.0-pr-3-e51e28c",
41
+ "@nx/eslint": "0.0.0-pr-3-e51e28c",
42
+ "@nx/react": "0.0.0-pr-3-e51e28c",
43
+ "@nx/workspace": "0.0.0-pr-3-e51e28c"
44
44
  },
45
45
  "executors": "./executors.json",
46
46
  "ng-update": {
@@ -43,11 +43,6 @@ async function reactNativeApplicationGeneratorInternal(host, schema) {
43
43
  }
44
44
  await (0, create_application_files_1.createApplicationFiles)(host, options);
45
45
  (0, add_project_1.addProject)(host, options);
46
- // If we are using the new TS solution
47
- // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
48
- if (options.isTsSolutionSetup) {
49
- (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.appProjectRoot);
50
- }
51
46
  const lintTask = await (0, add_linting_1.addLinting)(host, {
52
47
  ...options,
53
48
  projectRoot: options.appProjectRoot,
@@ -93,6 +88,11 @@ async function reactNativeApplicationGeneratorInternal(host, schema) {
93
88
  }, options.linter === 'eslint'
94
89
  ? ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
95
90
  : undefined);
91
+ // If we are using the new TS solution
92
+ // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
93
+ if (options.useTsSolution) {
94
+ (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.appProjectRoot);
95
+ }
96
96
  (0, sort_fields_1.sortPackageJsonFields)(host, options.appProjectRoot);
97
97
  if (!options.skipFormat) {
98
98
  await (0, devkit_1.formatFiles)(host);
@@ -14,7 +14,6 @@ async function addE2e(host, options) {
14
14
  styledModule: null,
15
15
  hasStyles: false,
16
16
  unitTestRunner: 'none',
17
- names: (0, devkit_1.names)(options.name),
18
17
  });
19
18
  case 'playwright':
20
19
  return (0, add_e2e_1.addE2e)(host, {
@@ -24,7 +23,6 @@ async function addE2e(host, options) {
24
23
  styledModule: null,
25
24
  hasStyles: false,
26
25
  unitTestRunner: 'none',
27
- names: (0, devkit_1.names)(options.name),
28
26
  });
29
27
  case 'detox':
30
28
  const { detoxApplicationGenerator } = (0, devkit_1.ensurePackage)('@nx/detox', versions_1.nxVersion);
@@ -16,23 +16,15 @@ function addProject(host, options) {
16
16
  tags: options.parsedTags,
17
17
  };
18
18
  if ((0, ts_solution_setup_1.isUsingTsSolutionSetup)(host)) {
19
- const packageJson = {
20
- name: options.importPath,
19
+ (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), {
20
+ name: options.projectName,
21
21
  version: '0.0.1',
22
22
  private: true,
23
- };
24
- if (options.projectName !== options.importPath) {
25
- packageJson.nx = { name: options.projectName };
26
- }
27
- if (!hasPlugin) {
28
- packageJson.nx ??= {};
29
- packageJson.nx.targets = getTargets(options);
30
- }
31
- if (options.parsedTags?.length) {
32
- packageJson.nx ??= {};
33
- packageJson.nx.tags = options.parsedTags;
34
- }
35
- (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), packageJson);
23
+ nx: {
24
+ targets: hasPlugin ? {} : getTargets(options),
25
+ tags: options.parsedTags?.length ? options.parsedTags : undefined,
26
+ },
27
+ });
36
28
  }
37
29
  else {
38
30
  (0, devkit_1.addProjectConfiguration)(host, options.projectName, {
@@ -1,6 +1,6 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import { Schema } from '../schema';
3
- export interface NormalizedSchema extends Omit<Schema, 'useTsSolution'> {
3
+ export interface NormalizedSchema extends Schema {
4
4
  className: string;
5
5
  fileName: string;
6
6
  projectName: string;
@@ -13,7 +13,6 @@ export interface NormalizedSchema extends Omit<Schema, 'useTsSolution'> {
13
13
  rootProject: boolean;
14
14
  e2eProjectName: string;
15
15
  e2eProjectRoot: string;
16
- importPath: string;
17
16
  isTsSolutionSetup: boolean;
18
17
  }
19
18
  export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
@@ -4,9 +4,10 @@ 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
6
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
7
+ const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
7
8
  async function normalizeOptions(host, options) {
8
- await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'application');
9
- const { projectName, names: projectNames, projectRoot: appProjectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
9
+ await (0, project_name_and_root_utils_1.ensureProjectName)(host, options, 'application');
10
+ const { projectName: appProjectName, names: projectNames, projectRoot: appProjectRoot, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
10
11
  name: options.name,
11
12
  projectType: 'application',
12
13
  directory: options.directory,
@@ -15,18 +16,17 @@ async function normalizeOptions(host, options) {
15
16
  const addPluginDefault = process.env.NX_ADD_PLUGINS !== 'false' &&
16
17
  nxJson.useInferencePlugins !== false;
17
18
  options.addPlugin ??= addPluginDefault;
18
- const { className, fileName } = (0, devkit_1.names)(projectNames.projectSimpleName);
19
+ const { className, fileName } = (0, devkit_1.names)(options.name);
19
20
  const iosProjectRoot = (0, devkit_1.joinPathFragments)(appProjectRoot, 'ios');
20
21
  const androidProjectRoot = (0, devkit_1.joinPathFragments)(appProjectRoot, 'android');
21
22
  const rootProject = appProjectRoot === '.';
22
- const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
23
- const appProjectName = !isTsSolutionSetup || options.name ? projectName : importPath;
24
23
  const e2eProjectName = rootProject ? 'e2e' : `${appProjectName}-e2e`;
25
24
  const e2eProjectRoot = rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
26
25
  const parsedTags = options.tags
27
26
  ? options.tags.split(',').map((s) => s.trim())
28
27
  : [];
29
28
  const entryFile = options.js ? 'src/main.js' : 'src/main.tsx';
29
+ const isTsSolutionSetup = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
30
30
  return {
31
31
  ...options,
32
32
  name: projectNames.projectSimpleName,
@@ -34,9 +34,10 @@ async function normalizeOptions(host, options) {
34
34
  fileName,
35
35
  lowerCaseName: className.toLowerCase(),
36
36
  displayName: options.displayName || className,
37
- projectName: appProjectName,
37
+ projectName: isTsSolutionSetup
38
+ ? (0, get_import_path_1.getImportPath)(host, appProjectName)
39
+ : appProjectName,
38
40
  appProjectRoot,
39
- importPath,
40
41
  iosProjectRoot,
41
42
  androidProjectRoot,
42
43
  parsedTags,
@@ -11,9 +11,7 @@ async function reactNativeComponentGenerator(host, schema) {
11
11
  const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
12
12
  createComponentFiles(host, options);
13
13
  addExportsToBarrel(host, options);
14
- if (!options.skipFormat) {
15
- await (0, devkit_1.formatFiles)(host);
16
- }
14
+ await (0, devkit_1.formatFiles)(host);
17
15
  }
18
16
  function createComponentFiles(host, options) {
19
17
  (0, devkit_1.generateFiles)(host, (0, path_1.join)(__dirname, 'files', options.fileExtensionType), options.directory, {
@@ -33,9 +31,7 @@ function addExportsToBarrel(host, options) {
33
31
  const proj = workspace.get(options.projectName);
34
32
  const isApp = (0, ts_solution_setup_1.getProjectType)(host, proj.root, proj.projectType) === 'application';
35
33
  if (options.export && !isApp) {
36
- const indexFilePath = (0, devkit_1.joinPathFragments)(...(options.projectSourceRoot
37
- ? [options.projectSourceRoot]
38
- : [options.projectRoot, 'src']), options.fileExtensionType === 'js' ? 'index.js' : 'index.ts');
34
+ const indexFilePath = (0, devkit_1.joinPathFragments)(options.projectSourceRoot, options.fileExtensionType === 'js' ? 'index.js' : 'index.ts');
39
35
  if (!host.exists(indexFilePath)) {
40
36
  return;
41
37
  }
@@ -10,6 +10,5 @@ export interface NormalizedSchema extends Omit<Schema, 'js'> {
10
10
  fileExtension: string;
11
11
  fileExtensionType: FileExtensionType;
12
12
  projectName: string;
13
- projectRoot: string;
14
13
  }
15
14
  export declare function normalizeOptions(host: Tree, options: Schema): Promise<NormalizedSchema>;
@@ -31,6 +31,5 @@ async function normalizeOptions(host, options) {
31
31
  fileExtensionType,
32
32
  projectSourceRoot,
33
33
  projectName,
34
- projectRoot: root,
35
34
  };
36
35
  }
@@ -7,7 +7,6 @@ export interface Schema {
7
7
  skipTests?: boolean;
8
8
  export?: boolean;
9
9
  classComponent?: boolean;
10
- skipFormat?: boolean;
11
10
 
12
11
  /**
13
12
  * @deprecated Provide the full file path including the file extension in the `path` option. This option will be removed in Nx v21.
@@ -59,12 +59,6 @@
59
59
  "alias": "C",
60
60
  "description": "Use class components instead of functional component.",
61
61
  "default": false
62
- },
63
- "skipFormat": {
64
- "description": "Skip formatting files.",
65
- "type": "boolean",
66
- "default": false,
67
- "x-priority": "internal"
68
62
  }
69
63
  },
70
64
  "required": ["path"]
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "<%= name %>",
3
+ "version": "0.0.1"
4
+ }
@@ -4,7 +4,6 @@ export interface NormalizedSchema extends Schema {
4
4
  name: string;
5
5
  fileName: string;
6
6
  projectRoot: string;
7
- importPath: string;
8
7
  routePath: string;
9
8
  parsedTags: string[];
10
9
  appMain?: string;
@@ -4,8 +4,9 @@ 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
6
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
7
+ const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
7
8
  async function normalizeOptions(host, options) {
8
- await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'library');
9
+ await (0, project_name_and_root_utils_1.ensureProjectName)(host, options, 'library');
9
10
  const { projectName, names: projectNames, projectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
10
11
  name: options.name,
11
12
  projectType: 'library',
@@ -24,7 +25,9 @@ async function normalizeOptions(host, options) {
24
25
  ...options,
25
26
  fileName: projectName,
26
27
  routePath: `/${projectNames.projectSimpleName}`,
27
- name: isUsingTsSolutionConfig && !options.name ? importPath : projectName,
28
+ name: isUsingTsSolutionConfig
29
+ ? (0, get_import_path_1.getImportPath)(host, projectName)
30
+ : projectName,
28
31
  projectRoot,
29
32
  parsedTags,
30
33
  importPath,
@@ -7,16 +7,12 @@ 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 component_1 = require("../component/component");
10
+ const versions_1 = require("../../utils/versions");
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
14
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
15
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");
20
16
  async function reactNativeLibraryGenerator(host, schema) {
21
17
  return await reactNativeLibraryGeneratorInternal(host, {
22
18
  addPlugin: false,
@@ -44,9 +40,6 @@ async function reactNativeLibraryGeneratorInternal(host, schema) {
44
40
  if (addProjectTask) {
45
41
  tasks.push(addProjectTask);
46
42
  }
47
- if (options.isUsingTsSolutionConfig) {
48
- (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.projectRoot);
49
- }
50
43
  const lintTask = await (0, add_linting_1.addLinting)(host, {
51
44
  ...options,
52
45
  projectName: options.name,
@@ -57,16 +50,9 @@ async function reactNativeLibraryGeneratorInternal(host, schema) {
57
50
  tasks.push(lintTask);
58
51
  const jestTask = await (0, add_jest_1.addJest)(host, options.unitTestRunner, options.name, options.projectRoot, options.js, options.skipPackageJson, options.addPlugin, 'tsconfig.lib.json');
59
52
  tasks.push(jestTask);
60
- const relativeCwd = (0, artifact_name_and_directory_utils_1.getRelativeCwd)();
61
- const path = (0, devkit_1.joinPathFragments)(options.projectRoot, 'src/lib', options.fileName);
62
- const componentTask = await (0, component_1.default)(host, {
63
- path: relativeCwd ? (0, path_1.relative)(relativeCwd, path) : path,
64
- skipTests: options.unitTestRunner === 'none',
65
- export: true,
66
- skipFormat: true,
67
- js: options.js,
68
- });
69
- tasks.push(() => componentTask);
53
+ if (options.publishable || options.buildable) {
54
+ updateLibPackageNpmScope(host, options);
55
+ }
70
56
  if (!options.skipTsConfig && !options.isUsingTsSolutionConfig) {
71
57
  (0, js_1.addTsConfigPath)(host, options.importPath, [
72
58
  (0, devkit_1.joinPathFragments)(options.projectRoot, './src', 'index.' + (options.js ? 'js' : 'ts')),
@@ -79,6 +65,9 @@ async function reactNativeLibraryGeneratorInternal(host, schema) {
79
65
  }, options.linter === 'eslint'
80
66
  ? ['eslint.config.js', 'eslint.config.cjs', 'eslint.config.mjs']
81
67
  : undefined);
68
+ if (options.isUsingTsSolutionConfig) {
69
+ (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.projectRoot);
70
+ }
82
71
  (0, sort_fields_1.sortPackageJsonFields)(host, options.projectRoot);
83
72
  if (!options.skipFormat) {
84
73
  await (0, devkit_1.formatFiles)(host);
@@ -100,54 +89,61 @@ async function addProject(host, options) {
100
89
  tags: options.parsedTags,
101
90
  targets: {},
102
91
  };
92
+ const packageJsonPath = (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json');
103
93
  if (options.isUsingTsSolutionConfig) {
104
- const packageJson = {
105
- name: options.importPath,
94
+ (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), {
95
+ name: options.name,
106
96
  version: '0.0.1',
107
97
  ...determineEntryFields(options),
108
- files: options.publishable ? ['dist', '!**/*.tsbuildinfo'] : undefined,
109
- peerDependencies: {
110
- react: versions_1.reactVersion,
111
- 'react-native': versions_1.reactNativeVersion,
98
+ nx: {
99
+ tags: options.parsedTags?.length ? options.parsedTags : undefined,
112
100
  },
113
- };
114
- if (options.name !== options.importPath) {
115
- packageJson.nx = { name: options.name };
116
- }
117
- if (options.parsedTags?.length) {
118
- packageJson.nx ??= {};
119
- packageJson.nx.tags = options.parsedTags;
120
- }
121
- (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.projectRoot, 'package.json'), packageJson);
101
+ });
122
102
  }
123
103
  else {
124
104
  (0, devkit_1.addProjectConfiguration)(host, options.name, project);
125
105
  }
126
- if (options.publishable || options.buildable) {
127
- const external = new Set([
128
- 'react/jsx-runtime',
129
- 'react-native',
130
- 'react',
131
- 'react-dom',
132
- ]);
133
- const rollupTask = await (0, add_rollup_build_target_1.addRollupBuildTarget)(host, {
134
- ...options,
135
- format: ['cjs', 'esm'],
136
- style: 'none',
137
- js: options.js,
138
- skipFormat: true,
139
- }, external);
140
- (0, devkit_1.updateJson)(host, `${options.projectRoot}/package.json`, (json) => {
141
- json.peerDependencies = {
142
- ...json.peerDependencies,
143
- react: versions_1.reactVersion,
144
- 'react-native': versions_1.reactNativeVersion,
145
- };
146
- return json;
147
- });
148
- return rollupTask;
106
+ if (!options.publishable && !options.buildable) {
107
+ return () => { };
149
108
  }
150
- return () => { };
109
+ const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rollup', versions_1.nxVersion);
110
+ const rollupConfigTask = await configurationGenerator(host, {
111
+ ...options,
112
+ project: options.name,
113
+ skipFormat: true,
114
+ });
115
+ (0, devkit_1.updateJson)(host, packageJsonPath, (json) => {
116
+ if (json.type === 'module') {
117
+ // The @nx/rollup:configuration generator can set the type to 'module' which would
118
+ // potentially break this library.
119
+ delete json.type;
120
+ }
121
+ return json;
122
+ });
123
+ const external = ['react/jsx-runtime', 'react-native', 'react', 'react-dom'];
124
+ project.targets.build = {
125
+ executor: '@nx/rollup:rollup',
126
+ outputs: ['{options.outputPath}'],
127
+ options: {
128
+ outputPath: options.isUsingTsSolutionConfig
129
+ ? `${options.projectRoot}/dist`
130
+ : `dist/${options.projectRoot}`,
131
+ tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
132
+ project: `${options.projectRoot}/package.json`,
133
+ entryFile: maybeJs(options, `${options.projectRoot}/src/index.ts`),
134
+ external,
135
+ rollupConfig: `@nx/react/plugins/bundle-rollup`,
136
+ assets: [
137
+ {
138
+ glob: `${options.projectRoot}/README.md`,
139
+ input: '.',
140
+ output: '.',
141
+ },
142
+ ],
143
+ },
144
+ };
145
+ (0, devkit_1.updateProjectConfiguration)(host, options.name, project);
146
+ return rollupConfigTask;
151
147
  }
152
148
  function updateTsConfig(tree, options) {
153
149
  if (options.isUsingTsSolutionConfig) {
@@ -173,12 +169,33 @@ function createFiles(host, options) {
173
169
  offsetFromRoot: (0, devkit_1.offsetFromRoot)(options.projectRoot),
174
170
  rootTsConfigPath: (0, js_1.getRelativePathToRootTsConfig)(host, options.projectRoot),
175
171
  });
172
+ if (!options.publishable && !options.buildable) {
173
+ host.delete(`${options.projectRoot}/package.json`);
174
+ }
176
175
  if (options.js) {
177
176
  (0, devkit_1.toJS)(host);
178
177
  }
179
178
  updateTsConfig(host, options);
180
179
  }
180
+ function updateLibPackageNpmScope(host, options) {
181
+ return (0, devkit_1.updateJson)(host, `${options.projectRoot}/package.json`, (json) => {
182
+ json.name = options.importPath;
183
+ json.peerDependencies = {
184
+ react: versions_1.reactVersion,
185
+ 'react-native': versions_1.reactNativeVersion,
186
+ };
187
+ return json;
188
+ });
189
+ }
190
+ function maybeJs(options, path) {
191
+ return options.js && (path.endsWith('.ts') || path.endsWith('.tsx'))
192
+ ? path.replace(/\.tsx?$/, '.js')
193
+ : path;
194
+ }
181
195
  function determineEntryFields(options) {
196
+ if (options.buildable) {
197
+ return {};
198
+ }
182
199
  return {
183
200
  main: options.js ? './src/index.js' : './src/index.ts',
184
201
  types: options.js ? './src/index.js' : './src/index.ts',