1
0
mirror of synced 2024-11-15 02:37: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 lint
- grunt test - grunt test
- grunt docs - grunt docs
- npm run node-prod
- grunt prod --msg="$COMPILE_MSG" - grunt prod --msg="$COMPILE_MSG"
- xvfb-run --server-args="-screen 0 1200x800x24" grunt testui - xvfb-run --server-args="-screen 0 1200x800x24" grunt testui
before_deploy: before_deploy:
@ -34,7 +33,7 @@ deploy:
file_glob: true file_glob: true
file: file:
- build/prod/*.zip - build/prod/*.zip
- build/node/CyberChef.js - src/node/cjs.js
on: on:
repo: gchq/CyberChef repo: gchq/CyberChef
tags: true tags: true

View File

@ -3,7 +3,6 @@
const webpack = require("webpack"); const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin"); const HtmlWebpackPlugin = require("html-webpack-plugin");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin; const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const NodeExternals = require("webpack-node-externals");
const glob = require("glob"); const glob = require("glob");
const path = require("path"); const path = require("path");
@ -15,7 +14,6 @@ const path = require("path");
* @license Apache-2.0 * @license Apache-2.0
*/ */
const NODE_PROD = process.env.NODE_ENV === "production";
module.exports = function (grunt) { module.exports = function (grunt) {
grunt.file.defaultEncoding = "utf8"; grunt.file.defaultEncoding = "utf8";
@ -36,8 +34,7 @@ module.exports = function (grunt) {
grunt.registerTask("node", grunt.registerTask("node",
"Compiles CyberChef into a single NodeJS module.", "Compiles CyberChef into a single NodeJS module.",
[ [
"clean:node", "clean:config", "clean:nodeConfig", "exec:generateConfig", "clean:node", "clean:config", "clean:nodeConfig", "exec:generateConfig", "exec:generateNodeIndex"
"exec:generateNodeIndex", "webpack:node", "webpack:nodeRepl", "chmod:build"
]); ]);
grunt.registerTask("test", 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": { "webpack-dev-server": {
options: { options: {

5
package-lock.json generated
View File

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

View File

@ -27,7 +27,7 @@
"type": "git", "type": "git",
"url": "https://github.com/gchq/CyberChef/" "url": "https://github.com/gchq/CyberChef/"
}, },
"main": "build/node/CyberChef.js", "main": "src/node/cjs.js",
"module": "src/node/index.mjs", "module": "src/node/index.mjs",
"bugs": "https://github.com/gchq/CyberChef/issues", "bugs": "https://github.com/gchq/CyberChef/issues",
"browserslist": [ "browserslist": [
@ -108,6 +108,7 @@
"diff": "^4.0.1", "diff": "^4.0.1",
"es6-promisify": "^6.0.1", "es6-promisify": "^6.0.1",
"escodegen": "^1.11.1", "escodegen": "^1.11.1",
"esm": "^3.2.25",
"esmangle": "^1.0.1", "esmangle": "^1.0.1",
"esprima": "^4.0.1", "esprima": "^4.0.1",
"exif-parser": "^0.1.12", "exif-parser": "^0.1.12",
@ -156,9 +157,7 @@
"scripts": { "scripts": {
"start": "grunt dev", "start": "grunt dev",
"build": "grunt prod", "build": "grunt prod",
"node": "NODE_ENV=development grunt node", "repl": "node src/node/repl.js",
"node-prod": "NODE_ENV=production grunt node",
"repl": "grunt node && node build/node/CyberChef-repl.js",
"test": "grunt test", "test": "grunt test",
"test-node": "grunt test-node", "test-node": "grunt test-node",
"testui": "grunt testui", "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 * @license Apache-2.0
*/ */
import chef from "./index.mjs"; const chef = require("./cjs.js");
import repl from "repl"; const repl = require("repl");
import File from "./File.mjs";
/*eslint no-console: ["off"] */ /*eslint no-console: ["off"] */
@ -26,7 +26,7 @@ const replServer = repl.start({
prompt: "chef > ", prompt: "chef > ",
}); });
global.File = File; global.File = chef.File;
Object.keys(chef).forEach((key) => { Object.keys(chef).forEach((key) => {
if (key !== "operations") { if (key !== "operations") {