@nx/react 0.0.0-pr-3-ec41644 → 0.0.0-pr-29993-91cbae3

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",
3
- "version": "0.0.0-pr-3-ec41644",
3
+ "version": "0.0.0-pr-29993-91cbae3",
4
4
  "private": false,
5
5
  "description": "The React plugin for Nx contains executors and generators for managing React applications and libraries within an Nx workspace. It provides:\n\n\n- Integration with libraries such as Jest, Vitest, Playwright, Cypress, and Storybook.\n\n- Generators for applications, libraries, components, hooks, and more.\n\n- Library build support for publishing packages to npm or other registries.\n\n- Utilities for automatic workspace refactoring.",
6
6
  "repository": {
@@ -38,11 +38,11 @@
38
38
  "minimatch": "9.0.3",
39
39
  "picocolors": "^1.1.0",
40
40
  "tslib": "^2.3.0",
41
- "@nx/devkit": "0.0.0-pr-3-ec41644",
42
- "@nx/js": "0.0.0-pr-3-ec41644",
43
- "@nx/eslint": "0.0.0-pr-3-ec41644",
44
- "@nx/web": "0.0.0-pr-3-ec41644",
45
- "@nx/module-federation": "0.0.0-pr-3-ec41644",
41
+ "@nx/devkit": "0.0.0-pr-29993-91cbae3",
42
+ "@nx/js": "0.0.0-pr-29993-91cbae3",
43
+ "@nx/eslint": "0.0.0-pr-29993-91cbae3",
44
+ "@nx/web": "0.0.0-pr-29993-91cbae3",
45
+ "@nx/module-federation": "0.0.0-pr-29993-91cbae3",
46
46
  "express": "^4.21.2",
47
47
  "http-proxy-middleware": "^3.0.3",
48
48
  "semver": "^7.6.3"
@@ -29,6 +29,7 @@ const sort_fields_1 = require("@nx/js/src/utils/package-json/sort-fields");
29
29
  async function applicationGenerator(tree, schema) {
30
30
  return await applicationGeneratorInternal(tree, {
31
31
  addPlugin: false,
32
+ useProjectJson: true,
32
33
  ...schema,
33
34
  });
34
35
  }
@@ -44,11 +45,6 @@ async function applicationGeneratorInternal(tree, schema) {
44
45
  });
45
46
  tasks.push(jsInitTask);
46
47
  const options = await (0, normalize_options_1.normalizeOptions)(tree, schema);
47
- // If we are using the new TS solution
48
- // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
49
- if (options.isUsingTsSolutionConfig) {
50
- (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.appProjectRoot);
51
- }
52
48
  (0, show_possible_warnings_1.showPossibleWarnings)(tree, options);
53
49
  const initTask = await (0, init_1.default)(tree, {
54
50
  ...options,
@@ -83,6 +79,11 @@ async function applicationGeneratorInternal(tree, schema) {
83
79
  }
84
80
  await (0, create_application_files_1.createApplicationFiles)(tree, options);
85
81
  (0, add_project_1.addProject)(tree, options);
82
+ // If we are using the new TS solution
83
+ // We need to update the workspace file (package.json or pnpm-workspaces.yaml) to include the new project
84
+ if (options.isUsingTsSolutionConfig) {
85
+ await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(tree, options.appProjectRoot);
86
+ }
86
87
  if (options.style === 'tailwind') {
87
88
  const twTask = await (0, setup_tailwind_1.setupTailwindGenerator)(tree, {
88
89
  project: options.projectName,
@@ -46,17 +46,15 @@ async function addE2e(tree, options) {
46
46
  switch (options.e2eTestRunner) {
47
47
  case 'cypress': {
48
48
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/cypress', versions_1.nxVersion);
49
- if (options.isUsingTsSolutionConfig) {
50
- (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), {
51
- name: options.e2eProjectName,
52
- version: '0.0.1',
53
- private: true,
54
- nx: {
55
- projectType: 'application',
56
- sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
57
- implicitDependencies: [options.projectName],
58
- },
59
- });
49
+ const packageJson = {
50
+ name: options.e2eProjectName,
51
+ version: '0.0.1',
52
+ private: true,
53
+ };
54
+ if (!options.useProjectJson) {
55
+ packageJson.nx = {
56
+ implicitDependencies: [options.projectName],
57
+ };
60
58
  }
61
59
  else {
62
60
  (0, devkit_1.addProjectConfiguration)(tree, options.e2eProjectName, {
@@ -68,6 +66,9 @@ async function addE2e(tree, options) {
68
66
  tags: [],
69
67
  });
70
68
  }
69
+ if (!options.useProjectJson || options.isUsingTsSolutionConfig) {
70
+ (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), packageJson);
71
+ }
71
72
  const e2eTask = await configurationGenerator(tree, {
72
73
  ...options,
73
74
  project: options.e2eProjectName,
@@ -116,17 +117,15 @@ async function addE2e(tree, options) {
116
117
  }
117
118
  case 'playwright': {
118
119
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/playwright', versions_1.nxVersion);
119
- if (options.isUsingTsSolutionConfig) {
120
- (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), {
121
- name: options.e2eProjectName,
122
- version: '0.0.1',
123
- private: true,
124
- nx: {
125
- projectType: 'application',
126
- sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
127
- implicitDependencies: [options.projectName],
128
- },
129
- });
120
+ const packageJson = {
121
+ name: options.e2eProjectName,
122
+ version: '0.0.1',
123
+ private: true,
124
+ };
125
+ if (!options.useProjectJson) {
126
+ packageJson.nx = {
127
+ implicitDependencies: [options.projectName],
128
+ };
130
129
  }
131
130
  else {
132
131
  (0, devkit_1.addProjectConfiguration)(tree, options.e2eProjectName, {
@@ -135,8 +134,12 @@ async function addE2e(tree, options) {
135
134
  sourceRoot: (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'src'),
136
135
  targets: {},
137
136
  implicitDependencies: [options.projectName],
137
+ tags: [],
138
138
  });
139
139
  }
140
+ if (!options.useProjectJson || options.isUsingTsSolutionConfig) {
141
+ (0, devkit_1.writeJson)(tree, (0, devkit_1.joinPathFragments)(options.e2eProjectRoot, 'package.json'), packageJson);
142
+ }
140
143
  const e2eTask = await configurationGenerator(tree, {
141
144
  project: options.e2eProjectName,
142
145
  skipFormat: true,
@@ -28,26 +28,31 @@ function addProject(host, options) {
28
28
  serve: createRspackServeTarget(options),
29
29
  };
30
30
  }
31
- if (options.isUsingTsSolutionConfig) {
32
- (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), {
33
- name: options.projectName,
34
- version: '0.0.1',
35
- private: true,
36
- });
31
+ const packageJson = {
32
+ name: options.importPath,
33
+ version: '0.0.1',
34
+ private: true,
35
+ };
36
+ if (!options.useProjectJson) {
37
+ if (options.projectName !== options.importPath) {
38
+ packageJson.nx = { name: options.projectName };
39
+ }
40
+ if (Object.keys(project.targets).length) {
41
+ packageJson.nx ??= {};
42
+ packageJson.nx.targets = project.targets;
43
+ }
44
+ if (options.parsedTags?.length) {
45
+ packageJson.nx ??= {};
46
+ packageJson.nx.tags = options.parsedTags;
47
+ }
37
48
  }
38
- if (!options.isUsingTsSolutionConfig || options.alwaysGenerateProjectJson) {
49
+ else {
39
50
  (0, devkit_1.addProjectConfiguration)(host, options.projectName, {
40
51
  ...project,
41
52
  });
42
53
  }
43
- else if (options.parsedTags?.length ||
44
- Object.keys(project.targets).length) {
45
- const updatedProject = {
46
- root: options.appProjectRoot,
47
- targets: project.targets,
48
- tags: options.parsedTags?.length ? options.parsedTags : undefined,
49
- };
50
- (0, devkit_1.updateProjectConfiguration)(host, options.projectName, updatedProject);
54
+ if (!options.useProjectJson || options.isUsingTsSolutionConfig) {
55
+ (0, devkit_1.writeJson)(host, (0, devkit_1.joinPathFragments)(options.appProjectRoot, 'package.json'), packageJson);
51
56
  }
52
57
  }
53
58
  function createRspackBuildTarget(options) {
@@ -39,7 +39,7 @@ async function createApplicationFiles(host, options) {
39
39
  const relativePathToRootTsConfig = (0, js_1.getRelativePathToRootTsConfig)(host, options.appProjectRoot);
40
40
  const appTests = (0, get_app_tests_1.getAppTests)(options);
41
41
  const templateVariables = {
42
- ...(0, devkit_1.names)(options.name),
42
+ ...options.names,
43
43
  ...options,
44
44
  js: !!options.js, // Ensure this is defined in template
45
45
  tmpl: '',
@@ -1,5 +1,3 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import { NormalizedSchema, Schema } from '../schema';
3
- export declare function normalizeDirectory(options: Schema): string;
4
- export declare function normalizeProjectName(options: Schema): string;
5
3
  export declare function normalizeOptions<T extends Schema = Schema>(host: Tree, options: Schema): Promise<NormalizedSchema<T>>;
@@ -1,27 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeDirectory = normalizeDirectory;
4
- exports.normalizeProjectName = normalizeProjectName;
5
3
  exports.normalizeOptions = normalizeOptions;
6
4
  const devkit_1 = require("@nx/devkit");
7
5
  const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
8
6
  const assertion_1 = require("../../../utils/assertion");
9
7
  const find_free_port_1 = require("./find-free-port");
10
8
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
11
- const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
12
- function normalizeDirectory(options) {
13
- options.directory = options.directory?.replace(/\\{1,2}/g, '/');
14
- const { projectDirectory } = (0, devkit_1.extractLayoutDirectory)(options.directory);
15
- return projectDirectory
16
- ? `${(0, devkit_1.names)(projectDirectory).fileName}/${(0, devkit_1.names)(options.name).fileName}`
17
- : (0, devkit_1.names)(options.name).fileName;
18
- }
19
- function normalizeProjectName(options) {
20
- return normalizeDirectory(options).replace(new RegExp('/', 'g'), '-');
21
- }
22
9
  async function normalizeOptions(host, options) {
23
- await (0, project_name_and_root_utils_1.ensureProjectName)(host, options, 'application');
24
- const { projectName: appProjectName, projectRoot: appProjectRoot } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
10
+ await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'application');
11
+ const { projectName, names: projectNames, projectRoot: appProjectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
25
12
  name: options.name,
26
13
  projectType: 'application',
27
14
  directory: options.directory,
@@ -32,6 +19,8 @@ async function normalizeOptions(host, options) {
32
19
  nxJson.useInferencePlugins !== false;
33
20
  options.addPlugin ??= addPlugin;
34
21
  options.rootProject = appProjectRoot === '.';
22
+ const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
23
+ const appProjectName = !isUsingTsSolutionConfig || options.name ? projectName : importPath;
35
24
  const e2eProjectName = options.rootProject ? 'e2e' : `${appProjectName}-e2e`;
36
25
  const e2eProjectRoot = options.rootProject ? 'e2e' : `${appProjectRoot}-e2e`;
37
26
  const parsedTags = options.tags
@@ -42,21 +31,20 @@ async function normalizeOptions(host, options) {
42
31
  ? null
43
32
  : options.style;
44
33
  (0, assertion_1.assertValidStyle)(options.style);
45
- const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
46
34
  const normalized = {
47
35
  ...options,
48
- name: appProjectName,
49
- projectName: isUsingTsSolutionConfig
50
- ? (0, get_import_path_1.getImportPath)(host, appProjectName)
51
- : appProjectName,
36
+ projectName: appProjectName,
52
37
  appProjectRoot,
38
+ importPath,
53
39
  e2eProjectName,
54
40
  e2eProjectRoot,
55
41
  parsedTags,
56
42
  fileName,
57
43
  styledModule,
58
44
  hasStyles: options.style !== 'none',
45
+ names: (0, devkit_1.names)(projectNames.projectSimpleName),
59
46
  isUsingTsSolutionConfig,
47
+ useProjectJson: options.useProjectJson ?? !isUsingTsSolutionConfig,
60
48
  };
61
49
  normalized.routing = normalized.routing ?? false;
62
50
  normalized.strict = normalized.strict ?? true;
@@ -1,3 +1,4 @@
1
+ import type { names } from '@nx/devkit';
1
2
  import type { Linter, LinterType } from '@nx/eslint';
2
3
  import type { SupportedStyles } from '../../../typings/style';
3
4
 
@@ -30,7 +31,7 @@ export interface Schema {
30
31
  nxCloudToken?: string;
31
32
  useTsSolution?: boolean;
32
33
  formatter?: 'prettier' | 'none';
33
- alwaysGenerateProjectJson?: boolean; // this is needed for MF currently
34
+ useProjectJson?: boolean;
34
35
  }
35
36
 
36
37
  export interface NormalizedSchema<T extends Schema = Schema> extends T {
@@ -38,11 +39,13 @@ export interface NormalizedSchema<T extends Schema = Schema> extends T {
38
39
  appProjectRoot: string;
39
40
  e2eProjectName: string;
40
41
  e2eProjectRoot: string;
42
+ importPath: string;
41
43
  parsedTags: string[];
42
44
  fileName: string;
43
45
  styledModule: null | SupportedStyles;
44
46
  hasStyles: boolean;
45
47
  unitTestRunner: 'jest' | 'vitest' | 'none';
46
48
  addPlugin?: boolean;
49
+ names: ReturnType<typeof names>;
47
50
  isUsingTsSolutionConfig?: boolean;
48
51
  }
@@ -187,6 +187,10 @@
187
187
  "description": "Generate a React app with a minimal setup, no separate test files.",
188
188
  "type": "boolean",
189
189
  "default": false
190
+ },
191
+ "useProjectJson": {
192
+ "type": "boolean",
193
+ "description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
190
194
  }
191
195
  },
192
196
  "required": ["directory"],
@@ -19,7 +19,10 @@ const update_module_federation_tsconfig_1 = require("./lib/update-module-federat
19
19
  async function hostGenerator(host, schema) {
20
20
  const tasks = [];
21
21
  const options = {
22
- ...(await (0, normalize_options_1.normalizeOptions)(host, schema)),
22
+ ...(await (0, normalize_options_1.normalizeOptions)(host, {
23
+ ...schema,
24
+ useProjectJson: true,
25
+ })),
23
26
  js: schema.js ?? false,
24
27
  typescriptConfiguration: schema.js
25
28
  ? false
@@ -39,7 +42,7 @@ async function hostGenerator(host, schema) {
39
42
  }
40
43
  });
41
44
  }
42
- await (0, project_name_and_root_utils_1.ensureProjectName)(host, options, 'application');
45
+ await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'application');
43
46
  const initTask = await (0, application_1.default)(host, {
44
47
  ...options,
45
48
  directory: options.appProjectRoot,
@@ -47,7 +50,7 @@ async function hostGenerator(host, schema) {
47
50
  // The target use-case is loading remotes as child routes, thus always enable routing.
48
51
  routing: true,
49
52
  skipFormat: true,
50
- alwaysGenerateProjectJson: true,
53
+ useProjectJson: true,
51
54
  });
52
55
  tasks.push(initTask);
53
56
  const remotesWithPorts = [];
@@ -1,4 +1,6 @@
1
1
  import { Tree } from 'nx/src/generators/tree';
2
2
  import { GeneratorCallback } from '@nx/devkit';
3
3
  import { NormalizedSchema } from '../schema';
4
- export declare function addRollupBuildTarget(host: Tree, options: NormalizedSchema): Promise<GeneratorCallback>;
4
+ export declare function addRollupBuildTarget(host: Tree, options: NormalizedSchema & {
5
+ format?: Array<'esm' | 'cjs'>;
6
+ }, external?: Set<String>): Promise<GeneratorCallback>;
@@ -4,7 +4,7 @@ exports.addRollupBuildTarget = addRollupBuildTarget;
4
4
  const devkit_1 = require("@nx/devkit");
5
5
  const maybe_js_1 = require("../../../utils/maybe-js");
6
6
  const versions_1 = require("../../../utils/versions");
7
- async function addRollupBuildTarget(host, options) {
7
+ async function addRollupBuildTarget(host, options, external = new Set(['react', 'react-dom'])) {
8
8
  const tasks = [];
9
9
  const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/rollup', versions_1.nxVersion);
10
10
  tasks.push(await configurationGenerator(host, {
@@ -19,12 +19,11 @@ async function addRollupBuildTarget(host, options) {
19
19
  '@svgr/rollup': versions_1.svgrRollupVersion,
20
20
  }));
21
21
  }
22
- const external = ['react', 'react-dom'];
23
22
  if (options.style === '@emotion/styled') {
24
- external.push('@emotion/react/jsx-runtime');
23
+ external.add('@emotion/react/jsx-runtime');
25
24
  }
26
25
  else {
27
- external.push('react/jsx-runtime');
26
+ external.add('react/jsx-runtime');
28
27
  }
29
28
  const nxJson = (0, devkit_1.readNxJson)(host);
30
29
  const hasRollupPlugin = !!nxJson.plugins?.some((p) => typeof p === 'string'
@@ -44,8 +43,8 @@ module.exports = withNx(
44
43
  : (0, devkit_1.joinPathFragments)((0, devkit_1.offsetFromRoot)(options.projectRoot), 'dist', options.projectRoot)}',
45
44
  tsConfig: './tsconfig.lib.json',
46
45
  compiler: '${options.compiler ?? 'babel'}',
47
- external: ${JSON.stringify(external)},
48
- format: ['esm'],
46
+ external: ${JSON.stringify(Array.from(external))},
47
+ format: ${JSON.stringify(options.format ?? ['esm'])},
49
48
  assets:[{ input: '.', output: '.', glob: 'README.md'}],
50
49
  }, {
51
50
  // Provide additional rollup configuration here. See: https://rollupjs.org/configuration-options
@@ -74,7 +73,7 @@ module.exports = withNx(
74
73
  tsConfig: `${options.projectRoot}/tsconfig.lib.json`,
75
74
  project: `${options.projectRoot}/package.json`,
76
75
  entryFile: (0, maybe_js_1.maybeJs)(options, `${options.projectRoot}/src/index.ts`),
77
- external,
76
+ external: Array.from(external),
78
77
  rollupConfig: `@nx/react/plugins/bundle-rollup`,
79
78
  compiler: options.compiler ?? 'babel',
80
79
  assets: [
@@ -43,7 +43,8 @@ function createFiles(host, options) {
43
43
  });
44
44
  }
45
45
  if ((options.publishable || options.buildable) &&
46
- !options.isUsingTsSolutionConfig) {
46
+ !options.isUsingTsSolutionConfig &&
47
+ options.useProjectJson) {
47
48
  if (options.bundler === 'vite') {
48
49
  (0, devkit_1.writeJson)(host, `${options.projectRoot}/package.json`, {
49
50
  name: options.importPath,
@@ -7,7 +7,7 @@ const assertion_1 = require("../../../utils/assertion");
7
7
  const ts_solution_setup_1 = require("@nx/js/src/utils/typescript/ts-solution-setup");
8
8
  async function normalizeOptions(host, options) {
9
9
  const isUsingTsSolutionConfig = (0, ts_solution_setup_1.isUsingTsSolutionSetup)(host);
10
- await (0, project_name_and_root_utils_1.ensureProjectName)(host, options, 'library');
10
+ await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'library');
11
11
  const { projectName, names: projectNames, projectRoot, importPath, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
12
12
  name: options.name,
13
13
  projectType: 'library',
@@ -41,23 +41,26 @@ async function normalizeOptions(host, options) {
41
41
  bundler,
42
42
  fileName,
43
43
  routePath: `/${projectNames.projectSimpleName}`,
44
- name: isUsingTsSolutionConfig ? importPath : projectName,
44
+ name: isUsingTsSolutionConfig && !options.name ? importPath : projectName,
45
45
  projectRoot,
46
46
  parsedTags,
47
47
  importPath,
48
+ useProjectJson: options.useProjectJson ?? !isUsingTsSolutionConfig,
48
49
  };
49
50
  // Libraries with a bundler or is publishable must also be buildable.
50
51
  normalized.buildable = Boolean(normalized.bundler !== 'none' || options.buildable || options.publishable);
51
52
  normalized.inSourceTests === normalized.minimal || normalized.inSourceTests;
52
53
  if (options.appProject) {
53
54
  const appProjectConfig = (0, devkit_1.getProjects)(host).get(options.appProject);
54
- if (appProjectConfig.projectType !== 'application') {
55
- throw new Error(`appProject expected type of "application" but got "${appProjectConfig.projectType}"`);
55
+ const appProjectType = (0, ts_solution_setup_1.getProjectType)(host, appProjectConfig.root, appProjectConfig.projectType);
56
+ if (appProjectType !== 'application') {
57
+ throw new Error(`appProject expected type of "application" but got "${appProjectType}"`);
56
58
  }
59
+ const appSourceRoot = (0, ts_solution_setup_1.getProjectSourceRoot)(host, appProjectConfig.sourceRoot, appProjectConfig.root);
57
60
  normalized.appMain =
58
61
  appProjectConfig.targets.build?.options?.main ??
59
62
  findMainEntry(host, appProjectConfig.root);
60
- normalized.appSourceRoot = (0, devkit_1.normalizePath)(appProjectConfig.sourceRoot);
63
+ normalized.appSourceRoot = (0, devkit_1.normalizePath)(appSourceRoot);
61
64
  // TODO(jack): We should use appEntryFile instead of appProject so users can directly set it rather than us inferring it.
62
65
  if (!normalized.appMain) {
63
66
  throw new Error(`Could not locate project main for ${options.appProject}`);
@@ -27,6 +27,7 @@ const add_release_config_1 = require("@nx/js/src/generators/library/utils/add-re
27
27
  async function libraryGenerator(host, schema) {
28
28
  return await libraryGeneratorInternal(host, {
29
29
  addPlugin: false,
30
+ useProjectJson: true,
30
31
  ...schema,
31
32
  });
32
33
  }
@@ -39,7 +40,7 @@ async function libraryGeneratorInternal(host, schema) {
39
40
  tasks.push(jsInitTask);
40
41
  const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
41
42
  if (options.isUsingTsSolutionConfig) {
42
- (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.projectRoot);
43
+ await (0, ts_solution_setup_1.addProjectToTsSolutionWorkspace)(host, options.projectRoot);
43
44
  }
44
45
  if (options.publishable === true && !schema.importPath) {
45
46
  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)`);
@@ -52,18 +53,20 @@ async function libraryGeneratorInternal(host, schema) {
52
53
  skipFormat: true,
53
54
  });
54
55
  tasks.push(initTask);
55
- if (options.isUsingTsSolutionConfig) {
56
- (0, devkit_1.writeJson)(host, `${options.projectRoot}/package.json`, {
57
- name: options.importPath ?? options.name,
58
- version: '0.0.1',
59
- ...(0, determine_entry_fields_1.determineEntryFields)(options),
60
- nx: options.parsedTags?.length
61
- ? {
62
- tags: options.parsedTags,
63
- }
64
- : undefined,
65
- files: options.publishable ? ['dist', '!**/*.tsbuildinfo'] : undefined,
66
- });
56
+ const packageJson = {
57
+ name: options.importPath,
58
+ version: '0.0.1',
59
+ ...(0, determine_entry_fields_1.determineEntryFields)(options),
60
+ files: options.publishable ? ['dist', '!**/*.tsbuildinfo'] : undefined,
61
+ };
62
+ if (!options.useProjectJson) {
63
+ if (options.name !== options.importPath) {
64
+ packageJson.nx = { name: options.name };
65
+ }
66
+ if (options.parsedTags?.length) {
67
+ packageJson.nx ??= {};
68
+ packageJson.nx.tags = options.parsedTags;
69
+ }
67
70
  }
68
71
  else {
69
72
  (0, devkit_1.addProjectConfiguration)(host, options.name, {
@@ -74,6 +77,9 @@ async function libraryGeneratorInternal(host, schema) {
74
77
  targets: {},
75
78
  });
76
79
  }
80
+ if (!options.useProjectJson || options.isUsingTsSolutionConfig) {
81
+ (0, devkit_1.writeJson)(host, `${options.projectRoot}/package.json`, packageJson);
82
+ }
77
83
  (0, create_files_1.createFiles)(host, options);
78
84
  const lintTask = await (0, add_linting_1.addLinting)(host, options);
79
85
  tasks.push(lintTask);
@@ -27,6 +27,7 @@ export interface Schema {
27
27
  minimal?: boolean;
28
28
  simpleName?: boolean;
29
29
  addPlugin?: boolean;
30
+ useProjectJson?: boolean;
30
31
  }
31
32
 
32
33
  export interface NormalizedSchema extends Schema {
@@ -36,6 +37,7 @@ export interface NormalizedSchema extends Schema {
36
37
  projectRoot: string;
37
38
  routePath: string;
38
39
  parsedTags: string[];
40
+ importPath: string;
39
41
  appMain?: string;
40
42
  appSourceRoot?: string;
41
43
  unitTestRunner: 'jest' | 'vitest' | 'none';
@@ -190,6 +190,10 @@
190
190
  "description": "Don't include the directory in the name of the module of the library.",
191
191
  "type": "boolean",
192
192
  "default": false
193
+ },
194
+ "useProjectJson": {
195
+ "type": "boolean",
196
+ "description": "Use a `project.json` configuration file instead of inlining the Nx configuration in the `package.json` file."
193
197
  }
194
198
  },
195
199
  "required": ["directory"]
@@ -48,7 +48,10 @@ function addModuleFederationFiles(host, options) {
48
48
  async function remoteGenerator(host, schema) {
49
49
  const tasks = [];
50
50
  const options = {
51
- ...(await (0, normalize_options_1.normalizeOptions)(host, schema)),
51
+ ...(await (0, normalize_options_1.normalizeOptions)(host, {
52
+ ...schema,
53
+ useProjectJson: true,
54
+ })),
52
55
  // when js is set to true, we want to use the js configuration
53
56
  js: schema.js ?? false,
54
57
  typescriptConfiguration: schema.js
@@ -62,29 +65,29 @@ async function remoteGenerator(host, schema) {
62
65
  if (options.dynamic) {
63
66
  // Dynamic remotes generate with library { type: 'var' } by default.
64
67
  // We need to ensure that the remote name is a valid variable name.
65
- const isValidRemote = (0, js_1.isValidVariable)(options.name);
68
+ const isValidRemote = (0, js_1.isValidVariable)(options.projectName);
66
69
  if (!isValidRemote.isValid) {
67
- throw new Error(`Invalid remote name provided: ${options.name}. ${isValidRemote.message}`);
70
+ throw new Error(`Invalid remote name provided: ${options.projectName}. ${isValidRemote.message}`);
68
71
  }
69
72
  }
70
- await (0, project_name_and_root_utils_1.ensureProjectName)(host, options, 'application');
73
+ await (0, project_name_and_root_utils_1.ensureRootProjectName)(options, 'application');
71
74
  const REMOTE_NAME_REGEX = '^[a-zA-Z_$][a-zA-Z_$0-9]*$';
72
75
  const remoteNameRegex = new RegExp(REMOTE_NAME_REGEX);
73
- if (!remoteNameRegex.test(options.name)) {
74
- throw new Error((0, devkit_1.stripIndents) `Invalid remote name: ${options.name}. Remote project names must:
76
+ if (!remoteNameRegex.test(options.projectName)) {
77
+ throw new Error((0, devkit_1.stripIndents) `Invalid remote name: ${options.projectName}. Remote project names must:
75
78
  - Start with a letter, dollar sign ($) or underscore (_)
76
79
  - Followed by any valid character (letters, digits, underscores, or dollar signs)
77
80
  The regular expression used is ${REMOTE_NAME_REGEX}.`);
78
81
  }
79
82
  const initAppTask = await (0, application_1.default)(host, {
80
83
  ...options,
81
- name: options.name,
84
+ name: options.projectName,
82
85
  skipFormat: true,
83
- alwaysGenerateProjectJson: true,
86
+ useProjectJson: true,
84
87
  });
85
88
  tasks.push(initAppTask);
86
89
  if (options.host) {
87
- (0, update_host_with_remote_1.updateHostWithRemote)(host, options.host, options.name);
90
+ (0, update_host_with_remote_1.updateHostWithRemote)(host, options.host, options.projectName);
88
91
  }
89
92
  // Module federation requires bootstrap code to be dynamically imported.
90
93
  // Renaming original entry file so we can use `import(./bootstrap)` in
@@ -42,8 +42,8 @@ export declare const typesExpressVersion = "^4.17.21";
42
42
  export declare const isbotVersion = "^3.6.5";
43
43
  export declare const corsVersion = "~2.8.5";
44
44
  export declare const typesCorsVersion = "~2.8.12";
45
- export declare const moduleFederationNodeVersion = "^2.6.21";
46
- export declare const moduleFederationEnhancedVersion = "^0.8.8";
45
+ export declare const moduleFederationNodeVersion = "^2.6.26";
46
+ export declare const moduleFederationEnhancedVersion = "^0.9.0";
47
47
  export declare const lessVersion = "3.12.2";
48
48
  export declare const sassVersion = "^1.55.0";
49
49
  export declare const rollupPluginUrlVersion = "^8.0.2";
@@ -48,8 +48,8 @@ exports.typesExpressVersion = '^4.17.21';
48
48
  exports.isbotVersion = '^3.6.5';
49
49
  exports.corsVersion = '~2.8.5';
50
50
  exports.typesCorsVersion = '~2.8.12';
51
- exports.moduleFederationNodeVersion = '^2.6.21';
52
- exports.moduleFederationEnhancedVersion = '^0.8.8';
51
+ exports.moduleFederationNodeVersion = '^2.6.26';
52
+ exports.moduleFederationEnhancedVersion = '^0.9.0';
53
53
  // style preprocessors
54
54
  exports.lessVersion = '3.12.2';
55
55
  exports.sassVersion = '^1.55.0';