Skip to content

Commit 63c8809

Browse files
committed
bug #2562 [Map][Translator][Turbo] Ensure TypeScript code is valid (Kocal)
This PR was squashed before being merged into the 2.x branch. Discussion ---------- [Map][Translator][Turbo] Ensure TypeScript code is valid | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT This PR aims to fail the build (and the CI) when TypeScript code contain issues. I also fixed existing issues in Map, Translator, and Turbo code. Before: ``` Cleaning up the "/home/runner/work/ux/ux/src/Chartjs/assets/dist" directory... Building JavaScript files from `@symfony`/ux-chartjs package... Done in 3.175 seconds. Cleaning up the "/home/runner/work/ux/ux/src/Autocomplete/assets/dist" directory... Building JavaScript files from `@symfony`/ux-autocomplete package... Done in 3.179 seconds. Cleaning up the "/home/runner/work/ux/ux/src/Cropperjs/assets/dist" directory... Building JavaScript files from `@symfony`/ux-cropperjs package... Minifying CSS... Done in 2.377 seconds. Cleaning up the "/home/runner/work/ux/ux/src/Dropzone/assets/dist" directory... Building JavaScript files from `@symfony`/ux-dropzone package... Minifying CSS... Done in 2.434 seconds. Cleaning up the "/home/runner/work/ux/ux/src/LazyImage/assets/dist" directory... Building JavaScript files from `@symfony`/ux-lazy-image package... Done in 2.438 seconds. Cleaning up the "/home/runner/work/ux/ux/src/LiveComponent/assets/dist" directory... Building JavaScript files from `@symfony`/ux-live-component package... Minifying CSS... Done in 3.861 seconds. Cleaning up the "/home/runner/work/ux/ux/src/Map/assets/dist" directory... Building JavaScript files from `@symfony`/ux-map package... Done in 2.515 seconds. Cleaning up the "/home/runner/work/ux/ux/src/Map/src/Bridge/Google/assets/dist" directory... Building JavaScript files from `@symfony`/ux-google-map package... Done in 2.509 seconds. [plugin typescript] src/map_controller.ts (12:35): `@rollup`/plugin-typescript TS2307: Cannot find module '`@symfony`/ux-map' or its corresponding type declarations. [plugin typescript] src/map_controller.ts (19:8): `@rollup`/plugin-typescript TS2307: Cannot find module '`@symfony`/ux-map' or its corresponding type declarations. [plugin typescript] src/map_controller.ts (78:21): `@rollup`/plugin-typescript TS7053: Element implicitly has an 'any' type because expression of type 'Library' can't be used to index type 'typeof maps'. Property 'streetView' does not exist on type 'typeof maps'. [plugin typescript] src/map_controller.ts (80:55): `@rollup`/plugin-typescript TS2698: Spread types may only be created from object types. [plugin typescript] src/map_controller.ts (89:30): `@rollup`/plugin-typescript TS2339: Property 'hasCenterValue' does not exist on type 'default'. [plugin typescript] src/map_controller.ts (89:53): `@rollup`/plugin-typescript TS2339: Property 'centerValue' does not exist on type 'default'. [plugin typescript] src/map_controller.ts (90:37): `@rollup`/plugin-typescript TS2339: Property 'centerValue' does not exist on type 'default'. [plugin typescript] src/map_controller.ts (95:30): `@rollup`/plugin-typescript TS2339: Property 'hasZoomValue' does not exist on type 'default'. [plugin typescript] src/map_controller.ts (95:51): `@rollup`/plugin-typescript TS2339: Property 'zoomValue' does not exist on type 'default'. [plugin typescript] src/map_controller.ts (96:35): `@rollup`/plugin-typescript TS2339: Property 'zoomValue' does not exist on type 'default'. [plugin typescript] src/map_controller.ts (101:14): `@rollup`/plugin-typescript TS2339: Property 'dispatch' does not exist on type 'default'. [plugin typescript] src/map_controller.ts (125:42): `@rollup`/plugin-typescript TS2339: Property 'element' does not exist on type 'default'. [plugin typescript] src/map_controller.ts (148:18): `@rollup`/plugin-typescript TS2551: Property 'createInfoWindow' does not exist on type 'default'. Did you mean 'doCreateInfoWindow'? [plugin typescript] src/map_controller.ts (176:18): `@rollup`/plugin-typescript TS2551: Property 'createInfoWindow' does not exist on type 'default'. Did you mean 'doCreateInfoWindow'? [plugin typescript] src/map_controller.ts (204:18): `@rollup`/plugin-typescript TS2551: Property 'createInfoWindow' does not exist on type 'default'. Did you mean 'doCreateInfoWindow'? [plugin typescript] src/map_controller.ts (264:18): `@rollup`/plugin-typescript TS2339: Property 'markers' does not exist on type 'default'. [plugin typescript] src/map_controller.ts (269:14): `@rollup`/plugin-typescript TS2339: Property 'markers' does not exist on type 'default'. [plugin typescript] src/map_controller.ts (269:31): `@rollup`/plugin-typescript TS7006: Parameter 'marker' implicitly has an 'any' type. [plugin typescript] src/map_controller.ts (296:14): `@rollup`/plugin-typescript TS2339: Property 'infoWindows' does not exist on type 'default'. [plugin typescript] src/map_controller.ts (296:35): `@rollup`/plugin-typescript TS7006: Parameter 'otherInfoWindow' implicitly has an 'any' type. Cleaning up the "/home/runner/work/ux/ux/src/Map/src/Bridge/Leaflet/assets/dist" directory... Building JavaScript files from `@symfony`/ux-leaflet-map package... Done in 2.459 seconds. "leaflet/dist/leaflet.min.css" is imported by "src/map_controller.ts", but could not be resolved – treating it as an external dependency. Cleaning up the "/home/runner/work/ux/ux/src/Notify/assets/dist" directory... Building JavaScript files from `@symfony`/ux-notify package... Done in 2.381 seconds. Cleaning up the "/home/runner/work/ux/ux/src/React/assets/dist" directory... Building JavaScript files from `@symfony`/ux-react package... Done in 2.498 seconds. Cleaning up the "/home/runner/work/ux/ux/src/StimulusBundle/assets/dist" directory... Building JavaScript files from `@symfony`/stimulus-bundle package... Done in 2.444 seconds. Cleaning up the "/home/runner/work/ux/ux/src/Svelte/assets/dist" directory... Building JavaScript files from `@symfony`/ux-svelte package... Done in 2.453 seconds. Cleaning up the "/home/runner/work/ux/ux/src/Swup/assets/dist" directory... Building JavaScript files from `@symfony`/ux-swup package... Done in 2.254 seconds. Cleaning up the "/home/runner/work/ux/ux/src/TogglePassword/assets/dist" directory... Building JavaScript files from `@symfony`/ux-toggle-password package... Minifying CSS... Done in 2.489 seconds. Cleaning up the "/home/runner/work/ux/ux/src/Translator/assets/dist" directory... Building JavaScript files from `@symfony`/ux-translator package... Done in 2.351 seconds. [plugin typescript] src/formatters/intl-formatter.ts (26:5): `@rollup`/plugin-typescript TS2[32](https://github.com/symfony/ux/actions/runs/13231659169/job/36929714748#step:5:37)2: Type 'string | number | (string | number)[]' is not assignable to type 'string'. Type 'number' is not assignable to type 'string'. [plugin typescript] src/translator.ts (152:57): `@rollup`/plugin-typescript TS2[34](https://github.com/symfony/ux/actions/runs/13231659169/job/36929714748#step:5:39)5: Argument of type 'ParametersType' is not assignable to parameter of type 'Record<string, string | number>'. Type 'Record<string, string | number | Date>' is not assignable to type 'Record<string, string | number>'. 'string' index signatures are incompatible. Type 'string | number | Date' is not assignable to type 'string | number'. [plugin typescript] src/translator.ts (166:49): `@rollup`/plugin-typescript TS2345: Argument of type 'ParametersType' is not assignable to parameter of type 'Record<string, string | number>'. Type 'Record<string, string | number | Date>' is not assignable to type 'Record<string, string | number>'. Cleaning up the "/home/runner/work/ux/ux/src/Turbo/assets/dist" directory... Building JavaScript files from `@symfony`/ux-turbo package... Done in 2.2[49](https://github.com/symfony/ux/actions/runs/13231659169/job/36929714748#step:5:54) seconds. [plugin typescript] src/turbo_stream_controller.ts (11:61): `@rollup`/plugin-typescript TS7016: Could not find a declaration file for module '`@hotwired`/turbo'. '/home/runner/work/ux/ux/node_modules/`@hotwired`/turbo/dist/turbo.es2017-umd.js' implicitly has an 'any' type. Try `npm i --save-dev `@types`/hotwired__turbo` if it exists or add a new declaration (.d.ts) file containing `declare module '`@hotwired`/turbo';` Cleaning up the "/home/runner/work/ux/ux/src/Typed/assets/dist" directory... Building JavaScript files from `@symfony`/ux-typed package... Done in 2.228 seconds. Cleaning up the "/home/runner/work/ux/ux/src/Vue/assets/dist" directory... Building JavaScript files from `@symfony`/ux-vue package... Done in 1.970 seconds. Done in 30s 328ms ``` After: ``` Cleaning up the "/home/runner/work/symfony-ux/symfony-ux/src/Chartjs/assets/dist" directory... Building JavaScript files from `@symfony`/ux-chartjs package... Done in 2.830 seconds. Cleaning up the "/home/runner/work/symfony-ux/symfony-ux/src/Autocomplete/assets/dist" directory... Building JavaScript files from `@symfony`/ux-autocomplete package... Done in 2.967 seconds. Cleaning up the "/home/runner/work/symfony-ux/symfony-ux/src/Cropperjs/assets/dist" directory... Building JavaScript files from `@symfony`/ux-cropperjs package... Minifying CSS... Done in 2.[39](https://github.com/Kocal/symfony-ux/actions/runs/13252531380/job/36993303948?pr=2562#step:5:44)2 seconds. Cleaning up the "/home/runner/work/symfony-ux/symfony-ux/src/Dropzone/assets/dist" directory... Building JavaScript files from `@symfony`/ux-dropzone package... Minifying CSS... Done in 2.[42](https://github.com/Kocal/symfony-ux/actions/runs/13252531380/job/36993303948?pr=2562#step:5:47)8 seconds. Cleaning up the "/home/runner/work/symfony-ux/symfony-ux/src/LazyImage/assets/dist" directory... Building JavaScript files from `@symfony`/ux-lazy-image package... Done in 2.472 seconds. Cleaning up the "/home/runner/work/symfony-ux/symfony-ux/src/LiveComponent/assets/dist" directory... Building JavaScript files from `@symfony`/ux-live-component package... Minifying CSS... Done in 3.855 seconds. Cleaning up the "/home/runner/work/symfony-ux/symfony-ux/src/Map/assets/dist" directory... Building JavaScript files from `@symfony`/ux-map package... Done in 2.[47](https://github.com/Kocal/symfony-ux/actions/runs/13252531380/job/36993303948?pr=2562#step:5:52)1 seconds. Cleaning up the "/home/runner/work/symfony-ux/symfony-ux/src/Notify/assets/dist" directory... Building JavaScript files from `@symfony`/ux-notify package... Done in 2.392 seconds. Cleaning up the "/home/runner/work/symfony-ux/symfony-ux/src/React/assets/dist" directory... Building JavaScript files from `@symfony`/ux-react package... Done in 2.597 seconds. Cleaning up the "/home/runner/work/symfony-ux/symfony-ux/src/StimulusBundle/assets/dist" directory... Building JavaScript files from `@symfony`/stimulus-bundle package... Done in 2.[48](https://github.com/Kocal/symfony-ux/actions/runs/13252531380/job/36993303948?pr=2562#step:5:53)4 seconds. Cleaning up the "/home/runner/work/symfony-ux/symfony-ux/src/Svelte/assets/dist" directory... Building JavaScript files from `@symfony`/ux-svelte package... Done in 2.470 seconds. Cleaning up the "/home/runner/work/symfony-ux/symfony-ux/src/Swup/assets/dist" directory... Building JavaScript files from `@symfony`/ux-swup package... Done in 2.264 seconds. Cleaning up the "/home/runner/work/symfony-ux/symfony-ux/src/TogglePassword/assets/dist" directory... Building JavaScript files from `@symfony`/ux-toggle-password package... Minifying CSS... Done in 2.[57](https://github.com/Kocal/symfony-ux/actions/runs/13252531380/job/36993303948?pr=2562#step:5:62)2 seconds. Cleaning up the "/home/runner/work/symfony-ux/symfony-ux/src/Translator/assets/dist" directory... Building JavaScript files from `@symfony`/ux-translator package... Done in 2.[58](https://github.com/Kocal/symfony-ux/actions/runs/13252531380/job/36993303948?pr=2562#step:5:63)1 seconds. Cleaning up the "/home/runner/work/symfony-ux/symfony-ux/src/Turbo/assets/dist" directory... Building JavaScript files from `@symfony`/ux-turbo package... Done in 2.296 seconds. Cleaning up the "/home/runner/work/symfony-ux/symfony-ux/src/Typed/assets/dist" directory... Building JavaScript files from `@symfony`/ux-typed package... Done in 2.273 seconds. Cleaning up the "/home/runner/work/symfony-ux/symfony-ux/src/Vue/assets/dist" directory... Building JavaScript files from `@symfony`/ux-vue package... Done in 2.083 seconds. Cleaning up the "/home/runner/work/symfony-ux/symfony-ux/src/Map/src/Bridge/Google/assets/dist" directory... Building JavaScript files from `@symfony`/ux-google-map package... Done in 2.579 seconds. Cleaning up the "/home/runner/work/symfony-ux/symfony-ux/src/Map/src/Bridge/Leaflet/assets/dist" directory... Building JavaScript files from `@symfony`/ux-leaflet-map package... Done in 2.742 seconds. "leaflet/dist/leaflet.min.css" is imported by "src/map_controller.ts", but could not be resolved – treating it as an external dependency. Done in 30s [68](https://github.com/Kocal/symfony-ux/actions/runs/13252531380/job/36993303948?pr=2562#step:5:73)6ms ``` Commits ------- ddbabd6 [Map] Fix TypeScript errors 975628b [Translator] Fix types definition, allow `Date` as parameter type 07b5078 Stop packages build when TypeScript code is invalid 795f2ad [Turbo] Install missing ``@hotwired`/turbo` definition types 863ba8c Fix ``@symfony`/ux-*-map` dev dependency, use `--topological-dev` to ensure `build` and `test` scripts respect workspaces topoligy
2 parents 3e99eb2 + ddbabd6 commit 63c8809

File tree

14 files changed

+34
-12
lines changed

14 files changed

+34
-12
lines changed

bin/rollup.js

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ function getRollupConfiguration({ packageRoot, inputFiles }) {
108108
typescript({
109109
filterRoot: '.',
110110
tsconfig: path.join(__dirname, '..', 'tsconfig.json'),
111+
noEmitOnError: true,
111112
include: [
112113
'src/**/*.ts',
113114
// TODO: Remove for the next major release

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"src/*/src/Bridge/*/assets"
77
],
88
"scripts": {
9-
"build": "yarn workspaces foreach -Apt run build",
10-
"test": "yarn workspaces foreach -Apt run test",
9+
"build": "yarn workspaces foreach -Ap --topological-dev run build",
10+
"test": "yarn workspaces foreach -Ap --topological-dev run test",
1111
"check": "biome check",
1212
"ci": "biome ci"
1313
},

src/Map/src/Bridge/Google/assets/dist/map_controller.js

+3
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ class map_controller extends default_1 {
113113
libraries = ['core', ...libraries.filter((library) => library !== 'core')];
114114
const librariesImplementations = await Promise.all(libraries.map((library) => loader.importLibrary(library)));
115115
librariesImplementations.map((libraryImplementation, index) => {
116+
if (typeof libraryImplementation !== 'object' || libraryImplementation === null) {
117+
return;
118+
}
116119
const library = libraries[index];
117120
if (['marker', 'places', 'geometry', 'journeySharing', 'drawing', 'visualization'].includes(library)) {
118121
_google.maps[library] = libraryImplementation;

src/Map/src/Bridge/Google/assets/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"devDependencies": {
4141
"@googlemaps/js-api-loader": "^1.16.6",
4242
"@hotwired/stimulus": "^3.0.0",
43+
"@symfony/ux-map": "workspace:*",
4344
"@types/google.maps": "^3.55.9"
4445
}
4546
}

src/Map/src/Bridge/Google/assets/src/map_controller.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,16 @@ export default class extends AbstractMapController<
7171
libraries.map((library) => loader.importLibrary(library))
7272
);
7373
librariesImplementations.map((libraryImplementation, index) => {
74+
if (typeof libraryImplementation !== 'object' || libraryImplementation === null) {
75+
return;
76+
}
77+
7478
const library = libraries[index];
7579

7680
// The following libraries are in a sub-namespace
7781
if (['marker', 'places', 'geometry', 'journeySharing', 'drawing', 'visualization'].includes(library)) {
78-
_google.maps[library] = libraryImplementation;
82+
// @ts-ignore
83+
_google.maps[library] = libraryImplementation as any;
7984
} else {
8085
_google.maps = { ..._google.maps, ...libraryImplementation };
8186
}

src/Map/src/Bridge/Leaflet/assets/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
},
4040
"devDependencies": {
4141
"@hotwired/stimulus": "^3.0.0",
42+
"@symfony/ux-map": "workspace:*",
4243
"@types/leaflet": "^1.9.12",
4344
"leaflet": "^1.9.4"
4445
}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export declare function format(id: string, parameters: Record<string, string | number>, locale: string): string;
1+
export declare function format(id: string, parameters: Record<string, string | number | Date>, locale: string): string;
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export declare function formatIntl(id: string, parameters: Record<string, string | number>, locale: string): string;
1+
export declare function formatIntl(id: string, parameters: Record<string, string | number | Date>, locale: string): string;

src/Translator/assets/dist/utils.d.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export declare function strtr(string: string, replacePairs: Record<string, string | number>): string;
1+
export declare function strtr(string: string, replacePairs: Record<string, string | number | Date>): string;

src/Translator/assets/src/formatters/formatter.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import { strtr } from '../utils';
4747
* @param parameters An array of parameters for the message
4848
* @param locale The locale
4949
*/
50-
export function format(id: string, parameters: Record<string, string | number>, locale: string): string {
50+
export function format(id: string, parameters: Record<string, string | number | Date>, locale: string): string {
5151
if (null === id || '' === id) {
5252
return '';
5353
}

src/Translator/assets/src/formatters/intl-formatter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { IntlMessageFormat } from 'intl-messageformat';
77
* @param parameters An array of parameters for the message
88
* @param locale The locale
99
*/
10-
export function formatIntl(id: string, parameters: Record<string, string | number>, locale: string): string {
10+
export function formatIntl(id: string, parameters: Record<string, string | number | Date>, locale: string): string {
1111
if (id === '') {
1212
return '';
1313
}
@@ -23,5 +23,5 @@ export function formatIntl(id: string, parameters: Record<string, string | numbe
2323
}
2424
});
2525

26-
return intlMessage.format(parameters);
26+
return intlMessage.format(parameters) as string;
2727
}

src/Translator/assets/src/utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @param string The string to replace in
77
* @param replacePairs The pairs of characters to replace
88
*/
9-
export function strtr(string: string, replacePairs: Record<string, string | number>): string {
9+
export function strtr(string: string, replacePairs: Record<string, string | number | Date>): string {
1010
const regex: Array<string> = Object.entries(replacePairs).map(([from]) => {
1111
return from.replace(/([-[\]{}()*+?.\\^$|#,])/g, '\\$1');
1212
});

src/Turbo/assets/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
},
3939
"devDependencies": {
4040
"@hotwired/stimulus": "^3.0.0",
41-
"@hotwired/turbo": "^7.1.0 || ^8.0"
41+
"@hotwired/turbo": "^7.1.0 || ^8.0",
42+
"@types/hotwired__turbo": "^8.0.4"
4243
}
4344
}

yarn.lock

+11-1
Original file line numberDiff line numberDiff line change
@@ -2888,6 +2888,7 @@ __metadata:
28882888
dependencies:
28892889
"@googlemaps/js-api-loader": "npm:^1.16.6"
28902890
"@hotwired/stimulus": "npm:^3.0.0"
2891+
"@symfony/ux-map": "workspace:*"
28912892
"@types/google.maps": "npm:^3.55.9"
28922893
peerDependencies:
28932894
"@googlemaps/js-api-loader": ^1.16.6
@@ -2913,6 +2914,7 @@ __metadata:
29132914
resolution: "@symfony/ux-leaflet-map@workspace:src/Map/src/Bridge/Leaflet/assets"
29142915
dependencies:
29152916
"@hotwired/stimulus": "npm:^3.0.0"
2917+
"@symfony/ux-map": "workspace:*"
29162918
"@types/leaflet": "npm:^1.9.12"
29172919
leaflet: "npm:^1.9.4"
29182920
peerDependencies:
@@ -2939,7 +2941,7 @@ __metadata:
29392941
languageName: unknown
29402942
linkType: soft
29412943

2942-
"@symfony/ux-map@workspace:src/Map/assets":
2944+
"@symfony/ux-map@workspace:*, @symfony/ux-map@workspace:src/Map/assets":
29432945
version: 0.0.0-use.local
29442946
resolution: "@symfony/ux-map@workspace:src/Map/assets"
29452947
dependencies:
@@ -3040,6 +3042,7 @@ __metadata:
30403042
dependencies:
30413043
"@hotwired/stimulus": "npm:^3.0.0"
30423044
"@hotwired/turbo": "npm:^7.1.0 || ^8.0"
3045+
"@types/hotwired__turbo": "npm:^8.0.4"
30433046
peerDependencies:
30443047
"@hotwired/stimulus": ^3.0.0
30453048
"@hotwired/turbo": ^7.1.1 || ^8.0
@@ -3278,6 +3281,13 @@ __metadata:
32783281
languageName: node
32793282
linkType: hard
32803283

3284+
"@types/hotwired__turbo@npm:^8.0.4":
3285+
version: 8.0.4
3286+
resolution: "@types/hotwired__turbo@npm:8.0.4"
3287+
checksum: 10c0/87fb69ea0dab21fd2a6e3e6d18cdaf679e3d7c8ea1f6f2b59d05c24a96cf3faf80a4c0ce5f57161afea9b61f2cc542f9e33cbdc6475fc4003d79516a94cedb5c
3288+
languageName: node
3289+
linkType: hard
3290+
32813291
"@types/istanbul-lib-coverage@npm:*, @types/istanbul-lib-coverage@npm:^2.0.0, @types/istanbul-lib-coverage@npm:^2.0.1":
32823292
version: 2.0.4
32833293
resolution: "@types/istanbul-lib-coverage@npm:2.0.4"

0 commit comments

Comments
 (0)