@osdlc/wayfinder 0.7.1 → 0.7.3
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 +33 -0
- package/README.md +210 -182
- package/SECURITY.md +39 -1
- package/bin/way.js +14 -9
- package/dist/args.d.ts +16 -16
- package/dist/args.js +19 -19
- package/dist/cache.js +3 -4
- package/dist/clean-command.d.ts +18 -18
- package/dist/clean-command.js +35 -36
- package/dist/cli.d.ts +19 -20
- package/dist/cli.js +76 -69
- package/dist/config-command.d.ts +15 -14
- package/dist/config-command.js +63 -59
- package/dist/config.d.ts +135 -130
- package/dist/config.js +156 -149
- package/dist/devlink.d.ts +6 -2
- package/dist/devlink.js +7 -2
- package/dist/guide.js +5 -4
- package/dist/origin-owner.d.ts +7 -2
- package/dist/origin-owner.js +20 -4
- package/dist/providers-command.d.ts +1 -1
- package/dist/providers-command.js +11 -23
- package/dist/serve.d.ts +43 -42
- package/dist/serve.js +251 -258
- package/dist/terminal-text.d.ts +57 -0
- package/dist/terminal-text.js +91 -0
- package/dist/tools.d.ts +4 -4
- package/dist/tools.js +4 -4
- package/dist/trust-command.d.ts +6 -7
- package/dist/trust-command.js +48 -50
- package/dist/trust-store.d.ts +1 -1
- package/dist/tui.d.ts +65 -66
- package/dist/tui.js +124 -130
- package/dist/web/main.js +371 -386
- package/dist/web/page.html +6 -5
- package/dist/web/styles.css +258 -271
- package/package.json +9 -9
package/dist/config.js
CHANGED
|
@@ -1,49 +1,50 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* wayfinder's configuration
|
|
3
|
-
*
|
|
2
|
+
* wayfinder's configuration. It is layered, and reading it runs nothing.
|
|
3
|
+
* Settings people want on every run (runners to skip, paths that are not
|
|
4
4
|
* project structure, whether execution is allowed, extra tools) are set once,
|
|
5
|
-
* per user and per project
|
|
5
|
+
* per user and per project. Flags are for one-off changes.
|
|
6
6
|
*
|
|
7
7
|
* ## Layers, lowest precedence first
|
|
8
8
|
*
|
|
9
9
|
* 1. `DEFAULT_CONFIG` — the built-in defaults.
|
|
10
10
|
* 2. USER — `$XDG_CONFIG_HOME/wayfinder/config.json`, or `~/.config/wayfinder/config.json`
|
|
11
|
-
* when `XDG_CONFIG_HOME` is unset.
|
|
11
|
+
* when `XDG_CONFIG_HOME` is unset or relative.
|
|
12
12
|
* 3. PROJECT — `wayfinder.config.json` at the root `findRoot` resolves.
|
|
13
|
-
* 4. CLI flags
|
|
14
|
-
*
|
|
13
|
+
* 4. CLI flags, applied by the caller. {@link collectOptionsFromConfig}
|
|
14
|
+
* returns the options a caller spreads its own flags on top of.
|
|
15
15
|
*
|
|
16
|
-
* `allowExec`
|
|
17
|
-
* `false
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* repository.
|
|
16
|
+
* `allowExec` is an exception to this order. The project layer may lower it to
|
|
17
|
+
* `false`, since a repository asking not to be run is safe to honour. It can
|
|
18
|
+
* never raise it to `true`. `wayfinder.config.json` lives inside the repository
|
|
19
|
+
* being scanned, so honouring `allowExec: true` from it would let a repository
|
|
20
|
+
* authorize running its own code. So `allowExec: true` is removed from the
|
|
21
|
+
* project layer before merging, with a warning. Only the user layer and the CLI
|
|
22
|
+
* flags can turn execution on. To give a repository lasting permission, run
|
|
23
|
+
* `way trust`, which records the consent outside the repository.
|
|
25
24
|
*
|
|
26
25
|
* `tools` is gated too, because a tool module is code. User-layer entries
|
|
27
26
|
* always load; project-layer entries load only when the repository is trusted
|
|
28
27
|
* and execution is allowed (see `tools.ts`).
|
|
29
28
|
*
|
|
30
|
-
* `trust`
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* `
|
|
36
|
-
*
|
|
37
|
-
*
|
|
29
|
+
* `trust` is a stricter exception. It has no lower setting a project could
|
|
30
|
+
* choose, so the whole project-layer `trust` block is dropped, with a warning
|
|
31
|
+
* when it is not empty. A repository must not be able to pre-authorize itself,
|
|
32
|
+
* or any group of repositories that includes it. Only the user layer's `trust`
|
|
33
|
+
* reaches `@osdlc/trust-repo`'s `policyExecGate`, which combines it with the
|
|
34
|
+
* marker store that `way trust` writes to. See that package's README for the
|
|
35
|
+
* glob dialect, and `origin-owner.ts` for the origin-remote lookup that
|
|
36
|
+
* `trust.owners` uses.
|
|
38
37
|
*
|
|
39
|
-
* XDG
|
|
40
|
-
* with a dotfiles repository expects this beside their other
|
|
38
|
+
* XDG paths are used on every platform, macOS included, as `gh` does. A
|
|
39
|
+
* developer with a dotfiles repository expects this file beside their other
|
|
40
|
+
* tool config.
|
|
41
41
|
*
|
|
42
|
-
* `WAYFINDER_CONFIG=/path/to/file`
|
|
43
|
-
*
|
|
44
|
-
* still read from the project root
|
|
45
|
-
*
|
|
46
|
-
*
|
|
42
|
+
* `WAYFINDER_CONFIG=/path/to/file` changes only where the user layer is read
|
|
43
|
+
* from. The named file is read instead of the XDG path. The project layer is
|
|
44
|
+
* still read from the project root and still merges on top. Naming a file that
|
|
45
|
+
* does not exist is an error, not an empty layer: an env var that points at
|
|
46
|
+
* nothing is a typo. A relative value is ignored with a warning, and the XDG
|
|
47
|
+
* path is read instead.
|
|
47
48
|
*
|
|
48
49
|
* ## The old waypost names
|
|
49
50
|
*
|
|
@@ -59,10 +60,10 @@
|
|
|
59
60
|
*
|
|
60
61
|
* ## Merge rule
|
|
61
62
|
*
|
|
62
|
-
* Objects merge key
|
|
63
|
-
*
|
|
64
|
-
* "which ones, in what order"
|
|
65
|
-
* that list, not that list appended to
|
|
63
|
+
* Objects merge key by key. Everything else, scalars and arrays alike,
|
|
64
|
+
* replaces the lower value whole. Arrays replace because each array setting
|
|
65
|
+
* answers "which ones, in what order". A project that says `order: ["just"]`
|
|
66
|
+
* means that list, not that list appended to the user's.
|
|
66
67
|
*
|
|
67
68
|
* user { runners: { disabled: ["cargo"], order: ["moon"] } }
|
|
68
69
|
* project { runners: { order: ["just"] } }
|
|
@@ -70,19 +71,18 @@
|
|
|
70
71
|
*
|
|
71
72
|
* ## Unknown keys and broken files
|
|
72
73
|
*
|
|
73
|
-
* An unknown key is a
|
|
74
|
-
* file still loads
|
|
75
|
-
* older one. A file
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
74
|
+
* An unknown key is a warning naming the file and the key, and the rest of the
|
|
75
|
+
* file still loads. A config written for a newer version must not break an
|
|
76
|
+
* older one. A malformed file, or a value of the wrong type for a known key, is
|
|
77
|
+
* a {@link ConfigError} naming the file and the problem. There is no silent
|
|
78
|
+
* fallback: a setting that quietly did not apply is worse than one that refused
|
|
79
|
+
* to load.
|
|
79
80
|
*/
|
|
80
81
|
import { existsSync } from 'node:fs';
|
|
81
82
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
82
|
-
import {
|
|
83
|
-
import { dirname, join, resolve } from 'node:path';
|
|
83
|
+
import { dirname, isAbsolute, join, resolve } from 'node:path';
|
|
84
84
|
import { readParsedFile } from '@osdlc/config-layers';
|
|
85
|
-
import { resolveTrustRoot } from '@osdlc/trust-repo';
|
|
85
|
+
import { homeDir, resolveTrustRoot, } from '@osdlc/trust-repo';
|
|
86
86
|
import { APP, BIN, CONFIG_ENV_VAR, LEGACY_APP, LEGACY_CONFIG_ENV_VAR, LEGACY_PROJECT_CONFIG_FILENAME, PROJECT_CONFIG_FILENAME, } from "./app.js";
|
|
87
87
|
import { originOwner } from "./origin-owner.js";
|
|
88
88
|
import { expandTilde } from "./xdg.js";
|
|
@@ -100,8 +100,8 @@ export const USER_CONFIG_FILENAME = 'config.json';
|
|
|
100
100
|
/**
|
|
101
101
|
* The built-in defaults layer.
|
|
102
102
|
*
|
|
103
|
-
* Every leaf is present,
|
|
104
|
-
*
|
|
103
|
+
* Every leaf is present, so {@link LoadedConfig.sources} has an entry for
|
|
104
|
+
* every key. A key set in no file is attributed to this layer.
|
|
105
105
|
*/
|
|
106
106
|
export const DEFAULT_CONFIG = {
|
|
107
107
|
runners: { disabled: [], order: [] },
|
|
@@ -128,9 +128,9 @@ export class ConfigError extends Error {
|
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
130
|
/**
|
|
131
|
-
* Every settable key, by dotted path.
|
|
132
|
-
*
|
|
133
|
-
*
|
|
131
|
+
* Every settable key, by dotted path. Validation, {@link setConfigValue} and
|
|
132
|
+
* the known-key check all read this one list, so a setting cannot be accepted
|
|
133
|
+
* in one place and rejected in another.
|
|
134
134
|
*/
|
|
135
135
|
const FIELDS = {
|
|
136
136
|
'runners.disabled': 'string-array',
|
|
@@ -145,16 +145,16 @@ const FIELDS = {
|
|
|
145
145
|
/**
|
|
146
146
|
* Every settable key, in schema order — the dotted names `config set` accepts.
|
|
147
147
|
*
|
|
148
|
-
* Derived from {@link FIELDS}
|
|
149
|
-
*
|
|
148
|
+
* Derived from {@link FIELDS}, so anything that lists the keys (the `guide`
|
|
149
|
+
* command's config section) stays in step with the schema.
|
|
150
150
|
*/
|
|
151
151
|
export const CONFIG_KEYS = Object.keys(FIELDS);
|
|
152
152
|
const DISCOVERY_VALUES = ['git', 'walk', 'auto'];
|
|
153
153
|
/**
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
154
|
+
* Key order for writing: schema order, not alphabetical, so a written file
|
|
155
|
+
* reads like the documented schema. Keys not listed here are unknown to this
|
|
156
|
+
* version. They are written after the known ones, in the order the file
|
|
157
|
+
* already had them.
|
|
158
158
|
*/
|
|
159
159
|
const KEY_ORDER = {
|
|
160
160
|
'': ['runners', 'allowExec', 'discovery', 'excludePaths', 'trust', 'tools'],
|
|
@@ -207,46 +207,50 @@ function unknownKeyWarning(file, key) {
|
|
|
207
207
|
return `${file}: unknown setting "${key}" (ignored)`;
|
|
208
208
|
}
|
|
209
209
|
/**
|
|
210
|
-
* Resolve where each layer's file lives. `env` and `home` are injectable
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
* waypost fallback (see the module docblock).
|
|
210
|
+
* Resolve where each layer's file lives. `env` and `home` are injectable so a
|
|
211
|
+
* test does not read the developer's own `~/.config`. The only other input is
|
|
212
|
+
* whether a file exists, which picks between a new name and its old waypost
|
|
213
|
+
* name (see the module docblock).
|
|
215
214
|
*
|
|
216
|
-
*
|
|
215
|
+
* Rules for a path taken from the environment:
|
|
217
216
|
*
|
|
218
217
|
* A leading `~` is expanded against `home`. A shell expands it before exec, but
|
|
219
|
-
* `.env` loaders, direnv and CI YAML
|
|
220
|
-
* `~/config.json`
|
|
221
|
-
* wrong answer this module refuses to give anywhere else.
|
|
218
|
+
* `.env` loaders, direnv and CI YAML pass the literal tilde through. Without
|
|
219
|
+
* this, `~/config.json` would silently become `<somewhere>/~/config.json`.
|
|
222
220
|
*
|
|
223
|
-
* A
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
221
|
+
* A relative `XDG_CONFIG_HOME` is ignored, as the XDG spec says. A relative
|
|
222
|
+
* `WAYFINDER_CONFIG` is ignored too, and `userEnvIgnored` says so. Resolved
|
|
223
|
+
* against the root, or against the cwd, which is usually the root, it would
|
|
224
|
+
* name a file inside the repository being scanned, and the user layer can
|
|
225
|
+
* turn execution on and load tools.
|
|
228
226
|
*/
|
|
229
|
-
export function configLocations(root, env = process.env, home =
|
|
227
|
+
export function configLocations(root, env = process.env, home = homeDir()) {
|
|
230
228
|
const base = resolve(root);
|
|
231
|
-
const absolute = (path) => resolve(base, expandTilde(path, home));
|
|
232
229
|
const fromVar = (name) => {
|
|
233
230
|
const value = env[name]?.trim();
|
|
234
231
|
return value !== undefined && value !== '' ? value : null;
|
|
235
232
|
};
|
|
236
233
|
const named = fromVar(CONFIG_ENV_VAR);
|
|
237
234
|
const legacyNamed = named === null ? fromVar(LEGACY_CONFIG_ENV_VAR) : null;
|
|
238
|
-
const
|
|
239
|
-
const
|
|
240
|
-
const
|
|
241
|
-
const
|
|
235
|
+
const namedVar = named !== null ? CONFIG_ENV_VAR : legacyNamed !== null ? LEGACY_CONFIG_ENV_VAR : null;
|
|
236
|
+
const envValue = named ?? legacyNamed;
|
|
237
|
+
const expanded = envValue === null ? null : expandTilde(envValue, home);
|
|
238
|
+
const envPath = expanded !== null && isAbsolute(expanded) ? expanded : null;
|
|
239
|
+
const userEnvVar = envPath !== null ? namedVar : null;
|
|
240
|
+
const userEnvIgnored = namedVar !== null && envValue !== null && envPath === null
|
|
241
|
+
? { variable: namedVar, value: envValue }
|
|
242
|
+
: null;
|
|
243
|
+
const xdg = expandTilde(env['XDG_CONFIG_HOME']?.trim() ?? '', home);
|
|
244
|
+
const configHome = isAbsolute(xdg) ? xdg : join(home, '.config');
|
|
242
245
|
const xdgUser = preferNew(join(configHome, USER_CONFIG_DIR, USER_CONFIG_FILENAME), join(configHome, LEGACY_USER_CONFIG_DIR, USER_CONFIG_FILENAME));
|
|
243
246
|
const project = preferNew(join(base, PROJECT_CONFIG_FILENAME), join(base, LEGACY_PROJECT_CONFIG_FILENAME));
|
|
244
247
|
return {
|
|
245
|
-
user: envPath !== null ?
|
|
248
|
+
user: envPath !== null ? resolve(envPath) : xdgUser.path,
|
|
246
249
|
userFromEnv: envPath !== null,
|
|
247
250
|
userEnvVar,
|
|
248
251
|
userLegacy: envPath === null && xdgUser.legacy,
|
|
249
252
|
userIgnored: envPath === null ? xdgUser.ignored : null,
|
|
253
|
+
userEnvIgnored,
|
|
250
254
|
project: project.path,
|
|
251
255
|
projectLegacy: project.legacy,
|
|
252
256
|
projectIgnored: project.ignored,
|
|
@@ -266,10 +270,9 @@ function preferNew(path, legacy) {
|
|
|
266
270
|
/**
|
|
267
271
|
* Validate a parsed JSON document against schema v1.
|
|
268
272
|
*
|
|
269
|
-
* Throws {@link ConfigError} on a type
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
* {@link readRawConfigFile}.
|
|
273
|
+
* Throws {@link ConfigError} on a type error. Returns the known keys plus one
|
|
274
|
+
* warning per unknown key. Because the result holds only known keys, the write
|
|
275
|
+
* path never goes through this shape (see {@link readRawConfigFile}).
|
|
273
276
|
*/
|
|
274
277
|
export function validateConfig(raw, file) {
|
|
275
278
|
if (!isPlainObject(raw)) {
|
|
@@ -336,11 +339,10 @@ export function validateConfig(raw, file) {
|
|
|
336
339
|
return { config, warnings };
|
|
337
340
|
}
|
|
338
341
|
/**
|
|
339
|
-
*
|
|
340
|
-
*
|
|
341
|
-
* exported
|
|
342
|
-
*
|
|
343
|
-
* the built-in defaults for every later load in the process.
|
|
342
|
+
* Deep-copy a value so the result shares no mutable structure with its source.
|
|
343
|
+
* A shallow spread is not enough. Every `loadConfig` merges on top of the
|
|
344
|
+
* exported `DEFAULT_CONFIG` object, so a shared branch would let a caller that
|
|
345
|
+
* mutates `effective` corrupt the defaults for every later load.
|
|
344
346
|
*/
|
|
345
347
|
function cloneValue(value) {
|
|
346
348
|
if (Array.isArray(value))
|
|
@@ -371,22 +373,20 @@ function deepMerge(base, over) {
|
|
|
371
373
|
return out;
|
|
372
374
|
}
|
|
373
375
|
/**
|
|
374
|
-
* Merge `over` onto `base` per the module's rule: objects key
|
|
375
|
-
* arrays
|
|
376
|
+
* Merge `over` onto `base` per the module's rule: objects key by key, scalars
|
|
377
|
+
* and arrays replaced whole.
|
|
376
378
|
*
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
* `DEFAULT_CONFIG`.
|
|
379
|
+
* Neither argument is changed, and the result shares no object or array with
|
|
380
|
+
* either, including branches `over` does not mention. Mutating a loaded config
|
|
381
|
+
* must not change `DEFAULT_CONFIG`.
|
|
381
382
|
*/
|
|
382
383
|
export function mergeConfig(base, over) {
|
|
383
384
|
return deepMerge(base, over);
|
|
384
385
|
}
|
|
385
386
|
/**
|
|
386
|
-
* One layer file as a plain object, read
|
|
387
|
-
*
|
|
388
|
-
*
|
|
389
|
-
* {@link ConfigError} naming it.
|
|
387
|
+
* One layer file as a plain object, read with `@osdlc/config-layers`'s
|
|
388
|
+
* `readParsedFile`. `null` when the file does not exist. A file that is
|
|
389
|
+
* unreadable, not JSON, or not an object throws {@link ConfigError} naming it.
|
|
390
390
|
*/
|
|
391
391
|
async function readJsonFile(file) {
|
|
392
392
|
const read = readParsedFile(file, 'json');
|
|
@@ -407,19 +407,18 @@ async function readJsonFile(file) {
|
|
|
407
407
|
/**
|
|
408
408
|
* The file's parsed object, unvalidated and with every key intact.
|
|
409
409
|
*
|
|
410
|
-
*
|
|
411
|
-
*
|
|
412
|
-
*
|
|
413
|
-
*
|
|
414
|
-
* file does not exist.
|
|
410
|
+
* `set` and `unset` edit this object, not the validated shape, because
|
|
411
|
+
* validation drops unknown keys. Writing a validated document back would
|
|
412
|
+
* silently delete a setting a newer version had written. `null` when the file
|
|
413
|
+
* does not exist.
|
|
415
414
|
*/
|
|
416
415
|
export async function readRawConfigFile(file) {
|
|
417
416
|
return readJsonFile(file);
|
|
418
417
|
}
|
|
419
418
|
/**
|
|
420
|
-
* Read, parse and validate one layer. `null` when the file does not exist
|
|
421
|
-
*
|
|
422
|
-
*
|
|
419
|
+
* Read, parse and validate one layer. `null` when the file does not exist,
|
|
420
|
+
* which is normal and not an error. A file that exists and is broken throws
|
|
421
|
+
* {@link ConfigError}.
|
|
423
422
|
*/
|
|
424
423
|
export async function readConfigFile(file) {
|
|
425
424
|
const raw = await readJsonFile(file);
|
|
@@ -449,11 +448,11 @@ function stabilize(record, section) {
|
|
|
449
448
|
* Parent directories are created.
|
|
450
449
|
*
|
|
451
450
|
* The order is fixed so that writing an unchanged document produces an
|
|
452
|
-
* unchanged file
|
|
451
|
+
* unchanged file. A config under version control should not show a diff
|
|
453
452
|
* because a key moved.
|
|
454
453
|
*
|
|
455
|
-
* Accepts a raw record as well as a {@link TaskConfig},
|
|
456
|
-
* unknown
|
|
454
|
+
* Accepts a raw record as well as a {@link TaskConfig}, so an edit can keep
|
|
455
|
+
* unknown keys.
|
|
457
456
|
*/
|
|
458
457
|
export async function writeConfigFile(file, config) {
|
|
459
458
|
const body = JSON.stringify(stabilize(config, ''), null, 2);
|
|
@@ -469,7 +468,7 @@ function leafPaths(value, prefix) {
|
|
|
469
468
|
* Load every layer and merge them. `env` and `home` are injectable for the same
|
|
470
469
|
* reason {@link configLocations} takes them.
|
|
471
470
|
*/
|
|
472
|
-
export async function loadConfig(root, env = process.env, home =
|
|
471
|
+
export async function loadConfig(root, env = process.env, home = homeDir()) {
|
|
473
472
|
const locations = configLocations(root, env, home);
|
|
474
473
|
const userRead = await readConfigFile(locations.user);
|
|
475
474
|
if (userRead === null && locations.userFromEnv) {
|
|
@@ -481,27 +480,25 @@ export async function loadConfig(root, env = process.env, home = homedir()) {
|
|
|
481
480
|
const warnings = [...(userRead?.warnings ?? []), ...(projectRead?.warnings ?? [])];
|
|
482
481
|
warnings.push(...legacyWarnings(locations));
|
|
483
482
|
// A repository cannot grant itself permission to run its own code. Lowering
|
|
484
|
-
// to false is honoured
|
|
485
|
-
// before `sources`, so `config list`
|
|
486
|
-
//
|
|
483
|
+
// to false is honoured. Raising to true is dropped here, before the merge and
|
|
484
|
+
// before `sources`, so `config list` names the layer that really supplied the
|
|
485
|
+
// value, not the ignored file.
|
|
487
486
|
//
|
|
488
|
-
// Not in validateConfig: that
|
|
489
|
-
// `config set
|
|
490
|
-
// came from, which only layer resolution knows.
|
|
487
|
+
// Not in validateConfig: that check is the same for every layer and is also
|
|
488
|
+
// used by `config set`. This rule depends on which layer a value came from.
|
|
491
489
|
if (project?.allowExec === true) {
|
|
492
|
-
//
|
|
493
|
-
//
|
|
494
|
-
//
|
|
490
|
+
// Warn even when the user layer already said true. The file's setting is
|
|
491
|
+
// never honoured, and without a warning its author might rely on it in a
|
|
492
|
+
// repo where it has no effect.
|
|
495
493
|
warnings.push(`${locations.project}: allowExec: true is ignored in a project file — a repository cannot grant itself permission to run subprocesses; run "${BIN} trust" to trust this repository`);
|
|
496
494
|
const { allowExec: _ignored, ...rest } = project;
|
|
497
495
|
project = rest;
|
|
498
496
|
}
|
|
499
|
-
//
|
|
500
|
-
// whole, whatever it holds
|
|
501
|
-
// itself or any
|
|
502
|
-
// otherwise
|
|
503
|
-
//
|
|
504
|
-
// `false`: an empty block granted nothing worth naming.
|
|
497
|
+
// A stricter version of the same rule: a project-layer `trust` block is
|
|
498
|
+
// dropped whole, whatever it holds. A repository must not pre-authorize
|
|
499
|
+
// itself or any group of repositories. Even an empty `paths: []` would
|
|
500
|
+
// otherwise replace the user's list in the merge. Only a non-empty block is
|
|
501
|
+
// warned about, since an empty one granted nothing.
|
|
505
502
|
if (project?.trust !== undefined) {
|
|
506
503
|
if ((project.trust.paths?.length ?? 0) > 0 || (project.trust.owners?.length ?? 0) > 0) {
|
|
507
504
|
warnings.push(`${locations.project}: trust is ignored in a project file — a repository cannot grant ` +
|
|
@@ -528,9 +525,20 @@ export async function loadConfig(root, env = process.env, home = homedir()) {
|
|
|
528
525
|
warnings,
|
|
529
526
|
};
|
|
530
527
|
}
|
|
531
|
-
/**
|
|
528
|
+
/** The warning for a relative `WAYFINDER_CONFIG` that was ignored, or null. */
|
|
529
|
+
export function envIgnoredWarning(locations) {
|
|
530
|
+
if (locations.userEnvIgnored === null)
|
|
531
|
+
return null;
|
|
532
|
+
const { variable, value } = locations.userEnvIgnored;
|
|
533
|
+
return (`${variable}=${value} is ignored because it is not an absolute path; ` +
|
|
534
|
+
`use an absolute path or ~/. Reading ${locations.user} instead`);
|
|
535
|
+
}
|
|
536
|
+
/** One warning per old waypost name in use, naming the new one, and one for an ignored env path. */
|
|
532
537
|
function legacyWarnings(locations) {
|
|
533
538
|
const out = [];
|
|
539
|
+
const ignored = envIgnoredWarning(locations);
|
|
540
|
+
if (ignored !== null)
|
|
541
|
+
out.push(ignored);
|
|
534
542
|
if (locations.userEnvVar === LEGACY_CONFIG_ENV_VAR) {
|
|
535
543
|
out.push(`${LEGACY_CONFIG_ENV_VAR} is the old name; set ${CONFIG_ENV_VAR} instead`);
|
|
536
544
|
}
|
|
@@ -560,14 +568,13 @@ export function getConfigValue(config, key) {
|
|
|
560
568
|
return cursor;
|
|
561
569
|
}
|
|
562
570
|
/**
|
|
563
|
-
* Set a dotted path, returning a new document.
|
|
564
|
-
* intermediate objects, so `set` works on an empty file.
|
|
571
|
+
* Set a dotted path, returning a new document. The input is not changed.
|
|
572
|
+
* Missing intermediate objects are created, so `set` works on an empty file.
|
|
565
573
|
*
|
|
566
|
-
*
|
|
567
|
-
*
|
|
568
|
-
*
|
|
569
|
-
*
|
|
570
|
-
* untouched.
|
|
574
|
+
* Throws {@link ConfigError} for an unknown key, a value of the wrong type, or
|
|
575
|
+
* an existing intermediate value that is not an object, rather than writing a
|
|
576
|
+
* file that will fail to load. Given a raw record, it returns a raw record with
|
|
577
|
+
* its unknown keys untouched.
|
|
571
578
|
*/
|
|
572
579
|
export function setConfigValue(config, key, value) {
|
|
573
580
|
if (!(key in FIELDS)) {
|
|
@@ -581,8 +588,8 @@ export function setConfigValue(config, key, value) {
|
|
|
581
588
|
for (const segment of segments.slice(0, -1)) {
|
|
582
589
|
walked = walked === '' ? segment : `${walked}.${segment}`;
|
|
583
590
|
const existing = cursor[segment];
|
|
584
|
-
// A container of the wrong type
|
|
585
|
-
// silently
|
|
591
|
+
// A container of the wrong type means the file is broken. Replacing it
|
|
592
|
+
// would silently delete whatever the user meant by it.
|
|
586
593
|
if (existing !== undefined && !isPlainObject(existing)) {
|
|
587
594
|
throw new ConfigError(`cannot set ${key}: ${walked} is ${describe(existing)}, not an object`, '');
|
|
588
595
|
}
|
|
@@ -598,8 +605,8 @@ export function setConfigValue(config, key, value) {
|
|
|
598
605
|
* removal is removed too, so unsetting the last `runners.*` key does not leave
|
|
599
606
|
* `"runners": {}` behind.
|
|
600
607
|
*
|
|
601
|
-
* Unlike `set`, any key may be unset
|
|
602
|
-
*
|
|
608
|
+
* Unlike `set`, any key may be unset, including one this version does not
|
|
609
|
+
* know, so a stale setting can be removed.
|
|
603
610
|
*/
|
|
604
611
|
export function unsetConfigValue(config, key) {
|
|
605
612
|
const segments = key.split('.');
|
|
@@ -624,9 +631,9 @@ export function unsetConfigValue(config, key) {
|
|
|
624
631
|
return out;
|
|
625
632
|
}
|
|
626
633
|
/**
|
|
627
|
-
* Parse a value typed on a command line. JSON first, so
|
|
628
|
-
* `["a","b"]`
|
|
629
|
-
*
|
|
634
|
+
* Parse a value typed on a command line. It is parsed as JSON first, so
|
|
635
|
+
* `true`, `3` and `["a","b"]` keep their types. A bare word that is not valid
|
|
636
|
+
* JSON is kept as a string, so `moon` need not be typed as `"moon"`.
|
|
630
637
|
*/
|
|
631
638
|
export function parseConfigValue(raw) {
|
|
632
639
|
try {
|
|
@@ -637,8 +644,8 @@ export function parseConfigValue(raw) {
|
|
|
637
644
|
}
|
|
638
645
|
}
|
|
639
646
|
/**
|
|
640
|
-
* The {@link WayOptions}
|
|
641
|
-
* sets are present, so a caller spreads its own flags after it.
|
|
647
|
+
* The {@link WayOptions} fields this configuration controls. Only keys the
|
|
648
|
+
* config sets are present, so a caller spreads its own flags after it.
|
|
642
649
|
*/
|
|
643
650
|
export function collectOptionsFromConfig(config) {
|
|
644
651
|
const options = {};
|
|
@@ -658,14 +665,14 @@ export function trustPolicyFromConfig(config) {
|
|
|
658
665
|
return { paths: config.trust?.paths ?? [], owners: config.trust?.owners ?? [] };
|
|
659
666
|
}
|
|
660
667
|
/**
|
|
661
|
-
* Expand a `trust.paths` entry's leading `~` against `home`, then
|
|
662
|
-
*
|
|
663
|
-
*
|
|
668
|
+
* Expand a `trust.paths` entry's leading `~` against `home`, then resolve
|
|
669
|
+
* symlinks in the pattern's static prefix (the part before the first glob
|
|
670
|
+
* character) with `resolveTrustRoot`.
|
|
664
671
|
*
|
|
665
|
-
*
|
|
666
|
-
*
|
|
667
|
-
* match the
|
|
668
|
-
*
|
|
672
|
+
* This is the `expandPath` that `policyExecGate` and `policyDecision` take.
|
|
673
|
+
* Without it, a pattern written as a person typed it (`/tmp/…`, which on macOS
|
|
674
|
+
* is really `/private/tmp/…`) would never match the resolved root that
|
|
675
|
+
* `policyDecision` compares it with.
|
|
669
676
|
*/
|
|
670
677
|
export async function expandTrustPath(raw, home) {
|
|
671
678
|
const abs = resolve(expandTilde(raw, home));
|
|
@@ -678,9 +685,9 @@ export async function expandTrustPath(raw, home) {
|
|
|
678
685
|
}
|
|
679
686
|
/**
|
|
680
687
|
* The options every `@osdlc/trust-repo` gate call takes: {@link expandTrustPath}
|
|
681
|
-
* against `home`, and the
|
|
682
|
-
*
|
|
683
|
-
*
|
|
688
|
+
* against `home`, and the {@link originOwner} lookup that `trust.owners` needs.
|
|
689
|
+
* Built in one place, so a call site cannot leave out `ownerOf` and silently
|
|
690
|
+
* stop honouring `trust.owners`.
|
|
684
691
|
*/
|
|
685
692
|
export function trustPolicyOptions(home) {
|
|
686
693
|
return { expandPath: (raw) => expandTrustPath(raw, home), ownerOf: originOwner };
|
|
@@ -688,7 +695,7 @@ export function trustPolicyOptions(home) {
|
|
|
688
695
|
/**
|
|
689
696
|
* Sort runner-keyed items for display: the ids named in `order` first, in that
|
|
690
697
|
* order, then everything else alphabetically. Alphabetical rather than
|
|
691
|
-
* registry order, so adding a tool does not
|
|
698
|
+
* registry order, so adding a tool does not reorder the list.
|
|
692
699
|
*/
|
|
693
700
|
export function orderRunners(items, order) {
|
|
694
701
|
const rank = new Map((order ?? []).map((id, index) => [id, index]));
|
package/dist/devlink.d.ts
CHANGED
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
* The devlink spec: what `@osdlc/cli-tool/devlink` needs to recognise a
|
|
3
3
|
* wayfinder checkout, run it, and put `way` on PATH.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* package ships `dist/` alone
|
|
5
|
+
* A checkout has the source entry and a `package.json` named
|
|
6
|
+
* `@osdlc/wayfinder`. The installed package ships `dist/` alone, so it never
|
|
7
|
+
* counts. A selected checkout runs its source under Bun.
|
|
8
|
+
*
|
|
9
|
+
* The cwd layer stays off. Only `WAY_HOME` or `way dev link` hand off to a
|
|
10
|
+
* checkout, so standing in a repository never runs that repository's code.
|
|
7
11
|
*/
|
|
8
12
|
import { type ToolSpec } from '@osdlc/cli-tool/devlink';
|
|
9
13
|
export declare const WAYFINDER_SPEC: ToolSpec;
|
package/dist/devlink.js
CHANGED
|
@@ -2,8 +2,12 @@
|
|
|
2
2
|
* The devlink spec: what `@osdlc/cli-tool/devlink` needs to recognise a
|
|
3
3
|
* wayfinder checkout, run it, and put `way` on PATH.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* package ships `dist/` alone
|
|
5
|
+
* A checkout has the source entry and a `package.json` named
|
|
6
|
+
* `@osdlc/wayfinder`. The installed package ships `dist/` alone, so it never
|
|
7
|
+
* counts. A selected checkout runs its source under Bun.
|
|
8
|
+
*
|
|
9
|
+
* The cwd layer stays off. Only `WAY_HOME` or `way dev link` hand off to a
|
|
10
|
+
* checkout, so standing in a repository never runs that repository's code.
|
|
7
11
|
*/
|
|
8
12
|
import { existsSync } from 'node:fs';
|
|
9
13
|
import { resolve } from 'node:path';
|
|
@@ -15,6 +19,7 @@ const MARKER = 'src/cli.ts';
|
|
|
15
19
|
export const WAYFINDER_SPEC = validateSpec({
|
|
16
20
|
name: BIN,
|
|
17
21
|
marker: MARKER,
|
|
22
|
+
packageName: '@osdlc/wayfinder',
|
|
18
23
|
entry: MARKER,
|
|
19
24
|
launcher: 'bin/way.js',
|
|
20
25
|
aliases: [APP],
|
package/dist/guide.js
CHANGED
|
@@ -150,12 +150,12 @@ Layers, lowest precedence first:
|
|
|
150
150
|
Files. The project file is \`${PROJECT_CONFIG_FILENAME}\` at the project root, the
|
|
151
151
|
root this tool resolved, not the working directory. The user file is
|
|
152
152
|
\`$XDG_CONFIG_HOME/${APP}/config.json\`, or \`~/.config/${APP}/config.json\` when
|
|
153
|
-
that variable is unset.
|
|
153
|
+
that variable is unset or relative.
|
|
154
154
|
|
|
155
155
|
\`${CONFIG_ENV_VAR}\` replaces the USER file's location and nothing else. It does
|
|
156
156
|
not move the project file and it does not add a layer. A path in it may start
|
|
157
|
-
with a tilde, which is expanded
|
|
158
|
-
project root
|
|
157
|
+
with a tilde, which is expanded. A relative path is ignored with a warning,
|
|
158
|
+
because from the project root it would name a file in the repository.
|
|
159
159
|
|
|
160
160
|
Old names. The tool was called ${LEGACY_APP} before its first release.
|
|
161
161
|
\`${LEGACY_CONFIG_ENV_VAR}\`, \`$XDG_CONFIG_HOME/${LEGACY_APP}/config.json\` and
|
|
@@ -301,7 +301,8 @@ this root, \`--list\` prints every trusted path. \`-C PATH\` reaches all of them
|
|
|
301
301
|
|
|
302
302
|
A root can also be trusted with no marker, by a trust block in the USER
|
|
303
303
|
config: \`trust.paths\` (a glob over the resolved root) and \`trust.owners\`
|
|
304
|
-
(the \`origin\` remote's owner
|
|
304
|
+
(the \`origin\` remote's \`host/owner\`; a bare owner means github.com), decided in
|
|
305
|
+
that order after the marker.
|
|
305
306
|
\`--show\` and \`--json\` name which layer decided (\`by\`:
|
|
306
307
|
\`marker\`/\`path\`/\`owner\`, plus the matching \`rule\` for a policy hit).
|
|
307
308
|
`;
|
package/dist/origin-owner.d.ts
CHANGED
|
@@ -2,13 +2,18 @@
|
|
|
2
2
|
* The git-backed `ownerOf` handed to `@osdlc/trust-repo`, which knows no git.
|
|
3
3
|
* Without it `trust.owners` never matches.
|
|
4
4
|
*/
|
|
5
|
+
import { type CommandRunner } from '@osdlc/command-seam';
|
|
5
6
|
/**
|
|
6
|
-
* `root`'s `origin` remote
|
|
7
|
+
* `root`'s `origin` remote host and owner as `host/owner`
|
|
8
|
+
* (`github.com/acme`), or null when there is none we can read. The host is
|
|
9
|
+
* part of the answer because the same owner name on another host is another
|
|
10
|
+
* account.
|
|
7
11
|
* Git runs in `root` with the caller's git location and config variables
|
|
8
12
|
* removed, so they cannot point it at another repository. Git still searches
|
|
9
13
|
* upward from `root`, so a directory without its own `.git` inside a
|
|
10
14
|
* repository gets that repository's owner. A remote that is neither a URL nor
|
|
11
15
|
* scp-style is a local path (`owner/repo` is one) and has no owner. A host
|
|
12
16
|
* hosted-git-info does not know (a self-hosted server) has no owner either.
|
|
17
|
+
* `git` is for tests; it defaults to the real binary.
|
|
13
18
|
*/
|
|
14
|
-
export declare function originOwner(root: string): string | null;
|
|
19
|
+
export declare function originOwner(root: string, git?: CommandRunner): string | null;
|