问题来自Gitlab私有包注册表

huangapple go评论75阅读模式
英文:

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 the dist/ folder, bypassing the .gitignore file (instead of defining an .npmignore article here ) is to define a files entry in the package.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 the postinstall 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.

huangapple
  • 本文由 发表于 2023年1月9日 19:06:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/75056382.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定