From c63672ac22f9e121bc464ccf4b1d7e43806b2ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Mon, 23 Oct 2023 17:57:10 +0200 Subject: [PATCH] feat(angular): drop support for angular v14 (#19711) --- .../angular/executors/webpack-browser.json | 6 +- .../angular/executors/webpack-server.json | 7 - .../angular/generators/application.json | 2 +- .../angular/generators/component.json | 2 +- .../angular/generators/directive.json | 2 +- .../angular/generators/federate-module.json | 2 +- .../packages/angular/generators/host.json | 2 +- .../packages/angular/generators/library.json | 22 +- .../generators/ngrx-feature-store.json | 4 +- .../angular/generators/ngrx-root-store.json | 2 +- .../packages/angular/generators/ngrx.json | 4 +- .../packages/angular/generators/pipe.json | 2 +- .../packages/angular/generators/remote.json | 2 +- .../generators/scam-to-standalone.json | 2 +- .../packages/angular/generators/setup-mf.json | 2 +- .../angular/generators/setup-ssr.json | 2 +- .../src/builders/webpack-browser/schema.json | 6 +- .../webpack-browser/validate-options.ts | 50 -- .../webpack-browser/webpack-browser.impl.ts | 2 - .../src/builders/webpack-server/schema.d.ts | 1 - .../src/builders/webpack-server/schema.json | 12 - .../webpack-server/validate-options.ts | 11 - .../webpack-server/webpack-server.impl.ts | 11 - .../browser-esbuild/browser-esbuild.impl.ts | 2 - .../browser-esbuild/lib/validate-options.ts | 52 --- .../styles/stylesheet-processor.ts | 14 - .../styles/stylesheet-processor.ts | 14 - .../__snapshots__/add-linting.spec.ts.snap | 49 -- .../add-linting/add-linting.spec.ts | 80 ---- .../application/application.spec.ts | 20 - .../src/generators/application/application.ts | 11 - .../files/base/tsconfig.app.json__tpl__ | 2 +- .../files/base/tsconfig.json__tpl__ | 4 +- .../files/ng-module/src/main.ts__tpl__ | 10 +- .../files/tsconfig.editor.json__tpl__ | 5 - .../files/v14/.browserlistrc__tpl__ | 16 - .../environments/environment.prod.ts__tpl__ | 3 - .../src/environments/environment.ts__tpl__ | 16 - .../files/v14/src/polyfills.ts__tpl__ | 53 --- .../application/lib/create-files.ts | 9 - .../application/lib/create-project.ts | 14 +- .../src/generators/application/schema.json | 2 +- .../generators/component/component.spec.ts | 28 -- .../src/generators/component/component.ts | 2 - .../src/generators/component/lib/index.ts | 1 - .../component/lib/validate-options.ts | 7 - .../src/generators/component/schema.json | 2 +- .../src/generators/directive/directive.ts | 3 +- .../src/generators/directive/lib/index.ts | 1 - .../directive/lib/validate-options.ts | 7 - .../src/generators/directive/schema.json | 2 +- .../federate-module/lib/add-remote.ts | 20 +- .../generators/federate-module/schema.json | 2 +- .../angular/src/generators/host/host.spec.ts | 21 - packages/angular/src/generators/host/host.ts | 10 - .../angular/src/generators/host/schema.json | 2 +- .../angular/src/generators/init/init.spec.ts | 66 +-- .../__snapshots__/library.spec.ts.snap | 45 -- .../src/generators/library/library.spec.ts | 119 ----- .../angular/src/generators/library/library.ts | 9 - .../src/generators/library/schema.json | 22 +- .../__fileName__.actions.ts__tmpl__ | 0 .../__fileName__.effects.spec.ts__tmpl__ | 0 .../__fileName__.effects.ts__tmpl__ | 0 .../__fileName__.facade.spec.ts__tmpl__ | 0 .../__fileName__.facade.ts__tmpl__ | 0 .../__fileName__.models.ts__tmpl__ | 0 .../__fileName__.reducer.spec.ts__tmpl__ | 0 .../__fileName__.reducer.ts__tmpl__ | 0 .../__fileName__.selectors.spec.ts__tmpl__ | 0 .../__fileName__.selectors.ts__tmpl__ | 0 .../__fileName__.effects.ts__tmpl__ | 22 - .../__fileName__.facade.ts__tmpl__ | 27 -- .../ngrx-feature-store/lib/generate-files.ts | 19 +- .../lib/validate-options.ts | 38 -- .../generators/ngrx-feature-store/schema.json | 4 +- .../ngrx-root-store/lib/validate-options.ts | 29 -- .../generators/ngrx-root-store/schema.json | 2 +- .../ngrx/__snapshots__/ngrx.spec.ts.snap | 114 ----- .../__fileName__.actions.ts__tmpl__ | 0 .../__fileName__.effects.spec.ts__tmpl__ | 0 .../__fileName__.effects.ts__tmpl__ | 0 .../__fileName__.facade.spec.ts__tmpl__ | 0 .../__fileName__.facade.ts__tmpl__ | 0 .../__fileName__.models.ts__tmpl__ | 0 .../__fileName__.reducer.spec.ts__tmpl__ | 0 .../__fileName__.reducer.ts__tmpl__ | 0 .../__fileName__.selectors.spec.ts__tmpl__ | 0 .../__fileName__.selectors.ts__tmpl__ | 0 .../__fileName__.effects.ts__tmpl__ | 22 - .../__fileName__.facade.ts__tmpl__ | 27 -- .../src/generators/ngrx/lib/generate-files.ts | 17 +- .../generators/ngrx/lib/validate-options.ts | 38 -- .../angular/src/generators/ngrx/ngrx.spec.ts | 145 +----- .../angular/src/generators/ngrx/schema.json | 4 +- .../angular/src/generators/pipe/lib/index.ts | 1 - .../generators/pipe/lib/validate-options.ts | 7 - packages/angular/src/generators/pipe/pipe.ts | 3 +- .../angular/src/generators/pipe/schema.json | 2 +- .../src/generators/remote/remote.spec.ts | 23 - .../angular/src/generators/remote/remote.ts | 10 - .../angular/src/generators/remote/schema.json | 2 +- .../scam-to-standalone.spec.ts | 22 - .../scam-to-standalone/scam-to-standalone.ts | 16 +- .../generators/scam-to-standalone/schema.json | 2 +- .../generators/setup-mf/lib/fix-bootstrap.ts | 23 +- .../src/generators/setup-mf/schema.json | 2 +- .../src/generators/setup-mf/setup-mf.spec.ts | 71 +-- .../src/generators/setup-mf/setup-mf.ts | 9 - .../setup-ssr/files/ngmodule/v14/src/__main__ | 11 - .../setup-ssr/lib/generate-files.ts | 12 +- .../setup-ssr/lib/validate-options.ts | 6 +- .../src/generators/setup-ssr/schema.json | 2 +- .../generators/setup-ssr/setup-ssr.spec.ts | 41 +- .../setup-tailwind.application.spec.ts.snap | 41 -- .../setup-tailwind.application.spec.ts | 426 ------------------ .../setup-tailwind.library.spec.ts | 297 ------------ .../src/generators/utils/create-ts-config.ts | 5 +- .../src/generators/utils/validations.ts | 22 +- .../generators/utils/version-utils.spec.ts | 12 +- .../src/generators/utils/version-utils.ts | 2 - .../src/utils/backward-compatible-versions.ts | 30 +- .../angular/legacy-angular-versions.ts | 6 +- .../angular/standalone-workspace.ts | 2 +- 124 files changed, 142 insertions(+), 2377 deletions(-) delete mode 100644 packages/angular/src/builders/webpack-browser/validate-options.ts delete mode 100644 packages/angular/src/executors/browser-esbuild/lib/validate-options.ts delete mode 100644 packages/angular/src/generators/application/files/tsconfig.editor.json__tpl__ delete mode 100644 packages/angular/src/generators/application/files/v14/.browserlistrc__tpl__ delete mode 100644 packages/angular/src/generators/application/files/v14/src/environments/environment.prod.ts__tpl__ delete mode 100644 packages/angular/src/generators/application/files/v14/src/environments/environment.ts__tpl__ delete mode 100644 packages/angular/src/generators/application/files/v14/src/polyfills.ts__tpl__ delete mode 100644 packages/angular/src/generators/component/lib/validate-options.ts delete mode 100644 packages/angular/src/generators/directive/lib/validate-options.ts rename packages/angular/src/generators/ngrx-feature-store/files/{base => }/__directory__/__fileName__.actions.ts__tmpl__ (100%) rename packages/angular/src/generators/ngrx-feature-store/files/{base => }/__directory__/__fileName__.effects.spec.ts__tmpl__ (100%) rename packages/angular/src/generators/ngrx-feature-store/files/{base => }/__directory__/__fileName__.effects.ts__tmpl__ (100%) rename packages/angular/src/generators/ngrx-feature-store/files/{base => }/__directory__/__fileName__.facade.spec.ts__tmpl__ (100%) rename packages/angular/src/generators/ngrx-feature-store/files/{base => }/__directory__/__fileName__.facade.ts__tmpl__ (100%) rename packages/angular/src/generators/ngrx-feature-store/files/{base => }/__directory__/__fileName__.models.ts__tmpl__ (100%) rename packages/angular/src/generators/ngrx-feature-store/files/{base => }/__directory__/__fileName__.reducer.spec.ts__tmpl__ (100%) rename packages/angular/src/generators/ngrx-feature-store/files/{base => }/__directory__/__fileName__.reducer.ts__tmpl__ (100%) rename packages/angular/src/generators/ngrx-feature-store/files/{base => }/__directory__/__fileName__.selectors.spec.ts__tmpl__ (100%) rename packages/angular/src/generators/ngrx-feature-store/files/{base => }/__directory__/__fileName__.selectors.ts__tmpl__ (100%) delete mode 100644 packages/angular/src/generators/ngrx-feature-store/files/no-inject/__directory__/__fileName__.effects.ts__tmpl__ delete mode 100644 packages/angular/src/generators/ngrx-feature-store/files/no-inject/__directory__/__fileName__.facade.ts__tmpl__ rename packages/angular/src/generators/ngrx/files/{base => }/__directory__/__fileName__.actions.ts__tmpl__ (100%) rename packages/angular/src/generators/ngrx/files/{base => }/__directory__/__fileName__.effects.spec.ts__tmpl__ (100%) rename packages/angular/src/generators/ngrx/files/{base => }/__directory__/__fileName__.effects.ts__tmpl__ (100%) rename packages/angular/src/generators/ngrx/files/{base => }/__directory__/__fileName__.facade.spec.ts__tmpl__ (100%) rename packages/angular/src/generators/ngrx/files/{base => }/__directory__/__fileName__.facade.ts__tmpl__ (100%) rename packages/angular/src/generators/ngrx/files/{base => }/__directory__/__fileName__.models.ts__tmpl__ (100%) rename packages/angular/src/generators/ngrx/files/{base => }/__directory__/__fileName__.reducer.spec.ts__tmpl__ (100%) rename packages/angular/src/generators/ngrx/files/{base => }/__directory__/__fileName__.reducer.ts__tmpl__ (100%) rename packages/angular/src/generators/ngrx/files/{base => }/__directory__/__fileName__.selectors.spec.ts__tmpl__ (100%) rename packages/angular/src/generators/ngrx/files/{base => }/__directory__/__fileName__.selectors.ts__tmpl__ (100%) delete mode 100644 packages/angular/src/generators/ngrx/files/no-inject/__directory__/__fileName__.effects.ts__tmpl__ delete mode 100644 packages/angular/src/generators/ngrx/files/no-inject/__directory__/__fileName__.facade.ts__tmpl__ delete mode 100644 packages/angular/src/generators/pipe/lib/validate-options.ts delete mode 100644 packages/angular/src/generators/setup-ssr/files/ngmodule/v14/src/__main__ diff --git a/docs/generated/packages/angular/executors/webpack-browser.json b/docs/generated/packages/angular/executors/webpack-browser.json index 549d90b3b2d98..2be388cb3c49d 100644 --- a/docs/generated/packages/angular/executors/webpack-browser.json +++ b/docs/generated/packages/angular/executors/webpack-browser.json @@ -75,7 +75,7 @@ "oneOf": [ { "type": "array", - "description": "A list of polyfills to include in the build. Can be a full path for a file, relative to the current workspace or module specifier. Example: 'zone.js'. _Note: supported in Angular versions >= 15.0.0_.", + "description": "A list of polyfills to include in the build. Can be a full path for a file, relative to the current workspace or module specifier. Example: 'zone.js'.", "items": { "type": "string", "uniqueItems": true }, "default": [] }, @@ -137,7 +137,7 @@ "input": { "type": "string", "description": "The file to include.", - "pattern": "\\.(?:css|scss|sass|less|styl)$" + "pattern": "\\.(?:css|scss|sass|less)$" }, "bundleName": { "type": "string", @@ -156,7 +156,7 @@ { "type": "string", "description": "The file to include.", - "pattern": "\\.(?:css|scss|sass|less|styl)$" + "pattern": "\\.(?:css|scss|sass|less)$" } ] }, diff --git a/docs/generated/packages/angular/executors/webpack-server.json b/docs/generated/packages/angular/executors/webpack-server.json index 6dd917c2cd839..f7ac56626598a 100644 --- a/docs/generated/packages/angular/executors/webpack-server.json +++ b/docs/generated/packages/angular/executors/webpack-server.json @@ -263,13 +263,6 @@ "items": { "type": "string" }, "default": [] }, - "bundleDependencies": { - "description": "Which external dependencies to bundle into the bundle. By default, all of node_modules will be bundled. _Note: This is only supported in Angular versions >= 14.0.0, < 15.0.0. It was removed in Angular 15._", - "oneOf": [ - { "type": "boolean" }, - { "type": "string", "enum": ["none", "all"] } - ] - }, "statsJson": { "type": "boolean", "description": "Generates a 'stats.json' file which can be analyzed using tools such as 'webpack-bundle-analyzer'.", diff --git a/docs/generated/packages/angular/generators/application.json b/docs/generated/packages/angular/generators/application.json index eb14d8976050a..7fb904eb1833e 100644 --- a/docs/generated/packages/angular/generators/application.json +++ b/docs/generated/packages/angular/generators/application.json @@ -151,7 +151,7 @@ "default": false }, "standalone": { - "description": "Generate an application that is setup to use standalone components. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "Generate an application that is setup to use standalone components.", "type": "boolean", "x-priority": "important" }, diff --git a/docs/generated/packages/angular/generators/component.json b/docs/generated/packages/angular/generators/component.json index 8af01710c8708..9afec65e169f1 100644 --- a/docs/generated/packages/angular/generators/component.json +++ b/docs/generated/packages/angular/generators/component.json @@ -58,7 +58,7 @@ "alias": "t" }, "standalone": { - "description": "Whether the generated component is standalone. _Note: This is only supported in Angular versions >= 14.1.0_.", + "description": "Whether the generated component is standalone.", "type": "boolean", "default": false, "x-priority": "important" diff --git a/docs/generated/packages/angular/generators/directive.json b/docs/generated/packages/angular/generators/directive.json index d2a60d2339be1..bb8e66e2788ee 100644 --- a/docs/generated/packages/angular/generators/directive.json +++ b/docs/generated/packages/angular/generators/directive.json @@ -59,7 +59,7 @@ "description": "The HTML selector to use for this directive." }, "standalone": { - "description": "Whether the generated directive is standalone. _Note: This is only supported in Angular versions >= 14.1.0_.", + "description": "Whether the generated directive is standalone.", "type": "boolean", "default": false }, diff --git a/docs/generated/packages/angular/generators/federate-module.json b/docs/generated/packages/angular/generators/federate-module.json index 2d9e2c76f975f..e7072182f6e8d 100644 --- a/docs/generated/packages/angular/generators/federate-module.json +++ b/docs/generated/packages/angular/generators/federate-module.json @@ -67,7 +67,7 @@ "default": "cypress" }, "standalone": { - "description": "Whether to generate the remote application with standalone components if it needs to be created. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "Whether to generate the remote application with standalone components if it needs to be created.", "type": "boolean", "default": false }, diff --git a/docs/generated/packages/angular/generators/host.json b/docs/generated/packages/angular/generators/host.json index 18eef256069fe..a4362218e8d60 100644 --- a/docs/generated/packages/angular/generators/host.json +++ b/docs/generated/packages/angular/generators/host.json @@ -162,7 +162,7 @@ }, "standalone": { "type": "boolean", - "description": "Whether to generate a host application that uses standalone components. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "Whether to generate a host application that uses standalone components.", "default": false }, "ssr": { diff --git a/docs/generated/packages/angular/generators/library.json b/docs/generated/packages/angular/generators/library.json index afc77f39bd074..029e04b842570 100644 --- a/docs/generated/packages/angular/generators/library.json +++ b/docs/generated/packages/angular/generators/library.json @@ -141,65 +141,65 @@ }, "standalone": { "type": "boolean", - "description": "Generate a library that uses a standalone component instead of a module as the entry point. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "Generate a library that uses a standalone component instead of a module as the entry point.", "default": false }, "displayBlock": { - "description": "Specifies if the component generated style will contain `:host { display: block; }`. Disclaimer: This option is only valid when `--standalone` is set to `true`. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "Specifies if the component generated style will contain `:host { display: block; }`. Disclaimer: This option is only valid when `--standalone` is set to `true`.", "type": "boolean", "default": false, "alias": "b" }, "inlineStyle": { - "description": "Include styles inline in the component.ts file. Only CSS styles can be included inline. By default, an external styles file is created and referenced in the component.ts file. Disclaimer: This option is only valid when `--standalone` is set to `true`. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "Include styles inline in the component.ts file. Only CSS styles can be included inline. By default, an external styles file is created and referenced in the component.ts file. Disclaimer: This option is only valid when `--standalone` is set to `true`.", "type": "boolean", "default": false, "alias": "s" }, "inlineTemplate": { - "description": "Include template inline in the component.ts file. By default, an external template file is created and referenced in the component.ts file. Disclaimer: This option is only valid when `--standalone` is set to `true`. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "Include template inline in the component.ts file. By default, an external template file is created and referenced in the component.ts file. Disclaimer: This option is only valid when `--standalone` is set to `true`.", "type": "boolean", "default": false, "alias": "t" }, "viewEncapsulation": { - "description": "The view encapsulation strategy to use in the new component. Disclaimer: This option is only valid when `--standalone` is set to `true`. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "The view encapsulation strategy to use in the new component. Disclaimer: This option is only valid when `--standalone` is set to `true`.", "enum": ["Emulated", "None", "ShadowDom"], "type": "string", "alias": "v" }, "changeDetection": { - "description": "The change detection strategy to use in the new component. Disclaimer: This option is only valid when `--standalone` is set to `true`. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "The change detection strategy to use in the new component. Disclaimer: This option is only valid when `--standalone` is set to `true`.", "enum": ["Default", "OnPush"], "type": "string", "default": "Default", "alias": "c" }, "style": { - "description": "The file extension or preprocessor to use for style files, or `none` to skip generating the style file. Disclaimer: This option is only valid when `--standalone` is set to `true`. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "The file extension or preprocessor to use for style files, or `none` to skip generating the style file. Disclaimer: This option is only valid when `--standalone` is set to `true`.", "type": "string", "default": "css", "enum": ["css", "scss", "sass", "less", "none"] }, "skipTests": { "type": "boolean", - "description": "Do not create `spec.ts` test files for the new component. Disclaimer: This option is only valid when `--standalone` is set to `true`. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "Do not create `spec.ts` test files for the new component. Disclaimer: This option is only valid when `--standalone` is set to `true`.", "default": false }, "selector": { "type": "string", "format": "html-selector", - "description": "The HTML selector to use for this component. Disclaimer: This option is only valid when `--standalone` is set to `true`. _Note: This is only supported in Angular versions >= 14.1.0_" + "description": "The HTML selector to use for this component. Disclaimer: This option is only valid when `--standalone` is set to `true`." }, "skipSelector": { "type": "boolean", "default": false, - "description": "Specifies if the component should have a selector or not. Disclaimer: This option is only valid when `--standalone` is set to `true`. _Note: This is only supported in Angular versions >= 14.1.0_" + "description": "Specifies if the component should have a selector or not. Disclaimer: This option is only valid when `--standalone` is set to `true`." }, "flat": { "type": "boolean", "default": false, - "description": "Ensure the generated standalone component is not placed in a subdirectory. Disclaimer: This option is only valid when `--standalone` is set to `true`. _Note: This is only supported in Angular versions >= 14.1.0_" + "description": "Ensure the generated standalone component is not placed in a subdirectory. Disclaimer: This option is only valid when `--standalone` is set to `true`." } }, "additionalProperties": false, diff --git a/docs/generated/packages/angular/generators/ngrx-feature-store.json b/docs/generated/packages/angular/generators/ngrx-feature-store.json index b153f50db15d4..18fba35179939 100644 --- a/docs/generated/packages/angular/generators/ngrx-feature-store.json +++ b/docs/generated/packages/angular/generators/ngrx-feature-store.json @@ -18,13 +18,13 @@ }, "parent": { "type": "string", - "description": "The path to the file where the state will be registered. For NgModule usage, this will be your Feature Module. For Standalone API usage, this will be your Routes definition file for your feature state. The host directory will create/use the new state directory. _Note: The Standalone API usage is only supported in Angular versions >= 14.1.0_.", + "description": "The path to the file where the state will be registered. For NgModule usage, this will be your Feature Module. For Standalone API usage, this will be your Routes definition file for your feature state. The host directory will create/use the new state directory.", "x-prompt": "What is the path to the module or Routes definition where this NgRx state should be registered?", "x-priority": "important" }, "route": { "type": "string", - "description": "The route that the Standalone NgRx Providers should be added to. _Note: This is only supported in Angular versions >= 14.1.0_.", + "description": "The route that the Standalone NgRx Providers should be added to.", "default": "''" }, "minimal": { diff --git a/docs/generated/packages/angular/generators/ngrx-root-store.json b/docs/generated/packages/angular/generators/ngrx-root-store.json index d34284e9b7044..e26d2706b98da 100644 --- a/docs/generated/packages/angular/generators/ngrx-root-store.json +++ b/docs/generated/packages/angular/generators/ngrx-root-store.json @@ -29,7 +29,7 @@ }, "route": { "type": "string", - "description": "The route that the Standalone NgRx Providers should be added to. _Note: This is only supported in Angular versions >= 14.1.0_.", + "description": "The route that the Standalone NgRx Providers should be added to.", "default": "''" }, "directory": { diff --git a/docs/generated/packages/angular/generators/ngrx.json b/docs/generated/packages/angular/generators/ngrx.json index 2b34ae403bcd0..87f0aa9d86135 100644 --- a/docs/generated/packages/angular/generators/ngrx.json +++ b/docs/generated/packages/angular/generators/ngrx.json @@ -42,13 +42,13 @@ }, "parent": { "type": "string", - "description": "The path to the file where the state will be registered. For NgModule usage, this will be your `app.module.ts` for your root state, or your Feature Module for feature state. For Standalone API usage, this will be your `app.config.ts` file for your root state, or the Routes definition file for your feature state. The host directory will create/use the new state directory. _Note: The Standalone API usage is only supported in Angular versions >= 14.1.0_.", + "description": "The path to the file where the state will be registered. For NgModule usage, this will be your `app.module.ts` for your root state, or your Feature Module for feature state. For Standalone API usage, this will be your `app.config.ts` file for your root state, or the Routes definition file for your feature state. The host directory will create/use the new state directory.", "x-prompt": "What is the path to the module or Routes definition where this NgRx state should be registered?", "x-priority": "important" }, "route": { "type": "string", - "description": "The route that the Standalone NgRx Providers should be added to. _Note: This is only supported in Angular versions >= 14.1.0_.", + "description": "The route that the Standalone NgRx Providers should be added to.", "default": "''" }, "directory": { diff --git a/docs/generated/packages/angular/generators/pipe.json b/docs/generated/packages/angular/generators/pipe.json index e022ed06fc4e7..98df605abc496 100644 --- a/docs/generated/packages/angular/generators/pipe.json +++ b/docs/generated/packages/angular/generators/pipe.json @@ -51,7 +51,7 @@ "description": "Do not import this pipe into the owning NgModule." }, "standalone": { - "description": "Whether the generated pipe is standalone. _Note: This is only supported in Angular versions >= 14.1.0_.", + "description": "Whether the generated pipe is standalone.", "type": "boolean", "default": false }, diff --git a/docs/generated/packages/angular/generators/remote.json b/docs/generated/packages/angular/generators/remote.json index 457fb29289c7e..93dc09ae02caa 100644 --- a/docs/generated/packages/angular/generators/remote.json +++ b/docs/generated/packages/angular/generators/remote.json @@ -155,7 +155,7 @@ "x-priority": "internal" }, "standalone": { - "description": "Whether to generate a remote application with standalone components. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "Whether to generate a remote application with standalone components.", "type": "boolean", "default": false }, diff --git a/docs/generated/packages/angular/generators/scam-to-standalone.json b/docs/generated/packages/angular/generators/scam-to-standalone.json index 1c64ecc99a0d1..3d98861b10198 100644 --- a/docs/generated/packages/angular/generators/scam-to-standalone.json +++ b/docs/generated/packages/angular/generators/scam-to-standalone.json @@ -6,7 +6,7 @@ "$id": "GeneratorAngularScamToStandalone", "cli": "nx", "title": "Convert an Inline SCAM to Standalone Component", - "description": "Convert an Inline SCAM to a Standalone Component. _Note: This generator is only supported with Angular versions >= 14.1.0_.", + "description": "Convert an Inline SCAM to a Standalone Component.", "type": "object", "properties": { "component": { diff --git a/docs/generated/packages/angular/generators/setup-mf.json b/docs/generated/packages/angular/generators/setup-mf.json index d9c47472c1ad8..e7f5d48641043 100644 --- a/docs/generated/packages/angular/generators/setup-mf.json +++ b/docs/generated/packages/angular/generators/setup-mf.json @@ -71,7 +71,7 @@ }, "standalone": { "type": "boolean", - "description": "Whether the application is a standalone application. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "Whether the application is a standalone application.", "default": false }, "typescriptConfiguration": { diff --git a/docs/generated/packages/angular/generators/setup-ssr.json b/docs/generated/packages/angular/generators/setup-ssr.json index c5ea6836263eb..e0c29ed43ab16 100644 --- a/docs/generated/packages/angular/generators/setup-ssr.json +++ b/docs/generated/packages/angular/generators/setup-ssr.json @@ -51,7 +51,7 @@ }, "standalone": { "type": "boolean", - "description": "Use Standalone Components to bootstrap SSR. _Note: This is only supported in Angular versions >= 14.1.0_." + "description": "Use Standalone Components to bootstrap SSR." }, "hydration": { "type": "boolean", diff --git a/packages/angular/src/builders/webpack-browser/schema.json b/packages/angular/src/builders/webpack-browser/schema.json index c2fb2ed8c3359..7f8760462a5a4 100644 --- a/packages/angular/src/builders/webpack-browser/schema.json +++ b/packages/angular/src/builders/webpack-browser/schema.json @@ -41,7 +41,7 @@ "oneOf": [ { "type": "array", - "description": "A list of polyfills to include in the build. Can be a full path for a file, relative to the current workspace or module specifier. Example: 'zone.js'. _Note: supported in Angular versions >= 15.0.0_.", + "description": "A list of polyfills to include in the build. Can be a full path for a file, relative to the current workspace or module specifier. Example: 'zone.js'.", "items": { "type": "string", "uniqueItems": true @@ -106,7 +106,7 @@ "input": { "type": "string", "description": "The file to include.", - "pattern": "\\.(?:css|scss|sass|less|styl)$" + "pattern": "\\.(?:css|scss|sass|less)$" }, "bundleName": { "type": "string", @@ -125,7 +125,7 @@ { "type": "string", "description": "The file to include.", - "pattern": "\\.(?:css|scss|sass|less|styl)$" + "pattern": "\\.(?:css|scss|sass|less)$" } ] }, diff --git a/packages/angular/src/builders/webpack-browser/validate-options.ts b/packages/angular/src/builders/webpack-browser/validate-options.ts deleted file mode 100644 index 797f27b446af0..0000000000000 --- a/packages/angular/src/builders/webpack-browser/validate-options.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { stripIndents } from '@nx/devkit'; -import { extname } from 'path'; -import type { VersionInfo } from '../../executors/utilities/angular-version-utils'; -import { getInstalledAngularVersionInfo } from '../../executors/utilities/angular-version-utils'; -import type { BrowserBuilderSchema } from './schema'; - -export function validateOptions(options: BrowserBuilderSchema): void { - const angularVersionInfo = getInstalledAngularVersionInfo(); - validatePolyfills(options, angularVersionInfo); - validateStyles(options, angularVersionInfo); -} - -function validatePolyfills( - options: BrowserBuilderSchema, - { major, version }: VersionInfo -): void { - if (major < 15 && Array.isArray(options.polyfills)) { - throw new Error(stripIndents`The array syntax for the "polyfills" option is supported from Angular >= 15.0.0. You are currently using "${version}". - You can resolve this error by removing the "polyfills" option, setting it to a string value or migrating to Angular 15.0.0.`); - } -} - -function validateStyles( - options: BrowserBuilderSchema, - { major, version }: VersionInfo -): void { - if (!options.styles || !options.styles.length) { - return; - } - - if (major < 15) { - return; - } - - const stylusFiles = []; - options.styles.forEach((style) => { - const styleFile = typeof style === 'string' ? style : style.input; - if (extname(styleFile) === '.styl') { - stylusFiles.push(styleFile); - } - }); - - if (stylusFiles.length) { - throw new Error(stripIndents`Stylus is not supported since Angular v15. You're currently using "${version}". - You have the "styles" option with the following file(s) using the ".styl" extension: ${stylusFiles - .map((x) => `"${x}"`) - .join(', ')}. - Make sure to convert them to a supported extension (".css", ".scss", ".sass", ".less").`); - } -} diff --git a/packages/angular/src/builders/webpack-browser/webpack-browser.impl.ts b/packages/angular/src/builders/webpack-browser/webpack-browser.impl.ts index 8192345ab34f7..5e2dee464c0f4 100644 --- a/packages/angular/src/builders/webpack-browser/webpack-browser.impl.ts +++ b/packages/angular/src/builders/webpack-browser/webpack-browser.impl.ts @@ -18,7 +18,6 @@ import { resolveIndexHtmlTransformer, } from '../utilities/webpack'; import type { BrowserBuilderSchema } from './schema'; -import { validateOptions } from './validate-options'; function shouldSkipInitialTargetRun( projectGraph: ProjectGraph, @@ -48,7 +47,6 @@ export function executeWebpackBrowserBuilder( options: BrowserBuilderSchema, context: import('@angular-devkit/architect').BuilderContext ): Observable { - validateOptions(options); options.buildLibsFromSource ??= true; const { diff --git a/packages/angular/src/builders/webpack-server/schema.d.ts b/packages/angular/src/builders/webpack-server/schema.d.ts index cf3001486b7f6..343d77de79845 100644 --- a/packages/angular/src/builders/webpack-server/schema.d.ts +++ b/packages/angular/src/builders/webpack-server/schema.d.ts @@ -5,5 +5,4 @@ export interface Schema extends ServerBuilderOptions { path: string; }; buildLibsFromSource?: boolean; - bundleDependencies?: boolean | 'none' | 'all'; } diff --git a/packages/angular/src/builders/webpack-server/schema.json b/packages/angular/src/builders/webpack-server/schema.json index 4bb2054adb348..561b0bba1a0cc 100644 --- a/packages/angular/src/builders/webpack-server/schema.json +++ b/packages/angular/src/builders/webpack-server/schema.json @@ -209,18 +209,6 @@ }, "default": [] }, - "bundleDependencies": { - "description": "Which external dependencies to bundle into the bundle. By default, all of node_modules will be bundled. _Note: This is only supported in Angular versions >= 14.0.0, < 15.0.0. It was removed in Angular 15._", - "oneOf": [ - { - "type": "boolean" - }, - { - "type": "string", - "enum": ["none", "all"] - } - ] - }, "statsJson": { "type": "boolean", "description": "Generates a 'stats.json' file which can be analyzed using tools such as 'webpack-bundle-analyzer'.", diff --git a/packages/angular/src/builders/webpack-server/validate-options.ts b/packages/angular/src/builders/webpack-server/validate-options.ts index 778660ee3cb1b..9de47194cf709 100644 --- a/packages/angular/src/builders/webpack-server/validate-options.ts +++ b/packages/angular/src/builders/webpack-server/validate-options.ts @@ -8,7 +8,6 @@ export function validateOptions(options: Schema): void { const angularVersionInfo = getInstalledAngularVersionInfo(); validateAssets(options, angularVersionInfo); validateBuildOptimizer(options, angularVersionInfo); - validateBundleDependencies(options, angularVersionInfo); validateVendorChunk(options, angularVersionInfo); } @@ -33,16 +32,6 @@ function validateBuildOptimizer( } } -function validateBundleDependencies( - options: Schema, - { major, version }: VersionInfo -): void { - if (major >= 15 && options.bundleDependencies) { - throw new Error(stripIndents`The "bundleDependencies" option was removed in Angular version 15. You are currently using "${version}". - You can resolve this error by removing the "bundleDependencies" option.`); - } -} - function validateVendorChunk(options: Schema, { version }: VersionInfo): void { if (lt(version, '15.1.0') && options.vendorChunk) { throw new Error(stripIndents`The "vendorChunk" option is supported from Angular >= 15.1.0. You are currently using "${version}". diff --git a/packages/angular/src/builders/webpack-server/webpack-server.impl.ts b/packages/angular/src/builders/webpack-server/webpack-server.impl.ts index 273e21ecbcea4..f9cae7d5600a4 100644 --- a/packages/angular/src/builders/webpack-server/webpack-server.impl.ts +++ b/packages/angular/src/builders/webpack-server/webpack-server.impl.ts @@ -2,8 +2,6 @@ import { joinPathFragments } from '@nx/devkit'; import { existsSync } from 'fs'; import { Observable, from } from 'rxjs'; import { switchMap } from 'rxjs/operators'; -import { lt } from 'semver'; -import { getInstalledAngularVersionInfo } from '../../executors/utilities/angular-version-utils'; import { createTmpTsConfigForBuildableLibs } from '../utilities/buildable-libs'; import { mergeCustomWebpackConfig } from '../utilities/webpack'; import { Schema } from './schema'; @@ -95,15 +93,6 @@ export function executeWebpackServerBuilder( ): Observable { validateOptions(options); - const installedAngularVersionInfo = getInstalledAngularVersionInfo(); - // default bundleDependencies to true if supported by Angular version - if ( - lt(installedAngularVersionInfo.version, '15.0.0') && - options.bundleDependencies === undefined - ) { - options.bundleDependencies = true; - } - options.buildLibsFromSource ??= true; if (!options.buildLibsFromSource) { diff --git a/packages/angular/src/executors/browser-esbuild/browser-esbuild.impl.ts b/packages/angular/src/executors/browser-esbuild/browser-esbuild.impl.ts index 2694cbd230e9f..c9f9a5bae5aef 100644 --- a/packages/angular/src/executors/browser-esbuild/browser-esbuild.impl.ts +++ b/packages/angular/src/executors/browser-esbuild/browser-esbuild.impl.ts @@ -1,5 +1,4 @@ import { type EsBuildSchema } from './schema'; -import { validateOptions } from './lib/validate-options'; import { type DependentBuildableProjectNode } from '@nx/js/src/utils/buildable-libs-utils'; import { type ExecutorContext, readCachedProjectGraph } from '@nx/devkit'; import { createTmpTsConfigForBuildableLibs } from './lib/buildable-libs'; @@ -11,7 +10,6 @@ export default async function* esbuildExecutor( options: EsBuildSchema, context: ExecutorContext ) { - validateOptions(options); options.buildLibsFromSource ??= true; const { buildLibsFromSource, ...delegateExecutorOptions } = options; diff --git a/packages/angular/src/executors/browser-esbuild/lib/validate-options.ts b/packages/angular/src/executors/browser-esbuild/lib/validate-options.ts deleted file mode 100644 index f68ed5c05a986..0000000000000 --- a/packages/angular/src/executors/browser-esbuild/lib/validate-options.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { - getInstalledAngularVersionInfo, - VersionInfo, -} from '../../utilities/angular-version-utils'; -import { stripIndents } from '@nx/devkit'; -import { extname } from 'path'; -import { type EsBuildSchema } from '../schema'; - -export function validateOptions(options: EsBuildSchema): void { - const angularVersionInfo = getInstalledAngularVersionInfo(); - validatePolyfills(options, angularVersionInfo); - validateStyles(options, angularVersionInfo); -} - -function validatePolyfills( - options: EsBuildSchema, - { major, version }: VersionInfo -): void { - if (major < 15 && Array.isArray(options.polyfills)) { - throw new Error(stripIndents`The array syntax for the "polyfills" option is supported from Angular >= 15.0.0. You are currently using "${version}". - You can resolve this error by removing the "polyfills" option, setting it to a string value or migrating to Angular 15.0.0.`); - } -} - -function validateStyles( - options: EsBuildSchema, - { major, version }: VersionInfo -): void { - if (!options.styles || !options.styles.length) { - return; - } - - if (major < 15) { - return; - } - - const stylusFiles = []; - options.styles.forEach((style) => { - const styleFile = typeof style === 'string' ? style : style.input; - if (extname(styleFile) === '.styl') { - stylusFiles.push(styleFile); - } - }); - - if (stylusFiles.length) { - throw new Error(stripIndents`Stylus is not supported since Angular v15. You're currently using "${version}". - You have the "styles" option with the following file(s) using the ".styl" extension: ${stylusFiles - .map((x) => `"${x}"`) - .join(', ')}. - Make sure to convert them to a supported extension (".css", ".scss", ".sass", ".less").`); - } -} diff --git a/packages/angular/src/executors/ng-packagr-lite/ng-packagr-adjustments/styles/stylesheet-processor.ts b/packages/angular/src/executors/ng-packagr-lite/ng-packagr-adjustments/styles/stylesheet-processor.ts index 42bfa872b8b29..69923851ebd41 100644 --- a/packages/angular/src/executors/ng-packagr-lite/ng-packagr-adjustments/styles/stylesheet-processor.ts +++ b/packages/angular/src/executors/ng-packagr-lite/ng-packagr-adjustments/styles/stylesheet-processor.ts @@ -21,7 +21,6 @@ import { dirname, extname, join } from 'path'; import * as postcssPresetEnv from 'postcss-preset-env'; import * as postcssUrl from 'postcss-url'; import { pathToFileURL } from 'node:url'; -import { getInstalledAngularVersionInfo } from '../../../utilities/angular-version-utils'; import { getTailwindPostCssPlugins, getTailwindSetup, @@ -251,19 +250,6 @@ export class StylesheetProcessor { switch (ext) { case '.sass': case '.scss': { - const angularVersion = getInstalledAngularVersionInfo(); - if (angularVersion && angularVersion.major < 15) { - return (await import('sass')) - .renderSync({ - file: filePath, - data: css, - indentedSyntax: '.sass' === ext, - importer: customSassImporter, - includePaths: this.styleIncludePaths, - }) - .css.toString(); - } - return (await import('sass')) .compileString(css, { url: pathToFileURL(filePath), diff --git a/packages/angular/src/executors/package/ng-packagr-adjustments/styles/stylesheet-processor.ts b/packages/angular/src/executors/package/ng-packagr-adjustments/styles/stylesheet-processor.ts index 2cb05da94c423..e3a10b87e7d7b 100644 --- a/packages/angular/src/executors/package/ng-packagr-adjustments/styles/stylesheet-processor.ts +++ b/packages/angular/src/executors/package/ng-packagr-adjustments/styles/stylesheet-processor.ts @@ -21,7 +21,6 @@ import { dirname, extname, join } from 'path'; import * as postcssPresetEnv from 'postcss-preset-env'; import * as postcssUrl from 'postcss-url'; import { pathToFileURL } from 'node:url'; -import { getInstalledAngularVersionInfo } from '../../../utilities/angular-version-utils'; import { getTailwindPostCssPlugins, getTailwindSetup, @@ -244,19 +243,6 @@ export class StylesheetProcessor { switch (ext) { case '.sass': case '.scss': { - const angularVersion = getInstalledAngularVersionInfo(); - if (angularVersion && angularVersion.major < 15) { - return (await import('sass')) - .renderSync({ - file: filePath, - data: css, - indentedSyntax: '.sass' === ext, - importer: customSassImporter, - includePaths: this.styleIncludePaths, - }) - .css.toString(); - } - return (await import('sass')) .compileString(css, { url: pathToFileURL(filePath), diff --git a/packages/angular/src/generators/add-linting/__snapshots__/add-linting.spec.ts.snap b/packages/angular/src/generators/add-linting/__snapshots__/add-linting.spec.ts.snap index 4a116b4918647..deedf6d74c44f 100644 --- a/packages/angular/src/generators/add-linting/__snapshots__/add-linting.spec.ts.snap +++ b/packages/angular/src/generators/add-linting/__snapshots__/add-linting.spec.ts.snap @@ -48,52 +48,3 @@ exports[`addLinting generator should correctly generate the .eslintrc.json file ], } `; - -exports[`addLinting generator support angular v14 should correctly generate the .eslintrc.json file 1`] = ` -{ - "extends": [ - "../../.eslintrc.json", - ], - "ignorePatterns": [ - "!**/*", - ], - "overrides": [ - { - "extends": [ - "plugin:@nx/angular", - "plugin:@angular-eslint/template/process-inline-templates", - ], - "files": [ - "*.ts", - ], - "rules": { - "@angular-eslint/component-selector": [ - "error", - { - "prefix": "my-org", - "style": "kebab-case", - "type": "element", - }, - ], - "@angular-eslint/directive-selector": [ - "error", - { - "prefix": "myOrg", - "style": "camelCase", - "type": "attribute", - }, - ], - }, - }, - { - "extends": [ - "plugin:@nx/angular-template", - ], - "files": [ - "*.html", - ], - "rules": {}, - }, - ], -} -`; diff --git a/packages/angular/src/generators/add-linting/add-linting.spec.ts b/packages/angular/src/generators/add-linting/add-linting.spec.ts index f298773d34dad..459e64c6000c0 100644 --- a/packages/angular/src/generators/add-linting/add-linting.spec.ts +++ b/packages/angular/src/generators/add-linting/add-linting.spec.ts @@ -3,7 +3,6 @@ import { addProjectConfiguration, readJson, readProjectConfiguration, - updateJson, } from '@nx/devkit'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import * as linter from '@nx/eslint'; @@ -82,83 +81,4 @@ describe('addLinting generator', () => { outputs: ['{options.outputFile}'], }); }); - - describe('support angular v14', () => { - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - updateJson(tree, 'package.json', (json) => ({ - ...json, - dependencies: { - ...json.dependencies, - '@angular/core': '14.1.0', - }, - })); - - addProjectConfiguration(tree, appProjectName, { - root: appProjectRoot, - prefix: 'myOrg', - projectType: 'application', - targets: {}, - } as ProjectConfiguration); - }); - - it('should invoke the lintProjectGenerator', async () => { - jest.spyOn(linter, 'lintProjectGenerator'); - - await addLintingGenerator(tree, { - prefix: 'myOrg', - projectName: appProjectName, - projectRoot: appProjectRoot, - }); - - expect(linter.lintProjectGenerator).toHaveBeenCalled(); - }); - - it('should add the Angular specific EsLint devDependencies', async () => { - await addLintingGenerator(tree, { - prefix: 'myOrg', - projectName: appProjectName, - projectRoot: appProjectRoot, - }); - - const { dependencies, devDependencies } = readJson(tree, 'package.json'); - expect(dependencies['@angular/core']).toEqual('14.1.0'); - expect(devDependencies['@angular-eslint/eslint-plugin']).toBeDefined(); - expect( - devDependencies['@angular-eslint/eslint-plugin-template'] - ).toBeDefined(); - expect(devDependencies['@angular-eslint/template-parser']).toBeDefined(); - }); - - it('should correctly generate the .eslintrc.json file', async () => { - await addLintingGenerator(tree, { - prefix: 'myOrg', - projectName: appProjectName, - projectRoot: appProjectRoot, - }); - - const eslintConfig = readJson(tree, `${appProjectRoot}/.eslintrc.json`); - expect(eslintConfig).toMatchSnapshot(); - }); - - it('should update the project with the right lint target configuration', async () => { - await addLintingGenerator(tree, { - prefix: 'myOrg', - projectName: appProjectName, - projectRoot: appProjectRoot, - }); - - const project = readProjectConfiguration(tree, appProjectName); - expect(project.targets.lint).toEqual({ - executor: '@nx/eslint:lint', - options: { - lintFilePatterns: [ - `${appProjectRoot}/**/*.ts`, - `${appProjectRoot}/**/*.html`, - ], - }, - outputs: ['{options.outputFile}'], - }); - }); - }); }); diff --git a/packages/angular/src/generators/application/application.spec.ts b/packages/angular/src/generators/application/application.spec.ts index 7c4650e0dd2db..06c290d701ae6 100644 --- a/packages/angular/src/generators/application/application.spec.ts +++ b/packages/angular/src/generators/application/application.spec.ts @@ -877,26 +877,6 @@ describe('app', () => { }); }); - it('should error correctly when Angular version does not support standalone', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - updateJson(tree, 'package.json', (json) => ({ - ...json, - dependencies: { - '@angular/core': '14.0.0', - }, - })); - - // ACT & ASSERT - await expect( - generateApp(tree, 'my-app', { - standalone: true, - }) - ).rejects - .toThrow(stripIndents`The "standalone" option is only supported in Angular >= 14.1.0. You are currently using 14.0.0. - You can resolve this error by removing the "standalone" option or by migrating to Angular 14.1.0.`); - }); - describe('--minimal', () => { it('should skip "nx-welcome.component.ts" file and references for non-standalone apps without routing', async () => { await generateApp(appTree, 'plain', { minimal: true, routing: false }); diff --git a/packages/angular/src/generators/application/application.ts b/packages/angular/src/generators/application/application.ts index 049bbaba11966..beae6be5122e0 100644 --- a/packages/angular/src/generators/application/application.ts +++ b/packages/angular/src/generators/application/application.ts @@ -4,13 +4,11 @@ import { installPackagesTask, offsetFromRoot, readNxJson, - stripIndents, Tree, updateNxJson, } from '@nx/devkit'; import { angularInitGenerator } from '../init/init'; import { setupTailwindGenerator } from '../setup-tailwind/setup-tailwind'; -import { getInstalledAngularVersionInfo } from '../utils/version-utils'; import { addE2e, addLinting, @@ -24,7 +22,6 @@ import { updateEditorTsConfig, } from './lib'; import type { Schema } from './schema'; -import { gte, lt } from 'semver'; import { prompt } from 'enquirer'; export async function applicationGenerator( @@ -41,15 +38,7 @@ export async function applicationGeneratorInternal( tree: Tree, schema: Partial ): Promise { - const installedAngularVersionInfo = getInstalledAngularVersionInfo(tree); - - if (lt(installedAngularVersionInfo.version, '14.1.0') && schema.standalone) { - throw new Error(stripIndents`The "standalone" option is only supported in Angular >= 14.1.0. You are currently using ${installedAngularVersionInfo.version}. - You can resolve this error by removing the "standalone" option or by migrating to Angular 14.1.0.`); - } - if ( - gte(installedAngularVersionInfo.version, '14.1.0') && schema.standalone === undefined && process.env.NX_INTERACTIVE === 'true' ) { diff --git a/packages/angular/src/generators/application/files/base/tsconfig.app.json__tpl__ b/packages/angular/src/generators/application/files/base/tsconfig.app.json__tpl__ index 2d91132ac88c2..61dcf0ec390a8 100644 --- a/packages/angular/src/generators/application/files/base/tsconfig.app.json__tpl__ +++ b/packages/angular/src/generators/application/files/base/tsconfig.app.json__tpl__ @@ -4,7 +4,7 @@ "outDir": "<%= rootOffset %>dist/out-tsc", "types": [] }, - "files": ["src/main.ts"<% if(installedAngularInfo.major === 14) { %>, "src/polyfills.ts"<% } %>], + "files": ["src/main.ts"], "include": ["src/**/*.d.ts"], "exclude": ["jest.config.ts", "src/**/*.test.ts", "src/**/*.spec.ts"] } diff --git a/packages/angular/src/generators/application/files/base/tsconfig.json__tpl__ b/packages/angular/src/generators/application/files/base/tsconfig.json__tpl__ index 574499b52ee13..048f5849a98f0 100644 --- a/packages/angular/src/generators/application/files/base/tsconfig.json__tpl__ +++ b/packages/angular/src/generators/application/files/base/tsconfig.json__tpl__ @@ -1,7 +1,7 @@ { "compilerOptions": { - "target": <% if(installedAngularInfo.major === 14) { %>"es2020"<% } else { %>"es2022"<% } %><% if(installedAngularInfo.major === 15) { %>, - "useDefineForClassFields": false<% } %> + "target": "es2022", + "useDefineForClassFields": false }, "files": [], "include": [], diff --git a/packages/angular/src/generators/application/files/ng-module/src/main.ts__tpl__ b/packages/angular/src/generators/application/files/ng-module/src/main.ts__tpl__ index 8640123932894..16de2365d275e 100644 --- a/packages/angular/src/generators/application/files/ng-module/src/main.ts__tpl__ +++ b/packages/angular/src/generators/application/files/ng-module/src/main.ts__tpl__ @@ -1,11 +1,5 @@ -import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';<% if(installedAngularInfo.major === 14) { %> -import { enableProdMode } from '@angular/core';<% } %> -import { AppModule } from './app/app.module';<% if(installedAngularInfo.major === 14) { %> -import { environment } from './environments/environment'; - -if(environment.production) { - enableProdMode(); -}<% } %> +import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; +import { AppModule } from './app/app.module'; platformBrowserDynamic() .bootstrapModule(AppModule) diff --git a/packages/angular/src/generators/application/files/tsconfig.editor.json__tpl__ b/packages/angular/src/generators/application/files/tsconfig.editor.json__tpl__ deleted file mode 100644 index 57caccc2ab346..0000000000000 --- a/packages/angular/src/generators/application/files/tsconfig.editor.json__tpl__ +++ /dev/null @@ -1,5 +0,0 @@ -{ - "extends": "./tsconfig.json", - "include": ["src/**/*.ts"], - "compilerOptions": {} -} diff --git a/packages/angular/src/generators/application/files/v14/.browserlistrc__tpl__ b/packages/angular/src/generators/application/files/v14/.browserlistrc__tpl__ deleted file mode 100644 index 4f9ac26980c15..0000000000000 --- a/packages/angular/src/generators/application/files/v14/.browserlistrc__tpl__ +++ /dev/null @@ -1,16 +0,0 @@ -# This file is used by the build system to adjust CSS and JS output to support the specified browsers below. -# For additional information regarding the format and rule options, please see: -# https://github.com/browserslist/browserslist#queries - -# For the full list of supported browsers by the Angular framework, please see: -# https://angular.io/guide/browser-support - -# You can see what browsers were selected by your queries by running: -# npx browserslist - -last 1 Chrome version -last 1 Firefox version -last 2 Edge major versions -last 2 Safari major versions -last 2 iOS major versions -Firefox ESR diff --git a/packages/angular/src/generators/application/files/v14/src/environments/environment.prod.ts__tpl__ b/packages/angular/src/generators/application/files/v14/src/environments/environment.prod.ts__tpl__ deleted file mode 100644 index 3612073bc31cd..0000000000000 --- a/packages/angular/src/generators/application/files/v14/src/environments/environment.prod.ts__tpl__ +++ /dev/null @@ -1,3 +0,0 @@ -export const environment = { - production: true -}; diff --git a/packages/angular/src/generators/application/files/v14/src/environments/environment.ts__tpl__ b/packages/angular/src/generators/application/files/v14/src/environments/environment.ts__tpl__ deleted file mode 100644 index 8c29253accfd8..0000000000000 --- a/packages/angular/src/generators/application/files/v14/src/environments/environment.ts__tpl__ +++ /dev/null @@ -1,16 +0,0 @@ -// This file can be replaced during build by using the `fileReplacements` array. -// `ng build` replaces `environment.ts` with `environment.prod.ts`. -// The list of file replacements can be found in `angular.json`. - -export const environment = { - production: false -}; - -/* - * For easier debugging in development mode, you can import the following file - * to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`. - * - * This import should be commented out in production mode because it will have a negative impact - * on performance if an error is thrown. - */ -// import 'zone.js/plugins/zone-error'; diff --git a/packages/angular/src/generators/application/files/v14/src/polyfills.ts__tpl__ b/packages/angular/src/generators/application/files/v14/src/polyfills.ts__tpl__ deleted file mode 100644 index 429bb9ef2d340..0000000000000 --- a/packages/angular/src/generators/application/files/v14/src/polyfills.ts__tpl__ +++ /dev/null @@ -1,53 +0,0 @@ -/** - * This file includes polyfills needed by Angular and is loaded before the app. - * You can add your own extra polyfills to this file. - * - * This file is divided into 2 sections: - * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. - * 2. Application imports. Files imported after ZoneJS that should be loaded before your main - * file. - * - * The current setup is for so-called "evergreen" browsers; the last versions of browsers that - * automatically update themselves. This includes recent versions of Safari, Chrome (including - * Opera), Edge on the desktop, and iOS and Chrome on mobile. - * - * Learn more in https://angular.io/guide/browser-support - */ - -/*************************************************************************************************** - * BROWSER POLYFILLS - */ - -/** - * By default, zone.js will patch all possible macroTask and DomEvents - * user can disable parts of macroTask/DomEvents patch by setting following flags - * because those flags need to be set before `zone.js` being loaded, and webpack - * will put import in the top of bundle, so user need to create a separate file - * in this directory (for example: zone-flags.ts), and put the following flags - * into that file, and then add the following code before importing zone.js. - * import './zone-flags'; - * - * The flags allowed in zone-flags.ts are listed here. - * - * The following flags will work for all browsers. - * - * (window as any).__Zone_disable_requestAnimationFrame = true; // disable patch requestAnimationFrame - * (window as any).__Zone_disable_on_property = true; // disable patch onProperty such as onclick - * (window as any).__zone_symbol__UNPATCHED_EVENTS = ['scroll', 'mousemove']; // disable patch specified eventNames - * - * in IE/Edge developer tools, the addEventListener will also be wrapped by zone.js - * with the following flag, it will bypass `zone.js` patch for IE/Edge - * - * (window as any).__Zone_enable_cross_context_check = true; - * - */ - -/*************************************************************************************************** - * Zone JS is required by default for Angular itself. - */ -import 'zone.js'; // Included with Angular CLI. - - -/*************************************************************************************************** - * APPLICATION IMPORTS - */ diff --git a/packages/angular/src/generators/application/lib/create-files.ts b/packages/angular/src/generators/application/lib/create-files.ts index 88c4601dadc01..d0910cc6070f5 100644 --- a/packages/angular/src/generators/application/lib/create-files.ts +++ b/packages/angular/src/generators/application/lib/create-files.ts @@ -36,15 +36,6 @@ export async function createFiles( substitutions ); - if (installedAngularInfo.major === 14) { - generateFiles( - tree, - joinPathFragments(__dirname, '../files/v14'), - options.appProjectRoot, - substitutions - ); - } - if (options.standalone) { generateFiles( tree, diff --git a/packages/angular/src/generators/application/lib/create-project.ts b/packages/angular/src/generators/application/lib/create-project.ts index 76f29504fb4a8..3743d3079a382 100644 --- a/packages/angular/src/generators/application/lib/create-project.ts +++ b/packages/angular/src/generators/application/lib/create-project.ts @@ -27,10 +27,7 @@ export function createProject(tree: Tree, options: NormalizedSchema) { }`, index: `${options.appProjectRoot}/src/index.html`, main: `${options.appProjectRoot}/src/main.ts`, - polyfills: - installedAngularInfo.major === 14 - ? `${options.appProjectRoot}/src/polyfills.ts` - : ['zone.js'], + polyfills: ['zone.js'], tsConfig: `${options.appProjectRoot}/tsconfig.app.json`, assets: [ `${options.appProjectRoot}/src/favicon.ico`, @@ -56,15 +53,6 @@ export function createProject(tree: Tree, options: NormalizedSchema) { }, ] : undefined, - fileReplacements: - installedAngularInfo.major === 14 - ? [ - { - replace: `${options.appProjectRoot}/src/environments/environment.ts`, - with: `${options.appProjectRoot}/src/environments/environment.prod.ts`, - }, - ] - : undefined, outputHashing: 'all', }, development: { diff --git a/packages/angular/src/generators/application/schema.json b/packages/angular/src/generators/application/schema.json index 5e8735dcbdcd2..806d7048ba488 100644 --- a/packages/angular/src/generators/application/schema.json +++ b/packages/angular/src/generators/application/schema.json @@ -154,7 +154,7 @@ "default": false }, "standalone": { - "description": "Generate an application that is setup to use standalone components. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "Generate an application that is setup to use standalone components.", "type": "boolean", "x-priority": "important" }, diff --git a/packages/angular/src/generators/component/component.spec.ts b/packages/angular/src/generators/component/component.spec.ts index c425e77f72035..2bfdf50e0e804 100644 --- a/packages/angular/src/generators/component/component.spec.ts +++ b/packages/angular/src/generators/component/component.spec.ts @@ -971,32 +971,4 @@ describe('component Generator', () => { expect(indexSource).toBe(''); }); }); - - it('should error correctly when Angular version does not support standalone', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - updateJson(tree, 'package.json', (json) => ({ - ...json, - dependencies: { - '@angular/core': '14.0.0', - }, - })); - - addProjectConfiguration(tree, 'lib1', { - projectType: 'library', - sourceRoot: 'libs/lib1/src', - root: 'libs/lib1', - }); - - // ACT & ASSERT - await expect( - componentGenerator(tree, { - name: 'example', - project: 'lib1', - standalone: true, - }) - ).rejects - .toThrow(stripIndents`The "standalone" option is only supported in Angular >= 14.1.0. You are currently using "14.0.0". - You can resolve this error by removing the "standalone" option or by migrating to Angular 14.1.0.`); - }); }); diff --git a/packages/angular/src/generators/component/component.ts b/packages/angular/src/generators/component/component.ts index 5f9c3a383561c..a6ff38ce1ba0e 100644 --- a/packages/angular/src/generators/component/component.ts +++ b/packages/angular/src/generators/component/component.ts @@ -10,7 +10,6 @@ import { exportComponentInEntryPoint, findModuleFromOptions, normalizeOptions, - validateOptions, } from './lib'; import type { Schema } from './schema'; @@ -25,7 +24,6 @@ export async function componentGeneratorInternal( tree: Tree, rawOptions: Schema ) { - validateOptions(tree, rawOptions); const options = await normalizeOptions(tree, rawOptions); generateFiles( diff --git a/packages/angular/src/generators/component/lib/index.ts b/packages/angular/src/generators/component/lib/index.ts index 46e96e2292c93..33dc5c4e3a267 100644 --- a/packages/angular/src/generators/component/lib/index.ts +++ b/packages/angular/src/generators/component/lib/index.ts @@ -1,4 +1,3 @@ export * from './component'; export * from './module'; export * from './normalize-options'; -export * from './validate-options'; diff --git a/packages/angular/src/generators/component/lib/validate-options.ts b/packages/angular/src/generators/component/lib/validate-options.ts deleted file mode 100644 index d51a443cd84fb..0000000000000 --- a/packages/angular/src/generators/component/lib/validate-options.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { Tree } from '@nx/devkit'; -import { validateStandaloneOption } from '../../utils/validations'; -import type { Schema } from '../schema'; - -export function validateOptions(tree: Tree, options: Schema): void { - validateStandaloneOption(tree, options.standalone); -} diff --git a/packages/angular/src/generators/component/schema.json b/packages/angular/src/generators/component/schema.json index d66db2fcdc5d4..adc4795c15818 100644 --- a/packages/angular/src/generators/component/schema.json +++ b/packages/angular/src/generators/component/schema.json @@ -60,7 +60,7 @@ "alias": "t" }, "standalone": { - "description": "Whether the generated component is standalone. _Note: This is only supported in Angular versions >= 14.1.0_.", + "description": "Whether the generated component is standalone.", "type": "boolean", "default": false, "x-priority": "important" diff --git a/packages/angular/src/generators/directive/directive.ts b/packages/angular/src/generators/directive/directive.ts index f26419c308824..dfc3625a0cdbf 100644 --- a/packages/angular/src/generators/directive/directive.ts +++ b/packages/angular/src/generators/directive/directive.ts @@ -6,11 +6,10 @@ import { names, } from '@nx/devkit'; import { addToNgModule, findModule } from '../utils'; -import { normalizeOptions, validateOptions } from './lib'; +import { normalizeOptions } from './lib'; import type { Schema } from './schema'; export async function directiveGenerator(tree: Tree, schema: Schema) { - validateOptions(tree, schema); const options = await normalizeOptions(tree, schema); generateFiles( diff --git a/packages/angular/src/generators/directive/lib/index.ts b/packages/angular/src/generators/directive/lib/index.ts index da94c6f89ca24..f9451963f55a2 100644 --- a/packages/angular/src/generators/directive/lib/index.ts +++ b/packages/angular/src/generators/directive/lib/index.ts @@ -1,2 +1 @@ export * from './normalize-options'; -export * from './validate-options'; diff --git a/packages/angular/src/generators/directive/lib/validate-options.ts b/packages/angular/src/generators/directive/lib/validate-options.ts deleted file mode 100644 index d51a443cd84fb..0000000000000 --- a/packages/angular/src/generators/directive/lib/validate-options.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { Tree } from '@nx/devkit'; -import { validateStandaloneOption } from '../../utils/validations'; -import type { Schema } from '../schema'; - -export function validateOptions(tree: Tree, options: Schema): void { - validateStandaloneOption(tree, options.standalone); -} diff --git a/packages/angular/src/generators/directive/schema.json b/packages/angular/src/generators/directive/schema.json index 9ac21fb8dcca7..4c72bcb6fccec 100644 --- a/packages/angular/src/generators/directive/schema.json +++ b/packages/angular/src/generators/directive/schema.json @@ -66,7 +66,7 @@ "description": "The HTML selector to use for this directive." }, "standalone": { - "description": "Whether the generated directive is standalone. _Note: This is only supported in Angular versions >= 14.1.0_.", + "description": "Whether the generated directive is standalone.", "type": "boolean", "default": false }, diff --git a/packages/angular/src/generators/federate-module/lib/add-remote.ts b/packages/angular/src/generators/federate-module/lib/add-remote.ts index 13c061fa72cb5..7132a1ec222fa 100644 --- a/packages/angular/src/generators/federate-module/lib/add-remote.ts +++ b/packages/angular/src/generators/federate-module/lib/add-remote.ts @@ -1,11 +1,9 @@ -import { GeneratorCallback, stripIndents, type Tree } from '@nx/devkit'; +import type { GeneratorCallback, Tree } from '@nx/devkit'; import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; -import { lt } from 'semver'; -import { getRemoteIfExists } from './check-remote-exists'; -import { getInstalledAngularVersionInfo } from '../../utils/version-utils'; -import { type Schema } from '../schema'; -import remoteGenerator from '../../remote/remote'; import { E2eTestRunner, UnitTestRunner } from '../../../utils/test-runners'; +import remoteGenerator from '../../remote/remote'; +import { type Schema } from '../schema'; +import { getRemoteIfExists } from './check-remote-exists'; export async function addRemote(tree: Tree, schema: Schema) { const tasks: GeneratorCallback[] = []; @@ -14,16 +12,6 @@ export async function addRemote(tree: Tree, schema: Schema) { let projectRoot, remoteName; if (!remote) { - const installedAngularVersionInfo = getInstalledAngularVersionInfo(tree); - - if ( - lt(installedAngularVersionInfo.version, '14.1.0') && - schema.standalone - ) { - throw new Error(stripIndents`The "standalone" option is only supported in Angular >= 14.1.0. You are currently using ${installedAngularVersionInfo.version}. - You can resolve this error by removing the "standalone" option or by migrating to Angular 14.1.0.`); - } - const remoteGeneratorCallback = await remoteGenerator(tree, { name: schema.remote, directory: schema.remoteDirectory, diff --git a/packages/angular/src/generators/federate-module/schema.json b/packages/angular/src/generators/federate-module/schema.json index d586d263da808..eeb59ca285319 100644 --- a/packages/angular/src/generators/federate-module/schema.json +++ b/packages/angular/src/generators/federate-module/schema.json @@ -67,7 +67,7 @@ "default": "cypress" }, "standalone": { - "description": "Whether to generate the remote application with standalone components if it needs to be created. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "Whether to generate the remote application with standalone components if it needs to be created.", "type": "boolean", "default": false }, diff --git a/packages/angular/src/generators/host/host.spec.ts b/packages/angular/src/generators/host/host.spec.ts index c6dc2b6fe65b5..2b2e04f0f1e03 100644 --- a/packages/angular/src/generators/host/host.spec.ts +++ b/packages/angular/src/generators/host/host.spec.ts @@ -460,27 +460,6 @@ describe('Host App Generator', () => { }); }); - it('should error correctly when Angular version does not support standalone', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - updateJson(tree, 'package.json', (json) => ({ - ...json, - dependencies: { - '@angular/core': '14.0.0', - }, - })); - - // ACT & ASSERT - await expect( - generateTestHostApplication(tree, { - name: 'test', - standalone: true, - }) - ).rejects - .toThrow(stripIndents`The "standalone" option is only supported in Angular >= 14.1.0. You are currently using 14.0.0. - You can resolve this error by removing the "standalone" option or by migrating to Angular 14.1.0.`); - }); - describe('--project-name-and-root-format=derived', () => { it('should generate a host, integrate existing remotes and generate any remotes that dont exist', async () => { // ARRANGE diff --git a/packages/angular/src/generators/host/host.ts b/packages/angular/src/generators/host/host.ts index 7cff6f5780c9a..83a8e478795fa 100644 --- a/packages/angular/src/generators/host/host.ts +++ b/packages/angular/src/generators/host/host.ts @@ -3,16 +3,13 @@ import { getProjects, joinPathFragments, runTasksInSerial, - stripIndents, Tree, } from '@nx/devkit'; import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; -import { lt } from 'semver'; import { E2eTestRunner } from '../../utils/test-runners'; import applicationGenerator from '../application/application'; import remoteGenerator from '../remote/remote'; import { setupMf } from '../setup-mf/setup-mf'; -import { getInstalledAngularVersionInfo } from '../utils/version-utils'; import { addSsr } from './lib'; import type { Schema } from './schema'; @@ -24,13 +21,6 @@ export async function host(tree: Tree, options: Schema) { } export async function hostInternal(tree: Tree, schema: Schema) { - const installedAngularVersionInfo = getInstalledAngularVersionInfo(tree); - - if (lt(installedAngularVersionInfo.version, '14.1.0') && schema.standalone) { - throw new Error(stripIndents`The "standalone" option is only supported in Angular >= 14.1.0. You are currently using ${installedAngularVersionInfo.version}. - You can resolve this error by removing the "standalone" option or by migrating to Angular 14.1.0.`); - } - const { typescriptConfiguration = true, ...options }: Schema = schema; const projects = getProjects(tree); diff --git a/packages/angular/src/generators/host/schema.json b/packages/angular/src/generators/host/schema.json index 890a298c2992a..18bfbe4f9a5f1 100644 --- a/packages/angular/src/generators/host/schema.json +++ b/packages/angular/src/generators/host/schema.json @@ -165,7 +165,7 @@ }, "standalone": { "type": "boolean", - "description": "Whether to generate a host application that uses standalone components. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "Whether to generate a host application that uses standalone components.", "default": false }, "ssr": { diff --git a/packages/angular/src/generators/init/init.spec.ts b/packages/angular/src/generators/init/init.spec.ts index 47babcef7a8a4..5082444b1a30f 100644 --- a/packages/angular/src/generators/init/init.spec.ts +++ b/packages/angular/src/generators/init/init.spec.ts @@ -375,7 +375,7 @@ bar }); }); - describe('v14 support', () => { + describe('v15 support', () => { let tree: Tree; beforeEach(() => { tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); @@ -383,7 +383,7 @@ bar ...json, dependencies: { ...json.dependencies, - '@angular/core': '~14.2.0', + '@angular/core': '~15.2.0', }, })); }); @@ -400,43 +400,43 @@ bar const { dependencies, devDependencies } = readJson(tree, 'package.json'); expect(dependencies['@angular/animations']).toEqual( - backwardCompatibleVersions.angularV14.angularVersion + backwardCompatibleVersions.angularV15.angularVersion ); expect(dependencies['@angular/common']).toEqual( - backwardCompatibleVersions.angularV14.angularVersion + backwardCompatibleVersions.angularV15.angularVersion ); expect(dependencies['@angular/compiler']).toEqual( - backwardCompatibleVersions.angularV14.angularVersion + backwardCompatibleVersions.angularV15.angularVersion ); expect(dependencies['@angular/core']).toEqual( - backwardCompatibleVersions.angularV14.angularVersion + backwardCompatibleVersions.angularV15.angularVersion ); expect(dependencies['@angular/platform-browser']).toEqual( - backwardCompatibleVersions.angularV14.angularVersion + backwardCompatibleVersions.angularV15.angularVersion ); expect(dependencies['@angular/platform-browser-dynamic']).toEqual( - backwardCompatibleVersions.angularV14.angularVersion + backwardCompatibleVersions.angularV15.angularVersion ); expect(dependencies['@angular/router']).toEqual( - backwardCompatibleVersions.angularV14.angularVersion + backwardCompatibleVersions.angularV15.angularVersion ); expect(dependencies['rxjs']).toEqual( - backwardCompatibleVersions.angularV14.rxjsVersion + backwardCompatibleVersions.angularV15.rxjsVersion ); expect(dependencies['zone.js']).toEqual( - backwardCompatibleVersions.angularV14.zoneJsVersion + backwardCompatibleVersions.angularV15.zoneJsVersion ); expect(devDependencies['@angular/cli']).toEqual( - backwardCompatibleVersions.angularV14.angularDevkitVersion + backwardCompatibleVersions.angularV15.angularDevkitVersion ); expect(devDependencies['@angular/compiler-cli']).toEqual( - backwardCompatibleVersions.angularV14.angularDevkitVersion + backwardCompatibleVersions.angularV15.angularDevkitVersion ); expect(devDependencies['@angular/language-service']).toEqual( - backwardCompatibleVersions.angularV14.angularVersion + backwardCompatibleVersions.angularV15.angularVersion ); expect(devDependencies['@angular-devkit/build-angular']).toEqual( - backwardCompatibleVersions.angularV14.angularDevkitVersion + backwardCompatibleVersions.angularV15.angularDevkitVersion ); // codelyzer should no longer be there by default @@ -449,11 +449,11 @@ bar ...json, dependencies: { ...json.dependencies, - '@angular/core': '~14.0.0', + '@angular/core': '~15.0.0', }, devDependencies: { ...json.devDependencies, - '@angular-devkit/build-angular': '~14.0.0', + '@angular-devkit/build-angular': '~15.0.0', }, })); @@ -463,20 +463,20 @@ bar // ASSERT const { dependencies, devDependencies } = readJson(tree, 'package.json'); - expect(dependencies['@angular/animations']).toBe('~14.0.0'); - expect(dependencies['@angular/common']).toBe('~14.0.0'); - expect(dependencies['@angular/compiler']).toBe('~14.0.0'); - expect(dependencies['@angular/core']).toBe('~14.0.0'); - expect(dependencies['@angular/platform-browser']).toBe('~14.0.0'); - expect(dependencies['@angular/platform-browser-dynamic']).toBe('~14.0.0'); - expect(dependencies['@angular/router']).toBe('~14.0.0'); + expect(dependencies['@angular/animations']).toBe('~15.0.0'); + expect(dependencies['@angular/common']).toBe('~15.0.0'); + expect(dependencies['@angular/compiler']).toBe('~15.0.0'); + expect(dependencies['@angular/core']).toBe('~15.0.0'); + expect(dependencies['@angular/platform-browser']).toBe('~15.0.0'); + expect(dependencies['@angular/platform-browser-dynamic']).toBe('~15.0.0'); + expect(dependencies['@angular/router']).toBe('~15.0.0'); expect(dependencies['rxjs']).toBeDefined(); expect(dependencies['tslib']).toBeDefined(); expect(dependencies['zone.js']).toBeDefined(); - expect(devDependencies['@angular/cli']).toBe('~14.0.0'); - expect(devDependencies['@angular/compiler-cli']).toBe('~14.0.0'); - expect(devDependencies['@angular/language-service']).toBe('~14.0.0'); - expect(devDependencies['@angular-devkit/build-angular']).toBe('~14.0.0'); + expect(devDependencies['@angular/cli']).toBe('~15.0.0'); + expect(devDependencies['@angular/compiler-cli']).toBe('~15.0.0'); + expect(devDependencies['@angular/language-service']).toBe('~15.0.0'); + expect(devDependencies['@angular-devkit/build-angular']).toBe('~15.0.0'); }); it('should not overwrite already installed dependencies', async () => { @@ -485,8 +485,8 @@ bar ...json, dependencies: { ...json.dependencies, - '@angular/animations': '~14.0.1', - '@angular/core': '~14.0.0', + '@angular/animations': '~15.0.1', + '@angular/core': '~15.0.0', }, })); @@ -496,8 +496,8 @@ bar // ASSERT const { dependencies } = readJson(tree, 'package.json'); - expect(dependencies['@angular/animations']).toBe('~14.0.1'); - expect(dependencies['@angular/core']).toBe('~14.0.0'); + expect(dependencies['@angular/animations']).toBe('~15.0.1'); + expect(dependencies['@angular/core']).toBe('~15.0.0'); }); describe('--unit-test-runner', () => { @@ -516,7 +516,7 @@ bar expect(devDependencies['@nx/jest']).toBeDefined(); expect(devDependencies['jest']).toBeDefined(); expect(devDependencies['jest-preset-angular']).toEqual( - backwardCompatibleVersions.angularV14.jestPresetAngularVersion + backwardCompatibleVersions.angularV15.jestPresetAngularVersion ); }); diff --git a/packages/angular/src/generators/library/__snapshots__/library.spec.ts.snap b/packages/angular/src/generators/library/__snapshots__/library.spec.ts.snap index cac7e9d2e869a..f5d052c4c9e80 100644 --- a/packages/angular/src/generators/library/__snapshots__/library.spec.ts.snap +++ b/packages/angular/src/generators/library/__snapshots__/library.spec.ts.snap @@ -1,50 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`lib --angular-14 should generate a library with a standalone component as entry point with angular 14.1.0 1`] = ` -"export * from './lib/my-lib/my-lib.component'; -" -`; - -exports[`lib --angular-14 should generate a library with a standalone component as entry point with angular 14.1.0 2`] = ` -"import { Component } from '@angular/core'; -import { CommonModule } from '@angular/common'; - -@Component({ - selector: 'proj-my-lib', - standalone: true, - imports: [CommonModule], - templateUrl: './my-lib.component.html', - styleUrls: ['./my-lib.component.css'], -}) -export class MyLibComponent {} -" -`; - -exports[`lib --angular-14 should generate a library with a standalone component as entry point with angular 14.1.0 3`] = ` -"import { ComponentFixture, TestBed } from '@angular/core/testing'; -import { MyLibComponent } from './my-lib.component'; - -describe('MyLibComponent', () => { - let component: MyLibComponent; - let fixture: ComponentFixture; - - beforeEach(async () => { - await TestBed.configureTestingModule({ - imports: [MyLibComponent], - }).compileComponents(); - - fixture = TestBed.createComponent(MyLibComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should create', () => { - expect(component).toBeTruthy(); - }); -}); -" -`; - exports[`lib --standalone should generate a library with a standalone component and have it flat 1`] = ` "export * from './lib/my-lib.component'; " diff --git a/packages/angular/src/generators/library/library.spec.ts b/packages/angular/src/generators/library/library.spec.ts index 1b080293f7af1..dc2e7ee2e4c2d 100644 --- a/packages/angular/src/generators/library/library.spec.ts +++ b/packages/angular/src/generators/library/library.spec.ts @@ -10,7 +10,6 @@ import { } from '@nx/devkit'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import { Linter } from '@nx/eslint'; -import { backwardCompatibleVersions } from '../../utils/backward-compatible-versions'; import { createApp } from '../../utils/nx-devkit/testing'; import { UnitTestRunner } from '../../utils/test-runners'; import { @@ -1679,124 +1678,6 @@ describe('lib', () => { }); }); - describe('--angular-14', () => { - beforeEach(() => { - tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - updateJson(tree, 'package.json', (json) => ({ - ...json, - dependencies: { - ...json.dependencies, - '@angular/core': '14.1.0', - }, - })); - }); - - it('should create a local tsconfig.json', async () => { - // ACT - await runLibraryGeneratorWithOpts(); - - // ASSERT - const tsconfigJson = readJson(tree, 'my-lib/tsconfig.json'); - expect(tsconfigJson).toEqual({ - extends: '../tsconfig.base.json', - angularCompilerOptions: { - enableI18nLegacyMessageIdFormat: false, - strictInjectionParameters: true, - strictInputAccessModifiers: true, - strictTemplates: true, - }, - compilerOptions: { - forceConsistentCasingInFileNames: true, - noFallthroughCasesInSwitch: true, - noPropertyAccessFromIndexSignature: true, - noImplicitOverride: true, - noImplicitReturns: true, - strict: true, - target: 'es2020', - useDefineForClassFields: false, - }, - files: [], - include: [], - references: [ - { - path: './tsconfig.lib.json', - }, - { - path: './tsconfig.spec.json', - }, - ], - }); - }); - - it('should create a local package.json', async () => { - // ACT - await runLibraryGeneratorWithOpts({ - publishable: true, - importPath: '@myorg/lib', - }); - - // ASSERT - const tsconfigJson = readJson(tree, 'my-lib/package.json'); - expect(tsconfigJson).toMatchInlineSnapshot(` - { - "dependencies": { - "tslib": "^2.3.0", - }, - "name": "@myorg/lib", - "peerDependencies": { - "@angular/common": "^14.1.0", - "@angular/core": "^14.1.0", - }, - "sideEffects": false, - "version": "0.0.1", - } - `); - }); - - it('should generate a library with a standalone component as entry point with angular 14.1.0', async () => { - await runLibraryGeneratorWithOpts({ standalone: true }); - - expect(tree.read('my-lib/src/index.ts', 'utf-8')).toMatchSnapshot(); - expect( - tree.read('my-lib/src/lib/my-lib/my-lib.component.ts', 'utf-8') - ).toMatchSnapshot(); - expect( - tree.read('my-lib/src/lib/my-lib/my-lib.component.spec.ts', 'utf-8') - ).toMatchSnapshot(); - }); - - it('should throw an error when trying to generate a library with a standalone component as entry point when angular version is < 14.1.0', async () => { - updateJson(tree, 'package.json', (json) => ({ - ...json, - dependencies: { - ...json.dependencies, - '@angular/core': '14.0.0', - }, - })); - - await expect( - runLibraryGeneratorWithOpts({ standalone: true }) - ).rejects.toThrow( - `The \"--standalone\" option is not supported in Angular versions < 14.1.0.` - ); - }); - - it('should update package.json with correct versions when buildable', async () => { - // ACT - await runLibraryGeneratorWithOpts({ buildable: true }); - - // ASSERT - const packageJson = readJson(tree, '/package.json'); - expect(packageJson.devDependencies['ng-packagr']).toEqual( - backwardCompatibleVersions.angularV14.ngPackagrVersion - ); - expect(packageJson.devDependencies['postcss']).toBeDefined(); - expect(packageJson.devDependencies['postcss-import']).toBeDefined(); - expect(packageJson.devDependencies['postcss-preset-env']).toBeDefined(); - expect(packageJson.devDependencies['postcss-url']).toBeDefined(); - }); - }); - describe('--project-name-and-root-format=derived', () => { it('should generate correctly when no directory is provided', async () => { await runLibraryGeneratorWithOpts({ diff --git a/packages/angular/src/generators/library/library.ts b/packages/angular/src/generators/library/library.ts index 3d96504c33cde..b520623e1de09 100644 --- a/packages/angular/src/generators/library/library.ts +++ b/packages/angular/src/generators/library/library.ts @@ -8,14 +8,12 @@ import { import { configurationGenerator } from '@nx/jest'; import { Linter } from '@nx/eslint'; import { addTsConfigPath } from '@nx/js'; -import { lt } from 'semver'; import init from '../../generators/init/init'; import { E2eTestRunner } from '../../utils/test-runners'; import addLintingGenerator from '../add-linting/add-linting'; import setupTailwindGenerator from '../setup-tailwind/setup-tailwind'; import { addDependenciesToPackageJsonIfDontExist, - getInstalledAngularVersionInfo, versions, } from '../utils/version-utils'; import { addBuildableLibrariesPostCssDependencies } from '../utils/dependencies'; @@ -66,13 +64,6 @@ export async function libraryGeneratorInternal( ); } - const userInstalledAngularVersion = getInstalledAngularVersionInfo(tree); - if (lt(userInstalledAngularVersion.version, '14.1.0') && schema.standalone) { - throw new Error( - `The "--standalone" option is not supported in Angular versions < 14.1.0.` - ); - } - const options = await normalizeOptions(tree, schema); const { libraryOptions } = options; diff --git a/packages/angular/src/generators/library/schema.json b/packages/angular/src/generators/library/schema.json index ca2858fae504c..8538d5d083761 100644 --- a/packages/angular/src/generators/library/schema.json +++ b/packages/angular/src/generators/library/schema.json @@ -141,65 +141,65 @@ }, "standalone": { "type": "boolean", - "description": "Generate a library that uses a standalone component instead of a module as the entry point. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "Generate a library that uses a standalone component instead of a module as the entry point.", "default": false }, "displayBlock": { - "description": "Specifies if the component generated style will contain `:host { display: block; }`. Disclaimer: This option is only valid when `--standalone` is set to `true`. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "Specifies if the component generated style will contain `:host { display: block; }`. Disclaimer: This option is only valid when `--standalone` is set to `true`.", "type": "boolean", "default": false, "alias": "b" }, "inlineStyle": { - "description": "Include styles inline in the component.ts file. Only CSS styles can be included inline. By default, an external styles file is created and referenced in the component.ts file. Disclaimer: This option is only valid when `--standalone` is set to `true`. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "Include styles inline in the component.ts file. Only CSS styles can be included inline. By default, an external styles file is created and referenced in the component.ts file. Disclaimer: This option is only valid when `--standalone` is set to `true`.", "type": "boolean", "default": false, "alias": "s" }, "inlineTemplate": { - "description": "Include template inline in the component.ts file. By default, an external template file is created and referenced in the component.ts file. Disclaimer: This option is only valid when `--standalone` is set to `true`. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "Include template inline in the component.ts file. By default, an external template file is created and referenced in the component.ts file. Disclaimer: This option is only valid when `--standalone` is set to `true`.", "type": "boolean", "default": false, "alias": "t" }, "viewEncapsulation": { - "description": "The view encapsulation strategy to use in the new component. Disclaimer: This option is only valid when `--standalone` is set to `true`. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "The view encapsulation strategy to use in the new component. Disclaimer: This option is only valid when `--standalone` is set to `true`.", "enum": ["Emulated", "None", "ShadowDom"], "type": "string", "alias": "v" }, "changeDetection": { - "description": "The change detection strategy to use in the new component. Disclaimer: This option is only valid when `--standalone` is set to `true`. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "The change detection strategy to use in the new component. Disclaimer: This option is only valid when `--standalone` is set to `true`.", "enum": ["Default", "OnPush"], "type": "string", "default": "Default", "alias": "c" }, "style": { - "description": "The file extension or preprocessor to use for style files, or `none` to skip generating the style file. Disclaimer: This option is only valid when `--standalone` is set to `true`. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "The file extension or preprocessor to use for style files, or `none` to skip generating the style file. Disclaimer: This option is only valid when `--standalone` is set to `true`.", "type": "string", "default": "css", "enum": ["css", "scss", "sass", "less", "none"] }, "skipTests": { "type": "boolean", - "description": "Do not create `spec.ts` test files for the new component. Disclaimer: This option is only valid when `--standalone` is set to `true`. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "Do not create `spec.ts` test files for the new component. Disclaimer: This option is only valid when `--standalone` is set to `true`.", "default": false }, "selector": { "type": "string", "format": "html-selector", - "description": "The HTML selector to use for this component. Disclaimer: This option is only valid when `--standalone` is set to `true`. _Note: This is only supported in Angular versions >= 14.1.0_" + "description": "The HTML selector to use for this component. Disclaimer: This option is only valid when `--standalone` is set to `true`." }, "skipSelector": { "type": "boolean", "default": false, - "description": "Specifies if the component should have a selector or not. Disclaimer: This option is only valid when `--standalone` is set to `true`. _Note: This is only supported in Angular versions >= 14.1.0_" + "description": "Specifies if the component should have a selector or not. Disclaimer: This option is only valid when `--standalone` is set to `true`." }, "flat": { "type": "boolean", "default": false, - "description": "Ensure the generated standalone component is not placed in a subdirectory. Disclaimer: This option is only valid when `--standalone` is set to `true`. _Note: This is only supported in Angular versions >= 14.1.0_" + "description": "Ensure the generated standalone component is not placed in a subdirectory. Disclaimer: This option is only valid when `--standalone` is set to `true`." } }, "additionalProperties": false, diff --git a/packages/angular/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.actions.ts__tmpl__ b/packages/angular/src/generators/ngrx-feature-store/files/__directory__/__fileName__.actions.ts__tmpl__ similarity index 100% rename from packages/angular/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.actions.ts__tmpl__ rename to packages/angular/src/generators/ngrx-feature-store/files/__directory__/__fileName__.actions.ts__tmpl__ diff --git a/packages/angular/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.effects.spec.ts__tmpl__ b/packages/angular/src/generators/ngrx-feature-store/files/__directory__/__fileName__.effects.spec.ts__tmpl__ similarity index 100% rename from packages/angular/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.effects.spec.ts__tmpl__ rename to packages/angular/src/generators/ngrx-feature-store/files/__directory__/__fileName__.effects.spec.ts__tmpl__ diff --git a/packages/angular/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.effects.ts__tmpl__ b/packages/angular/src/generators/ngrx-feature-store/files/__directory__/__fileName__.effects.ts__tmpl__ similarity index 100% rename from packages/angular/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.effects.ts__tmpl__ rename to packages/angular/src/generators/ngrx-feature-store/files/__directory__/__fileName__.effects.ts__tmpl__ diff --git a/packages/angular/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.facade.spec.ts__tmpl__ b/packages/angular/src/generators/ngrx-feature-store/files/__directory__/__fileName__.facade.spec.ts__tmpl__ similarity index 100% rename from packages/angular/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.facade.spec.ts__tmpl__ rename to packages/angular/src/generators/ngrx-feature-store/files/__directory__/__fileName__.facade.spec.ts__tmpl__ diff --git a/packages/angular/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.facade.ts__tmpl__ b/packages/angular/src/generators/ngrx-feature-store/files/__directory__/__fileName__.facade.ts__tmpl__ similarity index 100% rename from packages/angular/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.facade.ts__tmpl__ rename to packages/angular/src/generators/ngrx-feature-store/files/__directory__/__fileName__.facade.ts__tmpl__ diff --git a/packages/angular/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.models.ts__tmpl__ b/packages/angular/src/generators/ngrx-feature-store/files/__directory__/__fileName__.models.ts__tmpl__ similarity index 100% rename from packages/angular/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.models.ts__tmpl__ rename to packages/angular/src/generators/ngrx-feature-store/files/__directory__/__fileName__.models.ts__tmpl__ diff --git a/packages/angular/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.reducer.spec.ts__tmpl__ b/packages/angular/src/generators/ngrx-feature-store/files/__directory__/__fileName__.reducer.spec.ts__tmpl__ similarity index 100% rename from packages/angular/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.reducer.spec.ts__tmpl__ rename to packages/angular/src/generators/ngrx-feature-store/files/__directory__/__fileName__.reducer.spec.ts__tmpl__ diff --git a/packages/angular/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.reducer.ts__tmpl__ b/packages/angular/src/generators/ngrx-feature-store/files/__directory__/__fileName__.reducer.ts__tmpl__ similarity index 100% rename from packages/angular/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.reducer.ts__tmpl__ rename to packages/angular/src/generators/ngrx-feature-store/files/__directory__/__fileName__.reducer.ts__tmpl__ diff --git a/packages/angular/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.selectors.spec.ts__tmpl__ b/packages/angular/src/generators/ngrx-feature-store/files/__directory__/__fileName__.selectors.spec.ts__tmpl__ similarity index 100% rename from packages/angular/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.selectors.spec.ts__tmpl__ rename to packages/angular/src/generators/ngrx-feature-store/files/__directory__/__fileName__.selectors.spec.ts__tmpl__ diff --git a/packages/angular/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.selectors.ts__tmpl__ b/packages/angular/src/generators/ngrx-feature-store/files/__directory__/__fileName__.selectors.ts__tmpl__ similarity index 100% rename from packages/angular/src/generators/ngrx-feature-store/files/base/__directory__/__fileName__.selectors.ts__tmpl__ rename to packages/angular/src/generators/ngrx-feature-store/files/__directory__/__fileName__.selectors.ts__tmpl__ diff --git a/packages/angular/src/generators/ngrx-feature-store/files/no-inject/__directory__/__fileName__.effects.ts__tmpl__ b/packages/angular/src/generators/ngrx-feature-store/files/no-inject/__directory__/__fileName__.effects.ts__tmpl__ deleted file mode 100644 index c4c787a91cb64..0000000000000 --- a/packages/angular/src/generators/ngrx-feature-store/files/no-inject/__directory__/__fileName__.effects.ts__tmpl__ +++ /dev/null @@ -1,22 +0,0 @@ -import { Injectable } from '@angular/core'; -import { createEffect, Actions, ofType } from '@ngrx/effects'; - -import * as <%= className %>Actions from './<%= relativeFileName %>.actions'; -import * as <%= className %>Feature from './<%= relativeFileName %>.reducer'; - -import {switchMap, catchError, of} from 'rxjs'; - -@Injectable() -export class <%= className %>Effects { - init$ = createEffect(() => this.actions$.pipe( - ofType(<%= className %>Actions.init<%= className %>), - switchMap(() => of(<%= className %>Actions.load<%= className %>Success({ <%= propertyName %>: [] }))), - catchError((error) => { - console.error('Error', error); - return of(<%= className %>Actions.load<%= className %>Failure({ error })); - } - ) - )); - - constructor(private readonly actions$: Actions) {} -} diff --git a/packages/angular/src/generators/ngrx-feature-store/files/no-inject/__directory__/__fileName__.facade.ts__tmpl__ b/packages/angular/src/generators/ngrx-feature-store/files/no-inject/__directory__/__fileName__.facade.ts__tmpl__ deleted file mode 100644 index 61e66dcd8c1ac..0000000000000 --- a/packages/angular/src/generators/ngrx-feature-store/files/no-inject/__directory__/__fileName__.facade.ts__tmpl__ +++ /dev/null @@ -1,27 +0,0 @@ -import { Injectable } from '@angular/core'; -import { select, Store, Action } from '@ngrx/store'; - -import * as <%= className %>Actions from './<%= relativeFileName %>.actions'; -import * as <%= className %>Feature from './<%= relativeFileName %>.reducer'; -import * as <%= className %>Selectors from './<%= relativeFileName %>.selectors'; - -@Injectable() -export class <%= className %>Facade { - /** - * Combine pieces of state using createSelector, - * and expose them as observables through the facade. - */ - loaded$ = this.store.pipe(select(<%= className %>Selectors.select<%= className %>Loaded)); - all<%= className %>$ = this.store.pipe(select(<%= className %>Selectors.selectAll<%= className %>)); - selected<%= className %>$ = this.store.pipe(select(<%= className %>Selectors.selectEntity)); - - constructor(private readonly store: Store) {} - - /** - * Use the initialization action to perform one - * or more tasks in your Effects. - */ - init() { - this.store.dispatch(<%= className %>Actions.init<%= className %>()); - } -} diff --git a/packages/angular/src/generators/ngrx-feature-store/lib/generate-files.ts b/packages/angular/src/generators/ngrx-feature-store/lib/generate-files.ts index caee51b914021..a2de9ee60dc20 100644 --- a/packages/angular/src/generators/ngrx-feature-store/lib/generate-files.ts +++ b/packages/angular/src/generators/ngrx-feature-store/lib/generate-files.ts @@ -2,7 +2,6 @@ import type { Tree } from '@nx/devkit'; import { generateFiles, joinPathFragments, names } from '@nx/devkit'; import type { NormalizedNgRxFeatureStoreGeneratorOptions } from './normalize-options'; import { lt } from 'semver'; -import { getInstalledAngularVersion } from '../../utils/version-utils'; export function generateFilesFromTemplates( tree: Tree, @@ -15,7 +14,7 @@ export function generateFilesFromTemplates( generateFiles( tree, - joinPathFragments(__dirname, '..', 'files', 'base'), + joinPathFragments(__dirname, '..', 'files'), options.parentDirectory, { ...options, @@ -27,22 +26,6 @@ export function generateFilesFromTemplates( } ); - const angularVersion = getInstalledAngularVersion(tree); - if (lt(angularVersion, '14.1.0')) { - generateFiles( - tree, - joinPathFragments(__dirname, '..', 'files', 'no-inject'), - options.parentDirectory, - { - ...options, - ...projectNames, - fileName, - relativeFileName: projectNames.fileName, - tmpl: '', - } - ); - } - if (!options.facade) { tree.delete( joinPathFragments( diff --git a/packages/angular/src/generators/ngrx-feature-store/lib/validate-options.ts b/packages/angular/src/generators/ngrx-feature-store/lib/validate-options.ts index a13e9dddc46d7..be93fe817cd7a 100644 --- a/packages/angular/src/generators/ngrx-feature-store/lib/validate-options.ts +++ b/packages/angular/src/generators/ngrx-feature-store/lib/validate-options.ts @@ -1,12 +1,5 @@ import type { Tree } from '@nx/devkit'; import { Schema } from '../schema'; -import { - getInstalledAngularVersionInfo, - getInstalledPackageVersionInfo, -} from '../..//utils/version-utils'; -import { getPkgVersionForAngularMajorVersion } from '../../../utils/version-utils'; -import { coerce, lt, major } from 'semver'; -import { tsquery } from '@phenomnomnominal/tsquery'; export function validateOptions(tree: Tree, options: Schema): void { if (!options.parent) { @@ -16,35 +9,4 @@ export function validateOptions(tree: Tree, options: Schema): void { if (options.parent && !tree.exists(options.parent)) { throw new Error(`Parent does not exist: ${options.parent}.`); } - - const angularVersionInfo = getInstalledAngularVersionInfo(tree); - const intendedNgRxVersionForAngularMajor = - getPkgVersionForAngularMajorVersion( - 'ngrxVersion', - angularVersionInfo.major - ); - - const ngrxMajorVersion = - getInstalledPackageVersionInfo(tree, '@ngrx/store')?.major ?? - major(coerce(intendedNgRxVersionForAngularMajor)); - - if (lt(angularVersionInfo.version, '14.1.0') || ngrxMajorVersion < 15) { - const parentContent = tree.read(options.parent, 'utf-8'); - const { tsquery } = require('@phenomnomnominal/tsquery'); - const ast = tsquery.ast(parentContent); - - const NG_MODULE_DECORATOR_SELECTOR = - 'ClassDeclaration > Decorator > CallExpression:has(Identifier[name=NgModule])'; - const nodes = tsquery(ast, NG_MODULE_DECORATOR_SELECTOR, { - visitAllChildren: true, - }); - if (nodes.length === 0) { - throw new Error( - `The provided parent path "${options.parent}" does not contain an "NgModule". ` + - 'Please make sure to provide a path to an "NgModule" where the state will be registered. ' + - 'If you are trying to use a "Routes" definition file (for Standalone API usage), ' + - 'please note this is not supported in Angular versions lower than 14.1.0.' - ); - } - } } diff --git a/packages/angular/src/generators/ngrx-feature-store/schema.json b/packages/angular/src/generators/ngrx-feature-store/schema.json index 70915740f7c91..c0f1adb56e846 100644 --- a/packages/angular/src/generators/ngrx-feature-store/schema.json +++ b/packages/angular/src/generators/ngrx-feature-store/schema.json @@ -18,13 +18,13 @@ }, "parent": { "type": "string", - "description": "The path to the file where the state will be registered. For NgModule usage, this will be your Feature Module. For Standalone API usage, this will be your Routes definition file for your feature state. The host directory will create/use the new state directory. _Note: The Standalone API usage is only supported in Angular versions >= 14.1.0_.", + "description": "The path to the file where the state will be registered. For NgModule usage, this will be your Feature Module. For Standalone API usage, this will be your Routes definition file for your feature state. The host directory will create/use the new state directory.", "x-prompt": "What is the path to the module or Routes definition where this NgRx state should be registered?", "x-priority": "important" }, "route": { "type": "string", - "description": "The route that the Standalone NgRx Providers should be added to. _Note: This is only supported in Angular versions >= 14.1.0_.", + "description": "The route that the Standalone NgRx Providers should be added to.", "default": "''" }, "minimal": { diff --git a/packages/angular/src/generators/ngrx-root-store/lib/validate-options.ts b/packages/angular/src/generators/ngrx-root-store/lib/validate-options.ts index 48f8ab6fc5c0f..ab23ba9396a5f 100644 --- a/packages/angular/src/generators/ngrx-root-store/lib/validate-options.ts +++ b/packages/angular/src/generators/ngrx-root-store/lib/validate-options.ts @@ -1,13 +1,6 @@ import type { Tree } from '@nx/devkit'; import { getProjects, readProjectConfiguration } from '@nx/devkit'; import { Schema } from '../schema'; -import { - getInstalledAngularVersionInfo, - getInstalledPackageVersionInfo, -} from '../../utils/version-utils'; -import { getPkgVersionForAngularMajorVersion } from '../../../utils/version-utils'; -import { coerce, lt, major } from 'semver'; -import { isNgStandaloneApp } from '../../../utils/nx-devkit/ast-utils'; export function validateOptions(tree: Tree, options: Schema): void { if (!getProjects(tree).has(options.project)) { @@ -28,26 +21,4 @@ export function validateOptions(tree: Tree, options: Schema): void { `If generating a global feature state with your root store, you must provide a name for it with '--name'.` ); } - - const angularVersionInfo = getInstalledAngularVersionInfo(tree); - const intendedNgRxVersionForAngularMajor = - getPkgVersionForAngularMajorVersion( - 'ngrxVersion', - angularVersionInfo.major - ); - - const ngrxMajorVersion = - getInstalledPackageVersionInfo(tree, '@ngrx/store')?.major ?? - major(coerce(intendedNgRxVersionForAngularMajor)); - - const isStandalone = isNgStandaloneApp(tree, options.project); - - if (lt(angularVersionInfo.version, '14.1.0') || ngrxMajorVersion < 15) { - if (isStandalone) { - throw new Error( - `The provided project '${options.project}' is set up to use Standalone APIs, however your workspace is not configured to support Standalone APIs. ` + - 'Please make sure to provide a path to an "NgModule" where the state will be registered. ' - ); - } - } } diff --git a/packages/angular/src/generators/ngrx-root-store/schema.json b/packages/angular/src/generators/ngrx-root-store/schema.json index 4c637524c397a..532aab92c18f5 100644 --- a/packages/angular/src/generators/ngrx-root-store/schema.json +++ b/packages/angular/src/generators/ngrx-root-store/schema.json @@ -29,7 +29,7 @@ }, "route": { "type": "string", - "description": "The route that the Standalone NgRx Providers should be added to. _Note: This is only supported in Angular versions >= 14.1.0_.", + "description": "The route that the Standalone NgRx Providers should be added to.", "default": "''" }, "directory": { diff --git a/packages/angular/src/generators/ngrx/__snapshots__/ngrx.spec.ts.snap b/packages/angular/src/generators/ngrx/__snapshots__/ngrx.spec.ts.snap index 7a4129d543f25..b11e93ddb12ec 100644 --- a/packages/angular/src/generators/ngrx/__snapshots__/ngrx.spec.ts.snap +++ b/packages/angular/src/generators/ngrx/__snapshots__/ngrx.spec.ts.snap @@ -781,120 +781,6 @@ export const appRoutes: Routes = [ " `; -exports[`ngrx angular v14 support should generate the ngrx effects using "inject" for versions >= 14.1.0 1`] = ` -"import { Injectable, inject } from '@angular/core'; -import { createEffect, Actions, ofType } from '@ngrx/effects'; -import { switchMap, catchError, of } from 'rxjs'; -import * as UsersActions from './users.actions'; -import * as UsersFeature from './users.reducer'; - -@Injectable() -export class UsersEffects { - private actions$ = inject(Actions); - - init$ = createEffect(() => - this.actions$.pipe( - ofType(UsersActions.initUsers), - switchMap(() => of(UsersActions.loadUsersSuccess({ users: [] }))), - catchError((error) => { - console.error('Error', error); - return of(UsersActions.loadUsersFailure({ error })); - }) - ) - ); -} -" -`; - -exports[`ngrx angular v14 support should generate the ngrx effects with no usage of "inject" 1`] = ` -"import { Injectable } from '@angular/core'; -import { createEffect, Actions, ofType } from '@ngrx/effects'; - -import * as UsersActions from './users.actions'; -import * as UsersFeature from './users.reducer'; - -import { switchMap, catchError, of } from 'rxjs'; - -@Injectable() -export class UsersEffects { - init$ = createEffect(() => - this.actions$.pipe( - ofType(UsersActions.initUsers), - switchMap(() => of(UsersActions.loadUsersSuccess({ users: [] }))), - catchError((error) => { - console.error('Error', error); - return of(UsersActions.loadUsersFailure({ error })); - }) - ) - ); - - constructor(private readonly actions$: Actions) {} -} -" -`; - -exports[`ngrx angular v14 support should generate the ngrx facade using "inject" for versions >= 14.1.0 1`] = ` -"import { Injectable, inject } from '@angular/core'; -import { select, Store, Action } from '@ngrx/store'; - -import * as UsersActions from './users.actions'; -import * as UsersFeature from './users.reducer'; -import * as UsersSelectors from './users.selectors'; - -@Injectable() -export class UsersFacade { - private readonly store = inject(Store); - - /** - * Combine pieces of state using createSelector, - * and expose them as observables through the facade. - */ - loaded$ = this.store.pipe(select(UsersSelectors.selectUsersLoaded)); - allUsers$ = this.store.pipe(select(UsersSelectors.selectAllUsers)); - selectedUsers$ = this.store.pipe(select(UsersSelectors.selectEntity)); - - /** - * Use the initialization action to perform one - * or more tasks in your Effects. - */ - init() { - this.store.dispatch(UsersActions.initUsers()); - } -} -" -`; - -exports[`ngrx angular v14 support should generate the ngrx facade with no usage of "inject" 1`] = ` -"import { Injectable } from '@angular/core'; -import { select, Store, Action } from '@ngrx/store'; - -import * as UsersActions from './users.actions'; -import * as UsersFeature from './users.reducer'; -import * as UsersSelectors from './users.selectors'; - -@Injectable() -export class UsersFacade { - /** - * Combine pieces of state using createSelector, - * and expose them as observables through the facade. - */ - loaded$ = this.store.pipe(select(UsersSelectors.selectUsersLoaded)); - allUsers$ = this.store.pipe(select(UsersSelectors.selectAllUsers)); - selectedUsers$ = this.store.pipe(select(UsersSelectors.selectEntity)); - - constructor(private readonly store: Store) {} - - /** - * Use the initialization action to perform one - * or more tasks in your Effects. - */ - init() { - this.store.dispatch(UsersActions.initUsers()); - } -} -" -`; - exports[`ngrx rxjs v6 support should generate the ngrx effects using rxjs operators imported from "rxjs/operators" 1`] = ` "import { Injectable, inject } from '@angular/core'; import { createEffect, Actions, ofType } from '@ngrx/effects'; diff --git a/packages/angular/src/generators/ngrx/files/base/__directory__/__fileName__.actions.ts__tmpl__ b/packages/angular/src/generators/ngrx/files/__directory__/__fileName__.actions.ts__tmpl__ similarity index 100% rename from packages/angular/src/generators/ngrx/files/base/__directory__/__fileName__.actions.ts__tmpl__ rename to packages/angular/src/generators/ngrx/files/__directory__/__fileName__.actions.ts__tmpl__ diff --git a/packages/angular/src/generators/ngrx/files/base/__directory__/__fileName__.effects.spec.ts__tmpl__ b/packages/angular/src/generators/ngrx/files/__directory__/__fileName__.effects.spec.ts__tmpl__ similarity index 100% rename from packages/angular/src/generators/ngrx/files/base/__directory__/__fileName__.effects.spec.ts__tmpl__ rename to packages/angular/src/generators/ngrx/files/__directory__/__fileName__.effects.spec.ts__tmpl__ diff --git a/packages/angular/src/generators/ngrx/files/base/__directory__/__fileName__.effects.ts__tmpl__ b/packages/angular/src/generators/ngrx/files/__directory__/__fileName__.effects.ts__tmpl__ similarity index 100% rename from packages/angular/src/generators/ngrx/files/base/__directory__/__fileName__.effects.ts__tmpl__ rename to packages/angular/src/generators/ngrx/files/__directory__/__fileName__.effects.ts__tmpl__ diff --git a/packages/angular/src/generators/ngrx/files/base/__directory__/__fileName__.facade.spec.ts__tmpl__ b/packages/angular/src/generators/ngrx/files/__directory__/__fileName__.facade.spec.ts__tmpl__ similarity index 100% rename from packages/angular/src/generators/ngrx/files/base/__directory__/__fileName__.facade.spec.ts__tmpl__ rename to packages/angular/src/generators/ngrx/files/__directory__/__fileName__.facade.spec.ts__tmpl__ diff --git a/packages/angular/src/generators/ngrx/files/base/__directory__/__fileName__.facade.ts__tmpl__ b/packages/angular/src/generators/ngrx/files/__directory__/__fileName__.facade.ts__tmpl__ similarity index 100% rename from packages/angular/src/generators/ngrx/files/base/__directory__/__fileName__.facade.ts__tmpl__ rename to packages/angular/src/generators/ngrx/files/__directory__/__fileName__.facade.ts__tmpl__ diff --git a/packages/angular/src/generators/ngrx/files/base/__directory__/__fileName__.models.ts__tmpl__ b/packages/angular/src/generators/ngrx/files/__directory__/__fileName__.models.ts__tmpl__ similarity index 100% rename from packages/angular/src/generators/ngrx/files/base/__directory__/__fileName__.models.ts__tmpl__ rename to packages/angular/src/generators/ngrx/files/__directory__/__fileName__.models.ts__tmpl__ diff --git a/packages/angular/src/generators/ngrx/files/base/__directory__/__fileName__.reducer.spec.ts__tmpl__ b/packages/angular/src/generators/ngrx/files/__directory__/__fileName__.reducer.spec.ts__tmpl__ similarity index 100% rename from packages/angular/src/generators/ngrx/files/base/__directory__/__fileName__.reducer.spec.ts__tmpl__ rename to packages/angular/src/generators/ngrx/files/__directory__/__fileName__.reducer.spec.ts__tmpl__ diff --git a/packages/angular/src/generators/ngrx/files/base/__directory__/__fileName__.reducer.ts__tmpl__ b/packages/angular/src/generators/ngrx/files/__directory__/__fileName__.reducer.ts__tmpl__ similarity index 100% rename from packages/angular/src/generators/ngrx/files/base/__directory__/__fileName__.reducer.ts__tmpl__ rename to packages/angular/src/generators/ngrx/files/__directory__/__fileName__.reducer.ts__tmpl__ diff --git a/packages/angular/src/generators/ngrx/files/base/__directory__/__fileName__.selectors.spec.ts__tmpl__ b/packages/angular/src/generators/ngrx/files/__directory__/__fileName__.selectors.spec.ts__tmpl__ similarity index 100% rename from packages/angular/src/generators/ngrx/files/base/__directory__/__fileName__.selectors.spec.ts__tmpl__ rename to packages/angular/src/generators/ngrx/files/__directory__/__fileName__.selectors.spec.ts__tmpl__ diff --git a/packages/angular/src/generators/ngrx/files/base/__directory__/__fileName__.selectors.ts__tmpl__ b/packages/angular/src/generators/ngrx/files/__directory__/__fileName__.selectors.ts__tmpl__ similarity index 100% rename from packages/angular/src/generators/ngrx/files/base/__directory__/__fileName__.selectors.ts__tmpl__ rename to packages/angular/src/generators/ngrx/files/__directory__/__fileName__.selectors.ts__tmpl__ diff --git a/packages/angular/src/generators/ngrx/files/no-inject/__directory__/__fileName__.effects.ts__tmpl__ b/packages/angular/src/generators/ngrx/files/no-inject/__directory__/__fileName__.effects.ts__tmpl__ deleted file mode 100644 index 508c619520756..0000000000000 --- a/packages/angular/src/generators/ngrx/files/no-inject/__directory__/__fileName__.effects.ts__tmpl__ +++ /dev/null @@ -1,22 +0,0 @@ -import { Injectable } from '@angular/core'; -import { createEffect, Actions, ofType } from '@ngrx/effects'; - -import * as <%= className %>Actions from './<%= fileName %>.actions'; -import * as <%= className %>Feature from './<%= fileName %>.reducer'; - -import {switchMap, catchError, of} from 'rxjs'; - -@Injectable() -export class <%= className %>Effects { - init$ = createEffect(() => this.actions$.pipe( - ofType(<%= className %>Actions.init<%= className %>), - switchMap(() => of(<%= className %>Actions.load<%= className %>Success({ <%= propertyName %>: [] }))), - catchError((error) => { - console.error('Error', error); - return of(<%= className %>Actions.load<%= className %>Failure({ error })); - } - ) - )); - - constructor(private readonly actions$: Actions) {} -} diff --git a/packages/angular/src/generators/ngrx/files/no-inject/__directory__/__fileName__.facade.ts__tmpl__ b/packages/angular/src/generators/ngrx/files/no-inject/__directory__/__fileName__.facade.ts__tmpl__ deleted file mode 100644 index b5bd3607baa4f..0000000000000 --- a/packages/angular/src/generators/ngrx/files/no-inject/__directory__/__fileName__.facade.ts__tmpl__ +++ /dev/null @@ -1,27 +0,0 @@ -import { Injectable } from '@angular/core'; -import { select, Store, Action } from '@ngrx/store'; - -import * as <%= className %>Actions from './<%= fileName %>.actions'; -import * as <%= className %>Feature from './<%= fileName %>.reducer'; -import * as <%= className %>Selectors from './<%= fileName %>.selectors'; - -@Injectable() -export class <%= className %>Facade { - /** - * Combine pieces of state using createSelector, - * and expose them as observables through the facade. - */ - loaded$ = this.store.pipe(select(<%= className %>Selectors.select<%= className %>Loaded)); - all<%= className %>$ = this.store.pipe(select(<%= className %>Selectors.selectAll<%= className %>)); - selected<%= className %>$ = this.store.pipe(select(<%= className %>Selectors.selectEntity)); - - constructor(private readonly store: Store) {} - - /** - * Use the initialization action to perform one - * or more tasks in your Effects. - */ - init() { - this.store.dispatch(<%= className %>Actions.init<%= className %>()); - } -} diff --git a/packages/angular/src/generators/ngrx/lib/generate-files.ts b/packages/angular/src/generators/ngrx/lib/generate-files.ts index d0e478de02c89..dcf91e12e4bd5 100644 --- a/packages/angular/src/generators/ngrx/lib/generate-files.ts +++ b/packages/angular/src/generators/ngrx/lib/generate-files.ts @@ -1,7 +1,6 @@ import type { Tree } from '@nx/devkit'; import { generateFiles, joinPathFragments, names } from '@nx/devkit'; import { lt } from 'semver'; -import { getInstalledAngularVersion } from '../../utils/version-utils'; import { NormalizedNgRxGeneratorOptions } from './normalize-options'; /** @@ -16,7 +15,7 @@ export function generateNgrxFilesFromTemplates( generateFiles( tree, - joinPathFragments(__dirname, '..', 'files', 'base'), + joinPathFragments(__dirname, '..', 'files'), options.parentDirectory, { ...options, @@ -26,20 +25,6 @@ export function generateNgrxFilesFromTemplates( } ); - const angularVersion = getInstalledAngularVersion(tree); - if (lt(angularVersion, '14.1.0')) { - generateFiles( - tree, - joinPathFragments(__dirname, '..', 'files', 'no-inject'), - options.parentDirectory, - { - ...options, - ...projectNames, - tmpl: '', - } - ); - } - if (!options.facade) { tree.delete( joinPathFragments( diff --git a/packages/angular/src/generators/ngrx/lib/validate-options.ts b/packages/angular/src/generators/ngrx/lib/validate-options.ts index 5ead456ca43f0..f70302fae4ac4 100644 --- a/packages/angular/src/generators/ngrx/lib/validate-options.ts +++ b/packages/angular/src/generators/ngrx/lib/validate-options.ts @@ -1,11 +1,5 @@ import type { Tree } from '@nx/devkit'; -import { coerce, lt, major } from 'semver'; -import { - getInstalledAngularVersionInfo, - getInstalledPackageVersionInfo, -} from '../../utils/version-utils'; import type { NgRxGeneratorOptions } from '../schema'; -import { getPkgVersionForAngularMajorVersion } from '../../../utils/version-utils'; export function validateOptions( tree: Tree, @@ -20,36 +14,4 @@ export function validateOptions( if (options.parent && !tree.exists(options.parent)) { throw new Error(`Parent does not exist: ${options.parent}.`); } - - const angularVersionInfo = getInstalledAngularVersionInfo(tree); - const intendedNgRxVersionForAngularMajor = - getPkgVersionForAngularMajorVersion( - 'ngrxVersion', - angularVersionInfo.major - ); - - const ngrxMajorVersion = - getInstalledPackageVersionInfo(tree, '@ngrx/store')?.major ?? - major(coerce(intendedNgRxVersionForAngularMajor)); - - if (lt(angularVersionInfo.version, '14.1.0') || ngrxMajorVersion < 15) { - const parentPath = options.parent ?? options.module; - const parentContent = tree.read(parentPath, 'utf-8'); - const { tsquery } = require('@phenomnomnominal/tsquery'); - const ast = tsquery.ast(parentContent); - - const NG_MODULE_DECORATOR_SELECTOR = - 'ClassDeclaration > Decorator > CallExpression:has(Identifier[name=NgModule])'; - const nodes = tsquery(ast, NG_MODULE_DECORATOR_SELECTOR, { - visitAllChildren: true, - }); - if (nodes.length === 0) { - throw new Error( - `The provided parent path "${parentPath}" does not contain an "NgModule". ` + - 'Please make sure to provide a path to an "NgModule" where the state will be registered. ' + - 'If you are trying to use a "Routes" definition file (for Standalone API usage), ' + - 'please note this is not supported in Angular versions lower than 14.1.0.' - ); - } - } } diff --git a/packages/angular/src/generators/ngrx/ngrx.spec.ts b/packages/angular/src/generators/ngrx/ngrx.spec.ts index 71b80ac7e6745..a50b6ee7c01ba 100644 --- a/packages/angular/src/generators/ngrx/ngrx.spec.ts +++ b/packages/angular/src/generators/ngrx/ngrx.spec.ts @@ -633,7 +633,7 @@ describe('ngrx', () => { }); }); - describe('angular v14 support', () => { + describe('angular v15 support', () => { beforeEach(async () => { jest.clearAllMocks(); tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); @@ -642,163 +642,38 @@ describe('ngrx', () => { ...json, dependencies: { ...json.dependencies, - '@angular/core': '14.0.0', + '@angular/core': '15.0.0', }, })); }); - it('should install the ngrx 14 packages', async () => { + it('should install the ngrx 15 packages', async () => { await ngrxGenerator(tree, defaultOptions); const packageJson = devkit.readJson(tree, 'package.json'); expect(packageJson.dependencies['@ngrx/store']).toEqual( - backwardCompatibleVersions.angularV14.ngrxVersion + backwardCompatibleVersions.angularV15.ngrxVersion ); expect(packageJson.dependencies['@ngrx/effects']).toEqual( - backwardCompatibleVersions.angularV14.ngrxVersion + backwardCompatibleVersions.angularV15.ngrxVersion ); expect(packageJson.dependencies['@ngrx/entity']).toEqual( - backwardCompatibleVersions.angularV14.ngrxVersion + backwardCompatibleVersions.angularV15.ngrxVersion ); expect(packageJson.dependencies['@ngrx/router-store']).toEqual( - backwardCompatibleVersions.angularV14.ngrxVersion + backwardCompatibleVersions.angularV15.ngrxVersion ); expect(packageJson.dependencies['@ngrx/component-store']).toEqual( - backwardCompatibleVersions.angularV14.ngrxVersion + backwardCompatibleVersions.angularV15.ngrxVersion ); expect(packageJson.devDependencies['@ngrx/schematics']).toEqual( - backwardCompatibleVersions.angularV14.ngrxVersion + backwardCompatibleVersions.angularV15.ngrxVersion ); expect(packageJson.devDependencies['@ngrx/store-devtools']).toEqual( - backwardCompatibleVersions.angularV14.ngrxVersion + backwardCompatibleVersions.angularV15.ngrxVersion ); expect(packageJson.devDependencies['jasmine-marbles']).toBeDefined(); }); - - it('should generate the ngrx effects with no usage of "inject"', async () => { - await ngrxGenerator(tree, defaultOptions); - - expect( - tree.read('myapp/src/app/+state/users.effects.ts', 'utf-8') - ).toMatchSnapshot(); - }); - - it('should generate the ngrx effects using "inject" for versions >= 14.1.0', async () => { - devkit.updateJson(tree, 'package.json', (json) => ({ - ...json, - dependencies: { - ...json.dependencies, - '@angular/core': '14.1.0', - }, - })); - - await ngrxGenerator(tree, defaultOptions); - - expect( - tree.read('myapp/src/app/+state/users.effects.ts', 'utf-8') - ).toMatchSnapshot(); - }); - - it('should generate the ngrx facade with no usage of "inject"', async () => { - await ngrxGenerator(tree, { ...defaultOptions, facade: true }); - - expect( - tree.read('myapp/src/app/+state/users.facade.ts', 'utf-8') - ).toMatchSnapshot(); - }); - - it('should generate the ngrx facade using "inject" for versions >= 14.1.0', async () => { - devkit.updateJson(tree, 'package.json', (json) => ({ - ...json, - dependencies: { - ...json.dependencies, - '@angular/core': '14.1.0', - }, - })); - - await ngrxGenerator(tree, { ...defaultOptions, facade: true }); - - expect( - tree.read('myapp/src/app/+state/users.facade.ts', 'utf-8') - ).toMatchSnapshot(); - }); - - it('should throw when Angular version < 14.1 and NgRx < 15 but path to routes file is provided', async () => { - const parentPath = 'myapp/src/app/app.routes.ts'; - tree.write( - parentPath, - `import { Routes } from '@angular/router'; - import { NxWelcomeComponent } from './nx-welcome.component'; - export const appRoutes: Routes = [{ path: '', component: NxWelcomeComponent }];` - ); - - devkit.updateJson(tree, 'package.json', (json) => ({ - ...json, - dependencies: { - ...json.dependencies, - '@angular/core': '14.1.0', - '@ngrx/store': '14.1.0', - }, - })); - - // ACT & ASSERT - await expect( - ngrxGenerator(tree, { - ...defaultStandaloneOptions, - parent: parentPath, - }) - ).rejects.toThrowError( - `The provided parent path "${parentPath}" does not contain an "NgModule".` - ); - }); - - it('should throw when Angular version < 15 and NgRx is not currently installed but path to routes file is provided', async () => { - const parentPath = 'myapp/src/app/app.routes.ts'; - tree.write( - parentPath, - `import { Routes } from '@angular/router'; - import { NxWelcomeComponent } from './nx-welcome.component'; - export const appRoutes: Routes = [{ path: '', component: NxWelcomeComponent }];` - ); - - devkit.updateJson(tree, 'package.json', (json) => ({ - ...json, - dependencies: { - ...json.dependencies, - '@angular/core': '14.2.0', - }, - })); - - // ACT & ASSERT - await expect( - ngrxGenerator(tree, { - ...defaultStandaloneOptions, - parent: parentPath, - }) - ).rejects.toThrowError( - `The provided parent path "${parentPath}" does not contain an "NgModule".` - ); - }); - - it('should throw when the provided parent does not have an NgModule', async () => { - const parentPath = 'myapp/src/app/app.routes.ts'; - tree.write( - parentPath, - `import { Routes } from '@angular/router'; - import { NxWelcomeComponent } from './nx-welcome.component'; - export const appRoutes: Routes = [{ path: '', component: NxWelcomeComponent }];` - ); - - // ACT & ASSERT - await expect( - ngrxGenerator(tree, { - ...defaultStandaloneOptions, - parent: parentPath, - }) - ).rejects.toThrowError( - `The provided parent path "${parentPath}" does not contain an "NgModule".` - ); - }); }); describe('rxjs v6 support', () => { diff --git a/packages/angular/src/generators/ngrx/schema.json b/packages/angular/src/generators/ngrx/schema.json index dbf17be454e44..3ce79b1af633e 100644 --- a/packages/angular/src/generators/ngrx/schema.json +++ b/packages/angular/src/generators/ngrx/schema.json @@ -42,13 +42,13 @@ }, "parent": { "type": "string", - "description": "The path to the file where the state will be registered. For NgModule usage, this will be your `app.module.ts` for your root state, or your Feature Module for feature state. For Standalone API usage, this will be your `app.config.ts` file for your root state, or the Routes definition file for your feature state. The host directory will create/use the new state directory. _Note: The Standalone API usage is only supported in Angular versions >= 14.1.0_.", + "description": "The path to the file where the state will be registered. For NgModule usage, this will be your `app.module.ts` for your root state, or your Feature Module for feature state. For Standalone API usage, this will be your `app.config.ts` file for your root state, or the Routes definition file for your feature state. The host directory will create/use the new state directory.", "x-prompt": "What is the path to the module or Routes definition where this NgRx state should be registered?", "x-priority": "important" }, "route": { "type": "string", - "description": "The route that the Standalone NgRx Providers should be added to. _Note: This is only supported in Angular versions >= 14.1.0_.", + "description": "The route that the Standalone NgRx Providers should be added to.", "default": "''" }, "directory": { diff --git a/packages/angular/src/generators/pipe/lib/index.ts b/packages/angular/src/generators/pipe/lib/index.ts index da94c6f89ca24..f9451963f55a2 100644 --- a/packages/angular/src/generators/pipe/lib/index.ts +++ b/packages/angular/src/generators/pipe/lib/index.ts @@ -1,2 +1 @@ export * from './normalize-options'; -export * from './validate-options'; diff --git a/packages/angular/src/generators/pipe/lib/validate-options.ts b/packages/angular/src/generators/pipe/lib/validate-options.ts deleted file mode 100644 index d51a443cd84fb..0000000000000 --- a/packages/angular/src/generators/pipe/lib/validate-options.ts +++ /dev/null @@ -1,7 +0,0 @@ -import type { Tree } from '@nx/devkit'; -import { validateStandaloneOption } from '../../utils/validations'; -import type { Schema } from '../schema'; - -export function validateOptions(tree: Tree, options: Schema): void { - validateStandaloneOption(tree, options.standalone); -} diff --git a/packages/angular/src/generators/pipe/pipe.ts b/packages/angular/src/generators/pipe/pipe.ts index 74ad126c9855a..9b67117f59345 100644 --- a/packages/angular/src/generators/pipe/pipe.ts +++ b/packages/angular/src/generators/pipe/pipe.ts @@ -6,11 +6,10 @@ import { names, } from '@nx/devkit'; import { addToNgModule, findModule } from '../utils'; -import { normalizeOptions, validateOptions } from './lib'; +import { normalizeOptions } from './lib'; import type { Schema } from './schema'; export async function pipeGenerator(tree: Tree, rawOptions: Schema) { - validateOptions(tree, rawOptions); const options = await normalizeOptions(tree, rawOptions); const pipeNames = names(options.name); diff --git a/packages/angular/src/generators/pipe/schema.json b/packages/angular/src/generators/pipe/schema.json index 0be12fae31dbd..3d447e622b657 100644 --- a/packages/angular/src/generators/pipe/schema.json +++ b/packages/angular/src/generators/pipe/schema.json @@ -53,7 +53,7 @@ "description": "Do not import this pipe into the owning NgModule." }, "standalone": { - "description": "Whether the generated pipe is standalone. _Note: This is only supported in Angular versions >= 14.1.0_.", + "description": "Whether the generated pipe is standalone.", "type": "boolean", "default": false }, diff --git a/packages/angular/src/generators/remote/remote.spec.ts b/packages/angular/src/generators/remote/remote.spec.ts index f96a97af65a49..2197512a9941d 100644 --- a/packages/angular/src/generators/remote/remote.spec.ts +++ b/packages/angular/src/generators/remote/remote.spec.ts @@ -4,8 +4,6 @@ import { readJson, readNxJson, readProjectConfiguration, - stripIndents, - updateJson, } from '@nx/devkit'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import { @@ -374,27 +372,6 @@ describe('MF Remote App Generator', () => { }); }); - it('should error correctly when Angular version does not support standalone', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - updateJson(tree, 'package.json', (json) => ({ - ...json, - dependencies: { - '@angular/core': '14.0.0', - }, - })); - - // ACT & ASSERT - await expect( - generateTestRemoteApplication(tree, { - name: 'test', - standalone: true, - }) - ).rejects - .toThrow(stripIndents`The "standalone" option is only supported in Angular >= 14.1.0. You are currently using 14.0.0. - You can resolve this error by removing the "standalone" option or by migrating to Angular 14.1.0.`); - }); - describe('--project-name-and-root-format=derived', () => { it('should generate remote', async () => { const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); diff --git a/packages/angular/src/generators/remote/remote.ts b/packages/angular/src/generators/remote/remote.ts index 0393e14db80e7..abfbb750d52de 100644 --- a/packages/angular/src/generators/remote/remote.ts +++ b/packages/angular/src/generators/remote/remote.ts @@ -3,15 +3,12 @@ import { formatFiles, getProjects, runTasksInSerial, - stripIndents, Tree, } from '@nx/devkit'; import { determineProjectNameAndRootOptions } from '@nx/devkit/src/generators/project-name-and-root-utils'; -import { lt } from 'semver'; import { E2eTestRunner } from '../../utils/test-runners'; import { applicationGenerator } from '../application/application'; import { setupMf } from '../setup-mf/setup-mf'; -import { getInstalledAngularVersionInfo } from '../utils/version-utils'; import { addSsr, findNextAvailablePort } from './lib'; import type { Schema } from './schema'; import { swcHelpersVersion } from '@nx/js/src/utils/versions'; @@ -24,13 +21,6 @@ export async function remote(tree: Tree, options: Schema) { } export async function remoteInternal(tree: Tree, schema: Schema) { - const installedAngularVersionInfo = getInstalledAngularVersionInfo(tree); - - if (lt(installedAngularVersionInfo.version, '14.1.0') && schema.standalone) { - throw new Error(stripIndents`The "standalone" option is only supported in Angular >= 14.1.0. You are currently using ${installedAngularVersionInfo.version}. - You can resolve this error by removing the "standalone" option or by migrating to Angular 14.1.0.`); - } - const { typescriptConfiguration = true, ...options }: Schema = schema; const projects = getProjects(tree); diff --git a/packages/angular/src/generators/remote/schema.json b/packages/angular/src/generators/remote/schema.json index b819e8c7d4af2..8a77b3660887e 100644 --- a/packages/angular/src/generators/remote/schema.json +++ b/packages/angular/src/generators/remote/schema.json @@ -158,7 +158,7 @@ "x-priority": "internal" }, "standalone": { - "description": "Whether to generate a remote application with standalone components. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "Whether to generate a remote application with standalone components.", "type": "boolean", "default": false }, diff --git a/packages/angular/src/generators/scam-to-standalone/scam-to-standalone.spec.ts b/packages/angular/src/generators/scam-to-standalone/scam-to-standalone.spec.ts index d2739e01e5a91..2b318d1d0b8fa 100644 --- a/packages/angular/src/generators/scam-to-standalone/scam-to-standalone.spec.ts +++ b/packages/angular/src/generators/scam-to-standalone/scam-to-standalone.spec.ts @@ -1,4 +1,3 @@ -import { stripIndents, updateJson } from '@nx/devkit'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import scamGenerator from '../scam/scam'; import { generateTestApplication } from '../utils/testing'; @@ -78,25 +77,4 @@ describe('scam-to-standalone', () => { " `); }); - - it('should error correctly when Angular version does not support standalone', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - updateJson(tree, 'package.json', (json) => ({ - ...json, - dependencies: { - '@angular/core': '14.0.0', - }, - })); - - // ACT & ASSERT - await expect( - scamToStandalone(tree, { - component: 'src/app/bar/bar.component.ts', - project: 'foo', - }) - ).rejects - .toThrow(stripIndents`This generator is only supported with Angular >= 14.1.0. You are currently using 14.0.0. - You can resolve this error by migrating to Angular 14.1.0.`); - }); }); diff --git a/packages/angular/src/generators/scam-to-standalone/scam-to-standalone.ts b/packages/angular/src/generators/scam-to-standalone/scam-to-standalone.ts index 315b9a6e681fc..20d6d80701463 100644 --- a/packages/angular/src/generators/scam-to-standalone/scam-to-standalone.ts +++ b/packages/angular/src/generators/scam-to-standalone/scam-to-standalone.ts @@ -1,10 +1,5 @@ import type { Tree } from '@nx/devkit'; -import { - formatFiles, - getProjects, - joinPathFragments, - stripIndents, -} from '@nx/devkit'; +import { formatFiles, getProjects, joinPathFragments } from '@nx/devkit'; import type { Schema } from './schema'; import { convertScamToStandalone, @@ -15,20 +10,11 @@ import { verifyIsInlineScam, verifyModuleIsScam, } from './lib'; -import { getInstalledAngularVersionInfo } from '../utils/version-utils'; -import { lt } from 'semver'; export async function scamToStandalone( tree: Tree, { component, project: projectName, skipFormat }: Schema ) { - const installedAngularVersionInfo = getInstalledAngularVersionInfo(tree); - - if (lt(installedAngularVersionInfo.version, '14.1.0')) { - throw new Error(stripIndents`This generator is only supported with Angular >= 14.1.0. You are currently using ${installedAngularVersionInfo.version}. - You can resolve this error by migrating to Angular 14.1.0.`); - } - const projects = getProjects(tree); let project = getTargetProject(projectName, projects); diff --git a/packages/angular/src/generators/scam-to-standalone/schema.json b/packages/angular/src/generators/scam-to-standalone/schema.json index 230013ad45148..3987dcb68d3c7 100644 --- a/packages/angular/src/generators/scam-to-standalone/schema.json +++ b/packages/angular/src/generators/scam-to-standalone/schema.json @@ -3,7 +3,7 @@ "$id": "GeneratorAngularScamToStandalone", "cli": "nx", "title": "Convert an Inline SCAM to Standalone Component", - "description": "Convert an Inline SCAM to a Standalone Component. _Note: This generator is only supported with Angular versions >= 14.1.0_.", + "description": "Convert an Inline SCAM to a Standalone Component.", "type": "object", "properties": { "component": { diff --git a/packages/angular/src/generators/setup-mf/lib/fix-bootstrap.ts b/packages/angular/src/generators/setup-mf/lib/fix-bootstrap.ts index 7f8f7eac71cb1..6f9c33f738579 100644 --- a/packages/angular/src/generators/setup-mf/lib/fix-bootstrap.ts +++ b/packages/angular/src/generators/setup-mf/lib/fix-bootstrap.ts @@ -1,17 +1,12 @@ import type { Tree } from '@nx/devkit'; import { joinPathFragments } from '@nx/devkit'; import type { Schema } from '../schema'; -import { getInstalledAngularMajorVersion } from '../../utils/version-utils'; export function fixBootstrap(tree: Tree, appRoot: string, options: Schema) { const mainFilePath = joinPathFragments(appRoot, 'src/main.ts'); const bootstrapCode = tree.read(mainFilePath, 'utf-8'); - const installedAngularMajor = getInstalledAngularMajorVersion(tree); if (options.standalone) { - tree.write( - `${appRoot}/src/bootstrap.ts`, - standaloneBootstrapCode(installedAngularMajor === 14) - ); + tree.write(`${appRoot}/src/bootstrap.ts`, standaloneBootstrapCode()); } else { tree.write(joinPathFragments(appRoot, 'src/bootstrap.ts'), bootstrapCode); } @@ -33,21 +28,11 @@ export function fixBootstrap(tree: Tree, appRoot: string, options: Schema) { ); } -const standaloneBootstrapCode = ( - includeEnvironments: boolean = false -) => `import {bootstrapApplication} from "@angular/platform-browser"; +const standaloneBootstrapCode = + () => `import {bootstrapApplication} from "@angular/platform-browser"; import {appConfig} from './app/app.config'; import {RemoteEntryComponent} from './app/remote-entry/entry.component'; -${ - includeEnvironments - ? `import {enableProdMode} from '@angular/core'; -import {environment} from './environments/environment'; -if(environment.production) { - enableProdMode(); -} -` - : `` -} + bootstrapApplication(RemoteEntryComponent, appConfig).catch((err) => console.error(err) );`; diff --git a/packages/angular/src/generators/setup-mf/schema.json b/packages/angular/src/generators/setup-mf/schema.json index 69ab1639c41d6..64d5efc5caac1 100644 --- a/packages/angular/src/generators/setup-mf/schema.json +++ b/packages/angular/src/generators/setup-mf/schema.json @@ -71,7 +71,7 @@ }, "standalone": { "type": "boolean", - "description": "Whether the application is a standalone application. _Note: This is only supported in Angular versions >= 14.1.0_", + "description": "Whether the application is a standalone application.", "default": false }, "typescriptConfiguration": { diff --git a/packages/angular/src/generators/setup-mf/setup-mf.spec.ts b/packages/angular/src/generators/setup-mf/setup-mf.spec.ts index a78a62a4f2114..6770f6008cdcb 100644 --- a/packages/angular/src/generators/setup-mf/setup-mf.spec.ts +++ b/packages/angular/src/generators/setup-mf/setup-mf.spec.ts @@ -1,9 +1,4 @@ -import { - readJson, - readProjectConfiguration, - Tree, - updateJson, -} from '@nx/devkit'; +import { readJson, readProjectConfiguration, Tree } from '@nx/devkit'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import { generateTestApplication } from '../utils/testing'; import { setupMf } from './setup-mf'; @@ -475,48 +470,6 @@ describe('Init MF', () => { }); }); - it('should generate bootstrap with environments for ng14', async () => { - // ARRANGE - updateJson(tree, 'package.json', (json) => ({ - ...json, - dependencies: { - ...json.dependencies, - '@angular/core': '14.1.0', - }, - })); - - await generateTestApplication(tree, { - name: 'ng14', - routing: true, - standalone: true, - }); - - // ACT - await setupMf(tree, { - appName: 'ng14', - mfType: 'host', - routing: true, - standalone: true, - }); - - // ASSERT - expect(tree.read('ng14/src/bootstrap.ts', 'utf-8')).toMatchInlineSnapshot(` - "import { bootstrapApplication } from '@angular/platform-browser'; - import { appConfig } from './app/app.config'; - import { RemoteEntryComponent } from './app/remote-entry/entry.component'; - import { enableProdMode } from '@angular/core'; - import { environment } from './environments/environment'; - if (environment.production) { - enableProdMode(); - } - - bootstrapApplication(RemoteEntryComponent, appConfig).catch((err) => - console.error(err) - ); - " - `); - }); - it('should add a remote to dynamic host correctly', async () => { // ARRANGE await setupMf(tree, { @@ -580,26 +533,4 @@ describe('Init MF', () => { }); expect(tree.read('app1/src/app/app.routes.ts', 'utf-8')).toMatchSnapshot(); }); - - it('should throw an error when installed version of angular < 14.1.0 and --standalone is used', async () => { - // ARRANGE - updateJson(tree, 'package.json', (json) => ({ - ...json, - dependencies: { - ...json.dependencies, - '@angular/core': '14.0.0', - }, - })); - - // ACT & ASSERT - await expect( - setupMf(tree, { - appName: 'app1', - mfType: 'host', - standalone: true, - }) - ).rejects.toThrow( - 'The --standalone flag is not supported in your current version of Angular (14.0.0). Please update to a version of Angular that supports Standalone Components (>= 14.1.0).' - ); - }); }); diff --git a/packages/angular/src/generators/setup-mf/setup-mf.ts b/packages/angular/src/generators/setup-mf/setup-mf.ts index c2628d6126ca3..12e086576f220 100644 --- a/packages/angular/src/generators/setup-mf/setup-mf.ts +++ b/packages/angular/src/generators/setup-mf/setup-mf.ts @@ -22,18 +22,9 @@ import { updateHostAppRoutes, updateTsConfigTarget, } from './lib'; -import { getInstalledAngularVersionInfo } from '../utils/version-utils'; import { nxVersion } from '../../utils/versions'; -import { lt } from 'semver'; export async function setupMf(tree: Tree, rawOptions: Schema) { - const installedAngularInfo = getInstalledAngularVersionInfo(tree); - if (lt(installedAngularInfo.version, '14.1.0') && rawOptions.standalone) { - throw new Error( - `The --standalone flag is not supported in your current version of Angular (${installedAngularInfo.version}). Please update to a version of Angular that supports Standalone Components (>= 14.1.0).` - ); - } - const options = normalizeOptions(tree, rawOptions); const projectConfig = readProjectConfiguration(tree, options.appName); diff --git a/packages/angular/src/generators/setup-ssr/files/ngmodule/v14/src/__main__ b/packages/angular/src/generators/setup-ssr/files/ngmodule/v14/src/__main__ deleted file mode 100644 index ccb72c72f9e23..0000000000000 --- a/packages/angular/src/generators/setup-ssr/files/ngmodule/v14/src/__main__ +++ /dev/null @@ -1,11 +0,0 @@ -/*************************************************************************************************** - * Initialize the server environment - for example, adding DOM built-in types to the global scope. - * - * NOTE: - * This import must come before any imports (direct or transitive) that rely on DOM built-ins being - * available, such as `@angular/elements`. - */ -import '@angular/platform-server/init'; - -export { <%= rootModuleClassName %> } from './app/<%= rootModuleFileName.slice(0, -3) %>'; -export { renderModule } from '@angular/platform-server'; \ No newline at end of file diff --git a/packages/angular/src/generators/setup-ssr/lib/generate-files.ts b/packages/angular/src/generators/setup-ssr/lib/generate-files.ts index 9aada2b97fcdb..8826526ece864 100644 --- a/packages/angular/src/generators/setup-ssr/lib/generate-files.ts +++ b/packages/angular/src/generators/setup-ssr/lib/generate-files.ts @@ -39,18 +39,8 @@ export function generateSSRFiles(tree: Tree, schema: Schema) { { ...schema, browserBundleOutputPath, tpl: '' } ); - const { major: angularMajorVersion, version: angularVersion } = - getInstalledAngularVersionInfo(tree); + const { version: angularVersion } = getInstalledAngularVersionInfo(tree); - if (angularMajorVersion < 15) { - generateFiles( - tree, - joinPathFragments(pathToFiles, 'ngmodule', 'v14'), - projectRoot, - - { ...schema, browserBundleOutputPath, tpl: '' } - ); - } if (lt(angularVersion, '15.2.0')) { generateFiles( tree, diff --git a/packages/angular/src/generators/setup-ssr/lib/validate-options.ts b/packages/angular/src/generators/setup-ssr/lib/validate-options.ts index 6f8128d2c2a3a..5c11e51371cfc 100644 --- a/packages/angular/src/generators/setup-ssr/lib/validate-options.ts +++ b/packages/angular/src/generators/setup-ssr/lib/validate-options.ts @@ -1,16 +1,12 @@ import type { Tree } from '@nx/devkit'; import { stripIndents } from '@nx/devkit'; -import { - validateProject, - validateStandaloneOption, -} from '../../utils/validations'; +import { validateProject } from '../../utils/validations'; import type { Schema } from '../schema'; import { getInstalledAngularVersionInfo } from '../../utils/version-utils'; import { lt } from 'semver'; export function validateOptions(tree: Tree, options: Schema): void { validateProject(tree, options.project); - validateStandaloneOption(tree, options.standalone); validateHydrationOption(tree, options.hydration); } diff --git a/packages/angular/src/generators/setup-ssr/schema.json b/packages/angular/src/generators/setup-ssr/schema.json index f5da0d6ac96b6..7c8e7997fabfc 100644 --- a/packages/angular/src/generators/setup-ssr/schema.json +++ b/packages/angular/src/generators/setup-ssr/schema.json @@ -51,7 +51,7 @@ }, "standalone": { "type": "boolean", - "description": "Use Standalone Components to bootstrap SSR. _Note: This is only supported in Angular versions >= 14.1.0_." + "description": "Use Standalone Components to bootstrap SSR." }, "hydration": { "type": "boolean", diff --git a/packages/angular/src/generators/setup-ssr/setup-ssr.spec.ts b/packages/angular/src/generators/setup-ssr/setup-ssr.spec.ts index d8c86689b585d..50b8a48d6c2ed 100644 --- a/packages/angular/src/generators/setup-ssr/setup-ssr.spec.ts +++ b/packages/angular/src/generators/setup-ssr/setup-ssr.spec.ts @@ -7,6 +7,7 @@ import { } from '@nx/devkit'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; import { PackageJson } from 'nx/src/utils/package-json'; +import { backwardCompatibleVersions } from '../../utils/backward-compatible-versions'; import { angularVersion, ngUniversalVersion } from '../../utils/versions'; import { generateTestApplication } from '../utils/testing'; import { setupSsr } from './setup-ssr'; @@ -309,7 +310,7 @@ describe('setupSSR', () => { updateJson(tree, 'package.json', (json) => ({ ...json, dependencies: { - '@angular/core': '14.2.0', + '@angular/core': '15.2.0', }, })); @@ -319,48 +320,16 @@ describe('setupSSR', () => { // ASSERT const pkgJson = readJson(tree, 'package.json'); expect(pkgJson.dependencies['@angular/platform-server']).toEqual( - '~14.2.0' + backwardCompatibleVersions.angularV15.angularVersion ); expect(pkgJson.dependencies['@nguniversal/express-engine']).toEqual( - '~14.2.0' + backwardCompatibleVersions.angularV15.ngUniversalVersion ); expect(pkgJson.devDependencies['@nguniversal/builders']).toEqual( - '~14.2.0' + backwardCompatibleVersions.angularV15.ngUniversalVersion ); }); - it('should create the main.server.ts file correctly for Angular v14', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - await generateTestApplication(tree, { - name: 'app1', - }); - updateJson(tree, 'package.json', (json) => ({ - ...json, - dependencies: { '@angular/core': '14.2.0' }, - })); - - // ACT - await setupSsr(tree, { project: 'app1' }); - - // ASSERT - expect(tree.read('app1/src/main.server.ts', 'utf-8')) - .toMatchInlineSnapshot(` - "/*************************************************************************************************** - * Initialize the server environment - for example, adding DOM built-in types to the global scope. - * - * NOTE: - * This import must come before any imports (direct or transitive) that rely on DOM built-ins being - * available, such as \`@angular/elements\`. - */ - import '@angular/platform-server/init'; - - export { AppServerModule } from './app/app.server.module'; - export { renderModule } from '@angular/platform-server'; - " - `); - }); - it('should add "withServerTransition" call to app module for angular versions lower than 16', async () => { // ARRANGE const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); diff --git a/packages/angular/src/generators/setup-tailwind/__snapshots__/setup-tailwind.application.spec.ts.snap b/packages/angular/src/generators/setup-tailwind/__snapshots__/setup-tailwind.application.spec.ts.snap index 73d6639678152..7f8b05dada36f 100644 --- a/packages/angular/src/generators/setup-tailwind/__snapshots__/setup-tailwind.application.spec.ts.snap +++ b/packages/angular/src/generators/setup-tailwind/__snapshots__/setup-tailwind.application.spec.ts.snap @@ -40,44 +40,3 @@ p { } " `; - -exports[`setupTailwind generator support angular v14 application should add tailwind styles to "apps/app1/src/styles.css" when not provided 1`] = ` -"@tailwind base; -@tailwind components; -@tailwind utilities; - -p { - margin: 0; -} -" -`; - -exports[`setupTailwind generator support angular v14 application should add tailwind styles to "apps/app1/src/styles.less" when not provided 1`] = ` -"@tailwind base; -@tailwind components; -@tailwind utilities; - -p { - margin: 0; -} -" -`; - -exports[`setupTailwind generator support angular v14 application should add tailwind styles to "apps/app1/src/styles.sass" when not provided 1`] = ` -"@tailwind base; -@tailwind components; -@tailwind utilities; - -p { margin: 0; }" -`; - -exports[`setupTailwind generator support angular v14 application should add tailwind styles to "apps/app1/src/styles.scss" when not provided 1`] = ` -"@tailwind base; -@tailwind components; -@tailwind utilities; - -p { - margin: 0; -} -" -`; diff --git a/packages/angular/src/generators/setup-tailwind/setup-tailwind.application.spec.ts b/packages/angular/src/generators/setup-tailwind/setup-tailwind.application.spec.ts index 0c8fef7ffe173..3b3f100d85b1c 100644 --- a/packages/angular/src/generators/setup-tailwind/setup-tailwind.application.spec.ts +++ b/packages/angular/src/generators/setup-tailwind/setup-tailwind.application.spec.ts @@ -4,7 +4,6 @@ import { readJson, readProjectConfiguration, Tree, - updateJson, updateProjectConfiguration, } from '@nx/devkit'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; @@ -441,429 +440,4 @@ describe('setupTailwind generator', () => { expect(devkit.formatFiles).not.toHaveBeenCalled(); }); }); - - describe('support angular v14', () => { - beforeEach(() => { - updateJson(tree, 'package.json', (json) => ({ - ...json, - dependencies: { - ...json.dependencies, - '@angular/core': '14.1.0', - }, - })); - }); - - describe('application', () => { - const project = 'app1'; - - beforeEach(() => { - addProjectConfiguration(tree, project, { - name: project, - projectType: 'application', - root: `apps/${project}`, - sourceRoot: `apps/${project}/src`, - }); - }); - - it('should throw when tailwind is installed as a dependency with a version lower than 2.0.0', async () => { - tree.write( - 'package.json', - JSON.stringify({ dependencies: { tailwindcss: '^1.99.99' } }) - ); - - await expect(setupTailwindGenerator(tree, { project })).rejects.toThrow( - `Tailwind CSS version "^1.99.99" is not supported. Please upgrade to v2.0.0 or higher.` - ); - }); - - it('should throw when tailwind is installed as a devDependency with a version lower than 2.0.0', async () => { - tree.write( - 'package.json', - JSON.stringify({ devDependencies: { tailwindcss: '^1.99.99' } }) - ); - - await expect(setupTailwindGenerator(tree, { project })).rejects.toThrow( - `Tailwind CSS version "^1.99.99" is not supported. Please upgrade to v2.0.0 or higher.` - ); - }); - - it('should throw when there is a tailwind.config.js file in the project', async () => { - tree.write(`apps/${project}/tailwind.config.js`, ''); - - await expect(setupTailwindGenerator(tree, { project })).rejects.toThrow( - expect.objectContaining({ - message: expect.stringContaining( - `The "tailwind.config.js" file already exists in the project "${project}". Are you sure this is the right project to set up Tailwind?` - ), - }) - ); - }); - - it('should throw when the provided styles entry point is not found', async () => { - const stylesEntryPoint = `apps/${project}/src/foo.scss`; - - await expect( - setupTailwindGenerator(tree, { project, stylesEntryPoint }) - ).rejects.toThrow( - `The provided styles entry point "${stylesEntryPoint}" could not be found.` - ); - }); - - it('should throw when the styles entry point is not provided and it is not found', async () => { - await expect(setupTailwindGenerator(tree, { project })).rejects.toThrow( - expect.objectContaining({ - message: expect.stringContaining( - `Could not find a styles entry point for project "${project}"` - ), - }) - ); - }); - - it('should throw when styles is not configured in the build config', async () => { - const projectConfig = readProjectConfiguration(tree, project); - projectConfig.targets = { - build: { - executor: '@nx/angular:webpack-browser', - options: {}, - }, - }; - - await expect(setupTailwindGenerator(tree, { project })).rejects.toThrow( - expect.objectContaining({ - message: expect.stringContaining( - `Could not find a styles entry point for project "${project}"` - ), - }) - ); - }); - - it('should throw when the styles configured in the build config do not exist', async () => { - const stylesEntryPoint = `apps/${project}/src/custom-styles-entry-point.scss`; - const projectConfig = readProjectConfiguration(tree, project); - projectConfig.targets = { - build: { - executor: '@nx/angular:webpack-browser', - options: { - styles: ['node_modules/awesome-ds/styles.css', stylesEntryPoint], - }, - }, - }; - - await expect(setupTailwindGenerator(tree, { project })).rejects.toThrow( - expect.objectContaining({ - message: expect.stringContaining( - `Could not find a styles entry point for project "${project}"` - ), - }) - ); - }); - - it('should throw when no styles within the project root are configured in the build config', async () => { - const projectConfig = readProjectConfiguration(tree, project); - projectConfig.targets = { - build: { - executor: '@nx/angular:webpack-browser', - options: { - styles: ['node_modules/awesome-ds/styles.css'], - }, - }, - }; - - await expect(setupTailwindGenerator(tree, { project })).rejects.toThrow( - expect.objectContaining({ - message: expect.stringContaining( - `Could not find a styles entry point for project "${project}"` - ), - }) - ); - }); - - it('should throw when the style inside the project root specified in the build config as an object has "inject: false"', async () => { - const stylesEntryPoint = `apps/${project}/src/custom-styles-entry-point.scss`; - tree.write(stylesEntryPoint, 'p { margin: 0; }'); - const projectConfig = readProjectConfiguration(tree, project); - projectConfig.targets = { - build: { - executor: '@nx/angular:webpack-browser', - options: { - styles: [ - 'node_modules/awesome-ds/styles.css', - { - bundleName: 'styles.css', - input: stylesEntryPoint, - inject: false, - }, - ], - }, - }, - }; - updateProjectConfiguration(tree, project, projectConfig); - - await expect(setupTailwindGenerator(tree, { project })).rejects.toThrow( - expect.objectContaining({ - message: expect.stringContaining( - `Could not find a styles entry point for project "${project}"` - ), - }) - ); - }); - - it('should add tailwind styles to provided styles entry point', async () => { - const stylesEntryPoint = `apps/${project}/src/custom-styles-entry-point.scss`; - tree.write(stylesEntryPoint, 'p { margin: 0; }'); - - await setupTailwindGenerator(tree, { project, stylesEntryPoint }); - - expect(tree.read(stylesEntryPoint, 'utf-8')).toMatchInlineSnapshot(` - "@tailwind base; - @tailwind components; - @tailwind utilities; - - p { - margin: 0; - } - " - `); - }); - - it.each([ - `apps/${project}/src/styles.css`, - `apps/${project}/src/styles.scss`, - `apps/${project}/src/styles.sass`, - `apps/${project}/src/styles.less`, - ])( - 'should add tailwind styles to "%s" when not provided', - async (stylesEntryPoint) => { - tree.write(stylesEntryPoint, 'p { margin: 0; }'); - - await setupTailwindGenerator(tree, { project }); - - expect(tree.read(stylesEntryPoint, 'utf-8')).toMatchSnapshot(); - } - ); - - it('should add tailwind styles to the first style inside the project root specified in the build config as a string', async () => { - const stylesEntryPoint = `apps/${project}/src/custom-styles-entry-point.scss`; - tree.write(stylesEntryPoint, 'p { margin: 0; }'); - const projectConfig = readProjectConfiguration(tree, project); - projectConfig.targets = { - build: { - executor: '@nx/angular:webpack-browser', - options: { - styles: ['node_modules/awesome-ds/styles.css', stylesEntryPoint], - }, - }, - }; - updateProjectConfiguration(tree, project, projectConfig); - - await setupTailwindGenerator(tree, { project }); - - expect(tree.read(stylesEntryPoint, 'utf-8')).toMatchInlineSnapshot(` - "@tailwind base; - @tailwind components; - @tailwind utilities; - - p { - margin: 0; - } - " - `); - }); - - it('should add tailwind styles to the first style inside the project root specified in the build config as an object when inject is not specified', async () => { - const stylesEntryPoint = `apps/${project}/src/custom-styles-entry-point.scss`; - tree.write(stylesEntryPoint, 'p { margin: 0; }'); - const projectConfig = readProjectConfiguration(tree, project); - projectConfig.targets = { - build: { - executor: '@nx/angular:webpack-browser', - options: { - styles: [ - 'node_modules/awesome-ds/styles.css', - { - bundleName: 'styles.css', - input: stylesEntryPoint, - }, - ], - }, - }, - }; - updateProjectConfiguration(tree, project, projectConfig); - - await setupTailwindGenerator(tree, { project }); - - expect(tree.read(stylesEntryPoint, 'utf-8')).toMatchInlineSnapshot(` - "@tailwind base; - @tailwind components; - @tailwind utilities; - - p { - margin: 0; - } - " - `); - }); - - it('should add tailwind styles to the first style inside the project root specified in the build config as an object when "inject: true"', async () => { - const stylesEntryPoint = `apps/${project}/src/custom-styles-entry-point.scss`; - tree.write(stylesEntryPoint, 'p { margin: 0; }'); - const projectConfig = readProjectConfiguration(tree, project); - projectConfig.targets = { - build: { - executor: '@nx/angular:webpack-browser', - options: { - styles: [ - 'node_modules/awesome-ds/styles.css', - { - bundleName: 'styles.css', - input: stylesEntryPoint, - inject: true, - }, - ], - }, - }, - }; - updateProjectConfiguration(tree, project, projectConfig); - - await setupTailwindGenerator(tree, { project }); - - expect(tree.read(stylesEntryPoint, 'utf-8')).toMatchInlineSnapshot(` - "@tailwind base; - @tailwind components; - @tailwind utilities; - - p { - margin: 0; - } - " - `); - }); - - it('should add required packages', async () => { - const stylesEntryPoint = `apps/${project}/src/styles.scss`; - tree.write(stylesEntryPoint, 'p { margin: 0; }'); - - await setupTailwindGenerator(tree, { project, stylesEntryPoint }); - - const { devDependencies } = readJson(tree, 'package.json'); - expect(devDependencies.tailwindcss).toBe(tailwindVersion); - expect(devDependencies.autoprefixer).toBe(autoprefixerVersion); - expect(devDependencies.postcss).toBe(postcssVersion); - }); - - it('should generate the tailwind.config.js file in the project root with the config for v3 by default', async () => { - const stylesEntryPoint = `apps/${project}/src/styles.scss`; - tree.write(stylesEntryPoint, 'p { margin: 0; }'); - - await setupTailwindGenerator(tree, { project, stylesEntryPoint }); - - expect(tree.read(`apps/${project}/tailwind.config.js`, 'utf-8')) - .toMatchInlineSnapshot(` - "const { createGlobPatternsForDependencies } = require('@nx/angular/tailwind'); - const { join } = require('path'); - - /** @type {import('tailwindcss').Config} */ - module.exports = { - content: [ - join(__dirname, 'src/**/!(*.stories|*.spec).{ts,html}'), - ...createGlobPatternsForDependencies(__dirname), - ], - theme: { - extend: {}, - }, - plugins: [], - }; - " - `); - }); - - it('should generate the tailwind.config.js file in the project root with the config for v3 when a version greater than 3 is installed', async () => { - const stylesEntryPoint = `apps/${project}/src/styles.scss`; - tree.write(stylesEntryPoint, 'p { margin: 0; }'); - tree.write( - 'package.json', - JSON.stringify({ devDependencies: { tailwindcss: '^3.0.1' } }) - ); - - await setupTailwindGenerator(tree, { project, stylesEntryPoint }); - - expect(tree.read(`apps/${project}/tailwind.config.js`, 'utf-8')) - .toMatchInlineSnapshot(` - "const { createGlobPatternsForDependencies } = require('@nx/angular/tailwind'); - const { join } = require('path'); - - /** @type {import('tailwindcss').Config} */ - module.exports = { - content: [ - join(__dirname, 'src/**/!(*.stories|*.spec).{ts,html}'), - ...createGlobPatternsForDependencies(__dirname), - ], - theme: { - extend: {}, - }, - plugins: [], - }; - " - `); - }); - - it('should generate the tailwind.config.js file in the project root with the config for v2 when a version greater than 2 and lower than 3 is installed', async () => { - const stylesEntryPoint = `apps/${project}/src/styles.scss`; - tree.write(stylesEntryPoint, 'p { margin: 0; }'); - tree.write( - 'package.json', - JSON.stringify({ devDependencies: { tailwindcss: '~2.0.0' } }) - ); - - await setupTailwindGenerator(tree, { project, stylesEntryPoint }); - - expect(tree.read(`apps/${project}/tailwind.config.js`, 'utf-8')) - .toMatchInlineSnapshot(` - "const { createGlobPatternsForDependencies } = require('@nx/angular/tailwind'); - const { join } = require('path'); - - module.exports = { - mode: 'jit', - purge: [ - join(__dirname, 'src/**/!(*.stories|*.spec).{ts,html}'), - ...createGlobPatternsForDependencies(__dirname), - ], - darkMode: false, // or 'media' or 'class' - theme: { - extend: {}, - }, - variants: { - extend: {}, - }, - plugins: [], - }; - " - `); - }); - - it('should format files', async () => { - const stylesEntryPoint = `apps/${project}/src/styles.scss`; - tree.write(stylesEntryPoint, 'p { margin: 0; }'); - jest.spyOn(devkit, 'formatFiles'); - - await setupTailwindGenerator(tree, { project, stylesEntryPoint }); - - expect(devkit.formatFiles).toHaveBeenCalled(); - }); - - it('should not format files when "skipFormat: true"', async () => { - const stylesEntryPoint = `apps/${project}/src/styles.scss`; - tree.write(stylesEntryPoint, 'p { margin: 0; }'); - jest.spyOn(devkit, 'formatFiles'); - - await setupTailwindGenerator(tree, { - project, - stylesEntryPoint, - skipFormat: true, - }); - - expect(devkit.formatFiles).not.toHaveBeenCalled(); - }); - }); - }); }); diff --git a/packages/angular/src/generators/setup-tailwind/setup-tailwind.library.spec.ts b/packages/angular/src/generators/setup-tailwind/setup-tailwind.library.spec.ts index 2cd30a6277085..08e746cf3835d 100644 --- a/packages/angular/src/generators/setup-tailwind/setup-tailwind.library.spec.ts +++ b/packages/angular/src/generators/setup-tailwind/setup-tailwind.library.spec.ts @@ -4,7 +4,6 @@ import { readJson, readProjectConfiguration, Tree, - updateJson, updateProjectConfiguration, } from '@nx/devkit'; import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; @@ -312,300 +311,4 @@ describe('setupTailwind generator', () => { expect(devkit.formatFiles).not.toHaveBeenCalled(); }); }); - - describe('support angular v14', () => { - beforeEach(() => { - updateJson(tree, 'package.json', (json) => ({ - ...json, - dependencies: { - ...json.dependencies, - '@angular/core': '14.1.0', - }, - })); - }); - - describe('libraries', () => { - const project = 'lib1'; - - beforeEach(() => { - addProjectConfiguration(tree, project, { - name: project, - projectType: 'library', - root: `libs/${project}`, - sourceRoot: `libs/${project}/src`, - }); - }); - - it('should throw when tailwind is installed as a dependency with a version lower than 2.0.0', async () => { - tree.write( - 'package.json', - JSON.stringify({ dependencies: { tailwindcss: '^1.99.99' } }) - ); - - await expect(setupTailwindGenerator(tree, { project })).rejects.toThrow( - `Tailwind CSS version "^1.99.99" is not supported. Please upgrade to v2.0.0 or higher.` - ); - }); - - it('should throw when tailwind is installed as a devDependency with a version lower than 2.0.0', async () => { - tree.write( - 'package.json', - JSON.stringify({ devDependencies: { tailwindcss: '^1.99.99' } }) - ); - - await expect(setupTailwindGenerator(tree, { project })).rejects.toThrow( - `Tailwind CSS version "^1.99.99" is not supported. Please upgrade to v2.0.0 or higher.` - ); - }); - - it('should throw when the build target is not found', async () => { - await expect(setupTailwindGenerator(tree, { project })).rejects.toThrow( - expect.objectContaining({ - message: expect.stringContaining( - `The target "build" was not found for project "${project}".` - ), - }) - ); - }); - - it('should throw when the specified build target is not found', async () => { - await expect( - setupTailwindGenerator(tree, { project, buildTarget: 'custom-build' }) - ).rejects.toThrow( - expect.objectContaining({ - message: expect.stringContaining( - `The target "custom-build" was not found for project "${project}".` - ), - }) - ); - }); - - it('should throw when the build target is using an unsupported executor', async () => { - const projectConfig = readProjectConfiguration(tree, project); - projectConfig.targets = { - build: { - executor: '@angular/build-angular:browser', - options: {}, - }, - }; - updateProjectConfiguration(tree, project, projectConfig); - - await expect(setupTailwindGenerator(tree, { project })).rejects.toThrow( - expect.objectContaining({ - message: expect.stringContaining( - `The build target for project "${project}" is using an unsupported executor "@angular/build-angular:browser".` - ), - }) - ); - }); - - it('should throw when the tailwind config is configured in the build target and the file it points to exists', async () => { - const tailwindConfig = `libs/${project}/my-tailwind.config.js`; - let projectConfig = readProjectConfiguration(tree, project); - projectConfig.targets = { - build: { - executor: '@nx/angular:package', - options: { tailwindConfig }, - }, - }; - updateProjectConfiguration(tree, project, projectConfig); - tree.write(tailwindConfig, ''); - - await expect(setupTailwindGenerator(tree, { project })).rejects.toThrow( - expect.objectContaining({ - message: expect.stringContaining( - `The "${tailwindConfig}" file is already configured for the project "${project}". Are you sure this is the right project to set up Tailwind?` - ), - }) - ); - }); - - it('should add the tailwind config path to the "build" target by default when no build target is specified', async () => { - let projectConfig = readProjectConfiguration(tree, project); - projectConfig.targets = { - build: { executor: '@nx/angular:package', options: {} }, - }; - updateProjectConfiguration(tree, project, projectConfig); - - await setupTailwindGenerator(tree, { project }); - - projectConfig = readProjectConfiguration(tree, project); - expect(projectConfig.targets.build.options.tailwindConfig).toBe( - `libs/${project}/tailwind.config.js` - ); - }); - - it('should add the tailwind config path to the specified buildTarget', async () => { - const buildTarget = 'custom-build'; - let projectConfig = readProjectConfiguration(tree, project); - projectConfig.targets = { - [buildTarget]: { executor: '@nx/angular:package', options: {} }, - }; - updateProjectConfiguration(tree, project, projectConfig); - - await setupTailwindGenerator(tree, { project, buildTarget }); - - projectConfig = readProjectConfiguration(tree, project); - expect(projectConfig.targets[buildTarget].options.tailwindConfig).toBe( - `libs/${project}/tailwind.config.js` - ); - }); - - it.each(['@nx/angular:ng-packagr-lite', '@nx/angular:package'])( - 'should add the tailwind config path when using the "%s" executor', - async (executor) => { - let projectConfig = readProjectConfiguration(tree, project); - projectConfig.targets = { build: { executor, options: {} } }; - updateProjectConfiguration(tree, project, projectConfig); - - await setupTailwindGenerator(tree, { project }); - - projectConfig = readProjectConfiguration(tree, project); - expect(projectConfig.targets.build.options.tailwindConfig).toBe( - `libs/${project}/tailwind.config.js` - ); - } - ); - - it('should add required packages', async () => { - const projectConfig = readProjectConfiguration(tree, project); - projectConfig.targets = { - build: { executor: '@nx/angular:package', options: {} }, - }; - updateProjectConfiguration(tree, project, projectConfig); - - await setupTailwindGenerator(tree, { project }); - - const { devDependencies } = readJson(tree, 'package.json'); - expect(devDependencies.tailwindcss).toBe(tailwindVersion); - expect(devDependencies.autoprefixer).toBe(autoprefixerVersion); - expect(devDependencies.postcss).toBe(postcssVersion); - }); - - it('should generate the tailwind.config.js file in the project root for v3 by default', async () => { - const projectConfig = readProjectConfiguration(tree, project); - projectConfig.targets = { - build: { executor: '@nx/angular:package', options: {} }, - }; - updateProjectConfiguration(tree, project, projectConfig); - - await setupTailwindGenerator(tree, { project }); - - expect(tree.read(`libs/${project}/tailwind.config.js`, 'utf-8')) - .toMatchInlineSnapshot(` - "const { createGlobPatternsForDependencies } = require('@nx/angular/tailwind'); - const { join } = require('path'); - - /** @type {import('tailwindcss').Config} */ - module.exports = { - content: [ - join(__dirname, 'src/**/!(*.stories|*.spec).{ts,html}'), - ...createGlobPatternsForDependencies(__dirname), - ], - theme: { - extend: {}, - }, - plugins: [], - }; - " - `); - }); - - it('should generate the tailwind.config.js file in the project root with the config for v3 when a version greater than 3 is installed', async () => { - const projectConfig = readProjectConfiguration(tree, project); - projectConfig.targets = { - build: { executor: '@nx/angular:package', options: {} }, - }; - updateProjectConfiguration(tree, project, projectConfig); - tree.write( - 'package.json', - JSON.stringify({ devDependencies: { tailwindcss: '^3.0.1' } }) - ); - - await setupTailwindGenerator(tree, { project }); - - expect(tree.read(`libs/${project}/tailwind.config.js`, 'utf-8')) - .toMatchInlineSnapshot(` - "const { createGlobPatternsForDependencies } = require('@nx/angular/tailwind'); - const { join } = require('path'); - - /** @type {import('tailwindcss').Config} */ - module.exports = { - content: [ - join(__dirname, 'src/**/!(*.stories|*.spec).{ts,html}'), - ...createGlobPatternsForDependencies(__dirname), - ], - theme: { - extend: {}, - }, - plugins: [], - }; - " - `); - }); - - it('should generate the tailwind.config.js file in the project root with the config for v2 when a version greater than 2 and lower than 3 is installed', async () => { - const projectConfig = readProjectConfiguration(tree, project); - projectConfig.targets = { - build: { executor: '@nx/angular:package', options: {} }, - }; - updateProjectConfiguration(tree, project, projectConfig); - tree.write( - 'package.json', - JSON.stringify({ devDependencies: { tailwindcss: '~2.0.0' } }) - ); - - await setupTailwindGenerator(tree, { project }); - - expect(tree.read(`libs/${project}/tailwind.config.js`, 'utf-8')) - .toMatchInlineSnapshot(` - "const { createGlobPatternsForDependencies } = require('@nx/angular/tailwind'); - const { join } = require('path'); - - module.exports = { - mode: 'jit', - purge: [ - join(__dirname, 'src/**/!(*.stories|*.spec).{ts,html}'), - ...createGlobPatternsForDependencies(__dirname), - ], - darkMode: false, // or 'media' or 'class' - theme: { - extend: {}, - }, - variants: { - extend: {}, - }, - plugins: [], - }; - " - `); - }); - - it('should format files', async () => { - const projectConfig = readProjectConfiguration(tree, project); - projectConfig.targets = { - build: { executor: '@nx/angular:package', options: {} }, - }; - updateProjectConfiguration(tree, project, projectConfig); - jest.spyOn(devkit, 'formatFiles'); - - await setupTailwindGenerator(tree, { project }); - - expect(devkit.formatFiles).toHaveBeenCalled(); - }); - - it('should not format files when "skipFormat: true"', async () => { - const projectConfig = readProjectConfiguration(tree, project); - projectConfig.targets = { - build: { executor: '@nx/angular:package', options: {} }, - }; - updateProjectConfiguration(tree, project, projectConfig); - jest.spyOn(devkit, 'formatFiles'); - - await setupTailwindGenerator(tree, { project, skipFormat: true }); - - expect(devkit.formatFiles).not.toHaveBeenCalled(); - }); - }); - }); }); diff --git a/packages/angular/src/generators/utils/create-ts-config.ts b/packages/angular/src/generators/utils/create-ts-config.ts index 9b4d62469f22b..003281b8a38de 100644 --- a/packages/angular/src/generators/utils/create-ts-config.ts +++ b/packages/angular/src/generators/utils/create-ts-config.ts @@ -1,7 +1,6 @@ import type { Tree } from '@nx/devkit'; import { writeJson } from '@nx/devkit'; import { tsConfigBaseOptions } from '@nx/js'; -import { getInstalledAngularMajorVersion } from './version-utils'; export { extractTsConfigBase } from '@nx/js'; @@ -17,11 +16,9 @@ export function createTsConfig( }, relativePathToRootTsConfig: string ) { - const majorAngularVersion = getInstalledAngularMajorVersion(host); - const json = { compilerOptions: { - target: majorAngularVersion === 14 ? 'es2020' : 'es2022', + target: 'es2022', useDefineForClassFields: false, }, files: [], diff --git a/packages/angular/src/generators/utils/validations.ts b/packages/angular/src/generators/utils/validations.ts index 2462e0681579a..0a0ee0766949f 100644 --- a/packages/angular/src/generators/utils/validations.ts +++ b/packages/angular/src/generators/utils/validations.ts @@ -1,7 +1,5 @@ import type { Tree } from '@nx/devkit'; -import { getProjects, stripIndents } from '@nx/devkit'; -import { lt } from 'semver'; -import { getInstalledAngularVersionInfo } from './version-utils'; +import { getProjects } from '@nx/devkit'; export function validateProject(tree: Tree, projectName: string): void { const projects = getProjects(tree); @@ -12,21 +10,3 @@ export function validateProject(tree: Tree, projectName: string): void { ); } } - -export function validateStandaloneOption( - tree: Tree, - standalone: boolean | undefined, - angularVersion?: string -): void { - if (!standalone) { - return; - } - - const installedAngularVersion = - angularVersion ?? getInstalledAngularVersionInfo(tree).version; - - if (lt(installedAngularVersion, '14.1.0')) { - throw new Error(stripIndents`The "standalone" option is only supported in Angular >= 14.1.0. You are currently using "${installedAngularVersion}". - You can resolve this error by removing the "standalone" option or by migrating to Angular 14.1.0.`); - } -} diff --git a/packages/angular/src/generators/utils/version-utils.spec.ts b/packages/angular/src/generators/utils/version-utils.spec.ts index 4bfc240f9dce0..cc8df006c6122 100644 --- a/packages/angular/src/generators/utils/version-utils.spec.ts +++ b/packages/angular/src/generators/utils/version-utils.spec.ts @@ -6,7 +6,7 @@ import { } from './version-utils'; describe('angularVersionUtils', () => { - test.each(['14.0.0', '~14.1.0', '^14.2.0', '~14.3.0-beta.0'])( + test.each(['15.0.0', '~15.1.0', '^15.2.0', '~15.3.0-beta.0'])( 'should return correct major version', (ngVersion) => { // ARRANGE @@ -22,15 +22,15 @@ describe('angularVersionUtils', () => { const angularVersion = getInstalledAngularMajorVersion(tree); // ASSERT - expect(angularVersion).toBe(14); + expect(angularVersion).toBe(15); } ); test.each([ - ['14.0.0', '14.0.0'], - ['~14.1.0', '14.1.0'], - ['^14.2.0', '14.2.0'], - ['~14.3.0-beta.0', '14.3.0'], + ['15.0.0', '15.0.0'], + ['~15.1.0', '15.1.0'], + ['^15.2.0', '15.2.0'], + ['~15.3.0-beta.0', '15.3.0'], ])('should return correct major version', (ngVersion, expectedVersion) => { // ARRANGE const tree = createTreeWithEmptyWorkspace(); diff --git a/packages/angular/src/generators/utils/version-utils.ts b/packages/angular/src/generators/utils/version-utils.ts index ebdd5c3fd45dc..8905bd240830a 100644 --- a/packages/angular/src/generators/utils/version-utils.ts +++ b/packages/angular/src/generators/utils/version-utils.ts @@ -85,8 +85,6 @@ export function addDependenciesToPackageJsonIfDontExist( export function versions(tree: Tree) { const majorAngularVersion = getInstalledAngularMajorVersion(tree); switch (majorAngularVersion) { - case 14: - return backwardCompatibleVersions.angularV14; case 15: return backwardCompatibleVersions.angularV15; case 16: diff --git a/packages/angular/src/utils/backward-compatible-versions.ts b/packages/angular/src/utils/backward-compatible-versions.ts index 4eacce1f6ab67..ff0e2bf8bd5c6 100644 --- a/packages/angular/src/utils/backward-compatible-versions.ts +++ b/packages/angular/src/utils/backward-compatible-versions.ts @@ -1,6 +1,6 @@ import * as latestVersions from './versions'; -type SupportedVersions = 'angularV14' | 'angularV15' | 'angularV16'; +type SupportedVersions = 'angularV15' | 'angularV16'; export type PackageVersionNames = Exclude< keyof typeof latestVersions, 'nxVersion' @@ -11,34 +11,6 @@ export const backwardCompatibleVersions: Record< SupportedVersions, PackageVersions > = { - angularV14: { - angularVersion: '~14.2.0', - angularDevkitVersion: '~14.2.0', - ngPackagrVersion: '~14.2.0', - ngrxVersion: '~14.0.0', - rxjsVersion: '~7.8.0', - zoneJsVersion: '~0.11.4', - angularJsVersion: '1.7.9', - tsLibVersion: '^2.3.0', - ngUniversalVersion: '~14.2.0', - corsVersion: '~2.8.5', - typesCorsVersion: '~2.8.5', - expressVersion: '~4.18.2', - typesExpressVersion: '4.17.14', - moduleFederationNodeVersion: '~1.0.5', - angularEslintVersion: '~14.0.4', - tailwindVersion: '^3.0.2', - postcssVersion: '^8.4.5', - postcssImportVersion: '~14.1.0', - postcssPresetEnvVersion: '~7.5.0', - postcssUrlVersion: '~10.1.3', - autoprefixerVersion: '^10.4.0', - tsNodeVersion: '10.9.1', - jestPresetAngularVersion: '~12.2.3', - typesNodeVersion: '16.11.7', - jasmineMarblesVersion: '^0.9.2', - jsoncEslintParserVersion: '^2.1.0', - }, angularV15: { angularVersion: '~15.2.0', angularDevkitVersion: '~15.2.0', diff --git a/packages/nx/src/command-line/init/implementation/angular/legacy-angular-versions.ts b/packages/nx/src/command-line/init/implementation/angular/legacy-angular-versions.ts index e5888f27d99fa..00b9909b04847 100644 --- a/packages/nx/src/command-line/init/implementation/angular/legacy-angular-versions.ts +++ b/packages/nx/src/command-line/init/implementation/angular/legacy-angular-versions.ts @@ -16,9 +16,11 @@ import type { Options } from './types'; // map of Angular major versions to Nx versions to use for legacy `nx init` migrations, // key is major Angular version and value is Nx version to use -const nxAngularLegacyVersionMap: Record = {}; +const nxAngularLegacyVersionMap: Record = { + 14: '~17.1.0', +}; // min major angular version supported in latest Nx -const minMajorAngularVersionSupported = 14; +const minMajorAngularVersionSupported = 15; // version when the Nx CLI changed from @nrwl/tao & @nrwl/cli to nx const versionWithConsolidatedPackages = '13.9.0'; // version when packages were rescoped from @nrwl/* to @nx/* diff --git a/packages/nx/src/command-line/init/implementation/angular/standalone-workspace.ts b/packages/nx/src/command-line/init/implementation/angular/standalone-workspace.ts index 443c69c3a5755..4fb909600de14 100644 --- a/packages/nx/src/command-line/init/implementation/angular/standalone-workspace.ts +++ b/packages/nx/src/command-line/init/implementation/angular/standalone-workspace.ts @@ -138,7 +138,7 @@ function createNxJson( inputs: ['default', '^production'], }; } - // Angular 14 workspaces support defaultProject, keep it until we drop support + // Angular 15 workspaces still support defaultProject. Support was removed in Angular 16. nxJson.defaultProject = angularJson.defaultProject; writeJsonFile(join(repoRoot, 'nx.json'), nxJson); }