Version Rule͕࣮Ͱ͖·͢ Why Monorepo? monorepoͰͷύοέʔδͷόʔδϣϯΛ1͚ͭͩʹ౷Ұ͢ΔOne Version RuleΛpnpm c a t a logͰ࣮͢Δ https://tech.newmo.me/entry/one-version-rule-built-on-pnpm-c a t a log 9
several projects in it. We de fi nitely have “code colocation”, but if there are no well de fi ned relationships among them, we would not call it a monorepo. Likewise, if a repository contains a massive application without division and encapsulation of discrete parts, it's just a big repo. You can give it a fancy name like "garganturepo," but we're sorry to say, it's not a monorepo. In fact, such a repo is prohibitively monolithic, which is often the fi rst thing that comes to mind when people think of monorepos. Keep reading, and you'll see that a good monorepo is the opposite of monolithic. ✋ Monorepo ≠ Monolith A good monorepo is the opposite of monolithic! Read more about this and other misconceptions in the article on “Misconceptions about Monorepos: Monorepo != Monolith”. “ 13
Ϧׂ • → ྆ऀͱʮదͳཻͰͷׂʯͱʮ໌֬ͳڥքʯΛ ॏࢹ ஈ֊తͳׂɾਐԽ͕Մೳ • Modul a r MonolithɿඞཁʹԠͯ͡ϚΠΫϩαʔϏεԽ͕Մ ೳ • MonorepoɿඞཁʹԠͯ͡ϦϙδτϦׂ͕Մೳ • → ৫ͷʹ߹ΘͤͯॊೈʹରԠͰ͖Δ Why Monorepo? ґଘؔͷՄࢹੑ • Modul a r MonolithɿϞδϡʔϧؒͷґଘΛ໌ࣔతʹཧ • MonorepoɿϓϩδΣΫτؒͷґଘΛύοέʔδϚωʔ δϟͰཧ • → ґଘؔͷѲɾ੍ޚ͕༰қ ڞ௨Խͷଅਐ • Modul a r Monolithɿڞ௨ػೳΛϞδϡʔϧͱͯ͠Γग़ ͠ • Monorepoɿڞ௨ϥΠϒϥϦͱͯ͠Γग़͠ • → ࠶ར༻Մೳͳίʔυͷཧ͕ࣗવʹߦ͑Δ 17
th a t M a ximizes Developer Productivity • https://shopify.engineering/deconstructing-monolith-designing-softw a re- m a ximizes-developer-productivity • Monolith First • https://m a rtinfowler.com/bliki/MonolithFirst.html • Tow a rds Modern Development of Cloud Applic a tions • https://dl. a cm.org/doi/pdf/10.1145/3593856.3595909 Why Monorepo? 18
version of a package in third_party. This rule applies to both di ff erent versions of a single package, and forks or separate copies having di ff erent package names under third_party. There are several reasons for this restriction.” 20
ck a ge Xͷόʔδϣϯ 1.0.0 Λ͍ͬͯΔͱ͖ɺΞϓϦέʔγϣϯB p a ck a ge Xͷόʔδϣϯ 1.0.0 Λ͏Α͏ʹ౷Ұ͠·͢ ͜ΕʹΑͬͯɺ͋Δύοέʔδ͕1ͭͷόʔδϣϯ͚ͩʹू͞Εɺϝϯςφϯεੑ͕Α͘ͳͬͨΓɺύο έʔδͷΞοϓσʔτʹؔ͢ΔηΩϡϦςΟతͳʹରॲ͘͢͠ͳͬͨΓɺDi a mond dependencyͷΑ ͏ͳύοέʔδಉ࢜ͷґଘʹ͓͚ΔόʔδϣϯͷCon f lict͕ى͖ʹ͘͘ͳΓ·͢ Practicing the One Version Rule https://opensource.google/document a tion/reference/thirdp a rty/oneversion 21
a mlͱ͍͏ҰͭͷϑΝΠϧ ͰཧͰ͖ΔΑ͏ʹͳΓ·͢ɻ Practicing the One Version Rule catalogs: # Can be referenced through "catalog:react17" react17: react: ^17.0.2 react-dom: ^17.0.2 # Can be referenced through "catalog:react18" react18: react: ^18.2.0 react-dom: ^18.2.0 { "name": "@example/components", "dependencies": { "react": "catalog:react18", } } pnpm-workspace.yaml package.json 24
2. {"<name>": "catalog:"}ͱΞϓϦέʔγϣϯͰࢦఆ͞Εͨύοέʔδͷ࣮ࡍͷόʔδϣϯ ͕ pnpm-worksp a ce.y a ml ʹهࡌ͞Ε͍ͯΔ 3. Monorepoͷύοέʔδͱnode_modulesͷύοέʔδΛ۠ผͰ͖ΔΑ͏ͳ໊લΛ͚ͭΔ 4. όʔδϣϯඞͣPin͞ΕͨόʔδϣϯΛ͏Α͏ʹ͢Δ 5. ͜ͷϧʔϧΛຬͨ͞ͳ͍࣌ɺࣗಈతʹमਖ਼ίϚϯυΛΤϥʔʹදࣔ͢Δ Practicing the One Version Rule 26
king Ch a ngesͷରԠ͕શϓϩδΣΫτͰඞཁνʔϜӡ༻্ͷ՝ 2. νʔϜӡ༻্ͷ՝ • ৽نϥΠϒϥϦಋೖʹ͓͚Δ߹ҙܗ • ֤ϓϩδΣΫτͷݸผχʔζͱͷંΓ߹͍ 3. Ҡߦ࣌ͷ՝ • طଘͷෳόʔδϣϯࠞࡏঢ়ଶ͔Βͷ٫ • ஈ֊తͳҠߦͷͨΊͷ֬อ Practicing the One Version Rule 27
1 -d ./lib/typescript/p a ck a ges/ | grep "g a r a ge-" ᵓᴷᴷ g a r a ge-p a nd a css-preset ᵓᴷᴷ g a r a ge-p a nd a css-re a ct ᵓᴷᴷ g a r a ge-ui-re a ct 35
N a me: @newmo- a pp/g a r a ge-p a nd a css-preset 2. ׂ: Design TokenΛఆٛ͢Δ 3. ฤू͢Δత: Design TokenΛՃɺআɺߋ৽͢Δ 1. https://p a nd a -css.com/docs/customiz a tion/presets 2. UIϑϨʔϜϫʔΫ͝ͱͷ styled-system 1. P a ck a ge N a me: @newmo- a pp/g a r a ge-p a nd a css-re a ct 2. ׂ: ελΠϧΛఆٛ͢ΔUIϑϨʔϜϫʔΫ͝ͱͷؔ 3. ฤू͢Δత: P a nd a CSSͷઃఆΛมߋ͢Δͱ͖ 3. Design TokenҎ֎ͷઃఆ 1. UIϑϨʔϜϫʔΫ͝ͱͷ UIίϯϙʔωϯτ 2. P a ck a ge N a me: @newmo- a pp/g a r a ge-ui-re a ct 3. ׂ: ελΠϧ͖ͷUIίϯϙʔωϯτΛఏڙ͢Δ 4. ฤू͢Δత: ΞϓϦέʔγϣϯͰར༻͢ΔUIίϯϙʔωϯτΛ࡞ɺฤूɺআ͢Δͱ͖ Practical example Dependency diagram 45
ywrightΛ͍ͬͯΔͷͰɺpl a ywrightͰςετ Λॻ͘ • storybookͷςετํ๏Ͱॻ͘ Practical example ݁ σβΠϯͷݪଇͱͯ͠ɺׂ͕ಉ͡ͷͰ͖Δ͚ͩ Ұͭͷํ๏ʹ͢Δ • Inter a ction TestPl a ywrightͰॻ͘ • storybookͷpl a yؔΘͳ͍ • ίϯϙʔωϯτͷςετVRTΛجຊతʹߦ͏ Refs: Storybook Λϑϧ׆༻ͯ͠ςετΛ࣮ͨͦ͠ͷޙͷ https://blog.cybozu.io/entry/2024/08/13/140000 47
ίϯϙʔωϯτϨϕϧͷStoryཁݕ౼ 1. @newmo- a pp/g a r a ge-ui-re a ct ʹ͍࣋ͬͯ͘લʹɺ֤ΞϓϦέʔγϣϯʹίϯϙʔωϯτ͕ॻ͔ΕΔ 2. ΞϓϦέʔγϣϯͱ@newmo- a pp/g a r a ge-ui-re a ctͰຖճมίετ͕ൃੜ͢Δ 3. ΞϓϦέʔγϣϯʹStory͕ॻ͚Δͱ͜ΕղফͰ͖Δ͕ɺΞϓϦέʔγϣϯ͕Storyʹґଘ͠ग़͢ͷඍົ ݁ • StorybookσβΠϯγεςϜͷํ͚ͩʹ͓͘ • ΞϓϦέʔγϣϯଆʹstoriesॻ͔ͳ͍ • ͍࣋ͬͯ࣌͘ʹstoryΛॻ͘ Practical example 49
• ىಈ࣌ʹgrepͯ͠ɺstorybookʹinject͢ΔΈ͕͋Δͱྑ ͦ͞͏ • → ίϯϙʔωϯτ໊͕ύεʹೖΔΑ͏ʹ࣮ͯ͠ Practical example Refs: ιʔείʔυΛղੳ͚ͯࣾ͠UIϥΠϒϥϦͷ༻ঢ়گΛࣗಈͰूܭ͢Δ https://tech.pl a id.co.jp/ a n a lyze-intern a l-ui-libr a ry-us a ge import { Spinner } from "@newmo-app/garage-ui-react/Spinner"; export default function Loading() { return <Spinner />; } 51
& Polyrepo Str a tegies for Optim a l Softw a re Architecture • https://www.linkedin.com/pulse/n a vig a ting-monorepo-polyrepo-str a tegies-optim a l-softw a re-dev a m-n a rk a r- a 4crf/ • monorepo.tools • https://monorepo.tools/ • Deconstructing the Monolith: Designing Softw a re th a t M a ximizes Developer Productivity • https://shopify.engineering/deconstructing-monolith-designing-softw a re-m a ximizes-developer-productivity • Monolith First • https://m a rtinfowler.com/bliki/MonolithFirst.html • Tow a rds Modern Development of Cloud Applic a tions • https://dl. a cm.org/doi/pdf/10.1145/3593856.3595909 • Design Docs a t Google • https://www.industri a lemp a thy.com/posts/design-docs- a t-google/ • Storybook Λϑϧ׆༻ͯ͠ςετΛ࣮ͨͦ͠ͷޙͷ • https://blog.cybozu.io/entry/2024/08/13/140000 • ιʔείʔυΛղੳ͚ͯࣾ͠UIϥΠϒϥϦͷ༻ঢ়گΛࣗಈͰूܭ͢Δ https://tech.pl a id.co.jp/ a n a lyze-intern a l-ui-libr a ry-us a ge Wrap up 57