JavaScriptNode.js

GitHubのPackage Registoryにnpmモジュールを公開する時の覚書

自分の中での整理も兼ねて、tsdx createで作ったものをただ公開して見た時のTipsをまとめました。 .npmrcに設定を書く .npmrcにレジストリの設定を書いておきましょう。 スコープを指定しておかないと、n […]

広告ここから
広告ここまで

自分の中での整理も兼ねて、tsdx createで作ったものをただ公開して見た時のTipsをまとめました。

.npmrcに設定を書く

.npmrcにレジストリの設定を書いておきましょう。

//npm.pkg.github.com/:_authToken=${GITHUB_ACCESS_TOKEN}
@hideokamoto:registry=https://npm.pkg.github.com
registry=https://registry.npmjs.org
always-auth=false

スコープを指定しておかないと、npm installしたときにnpmjs.orgからダウンロードしてほしいものまでGitHub側を見に行ってしまうので要注意です。

$ yarn 
 yarn install v1.22.5
 info No lockfile found.
 [1/5] 🔍  Validating package.json…
 [2/5] 🔍  Resolving packages…
 error An unexpected error occurred: "https://npm.pkg.github.com/@size-limit%2fpreset-small-lib: npm package \"preset-small-lib\" does not exist under owner \"size-limit\"".
 info If you think this is a bug, please open a bug report with the information provided in "/Users/development/sandbox/react/github-registory/yarn-error.log".
 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

package.jsonに必要な情報を書く

package.jsonにいろいろと指定する必要があります。

repositoryでGitHubのリポジトリを指定する

tsdx createとかで作ると漏れていることが多く、自分はこれではまりました。どうやらリポジトリの情報がないと、HTTP 404を返される様子です。


  "repository": {
    "type": "git",
    "url": "https://github.com/hideokamoto/react-github-registory"
  },

nameに公開するユーザー / Orgの名前をつける

npmjs.orgでもそうですが、@XXXでネームスペースをつけておきましょう。

  "name": "@hideokamoto/github-registory",

publshConfigにレジストリを指定する

あとは公開するレジストリの指定も行います。

  "publishConfig": {
    "registry": "https://npm.pkg.github.com/@hideokamoto"
  },

npm publish

あとはnpm publishするだけです。この辺りは通常と特に変わりなくという印象でした。

npm notice 
 npm notice 📦  @hideokamoto/github-registory@0.1.2
 npm notice === Tarball Contents === 
 npm notice 1.1kB LICENSE                                        
 npm notice 316B  dist/github-registory.cjs.development.js       
 npm notice 260B  dist/github-registory.cjs.production.min.js    
 npm notice 223B  dist/github-registory.esm.js                   
 npm notice 210B  dist/index.js                                  
 npm notice 1.5kB package.json                                   
 npm notice 377B  dist/github-registory.cjs.development.js.map   
 npm notice 305B  dist/github-registory.cjs.production.min.js.map
 npm notice 360B  dist/github-registory.esm.js.map               
 npm notice 6.2kB README.md                                      
 npm notice 81B   dist/index.d.ts                                
 npm notice 140B  src/index.tsx                                  
 npm notice === Tarball Details === 
 npm notice name:          @hideokamoto/github-registory           
 npm notice version:       0.1.2                                   
 npm notice package size:  4.9 kB                                  
 npm notice unpacked size: 11.0 kB                                 
 npm notice shasum:        1303dac93c552dab9ad69908ef8c20e0bfd65f2f
 npm notice integrity:     sha512-cat5Bf4pj09J/[…]MSV2e2raoY+Dg==
 npm notice total files:   12                                      
 npm notice 
 @hideokamoto/github-registory@0.1.2 

公開されたかを確認する

あとはGitHubのリポジトリ側でチェックしておきましょう。

ブックマークや限定記事(予定)など

WP Kyotoサポーター募集中

WordPressやフロントエンドアプリのホスティング、Algolia・AWSなどのサービス利用料を支援する「WP Kyotoサポーター」を募集しています。
月額または年額の有料プランを契約すると、ブックマーク機能などのサポーター限定機能がご利用いただけます。

14日間のトライアルも用意しておりますので、「このサイトよく見るな」という方はぜひご検討ください。

広告ここから
広告ここまで

Related Category posts