Open13
TypeScriptでnpmパッケージ作成
Node.jsのインストール
Ubuntuなら以下でインストールできる
$ sudo snap install node --classic
$ node -v
v15.12.0
$ npm -v
7.6.3
$ yarn -v
1.22.5
nvmとかnとかnodenvとかnodeenvとかnodebrewとかあるけど,使わない
npm登録
https://www.npmjs.com/signup から登録する.
ターミナルから以下のようにログインすると,
$ npm login
npm notice Log in on https://registry.npmjs.org/
Username: eduidl
Password:
Email: (this IS public) yuma.hiramatsu@gmail.com
Logged in as eduidl on https://registry.npmjs.org/
~/.npmrc
に以下のように追記される.
//registry.npmjs.org/:_authToken=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
トークンの破棄は,https://www.npmjs.com 上で,自分のアイコン→「Access Tokens」からできる.
ついでに .npmrc
を適当に設定しておくと,npm init
が楽になる.
.npmrc
//registry.npmjs.org/:_authToken=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
init.author.name=Yuma Hiramatsu
init.author.email=yuma.hiramatsu@gmail.com
init.author.url=https://github.com/eduidl
init.license=Apache-2.0
init.version=0.1.0
git
のremote
がセットされていると,npm init
したときにリポジトリの情報が package.json
に記述されるので,その方がよい.
ここでは,GitHub上で***というリポジトリを作った.
$ git clone <repository>
$ cd <repository>
$ npm init -y
パッケージのインストール
TypsScript
$ npm i -D typescript @types/node
lint + formatter
ESLintとPrettierを使う.
$ npm i -D eslint @typescript-eslint/eslint-plugin @typescript-eslint/parser prettier eslint-config-prettier
色々調べてたら,eslint-plugin-prettier
非推奨になっているらしい.
Test
Jestを使う.
$ npm i -D jest ts-jest @types/jest
その他
npm scriptを使いやすくするためのパッケージ
$ npm i -D npm-run-all
tsconfig.json
について