1
0
mirror of synced 2024-11-14 18:27:40 +01:00

use std/esm to make chef compatible with cjs projects. Remove webpack work for node

This commit is contained in:
d98762625 2019-07-19 13:14:32 +01:00
parent 897dc0fb97
commit e4d98eba6b
6 changed files with 27 additions and 54 deletions

View File

@ -12,7 +12,6 @@ script:
- grunt lint
- grunt test
- grunt docs
- npm run node-prod
- grunt prod --msg="$COMPILE_MSG"
- xvfb-run --server-args="-screen 0 1200x800x24" grunt testui
before_deploy:
@ -34,7 +33,7 @@ deploy:
file_glob: true
file:
- build/prod/*.zip
- build/node/CyberChef.js
- src/node/cjs.js
on:
repo: gchq/CyberChef
tags: true

View File

@ -3,7 +3,6 @@
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const NodeExternals = require("webpack-node-externals");
const glob = require("glob");
const path = require("path");
@ -15,7 +14,6 @@ const path = require("path");
* @license Apache-2.0
*/
const NODE_PROD = process.env.NODE_ENV === "production";
module.exports = function (grunt) {
grunt.file.defaultEncoding = "utf8";
@ -36,8 +34,7 @@ module.exports = function (grunt) {
grunt.registerTask("node",
"Compiles CyberChef into a single NodeJS module.",
[
"clean:node", "clean:config", "clean:nodeConfig", "exec:generateConfig",
"exec:generateNodeIndex", "webpack:node", "webpack:nodeRepl", "chmod:build"
"clean:node", "clean:config", "clean:nodeConfig", "exec:generateConfig", "exec:generateNodeIndex"
]);
grunt.registerTask("test",
@ -201,46 +198,6 @@ module.exports = function (grunt) {
]
};
},
node: {
mode: NODE_PROD ? "production" : "development",
target: "node",
entry: "./src/node/index.mjs",
externals: [NodeExternals({
whitelist: ["crypto-api/src/crypto-api"]
})],
output: {
filename: "CyberChef.js",
path: __dirname + "/build/node",
library: "CyberChef",
libraryTarget: "commonjs2"
},
plugins: [
new webpack.DefinePlugin(BUILD_CONSTANTS),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1
})
],
},
nodeRepl: {
mode: NODE_PROD ? "production" : "development",
target: "node",
entry: "./src/node/repl-index.mjs",
externals: [NodeExternals({
whitelist: ["crypto-api/src/crypto-api"]
})],
output: {
filename: "CyberChef-repl.js",
path: __dirname + "/build/node",
library: "CyberChef",
libraryTarget: "commonjs2"
},
plugins: [
new webpack.DefinePlugin(BUILD_CONSTANTS),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1
})
],
}
},
"webpack-dev-server": {
options: {

5
package-lock.json generated
View File

@ -5097,6 +5097,11 @@
"integrity": "sha512-qzm/XxIbxm/FHyH341ZrbnMUpe+5Bocte9xkmFMzPMjRaZMcXww+MpBptFvtU+79L362nqiLhekCxCxDPaUMBQ==",
"dev": true
},
"esm": {
"version": "3.2.25",
"resolved": "https://registry.npmjs.org/esm/-/esm-3.2.25.tgz",
"integrity": "sha512-U1suiZ2oDVWv4zPO56S0NcR5QriEahGtdN2OR6FiOG4WJvcjBVFB0qI4+eKoWFH483PKGuLuu6V8Z4T5g63UVA=="
},
"esmangle": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/esmangle/-/esmangle-1.0.1.tgz",

View File

@ -27,7 +27,7 @@
"type": "git",
"url": "https://github.com/gchq/CyberChef/"
},
"main": "build/node/CyberChef.js",
"main": "src/node/cjs.js",
"module": "src/node/index.mjs",
"bugs": "https://github.com/gchq/CyberChef/issues",
"browserslist": [
@ -108,6 +108,7 @@
"diff": "^4.0.1",
"es6-promisify": "^6.0.1",
"escodegen": "^1.11.1",
"esm": "^3.2.25",
"esmangle": "^1.0.1",
"esprima": "^4.0.1",
"exif-parser": "^0.1.12",
@ -156,9 +157,7 @@
"scripts": {
"start": "grunt dev",
"build": "grunt prod",
"node": "NODE_ENV=development grunt node",
"node-prod": "NODE_ENV=production grunt node",
"repl": "grunt node && node build/node/CyberChef-repl.js",
"repl": "node src/node/repl.js",
"test": "grunt test",
"test-node": "grunt test-node",
"testui": "grunt testui",

13
src/node/cjs.js Normal file
View File

@ -0,0 +1,13 @@
/**
* Export the main ESM module as CommonJS
*
*
* @author d98762656 [d98762625@gmail.com]
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
/*eslint no-global-assign: ["off"] */
require = require("esm")(module);
module.exports = require("./index.mjs");
module.exports.File = require("./File.mjs");

View File

@ -7,9 +7,9 @@
* @license Apache-2.0
*/
import chef from "./index.mjs";
import repl from "repl";
import File from "./File.mjs";
const chef = require("./cjs.js");
const repl = require("repl");
/*eslint no-console: ["off"] */
@ -26,7 +26,7 @@ const replServer = repl.start({
prompt: "chef > ",
});
global.File = File;
global.File = chef.File;
Object.keys(chef).forEach((key) => {
if (key !== "operations") {