Slide 1

Slide 1 text

Corepack NodeֶԂ 37࣌ݶ໨ @shisama_ Node.jsʹ௥Ճ͞ΕΔύοέʔδϚωʔδϟʔϚωʔδϟʔͷ࿩

Slide 2

Slide 2 text

ฏ໺ ণ࢜ / Masashi Hirano @shisama_ shisama Node.js Core Collaborator

Slide 3

Slide 3 text

CorepackΛNode.jsʹ௥Ճ͢ΔPR͕Ϛʔδ🎉 https://github.com/nodejs/node/pull/39608

Slide 4

Slide 4 text

Corepackͱ͸ʁ🤔

Slide 5

Slide 5 text

https://github.com/nodejs/corepack/blob/main/README.md Nodejs͕։ൃɾ؅ཧ͍ͯ͠Δπʔϧ

Slide 6

Slide 6 text

Corepackͱ͸ • ύοέʔδϚωʔδʔΛ؅ཧ͢Δπʔϧ • ࠷ॳ͸pmm(package manager manager)ͱ͍͏໊લͩͬͨ • Node.jsΛΠϯετʔϧ͢Δ͚ͩͰɺYarn ͱ pnpm Λ࢖͑ΔΑ͏ʹ͢ Δͷ͕Ϟνϕʔγϣϯ • YarnͷϦʔυϝϯςφʔ͕ओʹ։ൃ͍ͯ͠Δ

Slide 7

Slide 7 text

ͳͥ࡞ΒΕͨʁ🤔

Slide 8

Slide 8 text

ݱࡏͷύοέʔδϚωʔδϟʔʹؔ͢Δ໰୊఺ • npmҎ֎ͷύοέʔδϚωʔδϟʔ͸Ϣʔβʔ͕ผ్Πϯετʔϧ͠ ͳ͚Ε͹͍͚ͳ͍ɻ 
 ⚠ Node.jsͷόʔδϣϯΛมߋ͢ΔͨͼʹΠϯετʔϧ͕ඞཁͰखؒ • npm Ҏ֎ͷύοέʔδϚωʔδϟ͕༏Ε͍ͯͯ΋ɺٕज़తͳཁૉΑ ΓΠϯετʔϧͷखؒͱ͍ͬͨ୯७͕͞༏ઌ͞Εͯ͠·͏͜ͱ͕͋Δ • ΤίγεςϜ΁ͷӨڹྗ͕σϑΥϧτͷnpmʹूத͍ͯ͠Δ

Slide 9

Slide 9 text

໰୊ΛͲ͏΍ͬͯղܾ͢Δͷ͔ʁ🤔

Slide 10

Slide 10 text

ࠓ೥ͷ͸͡Ί͔Βٞ࿦͞Ε͍ͯͨ https://github.com/nodejs/corepack/blob/main/README.md

Slide 11

Slide 11 text

YarnΛNode.jsʹՃ͑ΔPR͕࡞ΒΕ͕ͨɺ൓ରҙݟ΋͋ͬͨ https://github.com/nodejs/node/pull/37277

Slide 12

Slide 12 text

TSC಺Ͱ౤ථ͕ߦΘΕͯɺCorepackΛ௥Ճ͢Δํ਑Ͱܾఆ https://github.com/nodejs/node/pull/37277

Slide 13

Slide 13 text

ԿΛղܾ͢Δͷ͔ʁ🤔

Slide 14

Slide 14 text

Yarn ͱ pnpm Λผ్Πϯετʔϧ͠ͳͯ͘΋͍͍ • Corepack͕άϩʔόϧʹΠϯετʔϧ͞Ε͍ͯΔ؀ڥͰ͸ɺYarn ͱ pnpmΛผ్Πϯετʔϧ͢Δඞཁ͕ͳ͍ • Yarn΍pnpmΛ࣮ߦͨ͠ͱ͖Corepack͕ͦΕΒͷόΠφϦΛμ΢ϯ ϩʔυͯ͘͠ΕΔ • Corepack͸Node.jsʹඪ४όϯυϧ͞ΕΔ༧ఆͳͷͰɺNode.jsΛΠ ϯετʔϧ͢Δ͚ͩͰɺYarn ͱ pnpm΋࢖͑ΔΑ͏ʹͳΔ

Slide 15

Slide 15 text

Yarn ͱ pnpm Λผ్Πϯετʔϧ͠ͳͯ͘΋͍͍ • CorepackΛάϩʔόϧʹΠϯετʔϧ͞Ε͍ͯΔ؀ڥͰ͸ɺYarn ͱ pnpmΛผ్Πϯετʔϧ͢Δඞཁ͕ͳ͍ • Corepack͸Node.jsʹඪ४όϯυϧ͞ΕΔ༧ఆͳͷͰɺNode.jsΛΠ ϯετʔϧ͢Δ͚ͩͰɺYarn ͱ pnpmΛ࢖͑ΔΑ͏ʹͳΔ /PEFKTΛΠϯετʔϧͨ͠ΓόʔδϣϯΞοϓͨ͠Γ͢Δ࣌ɺ :BSO΍QOQNΛผ్Πϯετʔϧ͢Δख͕ؒল͚Δ

Slide 16

Slide 16 text

• package.jsonͷpackageManagerϑΟʔϧυʹϓϩδΣΫτͰར༻ ͢ΔύοέʔδϚωʔδϟʔͱόʔδϣϯΛهड़͓ͯ͘͠ ➡ύοέʔδϚωʔδϟΛར༻͢Δͱ͖ʹCorepack͕ͦͷύοέʔ δϚωʔδϟʔΛμ΢ϯϩʔυͯ͠Ωϟογϡͯ͘͠ΕΔ ϓϩδΣΫτ͝ͱʹར༻͢ΔύοέʔδϚωʔδϟͱόʔδϣϯΛ੾Γସ͑Δ { "packageManager": "[email protected]" }

Slide 17

Slide 17 text

• ϓϩδΣΫτͰར༻͢ΔύοέʔδϚωʔδϟʔͱόʔδϣϯΛ package.jsonʹهड़͓ͯ͘͠ ➡ύοέʔδϚωʔδϟΛར༻͢Δͱ͖ʹCorepack͕ͦͷύοέʔ δϚωʔδϟʔΛμ΢ϯϩʔυͯ͠Ωϟογϡͯ͘͠ΕΔ ϓϩδΣΫτ͝ͱʹύοέʔδϚωʔδϟͱόʔδϣϯΛ੾Γସ͑ { "packageManager": "[email protected]" } ύοέʔδϚωʔδϟʔ΍όʔδϣϯΛνʔϜϝϯόʔؒͰ౷ҰͰ͖ͨΓɺ ΞοϓσʔτͳͲΛ֤ϝϯόʔ͕खಈͰߦΘͳͯ͘΋Α͘ͳΔɻ

Slide 18

Slide 18 text

࣮ߦ͢ΔσΟϨΫτϦ͔Β 
 Ұ൪͍ۙpackage.jsonͰ൑ఆ ͨͱ͑͹… packages package-a package-b src package.json src package.json package.json “packageManager”: “[email protected]” “packageManager”: “[email protected]” “packageManager”: “[email protected]

Slide 19

Slide 19 text

Ұ൪͍ۙpackage.jsonͰ൑ఆ ͨͱ͑͹… packages package-a package-b src package.json src package.json package.json “packageManager”: “[email protected]” “packageManager”: “[email protected]” “packageManager”: “[email protected]” .POPSFQPͰ΋ύοέʔδ͝ͱʹར༻͢ΔύοέʔδϚωʔδϟʔΛ ม͑Δ͜ͱ͕Ͱ͖Δɻ ύοέʔδϚωʔδϟʔͷҠߦ΍όʔδϣϯΞοϓΛ 
 ύοέʔδ୯ҐͰߦ͑Δɻ

Slide 20

Slide 20 text

ଞͷύοέʔδϚωʔδϟͷར༻Λ੍ݶ͢Δ { "packageManager": "[email protected]" } $ npm install Usage Error: This project is con fi gured to use yarn package.jsonʹఆٛͨ͠ύοέʔδϚωʔδϟҎ֎ͷ ύοέʔδϚωʔδϟΛ࢖͏ͱΤϥʔʹͳΔ

Slide 21

Slide 21 text

ଞͷύοέʔδϚωʔδϟͷར༻Λ੍ݶ͢Δ { "packageManager": "[email protected]" } $ npm install Usage Error: This project is con fi gured to use yarn Package.jsonʹఆٛͨ͠ύοέʔδϚωʔδϟҎ֎ͷ ύοέʔδϚωʔδϟΛ࢖͏ͱΤϥʔʹͳΔ ؒҧͬͯଞͷύοέʔδϚωʔδϟʔ͕࢖ΘΕΔ͜ͱΛ੍ݶͰ͖Δɻ ΤϥʔϝοηʔδΛݟͯͲͷύοέʔδϚωʔδϟʔΛ 
 ࢖Θͳ͚Ε͹͍͚ͳ͍͔Θ͔Δɻ

Slide 22

Slide 22 text

• Corepack಺ʹఆٛ͞Ε͍ͯΔσϑΥϧτͷόʔδϣϯ͕࢖ΘΕΔ • 2021/08/30࣌఺Ͱ Yarn͸1.22.11ɺpnpm͸6.11.0 • σϑΥϧτͷόʔδϣϯΛมߋ͢Δʹ͸corepackίϚϯυͰมߋ package.jsonʹࢦఆ͕ແ͍৔߹ $ corepack prepare [email protected] —activate

Slide 23

Slide 23 text

• σϑΥϧτͷόʔδϣϯ͕࢖ΘΕΔ • σϑΥϧτͷόʔδϣϯ͸Corepack಺(con fi g.json)Ͱఆٛ͞Ε͍ͯ Δɻ2021/08/30࣌఺Ͱ Yarn͸1.22.11ɺpnpm͸6.11.0 • σϑΥϧτͷόʔδϣϯΛมߋ͢Δʹ͸corepackίϚϯυͰมߋ 
 `$ corepack parepare [email protected] —activate` ϓϩδΣΫτ͝ͱͷࢦఆ͕ແ͍৔߹ $PSFQBDL͕OQNJOTUBMMHZBSO!ʹ૬౰͢ΔίϚϯυΛ༻ҙ͠ ͍ͯΔ

Slide 24

Slide 24 text

⚠Corepackͷ஫ҙ఺⚠

Slide 25

Slide 25 text

⚠Corepackͷ஫ҙ఺⚠ • npmΛσϑΥϧτͰαϙʔτ͍ͯ͠ͳ͍ • npm install Ͱ Yarn ΍ pnpm ΛΠϯετʔϧ͠ͳ͍͜ͱ

Slide 26

Slide 26 text

npmΛσϑΥϧτͰαϙʔτ͍ͯ͠ͳ͍ { "packageManager": “[email protected]” } $ npm -v 6.14.15 Corepack͸Yarnͱpnpm͚ͩΛαϙʔτɻ 
 αϙʔτ͍ͯ͠ͳ͍ύοέʔδϚωʔδϟʔʹؔͯ͠͸ɺ ݩʑΠϯετʔϧ͞Ε͍ͯΔόΠφϦ͕࢖ΘΕΔ

Slide 27

Slide 27 text

$ corepack enable npm $ npm -v 7.0.0 $ yarn This project is con fi gured to use npm DPSFQBDLFOBCMFίϚϯυͰOQNͷ TIJNΛ$PSFQBDLͷ؅ཧԼʹ௥Ճ͢Δ $ corepack disable npm $ npm -v 6.14.8 DPSFQBDLEJTBCMFίϚϯυͰOQNͷ TIJNΛ࡟আ͢Δ

Slide 28

Slide 28 text

طଘͷnpmʹ͸Өڹ͠ͳ͍ https://github.com/nodejs/node/pull/39608 ݩʑΠϯετʔϧ͞Ε͍ͯΔOQNΛ্ॻ͖͠ͳ͍ɻ ͜Ε·Ͱ/PEFKTʹόϯυϧ͞Ε͍ͯΔOQNʹ͸৮Εͳ͍ܗͰ 
 $PSFQBDL͸/PEFKTʹ௥Ճ͞Ε͍ͯΔɻ

Slide 29

Slide 29 text

npm install -g yarn ͸࣮ߦ͠ͳ͍ • npm 7Ҏ߱ͩͱɺΠϯετʔϧࡁͷύοέʔδΛ࠶ΠϯετʔϧͰ͖ͳ͍ • Yarn ͱ pnpm͸Corepack͕͢ͰʹΠϯετʔϧ͍ͯ͠ΔͷͰΤϥʔ $ npm install -g yarn npm ERR! code EEXIST npm ERR! path /path/to/.nvm/versions/node/v14.15.0/bin/yarnpkg npm ERR! EEXIST: fi le already exists • Corepack͕Πϯετʔϧ͢ΔόΠφϦΛ্ॻ͖͠ͳ͍ͨΊʹ΋ɺ 
 npm installΛ࢖ͬͨYarn΍pnpmͷΠϯετʔϧ͸ආ͚ͨ΄͏͕ྑ͍ • Ͳ͏ͯ͠΋࣮ߦ͍ͨ͠৔߹͸—forceΛ෇͚Δ $ npm install -g yarn —force

Slide 30

Slide 30 text

͍͔ͭΒ࢖͑Δͷʁ🤔

Slide 31

Slide 31 text

8/25 ʹ Corepack௥ՃͷPR͕Node.jsͷ master ʹϚʔδ͞Εͨ https://github.com/nodejs/node/pull/39608 ϚΠόʔόʔδϣϯͰ௥ՃՄೳɻWYͷ ϦϦʔεͰ௥Ճ͞ΕΔ͔΋

Slide 32

Slide 32 text

Experimentalͳػೳͱͯ͠ϦϦʔε͞ΕΔ༧ఆ https://github.com/nodejs/node/blob/master/doc/api/corepack.md

Slide 33

Slide 33 text

ࠓ͙͢࢖͍͍ͨͳΒʁ https://www.npmjs.com/package/corepack OQNύοέʔδͱͯ͠΋഑෍͞Ε͍ͯΔͷͰɺ OQNJOTUBMMHDPSFQBDLͰΠϯετʔϧՄೳ

Slide 34

Slide 34 text

·ͱΊ • Corepack͕͋Ε͹… • Yarn ΍ pnpm ΛݸผʹΠϯετʔϧ͠ͳͯ͘΋Α͍ • ϓϩδΣΫτ͝ͱʹར༻͢ΔύοέʔδϚωʔδϟͱͦͷόʔδϣϯΛ package.jsonʹࢦఆ͢Δ͜ͱ͕Ͱ͖Δ • Corepack͕όϯυϧ͞ΕͨNode.js͸΋͏͙͢ϦϦʔε͞ΕΔ͔΋

Slide 35

Slide 35 text

https://zenn.dev/teppeis/articles/2021-05-corepack ࢀߟࢿྉ

Slide 36

Slide 36 text

Thanks. @shisama_ shisama