From 375ae9498b1dbd2fbb6e140a13c5c15da2f9d18d Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Tue, 25 May 2021 23:58:43 -0500 Subject: [PATCH 1/3] Rollup changes --- .babelrc | 4 --- .eslintignore | 4 +++ .eslintrc | 17 ++++++++++++ .eslintrc.json | 17 ------------ .gitignore | 7 +++-- .npmignore | 4 +++ .nvimrc | 1 - .prettierrc.json | 1 + .vimrc | 2 -- babel.config.js | 15 ++++++++++ package.json | 72 +++++++++++++++++++++++------------------------- rollup.config.js | 52 ++++++++++++++++++++++++++++++++++ 12 files changed, 131 insertions(+), 65 deletions(-) delete mode 100644 .babelrc create mode 100644 .eslintignore create mode 100644 .eslintrc delete mode 100644 .eslintrc.json create mode 100644 .npmignore delete mode 120000 .nvimrc delete mode 100644 .vimrc create mode 100644 babel.config.js create mode 100644 rollup.config.js diff --git a/.babelrc b/.babelrc deleted file mode 100644 index 6760090..0000000 --- a/.babelrc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "presets": ["@babel/preset-env"], - "plugins": ["@babel/plugin-proposal-class-properties", "@babel/transform-runtime"] -} diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..935c3d3 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,4 @@ +node_modules +.vscode +dist +backup \ No newline at end of file diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..d657a7e --- /dev/null +++ b/.eslintrc @@ -0,0 +1,17 @@ +{ + "env": { + "browser": true, + "node": true, + "jquery": true, + "jest/globals": true, + "es6": true + }, + "parserOptions": { + "sourceType": "module", + "allowImportExportEverywhere": true + }, + "extends": [ + "eslint:recommended" + ], + "parser": "babel-eslint" +} diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 11704c3..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "env": { - "browser": true, - "es2021": true, - "jest/globals": true - }, - "extends": "eslint:recommended", - "parserOptions": { - "ecmaVersion": 12, - "sourceType": "module" - }, - "plugins": { - "jest" - }, - "rules": { - } -} diff --git a/.gitignore b/.gitignore index 163f79a..f843fa2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ -package-lock.json -.idea/ node_modules/ -coverage/ +.vscode/ +dist/ +backup/ +.idea/ diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..935c3d3 --- /dev/null +++ b/.npmignore @@ -0,0 +1,4 @@ +node_modules +.vscode +dist +backup \ No newline at end of file diff --git a/.nvimrc b/.nvimrc deleted file mode 120000 index 1490f7a..0000000 --- a/.nvimrc +++ /dev/null @@ -1 +0,0 @@ -.vimrc \ No newline at end of file diff --git a/.prettierrc.json b/.prettierrc.json index 5d823c2..163754d 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -5,3 +5,4 @@ "singleQuote": true, "jsxBracketSameLine": true } + diff --git a/.vimrc b/.vimrc deleted file mode 100644 index 72b62bc..0000000 --- a/.vimrc +++ /dev/null @@ -1,2 +0,0 @@ -set autoread -set path+=.,src/** diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 0000000..b5d5053 --- /dev/null +++ b/babel.config.js @@ -0,0 +1,15 @@ +module.exports = function (api) { + api.cache(true); + return { + presets: [ + '@babel/preset-env' + ], + plugins: [ + '@babel/plugin-proposal-class-properties', + '@babel/plugin-proposal-private-methods', + '@babel/plugin-transform-runtime', + '@babel/plugin-transform-regenerator', + '@babel/plugin-transform-async-to-generator' + ] + }; +}; \ No newline at end of file diff --git a/package.json b/package.json index 21bed65..2332283 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,13 @@ { - "name": "@scottg1/repertory-js", + "name": "@blockstorage/repertory-js", "version": "1.3.1-r1", "description": "A Node.js module for interfacing with Repertory's remote mount API", - "scripts": { - "test": "jest", - "coverage": "jest --collect-coverage" + "author": "scott.e.graves@protonmail.com", + "license": "MIT", + "homepage": "https://bitbucket.org/blockstorage/repertory-js", + "repository": { + "type": "git", + "url": "https://bitbucket.org/blockstorage/repertory-js.git" }, "keywords": [ "repertory", @@ -20,11 +23,16 @@ "altcoin", "cryptocurrency" ], - "author": "scott.e.graves@protonmail.com", - "homepage": "https://bitbucket.org/blockstorage/repertory-js", - "license": "MIT", + "module": "dist/mjs/repertory-js.mjs", + "files": [ + "dist/mjs" + ], + "scripts": { + "build": "rollup -c", + "test": "jest", + "prepublish": "rollup -c --silent" + }, "dependencies": { - "@babel/runtime": "^7.13.9", "int64-buffer": "^1.0.0", "js-sha256": "^0.9.0", "socket-pool": "^1.2.3", @@ -32,35 +40,23 @@ "uuid": "^8.3.2" }, "devDependencies": { - "@babel/plugin-transform-runtime": "^7.13.9", - "@babel/preset-env": "^7.13.9", - "babel-plugin-transform-class-properties": "^6.24.1", - "eslint": "^7.22.0", - "eslint-plugin-jest": "^24.3.2", - "jest": "^26.6.3" - }, - "type": "module", - "jest": { - "roots": [ - "src" - ], - "modulePaths": [ - "src" - ], - "moduleDirectories": [ - "node_modules" - ], - "testMatch": [ - "**/__tests__/**/*.[jt]s?(x)", - "**/?(*.)+(spec|test).[jt]s?(x)" - ], - "transform": { - "^.+\\.js?$": "babel-jest" - } - }, - "main": "src/index.js", - "repository": { - "type": "git", - "url": "https://bitbucket.org/blockstorage/repertory-js.git" + "@babel/core": "^7.14.3", + "@babel/plugin-proposal-class-properties": "^7.13.0", + "@babel/plugin-proposal-private-methods": "^7.13.0", + "@babel/plugin-transform-async-to-generator": "^7.13.0", + "@babel/plugin-transform-regenerator": "^7.13.15", + "@babel/plugin-transform-runtime": "^7.14.3", + "@babel/preset-env": "^7.14.2", + "@rollup/plugin-babel": "^5.3.0", + "@rollup/plugin-commonjs": "^15.1.0", + "@rollup/plugin-json": "^4.0.0", + "@rollup/plugin-node-resolve": "^9.0.0", + "@types/jest": "^26.0.23", + "babel-eslint": "^10.1.0", + "jest": "^26.6.3", + "rollup": "^2.50.0", + "rollup-plugin-eslint": "^7.0.0", + "rollup-plugin-node-polyfills": "^0.2.1", + "rollup-plugin-terser": "^7.0.2" } } diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..ea0f5f5 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,52 @@ +import resolve from "@rollup/plugin-node-resolve"; +import commonjs from "@rollup/plugin-commonjs"; +import babel from "@rollup/plugin-babel"; +import { terser } from "rollup-plugin-terser"; +import json from '@rollup/plugin-json'; + +const commonConfig = { + input: 'src/index.js', + output: { + name: 'repertory-js', + sourcemap: true + }, + plugins: [ + resolve({ + customResolveOptions: { + moduleDirectory: 'node_modules' + } + }), + babel({ + exclude: 'node_modules/**', + babelHelpers: 'runtime' + }), + commonjs(), + json() + ] +}; + +// ESM config +const esmConfig = Object.assign({}, commonConfig); +esmConfig.output = Object.assign({}, commonConfig.output, { + file: 'dist/mjs/repertory-js.mjs', + format: 'esm' +}); + +// ESM prod config +const esmProdConfig = Object.assign({}, esmConfig); +esmProdConfig.output = Object.assign({}, esmConfig.output, { + file: 'dist/mjs/repertory-js.min.mjs', + sourcemap: false +}); +esmProdConfig.plugins = [ + ...esmConfig.plugins, + terser() +]; + +let configurations = []; +configurations.push( + esmConfig, + esmProdConfig +) + +export default configurations; From 67abe2abc2ae6148dcdc71315d02c194cf2fb995 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 26 May 2021 13:51:53 -0500 Subject: [PATCH 2/3] esm syntax changes --- README.md | 2 +- package.json | 2 +- src/__tests__/connection.test.js | 3 +-- src/__tests__/constants.test.js | 5 ++--- src/networking/packet.js | 18 +++++++++--------- src/utils/constants.js | 2 +- 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 42dd255..9e05b0b 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ also be set to a strong, random password. ## Example API Usage ```javascript -const rep = require('@blockstorage/repertory-js'); +import * as rep from 'repertory-js'; // Repertory host settings diff --git a/package.json b/package.json index 2332283..9bba623 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,7 @@ "altcoin", "cryptocurrency" ], + "main": "dist/mjs/repertory-js.mjs", "module": "dist/mjs/repertory-js.mjs", "files": [ "dist/mjs" @@ -34,7 +35,6 @@ }, "dependencies": { "int64-buffer": "^1.0.0", - "js-sha256": "^0.9.0", "socket-pool": "^1.2.3", "text-encoding": "^0.7.0", "uuid": "^8.3.2" diff --git a/src/__tests__/connection.test.js b/src/__tests__/connection.test.js index 9bcc75e..4bf723a 100644 --- a/src/__tests__/connection.test.js +++ b/src/__tests__/connection.test.js @@ -1,7 +1,6 @@ import connection from '../networking/connection'; import packet from '../networking/packet'; - -const Socket = require('net'); +import Socket from 'net'; test(`connect fails when error occurs during createConnection`, async () => { const mock_create = (port, host, cb) => { diff --git a/src/__tests__/constants.test.js b/src/__tests__/constants.test.js index fcf0651..18f6439 100644 --- a/src/__tests__/constants.test.js +++ b/src/__tests__/constants.test.js @@ -1,6 +1,5 @@ -import { get_version, instance_id, package_json } from '../utils/constants'; - -const uuid = require('uuid'); +import {get_version, instance_id, package_json} from '../utils/constants'; +import * as uuid from 'uuid'; test(`can read 'package.json'`, () => { console.log(package_json); diff --git a/src/networking/packet.js b/src/networking/packet.js index 7cc527b..017e165 100644 --- a/src/networking/packet.js +++ b/src/networking/packet.js @@ -1,7 +1,7 @@ import { randomBytes } from 'crypto'; -import { Int64BE, Uint64BE } from 'int64-buffer'; -import { sha256 } from 'js-sha256'; -import { TextEncoder } from 'text-encoding'; +import {Int64BE, Uint64BE} from 'int64-buffer'; +import crypto from 'crypto'; +import {TextEncoder} from 'text-encoding'; import { be_ui8_array_to_i16, @@ -158,10 +158,10 @@ export default class packet { decrypt = async () => { try { - const hash = sha256.create(); - hash.update(new TextEncoder().encode(this.token)); + let hash = crypto.createHash('sha256'); + hash = hash.update(new TextEncoder().encode(this.token)); - const key = Uint8Array.from(hash.array()); + const key = Uint8Array.from(hash.digest()); const nonce = this.buffer.slice(0, 12); this.buffer = new JSChaCha20(key, nonce, 0).decrypt( @@ -270,10 +270,10 @@ export default class packet { encrypt = async (nonce) => { try { this.push_buffer(packet.HEADER); - const hash = sha256.create(); - hash.update(new TextEncoder().encode(this.token)); + let hash = crypto.createHash('sha256'); + hash = hash.update(new TextEncoder().encode(this.token)); - const key = Uint8Array.from(hash.array()); + const key = Uint8Array.from(hash.digest()); if (!nonce) { nonce = Uint8Array.from(randomBytes(12)); } diff --git a/src/utils/constants.js b/src/utils/constants.js index 2d5d868..4b6aee9 100644 --- a/src/utils/constants.js +++ b/src/utils/constants.js @@ -1,4 +1,4 @@ -const { v4: uuidv4 } = require('uuid'); +import {v4 as uuidv4} from 'uuid'; import _package_json from '../../package.json'; export const instance_id = uuidv4(); From 5fbd9b7fc549b2edad503a02333c60bd4cc966c5 Mon Sep 17 00:00:00 2001 From: "Scott E. Graves" Date: Wed, 26 May 2021 13:52:51 -0500 Subject: [PATCH 3/3] updated ignore list --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index f843fa2..8cde9d5 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ node_modules/ dist/ backup/ .idea/ +/package-lock.json