Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Make Node API work with CJS and ESM applications #600

Merged
merged 3 commits into from
Aug 12, 2019

Conversation

d98762625
Copy link
Member

@d98762625 d98762625 commented Jul 19, 2019

This attempts to address #596.

I also removed the node-related webpack, as consuming applications will do all necessary bundling at a later stage and it just added unnecessary time to development.

CJS compatibility

Using std/esm, we can export the CyberChef Node Api ESM project as a CJS export, making it compatible with consuming applications that use require.

By using src/node/cjs.js as the main path in the package.json, this will become the default export.

Running this example app shows the module loading errors we saw in #596 go away (run with node app.js):

// app.js
const chef = require("cyberchef");
d = chef.toBase64("hello")
console.log(d);

ESM compatibility

This now works as expected with esm consuming applications as well - we no longer need to declare the exact "deep import" path in the import. `

Running this example app shows this working (run with node --experimental-modules app.mjs):

import chef from "cyberchef";
const d = chef.toHex("hi");
console.log(d);

Note: you still need to make the 'deep import' if you want named imports.

I have tried this with v10.16.0 and v12.16.0

@n1474335 can you please verify

  • These example consuming applications work for you (use npm-link to use the external dependency locally
  • that the changes to .travis.yml are correct

Thank you!

@n1474335
Copy link
Member

Can confirm that these examples work for me in both Node 10 and Node 12. Automated tests in our CI would be good.

@d98762625
Copy link
Member Author

I'll work on adding some.

@d98762625 d98762625 changed the title Feature: Make Node API work with CJS and ESM applications WIP: Feature: Make Node API work with CJS and ESM applications Aug 2, 2019
@d98762625
Copy link
Member Author

I've added CJS, ESM and named ESM import tests which are now triggered in travis. All three work with v10.16.0 (lts), but the named import case fails in v12 due to the same crypto-api import error.

Travis is using the lts version of node for its tests so all tests will pass for the build. I will add some compatibility guidance to the Node API wiki to explain what does and doesn't work with.

@d98762625 d98762625 changed the title WIP: Feature: Make Node API work with CJS and ESM applications Feature: Make Node API work with CJS and ESM applications Aug 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants