Upgrade to Pro — share decks privately, control downloads, hide ads and more …

JavaScript Package Manager 2019

JavaScript Package Manager 2019

Node学園で発表した JavaScript Package Manager の話です。

Yosuke Furukawa

June 27, 2019
Tweet

More Decks by Yosuke Furukawa

Other Decks in Programming

Transcript

  1. ͦ΋ͦ΋npmͷ࢓૊Έɹ 1. ϩʔΧϧґଘϑΝΠϧΛಡΉ (package.json, package- lock.json, shrinkwrap.json) 2. ଘࡏ͠ͳ͍ύοέʔδͷϝλσʔλΛfetch͢Δ 3.

    ໦ߏ଄Λܭࢉͯ͠ɺ࣮ߦ͢Δʢnpm v3 Ҏ߱ͩͱflatten͢ Δʣ 4. ࣮ࡍʹଘࡏ͠ͳ͍ύοέʔδΛμ΢ϯϩʔυ͢Δ 5. ΠϯετʔϧεΫϦϓτΛ࣮ߦ͢Δ
  2. ࠓͷͲ͕͜μϝͳͷ͔ • ʮ4. ύοέʔδΛμ΢ϯϩʔυ͢Δʯ͕ߴෛՙͷॲཧ • μ΢ϯϩʔυ͢Δɺͱ͍͏ߦҝ͸ • tar ball Λ

    fetch ͯ͠ɺ • ͔ͦ͜Β gunzip ͯ͠ɺ • Ͱ͖͕͋ͬͨϑΝΠϧΛnode_modulesҎԼʹίϐʔ • ͱ͍͏ϐʔΩʔͳॲཧΛ͍ͯ͠Δɻɹ
  3. ࠓͷͲ͕͜μϝͳͷ͔ • tar ball Λ Fetch => Network IO΁ͷෛՙ •

    gunzip => CPU΁ͷෛՙ • node_modules Λίϐʔ => File IO΁ͷෛՙ Կ͔͠ΒͷΫϥΠΞϯτϦιʔεʹෛՙ͕ඞ͔͔ͣΔ
  4. ࠓͷͲ͕͜μϝͳͷ͔ • tar ball Λ Fetch => Network IO΁ͷෛՙ •

    gunzip => CPU΁ͷෛՙ • node_modules Λίϐʔ => File IO΁ͷෛՙ ಛʹOPEF@NPEVMFTʹ࣮ମͷϑΝΠϧ͕ඞཁʹͳΔͨΊɺϑΝΠϧͷ૯༰ྔ͕ ૿͑Δɻ
  5. tink sh • `tink sh <cmd>` Ͱىಈ͢Δɻ • tink sh

    ͕ node Λwrap ͍ͯ͠Δ • ͜ΕͰىಈ͢Δͱ node_modules ΛԾ૝্ ͷϑΥϧμʹ͢Δࣄ͕Ͱ͖Δɻ $ node foo.js # Ͱىಈ͢ΔͷͰ͸ͳ͘ɺ $ tink sh foo.js # Ͱىಈ͢Δɻɹ
  6. node_modulesΛԾ૝্ͷϑΥ ϧμʹ͢Δ͜ͱͷϝϦοτɹ • ࣮ࡍʹϑΝΠϧΛίϐʔ͠ͳ͍ͨΊɺ File IO΁ͷӨڹ͕ ؇࿨͞ΕΔ • ϩʔΧϧ಺ʹ hash

    Λϕʔεʹͨ͠cacheΛ࡞Γɺhash ஋͕Ұகͨ͠ΒcacheΛ࢖͏ Network IO΁ͷӨڹ΋؇ ࿨͞ΕΔ • ϥϯλΠϜͰϞδϡʔϧΛղܾ͢ΔͨΊɺ npm install ͕ཁΒͳ͘ͳΔɻ
  7. prepare && unwind • prepare ͸ࣄલʹ module Λ fetch ͢ΔίϚ

    ϯυ • unwind ͸ࣄલʹ node_modules Λ࣮ମԽ͢ ΔίϚϯυ $ tink prepare $ tink unwind
  8. prepare && unwind • prepare ͸ࣄલʹ module Λ fetch ͢ΔίϚ

    ϯυ • unwind ͸ࣄલʹ node_modules Λ࣮ମԽ͢ ΔίϚϯυ $ tink prepare $ tink unwind ຊ൪ىಈ࣌ʹ͸ىಈޙͷGFUDIΛ஗͍ͱ໰୊ͳͷ Ͱɺىಈલʹࣄલॲཧ͢ΔίϚϯυ͕ఏڙ͞ΕͯΔ
  9. ·ͱΊ • npm, yarn ͸ࠓޙ zero install ࣌୅ʹͳ͍ͬͯ ͘ •

    ҰํͰɺͲͪΒʹ΋༗ҙ͕ࠩ͋ΔΑ͏ʹ͸ݟ ͑ͳ͔ͬͨ • ·ͩ experimental ৭Μͳͱ͜ΖͰ໰୊఺Λग़ ͢ϑΣʔζ
  10. npmͷϏδωεϞσϧ • public module ΛແঈͰఏڙɺίετ͸npm Ͱෛ୲ • private module ΍

    enterprise ͳΞΫηείϯτ ϩʔϧΛ͢ΔͳΒ༗ঈ൛Λܖ໿ • public module cost Λ private module ͷച্ Ͱ࿫͏Ϟσϧ
  11. ·ͱΊ • npm vs yarn ͱ͔ͷ࿩Ͱ͸ͳ͘ɺࠓ΍ JavaScript Registry ͸༗ޮࡦ͕ग़ͳ͍ݶΓ·ͣ ͍ঢ়گ

    • ࠓٻΊΒΕͯΔͷ͸Registryͷӡ༻஌ݟ • ࠓޙͲ͏ͳΔ͔͸ෆ໌ɺΈΜͳͰ༗ޮࡦΛߟ͑ ͍ͯ͘ϑΣʔζ