Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
cneumann opened this issue Oct 30, 2020 · 7 comments

Comments

@cneumann
Copy link

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?

@danmarshall
Copy link
Owner

danmarshall commented Oct 30, 2020 via email

@cneumann
Copy link
Author

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.

@danmarshall
Copy link
Owner

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?

@llorenspujol
Copy link

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.

@danmarshall
Copy link
Owner

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

@llorenspujol
Copy link

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

@danmarshall
Copy link
Owner

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

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

No branches or pull requests

3 participants