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
TypeScriptでつくるNode.jsパッケージ
Search
Yusuke Hirao
May 15, 2019
Technology
3
590
TypeScriptでつくるNode.jsパッケージ
Fukuoka.js #8「TypeScript」
Yusuke Hirao
May 15, 2019
Tweet
Share
More Decks by Yusuke Hirao
See All by Yusuke Hirao
ユニバーサルHTMLとWebのポテンシャル
yusukehirao
1
780
READMEにバッヂが欲しくてテストを書き始めました
yusukehirao
1
740
ユニバーサルなマークアップをしよう
yusukehirao
2
860
アクセシビリティチェックを自動化するためのmarkuplintのロードマップ
yusukehirao
2
2.1k
本当に必要ですか?そのJavaScript 〜スクロールイベント・リサイズイベント編〜
yusukehirao
0
580
コードレビュー なんてしてられるかッ!!
yusukehirao
24
14k
自動化をデザインしよう
yusukehirao
1
870
JSONの型のはなし
yusukehirao
0
590
トランスパイラという文化(…とその後) - PHPカンファレンス福岡2016
yusukehirao
1
2.6k
Other Decks in Technology
See All in Technology
Terraform Stacks入門 #HashiTalks
msato
0
360
なぜ今 AI Agent なのか _近藤憲児
kenjikondobai
4
1.4k
AI前提のサービス運用ってなんだろう?
ryuichi1208
8
1.4k
アジャイルチームがらしさを発揮するための目標づくり / Making the goal and enabling the team
kakehashi
3
140
B2B SaaSから見た最近のC#/.NETの進化
sansantech
PRO
0
880
第1回 国土交通省 データコンペ参加者向け勉強会③- Snowflake x estie編 -
estie
0
130
Lambda10周年!Lambdaは何をもたらしたか
smt7174
2
110
個人でもIAM Identity Centerを使おう!(アクセス管理編)
ryder472
4
230
リンクアンドモチベーション ソフトウェアエンジニア向け紹介資料 / Introduction to Link and Motivation for Software Engineers
lmi
4
300k
マルチプロダクトな開発組織で 「開発生産性」に向き合うために試みたこと / Improving Multi-Product Dev Productivity
sugamasao
1
310
Shopifyアプリ開発における Shopifyの機能活用
sonatard
4
250
10XにおけるData Contractの導入について: Data Contract事例共有会
10xinc
6
660
Featured
See All Featured
Making Projects Easy
brettharned
115
5.9k
Testing 201, or: Great Expectations
jmmastey
38
7.1k
What's in a price? How to price your products and services
michaelherold
243
12k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
Facilitating Awesome Meetings
lara
50
6.1k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
47
2.1k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
329
21k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
What's new in Ruby 2.0
geeforr
343
31k
Agile that works and the tools we love
rasmusluckow
327
21k
Transcript
5ZQF4DSJQUͰͭ͘Δ /PEFKTύοέʔδ 'VLVPLBKTň5ZQF4DSJQUʼn גࣜձࣾσΟʔθϩ 8FCΞΫηγϏϦςΟΤϯδχΞ ฏඌΏ͏ͯΜ
©2019 Yusuke Hirao גࣜձࣾσΟʔθϩ 8FCΞΫηγϏϦςΟΤϯδχΞ ฏඌΏ͏ͯΜ 5ZQF4DSJQUͰͭ͘Δ /PEFKTύοέʔδ 'VLVPLBKTň5ZQF4DSJQUʼn
©2019 Yusuke Hirao ࣗݾհ ฏඌ༏యʢͻΒ͓Ώ͏ͯΜʣ גࣜձࣾσΟʔθϩ 8FCΞΫηγϏϦςΟΤϯδχΞ ϑϩϯτΤϯυΤϯδχΞ #-0(IUUQTOPUFNVZVTVLFIJSBP Yusuke
Hirao @cloud10designs
©2019 Yusuke Hirao ͜Μͳͷ࡞ͬͯ·͢ KBDPKTຊޠ༻จࣈมϥΠϒϥϦ NBSLVQMJOU)5.-ϦϯλʔόϦσʔλʔ
©2019 Yusuke Hirao ࠓͳ͢͜ͱ ࠷ݶͷϛχϚϜͳ tsconfig.json packge.json ઃఆʹ͍ͭͯ
©2019 Yusuke Hirao ࠓͳ͞ͳ͍͜ͱ ܕͷͳ͠ NPOPSFQPʹ͍ͭͯ
©2019 Yusuke Hirao ΞδΣϯμ ίʔυΛॻ͘લʹܾΊ͓ͯ͘͜ͱ ઃఆ Ϗϧυ͢Δ ύϒϦογϡ͢Δ
©2019 Yusuke Hirao ίʔυΛॻ͘લʹܾΊ͓ͯ͘͜ͱ
©2019 Yusuke Hirao ίʔυΛॻ͘લʹܾΊ͓ͯ͘͜ͱ ϦϙδτϦͷσΟϨΫτϦߏ +BWB4DSJQUϑΝΠϧ ܕఆٛϑΝΠϧʢ*.d.tsʣͳͲͷॻ͖ग़͠ઌ w OQNͰެ։͢ΔϑΝΠϧ܊ΛೖΕΔɻ w
HJUͰআ֎͢Δɻ w ໊લlibͰdistͰԿͰ͓ΈͰɻϞδϡʔϧʹύεࢀ রͰ͖Δύοέʔδʢ5SFF4IBLJOHͷͨΊͩͬͨΓʣʹ͍ͨ͠ ߹ɺσΟϨΫτϦ໊ͪΐͬͱॏཁɻʢྫKBDPKTʣ import toHiragana from "jaco/fn/toHiragana"; toHiragana("ΧλΧφΛͻΒͳ͕ʹ");
©2019 Yusuke Hirao ίʔυΛॻ͘લʹܾΊ͓ͯ͘͜ͱ ϦϙδτϦͷσΟϨΫτϦߏ 5ZQF4DSJQUϑΝΠϧͳͲιʔείʔυஔ͖ w OQNͰެ։͠ͳ͍ʢ͍͍ͯ͠ʣɻ w ໊͜͜લ͓ΈͰɻ
©2019 Yusuke Hirao ίʔυΛॻ͘લʹܾΊ͓ͯ͘͜ͱ ϦϙδτϦͷσΟϨΫτϦߏ ϑΥϧμผʑ͕Φεεϝ w HJUOQNͷআ֎ઃఆָ͕ɻ w ܕఆٛϑΝΠϧʢ*.d.ts.mapʣͷιʔεϚοϓΛར༻Ͱ͖Δɻ
©2019 Yusuke Hirao ίʔυΛॻ͘લʹܾΊ͓ͯ͘͜ͱ ॻ͖ग़͢+4ͷόʔδϣϯʢtargetʣ es5 es2017 esnext ϝϦοτ
ͲΜͳڥͰಈ͘ /PEFKTWҎ্ ͳΒಈ͘ import.metaରԠ ʢ&4.ʹඞਢʣ σϝϦοτ async/await for..ofͳͲ͕ ϨΨγʔίʔυม͞ΕΔ ϒϥβͰ͏߹ CBCFMͳͲ͕ඞཁʹͳΔ ී௨ʹ͏ͳΒ CBCFMͳͲ͕ඞཁ
©2019 Yusuke Hirao ίʔυΛॻ͘લʹܾΊ͓ͯ͘͜ͱ ॻ͖ग़͢+4ͷϞδϡʔϧγεςϜʢmoduleʣ commonjs esnext ͦͷଞ ϝϦοτ
ݱࡏͷඪ४ import.metaରԠ ʢ&4.ʹඞਢʣ ͠ΒΜ σϝϦοτ &4.Ͱ͑ͳ͍ ී௨ʹ͏ͳΒ CBCFMͳͲ͕ඞཁ Θ͔ΒΜ
©2019 Yusuke Hirao ઃఆ
©2019 Yusuke Hirao ઃఆ $ yarn init { "name": "@yusukehirao/sample",
"version": "0.1.0-alpha.0", "main": "lib/index.js", "author": "Yusuke Hirao <
[email protected]
>", "license": "MIT" } ࣮ݧͷࡍ4DPQFEQBDLFHFʹ͠·͠ΐ͏ ઌʹܾΊͨσΟϨΫτϦͷΤϯτϦʔϑΝΠϧ import sample from "@yusukehirao/sample"; ௨ৗͷimport࣌ͷࢀরઌʹͳΔ package.json
©2019 Yusuke Hirao ઃఆ $ yarn add -D typescript ίϯύΠϥΛΠϯετʔϧ
{ "name": "@yusukehirao/sample", "version": "0.1.0-alpha.0", "main": "lib/index.js", "author": "Yusuke Hirao <
[email protected]
>", "license": "MIT", "devDependencies": { "typescript": "^3.4.5" } } package.json
©2019 Yusuke Hirao ઃఆ $ ./node_modules/.bin/tsc —init { "compilerOptions": {
"target": "es2017", "module": "commonjs", "declaration": true, "declarationMap": true, "sourceMap": true, "outDir": "./lib", "rootDir": "./src", "strict": true, "esModuleInterop": true } } tsconfig.json ܾΊͨॻ͖ग़͠ઌͱιʔείʔυஔ͖ ܾΊͨ&4όʔδϣϯϞδϡʔϧγεςϜ
©2019 Yusuke Hirao ઃఆ $ ./node_modules/.bin/tsc —init { "compilerOptions": {
"target": "es2017", "module": "commonjs", "declaration": true, "declarationMap": true, "sourceMap": true, "outDir": "./lib", "rootDir": "./src", "strict": true, "esModuleInterop": true } } tsconfig.json ܕఆٛϑΝΠϧͱιʔεϚοϓϑΝΠϧͷ ੜΛ༗ޮʹ͓ͯ͘͠
©2019 Yusuke Hirao ઃఆ ίϯύΠϧίϚϯυΛొ tsc ίϚϯυΛొ͓ͯ͘͠ { "name": "@yusukehirao/sample",
"version": "0.1.0-alpha.0", "main": "lib/index.js", "author": "Yusuke Hirao <
[email protected]
>", "license": "MIT", "scripts": { "build": "tsc", "prepack": "tsc" }, "devDependencies": { "typescript": "^3.4.5" } } package.json w Φϓγϣϯtsconfig.jsonʹॻ͍͓͚ͯ جຊ͍Βͳ͍ɻ w prepackεΫϦϓτύοέʔδެ։࣌ͷ ϏϧυΕࢭɻ
©2019 Yusuke Hirao ઃఆ ܕఆٛϑΝΠϧΛొ ΤϯτϦʔϑΝΠϧͷܕఆٛϑΝΠϧͷύε { "name": "@yusukehirao/sample", "version":
"0.1.0-alpha.0", "main": "lib/index.js", "types": "lib/index.d.ts", "author": "Yusuke Hirao <
[email protected]
>", "license": "MIT", "scripts": { "build": "tsc", "prepack": "tsc" }, "devDependencies": { "typescript": "^3.4.5" } } package.json w ܕใΛఏڙͰ͖Δɻ w Α͘ @types/xxxxxͰࢀর͢Δ %FpOJUFMZ5ZQFE%FpOJUFMZ5ZQFEʹ13 ૹΔඞཁͳ͍ɻ
©2019 Yusuke Hirao Ϗϧυ͢Δ
©2019 Yusuke Hirao Ϗϧυ͢Δ $ yarn build
©2019 Yusuke Hirao Ϗϧυ͢Δ $ yarn build
©2019 Yusuke Hirao ύϒϦογϡ͢Δ
©2019 Yusuke Hirao ύϒϦογϡ͢Δ $ touch .npmignore ύοέʔδʹؚ·ͳ͍ϑΝΠϧͷআ֎ઃఆΛ͢Δ src tsconfig.json
tsconfig.tsbuildinfo .npmignore w package.jsonͷfilesʹύοέʔδʹؚΊ ͍ͨϑΝΠϧͷϗϫΠτϦετΛॻ͍ͯΑ ͍ɻ w .npmignore͔files͕ͳ͍ͱɺ.gitignore Λআ֎ઃఆͱΈͳ͢ͷͰɺॻ͖ग़͠ઌͷσΟϨ ΫτϦ͕ύοέʔδʹೖΒͳ͍൵ࢂͳ͜ͱʹͳ Δ
©2019 Yusuke Hirao ύϒϦογϡ͢Δ $ npm publish
©2019 Yusuke Hirao ύϒϦογϡ͢Δ ܕఆٛϑΝΠϧެ։͍ͯ͠ΔͷͰɺ 5ZQF4DSJQU͔ΒͪΖΜɺ+BWB4DSJQUͰܕΛࢀরͰ͖Δ
5ZQF4DSJQUͰ ར༻ͯ͠Β͑·͢Αʔʹ
גࣜձࣾσΟʔθϩ 8FCΞΫηγϏϦςΟΤϯδχΞ ฏඌΏ͏ͯΜ 5ZQF4DSJQUͰͭ͘Δ /PEFKTύοέʔδ 'VLVPLBKTň5ZQF4DSJQUʼn