Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
denoの話
Search
Yosuke Furukawa
PRO
June 29, 2018
Programming
4
2.4k
denoの話
Node学園 31時限目で発表した deno の話です。
Yosuke Furukawa
PRO
June 29, 2018
Tweet
Share
More Decks by Yosuke Furukawa
See All by Yosuke Furukawa
tc39 x jsconf.jp Panel Discussion 2024
yosuke_furukawa
PRO
0
150
Removing Corepack
yosuke_furukawa
PRO
9
1.3k
JavaScript Runtime とはなにか
yosuke_furukawa
PRO
15
2.5k
Strip Types と Storage
yosuke_furukawa
PRO
4
340
Module Harmony について
yosuke_furukawa
PRO
3
1.5k
LTのやり方
yosuke_furukawa
PRO
16
2.2k
AppRouter Panel Talk
yosuke_furukawa
PRO
3
700
Node.js v22 で変わること
yosuke_furukawa
PRO
13
5.3k
リアーキテクトと開発生産性について
yosuke_furukawa
PRO
25
9.6k
Other Decks in Programming
See All in Programming
Pinia Colada が実現するスマートな非同期処理
naokihaba
4
220
Why Jakarta EE Matters to Spring - and Vice Versa
ivargrimstad
0
1k
CSC509 Lecture 09
javiergs
PRO
0
140
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
330
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
310
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
100
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
Quine, Polyglot, 良いコード
qnighy
4
640
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
ヤプリ新卒SREの オンボーディング
masaki12
0
130
Featured
See All Featured
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Music & Morning Musume
bryan
46
6.2k
Designing the Hi-DPI Web
ddemaree
280
34k
Making Projects Easy
brettharned
115
5.9k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
Git: the NoSQL Database
bkeepers
PRO
427
64k
Why Our Code Smells
bkeepers
PRO
334
57k
Put a Button on it: Removing Barriers to Going Fast.
kastner
59
3.5k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
GraphQLとの向き合い方2022年版
quramy
43
13k
jQuery: Nuts, Bolts and Bling
dougneiner
61
7.5k
Making the Leap to Tech Lead
cromwellryan
133
8.9k
Transcript
denoʹ͍ͭͯ 2018/06/28 @ Recruit Technologies TEPCO office
Twitter: @yosuke_furukawa Github: yosuke-furukawa
2018/11/23 - 24 Node ֶԂࡇ։࠵
deno
ྺ࢙ΛḪΔ͜ͱ9લ…
Ryan Dahl ͕Node.jsʹ͍ͭͯτʔΫ
https://www.slideshare.net/shigeki_ohtsu/node-v012tng12
v0.1ͷެද͔Β9ޙ…
10 THINGS I REGRET ABOUT NODE.JS
Ryan DahlͷޙչϙΠϯτ • Dynamic Typed Language ʹͨ͜͠ͱ • Promise Λ࠾༻͠ͳ͔ͬͨ͜ͱ
• Security ϞσϧΛצҊ͠ͳ͔ͬͨ͜ͱ • Gypʹ͔ͬͬͨ͜ͱ • moduleϋϯυϦϯά (package.json, node_modules, etc)
Dynamic Typed Language
Dynamic Typed Language • JavaScript࠷ྑ͍ಈతܕ͚ݴޠͩͱࢥͬͯΔ • ͔͠͠ͳ͕Βɺಈతܕ͚ݴޠҰճ͖ͬ͜Γͷܭ ࢉΛ͢ΔͳΒ·ͩ͠ɺԿ࣮ߦ͢Δͷʹద༻ ͢Δ͖͡Όͳ͍ͱࢥ͏ •
Node.jsઃܭաఔʹ͓͍ͯෳͷτϥΠΤϥʔΛ ܁Γฦ͢ඞཁ͕͋Γɺͦͷ࣌ͷΤϥʔͷ༰Θ͔ Γʹ͘͘ɺΤϥʔͷղফ͖ͬΓͯ͠ͳ͍ɻ
Dynamic Typed Language • JavaScript࠷ྑ͍ಈతܕ͚ݴޠͩͱࢥͬͯΔ • ͔͠͠ͳ͕Βɺಈతܕ͚ݴޠҰճ͖ͬ͜Γͷܭ ࢉΛ͢ΔͳΒ·ͩ͠ɺԿ࣮ߦ͢Δͷʹద༻ ͢Δ͖͡Όͳ͍ͱࢥ͏ •
Node.jsઃܭաఔʹ͓͍ͯෳͷτϥΠΤϥʔΛ ܁Γฦ͢ඞཁ͕͋Γɺͦͷ࣌ͷΤϥʔͷ༰Θ͔ Γʹ͘͘ɺΤϥʔͷղফ͖ͬΓͯ͠ͳ͍ɻ ͔֬ʹͦ͏͔͠ΕΜ͚Ͳɺ͍·ͦΕ͍͏ʁ
Dynamic Typed Language • ࣮ੲNode.jsΛશ෦TypeScriptʹ͠Α͏ͱ͠ ͨΓɺCoffeeScriptʹ͠Α͏͍ͬͯ͏PR͕ ཱͬͨ͜ͱ͕͋ͬͨɻ • ͪΖΜશ෦ফ͞Ε͖ͯͨɻ
PromiseΛ࠾༻Ͱ͖ͳ͔ͬͨ
Promise • 2009ʹҰ࣮͞Εͨͷͷɺ2010ʹ ؙ͝ͱফͯ͠͠·ͬͨɻ • ࠓͰ۪͔ͳܾஅͩͬͨͱࢥ͍ͬͯ·͢ɻ • async/awaitͷநԽʹඞཁͰͨ͠ɻ
Promise • 2009ʹҰ࣮͞Εͨͷͷɺ2010ʹ ؙ͝ͱফͯ͠͠·ͬͨɻ • ࠓͰ۪͔ͳܾஅͩͬͨͱࢥ͍ͬͯ·͢ɻ • async/awaitͷநԽʹඞཁͰͨ͠ɻ PromiseͷΛ͢Δͱͷલ͕͘ͳΔ
Promise • Ұ masuidrive ͞Μ͕nodeͷඪ४APIΛͯ͢Promiseʹ͠ ͨࣄ͕͋ͬͨɻ • ҰํɺIRCͷதͰɺʮPromise͕ඪ४ʹͳΔ͔ෆ໌ͩ͠ɺ callbackͷ͕simpleͰΑ͘Ͷʁʯ͍ͬͯ͏͕ٞ͋ͬͨɻ •
͔ͯ͘͠ɺPromiseͷίʔυͯ͢ফ͞Εͯ͠·ͬͨɻ • ͜Ε͕ੈʹݴ͏ʮmasuidrive ͷ൵ܶʯͰ͋Δɻ
Security ϞσϧΛצҊ͠ͳ ͔ͬͨ͜ͱ
SecurityϞσϧΛצҊ͠ͳ͔ͬ ͨ͜ͱ • V8ͦΕࣗsecureͳsandboxϞσϧΛදݱ ͍ͯ͠·͢ɻ • ͬͱྑ͍ηΩϡϦςΟʹͰ͖ͨͣɻ • LinterΛಈ͔͚ͩ͢Ͱ networkͷΞΫηε
ϑΝΠϧॻ͖ࠐΈΛ͢Δඞཁͳ͍Ͱ͢ΑͶʁ
SecurityϞσϧΛצҊ͠ͳ͔ͬ ͨ͜ͱ • v8͚ͩͩͱ ϑΝΠϧಡΈࠐΈɺॻ͖ࠐΈͰ͖ ͳ͍͠ɺωοτϫʔΫΞΫηεͰ͖·ͤΜɻ • ඪ४ग़ྗͷconsole.logv8ͷ֎Ͱ͢ɻ • ͜ΕΒΛsandboxͷதͰదٓύʔϛογϣϯΛಘ
ͳ͕Β࣮ߦͰ͖ΕͬͱΑΓྑ͍ηΩϡϦςΟ ϞσϧΛఏڙͰ͖ͨɺͱݴ͍͍ͨͷͰ͠ΐ͏ɻ
GYPΛ࠾༻ͨ͜͠ͱ
GYPΛ࠾༻ͨ͜͠ͱ • GYPେ͖ͳࣦഊͩͬͨ • V8͕GYPΛ࠾༻͍ͯͯ͠ɺnode.jsͦΕʹ҆қʹ ͔ͬͬͯ͠·ͬͨɻ • v8GYP͔ΒgnʹҠΓNode.jsͷgypϢʔβʔऔΓ ͞Εͯ͠·ͬͨɻ •
ࠓͳΒͦ͏͠ͳ͍ɺ FFI Λ࠾༻͢Δɻ
GYPΛ࠾༻ͨ͜͠ͱ • FFI (Foreign Function Interface)ͷ͕ϙʔλϒ ϧͰݺͼ͍͢ҰํͰɺgypͷ͕ߴͩͱ͞Ε ͍ͯͨɻ • ੑೳΛ༏ઌͨ݁͠ՌɺgypΛ࠾༻͕ͨ͠ɺࠓ
gyppython2Ͱ͋ΓɺgypաڈͷҨ ࢈ʹͳͬͯ͠·͍·ͨ͠ɻ
moduleϋϯυϦϯάશൠ
moduleϋϯυϦϯάશൠ • package.jsonपΓɺෆཁͳใ͕ଟ͗͢Δ • require()ͨ࣌͠ʹnode_modulesҎԼʹ͋ΔmainϑΟʔϧυΛউ खʹಡΉͳͲɺfancyͳڍಈ͕ଟ͍ʢnpmʹ͋Δͷͳͷ͔ɺ localͷదͳϑΝΠϧͳͷ͔Θ͔Γʹ͍͘ʣ •
moduleϋϯυϦϯάશൠ
moduleϋϯυϦϯάશൠ • moduleͷղܾΞϧΰϦζϜ͕૬ෳࡶʹͳͬ ͯ͠·ͬͨɻ • ϒϥβͷsemantics͔Β֎Εͯ͠·ͬͨɻ
moduleϋϯυϦϯάશൠ • module ͷղܾΞϧΰϦζϜ node_modules ͷґଘ ؔΛͨͲͬͯґଘղܾΛ͢Δɻ • ·ͨɺ moduleࢦఆݩ͔Βͷ૬ରύεͰϑΝΠϧΛࢦ
ఆ͢Δ͕ɺ $NODE_PATH ڥมʹύε͕ηοτ͞Ε ͍ͯΔͱ͔ͦ͜ΒಡΈࠐΉɻ • ͜ͷଞʹ͍͔ͭ͘ hacky ͳํ๏͕͋Δ͕ɺͲΕඍົ
moduleϋϯυϦϯάશൠ
moduleϋϯυϦϯάશൠ • ".js" ͳ͠ͰಡΈࠐΊΔ • "index.js" লུՄೳ • ͳͲͳͲɺϑΝϯγʔͳػೳ͕ଟ͘ɺ࣮ͦΕ͕ ෳࡶ͞ͱόάͷԹচʹͳΓ͍͢ɻ
• লུͪ͠Ό͏ͱɺϑΥϧμͳͷ͔ϑΝΠϧͳͷ͔ ݟ͚͕͔ͭͳ͍ɻ
ͦ͜Ͱ deno Λ࡞ͬͨ
deno v8 Ͱಈ͘ηΩϡΞͳ TypeScript ࣮ߦڥ
TypeScript
None
None
None
TypeScript • denoTypeScriptΛ࠾༻ͨ͠ • TypeScriptDartͳͲͷͷͱҟͳΓɺ JavaScriptͷεʔύʔηοτͱ͍͏Ґஔ͚ͮ • ڊେͳγεςϜʹରԠͰ͖Δɻ
sandboxηΩϡϦςΟϞσϧ
sandbox ηΩϡϦςΟϞσϧ • denosandboxͰಈ͘ • v8ͷϨΠϠworkerͰJSͷruntime͕ಈ͖ɺϑΝ ΠϧωοτϫʔΫʹΞΫηε͢Δͱ͖͚ͩಛ ݖϞʔυʹͳΔɻ • ಛݖϞʔυͷϓϩηεͱruntimeؒͰ௨৴͢Δࡍ
protocol bufferΛͬͯ௨৴͢Δɻ
sandbox ηΩϡϦςΟϞσϧ • denosandboxͰಈ͘ • v8ͷϨΠϠworkerͰJSͷruntime͕ಈ͖ɺ ϑΝΠϧωοτϫʔΫʹΞΫηε͢Δͱ͖ ͚ͩಛݖϞʔυʹͳΔɻ
sandbox ηΩϡϦςΟϞσϧ • denosandboxͰಈ͘ • v8ͷϨΠϠworkerͰJSͷruntime͕ಈ͖ɺ ϑΝΠϧωοτϫʔΫʹΞΫηε͢Δͱ͖ ͚ͩಛݖϞʔυʹͳΔɻ ͓ɺOS͔Αɻɻɻ
ϞδϡʔϧγεςϜͷγϯϓϧԽ
ϞδϡʔϧγεςϜͷγϯϓϧ Խ • NodeͷطଘϞδϡʔϧͱͷੑٻΊͯ· ͤΜɻ • import૬ରύε͔ઈରύεɺ͘͠URL ͚ͩͰ͔͠ࢦఆͰ͖·ͤΜɻ import {
test } from "https://unpkg.com/
[email protected]
/testing.ts" import { log } from "./util.ts"
ϞδϡʔϧγεςϜͷγϯϓϧ Խ • NodeͷطଘϞδϡʔϧͱͷੑٻΊͯ· ͤΜɻ • import૬ରύε͔ઈରύεɺ͘͠URL ͚ͩͰ͔͠ࢦఆͰ͖·ͤΜɻ import {
test } from "https://unpkg.com/
[email protected]
/testing.ts" import { log } from "./util.ts" ͍͗͞Α͗͢Δɻ
2018Ͱ͋Δ͜ͱΛར༻ͨ͠ Ϟσϧ • Ωϟον͞Εͳ͍ྫ֎͕ى͖ͨΒଈ࠲ʹఀࢭ͢Δ • top-level await Λαϙʔτ͢Δ • ػೳతʹॏͳΔ߹ϒϥβͱͷޓΛ༏ઌ͢
Δ • ॳGoͰ࡞͍͕ͬͯͨɺࠓRustͱC++ʹͳͬ ͍ͯΔɻ
2018Ͱ͋Δ͜ͱΛར༻ͨ͠ Ϟσϧ • Ωϟον͞Εͳ͍ྫ֎͕ى͖ͨΒଈ࠲ʹఀࢭ͢Δ • top-level await Λαϙʔτ͢Δ • ػೳతʹॏͳΔ߹ϒϥβͱͷޓΛ༏ઌ͢
Δ • ॳGoͰ࡞͍͕ͬͯͨɺࠓRustͱC++ʹͳͬ ͍ͯΔɻ ͪͳΈʹಈ͔ͯ͠Կى͖·ͤΜͰͨ͠ɻ
ײ
ײ • ·ͩ·ͩϓϩτλΠϓʢͱ͍͏ΑΓϋϩʔϫʔϧυϨϕϧʣ • Node.jsͰࢀߟʹͳΔͱ͜Ζଟͦ͏ • Node.jsʹ͓͚Δ module ͱ package
ͷ͜ͱͰ͋ΓɺσΟϨΫτϦ Λࢦͯ͠Δɻ • ҰํͰ ES Modules deno ʹ͓͚Δ module ͱ͍͏ͷϑΝΠϧͷ ࣄͰ͋Γɺ࠷ݶͷ୯Ґ͔࣋ͨ͠ͳ͍ɻ • Կ͕Ұମਖ਼ղͩͬͨͷ͔·ͩΘ͔Βͳ͍ɻ໘നͦ͏ͳ͓ͪΌ͕ग़ ͖ͯͨͷͰ৮Δͷ͓͢͢Ίɻ