• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hexojs / hexo / 6709541831

31 Oct 2023 04:27PM UTC coverage: 99.535%. Remained the same
6709541831

Pull #5342

github

web-flow
Merge f4a5ef6ff into f7a581ea1
Pull Request #5342: fix(types): cast from `number` to `string` explicitly

2285 of 2375 branches covered (0.0%)

2 of 2 new or added lines in 2 files covered. (100.0%)

8997 of 9039 relevant lines covered (99.54%)

54.16 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.56
/lib/hexo/load_plugins.ts
1
import { join } from 'path';
1✔
2
import { exists, readFile, listDir } from 'hexo-fs';
1✔
3
import Promise from 'bluebird';
1✔
4
import { magenta } from 'picocolors';
1✔
5
import type Hexo from './index';
1✔
6

1✔
7
export = (ctx: Hexo) => {
1✔
8
  if (!ctx.env.init || ctx.env.safe) return;
82✔
9

18✔
10
  return loadModules(ctx).then(() => loadScripts(ctx));
18✔
11
};
18✔
12

1✔
13
function loadModuleList(ctx: Hexo, basedir: string) {
36✔
14
  const packagePath = join(basedir, 'package.json');
36✔
15

36✔
16
  // Make sure package.json exists
36✔
17
  return exists(packagePath).then(exist => {
36✔
18
    if (!exist) return [];
36✔
19

22✔
20
    // Read package.json and find dependencies
22✔
21
    return readFile(packagePath).then(content => {
22✔
22
      const json = JSON.parse(content as string);
22✔
23
      const deps = Object.keys(json.dependencies || {});
22!
24
      const devDeps = Object.keys(json.devDependencies || {});
22✔
25

22✔
26
      return basedir === ctx.base_dir ? deps.concat(devDeps) : deps;
22✔
27
    });
22✔
28
  }).filter(name => {
36✔
29
    // Ignore plugins whose name is not started with "hexo-"
22✔
30
    if (!/^hexo-|^@[^/]+\/hexo-/.test(name)) return false;
22✔
31

21✔
32
    // Ignore plugin whose name is started with "hexo-theme"
21✔
33
    if (/^hexo-theme-|^@[^/]+\/hexo-theme-/.test(name)) return false;
22✔
34

19✔
35
    // Ignore typescript definition file that is started with "@types/"
19✔
36
    if (name.startsWith('@types/')) return false;
22✔
37

18✔
38
    // Make sure the plugin exists
18✔
39
    const path = ctx.resolvePlugin(name, basedir);
18✔
40
    return exists(path);
18✔
41
  }).then(modules => {
36✔
42
    return Object.fromEntries(modules.map(name => [name, ctx.resolvePlugin(name, basedir)]));
36✔
43
  });
36✔
44
}
36✔
45

1✔
46
function loadModules(ctx: Hexo) {
18✔
47
  return Promise.map([ctx.base_dir, ctx.theme_dir], basedir => loadModuleList(ctx, basedir))
18✔
48
    .then(([hexoModuleList, themeModuleList]) => {
18✔
49
      return Object.entries(Object.assign(themeModuleList, hexoModuleList));
18✔
50
    })
18✔
51
    .map(([name, path]) => {
18✔
52
      // Load plugins
5✔
53
      return ctx.loadPlugin(path as string).then(() => {
5✔
54
        ctx.log.debug('Plugin loaded: %s', magenta(name));
5✔
55
      }).catch(err => {
5✔
56
        ctx.log.error({err}, 'Plugin load failed: %s', magenta(name));
×
57
      });
5✔
58
    });
18✔
59
}
18✔
60

1✔
61
function loadScripts(ctx: Hexo) {
18✔
62
  const baseDirLength = ctx.base_dir.length;
18✔
63

18✔
64
  return Promise.filter([
18✔
65
    ctx.theme_script_dir,
18✔
66
    ctx.script_dir
18✔
67
  ], scriptDir => { // Ignore the directory if it does not exist
18✔
68
    return scriptDir ? exists(scriptDir) : false;
36!
69
  }).map(scriptDir => listDir(scriptDir).map(name => {
18✔
70
    const path = join(scriptDir, name);
3✔
71

3✔
72
    return ctx.loadPlugin(path).then(() => {
3✔
73
      ctx.log.debug('Script loaded: %s', displayPath(path, baseDirLength));
3✔
74
    }).catch(err => {
3✔
75
      ctx.log.error({err}, 'Script load failed: %s', displayPath(path, baseDirLength));
×
76
    });
3✔
77
  }));
18✔
78
}
18✔
79

1✔
80
function displayPath(path: string, baseDirLength: number) {
3✔
81
  return magenta(path.substring(baseDirLength));
3✔
82
}
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc