BitBoxSwiss / bitbox02-api-js

BitBox02 JavaScript library
Other
11 stars 9 forks source link

Transpile to ES5 and deploy that instead of the original ES6 #52

Closed benma closed 3 years ago

benma commented 3 years ago

It is easier to use for downstream projects if this module is transpiled to ES5 syntax. E.g. in MetaMask, we couldn't figure out how to add this library as a dependency without it being ES5.

When using the transpiled code in MyEtherWallet, everything works, but there is this new warning:


 warning  in ./node_modules/bitbox02-api/lib/bitbox02-api-go.js

Critical dependency: require function is used in a way in which dependencies cannot be statically extracted

This file is copied as is without changes, so it is not clear why this warning would appear now.

benma commented 3 years ago

@thisconnect should we commit the compiled lib/ folder as well? So it is clear what the code is that is published instead of it being generated at publish-time.

Seems people don't usually do this, but it feels strange to me not to commit it.

thisconnect commented 3 years ago

I played around with https://nodejs.org/api/packages.html#packages_conditional_exports and tested if we could ship both ES5 and ES6. But then realized that the generated src/bitbox02-api-go.js is ES5 anyways (looks like AMD?) and the entry file uses import/export, this wont work purely with native import.

thisconnect commented 3 years ago

Let's just ship commonjs ES5 with require as you do in the PR, but make it a major version bump?

We could npm version next, so api consumers could test bitbox02-api@next ... or we just make it a major version bump. (see about publishing beta verison https://docs.npmjs.com/cli/v7/commands/npm-dist-tag#purpose)

benma commented 3 years ago

@thisconnect I added 'files' and dropped '.npmignore', PTAL.

benma commented 3 years ago

@thisconnect I now also commit the transpiled lib/ and check in CI that it derives from src/. This way, we know the lib/ is always ready to be published and up to date, which seems more robust than hoping that it runs correctly (or at all) when publishing.