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

A reusable library with a global dependency won't install #620

Open
vitaly-t opened this issue Jun 27, 2016 · 8 comments
Open

A reusable library with a global dependency won't install #620

vitaly-t opened this issue Jun 27, 2016 · 8 comments
Labels

Comments

@vitaly-t
Copy link

vitaly-t commented Jun 27, 2016

I've spent many hours searching for an answer, but couldn't find anything usable to seemingly a simple question - how to publish a package with global dependencies.

Here I asked the question: A reusable library with typings from GitHub

this is the real code example that I have:

{
  "name": "pg-promise",
  "global": true,
  "files": [
    "typescript/pg-promise.d.ts",
    "typescript/ext-promise.d.ts",
    "typescript/pg-minify.d.ts",
    "typescript/pg-subset.d.ts"
  ],
  "globalDependencies": {
    "spex": "github:vitaly-t/spex"
  }
}

If I instruct users to issue this command:

typings install --save --global github:vitaly-t/pg-promise

it installs everything but the spex.

The only way I was able to make it work is by manually patching the client to include spex explicitely, which is very awkward.

What am I missing? How to make to work?


I am using the latest version of typings + Node.js 6.2.2

@vitaly-t vitaly-t changed the title A reusable with a global dependency won't install A reusable library with a global dependency won't install Jun 27, 2016
@unional
Copy link
Member

unional commented Jun 27, 2016

Global dependency need to be install manually by the user

@vitaly-t
Copy link
Author

Is it possible then to change my dependency to become non-global? I've tried to remove "global", or set it to false, but nothing worked:

{
  "name": "spex",
  "global": false,
  "files": [
    "typescript/spex.d.ts"
  ]
}

but if I try to install it like this

typings install github:vitaly-t/spex --save

it tells me that my dependency is global regardless?

I just want to be able to install the parent package without the user having to manually install dependencies on top of it.

@blakeembrey
Copy link
Member

@vitaly-t Global dependencies are never automatically installed. You can write the dependencies in external module format. If you share a gist or link to your example, we'd be able to point out why it's a global module and not an external module. For simplicity, any definition without a top-level import or export is considered global by TypeScript.

@blakeembrey
Copy link
Member

Actually, I found it: https://github.com/vitaly-t/spex/blob/master/typescript/spex.d.ts. Don't wrap it in declare module "..." - that makes it a global dependencies.

@blakeembrey
Copy link
Member

Also, FWIW, you don't need Typings to type your library - if you type spex.d.ts as an external module, add a typings property to package.json, then type pg-promise in the same way - TypeScript will automatically pick it up.

@unional
Copy link
Member

unional commented Jun 27, 2016

If it is a module, you can and you should. Change the typings to external module format and publish them to the registry

@vitaly-t
Copy link
Author

vitaly-t commented Jun 27, 2016

I thought that declare module was required when implementing ambient declarations, because that's what that library is, it represents an interface for a JavaScript library.

How else should I declare an ambient module?

@blakeembrey
Copy link
Member

No. You can read about writing TypeScript definitions for existing libraries: http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html. For example, here's a definition for one of mine - see https://github.com/blakeembrey/change-case/blob/master/package.json#L6 and https://github.com/blakeembrey/change-case/blob/master/change-case.d.ts. Notice all the dependencies are also written in external module format. There is no reason you should have to write a module in global declaration format, it's a left-over and bad practice from before better tooling existed.

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

No branches or pull requests

3 participants