Restructure solution layout by module

This commit is contained in:
master
2025-10-28 15:10:40 +02:00
parent 95daa159c4
commit d870da18ce
4103 changed files with 192899 additions and 187024 deletions

View File

@@ -0,0 +1,133 @@
const { existsSync, readdirSync, statSync } = require('fs');
const { join } = require('path');
const linuxArchivePath = ['.cache', 'chromium', 'chrome-linux64', 'chrome'];
const windowsArchivePath = ['.cache', 'chromium', 'chrome-win64', 'chrome.exe'];
const macArchivePath = [
'.cache',
'chromium',
'chrome-mac',
'Chromium.app',
'Contents',
'MacOS',
'Chromium'
];
function expandVersionedArchives(rootDir = join(__dirname, '..')) {
const base = join(rootDir, '.cache', 'chromium');
if (!existsSync(base)) {
return [];
}
const nestedCandidates = [];
for (const entry of readdirSync(base)) {
const nestedRoot = join(base, entry);
try {
if (!statSync(nestedRoot).isDirectory()) {
continue;
}
} catch {
continue;
}
nestedCandidates.push(
join(nestedRoot, 'chrome-linux64', 'chrome'),
join(nestedRoot, 'chrome-win64', 'chrome.exe'),
join(nestedRoot, 'chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium')
);
}
return nestedCandidates;
}
function expandNestedArchives(rootDir = join(__dirname, '..')) {
const base = join(rootDir, '.cache', 'chromium');
if (!existsSync(base)) {
return [];
}
const maxDepth = 4;
const queue = [{ dir: base, depth: 0 }];
const candidates = [];
while (queue.length) {
const { dir, depth } = queue.shift();
let entries;
try {
entries = readdirSync(dir);
} catch {
continue;
}
for (const entry of entries) {
const nested = join(dir, entry);
let stats;
try {
stats = statSync(nested);
} catch {
continue;
}
if (!stats.isDirectory()) {
continue;
}
candidates.push(
join(nested, 'chrome-linux64', 'chrome'),
join(nested, 'chrome-win64', 'chrome.exe'),
join(nested, 'chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium')
);
if (depth + 1 <= maxDepth) {
queue.push({ dir: nested, depth: depth + 1 });
}
}
}
return candidates;
}
function candidatePaths(rootDir = join(__dirname, '..')) {
const { env } = process;
const baseCandidates = [
env.STELLAOPS_CHROMIUM_BIN,
env.CHROME_BIN,
env.PUPPETEER_EXECUTABLE_PATH,
'/usr/bin/chromium-browser',
'/usr/bin/chromium',
'/usr/bin/google-chrome',
'/usr/bin/google-chrome-stable',
join(rootDir, ...linuxArchivePath),
join(rootDir, ...windowsArchivePath),
join(rootDir, ...macArchivePath),
...expandVersionedArchives(rootDir),
...expandNestedArchives(rootDir)
];
const seen = new Set();
return baseCandidates
.filter(Boolean)
.filter((candidate) => {
if (seen.has(candidate)) {
return false;
}
seen.add(candidate);
return true;
});
}
function resolveChromeBinary(rootDir = join(__dirname, '..')) {
for (const candidate of candidatePaths(rootDir)) {
if (existsSync(candidate)) {
return candidate;
}
}
return null;
}
module.exports = {
candidatePaths,
resolveChromeBinary
};

View File

@@ -0,0 +1,24 @@
#!/usr/bin/env node
const { resolveChromeBinary, candidatePaths } = require('./chrome-path');
const { join } = require('path');
const projectRoot = join(__dirname, '..');
const resolved = resolveChromeBinary(projectRoot);
if (resolved) {
console.log(`Chromium binary detected: ${resolved}`);
process.exit(0);
}
console.error('Chromium binary not found.');
console.error('Checked locations:');
for (const candidate of candidatePaths(projectRoot)) {
console.error(` - ${candidate}`);
}
console.error('');
console.error(
'Ensure Google Chrome/Chromium is available on PATH, set CHROME_BIN/STELLAOPS_CHROMIUM_BIN, or drop an offline Chromium build under .cache/chromium/.'
);
console.error('See docs/DeterministicInstall.md for detailed guidance.');
process.exit(1);