@kurvball/ashlar 0.0.0-stage → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +250 -0
- package/LICENSE +21 -0
- package/README.md +150 -2
- package/dist/affected.d.ts +19 -0
- package/dist/affected.js +78 -0
- package/dist/areas.d.ts +2 -0
- package/dist/areas.js +20 -0
- package/dist/baseline.d.ts +27 -0
- package/dist/baseline.js +109 -0
- package/dist/beside.d.ts +1 -0
- package/dist/beside.js +4 -0
- package/dist/check.d.ts +40 -0
- package/dist/check.js +109 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +215 -0
- package/dist/config.d.ts +84 -0
- package/dist/config.js +98 -0
- package/dist/configCheck.d.ts +2 -0
- package/dist/configCheck.js +204 -0
- package/dist/css.d.ts +13 -0
- package/dist/css.js +66 -0
- package/dist/drive.d.ts +77 -0
- package/dist/drive.js +188 -0
- package/dist/features.d.ts +32 -0
- package/dist/features.js +156 -0
- package/dist/git.d.ts +18 -0
- package/dist/git.js +143 -0
- package/dist/glob.d.ts +5 -0
- package/dist/glob.js +49 -0
- package/dist/graph.d.ts +16 -0
- package/dist/graph.js +83 -0
- package/dist/identity.d.ts +1 -0
- package/dist/identity.js +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +18 -0
- package/dist/jsonc.d.ts +1 -0
- package/dist/jsonc.js +66 -0
- package/dist/knowledge/areas.d.ts +25 -0
- package/dist/knowledge/areas.js +86 -0
- package/dist/knowledge/decisions.d.ts +14 -0
- package/dist/knowledge/decisions.js +53 -0
- package/dist/knowledge/guards.d.ts +4 -0
- package/dist/knowledge/guards.js +60 -0
- package/dist/knowledge/rules.d.ts +12 -0
- package/dist/knowledge/rules.js +100 -0
- package/dist/knowledge/secrets.d.ts +6 -0
- package/dist/knowledge/secrets.js +58 -0
- package/dist/layout.d.ts +61 -0
- package/dist/layout.js +120 -0
- package/dist/ledger.d.ts +28 -0
- package/dist/ledger.js +44 -0
- package/dist/lint.d.ts +11 -0
- package/dist/lint.js +109 -0
- package/dist/map.d.ts +25 -0
- package/dist/map.js +37 -0
- package/dist/move.d.ts +18 -0
- package/dist/move.js +94 -0
- package/dist/onboard/applies.d.ts +11 -0
- package/dist/onboard/applies.js +28 -0
- package/dist/onboard/brief.d.ts +40 -0
- package/dist/onboard/brief.js +126 -0
- package/dist/onboard/guide.d.ts +7 -0
- package/dist/onboard/guide.js +150 -0
- package/dist/onboard/model.d.ts +15 -0
- package/dist/onboard/model.js +57 -0
- package/dist/onboard/onboard.d.ts +28 -0
- package/dist/onboard/onboard.js +86 -0
- package/dist/onboard/questions.d.ts +15 -0
- package/dist/onboard/questions.js +90 -0
- package/dist/onboard/snapshot.d.ts +28 -0
- package/dist/onboard/snapshot.js +58 -0
- package/dist/order.d.ts +1 -0
- package/dist/order.js +1 -0
- package/dist/origins.d.ts +6 -0
- package/dist/origins.js +51 -0
- package/dist/plugin/boundaries.d.ts +5 -0
- package/dist/plugin/boundaries.js +174 -0
- package/dist/plugin/exports.d.ts +2 -0
- package/dist/plugin/exports.js +41 -0
- package/dist/plugin/features.d.ts +4 -0
- package/dist/plugin/features.js +34 -0
- package/dist/plugin/here.d.ts +13 -0
- package/dist/plugin/here.js +69 -0
- package/dist/plugin/imports.d.ts +12 -0
- package/dist/plugin/imports.js +103 -0
- package/dist/plugin/index.d.ts +14 -0
- package/dist/plugin/index.js +19 -0
- package/dist/plugin/messages.d.ts +20 -0
- package/dist/plugin/messages.js +36 -0
- package/dist/plugin/names.d.ts +3 -0
- package/dist/plugin/names.js +68 -0
- package/dist/plugin/references.d.ts +5 -0
- package/dist/plugin/references.js +52 -0
- package/dist/plugin/text.d.ts +7 -0
- package/dist/plugin/text.js +87 -0
- package/dist/plugin/types.d.ts +87 -0
- package/dist/plugin/types.js +1 -0
- package/dist/reach.d.ts +82 -0
- package/dist/reach.js +163 -0
- package/dist/reachDrive.d.ts +31 -0
- package/dist/reachDrive.js +200 -0
- package/dist/reachReader.d.ts +1 -0
- package/dist/reachReader.js +31 -0
- package/dist/rehearse/dependents.d.ts +9 -0
- package/dist/rehearse/dependents.js +38 -0
- package/dist/rehearse/fill.d.ts +28 -0
- package/dist/rehearse/fill.js +44 -0
- package/dist/report.d.ts +6 -0
- package/dist/report.js +91 -0
- package/dist/resolve.d.ts +3 -0
- package/dist/resolve.js +114 -0
- package/dist/runner.d.ts +6 -0
- package/dist/runner.js +29 -0
- package/dist/skill.d.ts +23 -0
- package/dist/skill.js +235 -0
- package/dist/usage.d.ts +1 -0
- package/dist/usage.js +55 -0
- package/dist/workspace.d.ts +16 -0
- package/dist/workspace.js +125 -0
- package/ledger.json +201 -0
- package/package.json +73 -3
- package/schema/affected.v1.json +58 -0
- package/schema/brief.v1.json +205 -0
- package/schema/check.v1.json +151 -0
- package/schema/dependents.v1.json +30 -0
- package/schema/drive.v1.json +55 -0
- package/schema/ledger.v1.json +61 -0
- package/schema/map.v1.json +62 -0
- package/schema/move.v1.json +61 -0
- package/schema/onboard.v1.json +186 -0
- package/schema/rehearse.v1.json +91 -0
- package/schema/snapshot.v1.json +101 -0
package/dist/features.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, mkdtempSync, readdirSync, readFileSync, rmSync, statSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { besideModule } from './beside.js';
|
|
6
|
+
import { tidy } from './layout.js';
|
|
7
|
+
import { featureMap, mapFeature, nameOfFolder } from './map.js';
|
|
8
|
+
import { FEATURE_REACH, REACH_FILE } from './reach.js';
|
|
9
|
+
import { walkFolders } from './workspace.js';
|
|
10
|
+
const READER = besideModule('./reachReader', import.meta.url);
|
|
11
|
+
export const READ_MS = 30_000;
|
|
12
|
+
const isFolder = (path) => statSync(path, { throwIfNoEntry: false })?.isDirectory() ?? false;
|
|
13
|
+
function subfolders(config, folder) {
|
|
14
|
+
if (!isFolder(join(config.root, folder)))
|
|
15
|
+
return [];
|
|
16
|
+
return readdirSync(join(config.root, folder), { withFileTypes: true })
|
|
17
|
+
.filter((entry) => entry.isDirectory() && !entry.name.startsWith('.') && !config.ignore.includes(entry.name))
|
|
18
|
+
.map((entry) => tidy(`${folder}/${entry.name}`));
|
|
19
|
+
}
|
|
20
|
+
export function featureFolders(config) {
|
|
21
|
+
const folders = new Set();
|
|
22
|
+
for (const app of config.apps) {
|
|
23
|
+
for (const pattern of app.roles.features) {
|
|
24
|
+
if (pattern.endsWith('/*'))
|
|
25
|
+
for (const folder of subfolders(config, pattern.slice(0, -2)))
|
|
26
|
+
folders.add(folder);
|
|
27
|
+
else if (isFolder(join(config.root, pattern)))
|
|
28
|
+
folders.add(pattern);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return [...folders].sort();
|
|
32
|
+
}
|
|
33
|
+
export function proofsOf(config, folder) {
|
|
34
|
+
const proofs = [];
|
|
35
|
+
walkFolders(config.root, [folder], new Set(config.ignore), (file) => {
|
|
36
|
+
if (config.tests.some((suffix) => file.endsWith(suffix)))
|
|
37
|
+
proofs.push(file);
|
|
38
|
+
});
|
|
39
|
+
return proofs.sort();
|
|
40
|
+
}
|
|
41
|
+
const READ_SECONDS = READ_MS / 1000;
|
|
42
|
+
export const READ_WORDS = {
|
|
43
|
+
timedOut: (file, seconds = READ_SECONDS) => `Node didn’t load ${file} in ${seconds} s: it may wait on something forever.`,
|
|
44
|
+
noNode: (file, why) => `Node couldn’t start to load ${file}: ${why}`,
|
|
45
|
+
stopped: (file, said) => `Node stopped while it loaded ${file}${said ? `: ${said}` : ', and said nothing.'}`,
|
|
46
|
+
sameName: (name, folder) => `Its name, “${name}”, is already the feature in ${folder}: give each feature a name of its own.`,
|
|
47
|
+
};
|
|
48
|
+
export function unread(run, file, readMs = READ_MS) {
|
|
49
|
+
if (run.error) {
|
|
50
|
+
const code = run.error.code;
|
|
51
|
+
return code === 'ETIMEDOUT'
|
|
52
|
+
? READ_WORDS.timedOut(file, readMs / 1000)
|
|
53
|
+
: READ_WORDS.noNode(file, run.error.message.split('\n')[0].trim());
|
|
54
|
+
}
|
|
55
|
+
return READ_WORDS.stopped(file, `${run.stderr ?? ''}`.trim().split('\n').at(-1)?.trim() ?? '');
|
|
56
|
+
}
|
|
57
|
+
function recorded(record) {
|
|
58
|
+
try {
|
|
59
|
+
return existsSync(record) ? JSON.parse(readFileSync(record, 'utf8')) : [];
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return [];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
export function readReaches(config, folders, readMs = READ_MS) {
|
|
66
|
+
const loads = new Map(folders.map((folder) => [folder, null]));
|
|
67
|
+
let left = folders.filter((folder) => existsSync(join(config.root, folder, REACH_FILE)));
|
|
68
|
+
if (left.length === 0)
|
|
69
|
+
return loads;
|
|
70
|
+
const scratch = mkdtempSync(join(tmpdir(), 'ashlar-reach-'));
|
|
71
|
+
try {
|
|
72
|
+
for (let round = 0; left.length > 0; round += 1) {
|
|
73
|
+
const record = join(scratch, `reaches-${round}.json`);
|
|
74
|
+
const files = left.map((folder) => join(config.root, folder, REACH_FILE));
|
|
75
|
+
const run = spawnSync(process.execPath, [READER, record, ...files], {
|
|
76
|
+
cwd: config.root,
|
|
77
|
+
encoding: 'utf8',
|
|
78
|
+
timeout: readMs,
|
|
79
|
+
});
|
|
80
|
+
const read = recorded(record).slice(0, left.length);
|
|
81
|
+
read.forEach((load, i) => loads.set(left[i], load));
|
|
82
|
+
if (read.length === left.length)
|
|
83
|
+
break;
|
|
84
|
+
const stuck = left[read.length];
|
|
85
|
+
loads.set(stuck, { ok: false, says: unread(run, `${stuck}/${REACH_FILE}`, readMs) });
|
|
86
|
+
left = left.slice(read.length + 1);
|
|
87
|
+
}
|
|
88
|
+
return loads;
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
rmSync(scratch, { recursive: true, force: true });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const nameKey = (name) => name.trim().replace(/\s+/g, ' ').toLowerCase();
|
|
95
|
+
function shownName(folder, load) {
|
|
96
|
+
return load?.ok ? load.script.name : nameOfFolder(folder);
|
|
97
|
+
}
|
|
98
|
+
function withOwnNames(folders, loads) {
|
|
99
|
+
for (;;) {
|
|
100
|
+
const groups = new Map();
|
|
101
|
+
for (const folder of folders) {
|
|
102
|
+
const key = nameKey(shownName(folder, loads.get(folder)));
|
|
103
|
+
groups.set(key, [...(groups.get(key) ?? []), folder]);
|
|
104
|
+
}
|
|
105
|
+
let demoted = false;
|
|
106
|
+
for (const holders of groups.values()) {
|
|
107
|
+
if (holders.length < 2)
|
|
108
|
+
continue;
|
|
109
|
+
const named = holders.filter((folder) => loads.get(folder)?.ok);
|
|
110
|
+
const keeper = named.length === holders.length ? named[0] : undefined;
|
|
111
|
+
for (const folder of named) {
|
|
112
|
+
if (folder === keeper)
|
|
113
|
+
continue;
|
|
114
|
+
const load = loads.get(folder);
|
|
115
|
+
if (!load?.ok)
|
|
116
|
+
continue;
|
|
117
|
+
const holder = keeper ?? holders.find((other) => !loads.get(other)?.ok);
|
|
118
|
+
loads.set(folder, { ok: false, says: READ_WORDS.sameName(load.script.name, holder) });
|
|
119
|
+
demoted = true;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
if (!demoted)
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export function featuresOf(config) {
|
|
127
|
+
const folders = featureFolders(config);
|
|
128
|
+
const loads = readReaches(config, folders);
|
|
129
|
+
withOwnNames(folders, loads);
|
|
130
|
+
return folders.map((folder) => {
|
|
131
|
+
const reach = loads.get(folder) ?? null;
|
|
132
|
+
return { name: shownName(folder, reach), folder, reach };
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
export function unreadText(features) {
|
|
136
|
+
const lines = features.flatMap((f) => f.reach && !f.reach.ok ? [`${f.name}’s reach script doesn’t read. ${f.reach.says}`] : []);
|
|
137
|
+
return lines.length ? `\n${lines.join('\n')}\n` : '';
|
|
138
|
+
}
|
|
139
|
+
export function buildMap(config, features = featuresOf(config)) {
|
|
140
|
+
return featureMap(features.map((feature) => mapFeature(feature.folder, feature.reach?.ok ? feature.reach.script : null, proofsOf(config, feature.folder))));
|
|
141
|
+
}
|
|
142
|
+
export function withReachBreaks(config, files, features) {
|
|
143
|
+
if (!config.rules.includes('feature-reach'))
|
|
144
|
+
return files;
|
|
145
|
+
const out = { ...files };
|
|
146
|
+
for (const feature of features ?? featuresOf(config)) {
|
|
147
|
+
if (feature.reach?.ok)
|
|
148
|
+
continue;
|
|
149
|
+
const file = `${feature.folder}/${REACH_FILE}`;
|
|
150
|
+
const was = out[file] ?? { breaks: [], edges: [] };
|
|
151
|
+
const message = config.messages['feature-reach'] ?? FEATURE_REACH.message;
|
|
152
|
+
const found = { rule: FEATURE_REACH.rule, line: 1, column: 1, size: 1, message };
|
|
153
|
+
out[file] = { ...was, breaks: [...was.breaks, found] };
|
|
154
|
+
}
|
|
155
|
+
return out;
|
|
156
|
+
}
|
package/dist/git.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type Loaded } from './config.ts';
|
|
2
|
+
export type ChangedLines = Map<string, Set<number> | 'all'>;
|
|
3
|
+
export declare function mergeBase(root: string, ref: string): string;
|
|
4
|
+
export declare function untracked(root: string, folders: string[]): string[];
|
|
5
|
+
export declare function changedSince(root: string, ref: string, folders?: string[]): string[];
|
|
6
|
+
export interface Renamed {
|
|
7
|
+
from: string;
|
|
8
|
+
to: string;
|
|
9
|
+
}
|
|
10
|
+
export declare function renamedSince(root: string, folders: string[], since?: string): Renamed[];
|
|
11
|
+
export declare function changedLines(root: string, folders: string[], since?: string): ChangedLines;
|
|
12
|
+
export declare function hasHead(root: string): boolean;
|
|
13
|
+
export declare function knownRef(root: string, ref: string): void;
|
|
14
|
+
export interface Tree {
|
|
15
|
+
config: Loaded;
|
|
16
|
+
holds: (path: string) => boolean;
|
|
17
|
+
}
|
|
18
|
+
export declare function atRef<T>(config: Loaded, ref: string, read: (tree: Tree) => T): T | null;
|
package/dist/git.js
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, mkdtempSync, realpathSync, rmSync } from 'node:fs';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
import { AshlarError } from './config.js';
|
|
6
|
+
const MAIN_REFS = ['main', 'origin/main', 'master', 'origin/master'];
|
|
7
|
+
function git(root, args) {
|
|
8
|
+
const run = spawnSync('git', args, { cwd: root, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
|
|
9
|
+
return run.status === 0 ? run.stdout : null;
|
|
10
|
+
}
|
|
11
|
+
function lines(output) {
|
|
12
|
+
return (output ?? '').split('\n').filter((line) => line !== '');
|
|
13
|
+
}
|
|
14
|
+
export function mergeBase(root, ref) {
|
|
15
|
+
const base = git(root, ['merge-base', 'HEAD', ref])?.trim();
|
|
16
|
+
if (base)
|
|
17
|
+
return base;
|
|
18
|
+
knownRef(root, ref);
|
|
19
|
+
return ref;
|
|
20
|
+
}
|
|
21
|
+
function defaultBase(root) {
|
|
22
|
+
let closest = null;
|
|
23
|
+
for (const ref of MAIN_REFS) {
|
|
24
|
+
const base = git(root, ['merge-base', 'HEAD', ref])?.trim();
|
|
25
|
+
if (!base)
|
|
26
|
+
continue;
|
|
27
|
+
const distance = Number(git(root, ['rev-list', '--count', `${base}..HEAD`])?.trim() ?? Infinity);
|
|
28
|
+
if (!closest || distance < closest.distance)
|
|
29
|
+
closest = { base, distance };
|
|
30
|
+
}
|
|
31
|
+
if (closest)
|
|
32
|
+
return closest.base;
|
|
33
|
+
return git(root, ['rev-parse', '--verify', '--quiet', 'HEAD']) === null ? null : 'HEAD';
|
|
34
|
+
}
|
|
35
|
+
function baseOf(root, since) {
|
|
36
|
+
return since === undefined ? defaultBase(root) : mergeBase(root, since);
|
|
37
|
+
}
|
|
38
|
+
export function untracked(root, folders) {
|
|
39
|
+
return lines(git(root, ['ls-files', '--others', '--exclude-standard', '--', ...folders]));
|
|
40
|
+
}
|
|
41
|
+
export function changedSince(root, ref, folders = []) {
|
|
42
|
+
const base = mergeBase(root, ref);
|
|
43
|
+
const changed = lines(git(root, ['diff', '--relative', '--name-only', '--no-renames', base, '--', ...folders]));
|
|
44
|
+
return [...new Set([...changed, ...untracked(root, folders)])].sort();
|
|
45
|
+
}
|
|
46
|
+
export function renamedSince(root, folders, since) {
|
|
47
|
+
const base = baseOf(root, since);
|
|
48
|
+
if (base === null)
|
|
49
|
+
return [];
|
|
50
|
+
const listed = git(root, ['diff', '--relative', '--name-status', '-M', base, '--', ...folders]);
|
|
51
|
+
return lines(listed).flatMap((line) => {
|
|
52
|
+
const [status = '', from, to] = line.split('\t');
|
|
53
|
+
return status.startsWith('R') && from && to ? [{ from, to }] : [];
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
export function changedLines(root, folders, since) {
|
|
57
|
+
const changed = new Map();
|
|
58
|
+
const base = baseOf(root, since);
|
|
59
|
+
if (base === null)
|
|
60
|
+
return changed;
|
|
61
|
+
const diff = git(root, [
|
|
62
|
+
'diff',
|
|
63
|
+
'--relative',
|
|
64
|
+
'--unified=0',
|
|
65
|
+
'--src-prefix=a/',
|
|
66
|
+
'--dst-prefix=b/',
|
|
67
|
+
'--no-color',
|
|
68
|
+
'--no-ext-diff',
|
|
69
|
+
'-M',
|
|
70
|
+
base,
|
|
71
|
+
'--',
|
|
72
|
+
...folders,
|
|
73
|
+
]);
|
|
74
|
+
let file = null;
|
|
75
|
+
for (const line of lines(diff)) {
|
|
76
|
+
if (line.startsWith('+++ ')) {
|
|
77
|
+
file = line === '+++ /dev/null' ? null : line.slice(6);
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const hunk = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/.exec(line);
|
|
81
|
+
if (!hunk || file === null)
|
|
82
|
+
continue;
|
|
83
|
+
const start = Number(hunk[1]);
|
|
84
|
+
const count = hunk[2] === undefined ? 1 : Number(hunk[2]);
|
|
85
|
+
let known = changed.get(file);
|
|
86
|
+
if (known === undefined) {
|
|
87
|
+
known = new Set();
|
|
88
|
+
changed.set(file, known);
|
|
89
|
+
}
|
|
90
|
+
if (known === 'all')
|
|
91
|
+
continue;
|
|
92
|
+
for (let at = start; at < start + count; at += 1)
|
|
93
|
+
known.add(at);
|
|
94
|
+
}
|
|
95
|
+
for (const file of untracked(root, folders))
|
|
96
|
+
changed.set(file, 'all');
|
|
97
|
+
return changed;
|
|
98
|
+
}
|
|
99
|
+
export function hasHead(root) {
|
|
100
|
+
return git(root, ['rev-parse', '--verify', '--quiet', 'HEAD^{commit}']) !== null;
|
|
101
|
+
}
|
|
102
|
+
export function knownRef(root, ref) {
|
|
103
|
+
if (git(root, ['rev-parse', '--verify', '--quiet', `${ref}^{commit}`]) === null) {
|
|
104
|
+
throw new AshlarError(`git knows no ${ref} here.`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function said(output) {
|
|
108
|
+
return output?.toString().trim() ?? '';
|
|
109
|
+
}
|
|
110
|
+
export function atRef(config, ref, read) {
|
|
111
|
+
knownRef(config.root, ref);
|
|
112
|
+
const wanted = [...config.include, 'tsconfig.json'];
|
|
113
|
+
const listing = spawnSync('git', ['ls-tree', '--name-only', ref, '--', ...wanted], {
|
|
114
|
+
cwd: config.root,
|
|
115
|
+
encoding: 'utf8',
|
|
116
|
+
maxBuffer: 64 * 1024 * 1024,
|
|
117
|
+
});
|
|
118
|
+
if (listing.status !== 0) {
|
|
119
|
+
throw new AshlarError(`git couldn't list the files at ${ref}: ${said(listing.stderr)}`);
|
|
120
|
+
}
|
|
121
|
+
const listed = lines(listing.stdout);
|
|
122
|
+
if (listed.length === 0)
|
|
123
|
+
return null;
|
|
124
|
+
const archive = spawnSync('git', ['archive', '--format=tar', ref, '--', ...listed], {
|
|
125
|
+
cwd: config.root,
|
|
126
|
+
maxBuffer: 1024 * 1024 * 1024,
|
|
127
|
+
});
|
|
128
|
+
if (archive.status !== 0) {
|
|
129
|
+
throw new AshlarError(`git couldn't read the files at ${ref}: ${said(archive.stderr)}`);
|
|
130
|
+
}
|
|
131
|
+
const root = realpathSync(mkdtempSync(join(tmpdir(), 'ashlar-at-')));
|
|
132
|
+
try {
|
|
133
|
+
const unpacked = spawnSync('tar', ['-x', '-f', '-', '-C', root], { input: archive.stdout });
|
|
134
|
+
if (unpacked.status !== 0) {
|
|
135
|
+
throw new AshlarError(`Ashlar couldn't unpack the files at ${ref}: ${said(unpacked.stderr)}`);
|
|
136
|
+
}
|
|
137
|
+
const holds = (path) => existsSync(join(root, path));
|
|
138
|
+
return read({ config: { ...config, root }, holds });
|
|
139
|
+
}
|
|
140
|
+
finally {
|
|
141
|
+
rmSync(root, { recursive: true, force: true });
|
|
142
|
+
}
|
|
143
|
+
}
|
package/dist/glob.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export type Matcher = (path: string) => boolean;
|
|
2
|
+
export declare function isGlob(pattern: string): boolean;
|
|
3
|
+
export declare function globOf(pattern: string): RegExp;
|
|
4
|
+
export declare function matcherOf(pattern: string): Matcher;
|
|
5
|
+
export declare function anyOf(patterns: string[]): Matcher;
|
package/dist/glob.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { within } from './layout.js';
|
|
2
|
+
const GLOB = /[*?{]/;
|
|
3
|
+
const SPECIAL = /[.+^$()|[\]\\]/g;
|
|
4
|
+
export function isGlob(pattern) {
|
|
5
|
+
return GLOB.test(pattern);
|
|
6
|
+
}
|
|
7
|
+
export function globOf(pattern) {
|
|
8
|
+
let out = '';
|
|
9
|
+
let depth = 0;
|
|
10
|
+
for (let i = 0; i < pattern.length; i += 1) {
|
|
11
|
+
const char = pattern[i];
|
|
12
|
+
if (char === '*' && pattern[i + 1] === '*') {
|
|
13
|
+
i += 1;
|
|
14
|
+
if (pattern[i + 1] === '/') {
|
|
15
|
+
i += 1;
|
|
16
|
+
out += '(?:.*/)?';
|
|
17
|
+
}
|
|
18
|
+
else
|
|
19
|
+
out += '.*';
|
|
20
|
+
}
|
|
21
|
+
else if (char === '*')
|
|
22
|
+
out += '[^/]*';
|
|
23
|
+
else if (char === '?')
|
|
24
|
+
out += '[^/]';
|
|
25
|
+
else if (char === '{') {
|
|
26
|
+
depth += 1;
|
|
27
|
+
out += '(?:';
|
|
28
|
+
}
|
|
29
|
+
else if (char === '}' && depth > 0) {
|
|
30
|
+
depth -= 1;
|
|
31
|
+
out += ')';
|
|
32
|
+
}
|
|
33
|
+
else if (char === ',' && depth > 0)
|
|
34
|
+
out += '|';
|
|
35
|
+
else
|
|
36
|
+
out += char.replace(SPECIAL, '\\$&');
|
|
37
|
+
}
|
|
38
|
+
return new RegExp(`^${out}$`);
|
|
39
|
+
}
|
|
40
|
+
export function matcherOf(pattern) {
|
|
41
|
+
if (!isGlob(pattern))
|
|
42
|
+
return (path) => within(path, pattern);
|
|
43
|
+
const glob = globOf(pattern);
|
|
44
|
+
return (path) => glob.test(path);
|
|
45
|
+
}
|
|
46
|
+
export function anyOf(patterns) {
|
|
47
|
+
const matchers = patterns.map(matcherOf);
|
|
48
|
+
return (path) => matchers.some((matches) => matches(path));
|
|
49
|
+
}
|
package/dist/graph.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Loaded } from './config.ts';
|
|
2
|
+
import { type Source } from './css.ts';
|
|
3
|
+
import { type Matcher } from './glob.ts';
|
|
4
|
+
export interface SetupReach {
|
|
5
|
+
files: Matcher;
|
|
6
|
+
tests: string[];
|
|
7
|
+
}
|
|
8
|
+
export interface Graph {
|
|
9
|
+
files: Set<string>;
|
|
10
|
+
importers: Map<string, string[]>;
|
|
11
|
+
sources: Source[];
|
|
12
|
+
setups: SetupReach[];
|
|
13
|
+
}
|
|
14
|
+
export declare function helpersOf(config: Loaded): Matcher;
|
|
15
|
+
export declare function graphOf(config: Loaded): Graph;
|
|
16
|
+
export declare function dependents(start: string, graph: Graph): Set<string>;
|
package/dist/graph.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { cssFiles, cssGraph } from './css.js';
|
|
2
|
+
import { anyOf } from './glob.js';
|
|
3
|
+
import { edgesOf, lint, workspaceOf } from './lint.js';
|
|
4
|
+
import { originsOf } from './origins.js';
|
|
5
|
+
import { makeResolver } from './resolve.js';
|
|
6
|
+
const TEST_FOLDER = /(?:^|\/)test\//;
|
|
7
|
+
export function helpersOf(config) {
|
|
8
|
+
const setups = anyOf([...config.setups, ...config.apps.flatMap((app) => app.setups)].flatMap((setup) => setup.files));
|
|
9
|
+
return (path) => TEST_FOLDER.test(path) || setups(path);
|
|
10
|
+
}
|
|
11
|
+
function link(importers, from, to) {
|
|
12
|
+
const known = importers.get(to);
|
|
13
|
+
if (known)
|
|
14
|
+
known.push(from);
|
|
15
|
+
else
|
|
16
|
+
importers.set(to, [from]);
|
|
17
|
+
}
|
|
18
|
+
function setupsOf(config, tests) {
|
|
19
|
+
return [...config.setups, ...config.apps.flatMap((app) => app.setups)].map((setup) => {
|
|
20
|
+
const included = anyOf(setup.tests);
|
|
21
|
+
const excluded = anyOf(setup.exclude ?? []);
|
|
22
|
+
return { files: anyOf(setup.files), tests: tests.filter((test) => included(test) && !excluded(test)) };
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
export function graphOf(config) {
|
|
26
|
+
const workspace = workspaceOf(config);
|
|
27
|
+
const linted = lint(config, ['graph'], workspace).files;
|
|
28
|
+
const styles = cssGraph(config.root, cssFiles(config.root, config.include, config.ignore), makeResolver(config.root, workspace));
|
|
29
|
+
const importers = new Map();
|
|
30
|
+
const edges = edgesOf(linted);
|
|
31
|
+
const origins = originsOf(linted, edges);
|
|
32
|
+
for (const [file, out] of edges)
|
|
33
|
+
for (const edge of out) {
|
|
34
|
+
if (edge.type || edge.takes === undefined)
|
|
35
|
+
continue;
|
|
36
|
+
const takes = edge.takes;
|
|
37
|
+
const reached = takes === null ? origins.whole(edge.to) : takes.flatMap((name) => origins.of(edge.to, name));
|
|
38
|
+
for (const to of new Set([edge.to, ...reached]))
|
|
39
|
+
if (to !== file)
|
|
40
|
+
link(importers, file, to);
|
|
41
|
+
}
|
|
42
|
+
for (const [file, out] of styles.edges)
|
|
43
|
+
for (const to of out)
|
|
44
|
+
link(importers, file, to);
|
|
45
|
+
const isTest = (path) => config.tests.some((suffix) => path.endsWith(suffix));
|
|
46
|
+
const helper = helpersOf(config);
|
|
47
|
+
const read = (path) => !path.endsWith('.css') && !isTest(path) && !helper(path);
|
|
48
|
+
const files = new Set([...Object.keys(linted), ...styles.files]);
|
|
49
|
+
return {
|
|
50
|
+
files,
|
|
51
|
+
importers,
|
|
52
|
+
sources: styles.sources.map(({ css, holds }) => ({ css, holds: (path) => read(path) && holds(path) })),
|
|
53
|
+
setups: setupsOf(config, [...files].filter(isTest)),
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
export function dependents(start, graph) {
|
|
57
|
+
const plain = new Set([start]);
|
|
58
|
+
const sourced = new Set();
|
|
59
|
+
const queue = [[start, false]];
|
|
60
|
+
const visit = (file, viaSource) => {
|
|
61
|
+
if (plain.has(file) || (viaSource && sourced.has(file)))
|
|
62
|
+
return;
|
|
63
|
+
(viaSource ? sourced : plain).add(file);
|
|
64
|
+
queue.push([file, viaSource]);
|
|
65
|
+
};
|
|
66
|
+
while (queue.length > 0) {
|
|
67
|
+
const [file, viaSource] = queue.pop();
|
|
68
|
+
if (viaSource && plain.has(file))
|
|
69
|
+
continue;
|
|
70
|
+
for (const importer of graph.importers.get(file) ?? [])
|
|
71
|
+
visit(importer, viaSource);
|
|
72
|
+
for (const source of graph.sources)
|
|
73
|
+
if (source.holds(file))
|
|
74
|
+
visit(source.css, true);
|
|
75
|
+
if (viaSource)
|
|
76
|
+
continue;
|
|
77
|
+
for (const setup of graph.setups)
|
|
78
|
+
if (setup.files(file))
|
|
79
|
+
for (const test of setup.tests)
|
|
80
|
+
visit(test, false);
|
|
81
|
+
}
|
|
82
|
+
return new Set([...plain, ...sourced]);
|
|
83
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const PACKAGE = "@kurvball/ashlar";
|
package/dist/identity.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PACKAGE = '@kurvball/ashlar';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export type { AffectedReport } from './affected.ts';
|
|
2
|
+
export type { BreakAt, CheckReport, RiseReport, RuleTotal } from './check.ts';
|
|
3
|
+
export { AshlarError, defineConfig, loadConfig, settle, type AshlarConfig, type Loaded, type RuleSwitch, type SkillsConfig, } from './config.ts';
|
|
4
|
+
export { checkConfig } from './configCheck.ts';
|
|
5
|
+
export { DRIVE_COMMANDS, parseDrive, type DriveCommand, type DriveFailure, type DriveParse, type DriveResult, type DriveVerb, } from './drive.ts';
|
|
6
|
+
export { buildMap, featureFolders, featuresOf, type Feature, type ReachLoad } from './features.ts';
|
|
7
|
+
export { SERVICE_PACKAGES, STACKS, type AppConfig, type Build, type Setup, type Stack } from './layout.ts';
|
|
8
|
+
export { MAP_VERSION, type FeatureMap, type MapFeature, type MapProof, type MapStep } from './map.ts';
|
|
9
|
+
export { FEATURE_REACH, REACH_FILE, reachScriptOf, type ReachOutcome, type ReachRun, type ReachScript, type ReachStep, } from './reach.ts';
|
|
10
|
+
export type { Moved, MoveOptions, MoveRise } from './move.ts';
|
|
11
|
+
export { LEDGER_EXPORT, ledgerOf, readLedger, type Ledger, type LedgerEntry } from './ledger.ts';
|
|
12
|
+
export { checkText } from './report.ts';
|
|
13
|
+
export { LINT_RULES, RULES, type LintRule, type RuleName } from './plugin/messages.ts';
|
|
14
|
+
export { driveLine, SCHEME_VARIABLE, SCHEMES, type Scheme } from './reachDrive.ts';
|
|
15
|
+
export { onboardSkill, SKILL_FILE, SKILLS, verifySkill, type SkillName } from './skill.ts';
|
|
16
|
+
export { onboard, type OnboardReport } from './onboard/onboard.ts';
|
|
17
|
+
export { brief, type Brief } from './onboard/brief.ts';
|
|
18
|
+
export { snapshot, type Snapshot } from './onboard/snapshot.ts';
|
|
19
|
+
export { questionsOf, type Question } from './onboard/questions.ts';
|
|
20
|
+
export { parseDecisions, DECISION_KINDS, type Decision, type DecisionKind } from './knowledge/decisions.ts';
|
|
21
|
+
export { parseRule, type FolderRule } from './knowledge/rules.ts';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { AshlarError, defineConfig, loadConfig, settle, } from './config.js';
|
|
2
|
+
export { checkConfig } from './configCheck.js';
|
|
3
|
+
export { DRIVE_COMMANDS, parseDrive, } from './drive.js';
|
|
4
|
+
export { buildMap, featureFolders, featuresOf } from './features.js';
|
|
5
|
+
export { SERVICE_PACKAGES, STACKS } from './layout.js';
|
|
6
|
+
export { MAP_VERSION } from './map.js';
|
|
7
|
+
export { FEATURE_REACH, REACH_FILE, reachScriptOf, } from './reach.js';
|
|
8
|
+
export { LEDGER_EXPORT, ledgerOf, readLedger } from './ledger.js';
|
|
9
|
+
export { checkText } from './report.js';
|
|
10
|
+
export { LINT_RULES, RULES } from './plugin/messages.js';
|
|
11
|
+
export { driveLine, SCHEME_VARIABLE, SCHEMES } from './reachDrive.js';
|
|
12
|
+
export { onboardSkill, SKILL_FILE, SKILLS, verifySkill } from './skill.js';
|
|
13
|
+
export { onboard } from './onboard/onboard.js';
|
|
14
|
+
export { brief } from './onboard/brief.js';
|
|
15
|
+
export { snapshot } from './onboard/snapshot.js';
|
|
16
|
+
export { questionsOf } from './onboard/questions.js';
|
|
17
|
+
export { parseDecisions, DECISION_KINDS } from './knowledge/decisions.js';
|
|
18
|
+
export { parseRule } from './knowledge/rules.js';
|
package/dist/jsonc.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function parseJsonc(text: string): unknown;
|
package/dist/jsonc.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export function parseJsonc(text) {
|
|
2
|
+
return JSON.parse(withoutTrailingCommas(withoutComments(text)));
|
|
3
|
+
}
|
|
4
|
+
function stringEnd(text, start) {
|
|
5
|
+
let i = start + 1;
|
|
6
|
+
while (i < text.length) {
|
|
7
|
+
if (text[i] === '\\')
|
|
8
|
+
i += 2;
|
|
9
|
+
else if (text[i] === '"')
|
|
10
|
+
return i + 1;
|
|
11
|
+
else
|
|
12
|
+
i += 1;
|
|
13
|
+
}
|
|
14
|
+
return text.length;
|
|
15
|
+
}
|
|
16
|
+
function withoutComments(text) {
|
|
17
|
+
let out = '';
|
|
18
|
+
let i = 0;
|
|
19
|
+
while (i < text.length) {
|
|
20
|
+
const char = text[i];
|
|
21
|
+
const next = text[i + 1];
|
|
22
|
+
if (char === '"') {
|
|
23
|
+
const end = stringEnd(text, i);
|
|
24
|
+
out += text.slice(i, end);
|
|
25
|
+
i = end;
|
|
26
|
+
}
|
|
27
|
+
else if (char === '/' && next === '/') {
|
|
28
|
+
while (i < text.length && text[i] !== '\n')
|
|
29
|
+
i += 1;
|
|
30
|
+
}
|
|
31
|
+
else if (char === '/' && next === '*') {
|
|
32
|
+
const end = text.indexOf('*/', i + 2);
|
|
33
|
+
i = end === -1 ? text.length : end + 2;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
out += char;
|
|
37
|
+
i += 1;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
function withoutTrailingCommas(text) {
|
|
43
|
+
let out = '';
|
|
44
|
+
let i = 0;
|
|
45
|
+
while (i < text.length) {
|
|
46
|
+
const char = text[i];
|
|
47
|
+
if (char === '"') {
|
|
48
|
+
const end = stringEnd(text, i);
|
|
49
|
+
out += text.slice(i, end);
|
|
50
|
+
i = end;
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
if (char === ',') {
|
|
54
|
+
let j = i + 1;
|
|
55
|
+
while (j < text.length && /\s/.test(text[j]))
|
|
56
|
+
j += 1;
|
|
57
|
+
if (text[j] === '}' || text[j] === ']') {
|
|
58
|
+
i += 1;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
out += char;
|
|
63
|
+
i += 1;
|
|
64
|
+
}
|
|
65
|
+
return out;
|
|
66
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Loaded } from '../config.ts';
|
|
2
|
+
import { type Decision } from './decisions.ts';
|
|
3
|
+
export type AreaKind = 'feature' | 'area' | 'folder';
|
|
4
|
+
export interface Area {
|
|
5
|
+
path: string;
|
|
6
|
+
name: string;
|
|
7
|
+
kind: AreaKind;
|
|
8
|
+
app: string | null;
|
|
9
|
+
}
|
|
10
|
+
export type OwnerSource = 'config' | 'decision' | 'default';
|
|
11
|
+
export interface Owner {
|
|
12
|
+
handle: string;
|
|
13
|
+
from: OwnerSource;
|
|
14
|
+
}
|
|
15
|
+
export declare function areasOf(config: Loaded, names?: ReadonlyMap<string, string>): Area[];
|
|
16
|
+
export declare function overlaps(a: string, b: string): boolean;
|
|
17
|
+
export declare function staticPart(pattern: string): string;
|
|
18
|
+
export declare function ruleCoversArea(rule: {
|
|
19
|
+
paths: string[] | null;
|
|
20
|
+
}, area: string): boolean;
|
|
21
|
+
export declare function isCrossCutting(rule: {
|
|
22
|
+
paths: string[] | null;
|
|
23
|
+
}): boolean;
|
|
24
|
+
export declare function decisionCovers(decision: Pick<Decision, 'areas'>, path: string): boolean;
|
|
25
|
+
export declare function ownerOf(config: Loaded, decisions: readonly Decision[], path: string): Owner | null;
|