lernaでnpmにpublicなscoped packageをpublishする方法

 · 2 min read

hothouseという、package.jsonを更新してPRを作成するGreenkeeperのようなOSSを作る際に、
プラグイン開発用の内部I/Fを@hothouse/typesというpublicなパッケージとしてpublishしようとしたところ、失敗しました。

公開する時はnpm publish —access=publicとするだけです。(デフォルトが—access=restrictedであるため明示する必要がある)

npmで名前空間を持ったモジュールを公開する方法(scoped modules) | Web Scratch

単一のnpm packageなら--accessをつければ良いのですが、(少なくとも2.11.0時点で)lernaでpublishする際に--accessを指定できる余地がない。
ということで調べてみました。

対応策

"publishConfig": {
  "access": "public"
}

No docs on how to publish public scoped packages · Issue #914 · lerna/lerna

LernaのIssueにこんなコメントがついており、試してみたところ無事publishできました。

publishConfigとはなんなのか

This is a set of config values that will be used at publish-time. It’s especially handy if you want to set the tag, registry or access, so that you can ensure that a given package is not tagged with “latest”, published to the global public registry or that a scoped module is private by default. Any config values can be overridden, but only “tag”, “registry” and “access” probably matter for the purposes of publishing.

package.json | npm Documentation

その名の通り、publishするときの設定を指定するためのフィールドです。
accessフィールドに値を指定すれば、publish時のアクセス設定を変更できるということでした。

lernaの仕様ではなく、npmの仕様だったので、このオプションを安心して使用できます。

JavaScriptnpm
© 2012-2022 Leko