jeffijoe / typesync

Install missing TypeScript typings for dependencies in your package.json.
MIT License
1.53k stars 22 forks source link

Crashes from root on PNPM monorepo #116

Closed lishaduck closed 4 months ago

lishaduck commented 4 months ago

I just tried adding typesync to PSDTools/psdtools.github.io, but it crashes as follows when run from the root of the workspace:

»  TypeSync v0.12.2
✖  Cannot convert undefined or null to object
Stack:
TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at /Users/dukese01/Developer/psdtools.github.io/node_modules/.pnpm/typesync@0.12.2_typescript@5.5.3/node_modules/typesync/lib/package-source.js:73:53
    at step (/Users/dukese01/Developer/psdtools.github.io/node_modules/.pnpm/typesync@0.12.2_typescript@5.5.3/node_modules/typesync/lib/package-source.js:33:23)
    at Object.next (/Users/dukese01/Developer/psdtools.github.io/node_modules/.pnpm/typesync@0.12.2_typescript@5.5.3/node_modules/typesync/lib/package-source.js:14:53)
    at fulfilled (/Users/dukese01/Developer/psdtools.github.io/node_modules/.pnpm/typesync@0.12.2_typescript@5.5.3/node_modules/typesync/lib/package-source.js:5:58)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

It works fine in individual projects (pnpm -r exec), but fails with both pnpm exec and npx.

jeffijoe commented 4 months ago

I haven’t used workspaces before, would you be able to debug it and potentially submit a fix?

lishaduck commented 4 months ago

I haven’t used workspaces before, would you be able to debug it and potentially submit a fix?

I'd be willing to look into it :)

lishaduck commented 4 months ago

Ok, this is a bit of an edge case 🤣: I have a workspace with two packages. One of them is named gpa-calculator. Because it's a workspace, it implicitly has two dependencies, gpa-calculator and phs-map. Now, back in 2017 (2020?), someone published a package named gpa-calculator but then unpublished it. You're trying to fetch @types/gpa-calculator, but then crash because you first check if gpa-calculator exists, in case you're in a monorepo and it's a private package. It does exist, but there are no versions becuase all 5 versions were unpublished. I think the correct thing to do would be to do some validation with zod, etc, that the api is the correct format, and then throw a nicer error message if it's not.

Additionally, I found that you were still bundling for ancient node, but only specify node 16, so I updated that locally for ease of debugging. If you wish, I can also (separately) PR that, as it would also help your size and debugging.

jeffijoe commented 4 months ago

Yeah I didnt consider packages with zero versions 😅 you can bundle the node upgrade in the same PR, thats fine