@nx/react 0.0.0-pr-27957-7e3588c → 0.0.0-pr-28218-5048fd1

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 (55) hide show
  1. package/generators.json +5 -11
  2. package/index.d.ts +0 -1
  3. package/index.js +1 -3
  4. package/package.json +8 -9
  5. package/plugins/storybook/index.js +1 -2
  6. package/src/generators/application/application.js +0 -1
  7. package/src/generators/application/lib/normalize-options.d.ts +1 -1
  8. package/src/generators/application/lib/normalize-options.js +2 -3
  9. package/src/generators/application/schema.d.ts +0 -1
  10. package/src/generators/application/schema.json +3 -9
  11. package/src/generators/component/component.d.ts +0 -1
  12. package/src/generators/component/component.js +0 -7
  13. package/src/generators/component/lib/normalize-options.js +0 -7
  14. package/src/generators/component/schema.d.ts +2 -20
  15. package/src/generators/component/schema.json +0 -29
  16. package/src/generators/cypress-component-configuration/cypress-component-configuration.js +0 -2
  17. package/src/generators/federate-module/federate-module.js +4 -5
  18. package/src/generators/hook/hook.d.ts +0 -1
  19. package/src/generators/hook/hook.js +9 -42
  20. package/src/generators/hook/schema.d.ts +3 -17
  21. package/src/generators/hook/schema.json +0 -29
  22. package/src/generators/host/host.d.ts +0 -1
  23. package/src/generators/host/host.js +2 -8
  24. package/src/generators/host/lib/add-module-federation-files.js +2 -2
  25. package/src/generators/host/lib/normalize-remote.js +10 -5
  26. package/src/generators/host/schema.d.ts +0 -1
  27. package/src/generators/host/schema.json +0 -6
  28. package/src/generators/library/lib/normalize-options.js +0 -1
  29. package/src/generators/library/library.js +1 -4
  30. package/src/generators/library/schema.d.ts +0 -1
  31. package/src/generators/library/schema.json +2 -7
  32. package/src/generators/redux/redux.d.ts +0 -1
  33. package/src/generators/redux/redux.js +0 -12
  34. package/src/generators/redux/schema.d.ts +3 -5
  35. package/src/generators/redux/schema.json +0 -9
  36. package/src/generators/remote/lib/setup-tspath-for-remote.d.ts +2 -2
  37. package/src/generators/remote/lib/setup-tspath-for-remote.js +2 -2
  38. package/src/generators/remote/remote.d.ts +0 -1
  39. package/src/generators/remote/remote.js +6 -12
  40. package/src/generators/remote/schema.d.ts +0 -1
  41. package/src/generators/remote/schema.json +0 -6
  42. package/src/generators/setup-tailwind/lib/update-project.js +1 -2
  43. package/src/generators/stories/schema.json +0 -10
  44. package/src/generators/stories/stories.d.ts +1 -3
  45. package/src/generators/stories/stories.js +2 -17
  46. package/src/generators/storybook-configuration/configuration.js +0 -9
  47. package/src/generators/storybook-configuration/schema.d.ts +0 -3
  48. package/src/generators/storybook-configuration/schema.json +0 -15
  49. package/src/utils/ct-utils.js +2 -7
  50. package/src/utils/versions.d.ts +1 -1
  51. package/src/utils/versions.js +1 -1
  52. package/src/generators/component-cypress-spec/component-cypress-spec.d.ts +0 -13
  53. package/src/generators/component-cypress-spec/component-cypress-spec.js +0 -104
  54. package/src/generators/component-cypress-spec/files/__componentName__.__fileExt__ +0 -13
  55. package/src/generators/component-cypress-spec/schema.json +0 -45
package/generators.json CHANGED
@@ -25,13 +25,13 @@
25
25
  "description": "Create a React library."
26
26
  },
27
27
  "component": {
28
- "factory": "./src/generators/component/component#componentGeneratorInternal",
28
+ "factory": "./src/generators/component/component",
29
29
  "schema": "./src/generators/component/schema.json",
30
30
  "description": "Create a React component.",
31
31
  "aliases": ["c"]
32
32
  },
33
33
  "redux": {
34
- "factory": "./src/generators/redux/redux#reduxGeneratorInternal",
34
+ "factory": "./src/generators/redux/redux",
35
35
  "schema": "./src/generators/redux/schema.json",
36
36
  "description": "Create a Redux slice for a project.",
37
37
  "aliases": ["slice"]
@@ -54,26 +54,20 @@
54
54
  "description": "Create stories/specs for all components declared in an app or library.",
55
55
  "hidden": false
56
56
  },
57
- "component-cypress-spec": {
58
- "factory": "./src/generators/component-cypress-spec/component-cypress-spec#componentCypressGenerator",
59
- "schema": "./src/generators/component-cypress-spec/schema.json",
60
- "description": "Create a Cypress spec for a UI component that has a story.",
61
- "hidden": false
62
- },
63
57
  "hook": {
64
- "factory": "./src/generators/hook/hook#hookGeneratorInternal",
58
+ "factory": "./src/generators/hook/hook",
65
59
  "schema": "./src/generators/hook/schema.json",
66
60
  "description": "Create a hook.",
67
61
  "aliases": ["c"]
68
62
  },
69
63
  "host": {
70
- "factory": "./src/generators/host/host#hostGeneratorInternal",
64
+ "factory": "./src/generators/host/host",
71
65
  "schema": "./src/generators/host/schema.json",
72
66
  "x-type": "application",
73
67
  "description": "Generate a host react application"
74
68
  },
75
69
  "remote": {
76
- "factory": "./src/generators/remote/remote#remoteGeneratorInternal",
70
+ "factory": "./src/generators/remote/remote",
77
71
  "schema": "./src/generators/remote/schema.json",
78
72
  "x-type": "application",
79
73
  "description": "Generate a remote react application"
package/index.d.ts CHANGED
@@ -8,7 +8,6 @@ export { reactDomVersion, reactVersion } from './src/utils/versions';
8
8
  export { applicationGenerator } from './src/generators/application/application';
9
9
  export { componentGenerator } from './src/generators/component/component';
10
10
  export { hookGenerator } from './src/generators/hook/hook';
11
- export { componentCypressGenerator } from './src/generators/component-cypress-spec/component-cypress-spec';
12
11
  export { componentStoryGenerator } from './src/generators/component-story/component-story';
13
12
  export { libraryGenerator } from './src/generators/library/library';
14
13
  export { reactInitGenerator } from './src/generators/init/init';
package/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.setupTailwindGenerator = exports.componentTestGenerator = exports.cypressComponentConfigGenerator = exports.remoteGenerator = exports.hostGenerator = exports.storybookConfigurationGenerator = exports.storiesGenerator = exports.reduxGenerator = exports.reactInitGenerator = exports.libraryGenerator = exports.componentStoryGenerator = exports.componentCypressGenerator = exports.hookGenerator = exports.componentGenerator = exports.applicationGenerator = exports.reactVersion = exports.reactDomVersion = exports.assertValidStyle = exports.cssInJsDependenciesBabel = exports.extendReactEslintJson = exports.extraEslintDependencies = exports.NxReactWebpackPlugin = void 0;
3
+ exports.setupTailwindGenerator = exports.componentTestGenerator = exports.cypressComponentConfigGenerator = exports.remoteGenerator = exports.hostGenerator = exports.storybookConfigurationGenerator = exports.storiesGenerator = exports.reduxGenerator = exports.reactInitGenerator = exports.libraryGenerator = exports.componentStoryGenerator = exports.hookGenerator = exports.componentGenerator = exports.applicationGenerator = exports.reactVersion = exports.reactDomVersion = exports.assertValidStyle = exports.cssInJsDependenciesBabel = exports.extendReactEslintJson = exports.extraEslintDependencies = exports.NxReactWebpackPlugin = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const nx_react_webpack_plugin_1 = require("./plugins/nx-react-webpack-plugin/nx-react-webpack-plugin");
6
6
  // TODO(v20): Remove this in favor of deep imports in order to load configs faster (150-200ms faster).
@@ -22,8 +22,6 @@ var component_1 = require("./src/generators/component/component");
22
22
  Object.defineProperty(exports, "componentGenerator", { enumerable: true, get: function () { return component_1.componentGenerator; } });
23
23
  var hook_1 = require("./src/generators/hook/hook");
24
24
  Object.defineProperty(exports, "hookGenerator", { enumerable: true, get: function () { return hook_1.hookGenerator; } });
25
- var component_cypress_spec_1 = require("./src/generators/component-cypress-spec/component-cypress-spec");
26
- Object.defineProperty(exports, "componentCypressGenerator", { enumerable: true, get: function () { return component_cypress_spec_1.componentCypressGenerator; } });
27
25
  var component_story_1 = require("./src/generators/component-story/component-story");
28
26
  Object.defineProperty(exports, "componentStoryGenerator", { enumerable: true, get: function () { return component_story_1.componentStoryGenerator; } });
29
27
  var library_1 = require("./src/generators/library/library");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/react",
3
- "version": "0.0.0-pr-27957-7e3588c",
3
+ "version": "0.0.0-pr-28218-5048fd1",
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,18 +38,17 @@
38
38
  "file-loader": "^6.2.0",
39
39
  "minimatch": "9.0.3",
40
40
  "tslib": "^2.3.0",
41
- "@module-federation/enhanced": "~0.6.0",
42
- "@nx/devkit": "0.0.0-pr-27957-7e3588c",
43
- "@nx/js": "0.0.0-pr-27957-7e3588c",
44
- "@nx/eslint": "0.0.0-pr-27957-7e3588c",
45
- "@nx/web": "0.0.0-pr-27957-7e3588c",
41
+ "@module-federation/enhanced": "0.6.6",
42
+ "@nx/devkit": "0.0.0-pr-28218-5048fd1",
43
+ "@nx/js": "0.0.0-pr-28218-5048fd1",
44
+ "@nx/eslint": "0.0.0-pr-28218-5048fd1",
45
+ "@nx/web": "0.0.0-pr-28218-5048fd1",
46
46
  "express": "^4.19.2",
47
- "http-proxy-middleware": "^3.0.0",
48
- "@nrwl/react": "0.0.0-pr-27957-7e3588c"
47
+ "http-proxy-middleware": "^3.0.0"
49
48
  },
50
49
  "publishConfig": {
51
50
  "access": "public"
52
51
  },
53
52
  "type": "commonjs",
54
53
  "types": "./index.d.ts"
55
- }
54
+ }
@@ -73,8 +73,7 @@ const fixBabelConfigurationIfNeeded = (webpackConfig, projectData) => {
73
73
  return;
74
74
  const isUsingBabelUpwardRootMode = Object.keys(projectData.projectNode.data.targets).find((k) => {
75
75
  const targetConfig = projectData.projectNode.data.targets[k];
76
- return ((targetConfig.executor === '@nx/webpack:webpack' ||
77
- targetConfig.executor === '@nrwl/webpack:webpack') &&
76
+ return (targetConfig.executor === '@nx/webpack:webpack' &&
78
77
  targetConfig.options?.babelUpwardRootMode);
79
78
  });
80
79
  if (isUsingBabelUpwardRootMode)
@@ -68,7 +68,6 @@ async function addLinting(host, options) {
68
68
  async function applicationGenerator(host, schema) {
69
69
  return await applicationGeneratorInternal(host, {
70
70
  addPlugin: false,
71
- projectNameAndRootFormat: 'derived',
72
71
  ...schema,
73
72
  });
74
73
  }
@@ -2,4 +2,4 @@ import { Tree } from '@nx/devkit';
2
2
  import { NormalizedSchema, Schema } from '../schema';
3
3
  export declare function normalizeDirectory(options: Schema): string;
4
4
  export declare function normalizeProjectName(options: Schema): string;
5
- export declare function normalizeOptions<T extends Schema = Schema>(host: Tree, options: Schema, callingGenerator?: string): Promise<NormalizedSchema<T>>;
5
+ export declare function normalizeOptions<T extends Schema = Schema>(host: Tree, options: Schema): Promise<NormalizedSchema<T>>;
@@ -17,14 +17,13 @@ function normalizeDirectory(options) {
17
17
  function normalizeProjectName(options) {
18
18
  return normalizeDirectory(options).replace(new RegExp('/', 'g'), '-');
19
19
  }
20
- async function normalizeOptions(host, options, callingGenerator = '@nx/react:application') {
20
+ async function normalizeOptions(host, options) {
21
21
  const { projectName: appProjectName, projectRoot: appProjectRoot, projectNameAndRootFormat, } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
22
22
  name: options.name,
23
23
  projectType: 'application',
24
24
  directory: options.directory,
25
25
  projectNameAndRootFormat: options.projectNameAndRootFormat,
26
26
  rootProject: options.rootProject,
27
- callingGenerator,
28
27
  });
29
28
  const nxJson = (0, devkit_1.readNxJson)(host);
30
29
  const addPlugin = process.env.NX_ADD_PLUGINS !== 'false' &&
@@ -37,7 +36,7 @@ async function normalizeOptions(host, options, callingGenerator = '@nx/react:app
37
36
  const parsedTags = options.tags
38
37
  ? options.tags.split(',').map((s) => s.trim())
39
38
  : [];
40
- const fileName = options.pascalCaseFiles ? 'App' : 'app';
39
+ const fileName = 'app';
41
40
  const styledModule = /^(css|scss|less|tailwind|none)$/.test(options.style)
42
41
  ? null
43
42
  : options.style;
@@ -13,7 +13,6 @@ export interface Schema {
13
13
  inSourceTests?: boolean;
14
14
  e2eTestRunner: 'cypress' | 'playwright' | 'none';
15
15
  linter: Linter | LinterType;
16
- pascalCaseFiles?: boolean;
17
16
  classComponent?: boolean;
18
17
  routing?: boolean;
19
18
  skipNxJson?: boolean;
@@ -111,9 +111,9 @@
111
111
  },
112
112
  "unitTestRunner": {
113
113
  "type": "string",
114
- "enum": ["jest", "vitest", "none"],
114
+ "enum": ["vitest", "jest", "none"],
115
115
  "description": "Test runner to use for unit tests.",
116
- "default": "jest"
116
+ "default": "vitest"
117
117
  },
118
118
  "inSourceTests": {
119
119
  "type": "boolean",
@@ -132,12 +132,6 @@
132
132
  "description": "Add tags to the application (used for linting).",
133
133
  "alias": "t"
134
134
  },
135
- "pascalCaseFiles": {
136
- "type": "boolean",
137
- "description": "Use pascal case component file name (e.g. `App.tsx`).",
138
- "alias": "P",
139
- "default": false
140
- },
141
135
  "classComponent": {
142
136
  "type": "boolean",
143
137
  "description": "Use class components instead of functional component.",
@@ -187,7 +181,7 @@
187
181
  "type": "string",
188
182
  "enum": ["vite", "webpack", "rspack"],
189
183
  "x-prompt": "Which bundler do you want to use to build the application?",
190
- "default": "webpack",
184
+ "default": "vite",
191
185
  "x-priority": "important"
192
186
  },
193
187
  "minimal": {
@@ -1,5 +1,4 @@
1
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import { Schema } from './schema';
3
3
  export declare function componentGenerator(host: Tree, schema: Schema): Promise<GeneratorCallback>;
4
- export declare function componentGeneratorInternal(host: Tree, schema: Schema): Promise<GeneratorCallback>;
5
4
  export default componentGenerator;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.componentGenerator = componentGenerator;
4
- exports.componentGeneratorInternal = componentGeneratorInternal;
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
7
6
  const path_1 = require("path");
@@ -12,12 +11,6 @@ const versions_1 = require("../../utils/versions");
12
11
  const get_component_tests_1 = require("./lib/get-component-tests");
13
12
  const normalize_options_1 = require("./lib/normalize-options");
14
13
  async function componentGenerator(host, schema) {
15
- return componentGeneratorInternal(host, {
16
- nameAndDirectoryFormat: 'derived',
17
- ...schema,
18
- });
19
- }
20
- async function componentGeneratorInternal(host, schema) {
21
14
  const options = await (0, normalize_options_1.normalizeOptions)(host, schema);
22
15
  createComponentFiles(host, options);
23
16
  const tasks = [];
@@ -7,18 +7,11 @@ const assertion_1 = require("../../../utils/assertion");
7
7
  async function normalizeOptions(tree, options) {
8
8
  (0, assertion_1.assertValidStyle)(options.style);
9
9
  const { artifactName: name, directory, fileName, filePath, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(tree, {
10
- artifactType: 'component',
11
- callingGenerator: '@nx/react:component',
12
10
  name: options.name,
13
11
  directory: options.directory,
14
- derivedDirectory: options.derivedDirectory ?? options.directory,
15
- flat: options.flat,
16
12
  nameAndDirectoryFormat: options.nameAndDirectoryFormat,
17
- project: options.project,
18
13
  fileExtension: 'tsx',
19
14
  fileName: options.fileName,
20
- pascalCaseFile: options.pascalCaseFiles,
21
- pascalCaseDirectory: options.pascalCaseDirectory,
22
15
  });
23
16
  const project = (0, devkit_1.readProjectConfiguration)(tree, projectName);
24
17
  const { className } = (0, devkit_1.names)(name);
@@ -1,38 +1,20 @@
1
+ import type { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
1
2
  import { SupportedStyles } from '../../../typings/style';
2
3
 
3
4
  export interface Schema {
4
5
  name: string;
5
- /**
6
- * @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.
7
- */
8
- project?: string;
9
6
  style: SupportedStyles;
10
7
  skipTests?: boolean;
11
8
  directory?: string;
12
9
  export?: boolean;
13
- /**
14
- * @deprecated Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19.
15
- */
16
- pascalCaseFiles?: boolean;
17
- /**
18
- * @deprecated Provide the `directory` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19.
19
- */
20
- pascalCaseDirectory?: boolean;
21
10
  classComponent?: boolean;
22
11
  routing?: boolean;
23
12
  js?: boolean;
24
- /**
25
- * @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19.
26
- */
27
- flat?: boolean;
28
13
  globalCss?: boolean;
29
14
  fileName?: string;
30
15
  inSourceTests?: boolean;
31
16
  skipFormat?: boolean;
32
- nameAndDirectoryFormat?: 'as-provided' | 'derived';
33
- // Used by other wrapping generators to preserve previous behavior
34
- // e.g. @nx/next:component
35
- derivedDirectory?: string;
17
+ nameAndDirectoryFormat?: NameAndDirectoryFormat;
36
18
  // Used by Next.js to determine how React should generate the page
37
19
  isNextPage?: boolean;
38
20
  }
@@ -6,15 +6,6 @@
6
6
  "description": "Create a React Component for Nx.",
7
7
  "type": "object",
8
8
  "properties": {
9
- "project": {
10
- "type": "string",
11
- "description": "The name of the project.",
12
- "alias": "p",
13
- "$default": {
14
- "$source": "projectName"
15
- },
16
- "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."
17
- },
18
9
  "name": {
19
10
  "type": "string",
20
11
  "description": "The name of the component.",
@@ -87,12 +78,6 @@
87
78
  "type": "string",
88
79
  "enum": ["as-provided", "derived"]
89
80
  },
90
- "flat": {
91
- "type": "boolean",
92
- "description": "Create component at the source root rather than its own directory.",
93
- "default": false,
94
- "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19."
95
- },
96
81
  "export": {
97
82
  "type": "boolean",
98
83
  "description": "When true, the component is exported from the project `index.ts` (if it exists).",
@@ -100,20 +85,6 @@
100
85
  "default": false,
101
86
  "x-prompt": "Should this component be exported in the project?"
102
87
  },
103
- "pascalCaseFiles": {
104
- "type": "boolean",
105
- "description": "Use pascal case component file name (e.g. `App.tsx`).",
106
- "alias": "P",
107
- "default": false,
108
- "x-deprecated": "Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19."
109
- },
110
- "pascalCaseDirectory": {
111
- "type": "boolean",
112
- "description": "Use pascal case directory name (e.g. `App/App.tsx`).",
113
- "alias": "R",
114
- "default": false,
115
- "x-deprecated": "Provide the `directory` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19."
116
- },
117
88
  "classComponent": {
118
89
  "type": "boolean",
119
90
  "alias": "C",
@@ -37,8 +37,6 @@ async function cypressComponentConfigGeneratorInternal(tree, options) {
37
37
  validExecutorNames: new Set([
38
38
  '@nx/webpack:webpack',
39
39
  '@nx/vite:build',
40
- '@nrwl/webpack:webpack',
41
- '@nrwl/vite:build',
42
40
  ]),
43
41
  });
44
42
  await (0, add_files_1.addFiles)(tree, projectConfig, options, found);
@@ -19,7 +19,7 @@ async function federateModuleGenerator(tree, schema) {
19
19
  let projectRoot, remoteName;
20
20
  if (!remote) {
21
21
  // create remote
22
- const remoteGenerator = await (0, remote_1.remoteGeneratorInternal)(tree, {
22
+ const remoteGeneratorTask = await (0, remote_1.remoteGenerator)(tree, {
23
23
  name: schema.remote,
24
24
  directory: schema.remoteDirectory,
25
25
  e2eTestRunner: schema.e2eTestRunner,
@@ -28,16 +28,15 @@ async function federateModuleGenerator(tree, schema) {
28
28
  style: schema.style,
29
29
  unitTestRunner: schema.unitTestRunner,
30
30
  host: schema.host,
31
- projectNameAndRootFormat: schema.projectNameAndRootFormat ?? 'derived',
32
31
  bundler: schema.bundler ?? 'rspack',
32
+ projectNameAndRootFormat: schema.projectNameAndRootFormat,
33
33
  });
34
- tasks.push(remoteGenerator);
34
+ tasks.push(remoteGeneratorTask);
35
35
  const { projectName, projectRoot: remoteRoot } = await (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
36
36
  name: schema.remote,
37
37
  directory: schema.remoteDirectory,
38
38
  projectType: 'application',
39
- projectNameAndRootFormat: schema.projectNameAndRootFormat ?? 'derived',
40
- callingGenerator: '@nx/react:federate-module',
39
+ projectNameAndRootFormat: schema.projectNameAndRootFormat,
41
40
  });
42
41
  projectRoot = remoteRoot;
43
42
  remoteName = projectName;
@@ -1,5 +1,4 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import { Schema } from './schema';
3
3
  export declare function hookGenerator(host: Tree, schema: Schema): Promise<void>;
4
- export declare function hookGeneratorInternal(host: Tree, schema: Schema): Promise<void>;
5
4
  export default hookGenerator;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hookGenerator = hookGenerator;
4
- exports.hookGeneratorInternal = hookGeneratorInternal;
5
4
  // TODO(jack): Remove inline renderHook function when RTL releases with its own version
6
5
  const devkit_1 = require("@nx/devkit");
7
6
  const ast_utils_1 = require("../../utils/ast-utils");
@@ -9,12 +8,6 @@ const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescri
9
8
  const path_1 = require("path");
10
9
  const artifact_name_and_directory_utils_1 = require("@nx/devkit/src/generators/artifact-name-and-directory-utils");
11
10
  async function hookGenerator(host, schema) {
12
- return hookGeneratorInternal(host, {
13
- nameAndDirectoryFormat: 'derived',
14
- ...schema,
15
- });
16
- }
17
- async function hookGeneratorInternal(host, schema) {
18
11
  const options = await normalizeOptions(host, schema);
19
12
  createFiles(host, options);
20
13
  addExportsToBarrel(host, options);
@@ -57,53 +50,27 @@ function addExportsToBarrel(host, options) {
57
50
  }
58
51
  async function normalizeOptions(host, options) {
59
52
  assertValidOptions(options);
60
- const { artifactName: name, directory: _directory, fileName: _fileName, nameAndDirectoryFormat, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
61
- artifactType: 'hook',
62
- callingGenerator: '@nx/react:hook',
53
+ const { directory, fileName: _fileName, project: projectName, } = await (0, artifact_name_and_directory_utils_1.determineArtifactNameAndDirectoryOptions)(host, {
63
54
  name: options.name,
64
55
  directory: options.directory,
65
- derivedDirectory: options.directory,
66
- flat: options.flat,
67
56
  nameAndDirectoryFormat: options.nameAndDirectoryFormat,
68
- project: options.project,
69
57
  fileExtension: 'tsx',
70
- pascalCaseFile: options.pascalCaseFiles,
71
- pascalCaseDirectory: options.pascalCaseDirectory,
72
58
  });
73
- let base = _fileName;
74
- if (base.startsWith('use-')) {
75
- base = base.substring(4);
76
- }
77
- else if (base.startsWith('use')) {
78
- base = base.substring(3);
79
- }
80
- const { className, fileName } = (0, devkit_1.names)(base);
59
+ const { className, fileName } = (0, devkit_1.names)(_fileName);
81
60
  // If using `as-provided` file and directory, then don't normalize.
82
61
  // Otherwise, support legacy behavior of prefixing filename with `use-`.
83
- const hookFilename = nameAndDirectoryFormat === 'as-provided'
84
- ? fileName
85
- : options.pascalCaseFiles
86
- ? 'use'.concat(className)
87
- : 'use-'.concat(fileName);
88
- const hookName = 'use'.concat(className);
89
- const hookTypeName = 'Use'.concat(className);
62
+ const hookFilename = fileName;
63
+ const hookName = className.toLocaleLowerCase().startsWith('use')
64
+ ? className
65
+ : 'use'.concat(className);
66
+ const hookTypeName = className.toLocaleLowerCase().startsWith('use')
67
+ ? className
68
+ : 'Use'.concat(className);
90
69
  const project = (0, devkit_1.getProjects)(host).get(projectName);
91
70
  const { sourceRoot: projectSourceRoot, projectType } = project;
92
71
  if (options.export && projectType === 'application') {
93
72
  devkit_1.logger.warn(`The "--export" option should not be used with applications and will do nothing.`);
94
73
  }
95
- // Support legacy behavior of derived directory to prefix with `use-`.
96
- let directory = _directory;
97
- if (nameAndDirectoryFormat === 'derived') {
98
- const parts = directory.split('/');
99
- parts.pop();
100
- if (!options.flat) {
101
- parts.push(options.pascalCaseDirectory
102
- ? 'use'.concat(className)
103
- : 'use-'.concat(fileName));
104
- }
105
- directory = parts.join('/');
106
- }
107
74
  return {
108
75
  ...options,
109
76
  directory,
@@ -1,24 +1,10 @@
1
+ import type { NameAndDirectoryFormat } from '@nx/devkit/src/generators/artifact-name-and-directory-utils';
2
+
1
3
  export interface Schema {
2
4
  name: string;
3
- /**
4
- * @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.
5
- */
6
- project: string;
7
5
  skipTests?: boolean;
8
6
  directory?: string;
9
7
  export?: boolean;
10
- /**
11
- * @deprecated Provide the `name` option instead and use the `as-provided` format. This option will be removed in Nx v19.
12
- */
13
- pascalCaseFiles?: boolean;
14
- /**
15
- * @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19.
16
- */
17
- pascalCaseDirectory?: boolean;
18
- /**
19
- * @deprecated Provide the `directory` option instead and use the `as-provided` format. This option will be removed in Nx v19.
20
- */
21
- flat?: boolean;
22
8
  js?: boolean;
23
- nameAndDirectoryFormat?: 'as-provided' | 'derived';
9
+ nameAndDirectoryFormat?: NameAndDirectoryFormat;
24
10
  }
@@ -12,15 +12,6 @@
12
12
  }
13
13
  ],
14
14
  "properties": {
15
- "project": {
16
- "type": "string",
17
- "description": "The name of the project.",
18
- "alias": "p",
19
- "$default": {
20
- "$source": "projectName"
21
- },
22
- "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."
23
- },
24
15
  "name": {
25
16
  "type": "string",
26
17
  "description": "The name of the hook.",
@@ -52,32 +43,12 @@
52
43
  "type": "string",
53
44
  "enum": ["as-provided", "derived"]
54
45
  },
55
- "flat": {
56
- "type": "boolean",
57
- "description": "Create hook at the source root rather than its own directory.",
58
- "default": false,
59
- "x-deprecated": "Provide the `directory` option instead and use the `as-provided` format. It will be removed in Nx v20."
60
- },
61
46
  "export": {
62
47
  "type": "boolean",
63
48
  "description": "When true, the hook is exported from the project `index.ts` (if it exists).",
64
49
  "alias": "e",
65
50
  "default": false,
66
51
  "x-prompt": "Should this hook be exported in the project?"
67
- },
68
- "pascalCaseFiles": {
69
- "type": "boolean",
70
- "description": "Use pascal case hook file name (e.g. `useHook.ts`).",
71
- "alias": "P",
72
- "default": false,
73
- "x-deprecated": "Provide the `name` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19."
74
- },
75
- "pascalCaseDirectory": {
76
- "type": "boolean",
77
- "description": "Use pascal case directory name (e.g. `useHook/useHook.ts`).",
78
- "alias": "R",
79
- "default": false,
80
- "x-deprecated": "Provide the `directory` in pascal-case and use the `as-provided` format. This option will be removed in Nx v19."
81
52
  }
82
53
  },
83
54
  "required": ["name"]
@@ -1,5 +1,4 @@
1
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import { Schema } from './schema';
3
3
  export declare function hostGenerator(host: Tree, schema: Schema): Promise<GeneratorCallback>;
4
- export declare function hostGeneratorInternal(host: Tree, schema: Schema): Promise<GeneratorCallback>;
5
4
  export default hostGenerator;
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.hostGenerator = hostGenerator;
4
- exports.hostGeneratorInternal = hostGeneratorInternal;
5
4
  const devkit_1 = require("@nx/devkit");
6
5
  const update_module_federation_project_1 = require("../../rules/update-module-federation-project");
7
6
  const application_1 = require("../application/application");
@@ -16,15 +15,9 @@ const add_mf_env_to_inputs_1 = require("../../utils/add-mf-env-to-inputs");
16
15
  const js_1 = require("@nx/js");
17
16
  const versions_1 = require("../../utils/versions");
18
17
  async function hostGenerator(host, schema) {
19
- return hostGeneratorInternal(host, {
20
- projectNameAndRootFormat: 'derived',
21
- ...schema,
22
- });
23
- }
24
- async function hostGeneratorInternal(host, schema) {
25
18
  const tasks = [];
26
19
  const options = {
27
- ...(await (0, normalize_options_1.normalizeOptions)(host, schema, '@nx/react:host')),
20
+ ...(await (0, normalize_options_1.normalizeOptions)(host, schema)),
28
21
  js: schema.js ?? false,
29
22
  typescriptConfiguration: schema.js
30
23
  ? false
@@ -46,6 +39,7 @@ async function hostGeneratorInternal(host, schema) {
46
39
  }
47
40
  const initTask = await (0, application_1.default)(host, {
48
41
  ...options,
42
+ name: options.projectName,
49
43
  // The target use-case is loading remotes as child routes, thus always enable routing.
50
44
  routing: true,
51
45
  skipFormat: true,
@@ -5,7 +5,7 @@ const devkit_1 = require("@nx/devkit");
5
5
  const maybe_js_1 = require("../../../utils/maybe-js");
6
6
  function addModuleFederationFiles(host, options, defaultRemoteManifest) {
7
7
  const templateVariables = {
8
- ...(0, devkit_1.names)(options.name),
8
+ ...(0, devkit_1.names)(options.projectName),
9
9
  ...options,
10
10
  static: !options?.dynamic,
11
11
  tmpl: '',
@@ -16,7 +16,7 @@ function addModuleFederationFiles(host, options, defaultRemoteManifest) {
16
16
  };
17
17
  }),
18
18
  };
19
- const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.name);
19
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(host, options.projectName);
20
20
  const pathToMFManifest = (0, devkit_1.joinPathFragments)(projectConfig.sourceRoot, 'assets/module-federation.manifest.json');
21
21
  // Module federation requires bootstrap code to be dynamically imported.
22
22
  // Renaming original entry file so we can use `import(./bootstrap)` in
@@ -10,18 +10,23 @@ async function normalizeRemoteName(tree, remote, options) {
10
10
  projectType: 'application',
11
11
  directory: options.directory,
12
12
  projectNameAndRootFormat: options.projectNameAndRootFormat,
13
- callingGenerator: '@nx/react:host',
14
13
  });
15
14
  return remoteName;
16
15
  }
17
16
  function normalizeRemoteDirectory(remote, options) {
18
- if (options.projectNameAndRootFormat === 'derived' || !options.directory) {
19
- return options.directory;
20
- }
21
17
  /**
22
18
  * With the `as-provided` format, the provided directory would be the root
23
19
  * of the host application. Append the remote name to the host parent
24
20
  * directory to get the remote directory.
21
+ *
22
+ * If no directory is provided, the remote directory will use the grandparent of the hostRoot 'acme/host/src' -> 'acme'
25
23
  */
26
- return (0, devkit_1.joinPathFragments)(options.directory, '..', remote);
24
+ if (options.directory) {
25
+ return (0, devkit_1.joinPathFragments)(options.directory, '..', remote);
26
+ }
27
+ else {
28
+ return options.appProjectRoot === '.'
29
+ ? remote
30
+ : (0, devkit_1.joinPathFragments)(options.appProjectRoot, '..', remote);
31
+ }
27
32
  }