Skip to content

Commit ff23d3a

Browse files
authored
Upgrade to Angular 18 (#19614)
Nx migration: - "@angular-eslint/eslint-plugin" bumped to 18.4.2, - "@angular-eslint/eslint-plugin-template" bumped to 18.4.2, - "@angular-eslint/template-parser" bumped to 18.4.2, - "@nx/angular" bumped to 20.1.3 - "@nx/devkit" bumped to 20.1.3 - "@nx/eslint-plugin" bumped to 20.1.3 - "@nx/jest" bumped to 20.1.3 - "@nx/workspace" bumped to 20.1.3 - "@types/jest" bumped to 29.5.14 - "jest" bumped to 29.7.0 - "jest-preset-angular" bumped to 14.1.1 - "nx" bumped to 20.1.3, - "useInferencePlugins": false added to nx.json for more, see: https://nx.dev/concepts/inferred-tasks#existing-nx-workspaces - "useLegacyCache": true added to nx.json for more, see: https://nx.dev/nx-api/devkit/documents/Workspace#uselegacycach - /.nx/workspace-data added to .gitignore and .prettierignore Angular migration: - "@angular/.." libraries bumped from 17.0.5 to 18.2.9 - "@angular-devkit/.." libraries bumped from 17.0.5 to 18.2.9 - "@angular-eslint/.." libraries bumped from 17.1.0 to 18.4.2 - "@typescript-eslint/" libraries bumped from 6.13.1 to 7.2.0 - "@schematics/angular" bumped from 17.0.5 to 18.2.9 - "@ng-select/ng-select" bumped from 12.0.4 to 13.9.0 - "ngx-infinite-scroll" bumped from 17.0.0 to 18.0.0 - "zone.js" bumped from 0.14.2 to 0.14.10 - "@angular-builders/custom-webpack" bumped from 15.0.0 to 18.0.0 - "ng-packagr" bumped from 17.0.2 to 18.2.1 - replaced deprecated HTTP related modules with provider functions - fixed issues after replacement in some tests (redundant code) (?) - adjusted 'form-errors.component.ts' to new 'AbstractControl' shape - set 'MessageService' as optional in form.component.ts and remove it from FormModule providers' array - replaced boolean | UrlTree return type with GuardResult for canActivate guard functions and related code with NgRx: - "@ngrx/effects" bumped from 17.0.1 to 18.1.0 - "@ngrx/router-store" bumped from 17.0.1 to 18.1.0 - "@ngrx/store" bumped from 17.0.1 to 18.1.0 - "@ngrx/store-devtools" bumped from 17.0.1 to 18.1.0 - "@ngrx/operators" introduced - TypedAction removed in favour of Action Build issues: - replaced Observable<boolean | UrlTree> with combined Observable<GuardResult> from @angular/router for more, see: feat(router): Add ability to return UrlTree with NavigationBehaviorOptions from guards angular/angular#45023 - add node to "types" in all tsconfig.schematics.json to support node API - remove redundant dist and assets property from nested ng-package.json in CDP, OPF and OMF for more, see: https://github.com/ng-packagr/ng-packagr/pull/2754/files - Unit tests: - add support for RedirectCommand type in guard tests - adjust order-return-requrest-list.component.spec.ts to look for input[aria-controls="order-return-table"] instead of div[aria-controls="order-return-table"] due to changes in ng-select for more, see: fix(wcag): adds role 'combobox' to input ng-select/ng-select#2428 - remove recommended property from eslint rules - add fix-jsdom-environment.ts containing fix for missing support of structuredClone in jest-environment-jsdom for more, see: [Bug]: structuredClone is not defined jsdom/jsdom#3363 (comment) - convertAnnotatedSourceToFailureCase is now imported from @angular-eslint/test-utils(new dependency) instead from @angular-eslint/utils - include TS files in tsconfig.spec.json - replace/remove redundant RouterTestingModule - update snapshots in schematics tests Linting: - added new @stylistic/eslint-plugin-ts due to moving some there som config from @typescript-eslint/eslint-plugin: - quotes - member-delimiter-style - semi - type-annotation-spacing` for more, see e.g.: https://typescript-eslint.io/rules/member-delimiter-style/ - removed redundant rules from legacy-ng-cli-compat files Schematics: - fixed type in file-utils_spec.ts - update dependencies.json - adjusted schema.json to work with new Angular for more, see: fix(@angular/cli): support default options for multiselect list x-prompt angular/angular-cli#28842 - Linter for styles: - fixed issues caught after bumping minor version of "stylelint" packages (when upgrading package-lock.json) - added "integration-libs" to the linter scope
1 parent 849ba77 commit ff23d3a

File tree

547 files changed

+15186
-27441
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

547 files changed

+15186
-27441
lines changed

.eslintrc.json

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,39 @@
1313
"./tools/eslint-plugins/legacy-ng-cli-compat",
1414
"./tools/eslint-plugins/legacy-ng-cli-compat--formatting-add-on"
1515
],
16-
"plugins": ["deprecation", "@typescript-eslint", "@nx"],
16+
"plugins": ["deprecation", "@typescript-eslint", "@nx", "@stylistic/ts"],
1717
"rules": {
1818
"@angular-eslint/no-host-metadata-property": "off",
19-
"@typescript-eslint/no-empty-interface": "off",
2019
"deprecation/deprecation": "warn",
2120
"prefer-arrow/prefer-arrow-functions": "off",
22-
"@typescript-eslint/no-inferrable-types": "off",
23-
"@typescript-eslint/naming-convention": "off",
2421
"space-before-function-paren": "off",
2522
"@angular-eslint/no-input-rename": "off",
2623
"curly": "off",
2724
"no-var": "off",
28-
"@typescript-eslint/ban-types": "off",
2925
"jsdoc/newline-after-description": "off",
3026
"no-shadow": "off",
31-
"@typescript-eslint/no-shadow": "off",
32-
"@typescript-eslint/no-unused-expressions": "off",
33-
"@typescript-eslint/member-ordering": "off",
3427
"arrow-body-style": "off",
3528
"object-shorthand": "off",
36-
"@typescript-eslint/prefer-for-of": "off",
3729
"jsdoc/no-types": "off",
3830
"no-fallthrough": "off",
3931
"prefer-const": "off",
40-
"@typescript-eslint/no-namespace": "off",
41-
"@typescript-eslint/consistent-type-assertions": "off",
4232
"@angular-eslint/use-lifecycle-interface": "error",
43-
"@typescript-eslint/quotes": "off",
33+
"@stylistic/ts/quotes": "off",
34+
"@stylistic/ts/member-delimiter-style": [
35+
"error",
36+
{
37+
"multiline": {
38+
"delimiter": "semi",
39+
"requireLast": true
40+
},
41+
"singleline": {
42+
"delimiter": "semi",
43+
"requireLast": false
44+
}
45+
}
46+
],
47+
"@stylistic/ts/semi": ["error", "always"],
48+
"@stylistic/ts/type-annotation-spacing": "error",
4449
"@angular-eslint/component-selector": [
4550
"error",
4651
{
@@ -58,7 +63,6 @@
5863
}
5964
],
6065
"@typescript-eslint/consistent-type-definitions": "off",
61-
"@typescript-eslint/dot-notation": "off",
6266
"@typescript-eslint/explicit-member-accessibility": [
6367
"off",
6468
{

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,5 @@ Thumbs.db
7171
**/git-ignore
7272

7373
.nx/cache
74+
.nx/workspace-data
7475

.prettierignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ feature-libs/smartedit/assets/webApplicationInjector.js
44
**/*.yml
55
coverage
66

7-
/.nx/cache
7+
/.nx/cache
8+
/.nx/workspace-data

core-libs/setup/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
"tslib": "^2.6.2"
2020
},
2121
"peerDependencies": {
22-
"@angular/core": "^17.0.5",
23-
"@angular/ssr": "^17.0.5",
22+
"@angular/core": "^18.2.9",
23+
"@angular/ssr": "^18.2.9",
2424
"@spartacus/cart": "2211.32.0-1",
2525
"@spartacus/core": "2211.32.0-1",
2626
"@spartacus/order": "2211.32.0-1",
2727
"@spartacus/user": "2211.32.0-1"
2828
},
2929
"optionalDependencies": {
30-
"@angular/platform-server": "^17.0.5",
30+
"@angular/platform-server": "^18.2.9",
3131
"express": "^4.21.2"
3232
},
3333
"publishConfig": {

core-libs/setup/ssr/engine/__snapshots__/cx-common-engine.spec.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ exports[`CxCommonEngine should handle APP_INITIALIZER errors the standard Angula
77

88
exports[`CxCommonEngine should handle errors propagated from SSR 1`] = `"test error"`;
99

10-
exports[`CxCommonEngine should not override providers passed to options 1`] = `"<html data-critters-container><head></head><body><cx-token ng-version="17.0.5" ng-server-context="ssr">message:test</cx-token></body></html>"`;
10+
exports[`CxCommonEngine should not override providers passed to options 1`] = `"<html data-critters-container><head></head><body><cx-token ng-version="18.2.9" ng-server-context="ssr">message:test</cx-token></body></html>"`;
1111

12-
exports[`CxCommonEngine should return html if no errors 1`] = `"<html data-critters-container><head></head><body><cx-mock ng-version="17.0.5" ng-server-context="ssr">some template</cx-mock></body></html>"`;
12+
exports[`CxCommonEngine should return html if no errors 1`] = `"<html data-critters-container><head></head><body><cx-mock ng-version="18.2.9" ng-server-context="ssr">some template</cx-mock></body></html>"`;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# (EARLY NOTES) Migrating a custom app to use Spartacus with Angular v18
2+
3+
Before upgrading Spartacus to the new version with Angular 18, you need to first:
4+
- upgrade to the latest 2211.x of Spartacus
5+
- upgrade Angular to version v18
6+
7+
## Update Angular to 17 and 18
8+
9+
### Update Angular to 17 and 3rd party deps to be compatible with Angular 18
10+
11+
Follow the [Angular guidelines for upgrading from v17 to v18](https://angular.dev/update-guide?v=17.0-18.0&l=3) and bump the Angular version locally, and update other 3rd party dependencies from Angular ecosystem to versions compatible with Angular 18 (e.g. `@ng-select/ng-select@13`, `@ngrx/store@18`, `ngx-infinite-scroll@18`):
12+
13+
```bash
14+
ng update @angular/core@18 @angular/cli@18 @ng-select/ng-select@13 @ngrx/store@18 ngx-infinite-scroll@18 --force
15+
git add .
16+
git commit -m "update angular 18 and 3rd party deps angular 18 compatible"
17+
```
18+
Note: Do not select `use-application-builder` migration when migrating to Angular 18. Applications created before SPA 2211.19 doesn't support this builder. Applications created starting from 2211.19 already supports it.
19+
20+
### Run Spartacus update
21+
22+
After successfully updating the application to Angular 18, execute this command to initiate the Spartacus update process.
23+
24+
```bash
25+
ng update @spartacus/schematics@latest
26+
```
27+
28+
### Adjust Angular configuration
29+
30+
Due to changes in Angular's application builder, for applications created starting from SPA 2211.19, you need to adjust the `angular.json` file to generate the `index.html` file in the `dist` folder. This is required for CCv2 to map `OCC_BACKEND_BASE_URL_VALUE` and `MEDIA_BACKEND_BASE_URL_VALUE` meta tags to the correct values. Unfortunately, this will contribute to pre-rendering to not work properly (which is a known issue)
31+
32+
```diff
33+
- "index": "src/index.html"
34+
+ "index": {
35+
+ "input": "src/index.html",
36+
+ "output": "index.html"
37+
+ }
38+
```

feature-libs/asm/customer-360/occ/adapters/occ-asm-customer-360.adapter.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
2-
HttpClientTestingModule,
32
HttpTestingController,
3+
provideHttpClientTesting,
44
} from '@angular/common/http/testing';
55
import { TestBed } from '@angular/core/testing';
66
import {
@@ -17,6 +17,10 @@ import {
1717
} from '@spartacus/core';
1818
import { Observable, of } from 'rxjs';
1919
import { OccAsmCustomer360Adapter } from './occ-asm-customer-360.adapter';
20+
import {
21+
provideHttpClient,
22+
withInterceptorsFromDi,
23+
} from '@angular/common/http';
2024

2125
const baseSite = 'test-site';
2226
class MockBaseSiteService {
@@ -43,11 +47,13 @@ describe('OccAsmCustomer360Adapter', () => {
4347

4448
beforeEach(() => {
4549
TestBed.configureTestingModule({
46-
imports: [HttpClientTestingModule],
50+
imports: [],
4751
providers: [
4852
OccAsmCustomer360Adapter,
4953
{ provide: BaseSiteService, useClass: MockBaseSiteService },
5054
{ provide: OccEndpointsService, useClass: MockOccEndpointsService },
55+
provideHttpClient(withInterceptorsFromDi()),
56+
provideHttpClientTesting(),
5157
],
5258
});
5359

feature-libs/asm/customer-360/root/interceptors/site-context.interceptor.spec.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import { HttpClient, HTTP_INTERCEPTORS } from '@angular/common/http';
21
import {
3-
HttpClientTestingModule,
2+
HttpClient,
3+
HTTP_INTERCEPTORS,
4+
provideHttpClient,
5+
withInterceptorsFromDi,
6+
} from '@angular/common/http';
7+
import {
48
HttpTestingController,
59
TestRequest,
10+
provideHttpClientTesting,
611
} from '@angular/common/http/testing';
712
import { inject, TestBed } from '@angular/core/testing';
813
import {
@@ -63,7 +68,7 @@ describe('SiteContextInterceptor', () => {
6368

6469
beforeEach(() => {
6570
TestBed.configureTestingModule({
66-
imports: [HttpClientTestingModule],
71+
imports: [],
6772
providers: [
6873
{
6974
provide: LanguageService,
@@ -86,6 +91,8 @@ describe('SiteContextInterceptor', () => {
8691
useClass: SiteContextInterceptor,
8792
multi: true,
8893
},
94+
provideHttpClient(withInterceptorsFromDi()),
95+
provideHttpClientTesting(),
8996
],
9097
});
9198
httpMock = TestBed.inject(HttpTestingController);

feature-libs/asm/customer-360/styles/components/_index.scss

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
@import '@spartacus/styles/scss/core';
22

3-
@import './_asm-customer-360.component.scss';
4-
@import './_asm-customer-360-profile.scss';
3+
@import './_asm-customer-360.component';
4+
@import './_asm-customer-360-profile';
55
@import './_asm-customer-360-product-listing.component';
6-
@import './_asm-customer-360-table.component.scss';
7-
@import './_asm-customer-360-map.component.scss';
8-
@import './_asm-customer-360-promotion-listing.component.scss';
6+
@import './_asm-customer-360-table.component';
7+
@import './_asm-customer-360-map.component';
8+
@import './_asm-customer-360-promotion-listing.component';
99

1010
$customer-360-components-allowlist: cx-asm-customer-360,
1111
cx-asm-customer-360-profile, cx-asm-customer-360-product-listing,

feature-libs/asm/occ/adapters/occ-asm.adapter.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
2-
HttpClientTestingModule,
32
HttpTestingController,
43
TestRequest,
4+
provideHttpClientTesting,
55
} from '@angular/common/http/testing';
66
import { TestBed } from '@angular/core/testing';
77
import {
@@ -25,6 +25,10 @@ import {
2525
} from '@spartacus/core';
2626
import { Observable, of } from 'rxjs';
2727
import { OccAsmAdapter } from './occ-asm.adapter';
28+
import {
29+
provideHttpClient,
30+
withInterceptorsFromDi,
31+
} from '@angular/common/http';
2832

2933
const MockAsmConfig: AsmConfig = {};
3034

@@ -84,12 +88,14 @@ describe('OccAsmAdapter', () => {
8488

8589
beforeEach(() => {
8690
TestBed.configureTestingModule({
87-
imports: [HttpClientTestingModule],
91+
imports: [],
8892
providers: [
8993
OccAsmAdapter,
9094
{ provide: BaseSiteService, useClass: MockBaseSiteService },
9195
{ provide: AsmConfig, useValue: MockAsmConfig },
9296
{ provide: OccEndpointsService, useClass: MockOccEndpointsService },
97+
provideHttpClient(withInterceptorsFromDi()),
98+
provideHttpClientTesting(),
9399
],
94100
});
95101

0 commit comments

Comments
 (0)