[英]Installing a private package to @types - TypeScript & NPM
我有一个只包含一个index.d.ts
文件(TypeScript 定义文件)的存储库,我想在我拥有的多个存储库中共享该文件。 类型定义文件中的唯一声明是这样的接口:
interface MyInterface {
thisSuperCoolFunction(): void;
}
不幸的是,我使用的定义仓库和所有其他仓库都是私有的。 是否可以向@types 提交一个私有的 npm @types
项目,以便安装它可以正常工作,但也不会将其暴露给其他任何人?
注意:不是类型库,只有@types
。
您不必在任何地方发送您的打字。 您可以使用git url 作为依赖项或本地路径
假设您要创建@types/secret-library
。 您的类型在文件index.d.ts
中。
使用@types/secret-library
作为包名创建package.json
// package.json
{
"name": "@types/secret-library",
"private": true,
"types:" "index.d.ts"
}
将index.d.ts
和package.json
推送到某个仓库,例如git.acme.com/secret-project.git
。
现在在您的其他项目中,您可以将此存储库作为依赖项引用
// package.json
{
"name": "doom-machine",
"private": true,
"dependencies":{
"@types/secret-library": "git://git.acme.com/secret-project.git"
}
}
如果index.d.ts
和package.json
都在目录/home/evil-genius/doom-saucer
您可以将此路径作为依赖项引用
// package.json
{
"name": "doom-machine",
"private": true,
"dependencies":{
"@types/secret-library": "file:/home/evil-genius/doom-saucer"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.