Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: drop lodash.merge #3880

Merged
merged 3 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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