chenyc
2026-05-20 c8ba0f92b3f84273a78f06de25359db20c1b2a4d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const fs = require('fs');
const path = require('path');
 
function fileExists(filePath) {
  try {
    return fs.statSync(filePath).isFile();
  } catch (_error) {
    return false;
  }
}
 
function getDefaultConfigCandidates(options = {}) {
  const packaged = options.packaged !== undefined ? options.packaged : Boolean(process.pkg);
  const cwd = options.cwd || process.cwd();
  const appDir = options.appDir || __dirname;
  const execPath = options.execPath || process.execPath;
 
  if (packaged) {
    const execDir = path.dirname(execPath);
    return [
      path.join(execDir, 'runtime', 'config.json'),
      path.join(execDir, 'config.json'),
      path.join(cwd, 'config.json'),
    ];
  }
 
  return [
    path.join(cwd, 'config.json'),
    path.join(appDir, 'config.json'),
  ];
}
 
function getDefaultConfigPath(options = {}) {
  const candidates = getDefaultConfigCandidates(options);
  return candidates.find(fileExists) || candidates[0];
}
 
module.exports = {
  fileExists,
  getDefaultConfigCandidates,
  getDefaultConfigPath,
};