Skip to content

Commit

Permalink
refactor: drop lodash.merge (#3880)
Browse files Browse the repository at this point in the history
* refactor: replace lodash.merge with ES6

* refactor: replace lodash.merge with deepmerge

* refactor: utilize hexo-util
  • Loading branch information
SukkaW authored Dec 10, 2019
1 parent 140ed36 commit c15ce89
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/hexo/load_config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

const merge = require('lodash/merge');
const { sep, resolve, join, parse } = require('path');
const tildify = require('tildify');
const Theme = require('../theme');
const Source = require('./source');
const fs = require('hexo-fs');
const chalk = require('chalk');
const { deepMerge } = require('hexo-util');

module.exports = ctx => {
if (!ctx.env.init) return;
Expand All @@ -26,7 +26,9 @@ module.exports = ctx => {

ctx.log.debug('Config loaded: %s', chalk.magenta(tildify(configPath)));

config = merge(ctx.config, config);
ctx.config = deepMerge(ctx.config, config);
config = ctx.config;

ctx.config_path = configPath;

config.root = config.root.replace(/\/*$/, '/');
Expand Down
8 changes: 4 additions & 4 deletions lib/hexo/multi_config_path.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

const { isAbsolute, resolve, join, extname } = require('path');
const fs = require('hexo-fs');
const merge = require('lodash/merge');
const yml = require('js-yaml');
const { deepMerge } = require('hexo-util');

module.exports = ctx => function multiConfigPath(base, configPaths, outputDir) {
const { log } = ctx;
Expand Down Expand Up @@ -33,7 +33,7 @@ module.exports = ctx => function multiConfigPath(base, configPaths, outputDir) {
const numPaths = paths.length;

// combine files
const combinedConfig = {};
let combinedConfig = {};
let count = 0;
for (let i = 0; i < numPaths; i++) {
const configPath = isAbsolute(paths[i]) ? paths[i] : join(base, paths[i]);
Expand All @@ -48,10 +48,10 @@ module.exports = ctx => function multiConfigPath(base, configPaths, outputDir) {
const ext = extname(paths[i]).toLowerCase();

if (ext === '.yml') {
merge(combinedConfig, yml.load(file));
combinedConfig = deepMerge(combinedConfig, yml.load(file));
count++;
} else if (ext === '.json') {
merge(combinedConfig, yml.safeLoad(file, {json: true}));
combinedConfig = deepMerge(combinedConfig, yml.safeLoad(file, {json: true}));
count++;
} else {
log.w(`Config file ${paths[i]} not supported type.`);
Expand Down

0 comments on commit c15ce89

Please sign in to comment.