Skip to content

Commit 6b4c4bb

Browse files
feat(load_config): remove findConfigPath
1 parent ebe92ba commit 6b4c4bb

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

lib/hexo/load_config.ts

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { sep, resolve, join, parse } from 'path';
1+
import { sep, resolve, join } from 'path';
22
import tildify from 'tildify';
33
import Theme from '../theme';
44
import Source from './source';
5-
import { exists, readdir } from 'hexo-fs';
5+
import { exists } from 'hexo-fs';
66
import { magenta } from 'picocolors';
77
import { deepMerge } from 'hexo-util';
88
import validateConfig from './validate_config';
@@ -12,13 +12,12 @@ export = async (ctx: Hexo): Promise<void> => {
1212
if (!ctx.env.init) return;
1313

1414
const baseDir = ctx.base_dir;
15-
let configPath = ctx.config_path;
15+
const configPath = ctx.config_path;
1616

17-
const path = await exists(configPath) ? configPath : await findConfigPath(configPath);
18-
if (!path) return;
19-
configPath = path;
17+
const configExists = await exists(configPath);
18+
if (!configExists) return;
2019

21-
let config = await ctx.render.render({ path });
20+
let config = await ctx.render.render({ path: configPath });
2221
if (!config || typeof config !== 'object') return;
2322

2423
ctx.log.debug('Config loaded: %s', magenta(tildify(configPath)));
@@ -63,13 +62,4 @@ export = async (ctx: Hexo): Promise<void> => {
6362
}
6463
ctx.theme_script_dir = join(ctx.theme_dir, 'scripts') + sep;
6564
ctx.theme = new Theme(ctx, { ignored });
66-
6765
};
68-
69-
async function findConfigPath(path: string): Promise<string> {
70-
const { dir, name } = parse(path);
71-
72-
const files = await readdir(dir);
73-
const item = files.find(item => item.startsWith(name));
74-
if (item != null) return join(dir, item);
75-
}

test/scripts/hexo/load_config.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('Load config', () => {
4040
try {
4141
await writeFile(configPath, '{"baz": 3}');
4242
await loadConfig(hexo);
43-
hexo.config.baz.should.eql(3);
43+
hexo.config.should.eql(defaultConfig);
4444
} finally {
4545
await unlink(configPath);
4646
}
@@ -79,8 +79,8 @@ describe('Load config', () => {
7979
try {
8080
await writeFile(realPath, '{"foo": 2}');
8181
await loadConfig(hexo);
82-
hexo.config.foo.should.eql(2);
83-
hexo.config_path.should.eql(realPath);
82+
hexo.config.should.eql(defaultConfig);
83+
hexo.config_path.should.not.eql(realPath);
8484
} finally {
8585
hexo.config_path = join(hexo.base_dir, '_config.yml');
8686
await unlink(realPath);

0 commit comments

Comments
 (0)