Work with / build local package

Hi,

I’m in need to develop a package, which will never be published to npm, but only shared locally with other developers and local projects. It’s kind of an API wrapper.

The actual project wants to use this package, thus it’s in local git. Available via git+ssh. Installing the package with npm install works in the way, that the sources are being fetched and put in to the correct node_modules directory.

But, the sources are not built. The package is Typescript API wrapper, which need to be build using “npm build”. The build script in package.json is simply “tsc”. Before tsc will work, npm install on this module needs to be executed, in order to fetch the required dev dependencies.

Can anyone explain what to do?

Thanks.

You might just need a prepare script which calls tsc. (I use prepare with my top-level TypeScript packages, but have not tried it in a git dependency.)

A variety of the lifecycle scripts are called for installing git dependencies to allow this sort of usage: https://docs.npmjs.com/misc/scripts

Ok, that works. At least half of it.

tsc transpiles the ts files to a js file, that’s good. But the tsconfig.json has "declaration": true, which should produce a index.d.ts file.

When I run npm build manually, this file is being created, prepare in turn does not create it.

"scripts": { "build": "tsc", "prepare": "tsc" }

Any idea?

Is the index.d.ts included in the “published” files? My understanding is the install from git is a bit like a clone+publish+install rolled together. So I would expect to see index.d.ts listed if you run this from your package:

npm pack --dry-run

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.