mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-19 08:28:06 +02:00
chore: standardize pre-commit checks
This commit is contained in:
parent
c35297b80a
commit
52400c599c
3 changed files with 87 additions and 14 deletions
|
|
@ -1,12 +1,11 @@
|
|||
#!/usr/bin/env node
|
||||
import { spawnSync } from 'node:child_process';
|
||||
import { existsSync, readFileSync } from 'node:fs';
|
||||
import { dirname, join, relative, sep } from 'node:path';
|
||||
import { dirname, join, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
|
||||
const scriptPath = fileURLToPath(import.meta.url);
|
||||
const ktxRoot = dirname(dirname(scriptPath));
|
||||
const repoRoot = dirname(ktxRoot);
|
||||
|
||||
const packageNameByDir = new Map(
|
||||
[
|
||||
|
|
@ -35,7 +34,8 @@ const pythonPackageTests = new Map([
|
|||
]);
|
||||
|
||||
function normalizeFilePath(filePath) {
|
||||
return filePath.replaceAll('\\', '/').replace(/^\.\//, '');
|
||||
const normalized = filePath.replaceAll('\\', '/').replace(/^\.\//, '');
|
||||
return normalized.startsWith('ktx/') ? normalized.slice('ktx/'.length) : normalized;
|
||||
}
|
||||
|
||||
function stablePush(commands, key, cmd, args) {
|
||||
|
|
@ -68,13 +68,7 @@ export function planChecks(files) {
|
|||
let runAllPythonTests = false;
|
||||
|
||||
for (const rawFile of files) {
|
||||
const file = normalizeFilePath(rawFile);
|
||||
|
||||
if (!file.startsWith('ktx/')) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const ktxFile = file.slice('ktx/'.length);
|
||||
const ktxFile = normalizeFilePath(rawFile);
|
||||
|
||||
if (ktxFile.startsWith('packages/')) {
|
||||
const [, packageDir, ...rest] = ktxFile.split('/');
|
||||
|
|
@ -189,6 +183,6 @@ export function runChecks(files) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (process.argv[1] && relative(repoRoot, process.argv[1]).split(sep).join('/') === 'ktx/scripts/precommit-check.mjs') {
|
||||
if (process.argv[1] && resolve(process.argv[1]) === scriptPath) {
|
||||
process.exitCode = runChecks(process.argv.slice(2));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,16 @@ describe('precommit-check', () => {
|
|||
assert.deepEqual(commandKeys(['outside-workspace/src/app.ts']), []);
|
||||
});
|
||||
|
||||
it('runs only the touched package checks for package code', () => {
|
||||
it('runs only the touched package checks for standalone package paths', () => {
|
||||
assert.deepEqual(commandKeys(['packages/cli/src/index.ts']), [
|
||||
'boundary-check',
|
||||
'type-check:@ktx/cli',
|
||||
'build:@ktx/cli',
|
||||
'test:@ktx/cli',
|
||||
]);
|
||||
});
|
||||
|
||||
it('accepts legacy subtree-prefixed package paths', () => {
|
||||
assert.deepEqual(commandKeys(['ktx/packages/cli/src/index.ts']), [
|
||||
'boundary-check',
|
||||
'type-check:@ktx/cli',
|
||||
|
|
@ -22,12 +31,12 @@ describe('precommit-check', () => {
|
|||
});
|
||||
|
||||
it('runs the matching script test when a script changes', () => {
|
||||
assert.deepEqual(commandKeys(['ktx/scripts/check-boundaries.mjs']), [
|
||||
assert.deepEqual(commandKeys(['scripts/check-boundaries.mjs']), [
|
||||
'script-test:scripts/check-boundaries.test.mjs',
|
||||
]);
|
||||
});
|
||||
|
||||
it('runs the touched python package tests', () => {
|
||||
assert.deepEqual(commandKeys(['ktx/python/ktx-sl/semantic_layer/parser.py']), ['pytest:ktx-sl']);
|
||||
assert.deepEqual(commandKeys(['python/ktx-sl/semantic_layer/parser.py']), ['pytest:ktx-sl']);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue