paralleldrive / cuid

Collision-resistant ids optimized for horizontal scaling and performance.
Other
3.44k stars 123 forks source link

Fix for webworkers #70

Closed gmaclennan closed 7 years ago

gmaclennan commented 8 years ago

This is a temporary fix to make this work in web workers and service workers. window and navigator.mimeTypes are undefined in this context. This is quick and dirty but should allow for a minor point release and allow some dependent modules to work.

As far as I can see the code that is published on npm in dist/*-cuid.js is not built from any other code, and it is not tested. Tests look like they run on source/*, and that code is in build/* but that code seems to have a different api and is not published via npm.

Therefore I have only changed dist/browser-cuid.js and hopefully merging this patch will allow a minor release off master to npm without breaking anything.

ericelliott commented 8 years ago

Please feel free to revert to the old source files since the new ones have not been properly tested, and the contributor who made the new source files has not been responsive lately.

This PR will not me merged as-is.

ericelliott commented 8 years ago

Alternatively, you can take this on: https://github.com/ericelliott/cuid/issues/68

gmaclennan commented 8 years ago

Hi @ericelliott thanks for the info, I understand the previous build process a little better now. I don't have time for #68 right now but I was hoping I could do this in a way that allowed for a patch / minor release without any breaking changes, as a stopgap until #68 is done.

Here's what I have done:

This should enable you to publish a v1.3.9 release to npm from this branch with these fixes for webworkers and serviceWorkers. The changes should not change anything if this code is not run in a webworker or serviceWorker.

To publish from this branch you will need to:

I'm not sure the best way to merge these changes into master / whether it's possible to, given that master currently has a lot of work that has not been published to npm, and a few commits since v1.2.5 have modified the dist/ directly - although those changes were only to comments not the code. I'll have to leave you to decide what to do with that.

gmaclennan commented 7 years ago

Merged into #72