mirror of https://github.com/embarklabs/embark.git
refactor(@embark/code-runner): move code-runner into its own package
This commit is contained in:
parent
038928f8a5
commit
3aca2fe17b
|
@ -0,0 +1,4 @@
|
||||||
|
engine-strict = true
|
||||||
|
package-lock = false
|
||||||
|
save-exact = true
|
||||||
|
scripts-prepend-node-path = true
|
|
@ -0,0 +1,6 @@
|
||||||
|
# `embark-code-runner`
|
||||||
|
|
||||||
|
> Code execution VM for Embark
|
||||||
|
|
||||||
|
Visit [embark.status.im](https://embark.status.im/) to get started with
|
||||||
|
[Embark](https://github.com/embark-framework/embark).
|
|
@ -0,0 +1,74 @@
|
||||||
|
{
|
||||||
|
"name": "embark-code-runner",
|
||||||
|
"version": "4.1.0-beta.1",
|
||||||
|
"author": "Iuri Matias <iuri.matias@gmail.com>",
|
||||||
|
"contributors": [],
|
||||||
|
"description": "Code execution VM for Embark",
|
||||||
|
"homepage": "https://github.com/embark-framework/embark/tree/master/packages/embark-code-runner#readme",
|
||||||
|
"bugs": "https://github.com/embark-framework/embark/issues",
|
||||||
|
"keywords": [
|
||||||
|
"blockchain",
|
||||||
|
"dapps",
|
||||||
|
"ethereum",
|
||||||
|
"ipfs",
|
||||||
|
"serverless",
|
||||||
|
"solc",
|
||||||
|
"solidity"
|
||||||
|
],
|
||||||
|
"files": [
|
||||||
|
"dist"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"repository": {
|
||||||
|
"directory": "packages/embark-code-runner",
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/embark-framework/embark.git"
|
||||||
|
},
|
||||||
|
"main": "./dist/index.js",
|
||||||
|
"scripts": {
|
||||||
|
"build": "cross-env BABEL_ENV=node babel src --extensions \".js,.ts\" --out-dir dist --root-mode upward --source-maps",
|
||||||
|
"ci": "npm run qa",
|
||||||
|
"clean": "npm run reset",
|
||||||
|
"lint": "npm-run-all lint:*",
|
||||||
|
"lint:js": "eslint src/",
|
||||||
|
"lint:ts": "tslint -c tslint.json \"src/**/*.ts\"",
|
||||||
|
"package": "npm pack",
|
||||||
|
"qa": "npm-run-all lint typecheck build package",
|
||||||
|
"reset": "npx rimraf dist embark-*.tgz package",
|
||||||
|
"start": "npm run watch",
|
||||||
|
"typecheck": "tsc",
|
||||||
|
"watch": "run-p watch:*",
|
||||||
|
"watch:build": "npm run build -- --verbose --watch",
|
||||||
|
"watch:typecheck": "npm run typecheck -- --preserveWatchOutput --watch"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"extends": "../../.eslintrc.json"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@babel/runtime-corejs2": "7.3.1",
|
||||||
|
"async": "2.6.1",
|
||||||
|
"colors": "1.3.2",
|
||||||
|
"embark-utils": "^4.1.0-beta.1",
|
||||||
|
"embarkjs": "^4.1.0-beta.1",
|
||||||
|
"fs-extra": "7.0.1",
|
||||||
|
"parse-json": "4.0.0",
|
||||||
|
"vm2": "3.6.4",
|
||||||
|
"web3": "1.0.0-beta.37"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@babel/cli": "7.2.3",
|
||||||
|
"@babel/core": "7.2.2",
|
||||||
|
"@types/async": "2.0.50",
|
||||||
|
"cross-env": "5.2.0",
|
||||||
|
"eslint": "5.7.0",
|
||||||
|
"npm-run-all": "4.1.5",
|
||||||
|
"rimraf": "2.6.3",
|
||||||
|
"tslint": "5.16.0",
|
||||||
|
"typescript": "3.4.5"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8.12.0",
|
||||||
|
"npm": ">=6.4.1",
|
||||||
|
"yarn": ">=1.12.3"
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,7 +1,11 @@
|
||||||
|
import * as fs from "./fs";
|
||||||
import VM from "./vm";
|
import VM from "./vm";
|
||||||
const fs = require("./fs");
|
|
||||||
|
export { fs, VM };
|
||||||
|
|
||||||
import { Callback, Embark, Events, Logger } /* supplied by @types/embark in packages/embark-typings */ from "embark";
|
import { Callback, Embark, Events, Logger } /* supplied by @types/embark in packages/embark-typings */ from "embark";
|
||||||
import Web3 from "web3";
|
import Web3 from "web3";
|
||||||
|
|
||||||
const EmbarkJS = require("embarkjs");
|
const EmbarkJS = require("embarkjs");
|
||||||
|
|
||||||
export enum ProviderEventType {
|
export enum ProviderEventType {
|
||||||
|
@ -9,7 +13,7 @@ export enum ProviderEventType {
|
||||||
ProviderSet = "providerSet",
|
ProviderSet = "providerSet",
|
||||||
}
|
}
|
||||||
|
|
||||||
class CodeRunner {
|
export default class CodeRunner {
|
||||||
private ready: boolean = false;
|
private ready: boolean = false;
|
||||||
private blockchainConnected: boolean = false;
|
private blockchainConnected: boolean = false;
|
||||||
private logger: Logger;
|
private logger: Logger;
|
||||||
|
@ -158,5 +162,3 @@ private resetEmbarkJS(cb: Callback<null>) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = CodeRunner;
|
|
|
@ -1,12 +1,9 @@
|
||||||
import { each } from "async";
|
import { each } from "async";
|
||||||
import { Callback, Logger } /* supplied by @types/embark in packages/embark-typings */ from "embark";
|
import { Callback, Logger } /* supplied by @types/embark in packages/embark-typings */ from "embark";
|
||||||
|
import { compact, dappPath, isEs6Module, recursiveMerge } from "embark-utils";
|
||||||
|
import * as path from "path";
|
||||||
import { NodeVM, NodeVMOptions } from "vm2";
|
import { NodeVM, NodeVMOptions } from "vm2";
|
||||||
|
|
||||||
import { compact, dappPath, recursiveMerge } from "embark-utils";
|
|
||||||
|
|
||||||
const path = require("path");
|
|
||||||
const { isEs6Module } = require("../../utils/utils");
|
|
||||||
|
|
||||||
const WEB3_INVALID_RESPONSE_ERROR: string = "Invalid JSON RPC response";
|
const WEB3_INVALID_RESPONSE_ERROR: string = "Invalid JSON RPC response";
|
||||||
|
|
||||||
interface Command {
|
interface Command {
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"extends": "../../tsconfig.json",
|
||||||
|
"include": ["src/**/*"]
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"extends": "../../tslint.json"
|
||||||
|
}
|
|
@ -16,6 +16,7 @@ declare module "embark-utils" {
|
||||||
function embarkPath(...names: string[]): string;
|
function embarkPath(...names: string[]): string;
|
||||||
function exit(code?: any): void;
|
function exit(code?: any): void;
|
||||||
function findNextPort(port: number): Promise<number>;
|
function findNextPort(port: number): Promise<number>;
|
||||||
|
function isEs6Module(module: any): boolean;
|
||||||
function jsonFunctionReplacer(key: any, value: any): any;
|
function jsonFunctionReplacer(key: any, value: any): any;
|
||||||
function fuzzySearch(text: string, list: any, filter: any): any;
|
function fuzzySearch(text: string, list: any, filter: any): any;
|
||||||
function getExternalContractUrl(file: string, provideUrl: string): string;
|
function getExternalContractUrl(file: string, provideUrl: string): string;
|
||||||
|
|
|
@ -259,6 +259,13 @@ function errorMessage(e) {
|
||||||
return e;
|
return e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isConstructor(obj) {
|
||||||
|
return !!obj.prototype && !!obj.prototype.constructor.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isEs6Module(module) {
|
||||||
|
return (typeof module === 'function' && isConstructor(module)) || (typeof module === 'object' && typeof module.default === 'function' && module.__esModule);
|
||||||
|
}
|
||||||
|
|
||||||
const Utils = {
|
const Utils = {
|
||||||
anchoredValue,
|
anchoredValue,
|
||||||
|
@ -286,6 +293,7 @@ const Utils = {
|
||||||
getAddressToContract,
|
getAddressToContract,
|
||||||
getTransactionParams,
|
getTransactionParams,
|
||||||
isDocker,
|
isDocker,
|
||||||
|
isEs6Module,
|
||||||
checkIsAvailable,
|
checkIsAvailable,
|
||||||
File,
|
File,
|
||||||
findNextPort,
|
findNextPort,
|
||||||
|
|
|
@ -97,6 +97,7 @@
|
||||||
"embark-blockchain-listener": "^4.1.0-beta.1",
|
"embark-blockchain-listener": "^4.1.0-beta.1",
|
||||||
"embark-blockchain-process": "^4.1.0-beta.1",
|
"embark-blockchain-process": "^4.1.0-beta.1",
|
||||||
"embark-code-generator": "^4.1.0-beta.1",
|
"embark-code-generator": "^4.1.0-beta.1",
|
||||||
|
"embark-code-runner": "^4.1.0-beta.1",
|
||||||
"embark-compiler": "^4.1.0-beta.1",
|
"embark-compiler": "^4.1.0-beta.1",
|
||||||
"embark-console": "^4.1.0-beta.1",
|
"embark-console": "^4.1.0-beta.1",
|
||||||
"embark-console-listener": "^4.1.0-beta.1",
|
"embark-console-listener": "^4.1.0-beta.1",
|
||||||
|
|
|
@ -181,7 +181,7 @@ class Engine {
|
||||||
}
|
}
|
||||||
|
|
||||||
codeRunnerService(_options) {
|
codeRunnerService(_options) {
|
||||||
this.registerModule('codeRunner', {
|
this.registerModulePackage('embark-code-runner', {
|
||||||
ipc: this.ipc
|
ipc: this.ipc
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const utils = require('../utils/utils.js');
|
const utils = require('../utils/utils.js');
|
||||||
import { __ } from 'embark-i18n';
|
import { __ } from 'embark-i18n';
|
||||||
import { dappPath, embarkPath, joinPath } from 'embark-utils';
|
import { dappPath, embarkPath, isEs6Module, joinPath } from 'embark-utils';
|
||||||
const constants = require('embark-core/constants');
|
const constants = require('embark-core/constants');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const deepEqual = require('deep-equal');
|
const deepEqual = require('deep-equal');
|
||||||
|
@ -98,7 +98,7 @@ Plugin.prototype.loadPlugin = function() {
|
||||||
if (this.shouldInterceptLogs) {
|
if (this.shouldInterceptLogs) {
|
||||||
this.setUpLogger();
|
this.setUpLogger();
|
||||||
}
|
}
|
||||||
if (utils.isEs6Module(this.pluginModule)) {
|
if (isEs6Module(this.pluginModule)) {
|
||||||
if (this.pluginModule.default) {
|
if (this.pluginModule.default) {
|
||||||
this.pluginModule = this.pluginModule.default;
|
this.pluginModule = this.pluginModule.default;
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ Plugin.prototype.loadPlugin = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Plugin.prototype.loadInternalPlugin = function() {
|
Plugin.prototype.loadInternalPlugin = function() {
|
||||||
if (utils.isEs6Module(this.pluginModule)) {
|
if (isEs6Module(this.pluginModule)) {
|
||||||
if (this.pluginModule.default) {
|
if (this.pluginModule.default) {
|
||||||
this.pluginModule = this.pluginModule.default;
|
this.pluginModule = this.pluginModule.default;
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,14 +154,6 @@ function getWindowSize() {
|
||||||
return {width: 240, height: 75};
|
return {width: 240, height: 75};
|
||||||
}
|
}
|
||||||
|
|
||||||
function isConstructor(obj) {
|
|
||||||
return !!obj.prototype && !!obj.prototype.constructor.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isEs6Module(module) {
|
|
||||||
return (typeof module === 'function' && isConstructor(module)) || (typeof module === 'object' && typeof module.default === 'function' && module.__esModule);
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
dirname,
|
dirname,
|
||||||
filesMatchingPattern,
|
filesMatchingPattern,
|
||||||
|
@ -178,6 +170,5 @@ module.exports = {
|
||||||
extractZip,
|
extractZip,
|
||||||
normalizeInput,
|
normalizeInput,
|
||||||
interceptLogs,
|
interceptLogs,
|
||||||
getWindowSize,
|
getWindowSize
|
||||||
isEs6Module
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
/*globals describe, it*/
|
/*globals describe, it*/
|
||||||
const TestLogger = require('../lib/utils/test_logger');
|
const TestLogger = require('../lib/utils/test_logger');
|
||||||
const VM = require('../lib/modules/codeRunner/vm').default;
|
import { VM } from 'embark-code-runner';
|
||||||
const {expect} = require('chai');
|
const {expect} = require('chai');
|
||||||
|
|
||||||
describe('embark.vm', function () {
|
describe('embark.vm', function () {
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
/*global after, before, describe, it, require, process*/
|
/*global after, before, describe, it, require, process*/
|
||||||
|
import { fs } from 'embark-code-runner';
|
||||||
const { embarkPath } = require('embark-utils');
|
const { embarkPath } = require('embark-utils');
|
||||||
const {assert} = require('chai');
|
const {assert} = require('chai');
|
||||||
const os = require('os');
|
const os = require('os');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const underlyingFs = require('fs-extra');
|
const underlyingFs = require('fs-extra');
|
||||||
const fs = require('../lib/modules/codeRunner/fs');
|
|
||||||
|
|
||||||
describe('fs', () => {
|
describe('fs', () => {
|
||||||
let fsMethods = {};
|
let fsMethods = {};
|
||||||
|
@ -36,6 +36,7 @@ describe('fs', () => {
|
||||||
|
|
||||||
const helperFunctions = [
|
const helperFunctions = [
|
||||||
'dappPath',
|
'dappPath',
|
||||||
|
'default', // not a helper function but a property on `fs` due to how it's exported
|
||||||
'diagramPath',
|
'diagramPath',
|
||||||
'embarkPath',
|
'embarkPath',
|
||||||
'ipcPath',
|
'ipcPath',
|
||||||
|
|
Loading…
Reference in New Issue