udacity / cloudflare-typescript-workers

Types and mocks for building a tested Typescript Cloudflare Worker, generates three NPM packages
Apache License 2.0
139 stars 12 forks source link

Missing Dependency in cloudflare-worker-mock's package.json #21

Open SNordlinger opened 4 years ago

SNordlinger commented 4 years ago

It appears that cloudflare-worker-mock has a dependency on @udacity/types-service-worker-mock, which is not listed as a dependency in the package.json.

Requiring the module in JS gives this error:

Error: Cannot find module '@udacity/types-service-worker-mock/global'

Thanks for all your work on this!

13rac1 commented 4 years ago

Thanks!

It's listed as a peer dependency: https://github.com/udacity/cloudflare-typescript-workers/blob/c782815348ee378c703484d8714a5188de06c109/packages/cloudflare-worker-mock/package.json Which I think (open for arguments against) is correct, because cloudflare-worker-mock can used in JS-only codebases too.

SNordlinger commented 4 years ago

Ugh, I definitely missed the peer dependency dialog when installing... 🤦‍♂

My project is JS-only. Looking through my node modules, it seems the import '@udacity/types-service-worker-mock/global' statement is not being erased by the typescript compiler and a require statement is making it into the published package. In JS, types-service-worker-mock/global.js is a no-op, but it is required to make things happy.

I feel like there's got to be a way to not have the dependency in JS, but I'm not all that familiar with global augmentation in typescript. Maybe the type-only imports in typescript 3.8 might help?

13rac1 commented 4 years ago

I'm not sure what the ideal solution for this is. :thinking: