Skip to content

Improve CJS and ESM module support#1037

Closed
d98762625 wants to merge 8 commits intogchq:masterfrom
d98762625:node-12-support
Closed

Improve CJS and ESM module support#1037
d98762625 wants to merge 8 commits intogchq:masterfrom
d98762625:node-12-support

Conversation

@d98762625
Copy link
Copy Markdown
Member

Functional changes:

  • Can now use chef with CJS and ES Modules
  • use exports in package.json to explicitly define entrypoints for import and require routes
  • can now use named imports with NodeJS v12+

load via require
Loading via require will take you to the esm wrapped module which exports the top-level ESModule as a CJS module. This provides full compatibility with ESM modules, but loading takes a performance hit, as shown in this PR

Performance profile

console.time('require');
require('cyberchef')
console.timeEnd('require');

// => require: 6313.314ms

Screenshot 2020-05-22 at 15 52 57

load via import
Node.js as increasing support for ESM / CJS interoperability. We can use this with a couple of extra flags. A consumer will need to use --experimental-json-modules to load JSON files as modules, and --experimental-specifier-resolution to resolve non-explicit imports in our dependencies.

Performance profile

console.time('import');
import chef from "cyberchef";
console.timeEnd('import');

// => import: 0.110ms

Screenshot 2020-05-22 at 17 24 22

Later Node.js versions
I've tested this with latest stable (14.3.0) - you don't need the --experimental-modules flag but you do need the other two when using import.

Loading
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.

3 participants