@dsivd/prestations-ng 19.2.0-beta.2 → 19.2.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +301 -0
- package/CONTRIBUTING.md +74 -4
- package/GOOD_PRACTICES.md +673 -372
- package/INTRODUCTION_ANGULAR_SIGNALS.md +199 -154
- package/UPGRADING_V18.md +5 -5
- package/UPGRADING_V19.md +278 -13
- package/eslint/configs/spec-ts-recommended.mjs +34 -0
- package/eslint/configs/template-recommended.mjs +2 -0
- package/eslint/configs/template-rules.mjs +6 -2
- package/eslint/configs/ts-recommended.mjs +2 -0
- package/eslint/configs/ts-rules.mjs +6 -2
- package/eslint/index.mjs +17 -0
- package/eslint/rules/no-direct-signal-mutation.mjs +1 -1
- package/fesm2022/dsivd-prestations-ng.mjs +2356 -1878
- package/fesm2022/dsivd-prestations-ng.mjs.map +1 -1
- package/package.json +1 -2
- package/schematics/ng-add/index.js +2 -4
- package/schematics/ng-update/migrations/update-13_2_0/index.js +7 -2
- package/schematics/utility/add-allowed-common-js-dependencies.js +39 -29
- package/schematics/utility/remove-emit-decorator-metadata.js +8 -9
- package/src/eslint/configs/__tests__/configs.test.mjs +46 -2
- package/src/eslint/configs/spec-ts-recommended.mjs +34 -0
- package/src/eslint/configs/template-recommended.mjs +2 -0
- package/src/eslint/configs/template-rules.mjs +6 -2
- package/src/eslint/configs/ts-recommended.mjs +2 -0
- package/src/eslint/configs/ts-rules.mjs +6 -2
- package/src/eslint/index.mjs +17 -0
- package/src/eslint/rules/no-direct-signal-mutation.mjs +1 -1
- package/types/dsivd-prestations-ng.d.ts +422 -209
- package/dsivd-prestations-ng-19.2.0-beta.2.tgz +0 -0
package/UPGRADING_V18.md
CHANGED
|
@@ -51,10 +51,8 @@ Fix application.properties :
|
|
|
51
51
|
|
|
52
52
|
```diff
|
|
53
53
|
logging.config=${ch.vd.configDir}/logback-spring.xml
|
|
54
|
-
+ # Restore sleuth traces at the same position as in spring boot 2
|
|
55
|
-
+ logging.pattern.
|
|
56
|
-
+ # remove sleuth traces added by spring boot 3
|
|
57
|
-
+ logging.pattern.correlation=
|
|
54
|
+
+ # Restore sleuth traces at the same position as in spring boot 2, bien laisser l'espace à la fin de la ligne
|
|
55
|
+
+ logging.pattern.correlation=[${spring.application.name:},%X{traceId:-},%X{spanId:-}]
|
|
58
56
|
+ logging.include-application-name=false
|
|
59
57
|
```
|
|
60
58
|
|
|
@@ -350,7 +348,9 @@ repository. The subfolder name must correspond to the deployUnit name.
|
|
|
350
348
|
Define `deployUnit.groupId` et `deployUnit.name` in your moved base properties file.
|
|
351
349
|
|
|
352
350
|
In the helm folder, add a subfolder with the deployUnit name and fill it with a values.yaml file (copy-paste-replace
|
|
353
|
-
from another similar
|
|
351
|
+
from another similar, take care that there is a `environment: {{ get .Properties.rftoolkit "environment" }}` (with the
|
|
352
|
+
right application name, the right number of replicas, the right management port, the right liveness and readiness
|
|
353
|
+
probes, the right resources, etc.).
|
|
354
354
|
NB : if your application is using a `${ch.vd.dataDir}` that must survive a restart, your can mount a persistent
|
|
355
355
|
volume by adding `dataDirSize: 10Mi` (pick the right size) in the values.yaml file.
|
|
356
356
|
|
package/UPGRADING_V19.md
CHANGED
|
@@ -97,16 +97,9 @@ if you use oracle, you should replace `ojdbc10` by `ojdbc17` in your `pom.xml` a
|
|
|
97
97
|
With Spring Boot 4, Jackson 3 is now used instead of Jackson 2, so we need to replace the previous Jackson 2 classes.
|
|
98
98
|
Replace `com.fasterxml.jackson.databind.ObjectMapper` with `tools.jackson.databind.json.JsonMapper`.
|
|
99
99
|
|
|
100
|
-
###
|
|
101
|
-
|
|
102
|
-
- `ch.vd.cyberadminbe.jms` has been moved to `ch.vd.cyber.backofficebe.jms`
|
|
103
|
-
- `ch.vd.cyberadminbe.security` has been moved to `ch.vd.cyber.backofficebe.security`
|
|
104
|
-
- `ch.vd.cyberadminbe.editique` has been moved to `ch.vd.cyber.backofficebe.editique`
|
|
105
|
-
- `cyberadminbe.config.CyberAdminBeEsbHttpConfig` has been renamed to `backofficebe.config.BoCommonEsbHttpConfig`
|
|
100
|
+
### Brave Tracer
|
|
106
101
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
If you are using Brave Tracer (search `brave.Tracer` in the code, usually in backoffices), you need to replace it with
|
|
102
|
+
If you are using Brave Tracer (search `brave.Tracer` in the code), you need to replace it with
|
|
110
103
|
OpenTelemetry by adding the following dependencies (already included by `ch.vd.cyber:starter-bo-jdbc-jms` and `ch.vd.cyber:starter-prestation`):
|
|
111
104
|
|
|
112
105
|
```xml
|
|
@@ -123,6 +116,13 @@ OpenTelemetry by adding the following dependencies (already included by `ch.vd.c
|
|
|
123
116
|
|
|
124
117
|
And replace `brave.Tracer` imports by `io.micrometer.tracing.Tracer`;
|
|
125
118
|
|
|
119
|
+
### BO : Package renaming
|
|
120
|
+
|
|
121
|
+
- `ch.vd.cyberadminbe.jms` has been moved to `ch.vd.cyber.backofficebe.jms`
|
|
122
|
+
- `ch.vd.cyberadminbe.security` has been moved to `ch.vd.cyber.backofficebe.security`
|
|
123
|
+
- `ch.vd.cyberadminbe.editique` has been moved to `ch.vd.cyber.backofficebe.editique`
|
|
124
|
+
- `cyberadminbe.config.CyberAdminBeEsbHttpConfig` has been renamed to `backofficebe.config.BoCommonEsbHttpConfig`
|
|
125
|
+
|
|
126
126
|
#### BO : EsbMessageListenerWithSleuthIntegration
|
|
127
127
|
|
|
128
128
|
This base class has been moved from `ch.vd.cyber.sdk:cyberadmin-be` to `ch.vd.cyber.sdk:backoffice-be`
|
|
@@ -1064,8 +1064,13 @@ npm install --save-dev eslint-plugin-simple-import-sort@13
|
|
|
1064
1064
|
npm install --save-dev eslint-config-prettier@10
|
|
1065
1065
|
npm install --save-dev eslint-plugin-import-x@4
|
|
1066
1066
|
npm install --save-dev prettier
|
|
1067
|
+
# only if your project has Vitest specs (see "Migrate to vitest")
|
|
1068
|
+
npm install --save-dev --save-exact @vitest/eslint-plugin@1.6.27
|
|
1067
1069
|
```
|
|
1068
1070
|
|
|
1071
|
+
`@vitest/eslint-plugin` 1.6.28 and later need TypeScript 6: with the TypeScript 5.9 of Angular 21, `npm install` fails
|
|
1072
|
+
with `ERESOLVE`. Keep 1.6.27 until your project moves to TypeScript 6.
|
|
1073
|
+
|
|
1069
1074
|
In your `front` folder, add a `.prettierrc` file with the following content:
|
|
1070
1075
|
|
|
1071
1076
|
```json
|
|
@@ -1140,6 +1145,12 @@ export default tseslint.config(
|
|
|
1140
1145
|
extends: [...prestationsNg.configs.templateRecommended],
|
|
1141
1146
|
},
|
|
1142
1147
|
|
|
1148
|
+
// ─── Vitest specs (only if your project has Vitest specs) ─────────────────
|
|
1149
|
+
{
|
|
1150
|
+
files: ['**/*.spec.ts'],
|
|
1151
|
+
extends: [...prestationsNg.configs.specTsRecommended],
|
|
1152
|
+
},
|
|
1153
|
+
|
|
1143
1154
|
// ─── Prettier (must be last — disables formatting rules) ───────────────────
|
|
1144
1155
|
prettier,
|
|
1145
1156
|
);
|
|
@@ -1150,6 +1161,11 @@ everything: the `eslint`, `typescript-eslint` and `angular-eslint` baselines, th
|
|
|
1150
1161
|
accessibility set, the naming and import conventions, and the rules written by the library
|
|
1151
1162
|
itself. You declare no `plugins` and list no rule.
|
|
1152
1163
|
|
|
1164
|
+
`specTsRecommended` is the `recommended` config of `@vitest/eslint-plugin`, which also counts the assertions
|
|
1165
|
+
made by the `HttpTestingController` (`expectOne`, `expectNone`, `verify`) and by helpers named `expect*`,
|
|
1166
|
+
`assert*` or `test*`. The `**/*.spec.ts` pattern does not reach the Cypress `*.spec.cy.ts` files. It needs
|
|
1167
|
+
`@vitest/eslint-plugin` only when you use it: the other configs work without it.
|
|
1168
|
+
|
|
1153
1169
|
The packages installed above are still required — the library's config imports them from your
|
|
1154
1170
|
`node_modules` rather than shipping its own copies. For the same reason, do **not** spread
|
|
1155
1171
|
`angular.configs.tsRecommended` or `angular.configs.templateRecommended` yourself: they are
|
|
@@ -1233,7 +1249,7 @@ In `front/src/`, remove the file `typings.d.ts` if it is still there.
|
|
|
1233
1249
|
{
|
|
1234
1250
|
"extends": "./tsconfig.json",
|
|
1235
1251
|
"compilerOptions": {
|
|
1236
|
-
"outDir": "
|
|
1252
|
+
"outDir": "./out-tsc/app",
|
|
1237
1253
|
"types": []
|
|
1238
1254
|
},
|
|
1239
1255
|
"include": ["src/**/*.ts"],
|
|
@@ -1430,17 +1446,67 @@ When using `IntelliJ`, you can run code inspection on your project to fix deprec
|
|
|
1430
1446
|
- IntelliJ window menu, go to: `Code > Analyze code > Run inspection by name...` (or **Ctrl+Alt+Maj+i**) and type `Deprecated symbol used`.
|
|
1431
1447
|
- Or select your project in your project panel and `right click` on it then `Analyze > Run inspection by name...` (or **Ctrl+Alt+Maj+i**) and type `Deprecated symbol used`.
|
|
1432
1448
|
|
|
1449
|
+
### `(modelChange)` is emitted only when the component writes its model
|
|
1450
|
+
|
|
1451
|
+
In v18, a `foehn-input-*` component emitted `modelChange` again each time the page gave it a model, the same value
|
|
1452
|
+
included: the form loaded from the backend, a prefill, a reset... (with `undefined` at the initialization). Since
|
|
1453
|
+
19.0.0, the model of the components is a signal (`model()`), and `modelChange` is emitted only when the component
|
|
1454
|
+
writes its model, with a new value:
|
|
1455
|
+
|
|
1456
|
+
- at each input of the user, at once (`userInput` comes after a debounce);
|
|
1457
|
+
- when the component corrects the model the page gave it, e.g. `''` replaced by `null` in the text fields, a NAVS
|
|
1458
|
+
formatted as `756.xxxx.xxxx.xx`, the default country of an address, the `defaultElementValue` of a `foehn-select`.
|
|
1459
|
+
|
|
1460
|
+
It is no longer emitted when the page changes the model itself, which `[(model)]` doesn't need. Search your templates
|
|
1461
|
+
for `(modelChange)` on a `foehn-` component: a handler which also had to react to a model set by the page (e.g. to
|
|
1462
|
+
fill another field once the form is loaded, often behind a guard on `undefined`) is no longer called for it. Do that
|
|
1463
|
+
work where the page writes the form: after its loading (`GesdemEventService.formInitializationObservable()`, which
|
|
1464
|
+
emits the loaded form), after a prefill, after a reset.
|
|
1465
|
+
|
|
1433
1466
|
### Strict mode (optional when migrating large projects but recommended)
|
|
1434
1467
|
|
|
1435
1468
|
- In your `tsconfig.json` file, add `"strict": true` in `compilerOptions` and remove `alwaysStrict`, `noImplicitThis`, `strictBindCallApply` and `strictFunctionTypes` as they are already included in `strict` mode.
|
|
1436
1469
|
- In your `tsconfig.json` file, remove `useDefineForClassFields` from `compilerOptions`.
|
|
1437
1470
|
|
|
1438
|
-
|
|
1471
|
+
Without `useDefineForClassFields: false`, the class fields follow the standard semantics: they are initialized before
|
|
1472
|
+
the body of the constructor, so before the parameter properties, and a field declared again in a subclass overwrites
|
|
1473
|
+
the value set by the parent class. Two errors can appear:
|
|
1474
|
+
|
|
1475
|
+
- TS2729 (`Property 'x' is used before its initialization`): a field initializer uses a parameter property of the
|
|
1476
|
+
constructor. Use `inject()` in the initializer, or assign the field in the constructor. Don't move a
|
|
1477
|
+
`private readonly x = inject(X)` field above the public fields: the `@typescript-eslint/member-ordering` rule of
|
|
1478
|
+
`@dsivd/prestations-ng/eslint` wants the public fields first.
|
|
1479
|
+
|
|
1480
|
+
```diff
|
|
1481
|
+
- readonly items = toSignal(this.itemService.getItems(), { initialValue: [] });
|
|
1482
|
+
-
|
|
1483
|
+
- constructor(private readonly itemService: ItemService) {}
|
|
1484
|
+
+ readonly items = toSignal(inject(ItemService).getItems(), { initialValue: [] });
|
|
1485
|
+
```
|
|
1486
|
+
|
|
1487
|
+
```ts
|
|
1488
|
+
readonly items: Signal<Item[]>;
|
|
1489
|
+
|
|
1490
|
+
private readonly itemService = inject(ItemService);
|
|
1491
|
+
|
|
1492
|
+
constructor() {
|
|
1493
|
+
this.items = toSignal(this.itemService.getItems(), { initialValue: [] });
|
|
1494
|
+
}
|
|
1495
|
+
```
|
|
1496
|
+
|
|
1497
|
+
- TS2612 (`Property 'x' will overwrite the base property`): a subclass declares again a field of its parent class,
|
|
1498
|
+
e.g. to narrow its type. Add `declare` (`declare form: MyForm | null | undefined;`) or remove the declaration, but
|
|
1499
|
+
never add an initializer: it would overwrite the value set by the parent class.
|
|
1500
|
+
|
|
1501
|
+
Now fix your project until no more errors (unlike `tsc -b`, these commands write nothing):
|
|
1439
1502
|
|
|
1440
1503
|
```bash
|
|
1441
|
-
npx tsc -
|
|
1504
|
+
npx tsc -p tsconfig.app.json --noEmit
|
|
1505
|
+
npx tsc -p tsconfig.spec.json --noEmit
|
|
1442
1506
|
```
|
|
1443
1507
|
|
|
1508
|
+
`tsc` doesn't check the templates: the errors reported by `strictTemplates` appear when you build your application.
|
|
1509
|
+
|
|
1444
1510
|
and finally run the following commands to build, test and start your application:
|
|
1445
1511
|
|
|
1446
1512
|
```bash
|
|
@@ -1449,6 +1515,204 @@ npm run test
|
|
|
1449
1515
|
npm start
|
|
1450
1516
|
```
|
|
1451
1517
|
|
|
1518
|
+
### `foehn-list-summary` is now generic (since 19.2.0)
|
|
1519
|
+
|
|
1520
|
+
`FoehnListSummaryComponent` is now `FoehnListSummaryComponent<T extends FoehnListItem>` and `FoehnListItemDescription` now takes a type parameter: `FoehnListItemDescription<T>`.
|
|
1521
|
+
Using `FoehnListItemDescription` without its type parameter no longer compiles.
|
|
1522
|
+
|
|
1523
|
+
Replace every `FoehnListItemDescription` with `FoehnListItemDescription<MyItem>`, where `MyItem` is your class extending `FoehnListItem`. You can then drop the casts (or `any`) in `getFormattedValue` and `hideIfEmpty`:
|
|
1524
|
+
|
|
1525
|
+
Before:
|
|
1526
|
+
|
|
1527
|
+
```typescript
|
|
1528
|
+
getListItemsDescription(): FoehnListItemDescription[] {
|
|
1529
|
+
return [
|
|
1530
|
+
{
|
|
1531
|
+
label: 'Name',
|
|
1532
|
+
getFormattedValue: (item: FoehnListItem) =>
|
|
1533
|
+
(item as MyItem).name ?? '',
|
|
1534
|
+
},
|
|
1535
|
+
];
|
|
1536
|
+
}
|
|
1537
|
+
```
|
|
1538
|
+
|
|
1539
|
+
After:
|
|
1540
|
+
|
|
1541
|
+
```typescript
|
|
1542
|
+
getListItemsDescription(): FoehnListItemDescription<MyItem>[] {
|
|
1543
|
+
return [
|
|
1544
|
+
{
|
|
1545
|
+
label: 'Name',
|
|
1546
|
+
getFormattedValue: (item: MyItem) => item.name ?? '',
|
|
1547
|
+
},
|
|
1548
|
+
];
|
|
1549
|
+
}
|
|
1550
|
+
```
|
|
1551
|
+
|
|
1552
|
+
The same applies to the function passed to `getListItemTitle`, which now receives a `MyItem`.
|
|
1553
|
+
|
|
1554
|
+
Bind the list with `[(model)]`, never with a one-way `[model]` (see also "Quick fix"): the component removes the
|
|
1555
|
+
items itself, and only a two-way binding passes the new list to your form. A one-way `[model]` compiles without
|
|
1556
|
+
warning, but the removed item stays in the form and comes back when the form is saved. With the strict mode, guard
|
|
1557
|
+
the form rather than binding `[model]="form?.items"`:
|
|
1558
|
+
|
|
1559
|
+
```html
|
|
1560
|
+
@if (form) {
|
|
1561
|
+
<foehn-list-summary
|
|
1562
|
+
name="items"
|
|
1563
|
+
[(model)]="form.items"
|
|
1564
|
+
(itemRemoved)="itemRemoved()"
|
|
1565
|
+
/>
|
|
1566
|
+
}
|
|
1567
|
+
```
|
|
1568
|
+
|
|
1569
|
+
### `core-js` is no longer needed (since 19.2.0)
|
|
1570
|
+
|
|
1571
|
+
prestations-ng no longer imports `core-js` and no longer has it as a peer dependency. If your project does not
|
|
1572
|
+
import `core-js` itself, uninstall it:
|
|
1573
|
+
|
|
1574
|
+
```bash
|
|
1575
|
+
npm uninstall core-js
|
|
1576
|
+
```
|
|
1577
|
+
|
|
1578
|
+
Then, in your `angular.json` file, remove `"core-js/modules/es.array.includes"` from `"allowedCommonJsDependencies"`.
|
|
1579
|
+
The CommonJS dependencies of prestations-ng are now `"iban"` and `"dayjs"` (which also covers `dayjs/plugin/*` and
|
|
1580
|
+
`dayjs/locale/*`):
|
|
1581
|
+
|
|
1582
|
+
```json
|
|
1583
|
+
"allowedCommonJsDependencies": ["iban", "dayjs"]
|
|
1584
|
+
```
|
|
1585
|
+
|
|
1586
|
+
Also remove the packages that are no longer installed (`npm ls <package>` lists nothing).
|
|
1587
|
+
|
|
1588
|
+
### Zoneless (optional but recommended)
|
|
1589
|
+
|
|
1590
|
+
Since v19.2, prestations-ng does not need zone.js anymore: the state of its components is held by signals, which
|
|
1591
|
+
tell Angular when a component has to be refreshed. prestations-ng keeps working in an application using zone.js,
|
|
1592
|
+
so this step is optional, but a zoneless application is lighter, faster and easier to debug. See the
|
|
1593
|
+
[Angular zoneless guide](https://angular.dev/guide/zoneless).
|
|
1594
|
+
|
|
1595
|
+
In any case, if your code reads some fields of the prestations-ng components (e.g. through `viewChild()` or in
|
|
1596
|
+
your tests), check the fields that are now signals in the [CHANGELOG](CHANGELOG.md#1920---should-be-aligned-with-prestations-be-192x).
|
|
1597
|
+
|
|
1598
|
+
#### Enable the zoneless change detection
|
|
1599
|
+
|
|
1600
|
+
Zoneless is the default since Angular 21: `ng update` added `provideZoneChangeDetection()` to keep zone.js in your
|
|
1601
|
+
application. Replace it in your `app.config.ts` (`providePrestationsNgCore()` already provides
|
|
1602
|
+
`provideBrowserGlobalErrorListeners()`, which reports to your `ErrorHandler` the errors zone.js used to catch):
|
|
1603
|
+
|
|
1604
|
+
```diff
|
|
1605
|
+
export const appConfig: ApplicationConfig = {
|
|
1606
|
+
providers: [
|
|
1607
|
+
- provideZoneChangeDetection({ eventCoalescing: true }),
|
|
1608
|
+
+ provideZonelessChangeDetection(),
|
|
1609
|
+
providePrestationsNgCore(),
|
|
1610
|
+
...
|
|
1611
|
+
],
|
|
1612
|
+
};
|
|
1613
|
+
```
|
|
1614
|
+
|
|
1615
|
+
Remove `zone.js` and `zone.js/testing` from the `polyfills` of the `build` and `test` targets in your
|
|
1616
|
+
`angular.json` (and from your `polyfills.ts` file if you still have one): without them, the `TestBed` is zoneless
|
|
1617
|
+
too.
|
|
1618
|
+
|
|
1619
|
+
```diff
|
|
1620
|
+
"polyfills": [
|
|
1621
|
+
- "zone.js"
|
|
1622
|
+
],
|
|
1623
|
+
```
|
|
1624
|
+
|
|
1625
|
+
then uninstall zone.js:
|
|
1626
|
+
|
|
1627
|
+
```bash
|
|
1628
|
+
npm uninstall zone.js
|
|
1629
|
+
```
|
|
1630
|
+
|
|
1631
|
+
`zone.js` can stay in your `package-lock.json` as an optional peer dependency of `@angular/core`: this is expected. Check
|
|
1632
|
+
instead that the build of your application no longer outputs a `polyfills` chunk (unless you still have other
|
|
1633
|
+
polyfills, e.g. `@angular/localize/init`).
|
|
1634
|
+
|
|
1635
|
+
#### Check your components
|
|
1636
|
+
|
|
1637
|
+
Without zone.js, Angular refreshes a component only when it is notified that something changed:
|
|
1638
|
+
|
|
1639
|
+
- a listener of its template has been called (`(click)`, `(modelChange)`, `(userInput)`...), including the
|
|
1640
|
+
`[(model)]` two-way bindings
|
|
1641
|
+
- a signal read by its template has changed (`signal()`, `computed()`, `input()`, `model()`, `toSignal()`...)
|
|
1642
|
+
- `ChangeDetectorRef.markForCheck()` has been called, which is what the `async` pipe does when an observable emits
|
|
1643
|
+
|
|
1644
|
+
A field modified elsewhere (in a `subscribe()`, a `setTimeout()`, a `Promise`, a callback, an `effect()`...) is not
|
|
1645
|
+
displayed anymore until something else refreshes the component. Hold it in a signal (see
|
|
1646
|
+
[INTRODUCTION_ANGULAR_SIGNALS.md](INTRODUCTION_ANGULAR_SIGNALS.md)), as well as the fields read by the template that
|
|
1647
|
+
only a method called by a listener modifies: this method can later be called from elsewhere.
|
|
1648
|
+
|
|
1649
|
+
```diff
|
|
1650
|
+
- isLoading = true;
|
|
1651
|
+
+ readonly isLoading = signal(true);
|
|
1652
|
+
|
|
1653
|
+
ngOnInit(): void {
|
|
1654
|
+
this.myService.load().subscribe(() => {
|
|
1655
|
+
- this.isLoading = false;
|
|
1656
|
+
+ this.isLoading.set(false);
|
|
1657
|
+
});
|
|
1658
|
+
}
|
|
1659
|
+
```
|
|
1660
|
+
|
|
1661
|
+
```diff
|
|
1662
|
+
- @if (isLoading) {
|
|
1663
|
+
+ @if (isLoading()) {
|
|
1664
|
+
```
|
|
1665
|
+
|
|
1666
|
+
Pay attention to:
|
|
1667
|
+
|
|
1668
|
+
- your pages (`AbstractPageComponent` and its subclasses): `form` can't be a signal. prestations-ng refreshes them
|
|
1669
|
+
when it sets `form` and `reference`, but whenever your code modifies the form, call `markForCheck()` once after the
|
|
1670
|
+
modifications, whoever calls the method: a listener, an asynchronous callback (e.g. the one given to
|
|
1671
|
+
`SessionInfoWithApplicationService.prefillForm()` or a `subscribe()` of your own service), an `effect()`... A
|
|
1672
|
+
signal modified next to the form doesn't replace it: `set()` notifies Angular only when the value changes.
|
|
1673
|
+
|
|
1674
|
+
```ts
|
|
1675
|
+
private readonly changeDetectorRef = inject(ChangeDetectorRef);
|
|
1676
|
+
|
|
1677
|
+
ngOnInit(): void {
|
|
1678
|
+
super.ngOnInit();
|
|
1679
|
+
this.sessionInfoWithApplicationService.prefillForm((info) => {
|
|
1680
|
+
if (this.form) {
|
|
1681
|
+
this.form.firstName = info?.firstName ?? null;
|
|
1682
|
+
this.form.lastName = info?.lastName ?? null;
|
|
1683
|
+
this.changeDetectorRef.markForCheck();
|
|
1684
|
+
}
|
|
1685
|
+
});
|
|
1686
|
+
}
|
|
1687
|
+
```
|
|
1688
|
+
|
|
1689
|
+
- the fields read by the template and set in `ngAfterViewInit()`, `ngAfterContentInit()` or `ngAfterViewChecked()`:
|
|
1690
|
+
derive them with `computed()` from `viewChild()` or `contentChild()` (see "Deriving a state from view queries"
|
|
1691
|
+
in [GOOD_PRACTICES.md](GOOD_PRACTICES.md)).
|
|
1692
|
+
|
|
1693
|
+
- `NgZone`: `onStable`, `onMicrotaskEmpty` and `onUnstable` never emit without zone.js, and `run()` or
|
|
1694
|
+
`runOutsideAngular()` are useless. To act on the rendered DOM (focus, scroll...), replace them, as well as the
|
|
1695
|
+
`setTimeout()` waiting for the view, by `afterNextRender()`. `AbstractMenuPageComponent.ngZone` is deprecated.
|
|
1696
|
+
|
|
1697
|
+
```diff
|
|
1698
|
+
- this.ngZone.onStable.pipe(first()).subscribe(() => this.focusFirstField());
|
|
1699
|
+
+ afterNextRender(() => this.focusFirstField(), { injector: this.injector });
|
|
1700
|
+
```
|
|
1701
|
+
|
|
1702
|
+
#### Check your tests
|
|
1703
|
+
|
|
1704
|
+
- `fakeAsync()`, `tick()`, `flush()` and `waitForAsync()` need zone.js: write `async` tests, with
|
|
1705
|
+
`vi.useFakeTimers()` and `await vi.advanceTimersByTimeAsync(ms)` to control the timers (see
|
|
1706
|
+
[Migrate to vitest](#migrate-to-vitest)).
|
|
1707
|
+
- `fixture.detectChanges()` only refreshes the views which have been notified, then checks that nothing changed
|
|
1708
|
+
meanwhile: a field modified without notification makes the test fail with the error `NG0100`
|
|
1709
|
+
(`ExpressionChangedAfterItHasBeenCheckedError`). Fix the component (signal, `markForCheck()`) rather than the
|
|
1710
|
+
test.
|
|
1711
|
+
- `await fixture.whenStable()` waits for the change detection and for the pending tasks of the application
|
|
1712
|
+
(e.g. the debounced `userInput` of the prestations-ng inputs), not for the timers, nor for the HTTP requests of a
|
|
1713
|
+
spec: `provideHttpClientTesting()` keeps them pending until the test answers them. Answer them first with
|
|
1714
|
+
`HttpTestingController` (`expectOne(...).flush(...)`), then `await fixture.whenStable()`.
|
|
1715
|
+
|
|
1452
1716
|
### Last but not least, check if your application is working!!!
|
|
1453
1717
|
|
|
1454
1718
|
#### Be sure your application gets a fresh start
|
|
@@ -1488,7 +1752,8 @@ See [getImtPortailApplications](https://dsigit.etat-de-vaud.ch/outils/git/projec
|
|
|
1488
1752
|
'project': 'cybersdk',
|
|
1489
1753
|
'name' : 'skeleton',
|
|
1490
1754
|
'gitUrl' : 'ssh://git@bitbucket.etat-de-vaud.ch/cybsdk/skeleton.git',
|
|
1491
|
-
|
|
1755
|
+
- 'jdk' : '21',
|
|
1756
|
+
+ 'jdk' : '25',
|
|
1492
1757
|
- 'node' : '20'
|
|
1493
1758
|
+ 'node' : '22'
|
|
1494
1759
|
],
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The house preset of the Vitest specs: the recommended rules of `@vitest/eslint-plugin`, with the
|
|
3
|
+
* assertions also made by the helpers of the specs and by the `HttpTestingController`.
|
|
4
|
+
*
|
|
5
|
+
* Meant for the `extends` of a `**\/*.spec.ts` block (the Cypress `*.spec.cy.ts` files are not
|
|
6
|
+
* Vitest specs).
|
|
7
|
+
*
|
|
8
|
+
* @param {import('@vitest/eslint-plugin').default} vitest the `@vitest/eslint-plugin` module
|
|
9
|
+
* @returns {import('typescript-eslint').ConfigArray}
|
|
10
|
+
*/
|
|
11
|
+
const specTsRecommended = (vitest) => [
|
|
12
|
+
vitest.configs.recommended,
|
|
13
|
+
{
|
|
14
|
+
name: 'prestations-ng/spec-ts-recommended',
|
|
15
|
+
rules: {
|
|
16
|
+
'vitest/expect-expect': [
|
|
17
|
+
'error',
|
|
18
|
+
{
|
|
19
|
+
assertFunctionNames: [
|
|
20
|
+
'expect',
|
|
21
|
+
'expect*',
|
|
22
|
+
'assert*',
|
|
23
|
+
'test*',
|
|
24
|
+
'*.expectOne',
|
|
25
|
+
'*.expectNone',
|
|
26
|
+
'*.verify',
|
|
27
|
+
],
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
export default specTsRecommended;
|
|
@@ -8,6 +8,8 @@ import templateRules from './template-rules.mjs';
|
|
|
8
8
|
*
|
|
9
9
|
* Meant for the `extends` of a `**\/*.html` block. It brings its own parser and plugins,
|
|
10
10
|
* so do not spread `angular.configs.templateRecommended` alongside it.
|
|
11
|
+
*
|
|
12
|
+
* @returns {import('typescript-eslint').ConfigArray}
|
|
11
13
|
*/
|
|
12
14
|
const templateRecommended = (plugin) => [
|
|
13
15
|
...angular.configs.templateRecommended,
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import templateBase from './template-base.mjs';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Only the rules written by this library. `templateRecommended` includes it, alongside
|
|
5
|
+
* the house style; use this layer directly to opt out of the latter.
|
|
6
|
+
*
|
|
7
|
+
* @returns {import('typescript-eslint').ConfigArray}
|
|
8
|
+
*/
|
|
5
9
|
const templateRules = (plugin) => [
|
|
6
10
|
templateBase(plugin),
|
|
7
11
|
{
|
|
@@ -14,6 +14,8 @@ import tsRules from './ts-rules.mjs';
|
|
|
14
14
|
* Meant for the `extends` of a `**\/*.ts` block. It brings its own parser and plugins,
|
|
15
15
|
* so do not spread `angular.configs.tsRecommended` alongside it — declaring the same
|
|
16
16
|
* plugin twice from two different copies makes ESLint fail outright.
|
|
17
|
+
*
|
|
18
|
+
* @returns {import('typescript-eslint').ConfigArray}
|
|
17
19
|
*/
|
|
18
20
|
const tsRecommended = (plugin) => [
|
|
19
21
|
eslint.configs.recommended,
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import tsBase from './ts-base.mjs';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Only the rules written by this library. `tsRecommended` includes it, alongside the
|
|
5
|
+
* house style; use this layer directly to opt out of the latter.
|
|
6
|
+
*
|
|
7
|
+
* @returns {import('typescript-eslint').ConfigArray}
|
|
8
|
+
*/
|
|
5
9
|
const tsRules = (plugin) => [
|
|
6
10
|
tsBase(plugin),
|
|
7
11
|
{
|
package/eslint/index.mjs
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
import specTsRecommended from './configs/spec-ts-recommended.mjs';
|
|
1
2
|
import templateRecommended from './configs/template-recommended.mjs';
|
|
2
3
|
import templateRules from './configs/template-rules.mjs';
|
|
3
4
|
import tsRecommended from './configs/ts-recommended.mjs';
|
|
4
5
|
import tsRules from './configs/ts-rules.mjs';
|
|
5
6
|
import rules from './rules/index.mjs';
|
|
6
7
|
|
|
8
|
+
// Only needed by the projects linting Vitest specs: the other configs can be used without it.
|
|
9
|
+
const vitest = await import('@vitest/eslint-plugin').then(
|
|
10
|
+
(module) => module.default,
|
|
11
|
+
() => null,
|
|
12
|
+
);
|
|
13
|
+
const specTsRecommendedConfig = vitest ? specTsRecommended(vitest) : null;
|
|
14
|
+
|
|
7
15
|
const plugin = {
|
|
8
16
|
meta: { name: '@dsivd/prestations-ng' },
|
|
9
17
|
rules,
|
|
@@ -16,6 +24,15 @@ const configs = {
|
|
|
16
24
|
// Only this library's own rules, for a project that supplies its own style.
|
|
17
25
|
tsRules: tsRules(plugin),
|
|
18
26
|
templateRules: templateRules(plugin),
|
|
27
|
+
// The preset of the Vitest specs (needs @vitest/eslint-plugin)
|
|
28
|
+
get specTsRecommended() {
|
|
29
|
+
if (!specTsRecommendedConfig) {
|
|
30
|
+
throw new Error(
|
|
31
|
+
'prestationsNg.configs.specTsRecommended needs @vitest/eslint-plugin: npm install --save-dev @vitest/eslint-plugin@1',
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
return specTsRecommendedConfig;
|
|
35
|
+
},
|
|
19
36
|
};
|
|
20
37
|
|
|
21
38
|
export { configs, plugin, rules };
|
|
@@ -241,7 +241,7 @@ function boundNameSignalKind(identifier, scopeContext, seen) {
|
|
|
241
241
|
scopeContext.sourceCode.getScope(identifier),
|
|
242
242
|
identifier.name,
|
|
243
243
|
);
|
|
244
|
-
if (
|
|
244
|
+
if (variable?.defs.length !== 1 || seen.has(variable)) {
|
|
245
245
|
return undefined;
|
|
246
246
|
}
|
|
247
247
|
seen.add(variable);
|