繁体   English   中英

将私有包安装到 @types - TypeScript 和 NPM

[英]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.tspackage.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.tspackage.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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM