From 2673ef10901e531d6d65615c3b28e323235f8d0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Fri, 10 May 2024 14:50:21 +0200 Subject: [PATCH] feat(angular): remove angular v15 support (#23301) ## Current Behavior ## Expected Behavior ## Related Issue(s) Fixes # --- docs/generated/manifests/nx-api.json | 2 +- docs/generated/packages-metadata.json | 2 +- .../angular/executors/ng-packagr-lite.json | 4 +- .../angular/executors/webpack-server.json | 6 +- .../angular/generators/setup-ssr.json | 4 +- packages/angular/executors.json | 2 +- packages/angular/package.json | 8 +- .../src/builders/webpack-server/schema.json | 6 +- .../webpack-server/validate-options.ts | 40 -------- .../webpack-server/webpack-server.impl.ts | 5 +- .../entry-point/write-package.transform.ts | 6 -- .../src/executors/ng-packagr-lite/schema.json | 2 +- .../__snapshots__/application.spec.ts.snap | 2 +- .../application/application.spec.ts | 8 +- .../src/app/app.config.ts__tpl__ | 2 +- .../angular/src/generators/ngrx/ngrx.spec.ts | 18 ++-- .../ngmodule/pre-v15-2/src/main.ts__tpl__ | 14 --- .../files/ngmodule/{base => }/src/__main__ | 0 .../{base => }/src/app/__rootModuleFileName__ | 0 .../setup-ssr/lib/generate-files.ts | 14 +-- .../src/generators/setup-ssr/lib/index.ts | 1 - .../setup-ssr/lib/update-app-module.ts | 47 --------- .../setup-ssr/lib/validate-options.ts | 18 +--- .../src/generators/setup-ssr/schema.json | 4 +- .../generators/setup-ssr/setup-ssr.spec.ts | 99 +++---------------- .../src/generators/setup-ssr/setup-ssr.ts | 4 - .../src/generators/utils/version-utils.ts | 4 +- .../src/utils/backward-compatible-versions.ts | 22 ++--- .../angular/legacy-angular-versions.ts | 3 +- .../angular/standalone-workspace.ts | 2 - 30 files changed, 64 insertions(+), 285 deletions(-) delete mode 100644 packages/angular/src/builders/webpack-server/validate-options.ts delete mode 100644 packages/angular/src/generators/setup-ssr/files/ngmodule/pre-v15-2/src/main.ts__tpl__ rename packages/angular/src/generators/setup-ssr/files/ngmodule/{base => }/src/__main__ (100%) rename packages/angular/src/generators/setup-ssr/files/ngmodule/{base => }/src/app/__rootModuleFileName__ (100%) delete mode 100644 packages/angular/src/generators/setup-ssr/lib/update-app-module.ts diff --git a/docs/generated/manifests/nx-api.json b/docs/generated/manifests/nx-api.json index ce544edfe38083..5acb369ee33d04 100644 --- a/docs/generated/manifests/nx-api.json +++ b/docs/generated/manifests/nx-api.json @@ -63,7 +63,7 @@ "type": "executor" }, "/nx-api/angular/executors/ng-packagr-lite": { - "description": "Builds an Angular library with support for incremental builds.\n\nThis executor is meant to be used with buildable libraries in an incremental build scenario. It is similar to the `@nx/angular:package` executor but with some key differences:\n- For supported Angular versions lower than v16, it doesn't run `ngcc` automatically (`ngcc` is no longer available from Angular v16 onwards, for lower versions, it needs to be run separately beforehand if needed, this can be done in a `postinstall` hook on `package.json`).\n- It only produces ESM2022 bundles (ESM2020 for supported Angular versions lower than v16).", + "description": "Builds an Angular library with support for incremental builds.\n\nThis executor is meant to be used with buildable libraries in an incremental build scenario. It is similar to the `@nx/angular:package` executor but it only produces ESM2022 bundles.", "file": "generated/packages/angular/executors/ng-packagr-lite.json", "hidden": false, "name": "ng-packagr-lite", diff --git a/docs/generated/packages-metadata.json b/docs/generated/packages-metadata.json index e508db9895a377..20da3c9e981883 100644 --- a/docs/generated/packages-metadata.json +++ b/docs/generated/packages-metadata.json @@ -58,7 +58,7 @@ "type": "executor" }, { - "description": "Builds an Angular library with support for incremental builds.\n\nThis executor is meant to be used with buildable libraries in an incremental build scenario. It is similar to the `@nx/angular:package` executor but with some key differences:\n- For supported Angular versions lower than v16, it doesn't run `ngcc` automatically (`ngcc` is no longer available from Angular v16 onwards, for lower versions, it needs to be run separately beforehand if needed, this can be done in a `postinstall` hook on `package.json`).\n- It only produces ESM2022 bundles (ESM2020 for supported Angular versions lower than v16).", + "description": "Builds an Angular library with support for incremental builds.\n\nThis executor is meant to be used with buildable libraries in an incremental build scenario. It is similar to the `@nx/angular:package` executor but it only produces ESM2022 bundles.", "file": "generated/packages/angular/executors/ng-packagr-lite.json", "hidden": false, "name": "ng-packagr-lite", diff --git a/docs/generated/packages/angular/executors/ng-packagr-lite.json b/docs/generated/packages/angular/executors/ng-packagr-lite.json index 048e94ac6a7b97..55f2797bfe1d81 100644 --- a/docs/generated/packages/angular/executors/ng-packagr-lite.json +++ b/docs/generated/packages/angular/executors/ng-packagr-lite.json @@ -6,7 +6,7 @@ "outputCapture": "direct-nodejs", "$schema": "https://json-schema.org/schema", "title": "ng-packagr Target", - "description": "Builds an Angular library with support for incremental builds.\n\nThis executor is meant to be used with buildable libraries in an incremental build scenario. It is similar to the `@nx/angular:package` executor but with some key differences:\n- For supported Angular versions lower than v16, it doesn't run `ngcc` automatically (`ngcc` is no longer available from Angular v16 onwards, for lower versions, it needs to be run separately beforehand if needed, this can be done in a `postinstall` hook on `package.json`).\n- It only produces ESM2022 bundles (ESM2020 for supported Angular versions lower than v16).", + "description": "Builds an Angular library with support for incremental builds.\n\nThis executor is meant to be used with buildable libraries in an incremental build scenario. It is similar to the `@nx/angular:package` executor but it only produces ESM2022 bundles.", "cli": "nx", "type": "object", "presets": [ @@ -44,7 +44,7 @@ "additionalProperties": false, "required": ["project"] }, - "description": "Builds an Angular library with support for incremental builds.\n\nThis executor is meant to be used with buildable libraries in an incremental build scenario. It is similar to the `@nx/angular:package` executor but with some key differences:\n- For supported Angular versions lower than v16, it doesn't run `ngcc` automatically (`ngcc` is no longer available from Angular v16 onwards, for lower versions, it needs to be run separately beforehand if needed, this can be done in a `postinstall` hook on `package.json`).\n- It only produces ESM2022 bundles (ESM2020 for supported Angular versions lower than v16).", + "description": "Builds an Angular library with support for incremental builds.\n\nThis executor is meant to be used with buildable libraries in an incremental build scenario. It is similar to the `@nx/angular:package` executor but it only produces ESM2022 bundles.", "aliases": [], "hidden": false, "path": "/packages/angular/src/executors/ng-packagr-lite/schema.json", diff --git a/docs/generated/packages/angular/executors/webpack-server.json b/docs/generated/packages/angular/executors/webpack-server.json index 990a28a11183e7..22a391b7202ae9 100644 --- a/docs/generated/packages/angular/executors/webpack-server.json +++ b/docs/generated/packages/angular/executors/webpack-server.json @@ -11,7 +11,7 @@ "properties": { "assets": { "type": "array", - "description": "List of static application assets. _Note: only supported in Angular versions >= 15.1.0_", + "description": "List of static application assets.", "default": [], "items": { "oneOf": [ @@ -187,7 +187,7 @@ }, "vendorChunk": { "type": "boolean", - "description": "Generate a separate bundle containing only vendor libraries. This option should only be used for development to reduce the incremental compilation time. _Note: supported in Angular versions >= 15.1.0_", + "description": "Generate a separate bundle containing only vendor libraries. This option should only be used for development to reduce the incremental compilation time.", "default": false }, "verbose": { @@ -249,7 +249,7 @@ }, "buildOptimizer": { "type": "boolean", - "description": "Enables advanced build optimizations. _Note: only supported in Angular versions >= 16.0.0_.", + "description": "Enables advanced build optimizations.", "default": true }, "namedChunks": { diff --git a/docs/generated/packages/angular/generators/setup-ssr.json b/docs/generated/packages/angular/generators/setup-ssr.json index 60469d53069cf4..2d2013f2b160e3 100644 --- a/docs/generated/packages/angular/generators/setup-ssr.json +++ b/docs/generated/packages/angular/generators/setup-ssr.json @@ -19,7 +19,7 @@ "appId": { "type": "string", "format": "html-selector", - "description": "The `appId` to use with `withServerTransition`. _Note: This is only used in Angular versions <16.0.0. It's deprecated since Angular 16 and not supported since Angular 17._", + "description": "The `appId` to use with `withServerTransition`. _Note: This is deprecated and ignored since Angular 16 and not supported since Angular 17._", "default": "serverApp" }, "main": { @@ -55,7 +55,7 @@ }, "hydration": { "type": "boolean", - "description": "Set up Hydration for the SSR application. It defaults to `true` for Angular versions >= 17.0.0. Otherwise, it defaults to `false`. _Note: This is only supported in Angular versions >= 16.0.0_." + "description": "Set up Hydration for the SSR application. It defaults to `true` for Angular versions >= 17.0.0. Otherwise, it defaults to `false`." }, "skipFormat": { "type": "boolean", diff --git a/packages/angular/executors.json b/packages/angular/executors.json index 7d0df96c13cb33..ea2b1a6bb2a64b 100644 --- a/packages/angular/executors.json +++ b/packages/angular/executors.json @@ -8,7 +8,7 @@ "ng-packagr-lite": { "implementation": "./src/executors/ng-packagr-lite/ng-packagr-lite.impl", "schema": "./src/executors/ng-packagr-lite/schema.json", - "description": "Builds an Angular library with support for incremental builds.\n\nThis executor is meant to be used with buildable libraries in an incremental build scenario. It is similar to the `@nx/angular:package` executor but with some key differences:\n- For supported Angular versions lower than v16, it doesn't run `ngcc` automatically (`ngcc` is no longer available from Angular v16 onwards, for lower versions, it needs to be run separately beforehand if needed, this can be done in a `postinstall` hook on `package.json`).\n- It only produces ESM2022 bundles (ESM2020 for supported Angular versions lower than v16)." + "description": "Builds an Angular library with support for incremental builds.\n\nThis executor is meant to be used with buildable libraries in an incremental build scenario. It is similar to the `@nx/angular:package` executor but it only produces ESM2022 bundles." }, "package": { "implementation": "./src/executors/package/package.impl", diff --git a/packages/angular/package.json b/packages/angular/package.json index 474eac86de09c8..fe226536c743e3 100644 --- a/packages/angular/package.json +++ b/packages/angular/package.json @@ -66,10 +66,10 @@ "piscina": "^4.4.0" }, "peerDependencies": { - "@angular-devkit/build-angular": ">= 15.0.0 < 18.0.0", - "@angular-devkit/core": ">= 15.0.0 < 18.0.0", - "@angular-devkit/schematics": ">= 15.0.0 < 18.0.0", - "@schematics/angular": ">= 15.0.0 < 18.0.0", + "@angular-devkit/build-angular": ">= 16.0.0 < 19.0.0", + "@angular-devkit/core": ">= 16.0.0 < 19.0.0", + "@angular-devkit/schematics": ">= 16.0.0 < 19.0.0", + "@schematics/angular": ">= 16.0.0 < 19.0.0", "esbuild": "^0.19.2", "rxjs": "^6.5.3 || ^7.5.0" }, diff --git a/packages/angular/src/builders/webpack-server/schema.json b/packages/angular/src/builders/webpack-server/schema.json index 01d3042d7507a6..19027f6da277ed 100644 --- a/packages/angular/src/builders/webpack-server/schema.json +++ b/packages/angular/src/builders/webpack-server/schema.json @@ -8,7 +8,7 @@ "properties": { "assets": { "type": "array", - "description": "List of static application assets. _Note: only supported in Angular versions >= 15.1.0_", + "description": "List of static application assets.", "default": [], "items": { "$ref": "#/definitions/assetPattern" @@ -127,7 +127,7 @@ }, "vendorChunk": { "type": "boolean", - "description": "Generate a separate bundle containing only vendor libraries. This option should only be used for development to reduce the incremental compilation time. _Note: supported in Angular versions >= 15.1.0_", + "description": "Generate a separate bundle containing only vendor libraries. This option should only be used for development to reduce the incremental compilation time.", "default": false }, "verbose": { @@ -192,7 +192,7 @@ }, "buildOptimizer": { "type": "boolean", - "description": "Enables advanced build optimizations. _Note: only supported in Angular versions >= 16.0.0_.", + "description": "Enables advanced build optimizations.", "default": true }, "namedChunks": { diff --git a/packages/angular/src/builders/webpack-server/validate-options.ts b/packages/angular/src/builders/webpack-server/validate-options.ts deleted file mode 100644 index 9de47194cf709c..00000000000000 --- a/packages/angular/src/builders/webpack-server/validate-options.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { stripIndents } from '@nx/devkit'; -import { lt } from 'semver'; -import type { VersionInfo } from '../../executors/utilities/angular-version-utils'; -import { getInstalledAngularVersionInfo } from '../../executors/utilities/angular-version-utils'; -import type { Schema } from './schema'; - -export function validateOptions(options: Schema): void { - const angularVersionInfo = getInstalledAngularVersionInfo(); - validateAssets(options, angularVersionInfo); - validateBuildOptimizer(options, angularVersionInfo); - validateVendorChunk(options, angularVersionInfo); -} - -function validateAssets(options: Schema, { version }: VersionInfo): void { - if ( - lt(version, '15.1.0') && - Array.isArray(options.assets) && - options.assets.length > 0 - ) { - throw new Error(stripIndents`The "assets" option is supported from Angular >= 15.1.0. You are currently using "${version}". - You can resolve this error by removing the "assets" option or by migrating to Angular 15.1.0.`); - } -} - -function validateBuildOptimizer( - options: Schema, - { major, version }: VersionInfo -): void { - if (major < 16 && options.buildOptimizer) { - throw new Error(stripIndents`The "buildOptimizer" option is supported from Angular >= 16.0.0. You are currently using "${version}". - You can resolve this error by removing the "buildOptimizer" 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}". - You can resolve this error by removing the "vendorChunk" option or by migrating to Angular 15.1.0.`); - } -} 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 97b44bb9e81d0a..8bc75fdffe23ac 100644 --- a/packages/angular/src/builders/webpack-server/webpack-server.impl.ts +++ b/packages/angular/src/builders/webpack-server/webpack-server.impl.ts @@ -10,7 +10,6 @@ import { switchMap } from 'rxjs/operators'; import { createTmpTsConfigForBuildableLibs } from '../utilities/buildable-libs'; import { mergeCustomWebpackConfig } from '../utilities/webpack'; import { Schema } from './schema'; -import { validateOptions } from './validate-options'; function buildServerApp( options: Schema, @@ -55,7 +54,7 @@ function buildServerAppWithCustomWebpackConfiguration( switchMap(({ executeServerBuilder }) => executeServerBuilder(options, context as any, { webpackConfiguration: async (baseWebpackConfig) => { - // Angular 15 auto includes code from @angular/platform-server + // Angular auto includes code from @angular/platform-server // This includes the code outside the shared scope created by ModuleFederation // This code will be included in the generated code from our generators, // maintaining it within the shared scope. @@ -96,8 +95,6 @@ export function executeWebpackServerBuilder( options: Schema, context: import('@angular-devkit/architect').BuilderContext ): Observable { - validateOptions(options); - options.buildLibsFromSource ??= true; process.env.NX_BUILD_LIBS_FROM_SOURCE = `${options.buildLibsFromSource}`; diff --git a/packages/angular/src/executors/ng-packagr-lite/ng-packagr-adjustments/v17+/ng-package/entry-point/write-package.transform.ts b/packages/angular/src/executors/ng-packagr-lite/ng-packagr-adjustments/v17+/ng-package/entry-point/write-package.transform.ts index 43dcf43d0907b7..2aca0e5df5c6f6 100644 --- a/packages/angular/src/executors/ng-packagr-lite/ng-packagr-adjustments/v17+/ng-package/entry-point/write-package.transform.ts +++ b/packages/angular/src/executors/ng-packagr-lite/ng-packagr-adjustments/v17+/ng-package/entry-point/write-package.transform.ts @@ -354,12 +354,6 @@ type ConditionalExport = { esm2022?: string; esm?: string; default?: string; - - // backward compat for Angular < 16 - node?: string; - esm2020?: string; - es2020?: string; - es2015?: string; }; /** diff --git a/packages/angular/src/executors/ng-packagr-lite/schema.json b/packages/angular/src/executors/ng-packagr-lite/schema.json index 703d9b7856a7a3..c9ee575596926d 100644 --- a/packages/angular/src/executors/ng-packagr-lite/schema.json +++ b/packages/angular/src/executors/ng-packagr-lite/schema.json @@ -3,7 +3,7 @@ "outputCapture": "direct-nodejs", "$schema": "https://json-schema.org/schema", "title": "ng-packagr Target", - "description": "Builds an Angular library with support for incremental builds.\n\nThis executor is meant to be used with buildable libraries in an incremental build scenario. It is similar to the `@nx/angular:package` executor but with some key differences:\n- For supported Angular versions lower than v16, it doesn't run `ngcc` automatically (`ngcc` is no longer available from Angular v16 onwards, for lower versions, it needs to be run separately beforehand if needed, this can be done in a `postinstall` hook on `package.json`).\n- It only produces ESM2022 bundles (ESM2020 for supported Angular versions lower than v16).", + "description": "Builds an Angular library with support for incremental builds.\n\nThis executor is meant to be used with buildable libraries in an incremental build scenario. It is similar to the `@nx/angular:package` executor but it only produces ESM2022 bundles.", "cli": "nx", "type": "object", "presets": [ diff --git a/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap b/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap index 44a5b290870394..b49e3748b7eaee 100644 --- a/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap +++ b/packages/angular/src/generators/application/__snapshots__/application.spec.ts.snap @@ -835,7 +835,7 @@ exports[`app --strict should enable strict type checking: e2e tsconfig.json 1`] `; exports[`app angular compat support should import "ApplicationConfig" from "@angular/platform-browser" 1`] = ` -"import { ApplicationConfig } from '@angular/platform-browser'; +"import { ApplicationConfig } from '@angular/core'; import { provideRouter } from '@angular/router'; import { appRoutes } from './app.routes'; diff --git a/packages/angular/src/generators/application/application.spec.ts b/packages/angular/src/generators/application/application.spec.ts index a631d8c8aa8df9..3b4ad5b08ee046 100644 --- a/packages/angular/src/generators/application/application.spec.ts +++ b/packages/angular/src/generators/application/application.spec.ts @@ -1231,7 +1231,7 @@ describe('app', () => { ...json, dependencies: { ...json.dependencies, - '@angular/core': '~15.2.0', + '@angular/core': '~16.2.0', }, })); }); @@ -1241,13 +1241,13 @@ describe('app', () => { const { devDependencies } = readJson(appTree, 'package.json'); expect(devDependencies['@angular-devkit/build-angular']).toEqual( - backwardCompatibleVersions.angularV15.angularDevkitVersion + backwardCompatibleVersions.angularV16.angularDevkitVersion ); expect(devDependencies['@angular-devkit/schematics']).toEqual( - backwardCompatibleVersions.angularV15.angularDevkitVersion + backwardCompatibleVersions.angularV16.angularDevkitVersion ); expect(devDependencies['@schematics/angular']).toEqual( - backwardCompatibleVersions.angularV15.angularDevkitVersion + backwardCompatibleVersions.angularV16.angularDevkitVersion ); }); diff --git a/packages/angular/src/generators/application/files/standalone-components/src/app/app.config.ts__tpl__ b/packages/angular/src/generators/application/files/standalone-components/src/app/app.config.ts__tpl__ index 3052cc33c89b75..9655cae80bc4cb 100644 --- a/packages/angular/src/generators/application/files/standalone-components/src/app/app.config.ts__tpl__ +++ b/packages/angular/src/generators/application/files/standalone-components/src/app/app.config.ts__tpl__ @@ -1,4 +1,4 @@ -import { ApplicationConfig<% if (useEventCoalescing) { %>, provideZoneChangeDetection<% } %> } from <% if (angularMajorVersion >= 16) { %>'@angular/core';<% } else { %>'@angular/platform-browser';<% } %><% if (routing) { %> +import { ApplicationConfig<% if (useEventCoalescing) { %>, provideZoneChangeDetection<% } %> } from '@angular/core';<% if (routing) { %> import { provideRouter } from '@angular/router'; import { appRoutes } from './app.routes';<% } %> diff --git a/packages/angular/src/generators/ngrx/ngrx.spec.ts b/packages/angular/src/generators/ngrx/ngrx.spec.ts index 72b2e3ea32d4ca..fa1319c7dc0671 100644 --- a/packages/angular/src/generators/ngrx/ngrx.spec.ts +++ b/packages/angular/src/generators/ngrx/ngrx.spec.ts @@ -674,35 +674,35 @@ export const appRoutes: Routes = [{ path: 'home', component: NxWelcomeComponent ...json, dependencies: { ...json.dependencies, - '@angular/core': '15.0.0', + '@angular/core': '16.0.0', }, })); }); - it('should install the ngrx 15 packages', async () => { + it('should install the ngrx 16 packages', async () => { await ngrxGenerator(tree, defaultOptions); const packageJson = devkit.readJson(tree, 'package.json'); expect(packageJson.dependencies['@ngrx/store']).toEqual( - backwardCompatibleVersions.angularV15.ngrxVersion + backwardCompatibleVersions.angularV16.ngrxVersion ); expect(packageJson.dependencies['@ngrx/effects']).toEqual( - backwardCompatibleVersions.angularV15.ngrxVersion + backwardCompatibleVersions.angularV16.ngrxVersion ); expect(packageJson.dependencies['@ngrx/entity']).toEqual( - backwardCompatibleVersions.angularV15.ngrxVersion + backwardCompatibleVersions.angularV16.ngrxVersion ); expect(packageJson.dependencies['@ngrx/router-store']).toEqual( - backwardCompatibleVersions.angularV15.ngrxVersion + backwardCompatibleVersions.angularV16.ngrxVersion ); expect(packageJson.dependencies['@ngrx/component-store']).toEqual( - backwardCompatibleVersions.angularV15.ngrxVersion + backwardCompatibleVersions.angularV16.ngrxVersion ); expect(packageJson.devDependencies['@ngrx/schematics']).toEqual( - backwardCompatibleVersions.angularV15.ngrxVersion + backwardCompatibleVersions.angularV16.ngrxVersion ); expect(packageJson.devDependencies['@ngrx/store-devtools']).toEqual( - backwardCompatibleVersions.angularV15.ngrxVersion + backwardCompatibleVersions.angularV16.ngrxVersion ); expect(packageJson.devDependencies['jasmine-marbles']).toBeDefined(); }); diff --git a/packages/angular/src/generators/setup-ssr/files/ngmodule/pre-v15-2/src/main.ts__tpl__ b/packages/angular/src/generators/setup-ssr/files/ngmodule/pre-v15-2/src/main.ts__tpl__ deleted file mode 100644 index e497f8bd532afd..00000000000000 --- a/packages/angular/src/generators/setup-ssr/files/ngmodule/pre-v15-2/src/main.ts__tpl__ +++ /dev/null @@ -1,14 +0,0 @@ -import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; -import { AppModule } from './app/app.module'; - -function bootstrap() { - platformBrowserDynamic() - .bootstrapModule(AppModule) - .catch((err) => console.error(err)); -} - -if (document.readyState !== 'loading') { - bootstrap(); -} else { - document.addEventListener('DOMContentLoaded', bootstrap); -} diff --git a/packages/angular/src/generators/setup-ssr/files/ngmodule/base/src/__main__ b/packages/angular/src/generators/setup-ssr/files/ngmodule/src/__main__ similarity index 100% rename from packages/angular/src/generators/setup-ssr/files/ngmodule/base/src/__main__ rename to packages/angular/src/generators/setup-ssr/files/ngmodule/src/__main__ diff --git a/packages/angular/src/generators/setup-ssr/files/ngmodule/base/src/app/__rootModuleFileName__ b/packages/angular/src/generators/setup-ssr/files/ngmodule/src/app/__rootModuleFileName__ similarity index 100% rename from packages/angular/src/generators/setup-ssr/files/ngmodule/base/src/app/__rootModuleFileName__ rename to packages/angular/src/generators/setup-ssr/files/ngmodule/src/app/__rootModuleFileName__ 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 13766c8e4a3a8c..651d235b029f3c 100644 --- a/packages/angular/src/generators/setup-ssr/lib/generate-files.ts +++ b/packages/angular/src/generators/setup-ssr/lib/generate-files.ts @@ -4,8 +4,6 @@ import { joinPathFragments, readProjectConfiguration, } from '@nx/devkit'; -import { lt } from 'semver'; -import { getInstalledAngularVersionInfo } from '../../utils/version-utils'; import type { Schema } from '../schema'; export function generateSSRFiles( @@ -27,7 +25,6 @@ export function generateSSRFiles( } const pathToFiles = joinPathFragments(__dirname, '..', 'files'); - const { version: angularVersion } = getInstalledAngularVersionInfo(tree); if (schema.standalone) { generateFiles( @@ -39,18 +36,9 @@ export function generateSSRFiles( } else { generateFiles( tree, - joinPathFragments(pathToFiles, 'ngmodule', 'base'), + joinPathFragments(pathToFiles, 'ngmodule'), projectRoot, { ...schema, tpl: '' } ); - - if (lt(angularVersion, '15.2.0')) { - generateFiles( - tree, - joinPathFragments(pathToFiles, 'ngmodule', 'pre-v15-2'), - projectRoot, - { ...schema, tpl: '' } - ); - } } } diff --git a/packages/angular/src/generators/setup-ssr/lib/index.ts b/packages/angular/src/generators/setup-ssr/lib/index.ts index 37961feff80bea..bb50955a30d8e0 100644 --- a/packages/angular/src/generators/setup-ssr/lib/index.ts +++ b/packages/angular/src/generators/setup-ssr/lib/index.ts @@ -3,7 +3,6 @@ export * from './add-server-file'; export * from './generate-files'; export * from './generate-server-ts-config'; export * from './normalize-options'; -export * from './update-app-module'; export * from './update-project-config'; export * from './validate-options'; export * from './add-hydration'; diff --git a/packages/angular/src/generators/setup-ssr/lib/update-app-module.ts b/packages/angular/src/generators/setup-ssr/lib/update-app-module.ts deleted file mode 100644 index a0d267cf2f92a9..00000000000000 --- a/packages/angular/src/generators/setup-ssr/lib/update-app-module.ts +++ /dev/null @@ -1,47 +0,0 @@ -import type { Tree } from '@nx/devkit'; -import { joinPathFragments, readProjectConfiguration } from '@nx/devkit'; -import { ensureTypescript } from '@nx/js/src/utils/typescript/ensure-typescript'; -import { getInstalledAngularMajorVersion } from '../../utils/version-utils'; -import type { Schema } from '../schema'; - -export function updateAppModule(tree: Tree, schema: Schema) { - const angularMajorVersion = getInstalledAngularMajorVersion(tree); - if (angularMajorVersion >= 16) { - return; - } - - ensureTypescript(); - const { tsquery } = require('@phenomnomnominal/tsquery'); - // read the content of app module - const projectConfig = readProjectConfiguration(tree, schema.project); - const pathToAppModule = joinPathFragments( - projectConfig.sourceRoot, - 'app/app.module.ts' - ); - const fileContents = tree.read(pathToAppModule, 'utf-8'); - - const ast = tsquery.ast(fileContents); - const browserModuleImportNodes = tsquery( - ast, - 'PropertyAssignment:has(Identifier[name=imports]) > ArrayLiteralExpression Identifier[name=BrowserModule]', - { visitAllChildren: true } - ); - - if (browserModuleImportNodes.length === 0) { - throw new Error( - `Could not find BrowserModule declaration in ${pathToAppModule}. Please ensure this is correct.` - ); - } - - const browserModuleNode = browserModuleImportNodes[0]; - - const newFileContents = `${fileContents.slice( - 0, - browserModuleNode.getEnd() - )}.withServerTransition({ appId: '${schema.appId}' })${fileContents.slice( - browserModuleNode.getEnd(), - fileContents.length - )}`; - - tree.write(pathToAppModule, newFileContents); -} 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 3f0e648925b43c..23b1b0d3ed167a 100644 --- a/packages/angular/src/generators/setup-ssr/lib/validate-options.ts +++ b/packages/angular/src/generators/setup-ssr/lib/validate-options.ts @@ -1,14 +1,11 @@ import type { Tree } from '@nx/devkit'; -import { readProjectConfiguration, stripIndents } from '@nx/devkit'; +import { readProjectConfiguration } from '@nx/devkit'; import { validateProject as validateExistingProject } 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); validateBuildTarget(tree, options.project); - validateHydrationOption(tree, options.hydration); } function validateProject(tree: Tree, project: string): void { @@ -31,16 +28,3 @@ function validateBuildTarget(tree: Tree, project: string): void { ); } } - -function validateHydrationOption(tree: Tree, hydration: boolean): void { - if (!hydration) { - return; - } - - const installedAngularVersion = getInstalledAngularVersionInfo(tree).version; - - if (lt(installedAngularVersion, '16.0.0')) { - throw new Error(stripIndents`The "hydration" option is only supported in Angular >= 16.0.0. You are currently using "${installedAngularVersion}". - You can resolve this error by removing the "hydration" option or by migrating to Angular 16.0.0.`); - } -} diff --git a/packages/angular/src/generators/setup-ssr/schema.json b/packages/angular/src/generators/setup-ssr/schema.json index 294874ed65cefe..be85a23aefef6f 100644 --- a/packages/angular/src/generators/setup-ssr/schema.json +++ b/packages/angular/src/generators/setup-ssr/schema.json @@ -19,7 +19,7 @@ "appId": { "type": "string", "format": "html-selector", - "description": "The `appId` to use with `withServerTransition`. _Note: This is only used in Angular versions <16.0.0. It's deprecated since Angular 16 and not supported since Angular 17._", + "description": "The `appId` to use with `withServerTransition`. _Note: This is deprecated and ignored since Angular 16 and not supported since Angular 17._", "default": "serverApp" }, "main": { @@ -55,7 +55,7 @@ }, "hydration": { "type": "boolean", - "description": "Set up Hydration for the SSR application. It defaults to `true` for Angular versions >= 17.0.0. Otherwise, it defaults to `false`. _Note: This is only supported in Angular versions >= 16.0.0_." + "description": "Set up Hydration for the SSR application. It defaults to `true` for Angular versions >= 17.0.0. Otherwise, it defaults to `false`." }, "skipFormat": { "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 2f01a4285cc914..ce3fc2c1fef029 100644 --- a/packages/angular/src/generators/setup-ssr/setup-ssr.spec.ts +++ b/packages/angular/src/generators/setup-ssr/setup-ssr.spec.ts @@ -571,7 +571,7 @@ describe('setupSSR', () => { updateJson(tree, 'package.json', (json) => ({ ...json, dependencies: { - '@angular/core': '15.2.0', + '@angular/core': '16.2.0', }, })); @@ -582,63 +582,22 @@ describe('setupSSR', () => { const pkgJson = readJson(tree, 'package.json'); expect(pkgJson.dependencies['@angular/ssr']).toBeUndefined(); expect(pkgJson.dependencies['@angular/platform-server']).toEqual( - backwardCompatibleVersions.angularV15.angularVersion + backwardCompatibleVersions.angularV16.angularVersion ); expect(pkgJson.dependencies['@nguniversal/express-engine']).toEqual( - backwardCompatibleVersions.angularV15.ngUniversalVersion + backwardCompatibleVersions.angularV16.ngUniversalVersion ); expect(pkgJson.devDependencies['@nguniversal/builders']).toEqual( - backwardCompatibleVersions.angularV15.ngUniversalVersion + backwardCompatibleVersions.angularV16.ngUniversalVersion ); }); - it('should add "withServerTransition" call to app module for angular versions lower than 16', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - updateJson(tree, 'package.json', (json) => ({ - ...json, - dependencies: { ...json.dependencies, '@angular/core': '^15.2.0' }, - })); - - await generateTestApplication(tree, { - name: 'app1', - standalone: false, - skipFormat: true, - }); - - // ACT - await setupSsr(tree, { project: 'app1', skipFormat: true }); - - // ASSERT - expect(tree.read('app1/src/app/app.module.ts', 'utf-8')) - .toMatchInlineSnapshot(` - "import { NgModule } from '@angular/core'; - import { BrowserModule } from '@angular/platform-browser'; - import { RouterModule } from '@angular/router'; - import { AppComponent } from './app.component'; - import { appRoutes } from './app.routes'; - import { NxWelcomeComponent } from './nx-welcome.component'; - - @NgModule({ - declarations: [AppComponent, NxWelcomeComponent], - imports: [ - BrowserModule.withServerTransition({ appId: 'serverApp' }), - RouterModule.forRoot(appRoutes, { initialNavigation: 'enabledBlocking' }), - ], - providers: [], - bootstrap: [AppComponent], - }) - export class AppModule {} - " - `); - }); - it('should set "initialNavigation: enabledBlocking" in "RouterModule.forRoot" options', async () => { // ARRANGE const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); updateJson(tree, 'package.json', (json) => ({ ...json, - dependencies: { ...json.dependencies, '@angular/core': '^15.2.0' }, + dependencies: { ...json.dependencies, '@angular/core': '^16.2.0' }, })); await generateTestApplication(tree, { @@ -663,7 +622,7 @@ describe('setupSSR', () => { @NgModule({ declarations: [AppComponent, NxWelcomeComponent], imports: [ - BrowserModule.withServerTransition({ appId: 'serverApp' }), + BrowserModule, RouterModule.forRoot(appRoutes, { initialNavigation: 'enabledBlocking' }), ], providers: [], @@ -679,7 +638,7 @@ describe('setupSSR', () => { const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); updateJson(tree, 'package.json', (json) => ({ ...json, - dependencies: { ...json.dependencies, '@angular/core': '^15.2.0' }, + dependencies: { ...json.dependencies, '@angular/core': '^16.2.0' }, })); await generateTestApplication(tree, { name: 'app1', skipFormat: true }); @@ -690,7 +649,7 @@ describe('setupSSR', () => { // ASSERT expect(tree.read('app1/src/app/app.config.ts', 'utf-8')) .toMatchInlineSnapshot(` - "import { ApplicationConfig } from '@angular/platform-browser'; + "import { ApplicationConfig } from '@angular/core'; import { provideRouter, withEnabledBlockingInitialNavigation } from '@angular/router'; import { appRoutes } from './app.routes'; @@ -701,48 +660,12 @@ describe('setupSSR', () => { `); }); - it('should wrap bootstrap call for Angular versions lower than 15.2', async () => { - // ARRANGE - const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); - await generateTestApplication(tree, { - name: 'app1', - standalone: false, - skipFormat: true, - }); - updateJson(tree, 'package.json', (json) => ({ - ...json, - dependencies: { '@angular/core': '15.1.0' }, - })); - - // ACT - await setupSsr(tree, { project: 'app1', skipFormat: true }); - - // ASSERT - expect(tree.read('app1/src/main.ts', 'utf-8')).toMatchInlineSnapshot(` - "import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; - import { AppModule } from './app/app.module'; - - function bootstrap() { - platformBrowserDynamic() - .bootstrapModule(AppModule) - .catch((err) => console.error(err)); - } - - if (document.readyState !== 'loading') { - bootstrap(); - } else { - document.addEventListener('DOMContentLoaded', bootstrap); - } - " - `); - }); - it('should generate a correct server.ts', async () => { const tree = createTreeWithEmptyWorkspace({ layout: 'apps-libs' }); updateJson(tree, 'package.json', (json) => ({ ...json, dependencies: { - '@angular/core': '15.2.0', + '@angular/core': '16.2.0', }, })); await generateTestApplication(tree, { @@ -761,7 +684,7 @@ describe('setupSSR', () => { updateJson(tree, 'package.json', (json) => ({ ...json, dependencies: { - '@angular/core': '15.2.0', + '@angular/core': '16.2.0', }, })); await generateTestApplication(tree, { name: 'app1', skipFormat: true }); @@ -770,7 +693,7 @@ describe('setupSSR', () => { expect(tree.read('app1/src/app/app.config.ts', 'utf-8')) .toMatchInlineSnapshot(` - "import { ApplicationConfig } from '@angular/platform-browser'; + "import { ApplicationConfig } from '@angular/core'; import { provideRouter, withEnabledBlockingInitialNavigation } from '@angular/router'; import { appRoutes } from './app.routes'; diff --git a/packages/angular/src/generators/setup-ssr/setup-ssr.ts b/packages/angular/src/generators/setup-ssr/setup-ssr.ts index 14916e371d2b9e..49b0626855c359 100644 --- a/packages/angular/src/generators/setup-ssr/setup-ssr.ts +++ b/packages/angular/src/generators/setup-ssr/setup-ssr.ts @@ -14,7 +14,6 @@ import { normalizeOptions, setRouterInitialNavigation, setServerTsConfigOptionsForApplicationBuilder, - updateAppModule, updateProjectConfigForApplicationBuilder, updateProjectConfigForBrowserBuilder, validateOptions, @@ -35,9 +34,6 @@ export async function setupSsr(tree: Tree, schema: Schema) { } generateSSRFiles(tree, options, isUsingApplicationBuilder); - if (!options.standalone) { - updateAppModule(tree, options); - } if (options.hydration) { addHydration(tree, options); } diff --git a/packages/angular/src/generators/utils/version-utils.ts b/packages/angular/src/generators/utils/version-utils.ts index 45b120640be7a2..d06ae58cacfcea 100644 --- a/packages/angular/src/generators/utils/version-utils.ts +++ b/packages/angular/src/generators/utils/version-utils.ts @@ -60,10 +60,10 @@ export function versions( ): PackageLatestVersions | PackageCompatVersions { const majorAngularVersion = getInstalledAngularMajorVersion(tree); switch (majorAngularVersion) { - case 15: - return backwardCompatibleVersions.angularV15; case 16: return backwardCompatibleVersions.angularV16; + case 17: + return backwardCompatibleVersions.angularV17; default: return latestVersions; } diff --git a/packages/angular/src/utils/backward-compatible-versions.ts b/packages/angular/src/utils/backward-compatible-versions.ts index 1fa0d1687a78e2..f67245cb24fad5 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 = 'angularV15' | 'angularV16'; +type SupportedVersions = 'angularV16' | 'angularV17'; export type LatestPackageVersionNames = Exclude< keyof typeof latestVersions, @@ -18,34 +18,34 @@ export const backwardCompatibleVersions: Record< SupportedVersions, PackageCompatVersions > = { - angularV15: { - angularVersion: '~15.2.0', - angularDevkitVersion: '~15.2.0', - ngPackagrVersion: '~15.2.2', - ngrxVersion: '~15.3.0', + angularV16: { + angularVersion: '~16.2.0', + angularDevkitVersion: '~16.2.0', + ngPackagrVersion: '~16.2.0', + ngrxVersion: '~16.0.0', rxjsVersion: '~7.8.0', - zoneJsVersion: '~0.12.0', + zoneJsVersion: '~0.13.0', angularJsVersion: '1.7.9', tsLibVersion: '^2.3.0', - ngUniversalVersion: '~15.1.0', + ngUniversalVersion: '~16.2.0', corsVersion: '~2.8.5', typesCorsVersion: '~2.8.5', expressVersion: '~4.18.2', typesExpressVersion: '4.17.14', browserSyncVersion: '^3.0.0', moduleFederationNodeVersion: '~1.0.5', - angularEslintVersion: '~15.0.0', + angularEslintVersion: '~16.0.0', tailwindVersion: '^3.0.2', postcssVersion: '^8.4.5', postcssUrlVersion: '~10.1.3', autoprefixerVersion: '^10.4.0', tsNodeVersion: '10.9.1', - jestPresetAngularVersion: '~13.0.0', + jestPresetAngularVersion: '~13.1.0', typesNodeVersion: '16.11.7', jasmineMarblesVersion: '^0.9.2', jsoncEslintParserVersion: '^2.1.0', }, - angularV16: { + angularV17: { angularVersion: '~16.2.0', angularDevkitVersion: '~16.2.0', ngPackagrVersion: '~16.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 86afc96f1715f2..8503353f911d2b 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 @@ -19,9 +19,10 @@ import { connectExistingRepoToNxCloudPrompt } from '../../../connect/connect-to- // key is major Angular version and value is Nx version to use const nxAngularLegacyVersionMap: Record = { 14: '~17.0.0', + 15: '~19.1.0', }; // min major angular version supported in latest Nx -const minMajorAngularVersionSupported = 15; +const minMajorAngularVersionSupported = 16; // 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 4fb909600de143..9b739048c53c0c 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,8 +138,6 @@ function createNxJson( inputs: ['default', '^production'], }; } - // Angular 15 workspaces still support defaultProject. Support was removed in Angular 16. - nxJson.defaultProject = angularJson.defaultProject; writeJsonFile(join(repoRoot, 'nx.json'), nxJson); }