danmarshall/indefinitely-typed

Running npm install after files are copied to node_modules/@types removes them

cneumann opened this issue · 7 comments

Hi,
my project has a dev dependency on @danmarshall/deckgl-typings and when I installed it with
npm install --save-dev @danmarshall/deckgl-typings it correctly created directories and copied files to node_modules/@types/.
Now running npm install (e.g. because I pulled from my project's repo and other dependencies changed) removes the deck.gl* and related directories under node_modules/@types
npm outputs: removed 21 packages and audited 11 packages in 0.377s, which matches the 21 directories from deckgl-typings. This is with npm 6.14.5, node 12.18 on Windows 10 x64

You can reproduce with these steps:

npm init -y
npm install --save-dev @danmarshall/deckgl-typings
npm install

Should I have some different/additional dependency listed in my projects.json?

Hmm, I assume you are referring to the deckgl-typings readme and suggest adding a deck.d.ts file to my project? I do that and it works great, thanks! :)
It just felt like that was defeating the purpose of this project a little. It seems kinda unfortunate that the convenience of having the types placed under @types gets wiped away every time a coworker adds a new dependency to our project and I run npm install to bring my working copy up to date.

Oh, sorry - I was answering from my mobile and didn't see the context was on this project. 😳
Packages managers are getting good at cleaning... perhaps we can add a "restore" command?

I am suffering it too, is kind of annoying that they disappear on every npm install. Due to this, I would suggest to not copy the typings under @types/ and do always 'something' to include those types even they are not in @types folder.

I see you have one workaround:

import * as DeckTypings from "@danmarshall/deckgl-typings" 
declare module "deck.gl" { 
    export namespace DeckTypings {} 
}

but is there something that stops this library to do a workaround like including @danmarshall/deckgl-typings under the typeRoots?

  "typeRoots": [
      "node_modules/@types",
      "node_modules/@danmarshall"
  ]

With that it should be solved, and IMO it's neat and understandable.

@llorenspujol - thanks for the note. Does the typeRoots work this way?

Yes, in typeRoots are defined the root folders where the compiler would search for the type definitions, by default all TS projects have node_modules/@types but we can add more, and in this case, seems the perfect fit. I have tested it, and it works well (typescript 4.0.5). What finally is included into types is the .package.json 'types' property, in this case: "types": "deck.gl/index.d.ts".

But doing that is not enough for now with the code as it is, since some deckgl types depends on luma ones, and luma types are not included:
image

But this is easily solved referencing them in deck.gl/index.d.ts or in each file that depends on it, and it works perfectly after that.

Let me know your thoughts, and if agree, we can apply this change. I can help you if you need with MR or testing or both. If applied, it would have to be tested in different TS versions too, just for assuring that typeRoots works always the same...

@llorenspujol - sure I'm open to PRs :)