Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing a private package to @types - TypeScript & NPM

Tags:

npm

typescript

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. 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?

Note: Not the typings repo, only @types on npm.

like image 232
barndog Avatar asked Dec 21 '16 18:12

barndog


1 Answers

You don't have to send your typings anywhere. You can use git url as dependency or local path


Assuming you want to create @types/secret-library. And your types are in file index.d.ts.

Create package.json with @types/secret-library as a package name

// 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 e.g. 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

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"
  }
}
like image 111
mleko Avatar answered Nov 15 '22 08:11

mleko