Closed Hexxeh closed 5 years ago
The need to move back to src and lib makes me sad. In particular, I'd like node users to get the un-babel'd version.
We could set the "browser" field in package.json to point to the transpiled copy, and set "main" to the original version in src
? I can make that change now if you'd accept the change with that.
i think that helps. could you also move the originals back to lib, and do the browser build into a browser
directory (or whatever you want to name it)?
Please also add yourself to the contributors list in package.json.
Done, but the coveralls check is failing, but there's no source changes at this point, so that seems like it might be a false-positive.
nod. don't worry about the coveralls change. I'll pull this down and play with it over the weekend, which may need another tweak or two. Thanks for the PR!
Sounds great, please let me know if any further changes are needed. I'm hoping to avoid temporarily forking this package to pull it into our build, so I'm happy to do anything I can to get this into a published release ASAP. 😄
i'm sorry to keep asking for more things. how did you test this? can we make it easy for other people to test it in a browser?
Firefox is my highest priority.
I bet @linuxwolf could help us figure that out.
Could use Karma but it wouldn't tell us much in the case of this PR when run against modern browsers since those support >ES5 already.
I've been testing by yarn linking this into our create-react-app project and checking that the production build succeeds.
Is your create-react-app project public? Matt doesn't have time to help us this week, so let's talk requirements:
npm install
don't see any difference, the size of the download is still roughly the same and there aren't two copies to look at--headless
would be ideal. This likely means an HTML wrapper of some kind. If we can't do this with ava, I'll do the work to switch to something else.Unfortunately not, but any create-react-app that does:
import cbor from 'cbor;
cbor.encode({a: 1});
and then tries to run a production build will fail to build without this change.
I don't believe it's possible to exclude the browser files from ending up on disk for Node users, in the same way that browser developers will get the Node version on disk too.
Ava can't run tests in a browser: https://github.com/avajs/ava/blob/master/docs/recipes/browser-testing.md (it can try to emulate a browser like environment, but nothing more). Karma is designed for this.
Is having a browser test environment a blocker for landing a change to producing an ES5 build? It's not browser specific, it's just a lowest-common-denominator that build tools and engines accept.
Having a browser test environment is not a strict blocker, but I'd like to see it work once. In particular, I don't understand how this relatively-innocuous translation actually helps matters that much. It appears as if this just makes us ES5-safe, but doesn't do the browserify steps to deal with polyfilling Buffer, etc.
create-react-app uses a version of uglifyjs that can't parse ES6. You can use ES6 features in your own code, and that'll work because it gets transpiled with Babel, but it doesn't transpile dependencies. It still provides polyfills for Buffer because everything still runs through Webpack.
In general I guess transpiling dependencies is avoided because it's slower (and less fraught with edge-cases) than transpiling at publish-time?
Anything I can do to help get this landed?
This change addresses https://github.com/hildjj/node-cbor/issues/60 by running Babel over the code before publishing to npm, transpiling the code down to ES5.
The tests still pass and execute against the original code. Not sure what else I need to check to make sure I haven't broken it, but if you have concerns let me know!