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

Add some type packages #2347

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

PolariTOON
Copy link
Contributor

@PolariTOON PolariTOON commented Feb 3, 2023

This is kept as a draft, as this is not meant to be merged as is.
The changes are not needed to migrate to TypeScript, but should ease gradually renaming files from *.js{x} to *.ts{x}.
This also updates and adds some packages to get types on which to build upon to declare ours.

On another note, while exploring what could be done to migrate, I also faced another issue that is we are not able to import *.styl files from *.ts{x} files apparently.
This is not handled in this PR.

Demo link : https://polaritoon.github.io/cozy-ui/react/ (just to show it builds)

@bundlemon
Copy link

bundlemon bot commented Feb 3, 2023

BundleMon

Unchanged files (2)
Status Path Size Limits
dist/cozy-ui.min.css
19.67KB +5%
dist/cozy-ui.utils.min.css
9.99KB +5%

No change in files bundle size

Groups updated (1)
Status Path Size Limits
transpiled/react/**
606.77KB (+52.48KB +9.47%) -

Final result: ✅

View report in BundleMon website ➡️


Current branch size history | Target branch size history

@PolariTOON
Copy link
Contributor Author

This seems to increase to size of the build significantly. Perhaps every type packages should be in devDependencies instead of dependencies 🤔

package.json Outdated
@@ -175,7 +175,7 @@
"react-pdf": "^4.0.5",
"react-popper": "^2.2.3",
"react-remove-scroll": "^2.4.0",
"react-select": "^4.3.0",
"react-select": "^5.4.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

To be checked because there is a few BC in the lib, no? https://react-select.com/upgrade

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We may be impacted by the changes on refs since we indeed use one on ReactSelect in SelectBox to measure some height. Further investigation is needed for it. The remaining BCs look ok for us.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Quel besoin d'upgrade cette lib ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This brings types without needing to install a @types package:

Convert to TypeScript - TypeScript types now come packaged with react-select so you no longer need to have @types/react-select installed; we no longer include Flow types

Copy link
Contributor Author

Choose a reason for hiding this comment

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

J'ai finalement retiré la montée de version de ce paquet et installé @types/react-select, ça évite d'avoir à gérer le breaking change dans cette PR, et ça évite d'avoir à mettre à jour les snapshots.

@@ -7,14 +7,16 @@ import { isIOSApp } from 'cozy-device-helper'

import Icon from '../Icon'
import CheckIcon from '../Icons/Check'
import { dodgerBlue, silver, coolGrey, paleGrey } from '../palette'
import palette from '../palette'
Copy link
Contributor

Choose a reason for hiding this comment

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

@PolariTOON are you sure that this is not this line that create this big impact on the bundle size?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are already importing the palette in this way at other places and the file doesn't weight so much, thus i don't think so.

Copy link
Collaborator

@JF-Cozy JF-Cozy left a comment

Choose a reason for hiding this comment

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

Est-ce que tu peux ajouter un peu de descriptif dans la PR pour resituer un peu le contexte de pourquoi cette PR stp ?

@@ -7,14 +7,16 @@ import { isIOSApp } from 'cozy-device-helper'

import Icon from '../Icon'
import CheckIcon from '../Icons/Check'
import { dodgerBlue, silver, coolGrey, paleGrey } from '../palette'
import palette from '../palette'
Copy link
Collaborator

Choose a reason for hiding this comment

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

pourquoi ce changement ici ? Quel intérêt ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -10,4 +10,4 @@ echo "Making icon sprite, output file : ${outfile}..."
echo $icons | xargs yarn svgstore --inline -o /tmp/icons-sprite.svg
echo "// GENERATED FILE, DO NOT EDIT THIS FILE BY HAND" > $outfile
echo "// Use yarn sprite to regenerate" >> $outfile
echo "module.exports = \``cat /tmp/icons-sprite.svg`\`" >> $outfile
echo "export default \``cat /tmp/icons-sprite.svg`\`" >> $outfile
Copy link
Collaborator

@JF-Cozy JF-Cozy Feb 6, 2023

Choose a reason for hiding this comment

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

on s'est dit y'a quelques jours qu'on n'était pas chaud pour ces modifs, pourquoi le faire à nouveau maintenant ? 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Pourquoi on n'est pas chaud de faire ce changement ? Ça va dans le bon sens, non ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@PolariTOON peux-tu retrouver la PR de référence stp ?

Cela posait des soucis il me semble au niveau des tests.
A part une écriture plus moderne, que cela apporte t-il de "mieux" ? 🤔 Y'a t-il un intérêt autre qu’esthétique ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

J'avais initialement proposé les changements ici : #2342 et on avait décidé de ne pas inclure ce commit (les commentaires ont disparu apparemment, sans doute dû au retrait du commit ?).

Effectivement ça posait un problème de test, parce que je n'avais pas fait attention que le fichier généré par make-palette.sh exporte un type de valeur bien précis : un objet, qu'on importait soit directement (import palette from '../palette') soit en destructurant (import {...} from '../palette') selon l'endroit.
Quand on utilise la syntaxe ESM pour exporter quelque chose, on doit l'importer de la même manière. Donc si on utilise un export par défaut on doit faire un import par défaut, d'où le changement dans SelectBox qui était le seul fichier à faire un import nommé jusque là.

Par rapport à l'intérêt, l'idée était juste d'avoir une base de code plus cohérente en terme de syntaxe et qu'ensuite TS puisse bien identifier les imports erronés.

scripts/make-palette.sh Show resolved Hide resolved
'../react/SwipeableDrawer',
'../react/TextareaAutosize',
'../react/Toolbar',
'../react/Zoom'
Copy link
Collaborator

Choose a reason for hiding this comment

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

attention il me semble que certains fichier nécessitent l’extension car plusieurs fichiers index dans le dossier

Copy link
Contributor

Choose a reason for hiding this comment

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

Tu as des exemples ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Effectivement j'ai eu des soucis avec ça, mais le message d'erreur du styleguide n'est pas bien clair dont je n'ai pas identifié précisément où était le problème.
J'ai adapté ce commit pour conserver le /index partout et juste retirer l'extension, car c'était plutôt ça l'objectif à la base.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

J'ai parlé trop vite. Je pensais que c'était réglé parce que je n'avais plus d'erreur, mais une fois une démo de la documentation déployée, je me suis rendu compte qu'elle était complètement cassée. Je retire le commit de cette PR, ça a l'air bien plus complexe que je ne le croyais.

package.json Outdated
@@ -175,7 +175,7 @@
"react-pdf": "^4.0.5",
"react-popper": "^2.2.3",
"react-remove-scroll": "^2.4.0",
"react-select": "^4.3.0",
"react-select": "^5.4.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Quel besoin d'upgrade cette lib ?

@PolariTOON PolariTOON force-pushed the chore/typescript-migration-attempt branch from 8ea2d99 to 1684799 Compare February 14, 2023 11:49
@PolariTOON PolariTOON force-pushed the chore/typescript-migration-attempt branch 2 times, most recently from b54b9f7 to 691f24d Compare February 14, 2023 13:28
@PolariTOON PolariTOON force-pushed the chore/typescript-migration-attempt branch from 691f24d to 937419f Compare February 14, 2023 14:45
@PolariTOON
Copy link
Contributor Author

This should be ready for a review (here's the demo link https://polaritoon.github.io/cozy-ui/react/ to show it builds the doc fine).
Unfortunately i didn't manage to identify the issues with the styleguide config, so i dropped the commit even if it was one of the main points of this PR. Even so, I have left some other preparatory commits that aren't need anymore right now, but that shouldn't hurt.

@PolariTOON PolariTOON marked this pull request as ready for review February 14, 2023 16:33
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