Skip to content

Commit

Permalink
Improve CJS and ESM module support #1037
Browse files Browse the repository at this point in the history
  • Loading branch information
n1474335 committed Mar 28, 2022
1 parent 78a1827 commit 75dba51
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 47 deletions.
9 changes: 1 addition & 8 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ module.exports = function (grunt) {

grunt.registerTask("testnodeconsumer",
"A task which checks whether consuming CJS and ESM apps work with the CyberChef build",
["exec:setupNodeConsumers", "exec:testCJSNodeConsumer", "exec:testESMNodeConsumer", "exec:testESMDeepImportNodeConsumer", "exec:teardownNodeConsumers"]);
["exec:setupNodeConsumers", "exec:testCJSNodeConsumer", "exec:testESMNodeConsumer", "exec:teardownNodeConsumers"]);

grunt.registerTask("default",
"Lints the code base",
Expand Down Expand Up @@ -403,13 +403,6 @@ module.exports = function (grunt) {
]),
stdout: false,
},
testESMDeepImportNodeConsumer: {
command: chainCommands([
`cd ${nodeConsumerTestPath}`,
`node ${nodeFlags} esm-deep-import-consumer.mjs`,
]),
stdout: false,
},
fixCryptoApiImports: {
command: [
`[[ "$OSTYPE" == "darwin"* ]]`,
Expand Down
11 changes: 4 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@
"type": "git",
"url": "https://github.com/gchq/CyberChef/"
},
"main": "src/node/cjs.js",
"module": "src/node/index.mjs",
"main": "src/node/wrapper.js",
"exports": {
".": {
"require": "./src/node/cjs.js",
"import": "./src/node/index.mjs"
}
"import": "./src/node/index.mjs",
"require": "./src/node/wrapper.js"
},
"bugs": "https://github.com/gchq/CyberChef/issues",
"browserslist": [
Expand Down Expand Up @@ -174,7 +171,7 @@
"scripts": {
"start": "npx grunt dev",
"build": "npx grunt prod",
"repl": "node src/node/repl.js",
"repl": "node --experimental-modules --experimental-json-modules --experimental-specifier-resolution=node --no-warnings src/node/repl.mjs",
"test": "npx grunt configTests && node --experimental-modules --experimental-json-modules --no-warnings --no-deprecation tests/node/index.mjs && node --experimental-modules --experimental-json-modules --no-warnings --no-deprecation tests/operations/index.mjs",
"test-node-consumer": "npx grunt testnodeconsumer",
"testui": "npx grunt testui",
Expand Down
4 changes: 2 additions & 2 deletions src/node/repl.js → src/node/repl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
* @license Apache-2.0
*/

const chef = require("./cjs.js");
const repl = require("repl");
import chef from "./index.mjs";
import repl from "repl";


/* eslint no-console: ["off"] */
Expand Down
File renamed without changes.
24 changes: 22 additions & 2 deletions tests/node/consumers/esm-consumer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,28 @@
*/
import assert from "assert";
import chef from "cyberchef";
import { bake, toHex, reverse, unique, multiply } from "cyberchef";

const d = chef.bake("Testing, 1 2 3", [
const a = bake("Testing, 1 2 3", [
toHex,
reverse,
{
op: unique,
args: {
delimiter: "Space",
}
},
{
op: multiply,
args: {
delimiter: "Space",
}
}
]);

assert.equal(a.value, "630957449041920");

const b = chef.bake("Testing, 1 2 3", [
chef.toHex,
chef.reverse,
{
Expand All @@ -25,4 +45,4 @@ const d = chef.bake("Testing, 1 2 3", [
}
]);

assert.equal(d.value, "630957449041920");
assert.equal(b.value, "630957449041920");
28 changes: 0 additions & 28 deletions tests/node/consumers/esm-deep-import-consumer.mjs

This file was deleted.

0 comments on commit 75dba51

Please sign in to comment.