以下内容对我有用.npmrc
@mvce-superstars:registry=https://npm.pkg.github.com
Using yarn v2 https://yarnpkg.com/getting-started/install,以下内容对我有用.yarnrc.yml https://yarnpkg.com/configuration/yarnrc:
npmScopes:
"mvce-superstars":
npmAlwaysAuth: true
npmAuthToken: xxx-xxx # optional
npmRegistryServer: "https://npm.pkg.github.com"
Note
范围名称是小写。这应该是名字
存储库的所有者(例如MVCE-Superstars https://github.com/MVCE-Superstars) 包裹在哪里
已发布,但名称必须全部小写。
设置
出版
- 我创建了一个私人副本 https://help.github.com/en/github/creating-cloning-and-archiving-repositories/duplicating-a-repository这个的你好世界 https://github.com/rms1000watt/hello-world-npm.git存储库。
- 我复制了上面的内容
.npmrc
OR .yarnrc.yml
文件到存储库中。
- 接下来我使用以下方式登录
npm login --registry=https://npm.pkg.github.com/
OR yarn npm login --scope=mvce-superstars
命令 (skip if npmAuthToken https://yarnpkg.com/configuration/yarnrc#npmAuthToken上面指定了)
- 我输入了我的 github 用户名,以及我的token https://github.com/settings/tokens(带范围
read:package
, write:package
, and repo
) (skip if npmAuthToken
上面指定了)
- 最后,我使用将包推送到我的私人仓库
npm publish
OR yarn npm publish
Output
npm notice
npm notice ???? @mvce-superstars/[email protected] /cdn-cgi/l/email-protection
npm notice === Tarball Contents ===
npm notice 16.3kB example.gif
npm notice 89B bin.js
npm notice 175B lib/index.js
npm notice 734B package.json
npm notice 2.0kB yarn-error.log
npm notice 570B Readme.md
npm notice 167B init.sh
npm notice === Tarball Details ===
npm notice name: @mvce-superstars/hello-world-npm
npm notice version: 1.1.1
npm notice package size: 14.3 kB
npm notice unpacked size: 20.0 kB
npm notice shasum: 5379c8030fa9c5f57e5baef67f2a8a784ce93361
npm notice integrity: sha512-FAI/Wuy4gHW8C[...]FINQeIlZ+HDdg==
npm notice total files: 7
npm notice
+ @mvce-superstars/[email protected] /cdn-cgi/l/email-protection
正在下载
- 我使用创建一个新的 npm 项目
npm init
(use-hello-world-npm
)
- 我复制上面的
.npmrc
到文件夹的根目录
- 接下来我注销 npm (
npm logout --registry=https://npm.pkg.github.com/
) 并重新登录 (npm login --registry=https://npm.pkg.github.com/
), 只是要确定
- 最后,我跑
yarn
就像它应该的那样,它起作用了!
Output
yarn install v1.22.4
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 0.55s.
yarn v2
➤ YN0000: ┌ Resolution step
➤ YN0014: │ @mvce-superstars/hello-world-npm@npm:^1.1.1: Only some patterns can be imported from legacy lockfiles (not "https://npm.pkg.github.com/download/@mvce-superstars/hello-world-npm/1.1.1/426126f89734c2c76bfac0342c1de9c95ad003b6e905a7b9f9f745892c86da7a#5379c8030fa9c5f57e5baef67f2a8a784ce93361")
➤ YN0000: └ Completed in 0.55s
➤ YN0000: ┌ Fetch step
➤ YN0013: │ @mvce-superstars/hello-world-npm@npm:1.1.1::__archiveUrl=https%3A%2F%2Fnpm.pkg.github.com%2Fdownload%2F%40mvce-superstars%2Fhello-world-npm%2F1.1.1%2F426126f89734c2c76bfac0342c1de9c95ad003b6e905a7b9f9f745892c86da7a can't be found in the cache and will be fetched from the remote server
➤ YN0000: └ Completed in 1.3s
➤ YN0000: ┌ Link step
➤ YN0031: │ One or more node_modules have been detected and will be removed. This operation may take some time.
➤ YN0000: └ Completed
➤ YN0000: Done with warnings in 1.87s
之后的文件夹内容yarn
.
├── node_modules
│ └── @mvce-superstars
├── package.json
└── yarn.lock
为了更好地衡量,我将其删除(yarn remove @mvce-superstars/hello-world-npm
):
yarn remove v1.22.4
[1/2] Removing module @mvce-superstars/hello-world-npm...
[2/2] Regenerating lockfile and installing missing dependencies...
success Uninstalled packages.
Done in 0.06s.
并再次添加(yarn add @mvce-superstars/hello-world-npm
):
yarn add v1.22.4
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 1 new dependency.
info Direct dependencies
└─ @mvce-superstars/[email protected] /cdn-cgi/l/email-protection
info All dependencies
└─ @mvce-superstars/[email protected] /cdn-cgi/l/email-protection
Done in 1.08s.
Sources:
- https://help.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-npm-for-use-with-github-packages https://help.github.com/en/packages/using-github-packages-with-your-projects-ecosystem/configuring-npm-for-use-with-github-packages
- https://gemfury.com/help/private-yarn/ https://gemfury.com/help/private-yarn/
- https://github.com/yarnpkg/yarn/issues/4451 https://github.com/yarnpkg/yarn/issues/4451