Feature: Make Node API work with CJS and ESM applications#600
Merged
Feature: Make Node API work with CJS and ESM applications#600
Conversation
Member
|
Can confirm that these examples work for me in both Node 10 and Node 12. Automated tests in our CI would be good. |
Member
Author
|
I'll work on adding some. |
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.jsas themainpath 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.0andv12.16.0@n1474335 can you please verify
.travis.ymlare correctThank you!