ããã«ã¡ã¯ãã½ããã¦ã§ã¢ã¨ã³ã¸ãã¢ã®åäº (@manabusakai) ã§ãã
ã«ããã·ã®ãããã¯ãã¯ã管çè ã®æ¹ã使ã Web ã¢ããªã« Reactãç¾å ´ã®æ¹ã使ã iPad / iPhone ã¢ããªã« React Native ãæ¡ç¨ãã¦ãã¾ãã
ã©ã¡ããããã³ãã¨ã³ãã®æè¡ã¹ã¿ãã¯ãæ¡ç¨ãã¦ãããã¨ããããå æ¥ã¾ã§ã¯ Monorepo 㨠Yarn Workspaces ã®æ§æã§éç¨ããã¦ãã¾ããã
æè¿ã§ã¯ Monorepo åãé²ãã¦ããäºä¾ãããè¦ãããããã«ãªã£ã¦ãã¾ããã
ã§ãããã«ããã·ã§ã¯ Monorepo ãããã¦ãªãã¸ããªåå²ãããææ決å®ãè¡ãã¾ããã
å ·ä½çã«ã¯ãharami_client ã¨ãã Monorepo ã harami_web 㨠harami_mobile ã¨ãããªãã¸ããªã«åå²ãããã¨ã«ããå æ¥ã¤ãã«ãªãã¸ããªåå²ãå®äºãããã¨ãã§ãã¾ãã ð
ã¡ãªã¿ã«ãharami ã¨ããã®ã¯ãããã¯ãã®ã³ã¼ããã¼ã ã§ããã«ããã·ã§ã¯èã®é¨ä½ãã³ã¼ããã¼ã ã«æ¡ç¨ããã¦ãã¾ã ð
ä»å㯠Monorepo ããããèæ¯ãã©ããã風ã«ä½æ¥ãé²ããã®ãããç´¹ä»ãã¾ãï¼
ãªãããã®è¨äºã§ã¯ Monorepo ã®è©³ç´°ã«ã¯è§¦ããªãã®ã§ãåèã«ãªããããªãã¼ã¸ããç´¹ä»ãã¦ããã¾ãã
Monorepo ã«ããã課é¡
Monorepo ããã®å¯ãªä¾åé¢ä¿
äºã®çºç«¯ã¯ãiPad / iPhone ã¢ããªï¼ä»¥å¾ mobile ã¨è¡¨è¨ãã¾ãï¼ã§å©ç¨ãã¦ãã Expo SDK ã®ã¢ããã°ã¬ã¼ãã§ããã
å ã»ã©ãç´¹ä»ããããã«ã«ããã·ã®ãããã¯ã㯠React ããã¼ã¹ã«ãã¦ãã¾ãããReact ã®ãã¼ã¸ã§ã³ã¯ web 㨠mobile ã§å¯ãªä¾åé¢ä¿ã«ãããExpo SDK ã®ã¢ããã°ã¬ã¼ãã®ããã« mobile ã ã React ã®ãã¼ã¸ã§ã³ãä¸ããã¨ãããã¨ãé£ããç¶æ³ã§ããï¼Monorepo æ§æã§è¤æ°ã® React ãå ±åããããã¨ãã§ããªããã *1ï¼ã
ãã®ä¾åé¢ä¿ã¯æ¬æ¥ Monorepo ã®ã¡ãªããã§ãããã¾ãããè£ãè¿ãã¨ã©ã¡ããçæ¹ã®å¤æ´ãããçæ¹ã«ãå½±é¿ãä¸ãã¦ãã¾ãã¨ãããã¡ãªããã«ããªãå¾ã¾ãã
ã¾ããããããã±ã¼ã¸ã§ä½¿ç¨ãã¦ããã©ã¤ãã©ãªãå¥ã®ããã±ã¼ã¸ããå©ç¨ã§ãã¦ãã¾ããããæ示çãªä¾åé¢ä¿ãçã¾ãã¦ãã¾ããã
ã¢ããªã±ã¼ã·ã§ã³ã®ã©ã¤ããµã¤ã¯ã«ã®éã
web 㨠mobile ã§å©ç¨ãã¦ãããã¬ã¼ã ã¯ã¼ã¯ã®ã©ã¤ããµã¤ã¯ã«ã®éããããã«ç¶æ³ãé£ãããã¦ãã¾ããã
mobile ã§å©ç¨ãã¦ãã Expo SDK ã¯ããã 3 ãæããã«ã¡ã¸ã£ã¼ãªãªã¼ã¹ãè¡ããããã®å¾ã¯ 6 ãæããå¾æ¹äºææ§ãèå¼±æ§å¯¾å¿ãå«ãããµãã¼ããæä¾ããã¾ããï¼å·çæç¹ã§ã¯ Expo SDK 48 ãææ°ã§ããããµãã¼ãããã¦ããã®ã¯ 46 ã 48 ã® 3 ãã¼ã¸ã§ã³ã§ãï¼ã
ãã®ãã常ã«ææ°ãã¼ã¸ã§ã³ã追ãããç¶ãããã¨ãéè¦ã§ããããäºããå¯ã«ä¾åãã¦ããç¶æ³ã ã¨å¯¾å¿ã³ã¹ããå¢ãã¦ãã¾ããé常ã®æ©è½éçºãå§è¿«ãã¦ãã¾ã£ã¦ãã¾ããã
ã¨ã³ã¸ãã¢ã®äººæ°ãéãããã¹ã¿ã¼ãã¢ããã«ããã¦ããã®ç¶æ³ã¯ä½ã¨ãã¦ãæ¹åããããã¤ã³ãã§ããã
Monorepo ã§ã¯è§£æ±ºã§ããªãã¨å¤æ
ããã³ãã¨ã³ãã«è©³ããã¨ã³ã¸ãã¢ãä¸å¿ã« Monorepo ã®ã¾ã¾ä¸è¨ã®èª²é¡ã解決ããæ¹æ³ããªããæ¤è¨ãè¡ãã¾ããããæçµçã«ã¯ãªãã¸ããªåå²ãè¡ããã¨ãæã妥å½ã§ããã¨ããçµè«ã«è¾¿ãçãã¾ããã
ãªãã¸ããªåå²ã®ã¹ããã
èªè ã®æ¹ã«åãã¦ä½æ¥åã®ãªãã¸ããªãç°¡ç¥åãã¦ãä¼ãããã¨ã次ã®ãããªæ§é ã«ãªã£ã¦ãã¾ããã
harami_client âââ node_modules âââ package.json âââ packages â âââ api_docs // OpenAPI å®ç¾© â â âââ package.json â â âââ spec â â âââ openapi.yaml â âââ mobile // React Native â â âââ package.json â âââ web // React â âââ package.json âââ yarn.lock
Yarn Workspaces ã使ã£ã¦ããã®ã§ãnode_modules 㨠yarn.lock ã¯ãããã¬ãã«ã«é ç½®ããã¦ãã¦ãåã¢ããªã±ã¼ã·ã§ã³ãã㯠hoisting ããã¦åç §ããã¦ãã¾ãã
OpenAPI å®ç¾©ã®ç§»è¡
ãªãã¸ããªåå²ãè¡ããã¨ã決ã¾ãã¾ãããã解決ããªããã°ãããªãåé¡ã¯ä»ã«ãããã¾ããã packages é ä¸ã« web 㨠mobile ã®ã½ã¼ã¹ã³ã¼ããããã¾ããããªãã OpenAPI å®ç¾©ãã¯ã©ã¤ã¢ã³ãå´ã®ãªãã¸ããªã«åå¨ãã¦ãã¾ããã
éå»ã®çµç·¯ã®è©³ç´°ã¯åããã¾ããããå½æã¯ã¯ã©ã¤ã¢ã³ãå´ãã OpenAPI å®ç¾©ãåç §ãã¦ããªãã£ããããããã«ãã£ãã»ããé½åãè¯ãã£ãããã§ãï¼ç¾å¨ã¯ãµã¼ãå´ã«ãã¹ãã¼ãé§åéçºãå°å ¥ãã¤ã¤ããã¾ãï¼ã
ãªãã¸ããªåå²ã®åã«ãã¾ãã¯ãã® OpenAPI å®ç¾©ãé©åãªå ´æã«ç§»ããã¨ã«ãã¾ããã OpenAPI å®ç¾©ã ããæã¤ãªãã¸ããªãä½ããã¨ãæ¤è¨ãã¾ããããã²ã¨ã¾ãã¯ç®¡çã®æéãæ¸ããããã« API ãµã¼ãå´ã«ç§»ããã¨ã«ãã¾ãã *2ã
ããã¾ã§ã¯ hoisting ããã¦ãããã¬ãã«ã«ãã node_modules ã«ãã OpenAPI å®ç¾©ãåç §ããã¦ãã¾ãããããã®ã¿ã¤ãã³ã°ã§ npm ããã±ã¼ã¸åãããã¨ã«ãã¾ããã
OpenAPI å®ç¾©ãå¤æ´ãã Pull request ããã¼ã¸ãããã¨ãnpm ããã±ã¼ã¸ãä½æã GitHub Packages ã«ç»é²ããã¯ã¼ã¯ããã¼ã追å ãã¾ããããã㦠web 㨠mobile ã® package.json ã¯ãã® npm ããã±ã¼ã¸ãåç §ããããã«ãã¾ããã
ããã«ãã harami_client ã®ãªãã¸ããªã¯ web 㨠mobile ã ãã®ã½ã¼ã¹ã³ã¼ãã«ãªãã¾ããããããæåã®ã¹ãããã§ãã
ãªãã¸ããªåå²
ãããããèå¿ã®ãªãã¸ããªåå²ã§ãã
æ¹éã¨ãã¦ãharami_client ã®ãªãã¸ããªããæ¯è¼çå½±é¿ã®å°ãªã web ãå¼ãæããharami_client ã«ã¯ mobile ã ããæ®ãã¦ãªãã¼ã ãããã¨ã«ãã¾ããã
ã¾ãç¬ç«ãããªãã¸ããªã«ãããã¨ã§ãã£ã¬ã¯ããªãä¸ããå¿ è¦ããªããªãã®ã§ãåããã¦ãã£ã¬ã¯ããªã®åé ç½®ãè¡ãã¾ããã
ãã®ãªãã¸ããªåå²ãé²ããªãããmobile ã§ã¯ Expo SDK ã®ã¢ããã°ã¬ã¼ãä½æ¥ãé²ãã¦ãã¾ããããã®ãã 2 åã®ã¹ãããã«åãã¦ãã¾ã㯠web ã ãå è¡ãã¦é²ãã¦ãmobile ã¯å¥æ¥ã«å®æ½ãããã¨ã«ãã¾ããã
å ¨ä½ã®æµãã¨ãã¦ã¯ä»¥ä¸ã®ãããªæãã§ãã
éçºã¸ã®å½±é¿ãã§ããéãæ¸ããããã«ãã¬ãã¥ã¼ãçµãã£ã¦ãªãªã¼ã¹ã§ãããã®ã¯æ©ãã«ãã¼ã¸ãã¦ããã£ãããåå²å¾ã«æ³å®ããã FAQ ãããã¥ã¡ã³ãã«ã¾ã¨ãããªã©ãä¸å¯§ãªã³ãã¥ãã±ã¼ã·ã§ã³ãæèãã¾ããã
ãã¨ã¯å½æ¥ã«ã³ã¼ãããªã¼ãºãè¡ããäºåã«æºåããæé ãæ·¡ã ã¨é²ããã ãã§ããã幸ã大ããªãã©ãã«ããªãç¡äºã«çµãããã¨ãã§ãã¾ãã ð
ãªãã¸ããªåå²ãã¦ã©ããªã£ãã
解決ããã課é¡ã«å¯¾ãã¦é©åãªã¢ããã¼ãã ã£ãã®ãæ¯ãè¿ã£ã¦ã¿ã¾ãã
ã¾ãå¯ãªä¾åé¢ä¿ã«ã¤ãã¦ã¯ãç©ççã«ãªãã¸ããªãåãããã¨ã§å®å ¨ã«ä¾åé¢ä¿ããªããªãã¾ãããããã¾ã§ã¯ã©ãã§ä¾åãåã£ã¦ããã®ãææ¡ã§ãã¦ããªãã£ããããã¨ããããã±ã¼ã¸ã®å¤æ´ãä»ã«ãå½±é¿ãä¸ããå¯è½æ§ãããã¾ããããããããä¸å®ã解æ¶ããã¾ããã
ã¾ãããªãã¸ããªãåãããã¨ã§ãã¬ã¼ã ã¯ã¼ã¯ã®ã©ã¤ããµã¤ã¯ã«ã«ã追å¾ãããããªãã¾ããããã®è¨¼æ ã« 3 æã« Expo SDK 46ã4 æã« Expo SDK 47 ã«ã¢ããã°ã¬ã¼ããããã¨ãã§ãã5 æä¸ã«ã¯ Expo SDK 48 ã«ã¢ããã°ã¬ã¼ãããäºå®ã§ä½æ¥ãé²ãã¦ãã¾ãã
ãªãã¸ããªåå²ä»¥éã¯ã¢ããã°ã¬ã¼ãã«ãããå·¥æ°ããã£ã¨ç縮ãããã¨ãã§ãã¦ãããä»å¾ã¯ææ°ãã¼ã¸ã§ã³ã追ãããç¶ãããã¨ãã§ãããã§ãã
æå¾ã«ä½è«ã§ãããã«ããã·ã§ã¯ Pull request ããã¼ã¸ããåã«ææ°ã®ã³ã¼ãã«ãªã£ã¦ãããã¨ãè¦æ±ããã¾ããï¼GitHub ã® âRequire branches to be up to date before mergingâ ã®è¨å®ï¼ãã¨ã³ã¸ãã¢ãªã³ã°çµç¹ãæ¥æ¡å¤§ãã¦ããã®ã§ Pull request ããã¼ã¸ãããã¨ãã㨠rebase åæ¦ãèµ·ãã¦ãã¾ãããé©åã«ãªãã¸ããªãåå²ãããã¨ã§ããã®åé¡ãç·©åãããã¨ãã§ãã¾ããã
ãããã«
å½åã®ç®è«ã¿ã©ããã®çµæãåºããã¨ãã§ãã¦ãããä»ã®ã«ããã·ã«ã¨ã£ã¦ã¯ Monorepo ãããããã¨ãæåã®ã¢ããã¼ãã ã£ãã¨è¨ãããã§ãã
ã¨ã³ã¸ãã¢ãªã³ã°çµç¹ããããã¯ãã®ãã§ã¼ãºã«ãã£ã¦æé©è§£ã¯å¤ãã£ã¦ããã¨æãã¾ãããã«ããã·ã§ã¯ãããããæµè¡ãå»ãã«æµãããæè¡é¸å®ãã¦ãããã¨èãã¦ãã¾ãã
æå¾ã«å®£ä¼ã§ã ð£ ã«ããã·ã§ã¯çµ¶è³æ¡ç¨ä¸ã§ãï¼ ä¸ç·ã«å¼·ããã¼ã ãä½ã£ã¦ãã仲éãåéãã¦ãã¾ãï¼
*1:https://legacy.reactjs.org/warnings/invalid-hook-call-warning.html#duplicate-react
*2:Git ã®å±¥æ´ãç¶æããã¾ã¾ãªãã¸ããªéã§ãã¡ã¤ã«ã移ãæé ã¯ããGit ãªãã¸ããªã®ç¹å®ã®ãã¡ã¤ã«ãå¥ã® Git ãªãã¸ããªã«ç§»ããã«ã¾ã¨ãã¦ãã¾ãã®ã§èå³ãããæ¹ã¯ã覧ãã ããã