Files
dinlo 436a9631fc Initial commit
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-05-31 18:44:04 +08:00

30 lines
1.2 KiB
JavaScript

import fs from 'graceful-fs';
import path from 'node:path';
import { searchForModule } from './search-module.js';
import { fileURLToPath } from 'node:url';
const electronModuleNames = ['electron', 'electron-prebuilt-compile'];
async function locateModuleByImport() {
for (const moduleName of electronModuleNames) {
try {
const modulePath = path.resolve(fileURLToPath(import.meta.resolve(path.join(moduleName, 'package.json'))), '..');
if (fs.existsSync(path.join(modulePath, 'package.json'))) {
return modulePath;
}
}
catch { // eslint-disable-line no-empty
}
}
return null;
}
export async function locateElectronModule(projectRootPath = undefined, startDir = undefined) {
startDir ??= process.cwd();
for (const moduleName of electronModuleNames) {
const electronPaths = await searchForModule(startDir, moduleName, projectRootPath);
const electronPath = electronPaths.find((ePath) => fs.existsSync(path.join(ePath, 'package.json')));
if (electronPath) {
return electronPath;
}
}
return locateModuleByImport();
}
//# sourceMappingURL=electron-locator.js.map