avocode/json-immutable

Replace constructor.name with a bulletproof solution

Closed this issue · 8 comments

When using minified immutable.js build, serialization fails. It is possible for Maps (for instance) to be serialized as {"__iterable":"de"} as the constructor name is minified.

Interesting side-effect and corner case... working in a mono-repo via Lerna that has two packages with two instances of Immutable fails the comparison check. PackageA emits a Immutable.Map that PackageB then has to serialize.

This is such a corner case that I wouldn't expect you to even consider this, but this has cause my CI pipeline to fail as a result 😝

So if I take your comment correctly, using Lerna to manage several linked packages is a mistake? Seems like an issue with Lerna, honestly.

Don't know what Lerna is, but if it keeps multiple instances of the same package inside a build, it's not great thing.

Lerna is tooling to help manage mono-repos, you can see the issue I'm having here:

lerna/lerna#176

I did consider this issue before deciding on this but it seems such marginal that I did not even mention it.

I would suggest keeping only a single installation of immutable.js in a project. If any dependency of yours uses a different installation, would it be possible to dedupe them?

We were using the following command for this:

$ find . -name 'immutable' | grep -v '^\./node_modules/immutable' | grep 'node_modules/immutable$' | xargs rm -rf

It's a bit of a marginal issue to be sure and likely not worth consideration, to be honest. Lerna's set to be updated soon enough so this shouldn't be an issue for too much longer. My bash-fu isn't the strongest, but I was thinking I could do something like this, thanks for the help!

another wrinkle due to the change, if we're running locally and using npm link my-package-name-here we run into two different instances of immutable again. While I'm sure this works fine when you're plain npm install'ing your package, local development is hamstrung.