refactor (@embark/embark-utils): move recursiveMerge to embark-utils

This commit is contained in:
Iuri Matias 2019-03-29 18:14:33 -04:00 committed by Michael Bradley
parent 42aebb92fd
commit 79d96c3b4c
8 changed files with 25 additions and 23 deletions

View File

@ -47,6 +47,7 @@
"dependencies": {
"@babel/runtime-corejs2": "7.3.1",
"follow-redirects": "1.5.7",
"merge": "1.2.1",
"multihashes": "0.4.14",
"web3": "1.0.0-beta.37"
},

View File

@ -38,6 +38,11 @@ function soliditySha3(arg) {
return Web3.utils.soliditySha3(arg);
}
function recursiveMerge(target, source) {
const merge = require('merge');
return merge.recursive(target, source);
}
const Utils = {
joinPath: function() {
const path = require('path');
@ -52,7 +57,8 @@ const Utils = {
findNextPort,
hashTo32ByteHexString,
isHex,
soliditySha3
soliditySha3,
recursiveMerge
};
module.exports = Utils;

View File

@ -124,7 +124,6 @@
"json-parse-better-errors": "1.0.2",
"live-plugin-manager-git-fix": "0.12.1",
"lodash.clonedeep": "4.5.0",
"merge": "1.2.1",
"mocha": "5.2.0",
"neo-blessed": "0.2.0",
"netcat": "1.3.5",

View File

@ -5,7 +5,7 @@ const path = require('path');
const deepEqual = require('deep-equal');
const web3 = require('web3');
const constants = require('../constants');
import {canonicalHost, defaultHost} from 'embark-utils';
import {canonicalHost, defaultHost, recursiveMerge} from 'embark-utils';
const cloneDeep = require('lodash.clonedeep');
import { replaceZeroAddressShorthand } from '../utils/addressUtils';
import { unitRegex } from "../utils/regexConstants";
@ -219,10 +219,10 @@ Config.prototype._mergeConfig = function(configFilePath, defaultConfig, env, ena
} else {
config = fs.readJSONSync(configFilePath + '.json');
}
let configObject = utils.recursiveMerge(defaultConfig, config);
let configObject = recursiveMerge(defaultConfig, config);
if (env) {
return utils.recursiveMerge(configObject['default'] || {}, configObject[env]);
return recursiveMerge(configObject['default'] || {}, configObject[env]);
}
return configObject;
};
@ -315,7 +315,7 @@ Config.prototype.loadContractsConfigFile = function() {
"web3": "1.0.0-beta",
"solc": "0.5.0"
};
var versions = utils.recursiveMerge(defaultVersions, this.embarkConfig.versions || {});
var versions = recursiveMerge(defaultVersions, this.embarkConfig.versions || {});
var configObject = {
"default": {
@ -337,7 +337,7 @@ Config.prototype.loadContractsConfigFile = function() {
var contractsConfigs = this.plugins.getPluginsProperty('contractsConfig', 'contractsConfigs');
contractsConfigs.forEach(function(pluginConfig) {
configObject = utils.recursiveMerge(configObject, pluginConfig);
configObject = recursiveMerge(configObject, pluginConfig);
});
let configFilePath = this._getFileOrObject(this.configDir, 'contracts', 'contracts');
@ -413,7 +413,7 @@ Config.prototype.loadExternalContractsFiles = function() {
};
Config.prototype.loadStorageConfigFile = function() {
var versions = utils.recursiveMerge({"ipfs-api": "17.2.4"}, this.embarkConfig.versions || {});
var versions = recursiveMerge({"ipfs-api": "17.2.4"}, this.embarkConfig.versions || {});
var configObject = {
"default": {
@ -505,7 +505,7 @@ Config.prototype.loadWebServerConfigFile = function() {
}
if (this.webServerConfig) {
// cli flags to `embark run` should override configFile and defaults (configObject)
this.webServerConfig = utils.recursiveMerge(webServerConfig, this.webServerConfig);
this.webServerConfig = recursiveMerge(webServerConfig, this.webServerConfig);
} else {
this.webServerConfig = webServerConfig;
}
@ -524,7 +524,7 @@ Config.prototype.loadEmbarkConfigFile = function() {
"generationDir": "embarkArtifacts"
};
this.embarkConfig = utils.recursiveMerge(configObject, this.embarkConfig);
this.embarkConfig = recursiveMerge(configObject, this.embarkConfig);
const contracts = this.embarkConfig.contracts;
// determine contract 'root' directories
@ -561,8 +561,8 @@ Config.prototype.loadPipelineConfigFile = function() {
if (pipelineConfigPath && fs.existsSync(pipelineConfigPath)) {
delete require.cache[pipelineConfigPath];
pipelineConfig = utils.recursiveMerge(
utils.recursiveMerge(true, pipelineConfig),
pipelineConfig = recursiveMerge(
recursiveMerge(true, pipelineConfig),
require(pipelineConfigPath)
);
}

View File

@ -2,9 +2,11 @@ import { each } from "async";
import { Callback, Logger } from "embark";
import { NodeVM, NodeVMOptions } from "vm2";
import { recursiveMerge } from "embark-utils";
const fs = require("./fs");
const path = require("path");
const { recursiveMerge, isEs6Module, compact } = require("../../utils/utils");
const { isEs6Module, compact } = require("../../utils/utils");
const WEB3_INVALID_RESPONSE_ERROR: string = "Invalid JSON RPC response";

View File

@ -1,5 +1,4 @@
import {joinPath, hashTo32ByteHexString, soliditySha3} from 'embark-utils';
const utils = require('../../utils/utils.js');
import {joinPath, hashTo32ByteHexString, soliditySha3, recursiveMerge} from 'embark-utils';
const namehash = require('eth-ens-namehash');
const async = require('async');
const embarkJsUtils = require('embarkjs').Utils;
@ -414,7 +413,7 @@ class ENS {
function getNetworkId(next) {
self.events.request('blockchain:networkId', (networkId) => {
if (ENS_CONTRACTS_CONFIG[networkId]) {
self.ensConfig = utils.recursiveMerge(self.ensConfig, ENS_CONTRACTS_CONFIG[networkId]);
self.ensConfig = recursiveMerge(self.ensConfig, ENS_CONTRACTS_CONFIG[networkId]);
}
next();
});

View File

@ -1,4 +1,5 @@
import { red } from "colors";
import { recursiveMerge } from "embark-utils";
import { performance, PerformanceObserver } from "perf_hooks";
import prettyMs from "pretty-ms";
@ -43,7 +44,7 @@ export default class LongRunningProcessTimer {
private options: LongRunningProcessTimerOptions = LongRunningProcessTimer.DEFAULT_OPTIONS,
) {
this.options = utils.recursiveMerge(LongRunningProcessTimer.DEFAULT_OPTIONS, this.options);
this.options = recursiveMerge(LongRunningProcessTimer.DEFAULT_OPTIONS, this.options);
// define mark and measurement names
this.startMark = "downloadStart" + this.packageName + this.version;

View File

@ -20,11 +20,6 @@ function fileMatchesPattern(patterns, intendedPath) {
return globule.isMatch(patterns, intendedPath);
}
function recursiveMerge(target, source) {
const merge = require('merge');
return merge.recursive(target, source);
}
function httpGetRequest(httpObj, url, callback) {
httpObj.get(url, function (res) {
let body = '';
@ -608,7 +603,6 @@ module.exports = {
dirname,
filesMatchingPattern,
fileMatchesPattern,
recursiveMerge,
httpGet,
httpsGet,
httpGetJson,