Feature: Make Node API work with CJS and ESM applications #600
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 themain
path in thepackage.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
):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
):Note: you still need to make the 'deep import' if you want named imports.
I have tried this with
v10.16.0
andv12.16.0
@n1474335 can you please verify
.travis.yml
are correctThank you!