私人打字稿库作为npm依赖

时间:2018-09-21 12:26:41

标签: git typescript npm gitlab-ci yarnpkg

我有一个Typescript库,我将其打包为npm模块。在开发前端应用程序期间,我已经使用yarn link轻松集成了该库。

现在该是设置GitLab CI并让其他开发人员在前端应用程序上工作的时候了。我目前遇到分发此软件包的问题。

我确定的选项和遇到的问题:

  • yarn add <git-url>

这将添加源代码,但是由于它是打字稿,因此未编译。我无法使用相同的tsconfig.json来编译该库。仅编译一个文件。

此解决方案还具有以下问题:端口22在开发人员的计算机上被阻止。这将阻止他们使用git+ssh。我看不到CI如何能够检索到同样适用于开发人员的软件包。

  • yarn add tar-ball

我尝试使用压缩包,但是没有明显的方式来存储这个压缩包。 GitLab不会将生成的构件暴露给其他CI管道。

  • 提供包裹

接下来,我决定尝试将节点模块添加到git repo中。但是我发现没有任何方法可以防止纱线自动移除此包装。如果我将库添加到node_modules,则在运行yarn时将其删除。

当然,我可以切换到使用私有npm模块。但是在我看来,如果您已经拥有完善的GitLab环境,则应该为内部软件包的分发提供简便的选择。

如何在没有NPM私有注册表的情况下私​​下分发Typescript软件包?

1 个答案:

答案 0 :(得分:1)

One option is to vendor the package but put it in a custom directory (not under node_modules), for example my-library, and then in the dependencies in package.json, write "my-library": "link:my-library". This will cause Yarn to create a symlink from node_modules/my-library to my-library. See this thread for more information about the link: syntax.

相关问题