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

hexojs / hexo-util / 16626368405

30 Jul 2025 03:06PM UTC coverage: 68.03% (-28.8%) from 96.875%
16626368405

Pull #426

github

web-flow
Merge a039b3b6e into d497bc760
Pull Request #426: build: support both ESM and CommonJS

611 of 790 branches covered (77.34%)

1117 of 1626 new or added lines in 36 files covered. (68.7%)

116 existing lines in 2 files now uncovered.

3758 of 5524 relevant lines covered (68.03%)

64.46 hits per line

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

67.92
/scripts/pretest.mjs
1
import { spawnSync } from 'child_process';
1✔
2
import fs from 'fs';
1✔
3
import path from 'path';
1✔
4
import { fileURLToPath } from 'url';
1✔
5

1✔
6
const __filename = fileURLToPath(import.meta.url);
1✔
7
const __dirname = path.dirname(__filename);
1✔
8
const libDir = path.resolve(__dirname, '../lib');
1✔
9
const markerFile = path.resolve(__dirname, '../.last_build');
1✔
10
const extraFiles = [
1✔
11
  path.resolve(__dirname, '../test/utils.cjs'),
1✔
12
  path.resolve(__dirname, '../test/dual_mode.spec.ts'),
1✔
13
  __filename
1✔
14
];
1✔
15

1✔
NEW
16
function getAllFiles(dir) {
×
NEW
17
  let results = [];
×
NEW
18
  const list = fs.readdirSync(dir);
×
NEW
19
  list.forEach((file) => {
×
NEW
20
    const filePath = path.join(dir, file);
×
NEW
21
    const stat = fs.statSync(filePath);
×
NEW
22
    if (stat && stat.isDirectory()) {
×
NEW
23
      results = results.concat(getAllFiles(filePath));
×
NEW
24
    } else {
×
NEW
25
      results.push(filePath);
×
NEW
26
    }
×
NEW
27
  });
×
NEW
28
  return results;
×
NEW
29
}
×
30

1✔
31
function needsBuild() {
1✔
32
  if (!fs.existsSync(markerFile)) return true;
1✔
NEW
33
  const markerMtime = fs.statSync(markerFile).mtimeMs;
×
NEW
34
  const files = getAllFiles(libDir).concat(extraFiles);
×
NEW
35
  return files.some((f) => fs.existsSync(f) && fs.statSync(f).mtimeMs > markerMtime);
×
36
}
1✔
37

1✔
38
function isTestEnv() {
1✔
39
  return (
1✔
40
    process.env.MOCHA || process.argv.some((arg) => arg.includes('mocha')) || process.env.JEST_WORKER_ID !== undefined
1✔
41
  );
1✔
42
}
1✔
43

1✔
44
// If the marker file is older than the source files, rebuild
1✔
45
if (needsBuild() && !isTestEnv()) {
1✔
46
  console.log('Building hexo-util...');
1✔
47
  spawnSync('npm', ['run', 'build'], {
1✔
48
    stdio: 'inherit',
1✔
49
    cwd: process.cwd(),
1✔
50
    shell: true
1✔
51
  });
1✔
52
  fs.writeFileSync(markerFile, String(Date.now()));
1✔
53
}
1✔
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