简体   繁体   English

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

[英]Installing a private package to @types - TypeScript & NPM

I have a repo that's comprised only of an index.d.ts file (TypeScript definition file) that I want to share among a number of repos I have.我有一个只包含一个index.d.ts文件(TypeScript 定义文件)的存储库,我想在我拥有的多个存储库中共享该文件。 The only declaration in the type definition file is an interface like so:类型定义文件中的唯一声明是这样的接口:

interface MyInterface {
    thisSuperCoolFunction(): void;
}

Unfortunately, the definition repo and all other repos I'm using are private.不幸的是,我使用的定义仓库和所有其他仓库都是私有的。 Is it possible to submit a private npm typings project to @types so that installing it will just work but also not expose it to anyone else?是否可以向@types 提交一个私有的 npm @types项目,以便安装它可以正常工作,但也不会将其暴露给其他任何人?

Note: Not the typings repo, only @types on npm.注意:不是类型库,只有@types

You don't have to send your typings anywhere.您不必在任何地方发送您的打字。 You can use git url as dependency or local path您可以使用git url 作为依赖项本地路径


Assuming you want to create @types/secret-library .假设您要创建@types/secret-library And your types are in file index.d.ts .您的类型在文件index.d.ts中。

Create package.json with @types/secret-library as a package name使用@types/secret-library作为包名创建package.json

// package.json
{
  "name": "@types/secret-library",
  "private": true,
  "types:" "index.d.ts"
}

git url网址

Push both index.d.ts and package.json to some repo eg git.acme.com/secret-project.git .index.d.tspackage.json推送到某个仓库,例如git.acme.com/secret-project.git

Now in your other project you can reference this repository as a dependency现在在您的其他项目中,您可以将此存储库作为依赖项引用

// package.json
{
  "name": "doom-machine",
  "private": true,
  "dependencies":{
      "@types/secret-library": "git://git.acme.com/secret-project.git"
  }
}

local path本地路径

If both index.d.ts and package.json are in directory /home/evil-genius/doom-saucer如果index.d.tspackage.json都在目录/home/evil-genius/doom-saucer

You can reference this path as a dependency您可以将此路径作为依赖项引用

// 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