Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

npm typings with no runtime dependency #550

Open
3 tasks done
kitsonk opened this issue May 25, 2016 · 6 comments
Open
3 tasks done

npm typings with no runtime dependency #550

kitsonk opened this issue May 25, 2016 · 6 comments

Comments

@kitsonk
Copy link

kitsonk commented May 25, 2016

Prerequisites

  • Please first check README. There are breaking changes from 0.x to 1.0
  • Did you check the FAQ?
  • Did you search open and closed issues to see if your issue has already been reported?

Description

A typing dependency, but not a run-time dependency.

Trying to figure out the right way of modelling a situation in typings. We are using RxJS 5 (and ES Observables) where some of our modules can consume an Observable. Because we are only consuming Observables, there isn't an actual run-time dependency on the code. Therefore we have @reactivex/rxjs as a development dependency in our package.json and we are able to build our package successfully.

If someone though tries to consume the package, they would have to require in the whole npm module to be able to successfully. This means we could "promote" the dependency to a peerDependency in the package.json but all we really want/need/etc is a way to acquire the typings without the package being installed and for us to express that dependency properly in the typings.json of the distributable package.

(Ref: dojo/compose#32)

Steps to Reproduce

  1. npm install dojo-compose --save
  2. Add "dojo-compose": "npm:dojo-compose" to typings.json
  3. Try to compile.
  4. Get errors like: Cannot find module 'node_modules/@reactivex/rxjs/dist/cjs/Rx'.

Expected behavior: [What did you expect to happen?]

Work awesome like the rest of typings.

Actual behavior: [What actually happened?]

Confusion and frustration, likely self-inflicted.

Versions

1.0.4

@unional
Copy link
Member

unional commented May 25, 2016

How do you do step 2? typings i npm:dojo-compose -S?

@kitsonk
Copy link
Author

kitsonk commented May 25, 2016

In typings.json:

{
  "globalDependencies": {
    "dojo-compose": "npm:dojo-compose"
  }
}

We plan to migrate to "UMD" .d.ts files, but that will take a while to change our pipeline I suspect. Either way, I suspect it won't eliminate the problem.

@blakeembrey
Copy link
Member

The current implementation expects that modules listed in NPM dependencies have typings either in typings.json or their own packages. Aside from that, it sounds like you have the opposite error? It's not listed at all but erroring. I'll try to look into it when I can, but do you have the specific errors? I didn't see "Cannot find module" anywhere in the codebase.

@kitsonk
Copy link
Author

kitsonk commented May 28, 2016

@blakeembrey thanks. For clarity Cannot find module 'node_modules/@reactivex/rxjs/dist/cjs/Rx'. is coming from tsc, because the resulting typings/tsd.d.ts index does not contain the typing information from RxJS.

Also for clarity, I think we are asking for a feature versus a bug fix. Currently there appears to be no way to acquire types for a npm package unless that package is installed. The problem we have is that some packages we are only dependent upon them for their typings with no run-time need for their code, therefore in the package.json we don't want to express them as a dependency or peerDependency, but the only way in the typings.json we can express that dependency is to say "acquire them from the installed npm package" and if it isn't installed when you perform a typings install I don't think there is any error emitted at all.

There may not be an easy solution to acquire just the typings from an npm package without having npm install the whole package, but ideally that is the feature being requested.

@blakeembrey
Copy link
Member

Thanks, yes. I think someone has requested this before. It would require being able to grab data from the NPM registry instead of the local filesystem. I think the easiest fix for this, for now, would be to reference the file/commit via GitHub.

@kitsonk
Copy link
Author

kitsonk commented Jun 1, 2016

I think the easiest fix for this, for now, would be to reference the file/commit via GitHub.

Thanks. The only challenge is that many packages only generate their typings in their distributions and are not checked into GitHub (such as RxJS). So the only option would to be to extract the typings and host elsewhere on GitHub.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants