type-rename-move 0.0.1 → 0.14.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/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/bin/trmv-compliance.js +4 -0
- package/dist/bin/trmv-config.js +4 -0
- package/dist/bin/trmv-doctor.js +4 -0
- package/dist/bin/trmv-mock-lint.js +4 -0
- package/dist/bin/trmv-refactor.js +4 -0
- package/dist/bin/trmv-typecheck.js +4 -0
- package/dist/changes/index.d.ts +24 -0
- package/dist/changes/index.js +112 -0
- package/dist/cli/index.d.ts +4 -0
- package/dist/cli/index.js +36 -0
- package/dist/config/command.d.ts +20 -0
- package/dist/config/command.js +68 -0
- package/dist/config/error.d.ts +3 -0
- package/dist/config/error.js +4 -0
- package/dist/config/files.d.ts +6 -0
- package/dist/config/files.js +29 -0
- package/dist/config/format.d.ts +25 -0
- package/dist/config/format.js +172 -0
- package/dist/config/index.d.ts +73 -0
- package/dist/config/index.js +239 -0
- package/dist/config/read.d.ts +4 -0
- package/dist/config/read.js +37 -0
- package/dist/contract/data/CONTRACT_HASH +1 -0
- package/dist/contract/data/README.md +69 -0
- package/dist/contract/data/cli.yaml +239 -0
- package/dist/contract/data/config.yaml +8 -0
- package/dist/contract/data/findings.yaml +212 -0
- package/dist/contract/data/languages.yaml +146 -0
- package/dist/contract/data/regex-subset.md +28 -0
- package/dist/contract/data/schema/rename-map.schema.json +51 -0
- package/dist/contract/data/schema/trmv.schema.json +92 -0
- package/dist/contract/data/schema/word-table.schema.json +55 -0
- package/dist/contract/data/vectors/cli.yaml +216 -0
- package/dist/contract/data/vectors/command-split.yaml +69 -0
- package/dist/contract/data/vectors/diff.yaml +287 -0
- package/dist/contract/data/vectors/format.yaml +160 -0
- package/dist/contract/data/vectors/glob.yaml +148 -0
- package/dist/contract/data/vectors/materialize.yaml +51 -0
- package/dist/contract/data/vectors/os-errors.yaml +123 -0
- package/dist/contract/data/vectors/refactor-symbols.yaml +220 -0
- package/dist/contract/data/vectors/refactor-text.yaml +186 -0
- package/dist/contract/data/vectors/refactor-words.yaml +83 -0
- package/dist/contract/data/vectors/regex-subset.yaml +40 -0
- package/dist/contract/data/vectors/repr.yaml +118 -0
- package/dist/contract/data/vectors/skill-leaks.yaml +6 -0
- package/dist/contract/data/vectors/test-files.yaml +135 -0
- package/dist/contract/data/vectors/yaml.yaml +858 -0
- package/dist/contract/glob.d.ts +3 -0
- package/dist/contract/glob.js +49 -0
- package/dist/contract/index.d.ts +13 -0
- package/dist/contract/index.js +14 -0
- package/dist/contract/json.d.ts +1 -0
- package/dist/contract/json.js +43 -0
- package/dist/contract/os-error.d.ts +13 -0
- package/dist/contract/os-error.js +66 -0
- package/dist/contract/parser.d.ts +18 -0
- package/dist/contract/parser.js +207 -0
- package/dist/contract/plugin.d.ts +5 -0
- package/dist/contract/plugin.js +90 -0
- package/dist/contract/regex.d.ts +5 -0
- package/dist/contract/regex.js +116 -0
- package/dist/contract/render.d.ts +3 -0
- package/dist/contract/render.js +19 -0
- package/dist/contract/schema.d.ts +10 -0
- package/dist/contract/schema.js +139 -0
- package/dist/contract/snapshot.d.ts +47 -0
- package/dist/contract/snapshot.js +129 -0
- package/dist/contract/text.d.ts +14 -0
- package/dist/contract/text.js +56 -0
- package/dist/contract/values.d.ts +24 -0
- package/dist/contract/values.js +127 -0
- package/dist/contract/which.d.ts +4 -0
- package/dist/contract/which.js +27 -0
- package/dist/contract/yaml.d.ts +11 -0
- package/dist/contract/yaml.js +595 -0
- package/dist/doctor/index.d.ts +3 -0
- package/dist/doctor/index.js +69 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/lang/conventions.d.ts +33 -0
- package/dist/lang/conventions.js +216 -0
- package/dist/lang/edges.d.ts +2 -0
- package/dist/lang/edges.js +142 -0
- package/dist/lang/files.d.ts +28 -0
- package/dist/lang/files.js +122 -0
- package/dist/lang/imports.d.ts +3 -0
- package/dist/lang/imports.js +64 -0
- package/dist/lang/index.d.ts +13 -0
- package/dist/lang/index.js +18 -0
- package/dist/lang/lines.d.ts +21 -0
- package/dist/lang/lines.js +96 -0
- package/dist/lang/projects.d.ts +30 -0
- package/dist/lang/projects.js +115 -0
- package/dist/lang/specifiers.d.ts +7 -0
- package/dist/lang/specifiers.js +88 -0
- package/dist/lang/ts.d.ts +2 -0
- package/dist/lang/ts.js +7 -0
- package/dist/lang/tsc.d.ts +32 -0
- package/dist/lang/tsc.js +130 -0
- package/dist/lang/types.d.ts +27 -0
- package/dist/lang/types.js +4 -0
- package/dist/refactor/baseline.d.ts +13 -0
- package/dist/refactor/baseline.js +148 -0
- package/dist/refactor/bindings.d.ts +76 -0
- package/dist/refactor/bindings.js +594 -0
- package/dist/refactor/carve.d.ts +31 -0
- package/dist/refactor/carve.js +145 -0
- package/dist/refactor/compliance.d.ts +15 -0
- package/dist/refactor/compliance.js +161 -0
- package/dist/refactor/compound.d.ts +5 -0
- package/dist/refactor/compound.js +40 -0
- package/dist/refactor/diff.d.ts +2 -0
- package/dist/refactor/diff.js +170 -0
- package/dist/refactor/edits.d.ts +16 -0
- package/dist/refactor/edits.js +34 -0
- package/dist/refactor/generate.d.ts +4 -0
- package/dist/refactor/generate.js +209 -0
- package/dist/refactor/index.d.ts +11 -0
- package/dist/refactor/index.js +144 -0
- package/dist/refactor/lines.d.ts +13 -0
- package/dist/refactor/lines.js +34 -0
- package/dist/refactor/literal-sources.d.ts +20 -0
- package/dist/refactor/literal-sources.js +243 -0
- package/dist/refactor/map.d.ts +21 -0
- package/dist/refactor/map.js +45 -0
- package/dist/refactor/members.d.ts +68 -0
- package/dist/refactor/members.js +187 -0
- package/dist/refactor/mention-scope.d.ts +19 -0
- package/dist/refactor/mention-scope.js +113 -0
- package/dist/refactor/mentions.d.ts +28 -0
- package/dist/refactor/mentions.js +92 -0
- package/dist/refactor/mocks.d.ts +16 -0
- package/dist/refactor/mocks.js +139 -0
- package/dist/refactor/module-rename.d.ts +17 -0
- package/dist/refactor/module-rename.js +160 -0
- package/dist/refactor/outcomes.d.ts +42 -0
- package/dist/refactor/outcomes.js +61 -0
- package/dist/refactor/own-scope.d.ts +16 -0
- package/dist/refactor/own-scope.js +142 -0
- package/dist/refactor/position.d.ts +34 -0
- package/dist/refactor/position.js +58 -0
- package/dist/refactor/program-check.d.ts +11 -0
- package/dist/refactor/program-check.js +49 -0
- package/dist/refactor/progress.d.ts +27 -0
- package/dist/refactor/progress.js +66 -0
- package/dist/refactor/rename.d.ts +18 -0
- package/dist/refactor/rename.js +1299 -0
- package/dist/refactor/retarget.d.ts +79 -0
- package/dist/refactor/retarget.js +647 -0
- package/dist/refactor/routing.d.ts +19 -0
- package/dist/refactor/routing.js +237 -0
- package/dist/refactor/session.d.ts +81 -0
- package/dist/refactor/session.js +180 -0
- package/dist/refactor/sites.d.ts +62 -0
- package/dist/refactor/sites.js +207 -0
- package/dist/refactor/symbols.d.ts +41 -0
- package/dist/refactor/symbols.js +385 -0
- package/dist/refactor/timings.d.ts +24 -0
- package/dist/refactor/timings.js +79 -0
- package/dist/refactor/typescript.d.ts +5 -0
- package/dist/refactor/typescript.js +279 -0
- package/dist/refactor/words.d.ts +42 -0
- package/dist/refactor/words.js +114 -0
- package/dist/refactor/workspace.d.ts +59 -0
- package/dist/refactor/workspace.js +314 -0
- package/dist/refactor/writer.d.ts +10 -0
- package/dist/refactor/writer.js +110 -0
- package/dist/twin/index.d.ts +50 -0
- package/dist/twin/index.js +180 -0
- package/dist/typecheck/index.d.ts +11 -0
- package/dist/typecheck/index.js +210 -0
- package/package.json +84 -3
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export { type Handler, commandRoot, optional, runCommand } from './command.js';
|
|
2
|
+
export { ConfigError } from './error.js';
|
|
3
|
+
export { type Committed, FORMAT_KEY, checkFormat, compareVersions, currentFormat, formatProblem, isVersion, readCommitted, releasedFormats, stampFormat, } from './format.js';
|
|
4
|
+
export { parseConfig, readConfigText } from './read.js';
|
|
5
|
+
export { bothFilesProblem, configSource, ownFile } from './files.js';
|
|
6
|
+
export interface TypecheckConfig {
|
|
7
|
+
python: string | null;
|
|
8
|
+
typescript: string | null;
|
|
9
|
+
}
|
|
10
|
+
export interface RefactorConfig {
|
|
11
|
+
python: {
|
|
12
|
+
moved_module_stub: string | null;
|
|
13
|
+
};
|
|
14
|
+
string_forms: string[];
|
|
15
|
+
}
|
|
16
|
+
/** trmv's resolved config; built only by `resolveConfig`, so every default comes from the schema. */
|
|
17
|
+
export interface TrmvConfig {
|
|
18
|
+
format: string | null;
|
|
19
|
+
exempt: string[];
|
|
20
|
+
commands: {
|
|
21
|
+
test: string | null;
|
|
22
|
+
typecheck: TypecheckConfig;
|
|
23
|
+
};
|
|
24
|
+
refactor: RefactorConfig;
|
|
25
|
+
}
|
|
26
|
+
/** What repo-language detection reads from a config: exempt paths, checker commands, the ones set explicitly. */
|
|
27
|
+
export interface LanguageSettings {
|
|
28
|
+
exempt: string[];
|
|
29
|
+
typecheck: TypecheckConfig;
|
|
30
|
+
explicit: Set<string>;
|
|
31
|
+
}
|
|
32
|
+
/** Nearest ancestor of `start` (inclusive) containing `.git`, else `start`. */
|
|
33
|
+
export declare function findRepoRoot(start: string): string;
|
|
34
|
+
/** Config file `name` parsed, null when it does not exist; ConfigError when unreadable or not YAML. */
|
|
35
|
+
export declare function readConfig(root: string, name: string): unknown;
|
|
36
|
+
/** The trmv keys of config file `name`'s data: all of trmv's own file, and trmv's share of another package's file. */
|
|
37
|
+
export declare function trmvData(data: unknown, name: string): unknown;
|
|
38
|
+
/** Error unless every pattern is portable and holds exactly one capturing group. */
|
|
39
|
+
export declare function checkStringForms(patterns: string[]): void;
|
|
40
|
+
/** Validate trmv's config data (null = no file) and fill the schema defaults; Error if invalid. */
|
|
41
|
+
export declare function resolveConfig(data: unknown): TrmvConfig;
|
|
42
|
+
/** trmv's share of the config file it reads, and that file's name; [null, null] without one. */
|
|
43
|
+
export declare function loadDrData(root: string): [unknown, string | null];
|
|
44
|
+
/** trmv's config at `root`; defaults without a config file. ConfigError naming the faulty file. */
|
|
45
|
+
export declare function loadConfig(root: string): TrmvConfig;
|
|
46
|
+
/** The languages config `data` sets `commands.typecheck` for explicitly (to a command or null). */
|
|
47
|
+
export declare function explicitTypecheck(data: unknown): Set<string>;
|
|
48
|
+
/** trmv's config at `root`, and that config as language detection reads it, from one read of the file. */
|
|
49
|
+
export declare function loadWithLanguages(root: string): [TrmvConfig, LanguageSettings];
|
|
50
|
+
/** trmv's config at `root` as language detection reads it. */
|
|
51
|
+
export declare function languageSettings(root: string): LanguageSettings;
|
|
52
|
+
/** Tracked and untracked-but-not-ignored files, minus the exempt globs; none outside git. ConfigError when git fails inside a repo. */
|
|
53
|
+
export declare function sourceFiles(root: string, exempt: string[]): string[];
|
|
54
|
+
/** Languages with an explicit typecheck command, or with a root marker and a counted file; registry order. */
|
|
55
|
+
export declare function repoLanguages(root: string, settings: LanguageSettings): string[];
|
|
56
|
+
/** A public fact of a registered language; RangeError for any other language or key. */
|
|
57
|
+
export declare function languageFact(id: string, key: string): unknown;
|
|
58
|
+
/** A resolved config as a config command prints it: its dumpable values, the keys a local file overrides (in
|
|
59
|
+
* `localFile`), and what language detection reads. */
|
|
60
|
+
export interface ConfigView {
|
|
61
|
+
values: unknown;
|
|
62
|
+
overrides: string[];
|
|
63
|
+
localFile: string | null;
|
|
64
|
+
languages: LanguageSettings;
|
|
65
|
+
}
|
|
66
|
+
/** Shell-friendly: bools lowercase, null empty, containers as JSON. */
|
|
67
|
+
export declare function formatValue(value: unknown): string;
|
|
68
|
+
/** `show`: the resolved config as JSON, then one stderr note per key a local file overrides. */
|
|
69
|
+
export declare function runShow(prog: string, root: string, load: (root: string) => ConfigView): number;
|
|
70
|
+
/** `get KEY`: one value by dotted key; `languages` the repo languages, `lang.<language>.<key>` a language fact. */
|
|
71
|
+
export declare function runGet(prog: string, root: string, key: string, load: (root: string) => ConfigView): number;
|
|
72
|
+
/** trmv's config at `root`, as `trmv-config` prints it. */
|
|
73
|
+
export declare function trmvView(root: string): ConfigView;
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
// Per-repo config: the committed file trmv reads, validated and completed by trmv's schema; the shared loading, format
|
|
2
|
+
// check, language detection and config-command machinery la's config builds on.
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { existsSync, statSync } from 'node:fs';
|
|
5
|
+
import { basename, dirname, join, resolve } from 'node:path';
|
|
6
|
+
import { PyFloat, capturingGroups, fnmatch, isPortableRegex, language, languageIds, languageKeys, materializeDefaults, message, pyJson, reprFloat, schema, schemaOrdered, validate, } from '../contract/index.js';
|
|
7
|
+
import { ConfigError } from './error.js';
|
|
8
|
+
import { configSource, ownFile } from './files.js';
|
|
9
|
+
import { parseConfig, readConfigText } from './read.js';
|
|
10
|
+
export { commandRoot, optional, runCommand } from './command.js';
|
|
11
|
+
export { ConfigError } from './error.js';
|
|
12
|
+
export { FORMAT_KEY, checkFormat, compareVersions, currentFormat, formatProblem, isVersion, readCommitted, releasedFormats, stampFormat, } from './format.js';
|
|
13
|
+
export { parseConfig, readConfigText } from './read.js';
|
|
14
|
+
export { bothFilesProblem, configSource, ownFile } from './files.js';
|
|
15
|
+
/** The schema of trmv's own config file, named after it. */
|
|
16
|
+
function ownSchema() {
|
|
17
|
+
return schema(basename(ownFile(), '.yaml'));
|
|
18
|
+
}
|
|
19
|
+
/** Nearest ancestor of `start` (inclusive) containing `.git`, else `start`. */
|
|
20
|
+
export function findRepoRoot(start) {
|
|
21
|
+
let candidate = resolve(start);
|
|
22
|
+
for (;;) {
|
|
23
|
+
if (existsSync(join(candidate, '.git')))
|
|
24
|
+
return candidate;
|
|
25
|
+
const parent = dirname(candidate);
|
|
26
|
+
if (parent === candidate)
|
|
27
|
+
return resolve(start);
|
|
28
|
+
candidate = parent;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const isFile = (path) => existsSync(path) && statSync(path).isFile();
|
|
32
|
+
/** Config file `name` parsed, null when it does not exist; ConfigError when unreadable or not YAML. */
|
|
33
|
+
export function readConfig(root, name) {
|
|
34
|
+
const text = readConfigText(root, name);
|
|
35
|
+
return text === null ? null : parseConfig(text, name);
|
|
36
|
+
}
|
|
37
|
+
/** `data` with only the keys `sub` defines, recursively through the objects that list their keys. */
|
|
38
|
+
function project(sub, data) {
|
|
39
|
+
if (!(data instanceof Map) || sub.properties === undefined)
|
|
40
|
+
return data;
|
|
41
|
+
const out = new Map();
|
|
42
|
+
for (const [key, value] of data)
|
|
43
|
+
if (Object.hasOwn(sub.properties, String(key)))
|
|
44
|
+
out.set(key, project(sub.properties[String(key)], value));
|
|
45
|
+
return out;
|
|
46
|
+
}
|
|
47
|
+
/** The trmv keys of config file `name`'s data: all of trmv's own file, and trmv's share of another package's file. */
|
|
48
|
+
export function trmvData(data, name) {
|
|
49
|
+
return name === ownFile() || !(data instanceof Map) ? data : project(ownSchema(), data);
|
|
50
|
+
}
|
|
51
|
+
/** Error unless every pattern is portable and holds exactly one capturing group. */
|
|
52
|
+
export function checkStringForms(patterns) {
|
|
53
|
+
for (const pattern of patterns) {
|
|
54
|
+
if (!isPortableRegex(pattern))
|
|
55
|
+
throw new Error(`refactor.string_forms pattern ${pattern} is not in the portable regex subset`);
|
|
56
|
+
if (capturingGroups(pattern) !== 1)
|
|
57
|
+
throw new Error(`refactor.string_forms pattern ${pattern} must hold exactly one capturing group`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/** Validate trmv's config data (null = no file) and fill the schema defaults; Error if invalid. */
|
|
61
|
+
export function resolveConfig(data) {
|
|
62
|
+
const trmvSchema = ownSchema();
|
|
63
|
+
if (data !== null && !(data instanceof Map))
|
|
64
|
+
throw new Error('top level must be a mapping');
|
|
65
|
+
const errors = validate(trmvSchema, data ?? new Map());
|
|
66
|
+
if (errors.length > 0)
|
|
67
|
+
throw new Error(errors.join('; '));
|
|
68
|
+
const resolved = materializeDefaults(trmvSchema, data);
|
|
69
|
+
checkStringForms(resolved.refactor.string_forms);
|
|
70
|
+
return resolved;
|
|
71
|
+
}
|
|
72
|
+
/** trmv's share of the config file it reads, and that file's name; [null, null] without one. */
|
|
73
|
+
export function loadDrData(root) {
|
|
74
|
+
const name = configSource(root);
|
|
75
|
+
return name === null ? [null, null] : [trmvData(readConfig(root, name), name), name];
|
|
76
|
+
}
|
|
77
|
+
function resolved(root, data, name) {
|
|
78
|
+
try {
|
|
79
|
+
return resolveConfig(data);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
throw new ConfigError(`${join(root, String(name))}: ${error.message}`);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/** trmv's config at `root`; defaults without a config file. ConfigError naming the faulty file. */
|
|
86
|
+
export function loadConfig(root) {
|
|
87
|
+
return resolved(root, ...loadDrData(root));
|
|
88
|
+
}
|
|
89
|
+
/** The languages config `data` sets `commands.typecheck` for explicitly (to a command or null). */
|
|
90
|
+
export function explicitTypecheck(data) {
|
|
91
|
+
const commands = data instanceof Map ? data.get('commands') : undefined;
|
|
92
|
+
const typecheck = commands instanceof Map ? commands.get('typecheck') : undefined;
|
|
93
|
+
return new Set(typecheck instanceof Map ? [...typecheck.keys()].map(String) : []);
|
|
94
|
+
}
|
|
95
|
+
/** trmv's config at `root`, and that config as language detection reads it, from one read of the file. */
|
|
96
|
+
export function loadWithLanguages(root) {
|
|
97
|
+
const [data, name] = loadDrData(root);
|
|
98
|
+
const config = resolved(root, data, name);
|
|
99
|
+
return [config, { exempt: config.exempt, typecheck: config.commands.typecheck, explicit: explicitTypecheck(data) }];
|
|
100
|
+
}
|
|
101
|
+
/** trmv's config at `root` as language detection reads it. */
|
|
102
|
+
export function languageSettings(root) {
|
|
103
|
+
return loadWithLanguages(root)[1];
|
|
104
|
+
}
|
|
105
|
+
/** Tracked and untracked-but-not-ignored files, minus the exempt globs; none outside git. ConfigError when git fails inside a repo. */
|
|
106
|
+
export function sourceFiles(root, exempt) {
|
|
107
|
+
const proc = spawnSync('git', ['ls-files', '-z', '--cached', '--others', '--exclude-standard'], { cwd: root, maxBuffer: 1 << 30 }); // NOSONAR(S4036) — runs the user's own git from PATH by design
|
|
108
|
+
if (proc.status !== 0 && existsSync(join(root, '.git')))
|
|
109
|
+
throw new ConfigError(message('config.git-failed'));
|
|
110
|
+
const paths = (proc.stdout?.toString('utf8') ?? '').split('\0');
|
|
111
|
+
return paths.filter((p) => p && !exempt.some((pattern) => fnmatch(p, pattern)));
|
|
112
|
+
}
|
|
113
|
+
/** Languages with an explicit typecheck command, or with a root marker and a counted file; registry order. */
|
|
114
|
+
export function repoLanguages(root, settings) {
|
|
115
|
+
let files = null;
|
|
116
|
+
const out = [];
|
|
117
|
+
for (const id of languageIds()) {
|
|
118
|
+
if (settings.explicit.has(id) && settings.typecheck[id] !== null) {
|
|
119
|
+
out.push(id);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const entry = language(id);
|
|
123
|
+
if (!entry.markers.some((marker) => isFile(join(root, marker))))
|
|
124
|
+
continue;
|
|
125
|
+
files ??= sourceFiles(root, settings.exempt);
|
|
126
|
+
const extensions = entry.source_extensions;
|
|
127
|
+
if (files.some((f) => extensions.some((ext) => f.endsWith(ext))))
|
|
128
|
+
out.push(id);
|
|
129
|
+
}
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
/** A public fact of a registered language; RangeError for any other language or key. */
|
|
133
|
+
export function languageFact(id, key) {
|
|
134
|
+
if (!languageIds().includes(id) || !languageKeys().includes(key))
|
|
135
|
+
throw new RangeError(key);
|
|
136
|
+
const entry = language(id);
|
|
137
|
+
if (key === 'source_globs')
|
|
138
|
+
return entry.source_extensions.map((ext) => `**/*${ext}`);
|
|
139
|
+
if (key === 'waiver')
|
|
140
|
+
return message('config.waiver', { prefix: entry.comment_prefix });
|
|
141
|
+
return entry[key];
|
|
142
|
+
}
|
|
143
|
+
function lookup(data, dotted) {
|
|
144
|
+
let node = data;
|
|
145
|
+
for (const part of dotted.split('.')) {
|
|
146
|
+
if (node === null || typeof node !== 'object' || Array.isArray(node) || node instanceof PyFloat || !Object.hasOwn(node, part)) {
|
|
147
|
+
throw new RangeError(dotted);
|
|
148
|
+
}
|
|
149
|
+
node = node[part];
|
|
150
|
+
}
|
|
151
|
+
return node;
|
|
152
|
+
}
|
|
153
|
+
/** Shell-friendly: bools lowercase, null empty, containers as JSON. */
|
|
154
|
+
export function formatValue(value) {
|
|
155
|
+
if (value === true)
|
|
156
|
+
return 'true';
|
|
157
|
+
if (value === false)
|
|
158
|
+
return 'false';
|
|
159
|
+
if (value === null)
|
|
160
|
+
return '';
|
|
161
|
+
if (value instanceof PyFloat)
|
|
162
|
+
return reprFloat(value.value);
|
|
163
|
+
if (typeof value === 'object')
|
|
164
|
+
return pyJson(value);
|
|
165
|
+
return String(value);
|
|
166
|
+
}
|
|
167
|
+
function withView(prog, root, load, action) {
|
|
168
|
+
let view;
|
|
169
|
+
try {
|
|
170
|
+
view = load(root);
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
if (!(error instanceof ConfigError))
|
|
174
|
+
throw error;
|
|
175
|
+
process.stderr.write(`${message('config.error', { prog, error: error.message })}\n`);
|
|
176
|
+
return 1;
|
|
177
|
+
}
|
|
178
|
+
return action(view);
|
|
179
|
+
}
|
|
180
|
+
/** `show`: the resolved config as JSON, then one stderr note per key a local file overrides. */
|
|
181
|
+
export function runShow(prog, root, load) {
|
|
182
|
+
return withView(prog, root, load, (view) => {
|
|
183
|
+
process.stdout.write(`${pyJson(view.values, 2)}\n`);
|
|
184
|
+
for (const key of view.overrides) {
|
|
185
|
+
process.stderr.write(`${message('config.local-override', { prog, key, file: view.localFile })}\n`);
|
|
186
|
+
}
|
|
187
|
+
return 0;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
function printLanguages(prog, root, view) {
|
|
191
|
+
if (!existsSync(join(root, '.git'))) {
|
|
192
|
+
process.stderr.write(`${message('config.not-git', { prog })}\n`);
|
|
193
|
+
return 2;
|
|
194
|
+
}
|
|
195
|
+
let languages;
|
|
196
|
+
try {
|
|
197
|
+
languages = repoLanguages(root, view.languages);
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
if (!(error instanceof ConfigError))
|
|
201
|
+
throw error;
|
|
202
|
+
process.stderr.write(`${message('config.error', { prog, error: error.message })}\n`);
|
|
203
|
+
return 2;
|
|
204
|
+
}
|
|
205
|
+
process.stdout.write(`${formatValue(languages)}\n`);
|
|
206
|
+
return 0;
|
|
207
|
+
}
|
|
208
|
+
function value(view, key) {
|
|
209
|
+
const parts = key.split('.');
|
|
210
|
+
if (parts[0] === 'lang' && parts.length === 3)
|
|
211
|
+
return languageFact(parts[1] ?? '', parts[2] ?? '');
|
|
212
|
+
if (parts[0] === 'lang')
|
|
213
|
+
throw new RangeError(key);
|
|
214
|
+
return lookup(view.values, key);
|
|
215
|
+
}
|
|
216
|
+
/** `get KEY`: one value by dotted key; `languages` the repo languages, `lang.<language>.<key>` a language fact. */
|
|
217
|
+
export function runGet(prog, root, key, load) {
|
|
218
|
+
return withView(prog, root, load, (view) => {
|
|
219
|
+
if (key === 'languages')
|
|
220
|
+
return printLanguages(prog, root, view);
|
|
221
|
+
let found;
|
|
222
|
+
try {
|
|
223
|
+
found = value(view, key);
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
if (!(error instanceof RangeError))
|
|
227
|
+
throw error;
|
|
228
|
+
process.stderr.write(`${message('config.unknown-key', { prog, key })}\n`);
|
|
229
|
+
return 2;
|
|
230
|
+
}
|
|
231
|
+
process.stdout.write(`${formatValue(found)}\n`);
|
|
232
|
+
return 0;
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
/** trmv's config at `root`, as `trmv-config` prints it. */
|
|
236
|
+
export function trmvView(root) {
|
|
237
|
+
const [config, languages] = loadWithLanguages(root);
|
|
238
|
+
return { values: schemaOrdered(ownSchema(), config), overrides: [], localFile: null, languages };
|
|
239
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** The text of config file `name`, null when it does not exist; ConfigError when it cannot be read. */
|
|
2
|
+
export declare function readConfigText(root: string, name: string): string | null;
|
|
3
|
+
/** `text` of config file `name` in the shared YAML profile; ConfigError when it is not valid YAML. */
|
|
4
|
+
export declare function parseConfig(text: string, name: string): unknown;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Reading a config file: OS, decode and YAML errors become config errors from the shared templates.
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { DuplicateKeyError, YAMLError, decodeUtf8OrNull, isOsError, isRegularFile, loadYaml, message, osErrorText, readFile, } from '../contract/index.js';
|
|
4
|
+
import { ConfigError } from './error.js';
|
|
5
|
+
/** The text of config file `name`, null when it does not exist; ConfigError when it cannot be read. */
|
|
6
|
+
export function readConfigText(root, name) {
|
|
7
|
+
const path = join(root, name);
|
|
8
|
+
let bytes;
|
|
9
|
+
try {
|
|
10
|
+
if (!isRegularFile(path))
|
|
11
|
+
return null;
|
|
12
|
+
bytes = readFile(path);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
if (isOsError(error))
|
|
16
|
+
throw new ConfigError(osErrorText(error, root, path));
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
const text = decodeUtf8OrNull(bytes);
|
|
20
|
+
if (text === null)
|
|
21
|
+
throw new ConfigError(message('yaml.invalid', { path: name }));
|
|
22
|
+
return text;
|
|
23
|
+
}
|
|
24
|
+
/** `text` of config file `name` in the shared YAML profile; ConfigError when it is not valid YAML. */
|
|
25
|
+
export function parseConfig(text, name) {
|
|
26
|
+
try {
|
|
27
|
+
return loadYaml(text);
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
if (error instanceof DuplicateKeyError) {
|
|
31
|
+
throw new ConfigError(message('yaml.invalid-because', { path: name, error: error.message }));
|
|
32
|
+
}
|
|
33
|
+
if (error instanceof YAMLError)
|
|
34
|
+
throw new ConfigError(message('yaml.invalid', { path: name }));
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
d58dbb5c1bd3fd1348d78d00267fe0855bb21eec46f9e6d49a14235402720296
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# type-rename-move contract
|
|
2
|
+
|
|
3
|
+
The source of truth both trmv twins obey. Each twin vendors a byte-copy of this directory (refreshed by
|
|
4
|
+
`scripts/sync-shared`) and loads only that copy at runtime; la loads it through the trmv library it runs with.
|
|
5
|
+
|
|
6
|
+
| File | Defines |
|
|
7
|
+
|---|---|
|
|
8
|
+
| `schema/trmv.schema.json` | trmv's config keys (`format`, `exempt`, `commands.test`, `commands.typecheck`, `refactor`), their types and defaults |
|
|
9
|
+
| `schema/rename-map.schema.json`, `schema/word-table.schema.json` | `trmv-refactor rename-map`'s map and `generate-map`'s word table |
|
|
10
|
+
| `config.yaml` | the committed config files trmv reads, in order, and each file's released formats |
|
|
11
|
+
| `findings.yaml` | every finding, verdict and hint a trmv command prints, by id |
|
|
12
|
+
| `cli.yaml` | every trmv command's options, positionals, subcommands, exit codes and native languages; the public language keys; the base-branch fetch timeout |
|
|
13
|
+
| `languages.yaml` | per-language extensions, test globs, comment prefix, suppression syntax, twin runner and install command |
|
|
14
|
+
| `regex-subset.md` | the portable regex subset of `issue_key_pattern` and `refactor.string_forms` |
|
|
15
|
+
| `vectors/` | input/output vectors both test suites consume |
|
|
16
|
+
|
|
17
|
+
## YAML profile
|
|
18
|
+
|
|
19
|
+
The config files (`living-architecture.yaml`, `living-architecture.local.yaml`, `architecture/index.yaml`) and the
|
|
20
|
+
bundled data are read as YAML 1.1 as PyYAML's safe loader reads it, within a closed tag set: `yes`/`no`/`on`/`off` are booleans,
|
|
21
|
+
sexagesimal and `0`-prefixed octal integers are numbers, merge keys apply, and a scalar the safe loader cannot
|
|
22
|
+
construct is a YAML error. A mapping that repeats a key, at any depth, is a YAML error worded by `yaml.duplicate-key`:
|
|
23
|
+
two keys are the same when their loaded values, normalized (a timestamp to its ISO string), are equal: strings by
|
|
24
|
+
code points, `null` only with `null`, booleans, integers and floats as exact numbers (`false`/`true` as `0`/`1`,
|
|
25
|
+
`-0.0` as `0`), `.inf` and `-.inf` only with themselves, a NaN with a NaN, and a merge key only with another merge
|
|
26
|
+
key. An alias key counts as the value it resolves to; keys a merge brings in never count. The error names the first
|
|
27
|
+
occurrence's normalized key and the 1-based lines where the two occurrences start (an alias key where the alias
|
|
28
|
+
stands); with several repeats, the repeat that comes first in the document, paired with that key's first
|
|
29
|
+
occurrence. The tag set is `!!str`, `!!int`, `!!float`,
|
|
30
|
+
`!!bool`, `!!null`, `!!timestamp`, `!!seq`, `!!map` and `!!merge`, in any spelling; a non-specific `!` resolves a
|
|
31
|
+
node as if it were untagged, and a scalar as if it were plain whatever its style (`! '12'` is `12`). Any other tag
|
|
32
|
+
(`!!binary`, `!!set`, `!!omap`, `!!pairs`, the `!!value` a plain `=` resolves to, a local or unknown tag) is a YAML
|
|
33
|
+
error, as is a merge key (`<<` or `!!merge`) anywhere but a mapping key, and a mapping key that is a sequence or
|
|
34
|
+
mapping. Anchor and alias names are ASCII letters, digits, `-` and `_`. Line breaks are `\n`, `\r` and `\r\n`: a
|
|
35
|
+
raw NEL (U+0085), U+2028 or U+2029 anywhere in the text is a YAML error (the `\N`, `\L` and `\P` escapes in a
|
|
36
|
+
double-quoted scalar are not). The twins agree on all YAML real configs use; YAML no config uses, such as a sequence
|
|
37
|
+
or mapping tagged `!!merge` as a key, carries no such guarantee. Pinned by `vectors/yaml.yaml`.
|
|
38
|
+
|
|
39
|
+
## Configuration
|
|
40
|
+
|
|
41
|
+
1. Parse with the YAML profile; a missing or empty file is an empty mapping.
|
|
42
|
+
2. Validate against the schema (JSON Schema 2020-12).
|
|
43
|
+
3. Fill defaults recursively: an absent property with a `default` takes it; an absent object whose
|
|
44
|
+
sub-schema has defaulted properties is created and filled. Explicit values, including `false`, `0`, `[]`,
|
|
45
|
+
`""` and `null`, are never replaced, and a `default` is never merged into an explicit object.
|
|
46
|
+
|
|
47
|
+
## Templates
|
|
48
|
+
|
|
49
|
+
`{name}` inserts a string as is and any other value as its canonical repr; `{name!r}` inserts the canonical
|
|
50
|
+
repr; `{{` and `}}` are literal braces. A multi-line template renders to several output lines.
|
|
51
|
+
|
|
52
|
+
## Canonical repr
|
|
53
|
+
|
|
54
|
+
Python's `repr` for normalized values only: str, int, float, bool, null, list, mapping. Strings use single
|
|
55
|
+
quotes unless they contain `'` and no `"`; `\\`, `\n`, `\r`, `\t` and the quote in use are escaped; other
|
|
56
|
+
non-printable characters become `\xNN`, `\uNNNN` or `\UNNNNNNNN`. Floats use the shortest round-trip form
|
|
57
|
+
(`1e+16`, `1.5e-07`, `inf`). Pinned by `vectors/repr.yaml`.
|
|
58
|
+
|
|
59
|
+
## Glob dialect
|
|
60
|
+
|
|
61
|
+
Matched against the POSIX repo-relative path, case-sensitively. A pattern is split on `/`; a `**` segment
|
|
62
|
+
matches zero or more whole path segments; inside any other segment `*` matches any run of characters
|
|
63
|
+
(dots included) and every other character is literal. Pinned by `vectors/glob.yaml`.
|
|
64
|
+
|
|
65
|
+
## Contract hash
|
|
66
|
+
|
|
67
|
+
`CONTRACT_HASH` in each snapshot is the hex sha256 of, for every file except `CONTRACT_HASH` in ascending
|
|
68
|
+
byte order of its POSIX relative path: the path, `NUL`, `1` if executable else `0`, `NUL`, the byte length in
|
|
69
|
+
decimal, `NUL`, the bytes.
|