@nx/angular 16.7.1 → 16.8.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/generators.json +4 -4
  2. package/package.json +10 -10
  3. package/src/generators/application/application.d.ts +1 -0
  4. package/src/generators/application/application.js +9 -3
  5. package/src/generators/application/lib/add-e2e.js +3 -3
  6. package/src/generators/application/lib/index.d.ts +0 -2
  7. package/src/generators/application/lib/index.js +0 -2
  8. package/src/generators/application/lib/normalize-options.d.ts +1 -1
  9. package/src/generators/application/lib/normalize-options.js +39 -31
  10. package/src/generators/application/lib/normalized-schema.d.ts +0 -2
  11. package/src/generators/application/schema.d.ts +4 -2
  12. package/src/generators/application/schema.json +6 -1
  13. package/src/generators/host/host.d.ts +1 -0
  14. package/src/generators/host/host.js +24 -12
  15. package/src/generators/host/schema.d.ts +4 -2
  16. package/src/generators/host/schema.json +6 -1
  17. package/src/generators/library/lib/normalize-options.d.ts +1 -1
  18. package/src/generators/library/lib/normalize-options.js +53 -53
  19. package/src/generators/library/lib/normalized-schema.d.ts +0 -1
  20. package/src/generators/library/library.d.ts +1 -0
  21. package/src/generators/library/library.js +12 -3
  22. package/src/generators/library/schema.d.ts +4 -2
  23. package/src/generators/library/schema.json +6 -1
  24. package/src/generators/ng-add/utilities/workspace.js +8 -2
  25. package/src/generators/remote/remote.d.ts +1 -0
  26. package/src/generators/remote/remote.js +24 -12
  27. package/src/generators/remote/schema.d.ts +4 -2
  28. package/src/generators/remote/schema.json +6 -1
  29. package/src/generators/setup-ssr/lib/add-hydration.d.ts +3 -0
  30. package/src/generators/setup-ssr/lib/add-hydration.js +30 -0
  31. package/src/generators/setup-ssr/lib/index.d.ts +1 -0
  32. package/src/generators/setup-ssr/lib/index.js +1 -0
  33. package/src/generators/setup-ssr/lib/normalize-options.d.ts +1 -0
  34. package/src/generators/setup-ssr/lib/normalize-options.js +2 -1
  35. package/src/generators/setup-ssr/lib/validate-options.js +14 -0
  36. package/src/generators/setup-ssr/schema.d.ts +1 -0
  37. package/src/generators/setup-ssr/schema.json +4 -0
  38. package/src/generators/setup-ssr/setup-ssr.js +7 -3
  39. package/src/utils/backward-compatible-versions.js +2 -2
  40. package/src/utils/versions.d.ts +1 -1
  41. package/src/utils/versions.js +1 -1
  42. package/src/generators/application/lib/remove-scaffolded-e2e.d.ts +0 -3
  43. package/src/generators/application/lib/remove-scaffolded-e2e.js +0 -22
  44. package/src/generators/application/lib/update-e2e-project.d.ts +0 -3
  45. package/src/generators/application/lib/update-e2e-project.js +0 -39
package/generators.json CHANGED
@@ -163,7 +163,7 @@
163
163
  "hidden": true
164
164
  },
165
165
  "application": {
166
- "factory": "./src/generators/application/application",
166
+ "factory": "./src/generators/application/application#applicationGeneratorInternal",
167
167
  "schema": "./src/generators/application/schema.json",
168
168
  "aliases": ["app"],
169
169
  "x-type": "application",
@@ -211,7 +211,7 @@
211
211
  "hidden": true
212
212
  },
213
213
  "library": {
214
- "factory": "./src/generators/library/library",
214
+ "factory": "./src/generators/library/library#libraryGeneratorInternal",
215
215
  "schema": "./src/generators/library/schema.json",
216
216
  "aliases": ["lib"],
217
217
  "x-type": "library",
@@ -224,7 +224,7 @@
224
224
  "description": "Creates a secondary entry point for an Angular publishable library."
225
225
  },
226
226
  "remote": {
227
- "factory": "./src/generators/remote/remote",
227
+ "factory": "./src/generators/remote/remote#remoteInternal",
228
228
  "schema": "./src/generators/remote/schema.json",
229
229
  "x-type": "application",
230
230
  "description": "Generate a Remote Angular Module Federation Application."
@@ -241,7 +241,7 @@
241
241
  "description": "Converts an old micro frontend configuration to use the new withModuleFederation helper. It will run successfully if the following conditions are met: \n - Is either a host or remote application \n - Shared npm package configurations have not been modified \n - Name used to identify the Micro Frontend application matches the project name \n\n{% callout type=\"warning\" title=\"Overrides\" %}This generator will overwrite your webpack config. If you have additional custom configuration in your config file, it will be lost!{% /callout %}"
242
242
  },
243
243
  "host": {
244
- "factory": "./src/generators/host/host",
244
+ "factory": "./src/generators/host/host#hostInternal",
245
245
  "schema": "./src/generators/host/schema.json",
246
246
  "x-type": "application",
247
247
  "description": "Generate a Host Angular Module Federation Application."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/angular",
3
- "version": "16.7.1",
3
+ "version": "16.8.0-beta.0",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for Angular contains executors, generators, and utilities for managing Angular applications and libraries within an Nx workspace. It provides: \n\n- Integration with libraries such as Storybook, Jest, ESLint, Tailwind CSS, and Cypress. \n\n- Generators to help scaffold code quickly (like: Micro Frontends, Libraries, both internal to your codebase and publishable to npm) \n\n- Upgrading AngularJS applications \n\n- Single Component Application Modules (SCAMs) \n\n- NgRx helpers. \n\n- Utilities for automatic workspace refactoring.",
6
6
  "repository": {
@@ -66,14 +66,14 @@
66
66
  "migrations": "./migrations.json"
67
67
  },
68
68
  "dependencies": {
69
- "@nrwl/angular": "16.7.1",
70
- "@nx/cypress": "16.7.1",
71
- "@nx/devkit": "16.7.1",
72
- "@nx/jest": "16.7.1",
73
- "@nx/js": "16.7.1",
74
- "@nx/linter": "16.7.1",
75
- "@nx/webpack": "16.7.1",
76
- "@nx/workspace": "16.7.1",
69
+ "@nrwl/angular": "16.8.0-beta.0",
70
+ "@nx/cypress": "16.8.0-beta.0",
71
+ "@nx/devkit": "16.8.0-beta.0",
72
+ "@nx/jest": "16.8.0-beta.0",
73
+ "@nx/js": "16.8.0-beta.0",
74
+ "@nx/linter": "16.8.0-beta.0",
75
+ "@nx/webpack": "16.8.0-beta.0",
76
+ "@nx/workspace": "16.8.0-beta.0",
77
77
  "@phenomnomnominal/tsquery": "~5.0.1",
78
78
  "@typescript-eslint/type-utils": "^5.36.1",
79
79
  "chalk": "^4.1.0",
@@ -107,5 +107,5 @@
107
107
  "module": "fesm2022/nx-angular.mjs",
108
108
  "typings": "index.d.ts",
109
109
  "sideEffects": false,
110
- "gitHead": "8b38708d6c18496711695499d07c95f3ecc31cc9"
110
+ "gitHead": "818352404283c1d34ab303d91b3bd16474f54916"
111
111
  }
@@ -1,4 +1,5 @@
1
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import type { Schema } from './schema';
3
3
  export declare function applicationGenerator(tree: Tree, schema: Partial<Schema>): Promise<GeneratorCallback>;
4
+ export declare function applicationGeneratorInternal(tree: Tree, schema: Partial<Schema>): Promise<GeneratorCallback>;
4
5
  export default applicationGenerator;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.applicationGenerator = void 0;
3
+ exports.applicationGeneratorInternal = exports.applicationGenerator = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const init_1 = require("../init/init");
@@ -10,6 +10,12 @@ const lib_1 = require("./lib");
10
10
  const semver_1 = require("semver");
11
11
  const enquirer_1 = require("enquirer");
12
12
  function applicationGenerator(tree, schema) {
13
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
14
+ return yield applicationGeneratorInternal(tree, Object.assign({ projectNameAndRootFormat: 'derived' }, schema));
15
+ });
16
+ }
17
+ exports.applicationGenerator = applicationGenerator;
18
+ function applicationGeneratorInternal(tree, schema) {
13
19
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
14
20
  const installedAngularVersionInfo = (0, version_utils_1.getInstalledAngularVersionInfo)(tree);
15
21
  if ((0, semver_1.lt)(installedAngularVersionInfo.version, '14.1.0') && schema.standalone) {
@@ -25,7 +31,7 @@ function applicationGenerator(tree, schema) {
25
31
  type: 'confirm',
26
32
  }).then((a) => a['standalone-components']);
27
33
  }
28
- const options = (0, lib_1.normalizeOptions)(tree, schema);
34
+ const options = yield (0, lib_1.normalizeOptions)(tree, schema);
29
35
  const rootOffset = (0, devkit_1.offsetFromRoot)(options.appProjectRoot);
30
36
  yield (0, init_1.angularInitGenerator)(tree, Object.assign(Object.assign({}, options), { skipFormat: true }));
31
37
  (0, lib_1.createProject)(tree, options);
@@ -63,5 +69,5 @@ function applicationGenerator(tree, schema) {
63
69
  };
64
70
  });
65
71
  }
66
- exports.applicationGenerator = applicationGenerator;
72
+ exports.applicationGeneratorInternal = applicationGeneratorInternal;
67
73
  exports.default = applicationGenerator;
@@ -4,18 +4,18 @@ exports.addE2e = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const versions_1 = require("../../../utils/versions");
7
- const remove_scaffolded_e2e_1 = require("./remove-scaffolded-e2e");
8
7
  const cypress_1 = require("@nx/cypress");
9
8
  function addE2e(tree, options) {
10
9
  var _a;
11
10
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
12
- (0, remove_scaffolded_e2e_1.removeScaffoldedE2e)(tree, options, options.ngCliSchematicE2ERoot);
13
11
  if (options.e2eTestRunner === 'cypress') {
14
12
  // TODO: This can call `@nx/web:static-config` generator when ready
15
13
  addFileServerTarget(tree, options, 'serve-static');
16
14
  yield (0, cypress_1.cypressProjectGenerator)(tree, {
17
15
  name: options.e2eProjectName,
18
- directory: options.directory,
16
+ directory: options.e2eProjectRoot,
17
+ // the name and root are already normalized, instruct the generator to use them as is
18
+ projectNameAndRootFormat: 'as-provided',
19
19
  project: options.name,
20
20
  linter: options.linter,
21
21
  standaloneConfig: options.standaloneConfig,
@@ -7,7 +7,5 @@ export * from './create-project';
7
7
  export * from './enable-strict-type-checking';
8
8
  export * from './normalize-options';
9
9
  export * from './normalized-schema';
10
- export * from './remove-scaffolded-e2e';
11
10
  export * from './set-app-strict-default';
12
- export * from './update-e2e-project';
13
11
  export * from './update-editor-tsconfig';
@@ -10,7 +10,5 @@ tslib_1.__exportStar(require("./create-project"), exports);
10
10
  tslib_1.__exportStar(require("./enable-strict-type-checking"), exports);
11
11
  tslib_1.__exportStar(require("./normalize-options"), exports);
12
12
  tslib_1.__exportStar(require("./normalized-schema"), exports);
13
- tslib_1.__exportStar(require("./remove-scaffolded-e2e"), exports);
14
13
  tslib_1.__exportStar(require("./set-app-strict-default"), exports);
15
- tslib_1.__exportStar(require("./update-e2e-project"), exports);
16
14
  tslib_1.__exportStar(require("./update-editor-tsconfig"), exports);
@@ -1,4 +1,4 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import type { Schema } from '../schema';
3
3
  import type { NormalizedSchema } from './normalized-schema';
4
- export declare function normalizeOptions(host: Tree, options: Partial<Schema>): NormalizedSchema;
4
+ export declare function normalizeOptions(host: Tree, options: Partial<Schema>): Promise<NormalizedSchema>;
@@ -1,40 +1,48 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = void 0;
4
- const devkit_1 = require("@nx/devkit");
4
+ const tslib_1 = require("tslib");
5
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
5
6
  const get_npm_scope_1 = require("@nx/js/src/utils/package-json/get-npm-scope");
6
- const test_runners_1 = require("../../../utils/test-runners");
7
7
  const linter_1 = require("@nx/linter");
8
+ const test_runners_1 = require("../../../utils/test-runners");
8
9
  const project_1 = require("../../utils/project");
9
10
  function normalizeOptions(host, options) {
10
- var _a, _b;
11
- const { layoutDirectory, projectDirectory } = (0, devkit_1.extractLayoutDirectory)(options.directory);
12
- const appDirectory = (0, project_1.normalizeDirectory)(options.name, projectDirectory);
13
- const appProjectName = (0, project_1.normalizeProjectName)(options.name, projectDirectory);
14
- const e2eProjectName = options.rootProject
15
- ? 'e2e'
16
- : `${(0, devkit_1.names)(options.name).fileName}-e2e`;
17
- const { appsDir: defaultAppsDir, standaloneAsDefault } = (0, devkit_1.getWorkspaceLayout)(host);
18
- const appsDir = layoutDirectory !== null && layoutDirectory !== void 0 ? layoutDirectory : defaultAppsDir;
19
- const appProjectRoot = options.rootProject
20
- ? '.'
21
- : (0, devkit_1.joinPathFragments)(appsDir, appDirectory);
22
- const e2eProjectRoot = options.rootProject
23
- ? 'e2e'
24
- : (0, devkit_1.joinPathFragments)(appsDir, `${appDirectory}-e2e`);
25
- const parsedTags = options.tags
26
- ? options.tags.split(',').map((s) => s.trim())
27
- : [];
28
- const prefix = (0, project_1.normalizeNewProjectPrefix)(options.prefix, (0, get_npm_scope_1.getNpmScope)(host), 'app');
29
- options.standaloneConfig = (_a = options.standaloneConfig) !== null && _a !== void 0 ? _a : standaloneAsDefault;
30
- const ngCliSchematicAppRoot = appProjectName;
31
- const ngCliSchematicE2ERoot = `${appProjectName}/e2e`;
32
- // Set defaults and then overwrite with user options
33
- return Object.assign(Object.assign({ style: 'css', routing: false, inlineStyle: false, inlineTemplate: false, skipTests: options.unitTestRunner === test_runners_1.UnitTestRunner.None, skipFormat: false, unitTestRunner: test_runners_1.UnitTestRunner.Jest, e2eTestRunner: test_runners_1.E2eTestRunner.Cypress, linter: linter_1.Linter.EsLint, strict: true, bundler: (_b = options.bundler) !== null && _b !== void 0 ? _b : 'webpack' }, options), { prefix, name: appProjectName, appProjectRoot,
34
- e2eProjectRoot,
35
- e2eProjectName,
36
- parsedTags,
37
- ngCliSchematicAppRoot,
38
- ngCliSchematicE2ERoot });
11
+ var _a;
12
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
13
+ const { projectName: appProjectName, projectRoot: appProjectRoot, projectNameAndRootFormat, } = yield (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
14
+ name: options.name,
15
+ projectType: 'application',
16
+ directory: options.directory,
17
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
18
+ rootProject: options.rootProject,
19
+ callingGenerator: '@nx/angular:application',
20
+ });
21
+ options.rootProject = appProjectRoot === '.';
22
+ options.projectNameAndRootFormat = projectNameAndRootFormat;
23
+ let e2eProjectName = 'e2e';
24
+ let e2eProjectRoot = 'e2e';
25
+ if (!options.rootProject) {
26
+ const projectNameAndRoot = yield (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
27
+ name: `${options.name}-e2e`,
28
+ projectType: 'application',
29
+ directory: options.directory,
30
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
31
+ rootProject: options.rootProject,
32
+ callingGenerator: '@nx/angular:application',
33
+ });
34
+ e2eProjectName = projectNameAndRoot.projectName;
35
+ e2eProjectRoot = projectNameAndRoot.projectRoot;
36
+ }
37
+ const parsedTags = options.tags
38
+ ? options.tags.split(',').map((s) => s.trim())
39
+ : [];
40
+ const prefix = (0, project_1.normalizeNewProjectPrefix)(options.prefix, (0, get_npm_scope_1.getNpmScope)(host), 'app');
41
+ // Set defaults and then overwrite with user options
42
+ return Object.assign(Object.assign({ style: 'css', routing: false, inlineStyle: false, inlineTemplate: false, skipTests: options.unitTestRunner === test_runners_1.UnitTestRunner.None, skipFormat: false, unitTestRunner: test_runners_1.UnitTestRunner.Jest, e2eTestRunner: test_runners_1.E2eTestRunner.Cypress, linter: linter_1.Linter.EsLint, strict: true, bundler: (_a = options.bundler) !== null && _a !== void 0 ? _a : 'webpack' }, options), { prefix, name: appProjectName, appProjectRoot,
43
+ e2eProjectRoot,
44
+ e2eProjectName,
45
+ parsedTags });
46
+ });
39
47
  }
40
48
  exports.normalizeOptions = normalizeOptions;
@@ -10,6 +10,4 @@ export interface NormalizedSchema extends Schema {
10
10
  e2eProjectName: string;
11
11
  e2eProjectRoot: string;
12
12
  parsedTags: string[];
13
- ngCliSchematicAppRoot: string;
14
- ngCliSchematicE2ERoot: string;
15
13
  }
@@ -1,5 +1,6 @@
1
- import { Linter } from '@nx/linter';
2
- import { E2eTestRunner, UnitTestRunner } from '../../utils/test-runners';
1
+ import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
+ import type { Linter } from '@nx/linter';
3
+ import type { E2eTestRunner, UnitTestRunner } from '../../utils/test-runners';
3
4
  import type { Styles } from '../utils/types';
4
5
 
5
6
  export interface Schema {
@@ -14,6 +15,7 @@ export interface Schema {
14
15
  style?: Styles;
15
16
  skipTests?: boolean;
16
17
  directory?: string;
18
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
17
19
  tags?: string;
18
20
  linter?: Linter;
19
21
  unitTestRunner?: UnitTestRunner;
@@ -14,13 +14,18 @@
14
14
  "index": 0
15
15
  },
16
16
  "x-prompt": "What name would you like to use for the application?",
17
- "pattern": "^[a-zA-Z].*$"
17
+ "pattern": "^[a-zA-Z][^:]*$"
18
18
  },
19
19
  "directory": {
20
20
  "description": "The directory of the new application.",
21
21
  "type": "string",
22
22
  "x-priority": "important"
23
23
  },
24
+ "projectNameAndRootFormat": {
25
+ "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
26
+ "type": "string",
27
+ "enum": ["as-provided", "derived"]
28
+ },
24
29
  "style": {
25
30
  "description": "The file extension to be used for style files.",
26
31
  "type": "string",
@@ -1,4 +1,5 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import type { Schema } from './schema';
3
3
  export declare function host(tree: Tree, options: Schema): Promise<import("@nx/devkit").GeneratorCallback>;
4
+ export declare function hostInternal(tree: Tree, options: Schema): Promise<import("@nx/devkit").GeneratorCallback>;
4
5
  export default host;
@@ -1,17 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.host = void 0;
3
+ exports.hostInternal = exports.host = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
7
+ const semver_1 = require("semver");
8
+ const test_runners_1 = require("../../utils/test-runners");
6
9
  const application_1 = require("../application/application");
7
10
  const remote_1 = require("../remote/remote");
8
- const project_1 = require("../utils/project");
9
11
  const setup_mf_1 = require("../setup-mf/setup-mf");
10
- const test_runners_1 = require("../../utils/test-runners");
11
- const lib_1 = require("./lib");
12
12
  const version_utils_1 = require("../utils/version-utils");
13
- const semver_1 = require("semver");
13
+ const lib_1 = require("./lib");
14
14
  function host(tree, options) {
15
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
16
+ return yield hostInternal(tree, Object.assign({ projectNameAndRootFormat: 'derived' }, options));
17
+ });
18
+ }
19
+ exports.host = host;
20
+ function hostInternal(tree, options) {
15
21
  var _a;
16
22
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
17
23
  const installedAngularVersionInfo = (0, version_utils_1.getInstalledAngularVersionInfo)(tree);
@@ -32,12 +38,18 @@ function host(tree, options) {
32
38
  }
33
39
  });
34
40
  }
35
- const { projectDirectory } = (0, devkit_1.extractLayoutDirectory)(options.directory);
36
- const appName = (0, project_1.normalizeProjectName)(options.name, projectDirectory);
41
+ const { projectName: hostProjectName, projectNameAndRootFormat } = yield (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
42
+ name: options.name,
43
+ projectType: 'application',
44
+ directory: options.directory,
45
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
46
+ callingGenerator: '@nx/angular:host',
47
+ });
48
+ options.projectNameAndRootFormat = projectNameAndRootFormat;
37
49
  const appInstallTask = yield (0, application_1.default)(tree, Object.assign(Object.assign({}, options), { standalone: (_a = options.standalone) !== null && _a !== void 0 ? _a : false, routing: true, port: 4200, skipFormat: true }));
38
50
  const skipE2E = !options.e2eTestRunner || options.e2eTestRunner === test_runners_1.E2eTestRunner.None;
39
51
  yield (0, setup_mf_1.setupMf)(tree, {
40
- appName,
52
+ appName: hostProjectName,
41
53
  mfType: 'host',
42
54
  routing: true,
43
55
  port: 4200,
@@ -46,16 +58,16 @@ function host(tree, options) {
46
58
  skipPackageJson: options.skipPackageJson,
47
59
  skipFormat: true,
48
60
  skipE2E,
49
- e2eProjectName: skipE2E ? undefined : `${appName}-e2e`,
61
+ e2eProjectName: skipE2E ? undefined : `${hostProjectName}-e2e`,
50
62
  prefix: options.prefix,
51
63
  });
52
64
  let installTasks = [appInstallTask];
53
65
  if (options.ssr) {
54
- let ssrInstallTask = yield (0, lib_1.addSsr)(tree, options, appName);
66
+ let ssrInstallTask = yield (0, lib_1.addSsr)(tree, options, hostProjectName);
55
67
  installTasks.push(ssrInstallTask);
56
68
  }
57
69
  for (const remote of remotesToGenerate) {
58
- yield (0, remote_1.default)(tree, Object.assign(Object.assign({}, options), { name: remote, host: appName, skipFormat: true, standalone: options.standalone }));
70
+ yield (0, remote_1.default)(tree, Object.assign(Object.assign({}, options), { name: remote, host: hostProjectName, skipFormat: true, standalone: options.standalone }));
59
71
  }
60
72
  if (!options.skipFormat) {
61
73
  yield (0, devkit_1.formatFiles)(tree);
@@ -63,5 +75,5 @@ function host(tree, options) {
63
75
  return (0, devkit_1.runTasksInSerial)(...installTasks);
64
76
  });
65
77
  }
66
- exports.host = host;
78
+ exports.hostInternal = hostInternal;
67
79
  exports.default = host;
@@ -1,5 +1,6 @@
1
- import { Linter } from '@nx/linter';
2
- import { E2eTestRunner, UnitTestRunner } from '../../utils/test-runners';
1
+ import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
+ import type { Linter } from '@nx/linter';
3
+ import type { E2eTestRunner, UnitTestRunner } from '../../utils/test-runners';
3
4
  import type { Styles } from '../utils/types';
4
5
 
5
6
  export interface Schema {
@@ -14,6 +15,7 @@ export interface Schema {
14
15
  style?: Styles;
15
16
  skipTests?: boolean;
16
17
  directory?: string;
18
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
17
19
  tags?: string;
18
20
  linter?: Linter;
19
21
  unitTestRunner?: UnitTestRunner;
@@ -19,7 +19,7 @@
19
19
  "$source": "argv",
20
20
  "index": 0
21
21
  },
22
- "pattern": "^[a-zA-Z].*$"
22
+ "pattern": "^[a-zA-Z][^:]*$"
23
23
  },
24
24
  "remotes": {
25
25
  "type": "array",
@@ -35,6 +35,11 @@
35
35
  "description": "The directory of the new application.",
36
36
  "type": "string"
37
37
  },
38
+ "projectNameAndRootFormat": {
39
+ "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
40
+ "type": "string",
41
+ "enum": ["as-provided", "derived"]
42
+ },
38
43
  "style": {
39
44
  "description": "The file extension to be used for style files.",
40
45
  "type": "string",
@@ -1,4 +1,4 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import { Schema } from '../schema';
3
3
  import { NormalizedSchema } from './normalized-schema';
4
- export declare function normalizeOptions(host: Tree, schema: Schema): NormalizedSchema;
4
+ export declare function normalizeOptions(host: Tree, schema: Schema): Promise<NormalizedSchema>;
@@ -3,63 +3,63 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
- const get_import_path_1 = require("@nx/js/src/utils/get-import-path");
6
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
7
7
  const get_npm_scope_1 = require("@nx/js/src/utils/package-json/get-npm-scope");
8
8
  const linter_1 = require("@nx/linter");
9
9
  const test_runners_1 = require("../../../utils/test-runners");
10
10
  const project_1 = require("../../utils/project");
11
11
  function normalizeOptions(host, schema) {
12
- var _a, _b, _c, _d;
13
- // Create a schema with populated default values
14
- const options = Object.assign({ buildable: false, linter: linter_1.Linter.EsLint, publishable: false, simpleName: false, skipFormat: false, unitTestRunner: test_runners_1.UnitTestRunner.Jest,
15
- // Publishable libs cannot use `full` yet, so if its false then use the passed value or default to `full`
16
- compilationMode: schema.publishable
17
- ? 'partial'
18
- : (_a = schema.compilationMode) !== null && _a !== void 0 ? _a : 'full', skipModule: schema.skipModule || schema.standalone }, schema);
19
- const name = (0, devkit_1.names)(options.name).fileName;
20
- const { layoutDirectory, projectDirectory } = (0, devkit_1.extractLayoutDirectory)(options.directory);
21
- const fullProjectDirectory = projectDirectory
22
- ? `${(0, devkit_1.names)(projectDirectory).fileName}/${name}`.replace(/\/+/g, '/')
23
- : name;
24
- const { libsDir: defaultLibsDirectory, standaloneAsDefault } = (0, devkit_1.getWorkspaceLayout)(host);
25
- const npmScope = (0, get_npm_scope_1.getNpmScope)(host);
26
- const libsDir = layoutDirectory !== null && layoutDirectory !== void 0 ? layoutDirectory : defaultLibsDirectory;
27
- const projectName = fullProjectDirectory
28
- .replace(new RegExp('/', 'g'), '-')
29
- .replace(/-\d+/g, '');
30
- const fileName = options.simpleName ? name : projectName;
31
- const projectRoot = (0, devkit_1.joinPathFragments)(libsDir, fullProjectDirectory);
32
- const moduleName = `${(0, devkit_1.names)(fileName).className}Module`;
33
- const parsedTags = options.tags
34
- ? options.tags.split(',').map((s) => s.trim())
35
- : [];
36
- const modulePath = `${projectRoot}/src/lib/${fileName}.module.ts`;
37
- const prefix = (0, project_1.normalizeNewProjectPrefix)(options.prefix, npmScope, 'lib');
38
- options.standaloneConfig = (_b = options.standaloneConfig) !== null && _b !== void 0 ? _b : standaloneAsDefault;
39
- const importPath = options.importPath || (0, get_import_path_1.getImportPath)(host, fullProjectDirectory);
40
- const ngCliSchematicLibRoot = projectName;
41
- const allNormalizedOptions = Object.assign(Object.assign({}, options), { linter: (_c = options.linter) !== null && _c !== void 0 ? _c : linter_1.Linter.EsLint, unitTestRunner: (_d = options.unitTestRunner) !== null && _d !== void 0 ? _d : test_runners_1.UnitTestRunner.Jest, prefix, name: projectName, projectRoot, entryFile: 'index', moduleName, projectDirectory: fullProjectDirectory, modulePath,
42
- parsedTags,
43
- fileName,
44
- importPath,
45
- ngCliSchematicLibRoot, standaloneComponentName: `${(0, devkit_1.names)(name).className}Component` });
46
- const { displayBlock, inlineStyle, inlineTemplate, viewEncapsulation, changeDetection, style, skipTests, selector, skipSelector, flat } = allNormalizedOptions, libraryOptions = tslib_1.__rest(allNormalizedOptions, ["displayBlock", "inlineStyle", "inlineTemplate", "viewEncapsulation", "changeDetection", "style", "skipTests", "selector", "skipSelector", "flat"]);
47
- return {
48
- libraryOptions,
49
- componentOptions: {
50
- name: fileName,
51
- standalone: libraryOptions.standalone,
52
- displayBlock,
53
- inlineStyle,
54
- inlineTemplate,
55
- viewEncapsulation,
56
- changeDetection,
57
- style,
58
- skipTests,
59
- selector,
60
- skipSelector,
61
- flat,
62
- },
63
- };
12
+ var _a, _b, _c;
13
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
14
+ // Create a schema with populated default values
15
+ const options = Object.assign({ buildable: false, linter: linter_1.Linter.EsLint, publishable: false, simpleName: false, skipFormat: false, unitTestRunner: test_runners_1.UnitTestRunner.Jest,
16
+ // Publishable libs cannot use `full` yet, so if its false then use the passed value or default to `full`
17
+ compilationMode: schema.publishable
18
+ ? 'partial'
19
+ : (_a = schema.compilationMode) !== null && _a !== void 0 ? _a : 'full', skipModule: schema.skipModule || schema.standalone }, schema);
20
+ const { projectName, names: projectNames, projectRoot, importPath, } = yield (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(host, {
21
+ name: options.name,
22
+ projectType: 'library',
23
+ directory: options.directory,
24
+ importPath: options.importPath,
25
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
26
+ callingGenerator: '@nx/angular:library',
27
+ });
28
+ const fileName = options.simpleName
29
+ ? projectNames.projectSimpleName
30
+ : projectNames.projectFileName;
31
+ const moduleName = `${(0, devkit_1.names)(fileName).className}Module`;
32
+ const parsedTags = options.tags
33
+ ? options.tags.split(',').map((s) => s.trim())
34
+ : [];
35
+ const modulePath = `${projectRoot}/src/lib/${fileName}.module.ts`;
36
+ const npmScope = (0, get_npm_scope_1.getNpmScope)(host);
37
+ const prefix = (0, project_1.normalizeNewProjectPrefix)(options.prefix, npmScope, 'lib');
38
+ const ngCliSchematicLibRoot = projectName;
39
+ const allNormalizedOptions = Object.assign(Object.assign({}, options), { linter: (_b = options.linter) !== null && _b !== void 0 ? _b : linter_1.Linter.EsLint, unitTestRunner: (_c = options.unitTestRunner) !== null && _c !== void 0 ? _c : test_runners_1.UnitTestRunner.Jest, prefix, name: projectName, projectRoot, entryFile: 'index', moduleName,
40
+ modulePath,
41
+ parsedTags,
42
+ fileName,
43
+ importPath,
44
+ ngCliSchematicLibRoot, standaloneComponentName: `${(0, devkit_1.names)(projectNames.projectSimpleName).className}Component` });
45
+ const { displayBlock, inlineStyle, inlineTemplate, viewEncapsulation, changeDetection, style, skipTests, selector, skipSelector, flat } = allNormalizedOptions, libraryOptions = tslib_1.__rest(allNormalizedOptions, ["displayBlock", "inlineStyle", "inlineTemplate", "viewEncapsulation", "changeDetection", "style", "skipTests", "selector", "skipSelector", "flat"]);
46
+ return {
47
+ libraryOptions,
48
+ componentOptions: {
49
+ name: fileName,
50
+ standalone: libraryOptions.standalone,
51
+ displayBlock,
52
+ inlineStyle,
53
+ inlineTemplate,
54
+ viewEncapsulation,
55
+ changeDetection,
56
+ style,
57
+ skipTests,
58
+ selector,
59
+ skipSelector,
60
+ flat,
61
+ },
62
+ };
63
+ });
64
64
  }
65
65
  exports.normalizeOptions = normalizeOptions;
@@ -34,7 +34,6 @@ export interface NormalizedSchema {
34
34
  entryFile: string;
35
35
  modulePath: string;
36
36
  moduleName: string;
37
- projectDirectory: string;
38
37
  parsedTags: string[];
39
38
  ngCliSchematicLibRoot: string;
40
39
  standaloneComponentName: string;
@@ -1,4 +1,5 @@
1
1
  import { GeneratorCallback, Tree } from '@nx/devkit';
2
2
  import { Schema } from './schema';
3
3
  export declare function libraryGenerator(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
4
+ export declare function libraryGeneratorInternal(tree: Tree, schema: Schema): Promise<GeneratorCallback>;
4
5
  export default libraryGenerator;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.libraryGenerator = void 0;
3
+ exports.libraryGeneratorInternal = exports.libraryGenerator = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
6
  const jest_1 = require("@nx/jest");
@@ -22,6 +22,15 @@ const update_tsconfig_1 = require("./lib/update-tsconfig");
22
22
  const create_files_1 = require("./lib/create-files");
23
23
  const add_project_1 = require("./lib/add-project");
24
24
  function libraryGenerator(tree, schema) {
25
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
26
+ return yield libraryGeneratorInternal(tree, Object.assign({
27
+ // provide a default projectNameAndRootFormat to avoid breaking changes
28
+ // to external generators invoking this one
29
+ projectNameAndRootFormat: 'derived' }, schema));
30
+ });
31
+ }
32
+ exports.libraryGenerator = libraryGenerator;
33
+ function libraryGeneratorInternal(tree, schema) {
25
34
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
26
35
  // Do some validation checks
27
36
  if (!schema.routing && schema.lazy) {
@@ -37,7 +46,7 @@ function libraryGenerator(tree, schema) {
37
46
  if ((0, semver_1.lt)(userInstalledAngularVersion.version, '14.1.0') && schema.standalone) {
38
47
  throw new Error(`The "--standalone" option is not supported in Angular versions < 14.1.0.`);
39
48
  }
40
- const options = (0, normalize_options_1.normalizeOptions)(tree, schema);
49
+ const options = yield (0, normalize_options_1.normalizeOptions)(tree, schema);
41
50
  const { libraryOptions } = options;
42
51
  const pkgVersions = (0, version_utils_1.versions)(tree);
43
52
  yield (0, init_1.default)(tree, Object.assign(Object.assign({}, libraryOptions), { skipFormat: true, e2eTestRunner: test_runners_1.E2eTestRunner.None }));
@@ -77,7 +86,7 @@ function libraryGenerator(tree, schema) {
77
86
  };
78
87
  });
79
88
  }
80
- exports.libraryGenerator = libraryGenerator;
89
+ exports.libraryGeneratorInternal = libraryGeneratorInternal;
81
90
  function addUnitTestRunner(host, options) {
82
91
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
83
92
  if (options.unitTestRunner === 'jest') {
@@ -1,5 +1,6 @@
1
- import { UnitTestRunner } from '../../utils/test-runners';
2
- import { Linter } from '@nx/linter';
1
+ import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-directory-utils';
2
+ import type { Linter } from '@nx/linter';
3
+ import type { UnitTestRunner } from '../../utils/test-runners';
3
4
 
4
5
  export interface Schema {
5
6
  name: string;
@@ -8,6 +9,7 @@ export interface Schema {
8
9
  simpleName?: boolean;
9
10
  addModuleSpec?: boolean;
10
11
  directory?: string;
12
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
11
13
  sourceDir?: string;
12
14
  buildable?: boolean;
13
15
  publishable?: boolean;
@@ -14,13 +14,18 @@
14
14
  "index": 0
15
15
  },
16
16
  "x-prompt": "What name would you like to use for the library?",
17
- "pattern": "^[a-zA-Z].*$"
17
+ "pattern": "(?:^@[a-zA-Z0-9-*~][a-zA-Z0-9-*._~]*\\/[a-zA-Z0-9-~][a-zA-Z0-9-._~]*|^[a-zA-Z][^:]*)$"
18
18
  },
19
19
  "directory": {
20
20
  "type": "string",
21
21
  "description": "A directory where the library is placed.",
22
22
  "x-priority": "important"
23
23
  },
24
+ "projectNameAndRootFormat": {
25
+ "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
26
+ "type": "string",
27
+ "enum": ["as-provided", "derived"]
28
+ },
24
29
  "publishable": {
25
30
  "type": "boolean",
26
31
  "default": false,
@@ -57,7 +57,9 @@ function createNxJson(tree, options, defaultProject) {
57
57
  '!{projectRoot}/karma.conf.js',
58
58
  ]
59
59
  : []),
60
- targets.lint ? '!{projectRoot}/.eslintrc.json' : undefined,
60
+ ...(targets.lint
61
+ ? ['!{projectRoot}/.eslintrc.json', '!{projectRoot}/eslint.config.js']
62
+ : []),
61
63
  ].filter(Boolean),
62
64
  },
63
65
  targetDefaults: {
@@ -72,7 +74,11 @@ function createNxJson(tree, options, defaultProject) {
72
74
  : undefined,
73
75
  lint: targets.lint
74
76
  ? {
75
- inputs: ['default', '{workspaceRoot}/.eslintrc.json'],
77
+ inputs: [
78
+ 'default',
79
+ '{workspaceRoot}/.eslintrc.json',
80
+ '{workspaceRoot}/eslint.config.js',
81
+ ],
76
82
  }
77
83
  : undefined,
78
84
  e2e: targets.e2e
@@ -1,4 +1,5 @@
1
1
  import { Tree } from '@nx/devkit';
2
2
  import type { Schema } from './schema';
3
3
  export declare function remote(tree: Tree, options: Schema): Promise<import("@nx/devkit").GeneratorCallback>;
4
+ export declare function remoteInternal(tree: Tree, options: Schema): Promise<import("@nx/devkit").GeneratorCallback>;
4
5
  export default remote;
@@ -1,16 +1,22 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.remote = void 0;
3
+ exports.remoteInternal = exports.remote = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const devkit_1 = require("@nx/devkit");
6
+ const project_name_and_root_utils_1 = require("@nx/devkit/src/generators/project-name-and-root-utils");
7
+ const semver_1 = require("semver");
8
+ const test_runners_1 = require("../../utils/test-runners");
6
9
  const application_1 = require("../application/application");
7
- const project_1 = require("../utils/project");
8
10
  const setup_mf_1 = require("../setup-mf/setup-mf");
9
- const test_runners_1 = require("../../utils/test-runners");
10
- const lib_1 = require("./lib");
11
11
  const version_utils_1 = require("../utils/version-utils");
12
- const semver_1 = require("semver");
12
+ const lib_1 = require("./lib");
13
13
  function remote(tree, options) {
14
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
15
+ return yield remoteInternal(tree, Object.assign({ projectNameAndRootFormat: 'derived' }, options));
16
+ });
17
+ }
18
+ exports.remote = remote;
19
+ function remoteInternal(tree, options) {
14
20
  var _a, _b;
15
21
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
16
22
  const installedAngularVersionInfo = (0, version_utils_1.getInstalledAngularVersionInfo)(tree);
@@ -22,13 +28,19 @@ function remote(tree, options) {
22
28
  if (options.host && !projects.has(options.host)) {
23
29
  throw new Error(`The name of the application to be used as the host app does not exist. (${options.host})`);
24
30
  }
25
- const { projectDirectory } = (0, devkit_1.extractLayoutDirectory)(options.directory);
26
- const appName = (0, project_1.normalizeProjectName)(options.name, projectDirectory);
31
+ const { projectName: remoteProjectName, projectNameAndRootFormat } = yield (0, project_name_and_root_utils_1.determineProjectNameAndRootOptions)(tree, {
32
+ name: options.name,
33
+ projectType: 'application',
34
+ directory: options.directory,
35
+ projectNameAndRootFormat: options.projectNameAndRootFormat,
36
+ callingGenerator: '@nx/angular:remote',
37
+ });
38
+ options.projectNameAndRootFormat = projectNameAndRootFormat;
27
39
  const port = (_a = options.port) !== null && _a !== void 0 ? _a : (0, lib_1.findNextAvailablePort)(tree);
28
- const appInstallTask = yield (0, application_1.default)(tree, Object.assign(Object.assign({}, options), { standalone: (_b = options.standalone) !== null && _b !== void 0 ? _b : false, routing: true, port, skipFormat: true }));
40
+ const appInstallTask = yield (0, application_1.applicationGenerator)(tree, Object.assign(Object.assign({}, options), { standalone: (_b = options.standalone) !== null && _b !== void 0 ? _b : false, routing: true, port, skipFormat: true }));
29
41
  const skipE2E = !options.e2eTestRunner || options.e2eTestRunner === test_runners_1.E2eTestRunner.None;
30
42
  yield (0, setup_mf_1.setupMf)(tree, {
31
- appName,
43
+ appName: remoteProjectName,
32
44
  mfType: 'remote',
33
45
  routing: true,
34
46
  host: options.host,
@@ -36,14 +48,14 @@ function remote(tree, options) {
36
48
  skipPackageJson: options.skipPackageJson,
37
49
  skipFormat: true,
38
50
  skipE2E,
39
- e2eProjectName: skipE2E ? undefined : `${appName}-e2e`,
51
+ e2eProjectName: skipE2E ? undefined : `${remoteProjectName}-e2e`,
40
52
  standalone: options.standalone,
41
53
  prefix: options.prefix,
42
54
  });
43
55
  let installTasks = [appInstallTask];
44
56
  if (options.ssr) {
45
57
  let ssrInstallTask = yield (0, lib_1.addSsr)(tree, {
46
- appName,
58
+ appName: remoteProjectName,
47
59
  port,
48
60
  standalone: options.standalone,
49
61
  });
@@ -55,5 +67,5 @@ function remote(tree, options) {
55
67
  return (0, devkit_1.runTasksInSerial)(...installTasks);
56
68
  });
57
69
  }
58
- exports.remote = remote;
70
+ exports.remoteInternal = remoteInternal;
59
71
  exports.default = remote;
@@ -1,5 +1,6 @@
1
- import { Linter } from '@nx/linter';
2
- import { E2eTestRunner, UnitTestRunner } from '../../utils/test-runners';
1
+ import type { ProjectNameAndRootFormat } from '@nx/devkit/src/generators/project-name-and-root-utils';
2
+ import type { Linter } from '@nx/linter';
3
+ import type { E2eTestRunner, UnitTestRunner } from '../../utils/test-runners';
3
4
  import type { Styles } from '../utils/types';
4
5
 
5
6
  export interface Schema {
@@ -13,6 +14,7 @@ export interface Schema {
13
14
  style?: Styles;
14
15
  skipTests?: boolean;
15
16
  directory?: string;
17
+ projectNameAndRootFormat?: ProjectNameAndRootFormat;
16
18
  tags?: string;
17
19
  linter?: Linter;
18
20
  unitTestRunner?: UnitTestRunner;
@@ -19,7 +19,7 @@
19
19
  "$source": "argv",
20
20
  "index": 0
21
21
  },
22
- "pattern": "^[a-zA-Z].*$"
22
+ "pattern": "^[a-zA-Z][^:]*$"
23
23
  },
24
24
  "host": {
25
25
  "type": "string",
@@ -35,6 +35,11 @@
35
35
  "description": "The directory of the new application.",
36
36
  "type": "string"
37
37
  },
38
+ "projectNameAndRootFormat": {
39
+ "description": "Whether to generate the project name and root directory as provided (`as-provided`) or generate them composing their values and taking the configured layout into account (`derived`).",
40
+ "type": "string",
41
+ "enum": ["as-provided", "derived"]
42
+ },
38
43
  "style": {
39
44
  "description": "The file extension to be used for style files.",
40
45
  "type": "string",
@@ -0,0 +1,3 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ import { type Schema } from '../schema';
3
+ export declare function addHydration(tree: Tree, options: Schema): void;
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addHydration = void 0;
4
+ const devkit_1 = require("@nx/devkit");
5
+ const ast_utils_1 = require("../../../utils/nx-devkit/ast-utils");
6
+ const ensure_typescript_1 = require("@nx/js/src/utils/typescript/ensure-typescript");
7
+ const js_1 = require("@nx/js");
8
+ let tsModule;
9
+ function addHydration(tree, options) {
10
+ const projectConfig = (0, devkit_1.readProjectConfiguration)(tree, options.project);
11
+ if (!tsModule) {
12
+ tsModule = (0, ensure_typescript_1.ensureTypescript)();
13
+ }
14
+ const addImport = (source, symbolName, packageName, filePath, isDefault = false) => {
15
+ return (0, js_1.insertImport)(tree, source, filePath, symbolName, packageName, isDefault);
16
+ };
17
+ const pathToClientConfigFile = options.standalone
18
+ ? (0, devkit_1.joinPathFragments)(projectConfig.sourceRoot, 'app/app.config.ts')
19
+ : (0, devkit_1.joinPathFragments)(projectConfig.sourceRoot, 'app/app.module.ts');
20
+ const sourceText = tree.read(pathToClientConfigFile, 'utf-8');
21
+ let sourceFile = tsModule.createSourceFile(pathToClientConfigFile, sourceText, tsModule.ScriptTarget.Latest, true);
22
+ sourceFile = addImport(sourceFile, 'provideClientHydration', '@angular/platform-browser', pathToClientConfigFile);
23
+ if (options.standalone) {
24
+ (0, ast_utils_1.addProviderToAppConfig)(tree, pathToClientConfigFile, 'provideClientHydration()');
25
+ }
26
+ else {
27
+ (0, ast_utils_1.addProviderToModule)(tree, sourceFile, pathToClientConfigFile, 'provideClientHydration()');
28
+ }
29
+ }
30
+ exports.addHydration = addHydration;
@@ -3,3 +3,4 @@ export * from './normalize-options';
3
3
  export * from './update-app-module';
4
4
  export * from './update-project-config';
5
5
  export * from './validate-options';
6
+ export * from './add-hydration';
@@ -6,3 +6,4 @@ tslib_1.__exportStar(require("./normalize-options"), exports);
6
6
  tslib_1.__exportStar(require("./update-app-module"), exports);
7
7
  tslib_1.__exportStar(require("./update-project-config"), exports);
8
8
  tslib_1.__exportStar(require("./validate-options"), exports);
9
+ tslib_1.__exportStar(require("./add-hydration"), exports);
@@ -10,4 +10,5 @@ export declare function normalizeOptions(tree: Tree, options: Schema): {
10
10
  rootModuleClassName: string;
11
11
  skipFormat: boolean;
12
12
  standalone: boolean;
13
+ hydration: boolean;
13
14
  };
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeOptions = void 0;
4
4
  const ast_utils_1 = require("../../../utils/nx-devkit/ast-utils");
5
5
  function normalizeOptions(tree, options) {
6
- var _a, _b, _c, _d, _e, _f, _g, _h;
6
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
7
7
  const isStandaloneApp = (0, ast_utils_1.isNgStandaloneApp)(tree, options.project);
8
8
  return {
9
9
  project: options.project,
@@ -15,6 +15,7 @@ function normalizeOptions(tree, options) {
15
15
  rootModuleClassName: (_f = options.rootModuleClassName) !== null && _f !== void 0 ? _f : 'AppServerModule',
16
16
  skipFormat: (_g = options.skipFormat) !== null && _g !== void 0 ? _g : false,
17
17
  standalone: (_h = options.standalone) !== null && _h !== void 0 ? _h : isStandaloneApp,
18
+ hydration: (_j = options.hydration) !== null && _j !== void 0 ? _j : false,
18
19
  };
19
20
  }
20
21
  exports.normalizeOptions = normalizeOptions;
@@ -1,9 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.validateOptions = void 0;
4
+ const devkit_1 = require("@nx/devkit");
4
5
  const validations_1 = require("../../utils/validations");
6
+ const version_utils_1 = require("../../utils/version-utils");
7
+ const semver_1 = require("semver");
5
8
  function validateOptions(tree, options) {
6
9
  (0, validations_1.validateProject)(tree, options.project);
7
10
  (0, validations_1.validateStandaloneOption)(tree, options.standalone);
11
+ validateHydrationOption(tree, options.hydration);
8
12
  }
9
13
  exports.validateOptions = validateOptions;
14
+ function validateHydrationOption(tree, hydration) {
15
+ if (!hydration) {
16
+ return;
17
+ }
18
+ const installedAngularVersion = (0, version_utils_1.getInstalledAngularVersionInfo)(tree).version;
19
+ if ((0, semver_1.lt)(installedAngularVersion, '16.0.0')) {
20
+ throw new Error((0, devkit_1.stripIndents) `The "hydration" option is only supported in Angular >= 16.0.0. You are currently using "${installedAngularVersion}".
21
+ You can resolve this error by removing the "hydration" option or by migrating to Angular 16.0.0.`);
22
+ }
23
+ }
@@ -7,5 +7,6 @@ export interface Schema {
7
7
  rootModuleFileName?: string;
8
8
  rootModuleClassName?: string;
9
9
  standalone?: boolean;
10
+ hydration?: boolean;
10
11
  skipFormat?: boolean;
11
12
  }
@@ -53,6 +53,10 @@
53
53
  "type": "boolean",
54
54
  "description": "Use Standalone Components to bootstrap SSR. _Note: This is only supported in Angular versions >= 14.1.0_."
55
55
  },
56
+ "hydration": {
57
+ "type": "boolean",
58
+ "description": "Set up Hydration for the SSR application. _Note: This is only supported in Angular versions >= 16.0.0_."
59
+ },
56
60
  "skipFormat": {
57
61
  "type": "boolean",
58
62
  "description": "Skip formatting the workspace after the generator completes.",
@@ -6,6 +6,7 @@ const devkit_1 = require("@nx/devkit");
6
6
  const version_utils_1 = require("../utils/version-utils");
7
7
  const lib_1 = require("./lib");
8
8
  function setupSsr(tree, schema) {
9
+ var _a, _b, _c, _d, _e, _f;
9
10
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
11
  (0, lib_1.validateOptions)(tree, schema);
11
12
  const options = (0, lib_1.normalizeOptions)(tree, schema);
@@ -14,12 +15,15 @@ function setupSsr(tree, schema) {
14
15
  if (!options.standalone) {
15
16
  (0, lib_1.updateAppModule)(tree, options);
16
17
  }
18
+ if (options.hydration) {
19
+ (0, lib_1.addHydration)(tree, options);
20
+ }
17
21
  const pkgVersions = (0, version_utils_1.versions)(tree);
18
22
  (0, devkit_1.addDependenciesToPackageJson)(tree, {
19
- '@nguniversal/express-engine': pkgVersions.ngUniversalVersion,
20
- '@angular/platform-server': pkgVersions.angularVersion,
23
+ '@nguniversal/express-engine': (_b = (_a = (0, version_utils_1.getInstalledPackageVersionInfo)(tree, '@nguniversal/express-engine')) === null || _a === void 0 ? void 0 : _a.version) !== null && _b !== void 0 ? _b : pkgVersions.ngUniversalVersion,
24
+ '@angular/platform-server': (_d = (_c = (0, version_utils_1.getInstalledPackageVersionInfo)(tree, '@angular/platform-server')) === null || _c === void 0 ? void 0 : _c.version) !== null && _d !== void 0 ? _d : pkgVersions.angularVersion,
21
25
  }, {
22
- '@nguniversal/builders': pkgVersions.ngUniversalVersion,
26
+ '@nguniversal/builders': (_f = (_e = (0, version_utils_1.getInstalledPackageVersionInfo)(tree, '@nguniversal/builders')) === null || _e === void 0 ? void 0 : _e.version) !== null && _f !== void 0 ? _f : pkgVersions.ngUniversalVersion,
23
27
  });
24
28
  if (!options.skipFormat) {
25
29
  yield (0, devkit_1.formatFiles)(tree);
@@ -16,7 +16,7 @@ exports.backwardCompatibleVersions = {
16
16
  typesCorsVersion: '~2.8.5',
17
17
  expressVersion: '~4.18.2',
18
18
  typesExpressVersion: '4.17.14',
19
- moduleFederationNodeVersion: '^0.10.1',
19
+ moduleFederationNodeVersion: '~1.0.5',
20
20
  angularEslintVersion: '~14.0.4',
21
21
  tailwindVersion: '^3.0.2',
22
22
  postcssVersion: '^8.4.5',
@@ -43,7 +43,7 @@ exports.backwardCompatibleVersions = {
43
43
  typesCorsVersion: '~2.8.5',
44
44
  expressVersion: '~4.18.2',
45
45
  typesExpressVersion: '4.17.14',
46
- moduleFederationNodeVersion: '~0.10.1',
46
+ moduleFederationNodeVersion: '~1.0.5',
47
47
  angularEslintVersion: '~15.0.0',
48
48
  tailwindVersion: '^3.0.2',
49
49
  postcssVersion: '^8.4.5',
@@ -12,7 +12,7 @@ export declare const corsVersion = "~2.8.5";
12
12
  export declare const typesCorsVersion = "~2.8.5";
13
13
  export declare const expressVersion = "~4.18.2";
14
14
  export declare const typesExpressVersion = "4.17.14";
15
- export declare const moduleFederationNodeVersion = "~0.10.1";
15
+ export declare const moduleFederationNodeVersion = "~1.0.5";
16
16
  export declare const angularEslintVersion = "~16.0.0";
17
17
  export declare const tailwindVersion = "^3.0.2";
18
18
  export declare const postcssVersion = "^8.4.5";
@@ -15,7 +15,7 @@ exports.corsVersion = '~2.8.5';
15
15
  exports.typesCorsVersion = '~2.8.5';
16
16
  exports.expressVersion = '~4.18.2';
17
17
  exports.typesExpressVersion = '4.17.14';
18
- exports.moduleFederationNodeVersion = '~0.10.1';
18
+ exports.moduleFederationNodeVersion = '~1.0.5';
19
19
  exports.angularEslintVersion = '~16.0.0';
20
20
  exports.tailwindVersion = '^3.0.2';
21
21
  exports.postcssVersion = '^8.4.5';
@@ -1,3 +0,0 @@
1
- import type { Tree } from '@nx/devkit';
2
- import type { NormalizedSchema } from './normalized-schema';
3
- export declare function removeScaffoldedE2e(host: Tree, { name }: NormalizedSchema, e2eProjectRoot: string): void;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeScaffoldedE2e = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- function removeScaffoldedE2e(host, { name }, e2eProjectRoot) {
6
- if (host.exists(`${e2eProjectRoot}/src/app.e2e-spec.ts`)) {
7
- host.delete(`${e2eProjectRoot}/src/app.e2e-spec.ts`);
8
- }
9
- if (host.exists(`${e2eProjectRoot}/src/app.po.ts`)) {
10
- host.delete(`${e2eProjectRoot}/src/app.po.ts`);
11
- }
12
- if (host.exists(`${e2eProjectRoot}/protractor.conf.js`)) {
13
- host.delete(`${e2eProjectRoot}/protractor.conf.js`);
14
- }
15
- if (host.exists(`${e2eProjectRoot}/tsconfig.json`)) {
16
- host.delete(`${e2eProjectRoot}/tsconfig.json`);
17
- }
18
- const project = (0, devkit_1.readProjectConfiguration)(host, name);
19
- delete project.targets['e2e'];
20
- (0, devkit_1.updateProjectConfiguration)(host, name, project);
21
- }
22
- exports.removeScaffoldedE2e = removeScaffoldedE2e;
@@ -1,3 +0,0 @@
1
- import type { Tree } from '@nx/devkit';
2
- import type { NormalizedSchema } from './normalized-schema';
3
- export declare function updateE2eProject(tree: Tree, options: NormalizedSchema): void;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateE2eProject = void 0;
4
- const devkit_1 = require("@nx/devkit");
5
- const js_1 = require("@nx/js");
6
- function updateE2eProject(tree, options) {
7
- const spec = `${options.e2eProjectRoot}/src/app.e2e-spec.ts`;
8
- const content = tree.read(spec, 'utf-8');
9
- tree.write(spec, content.replace(`${options.name} app is running!`, `Welcome ${options.name}`));
10
- const page = `${options.e2eProjectRoot}/src/app.po.ts`;
11
- const pageContent = tree.read(page, 'utf-8');
12
- tree.write(page, pageContent.replace(`.content span`, `header h1`));
13
- const proj = (0, devkit_1.readProjectConfiguration)(tree, options.name);
14
- const project = {
15
- root: options.e2eProjectRoot,
16
- projectType: 'application',
17
- targets: {
18
- e2e: proj.targets.e2e,
19
- },
20
- implicitDependencies: [options.name],
21
- tags: [],
22
- };
23
- project.targets.e2e.options.protractorConfig = `${options.e2eProjectRoot}/protractor.conf.js`;
24
- (0, devkit_1.addProjectConfiguration)(tree, options.e2eProjectName, project);
25
- delete proj.targets.e2e;
26
- (0, devkit_1.updateProjectConfiguration)(tree, options.name, proj);
27
- // update tsconfig e2e
28
- if (!tree.exists(`${options.e2eProjectRoot}/tsconfig.e2e.json`)) {
29
- tree.write(`${options.e2eProjectRoot}/tsconfig.e2e.json`, '{}');
30
- }
31
- (0, devkit_1.updateJson)(tree, `${options.e2eProjectRoot}/tsconfig.e2e.json`, (json) => {
32
- return Object.assign(Object.assign({}, json), { extends: `./tsconfig.json`, compilerOptions: Object.assign(Object.assign({}, json.compilerOptions), { outDir: `${(0, devkit_1.offsetFromRoot)(options.e2eProjectRoot)}dist/out-tsc` }) });
33
- });
34
- // update tsconfig
35
- (0, devkit_1.updateJson)(tree, `${options.e2eProjectRoot}/tsconfig.json`, (json) => {
36
- return Object.assign(Object.assign({}, json), { extends: (0, js_1.getRelativePathToRootTsConfig)(tree, options.e2eProjectRoot) });
37
- });
38
- }
39
- exports.updateE2eProject = updateE2eProject;