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

hexojs / hexo / 6654591373

26 Oct 2023 01:10PM UTC coverage: 99.529%. Remained the same
6654591373

push

github

web-flow
Merge pull request #5328 from hexojs/v7.0.0

merge v7.0.0 branch

2285 of 2375 branches covered (0.0%)

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

8884 of 8926 relevant lines covered (99.53%)

54.82 hits per line

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

97.53
/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

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

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

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

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

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

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

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

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

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

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

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

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

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

1✔
79
function displayPath(path, baseDirLength) {
3✔
80
  return magenta(path.substring(baseDirLength));
3✔
81
}
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