GitNexus/.devcontainer/resources.cjs
Gergő Magyar b961e695ca
Some checks failed
Devcontainer Smoke / Config-transform unit tests (push) Has been cancelled
Devcontainer Smoke / Build devcontainer image (default) (push) Has been cancelled
Publish Development Images / publish (core) (push) Has been cancelled
Publish Development Images / publish (ui) (push) Has been cancelled
Devcontainer Smoke / Build devcontainer image (ui) (push) Has been cancelled
CodeQL / Analyze (python) (push) Waiting to run
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
Gitleaks / gitleaks (push) Waiting to run
Publish / ci (push) Blocked by required conditions
Publish / Classify release event (push) Waiting to run
Publish / RC guard (marker + release-PR skip) (push) Blocked by required conditions
Publish / Publish to npm (push) Blocked by required conditions
Publish / Build & Push RC Docker images (push) Blocked by required conditions
Scorecard / Scorecard analysis (push) Waiting to run
Skill copy sync / shipped skills drift guard (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-cli) (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-web) (push) Waiting to run
fix(devcontainer): refresh Node and streamline development (#3610)
2026-10-17 21:05:13 +00:00

33 lines
1.1 KiB
JavaScript

'use strict';
const fs = require('node:fs');
const os = require('node:os');
function read(file) {
try {
return fs.readFileSync(file, 'utf8').trim();
} catch {
return 'unavailable';
}
}
function workerBudget({
memory = os.totalmem(),
parallelism = os.availableParallelism(),
memoryMax = read('/sys/fs/cgroup/memory.max'),
cpuMax = read('/sys/fs/cgroup/cpu.max'),
override = process.env.GITNEXUS_DEV_TEST_WORKERS,
} = {}) {
if (override !== undefined && override !== '') {
if (!/^[1-9][0-9]?$/.test(override))
throw new Error('GITNEXUS_DEV_TEST_WORKERS must be an integer from 1 to 99');
return Number(override);
}
if (/^[0-9]+$/.test(memoryMax)) memory = Math.min(memory, Number(memoryMax));
const [quota, period] = cpuMax.split(' ').map(Number);
if (Number.isFinite(quota) && quota > 0 && period > 0)
parallelism = Math.min(parallelism, Math.max(1, Math.floor(quota / period)));
// Leave room for the editor/API and native allocations outside Node's heap.
return Math.max(1, Math.min(4, parallelism - 1, Math.floor(memory / 2 ** 30) - 1));
}
module.exports = { read, workerBudget };