Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Migrate existing apps with application builder to use index.server.html in server file #19848

Merged
merged 42 commits into from
Jan 28, 2025

Conversation

pawelfras
Copy link
Contributor

@pawelfras pawelfras commented Jan 9, 2025

This PR provides an automation that migrates SPA apps using application builder (created with SPA >=2211.19) to use server/index.server.html instead of browser/index.html due to changes in Angular 19 and what's the output of built application.

QA (installation script):

  • build and deploy Spartacus packages locally:
    npx ts-node ./tools/schematics/testing.ts in the SPA root folder
  • create new app npx @angular/cli@17 new my-app --standalone=false --style=scss --routing=false
  • go to the project's directory and install latest SPA 2211.x, e.g. from RBSC
  • migrate to Angualr 18, then 19 (following migration docs
  • update SPA to v2211.35.0:
    `npx @angular/cli@17 update @spartacus/schematics@latest
  • verify if migration runs (logs in console):
    image
  • verify server.ts file if changes are applied:
    image
  • run npm run build and NODE_TLS_REJECT_UNAUTHORIZED=0 run serve:ssr:my-app to test if app works

Required actions:
-[ ] change the migration from 2212.32.0 to the proper one, when it's known

pawelfras and others added 28 commits December 12, 2024 12:54
- ran `npx nx migrate latest` (bump most of libraries to the latest version) and `npx nx migrate --run-migration` (run packages' migration, all except angular's migration from initializer tokens to helper functions)
- bump '@angular/animations' to version '^19.0.3'
- bump '@angular/common' to version '^19.0.3'
- bump '@angular/compiler' to version '^19.0.3'
- bump '@angular/core' to version '^19.0.3'
- bump '@angular/forms' to version '^19.0.3'
- bump '@angular/platform-browser' to version '^19.0.3'
- bump '@angular/platform-browser-dynamic' to version '^19.0.3'
- bump '@angular/platform-server' to version '^19.0.3'
- bump '@angular/pwa' to version '^19.0.4'
- bump '@angular/router' to version '^19.0.3'
- bump '@angular/service-worker' to version '^19.0.3'
- bump '@angular/ssr' to version '^19.0.4'
- bump '@ng-select/ng-select' to version '^14.1.0'
- bump 'angular-oauth2-oidc' to version '19.0.0'
- bump 'ngx-infinite-scroll' to version '^19.0.0'
- bump 'zone.js' to version '0.15.0'
- bump '@angular-devkit/build-angular' to version '^19.0.4'
- bump '@angular-devkit/core' to version '^19.0.4'
- bump '@angular-devkit/schematics' to version '^19.0.4'
- bump '@angular-eslint/builder' to version '19.0.2'
- bump '@angular-eslint/eslint-plugin' to version '^19.0.2'
- bump '@angular-eslint/eslint-plugin-template' to version '^19.0.2'
- bump '@angular-eslint/schematics' to version '^19.0.2'
- bump '@angular-eslint/template-parser' to version '^19.0.2'
- bump '@angular-eslint/test-utils' to version '^19.0.2'
- bump '@angular-eslint/utils' to version '^19.0.2'
- bump '@angular/cli' to version '^19.0.4'
- bump '@angular/compiler-cli' to version '^19.0.3'
- bump '@angular/language-service' to version '^19.0.3'
- bump '@nx/angular' to version '^20.2.2'
- bump '@nx/devkit' to version '^20.2.2'
- bump '@nx/eslint-plugin' to version '^20.2.2'
- bump '@nx/jest' to version '^20.2.2'
- bump '@nx/workspace' to version '^20.2.2'
- bump '@schematics/angular' to version '^19.0.4'
- bump 'jest-preset-angular' to version '14.4.2'
- bump 'ng-packagr' to version '^19.0.1'
- bump 'nx' to version '^20.2.2'
- bump 'typescript' to version '^5.6.3'
- add `standalone: false` to all components, directives and pipes
  for more, see: angular/angular#57643
- add rule `"@angular-eslint/prefer-standalone": "off"` in eslint files
- remove deprecated `"angular-eslint/no-host-metadata-property"`
  for more, see: angular-eslint/angular-eslint#2113
- update '@angular/ssr' import paths to use the new '/node' entry point when 'CommonEngine' is detected
  for more, see: angular/angular-cli#28278
- change range specifier for typescript library to meet Angular's requirement (>=5.5.0 and <5.7.0)
- fix building libs and CSR by solvig type errors provided with TS 5.6
- this update is required for SSR to work, because previous version use Angualr 18 API which is no longer part of @angular/core in v19.
  for more, see: angular/angular#58891
- fix type issues
- use `takeUntil` with destroy subject in `trending-searches.service.ts` as a more reliable cleanup method to properly handle cleanup
- remove redundant 'declatartion: true' from 'tsconfig.schematics.json' files,
  that caused issues in unit tests due to type errors in '@schematics/angular' library
  'Buffer is not a generic type'. The issue appeared because '*.d.ts' files are taken into consideration when running tests, maybe unnecessary
  for more, see: https://github.com/angular/angular-cli/blob/4db4dd4315fd8c31872bbf1e82e3414eea15ffef/goldens/public-api/angular_devkit/schematics/index.api.md\?plain\=1\#L498
- update snapshots with new budget thresholds
  for more, see: angular/angular-cli#28255
- update snapshots with new packages versions
- update schematics and related tests with the new `server.ts` location
  for more, see: angular/angular-cli#28571
- adjust positions in utils tests to reflect the `standalone: false` in component decorators
- adjust SSR schematics to remove `withEventReplay()` that Angular installs by default
  for more, see:
- refactor tests for 2211.19 SSR migration to make them independent of Angular's schematics
  for more, see: angular/angular-cli#28469
- move `@angular-eslint/prefer-standalone` to global eslint rules
- add missing `OnDestroy` implementation in cds library
- remove `@angular-eslint/no-host-metadata-property` from the config as it is no longer part of the package
 for more, see: angular-eslint/angular-eslint#2113
- add missing comma to all files where 'standalone: false' was added
- upgrade to version that supports TS >= 5.6.3
- add `@typescript-eslint/rule-tester` which was missing peer dependency of `@angular-eslint/test-utils`
- adjust import-utils.ts to meet new typing
- bump `@ngrx/*` libraries to `19.0.0`
- adjust failing unit tests to satisfy types
- update snapshots
- adjust ssr/engine tests to use new required `standalone: false`
- adjust jest config for `setup/ssr` unit tests to use `beasties` from node modules instead of the internalized one provided with `@angular/ssr` due to issues with not supported ES format
….server.html`

- adjust server file
- update snapshot
- update docs with information about changing path to the index file to be in line with the builder's output
This reverts commit 3fb0b3a.
This reverts commit c304b34.
…io, where indexHtml variable is defined inside function
@pawelfras pawelfras requested a review from a team as a code owner January 9, 2025 13:25
@pawelfras pawelfras mentioned this pull request Jan 9, 2025
46 tasks
Copy link
Contributor

@kpawelczak kpawelczak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested the changes and the server.ts is updated after the migration. The SSR application properly uses the index.server.html.
@pawelfras There are sonar errors complaining about the if statement style

kpawelczak
kpawelczak previously approved these changes Jan 20, 2025
Base automatically changed from epic/upgrade-to-angular-19 to develop January 23, 2025 07:35
@pawelfras pawelfras dismissed kpawelczak’s stale review January 23, 2025 07:35

The base branch was changed.

@pawelfras pawelfras requested review from a team as code owners January 23, 2025 07:35
@github-actions github-actions bot marked this pull request as draft January 23, 2025 09:26
projects/schematics/src/shared/utils/package-utils_spec.ts Outdated Show resolved Hide resolved
Comment on lines 353 to 367
/**
* Reads and parses the angular.json file from the root of the project.
*
* @param tree - The virtual file tree provided by the Angular schematics
* @returns The parsed angular.json content as an object
* @throws SchematicsException if angular.json cannot be found or parsed
*/
function readAngularJson(tree: Tree): any {
const buffer = tree.read('angular.json');
if (!buffer) {
throw new SchematicsException('Could not find angular.json');
}
const angularFileBuffer = buffer.toString(UTF_8);
return JSON.parse(angularFileBuffer);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[QUESTION]
Why didn't we reuse the existing util function getWorkspace()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! Code from readAngularJson was used in few functions inside this util file so I extracted it to a separate function and reused, but I wasn't aware of getWorkspace util. It works as expected after switching to your proposal 👌

@pawelfras pawelfras marked this pull request as ready for review January 28, 2025 11:51
@pawelfras pawelfras merged commit 0ab6454 into develop Jan 28, 2025
18 checks passed
@pawelfras pawelfras deleted the feat/use-index-server-file branch January 28, 2025 12:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants