英文:
Issue pulling from Gitlab private package registry
问题
我们有一个自托管的GitLab(版本15.5.4),我已经配置好了发布npm包所需的一切。
有一个CI/CD流水线,可以正确地在包注册表中创建条目。
问题是,当我拉取这个包[npm i @scope/lib
]时(如果我在package.json中设置身份验证令牌或按照文档建议的方式传递环境变量,结果都不会改变),不希望的结果是@scope/lib
包中没有dist/
文件夹![node_module/@scope/lib/
]。
如果我浏览包注册表并手动下载.tgz
文件,我可以看到dist/
文件夹是存在的。
我尝试过对.npmignore
和"prepublish"
脚本进行了一些尝试,但都没有成功,而且我真的不知道为什么会发生这种情况。
如果有任何提示,将不胜感激。
英文:
We have a self-hosted GitLab (15.5.4) and I've configured everything we needed for publishing npm packages.
A CI/CD pipeline that properly creates the entry in the Package Registry.
The problem is that when I pull the package [npm i @scope/lib
] (It doesn't change if I cast the auth token in the package.json or I pass through an environment variable as suggested in the documentation) the unwanted result is that the @scope/lib
doesn't have the dist/
folder in it!! [node_module/@scope/lib/
].
If I browse to the Package Registry and manually download the .tgz
file I can see that the dist/
folder is present.
I've played around a bit with the .npmignore
and "prepublish"
script but I had no success and literally have no glue why this is happening.
Any tips would be very appreciated
答案1
得分: 0
-
为了澄清:
- 正确的方法是告诉
npm
保留dist/
文件夹,绕过.gitignore
文件(而不是定义一个.npmignore
文件 文章在这里),需要在package.json
中定义一个files
条目:
{ "files": [ "dist", "build", ... ] }
- 另一种不正确的方法来获取我需要的结果是使用
postinstall
命令。但这显然是一种反模式。考虑到我正在编写一个经过测试然后由 CI 编译的 TypeScript 库,没有必要在postinstall
命令中重新编译它。但在需要时,这可能是一个巧妙的解决方案。
{ "scripts": { "postinstall": "tsc src/index.ts" } }
- 正确的方法是告诉
总之,我认为这只是一个 npm
缓存问题,或更有可能是服务器端的缓存问题,因为我已经多次运行了 npm cache clean --force
。
希望这能有所帮助。
英文:
To clarify:
- The proper way is to tell
npm
to keep thedist/
folder, bypassing the.gitignore
file (instead of defining an.npmignore
article here ) is to define afiles
entry in thepackage.json
:
{
"files": [
"dist",
"build",
...
]
}
- Another unproper way to do get the result I needed is to use a
postinstall
command. But it is clearly an anti-pattern. Given that I am writing a typescript library, that is tested and then compiled by the CI, there's no need to recompile it within thepostinstall
command. But it could be an hacky solution when needed.
{
"scripts": {
"postinstall": "tsc src/index.ts"
}
}
To sum up, I think it was only an npm cache
issue or more probably a server-side cache issue, because I've run npm cache clean --force
different times.
Hope this helps.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论