chore: simplify backend verification
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
import { execFileSync } from 'node:child_process';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { dirname, resolve } from 'node:path';
|
||||
|
||||
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
|
||||
function git(args) {
|
||||
return execFileSync('git', args, { cwd: root, encoding: 'utf8' }).trim();
|
||||
}
|
||||
|
||||
function isIgnored(file) {
|
||||
try {
|
||||
execFileSync('git', ['check-ignore', '--no-index', '-q', file], {
|
||||
cwd: root,
|
||||
stdio: 'ignore',
|
||||
});
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (error.status === 1) return false;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
function assert(condition, message) {
|
||||
if (!condition) throw new Error(message);
|
||||
}
|
||||
|
||||
const trackedDatabases = git([
|
||||
'ls-files',
|
||||
'--',
|
||||
'dev.db',
|
||||
'dev.db-*',
|
||||
'prisma/*.db',
|
||||
'prisma/*.db-*',
|
||||
])
|
||||
.split('\n')
|
||||
.filter(Boolean);
|
||||
|
||||
assert(
|
||||
trackedDatabases.length === 0,
|
||||
`Runtime SQLite files in supported locations must not be tracked; found: ${trackedDatabases.join(', ')}`,
|
||||
);
|
||||
|
||||
for (const file of [
|
||||
'dev.db',
|
||||
'dev.db-wal',
|
||||
'dev.db-shm',
|
||||
'prisma/dev.db',
|
||||
'prisma/dev.db-wal',
|
||||
'prisma/dev.db-shm',
|
||||
]) {
|
||||
assert(isIgnored(file), `Runtime SQLite file must be ignored: ${file}`);
|
||||
}
|
||||
|
||||
assert(
|
||||
!isIgnored('test/fixtures/reference.db'),
|
||||
'Intentional fixture must remain versionable',
|
||||
);
|
||||
|
||||
console.log('Backend repository hygiene verified');
|
||||
@@ -1,26 +0,0 @@
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { dirname, resolve } from 'node:path';
|
||||
|
||||
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const packageJson = JSON.parse(readFileSync(resolve(root, 'package.json'), 'utf8'));
|
||||
const nvmVersion = readFileSync(resolve(root, '.nvmrc'), 'utf8').trim();
|
||||
const expectedMajor = nvmVersion.replace(/^v/, '').split('.')[0];
|
||||
const expectedEngine = `${expectedMajor}.x`;
|
||||
|
||||
if (packageJson.engines?.node !== expectedEngine) {
|
||||
throw new Error(
|
||||
`Node runtime contracts disagree: .nvmrc=${nvmVersion}, package.json engines.node=${packageJson.engines?.node ?? 'missing'}`,
|
||||
);
|
||||
}
|
||||
|
||||
const actualVersion = process.versions.node;
|
||||
const actualMajor = actualVersion.split('.')[0];
|
||||
if (actualMajor !== expectedMajor) {
|
||||
console.error(
|
||||
`Unsupported Node.js runtime: expected ${expectedEngine}, actual ${actualVersion}. Activate .nvmrc before running repository checks.`,
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`Node.js runtime verified: ${actualVersion} (${expectedEngine})`);
|
||||
Reference in New Issue
Block a user