barndog 0.1.1 → 0.2.1
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/README.md +31 -28
- package/dist/cli.js +11 -7
- package/dist/commands/add.js +34 -21
- package/dist/commands/adopt.js +91 -0
- package/dist/commands/arguments.js +12 -0
- package/dist/commands/asset-install.js +161 -0
- package/dist/commands/asset-list.js +126 -0
- package/dist/commands/asset-share.js +94 -0
- package/dist/commands/auth.js +4 -0
- package/dist/commands/availability.js +72 -27
- package/dist/commands/capabilities.js +79 -417
- package/dist/commands/collaboration.js +212 -108
- package/dist/commands/environment.js +18 -411
- package/dist/commands/github.js +200 -0
- package/dist/commands/harnesses.js +74 -0
- package/dist/commands/helpers.js +39 -0
- package/dist/commands/hooks.js +87 -0
- package/dist/commands/init.js +4 -2
- package/dist/commands/knowledge.js +73 -0
- package/dist/commands/mcp-env.js +78 -0
- package/dist/commands/mcp.js +64 -0
- package/dist/commands/origin.js +21 -23
- package/dist/commands/people.js +51 -0
- package/dist/commands/sets.js +141 -0
- package/dist/commands/status.js +36 -25
- package/dist/commands/sync.js +13 -5
- package/dist/commands/workspace.js +75 -23
- package/dist/config/environment.js +13 -27
- package/dist/config/paths.js +81 -0
- package/dist/config/selection.js +30 -0
- package/dist/config/settings.js +99 -108
- package/dist/config/state.js +67 -55
- package/dist/entry/knowledge-startup.js +32 -0
- package/dist/entry/mcp-launch.js +71 -0
- package/dist/entry/opencode-plugin.js +62 -0
- package/dist/{features/git-workspace/startup.js → entry/workspace-startup.js} +7 -2
- package/dist/errors.js +198 -55
- package/dist/features/adoption/adopt.js +234 -0
- package/dist/features/adoption/copies.js +29 -0
- package/dist/features/adoption/originals.js +116 -0
- package/dist/features/adoption/record.js +120 -0
- package/dist/features/adoption/restore.js +28 -0
- package/dist/features/adoption/scan.js +482 -0
- package/dist/features/adoption/undo.js +42 -0
- package/dist/features/asset-kinds/index.js +129 -0
- package/dist/features/asset-selection/index.js +51 -19
- package/dist/features/auth/credentials.js +80 -54
- package/dist/features/auth/session.js +83 -49
- package/dist/features/auth/transport.js +69 -17
- package/dist/features/catalog/index.js +32 -61
- package/dist/features/collaboration/api.js +160 -0
- package/dist/features/collaboration/index.js +321 -233
- package/dist/features/collaboration/remote.js +35 -115
- package/dist/features/collaboration/results.js +2 -0
- package/dist/features/collaboration/workspace-git.js +242 -152
- package/dist/features/collaboration/workspace-github.js +118 -54
- package/dist/features/collaboration/workspace-store.js +157 -97
- package/dist/features/collaboration/workspace.js +278 -173
- package/dist/features/discovery/index.js +68 -57
- package/dist/features/doctor/index.js +56 -26
- package/dist/features/environment/auto-sync.js +28 -27
- package/dist/features/environment/harnesses.js +36 -0
- package/dist/features/environment/moves.js +171 -0
- package/dist/features/environment/names.js +73 -49
- package/dist/features/environment/operations.js +322 -229
- package/dist/features/environment/own-entries.js +89 -0
- package/dist/features/environment/settle-names.js +91 -0
- package/dist/features/environment/stage.js +202 -0
- package/dist/features/environment/sync.js +127 -487
- package/dist/features/environment/transaction.js +179 -147
- package/dist/features/environment/writes.js +243 -0
- package/dist/features/github/account.js +25 -0
- package/dist/features/github/connections.js +119 -0
- package/dist/features/github/pulls.js +118 -0
- package/dist/features/hooks/adapt.js +32 -25
- package/dist/features/hooks/catalog.js +28 -0
- package/dist/features/hooks/compatibility.js +55 -0
- package/dist/features/hooks/divergence.js +36 -12
- package/dist/features/hooks/test.js +91 -66
- package/dist/features/hooks/types.js +1 -0
- package/dist/features/imports/discover.js +133 -60
- package/dist/features/imports/folder.js +48 -14
- package/dist/features/imports/local.js +127 -135
- package/dist/features/imports/remote.js +46 -26
- package/dist/features/inspection/index.js +17 -17
- package/dist/features/inventory/index.js +111 -111
- package/dist/features/inventory/show.js +74 -0
- package/dist/features/knowledge/index.js +69 -49
- package/dist/features/mcps/catalog.js +31 -0
- package/dist/features/mcps/import.js +369 -0
- package/dist/features/mcps/index.js +104 -50
- package/dist/features/mcps/values.js +33 -0
- package/dist/features/migration/migrate.js +263 -0
- package/dist/features/migration/move.js +448 -0
- package/dist/features/migration/promote.js +26 -0
- package/dist/features/native/adapters.js +69 -96
- package/dist/features/native/configuration.js +134 -84
- package/dist/features/native/hook-shell.js +55 -0
- package/dist/features/native/plugin-module.js +56 -0
- package/dist/features/native/secret-values.js +74 -0
- package/dist/features/onboarding/environment.js +67 -34
- package/dist/features/onboarding/setup.js +43 -40
- package/dist/features/repositories/context.js +30 -13
- package/dist/features/secrets/index.js +77 -0
- package/dist/features/server/catalog.js +58 -0
- package/dist/features/server/client.js +13 -0
- package/dist/features/server/connection.js +37 -0
- package/dist/features/server/origin.js +74 -0
- package/dist/features/server/pages.js +24 -0
- package/dist/features/skills/catalog.js +42 -0
- package/dist/features/workspace/assets.js +57 -0
- package/dist/features/workspace/cloud-source.js +34 -0
- package/dist/features/workspace/directory.js +38 -0
- package/dist/features/{git-workspace → workspace}/format.js +121 -54
- package/dist/features/workspace/git.js +221 -0
- package/dist/features/workspace/installed.js +92 -0
- package/dist/features/{git-workspace → workspace}/overlay.js +53 -46
- package/dist/features/workspace/packages.js +173 -0
- package/dist/features/{git-workspace → workspace}/publish.js +120 -64
- package/dist/features/workspace/repo-source.js +193 -0
- package/dist/features/{git-workspace → workspace}/setup.js +72 -45
- package/dist/features/{git-workspace → workspace}/snapshot.js +60 -19
- package/dist/features/workspace/source.js +1 -0
- package/dist/features/workspace/tree.js +52 -0
- package/dist/features/workspace/workspace-source.js +27 -0
- package/dist/harnesses/claude.js +23 -1
- package/dist/harnesses/codex.js +67 -1
- package/dist/harnesses/cursor.js +22 -1
- package/dist/harnesses/detect.js +6 -50
- package/dist/harnesses/formats.js +52 -0
- package/dist/harnesses/opencode.js +108 -0
- package/dist/harnesses/registry.js +35 -2
- package/dist/platform.js +403 -0
- package/dist/program.js +275 -56
- package/dist/runtime.js +1 -0
- package/dist/shared/cli-error.js +22 -0
- package/dist/shared/constants.js +32 -0
- package/dist/shared/files.js +107 -0
- package/dist/shared/lock.js +113 -0
- package/dist/shared/lookup.js +11 -0
- package/dist/shared/patterns.js +102 -0
- package/dist/shared/shell.js +20 -0
- package/dist/shared/values.js +26 -0
- package/dist/ui/add-asset.js +41 -400
- package/dist/ui/add-hook.js +219 -0
- package/dist/ui/add-mcp.js +170 -0
- package/dist/ui/add-prompts.js +47 -0
- package/dist/ui/add-skills.js +117 -0
- package/dist/ui/adopt.js +197 -0
- package/dist/ui/asset-list.js +31 -13
- package/dist/ui/assets.js +38 -47
- package/dist/ui/auth.js +45 -34
- package/dist/ui/clash.js +10 -6
- package/dist/ui/collaboration.js +116 -44
- package/dist/ui/connection.js +17 -6
- package/dist/ui/decision-error.js +24 -0
- package/dist/ui/environment-onboarding.js +35 -13
- package/dist/ui/format.js +66 -18
- package/dist/ui/harness-picker.js +18 -0
- package/dist/ui/hook-compatibility.js +14 -6
- package/dist/ui/mcp.js +28 -3
- package/dist/ui/move.js +57 -6
- package/dist/ui/onboarding.js +148 -95
- package/dist/ui/options.js +9 -0
- package/dist/ui/output.js +108 -43
- package/dist/ui/package-details.js +34 -0
- package/dist/ui/pick.js +45 -33
- package/dist/ui/scope-install.js +18 -7
- package/dist/ui/secret-input.js +19 -0
- package/dist/ui/selection.js +17 -11
- package/dist/ui/theme.js +37 -14
- package/dist/version.js +6 -3
- package/package.json +13 -3
- package/dist/features/capabilities/index.js +0 -106
- package/dist/features/collaboration/domain.js +0 -90
- package/dist/features/environment/cloud-source.js +0 -27
- package/dist/features/environment/installed.js +0 -124
- package/dist/features/environment/packages.js +0 -120
- package/dist/features/environment/remote.js +0 -71
- package/dist/features/environment/workspace-source.js +0 -19
- package/dist/features/git-hosts/index.js +0 -148
- package/dist/features/git-workspace/assets.js +0 -71
- package/dist/features/git-workspace/git.js +0 -135
- package/dist/features/git-workspace/migrate.js +0 -188
- package/dist/features/git-workspace/move.js +0 -337
- package/dist/features/git-workspace/source.js +0 -159
- package/dist/features/imports/mcp.js +0 -219
- package/dist/features/knowledge/startup.js +0 -25
- package/dist/features/native/mcp-launch.js +0 -57
- package/dist/features/skills/install.js +0 -25
- package/dist/features/skills/remote.js +0 -177
- package/dist/features/skills/sync.js +0 -121
- package/dist/features/skills/validation.js +0 -34
- /package/dist/features/environment/{source.js → events.js} +0 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { POSIX_MODE } from "./constants.js";
|
|
2
|
+
import { mkdir, readFile, rm, stat } from "node:fs/promises";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { setTimeout as sleep } from "node:timers/promises";
|
|
5
|
+
import { errorCode } from "./values.js";
|
|
6
|
+
import { CliError } from "./cli-error.js";
|
|
7
|
+
import { ifExists, writeAtomic } from "./files.js";
|
|
8
|
+
/**
|
|
9
|
+
* How long a lock may exist without a PID before it counts as left by a
|
|
10
|
+
* process that crashed between creating it and writing its PID. Writing the
|
|
11
|
+
* PID takes milliseconds.
|
|
12
|
+
*/
|
|
13
|
+
const STARTING_GRACE_MS = 10_000;
|
|
14
|
+
/** How long to wait while another process clears the same stale lock. */
|
|
15
|
+
const TAKEOVER_RETRY_MS = 50;
|
|
16
|
+
/** Attempts before giving up on a lock that keeps changing hands. */
|
|
17
|
+
const MAX_ATTEMPTS = 100;
|
|
18
|
+
async function ownerOf(path) {
|
|
19
|
+
const info = await ifExists(stat(path));
|
|
20
|
+
if (!info) {
|
|
21
|
+
return "free";
|
|
22
|
+
}
|
|
23
|
+
const text = await ifExists(readFile(join(path, "pid"), "utf8"));
|
|
24
|
+
const pid = Number(text ?? 0);
|
|
25
|
+
if (!Number.isSafeInteger(pid) || pid <= 0) {
|
|
26
|
+
return Date.now() - info.mtimeMs > STARTING_GRACE_MS ? "stale" : "starting";
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
process.kill(pid, 0);
|
|
30
|
+
return "running";
|
|
31
|
+
}
|
|
32
|
+
catch (failure) {
|
|
33
|
+
// EPERM: the owner is alive but belongs to another user, so it still holds the lock.
|
|
34
|
+
return errorCode(failure) === "ESRCH" ? "stale" : "running";
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Removes the lock at `path` if it is still stale. A short-lived guard folder
|
|
39
|
+
* makes the check and the removal one step, so a process that saw the same
|
|
40
|
+
* stale lock can't remove a fresh lock another process just took.
|
|
41
|
+
*/
|
|
42
|
+
async function removeStale(path) {
|
|
43
|
+
const guard = `${path}.takeover`;
|
|
44
|
+
try {
|
|
45
|
+
await mkdir(guard);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (errorCode(error) !== "EEXIST") {
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
const info = await ifExists(stat(guard));
|
|
52
|
+
if (info && Date.now() - info.mtimeMs > STARTING_GRACE_MS) {
|
|
53
|
+
await rm(guard, { recursive: true, force: true });
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
await sleep(TAKEOVER_RETRY_MS);
|
|
57
|
+
}
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
if ((await ownerOf(path)) === "stale") {
|
|
62
|
+
await rm(path, { recursive: true, force: true });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
finally {
|
|
66
|
+
await rm(guard, { recursive: true, force: true });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
/** Creates the lock folder, taking over a stale one; throws when it is held. */
|
|
70
|
+
async function acquire(path, messages) {
|
|
71
|
+
for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
|
|
72
|
+
try {
|
|
73
|
+
await mkdir(path, { mode: POSIX_MODE.privateDirectory });
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
if (errorCode(error) !== "EEXIST") {
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
const owner = await ownerOf(path);
|
|
81
|
+
if (owner === "starting") {
|
|
82
|
+
throw new CliError(messages.starting, undefined, { cause: error });
|
|
83
|
+
}
|
|
84
|
+
if (owner === "running") {
|
|
85
|
+
throw new CliError(messages.running, undefined, { cause: error });
|
|
86
|
+
}
|
|
87
|
+
if (owner === "stale") {
|
|
88
|
+
await removeStale(path);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
throw new CliError(messages.running);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Runs `run` while holding a lock across processes: a folder at `path` holding
|
|
96
|
+
* the owner's PID. A lock whose process has died, or that never got a PID, is
|
|
97
|
+
* taken over; liveness comes from the PID, not from the lock's age, so a long
|
|
98
|
+
* operation never loses it.
|
|
99
|
+
*/
|
|
100
|
+
export async function withPidLock(path, messages, run) {
|
|
101
|
+
await mkdir(dirname(path), {
|
|
102
|
+
recursive: true,
|
|
103
|
+
mode: POSIX_MODE.privateDirectory,
|
|
104
|
+
});
|
|
105
|
+
await acquire(path, messages);
|
|
106
|
+
try {
|
|
107
|
+
await writeAtomic(join(path, "pid"), String(process.pid));
|
|
108
|
+
return await run();
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
await rm(path, { recursive: true, force: true });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** `value`, or an Error saying `message` when a lookup the code relies on comes back empty. */
|
|
2
|
+
export function defined(value, message) {
|
|
3
|
+
if (value === undefined || value === null) {
|
|
4
|
+
throw new Error(message);
|
|
5
|
+
}
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
/** The one element of `items`, or undefined when there are none or several. */
|
|
9
|
+
export function only(items) {
|
|
10
|
+
return items.length === 1 ? items[0] : undefined;
|
|
11
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identifier shapes and text formats that several modules check. Each is
|
|
3
|
+
* defined once here so the copies can't drift apart; `src/tests/patterns.test.ts`
|
|
4
|
+
* covers them.
|
|
5
|
+
*/
|
|
6
|
+
import { MAX_ASSET_NAME_LENGTH } from "./constants.js";
|
|
7
|
+
/** A UUIDv4 in either case, such as `729b9d5a-4a8c-4aa7-9b8d-975a55ac373e`. */
|
|
8
|
+
export const UUID_V4 = /^[\da-f]{8}-[\da-f]{4}-4[\da-f]{3}-[89ab][\da-f]{3}-[\da-f]{12}$/i;
|
|
9
|
+
/**
|
|
10
|
+
* A full SHA-1 Git object name in lowercase, as Git prints it:
|
|
11
|
+
* `3f786850e387550fdab836ed7e6dc881de23001b`. SHA-256 repositories use 64
|
|
12
|
+
* digits and don't match.
|
|
13
|
+
*/
|
|
14
|
+
export const GIT_OBJECT_ID = /^[\da-f]{40}$/;
|
|
15
|
+
/**
|
|
16
|
+
* An asset, folder or slug name: lowercase letters and digits in words joined by
|
|
17
|
+
* single hyphens, such as `code-review` or `team2`. Never `-a`, `a--b` or `A`.
|
|
18
|
+
*/
|
|
19
|
+
export const NAME = /^[a-z\d]+(?:-[a-z\d]+)*$/;
|
|
20
|
+
/**
|
|
21
|
+
* Whether `name` can be an asset's folder and installed name: {@link NAME}, at
|
|
22
|
+
* most 64 characters.
|
|
23
|
+
*/
|
|
24
|
+
export const validAssetName = (name) => NAME.test(name) && name.length <= MAX_ASSET_NAME_LENGTH;
|
|
25
|
+
/**
|
|
26
|
+
* An MCP server name as coding tools accept it: letters, digits, `_` and `-`,
|
|
27
|
+
* such as `my_server` or `GitHub`. Tools name its tools after it
|
|
28
|
+
* (`mcp__my_server__search`), so BarnDog keeps it as written.
|
|
29
|
+
*/
|
|
30
|
+
export const MCP_NAME = /^[\w-]+$/;
|
|
31
|
+
/** Whether `name` can be an MCP server's name: {@link MCP_NAME}, at most 64 characters. */
|
|
32
|
+
export const validMcpName = (name) => MCP_NAME.test(name) && name.length <= MAX_ASSET_NAME_LENGTH;
|
|
33
|
+
/** Turns any text into a {@link NAME}-shaped slug: `Team A/Review!` → `team-a-review`. */
|
|
34
|
+
export function slugify(text) {
|
|
35
|
+
return text
|
|
36
|
+
.toLowerCase()
|
|
37
|
+
.replace(/[^a-z\d]+/g, "-")
|
|
38
|
+
.replace(/^-|-$/g, "");
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* YAML front matter at the very start of a Markdown file, optionally after a
|
|
42
|
+
* byte-order mark, with LF or CRLF line endings:
|
|
43
|
+
*
|
|
44
|
+
* ```text
|
|
45
|
+
* ---
|
|
46
|
+
* name: code-review
|
|
47
|
+
* description: Reviews a diff
|
|
48
|
+
* ---
|
|
49
|
+
* Body…
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
const FRONT_MATTER = /^(\uFEFF?---\r?\n)([\s\S]*?)(\r?\n---(?:\r?\n|$))/;
|
|
53
|
+
/** Splits a Markdown file into its front matter and body; null when there is none. */
|
|
54
|
+
export function splitFrontMatter(text) {
|
|
55
|
+
const match = FRONT_MATTER.exec(text);
|
|
56
|
+
if (!match) {
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
const [whole, open = "", yaml = "", close = ""] = match;
|
|
60
|
+
return { open, yaml, close, body: text.slice(whole.length) };
|
|
61
|
+
}
|
|
62
|
+
/** A top-level `name:` line in YAML, such as `name: code-review` or `name : x`. */
|
|
63
|
+
const NAME_LINE = /^name[ \t]*:.*$/m;
|
|
64
|
+
/**
|
|
65
|
+
* Sets the top-level `name:` in a YAML document (a `hook.yaml`, or the front
|
|
66
|
+
* matter of a `SKILL.md`), adding it as the first line when there is none.
|
|
67
|
+
* Only the first `name:` at the start of a line changes; nested keys are indented
|
|
68
|
+
* and left alone.
|
|
69
|
+
*/
|
|
70
|
+
export function setYamlName(yaml, name) {
|
|
71
|
+
return NAME_LINE.test(yaml)
|
|
72
|
+
? yaml.replace(NAME_LINE, () => `name: ${name}`)
|
|
73
|
+
: `name: ${name}\n${yaml}`;
|
|
74
|
+
}
|
|
75
|
+
/** A positive whole number as typed on the command line: `1`, `20`; never `0`, `01` or `1.5`. */
|
|
76
|
+
export const POSITIVE_INTEGER = /^[1-9]\d*$/;
|
|
77
|
+
/**
|
|
78
|
+
* A name in CONSTANT_CASE, such as an environment variable (`API_KEY`) or an
|
|
79
|
+
* error code (`KNOWLEDGE_NOT_FOUND`).
|
|
80
|
+
*/
|
|
81
|
+
export const CONSTANT_CASE = /^[A-Z][\dA-Z_]*$/;
|
|
82
|
+
/**
|
|
83
|
+
* The name inside a tool's environment variable reference (`${API_KEY}`,
|
|
84
|
+
* `{env:api_key}`, `$_TOKEN2`): a letter or underscore (a word character
|
|
85
|
+
* that isn't a digit), then word characters. Unanchored and without flags, for
|
|
86
|
+
* building those reference patterns from its `source`.
|
|
87
|
+
*/
|
|
88
|
+
export const VARIABLE_NAME = /[^\W\d]\w*/;
|
|
89
|
+
/**
|
|
90
|
+
* Splits an origin selector at its first `/` or `:`: `team/review` and
|
|
91
|
+
* `team:review` → `{ type: "team", value: "review" }`; `org` → `{ type: "org" }`.
|
|
92
|
+
* The value keeps any further separators: `repo/a/b` → `a/b`.
|
|
93
|
+
*/
|
|
94
|
+
export function splitOrigin(selector) {
|
|
95
|
+
const separator = selector.search(/[/:]/);
|
|
96
|
+
return separator < 0
|
|
97
|
+
? { type: selector }
|
|
98
|
+
: {
|
|
99
|
+
type: selector.slice(0, separator),
|
|
100
|
+
value: selector.slice(separator + 1),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Quotes text as one POSIX shell word: `it's` → `'it'\''s'`. */
|
|
2
|
+
export const posixQuote = (value) => "'" + value.replaceAll("'", "'\\''") + "'";
|
|
3
|
+
/**
|
|
4
|
+
* Text the shell reads as one word without quotes: `claude`, `v1.2-rc`, but
|
|
5
|
+
* not `a b`, `$HOME` or `/usr/bin`.
|
|
6
|
+
*/
|
|
7
|
+
export const PLAIN_WORD = /^[\w.-]+$/;
|
|
8
|
+
/** One POSIX shell word, quoted only when it needs to be. */
|
|
9
|
+
export const posixWord = (value) => PLAIN_WORD.test(value) ? value : posixQuote(value);
|
|
10
|
+
/**
|
|
11
|
+
* Quotes text as one PowerShell word. PowerShell also ends a single-quoted
|
|
12
|
+
* string at the typographic single quotes, so every one of them is doubled.
|
|
13
|
+
*/
|
|
14
|
+
export function powershellQuote(value) {
|
|
15
|
+
let quoted = value;
|
|
16
|
+
for (const quote of "'\u2018\u2019\u201A\u201B") {
|
|
17
|
+
quoted = quoted.replaceAll(quote, quote + quote);
|
|
18
|
+
}
|
|
19
|
+
return `'${quoted}'`;
|
|
20
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Narrowing for values whose shape isn't known: parsed JSON, YAML and TOML,
|
|
3
|
+
* especially config files other tools write.
|
|
4
|
+
*/
|
|
5
|
+
/** Whether `value` is a plain object: not null, not an array. */
|
|
6
|
+
export function isRecord(value) {
|
|
7
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
/** `value` when it's a plain object, otherwise an empty one: for config files written by other tools. */
|
|
10
|
+
export function asRecord(value) {
|
|
11
|
+
return isRecord(value) ? value : {};
|
|
12
|
+
}
|
|
13
|
+
/** The strings in `value` when it's an array, otherwise none. */
|
|
14
|
+
export function asStrings(value) {
|
|
15
|
+
return Array.isArray(value)
|
|
16
|
+
? value.filter((item) => typeof item === "string")
|
|
17
|
+
: [];
|
|
18
|
+
}
|
|
19
|
+
/** The `code` of a Node.js system error, such as `ENOENT`. */
|
|
20
|
+
export function errorCode(error) {
|
|
21
|
+
return error instanceof Error &&
|
|
22
|
+
"code" in error &&
|
|
23
|
+
typeof error.code === "string"
|
|
24
|
+
? error.code
|
|
25
|
+
: undefined;
|
|
26
|
+
}
|