Skip to content

Commit d4438be

Browse files
committed
Install xmd-dev directly from its Markdown example
1 parent 7f4c6c1 commit d4438be

5 files changed

Lines changed: 63 additions & 275 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,10 @@ The example installs `xmd-dev` in `~/.local/xmd-dev/bin` and prints the PATH
166166
step if your shell needs it. Add that export to your shell startup file if you
167167
want it in later terminals. The dedicated directory lets you select this
168168
launcher while keeping an older installation in place. To change the default
169-
checkout, move the installed link aside and run the example from the new
170-
checkout. To select another prepared checkout for one invocation, set
171-
`XMD_DEV_ROOT`. Run `xmd-dev` from your project directory.
169+
checkout, move the installed command aside and run the example from the new
170+
checkout. If you previously installed a symlink at that destination, move it
171+
aside before running the example. To select another prepared checkout for one
172+
invocation, set `XMD_DEV_ROOT`. Run `xmd-dev` from your project directory.
172173

173174
Compile the standalone `xmd` binary: prepare the checkout and then build,
174175
yielding `dist/xmd`, a self-contained executable for this host.

‎examples/install-xmd-dev.md‎

Lines changed: 52 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ Run this example from the root of a checkout you prepared with
77
xmd run examples/install-xmd-dev.md
88
```
99

10-
The installer links the checkout's launcher into `~/.local/xmd-dev/bin`. A
11-
symbolic link points to the launcher in the checkout, so later edits there take
12-
effect without reinstalling. The dedicated directory lets you put this launcher
13-
first on `PATH`, the list your shell searches for commands.
10+
The installer writes a small launcher into `~/.local/xmd-dev/bin` and
11+
records this checkout as its default. The dedicated directory lets you put
12+
the launcher first on `PATH`, the list your shell searches for commands.
1413

1514
```sh exec as="source"
16-
test -f scripts/xmd-dev && test -x scripts/xmd-dev
15+
test -f packages/cli/src/deno.ts
1716
```
1817

1918
<If condition={source.exitCode !== 0}>
20-
<Fail message="No executable scripts/xmd-dev was found here. Go to the root of your prepared checkout and run xmd run examples/install-xmd-dev.md again." />
19+
<Fail message="Go to the root of your prepared checkout and run xmd run examples/install-xmd-dev.md again." />
2120
</If>
2221

2322
```sh exec as="destination"
@@ -30,41 +29,57 @@ test -n "${HOME:-}" && printf '%s/.local/xmd-dev/bin/xmd-dev\n' "$HOME"
3029

3130
<Let as="installedPath" value={destination.stdout.trimEnd()} />
3231

33-
The link is created without replacement. For a repeat install, `realpath`
34-
resolves both launcher paths. The paths must match because the launcher uses its
35-
own directory to select the checkout. Move a conflicting command elsewhere
36-
before running the installer again.
37-
38-
```sh exec as="install"
39-
mkdir -p "$HOME/.local/xmd-dev/bin" &&
40-
ln -s "$(pwd -P)/scripts/xmd-dev" "$HOME/.local/xmd-dev/bin/"
32+
The installer stages a complete executable before publishing it. If the name
33+
already holds the same generated launcher, a repeat run leaves it in place.
34+
If it holds a different command, including a symlink from a previous install,
35+
move that command aside before running the installer again.
36+
37+
```bash exec as="install"
38+
set -eu
39+
checkout=$(pwd -P)
40+
bin="$HOME/.local/xmd-dev/bin"
41+
mkdir -p "$bin"
42+
staging=$(mktemp -d "$bin/.install.XXXXXXXX")
43+
trap 'rm -rf "$staging"' EXIT
44+
45+
{
46+
printf '%s\n' '#!/usr/bin/env bash' 'set -eu'
47+
printf 'checkout=%q\n' "$checkout"
48+
cat <<'LAUNCHER'
49+
launcher=$(cd "$(dirname "$0")" && pwd -P)/$(basename "$0")
50+
root=${XMD_DEV_ROOT:-$checkout}
51+
root=$(cd "$root" && pwd -P)
52+
entry=$root/packages/cli/src/deno.ts
53+
54+
if [ ! -f "$entry" ]; then
55+
printf 'xmd-dev: no CLI entrypoint at %s\n' "$entry" >&2
56+
exit 1
57+
fi
58+
59+
XMD_REPL_LAUNCHER=$launcher XMD_REPL_DENO_PROFILE=allow-all exec "${XMD_DEV_DENO:-deno}" run --allow-all "$entry" "$@"
60+
LAUNCHER
61+
} > "$staging/xmd-dev"
62+
chmod 755 "$staging/xmd-dev"
63+
64+
destination="$bin/xmd-dev"
65+
if ln "$staging/xmd-dev" "$bin/"; then
66+
printf 'installed\n'
67+
elif [ ! -L "$destination" ] && [ -f "$destination" ] &&
68+
[ -x "$destination" ] && cmp -s "$staging/xmd-dev" "$destination"; then
69+
printf 'already installed\n'
70+
else
71+
exit 1
72+
fi
4173
```
4274

4375
<If condition={install.exitCode !== 0}>
76+
<Let as="refusal">
4477

45-
```sh exec as="expected"
46-
realpath scripts/xmd-dev
47-
```
48-
49-
<If condition={expected.exitCode !== 0}>
50-
<Fail message={expected.stderr.trim()} />
51-
</If>
52-
53-
```sh exec as="existing"
54-
link="$HOME/.local/xmd-dev/bin/xmd-dev"
55-
test -L "$link" && test -f "$link" && realpath "$link"
56-
```
57-
58-
<If condition={existing.exitCode !== 0 || existing.stdout !== expected.stdout}>
59-
<Let as="refusal">
60-
61-
Could not install {installedPath}. Move a conflicting command aside before
62-
retrying.
63-
64-
</Let>
65-
<Fail message={refusal.trim() + " " + install.stderr.trim()} />
66-
</If>
78+
Could not install {installedPath}. Move a conflicting command aside before
79+
retrying.
6780

81+
</Let>
82+
<Fail message={refusal.trim() + " " + install.stderr.trim()} />
6883
</If>
6984

7085
```sh exec as="selected"
@@ -73,7 +88,7 @@ command -v xmd-dev
7388

7489
<Output>
7590

76-
<If condition={install.exitCode === 0}>
91+
<If condition={install.stdout.trim() === "installed"}>
7792

7893
Installed the launcher at {installedPath}.
7994

‎scripts/tests/repl-repositories-compiled.test.ts‎

Lines changed: 4 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,12 @@ import { replMountsJourney } from "../../packages/cli/tests/support/repl-mounts-
1818
*/
1919

2020
import { describe, it } from "@executablemd/test-support/bdd";
21-
import { expect } from "@executablemd/test-support/expect";
22-
import { useTempDirectory } from "@executablemd/test-support/temp";
23-
import { chmod, link, readlink, realpath, symlink, unlink } from "node:fs/promises";
24-
import { runShell, shellQuote } from "@executablemd/test-support/launch";
25-
import { copyFile, ensureDir, exists, readTextFile, writeTextFile } from "@effectionx/fs";
26-
import { scoped, until, type Operation } from "effection";
27-
import {
28-
allocate,
29-
focusPtyDraft,
30-
settledEntry,
31-
showing,
32-
showingAcross,
33-
} from "../../packages/cli/tests/support/pty.ts";
21+
import { shellQuote } from "@executablemd/test-support/launch";
22+
import { exists } from "@effectionx/fs";
23+
import type { Operation } from "effection";
3424
import { fileURLToPath as fromFileUrl } from "node:url";
35-
import { join, relative } from "node:path";
25+
import { join } from "node:path";
3626
import {
37-
click,
38-
ended,
39-
printedLocation,
4027
replFilesJourney,
4128
replGitJourney,
4229
replRepositoryJourney,
@@ -90,194 +77,3 @@ describe("the compiled binary's REPL entry files", () => {
9077
yield* replMountsJourney(compiled);
9178
});
9279
});
93-
94-
describe("1440: installed development and explicit compiled launchers", () => {
95-
it("pastes each full reopen hint through the correct launcher and restores the selected entry", function* () {
96-
yield* requireBinary();
97-
const home = yield* until(realpath(yield* useTempDirectory("xmd-1440 home ")));
98-
const bin = join(home, ".local", "xmd-dev", "bin");
99-
const project = join(home, "project", "nested");
100-
const leading = join(home, "leading PATH directory");
101-
yield* ensureDir(join(leading, "xmd"));
102-
yield* ensureDir(project);
103-
const launcher = join(bin, "xmd-dev");
104-
const installer = compiled([
105-
"run",
106-
shellQuote(join(ROOT, "examples", "install-xmd-dev.md")),
107-
"--raw",
108-
]);
109-
const install = (installHome: string, checkout = ROOT) =>
110-
runShell(installer, {
111-
cwd: checkout,
112-
env: { HOME: installHome },
113-
});
114-
const installed = yield* install(home).expect();
115-
expect(installed.stdout).toContain(`Installed the launcher at ${launcher}.`);
116-
expect(installed.stdout).toContain('export PATH="$HOME/.local/xmd-dev/bin:$PATH"');
117-
const source = join(ROOT, "scripts", "xmd-dev");
118-
expect(yield* until(readlink(launcher))).toBe(source);
119-
const repeated = yield* install(home).expect();
120-
expect(repeated.stdout).toContain("already points to this checkout");
121-
expect(yield* until(readlink(launcher))).toBe(source);
122-
const selectedInstall = yield* runShell(`PATH=${shellQuote(bin)}:"$PATH" ${installer}`, {
123-
cwd: ROOT,
124-
env: { HOME: home },
125-
}).expect();
126-
expect(selectedInstall.stdout).not.toContain("export PATH=");
127-
128-
const checkoutAlias = join(home, "checkout alias");
129-
yield* until(symlink(ROOT, checkoutAlias));
130-
const priorHome = join(home, "prior README home");
131-
const priorLink = join(priorHome, ".local", "xmd-dev", "bin", "xmd-dev");
132-
yield* runShell(
133-
`cd ${shellQuote(checkoutAlias)} &&
134-
mkdir -p "$HOME/.local/xmd-dev/bin" &&
135-
ln -s "$PWD/scripts/xmd-dev" "$HOME/.local/xmd-dev/bin/xmd-dev"`,
136-
{ cwd: ROOT, env: { HOME: priorHome } },
137-
).expect();
138-
const priorTarget = join(checkoutAlias, "scripts", "xmd-dev");
139-
expect(yield* until(readlink(priorLink))).toBe(priorTarget);
140-
expect((yield* install(priorHome).expect()).stdout).toContain(
141-
"already points to this checkout",
142-
);
143-
expect(yield* until(readlink(priorLink))).toBe(priorTarget);
144-
145-
const relativeHome = join(home, "relative link home");
146-
const relativeBin = join(relativeHome, ".local", "xmd-dev", "bin");
147-
const relativeLink = join(relativeBin, "xmd-dev");
148-
const relativeTarget = relative(relativeBin, source);
149-
yield* ensureDir(relativeBin);
150-
yield* until(symlink(relativeTarget, relativeLink));
151-
expect((yield* install(relativeHome).expect()).stdout).toContain(
152-
"already points to this checkout",
153-
);
154-
expect(yield* until(readlink(relativeLink))).toBe(relativeTarget);
155-
156-
const conflictHome = join(home, "conflicting home");
157-
const conflictBin = join(conflictHome, ".local", "xmd-dev", "bin");
158-
const conflict = join(conflictBin, "xmd-dev");
159-
yield* ensureDir(conflictBin);
160-
const conflictContents = "#!/bin/sh\nprintf '%s\\n' existing-launcher\n";
161-
yield* writeTextFile(conflict, conflictContents);
162-
yield* until(chmod(conflict, 0o755));
163-
const refused = yield* install(conflictHome).join();
164-
expect(refused.code).toBe(1);
165-
expect(refused.stderr).toContain(`Could not install ${conflict}.`);
166-
expect(yield* readTextFile(conflict)).toBe(conflictContents);
167-
yield* until(unlink(conflict));
168-
yield* writeTextFile(join(conflictBin, "other-launcher"), conflictContents);
169-
for (const target of ["other-launcher", "missing-launcher"]) {
170-
yield* until(symlink(target, conflict));
171-
expect((yield* install(conflictHome).join()).code).toBe(1);
172-
expect(yield* until(readlink(conflict))).toBe(target);
173-
yield* until(unlink(conflict));
174-
}
175-
yield* ensureDir(conflict);
176-
expect((yield* install(conflictHome).join()).code).toBe(1);
177-
expect(yield* exists(join(conflict, "xmd-dev"))).toBe(false);
178-
const checkoutA = join(home, "checkout A");
179-
const checkoutB = join(home, "checkout B");
180-
const launcherA = join(checkoutA, "scripts", "xmd-dev");
181-
const launcherB = join(checkoutB, "scripts", "xmd-dev");
182-
yield* ensureDir(join(checkoutA, "scripts"));
183-
yield* ensureDir(join(checkoutB, "scripts"));
184-
yield* copyFile(source, launcherA);
185-
yield* until(chmod(launcherA, 0o755));
186-
yield* until(link(launcherA, launcherB));
187-
188-
const linkedHome = join(home, "hard-linked launcher home");
189-
const linkedBin = join(linkedHome, ".local", "xmd-dev", "bin");
190-
const linkedLauncher = join(linkedBin, "xmd-dev");
191-
yield* ensureDir(linkedBin);
192-
yield* until(symlink(launcherB, linkedLauncher));
193-
const wrongCheckout = yield* install(linkedHome, checkoutA).join();
194-
expect(wrongCheckout.code).toBe(1);
195-
expect(wrongCheckout.stderr).toContain(`Could not install ${linkedLauncher}.`);
196-
expect(yield* until(readlink(linkedLauncher))).toBe(launcherB);
197-
198-
const prefix = `unset XMD_DEV_ROOT XMD_DEV_DENO; export PATH=${shellQuote(leading)}:${shellQuote(bin)}:"$PATH"; cd ${shellQuote(project)} &&`;
199-
const version = (yield* runShell(compiled(["--version"])).expect()).stdout.trim();
200-
const found = yield* runShell(`${prefix} command -v xmd-dev && xmd-dev --version`).expect();
201-
expect(found.stdout.trim().split("\n")).toEqual([launcher, version]);
202-
203-
const override = join(home, "override checkout");
204-
const overrideDir = join(override, "packages", "cli", "src");
205-
yield* ensureDir(overrideDir);
206-
yield* writeTextFile(
207-
join(overrideDir, "deno.ts"),
208-
'console.log("override checkout witness");\n',
209-
);
210-
const overrideLaunch = yield* runShell(
211-
`${prefix} XMD_DEV_ROOT=${shellQuote(override)} xmd-dev --version`,
212-
).expect();
213-
expect(overrideLaunch.stdout.trim()).toBe("override checkout witness");
214-
215-
const decoy = join(bin, "xmd");
216-
yield* writeTextFile(
217-
decoy,
218-
`#!/bin/sh\nif [ "$1" = --version ]; then printf '%s\\n' ${shellQuote(version)}; else exit 73; fi\n`,
219-
);
220-
yield* until(chmod(decoy, 0o755));
221-
expect((yield* runShell(`${prefix} xmd --version`).expect()).stdout.trim()).toBe(version);
222-
expect((yield* runShell(`${prefix} xmd repl`).join()).code).toBe(73);
223-
224-
const task = `deno task --cwd ${shellQuote(ROOT)} xmd`;
225-
expect((yield* runShell(`${prefix} ${task} --version`).expect()).stdout.trim()).toBe(version);
226-
const taskOutput = yield* runShell(
227-
`${prefix} ${task} run --eval ${shellQuote("<Output>Task argument witness</Output>")}`,
228-
).expect();
229-
expect(taskOutput.stdout.trim()).toBe("Task argument witness");
230-
231-
for (const command of ["xmd-dev", task, shellQuote(BINARY), "xmd"]) {
232-
if (command === "xmd") {
233-
yield* until(unlink(decoy));
234-
yield* until(symlink(BINARY, decoy));
235-
}
236-
yield* scoped(function* () {
237-
const pty = yield* allocate(`${prefix} ${command} repl --deny-all`, home);
238-
yield* showing(pty, "[exit]", 60_000);
239-
yield* focusPtyDraft(pty, 10_000);
240-
yield* pty.type("<Output>Retained launcher witness</Output>");
241-
yield* showing(pty, "Retained launcher witness", 10_000);
242-
yield* pty.type("\t\r");
243-
yield* settledEntry(pty, 1, "ok", 10_000);
244-
yield* click(pty, "[exit]");
245-
expect(yield* ended(pty)).toBe(0);
246-
const saved = printedLocation(yield* pty.finalOutput()).split("?")[0];
247-
expect(saved).toMatch(/\/entries\/entry-1$/);
248-
const location = saved + "?at=close:root&right=bindings";
249-
const selected = yield* allocate(`${prefix} ${command} repl ${shellQuote(location)}`, home);
250-
yield* showingAcross(selected, "Retained launcher witness", 30_000);
251-
yield* click(selected, "[exit]");
252-
expect(yield* ended(selected)).toBe(0);
253-
const printed = /^ (.+ repl 'xmd:\/\/repl\/[^']+')\r?$/m.exec(
254-
yield* selected.finalOutput(),
255-
)?.[1];
256-
if (printed === undefined) {
257-
throw new Error("The terminal printed no complete reopen command.");
258-
}
259-
if (command === "xmd") {
260-
expect(printed.startsWith("xmd repl ")).toBe(true);
261-
} else if (command === task) {
262-
expect(printed).toContain("XMD_REPL_DENO_PROFILE='repository-task'");
263-
expect(printed).toContain(" run --allow-all ");
264-
expect(printed).toContain(join(ROOT, "packages", "cli", "src", "deno.ts"));
265-
} else {
266-
expect(printed).toContain(command === "xmd-dev" ? shellQuote(launcher) : BINARY);
267-
}
268-
expect(printed.endsWith(shellQuote(location))).toBe(true);
269-
270-
// A pasted development hint carries its original checkout even when
271-
// the receiving shell has selected another checkout.
272-
const pasted = yield* allocate(
273-
`${prefix} export XMD_DEV_ROOT=${shellQuote(override)}; ${printed}`,
274-
home,
275-
);
276-
yield* showingAcross(pasted, "Retained launcher witness", 30_000);
277-
yield* click(pasted, "[exit]");
278-
expect(yield* ended(pasted)).toBe(0);
279-
expect(yield* pasted.finalOutput()).toContain(printed);
280-
});
281-
}
282-
});
283-
});

‎scripts/xmd-dev‎

Lines changed: 0 additions & 24 deletions
This file was deleted.

‎specs/repl-spec.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1857,9 +1857,9 @@ form when the first executable on the host's absolute PATH search resolves to
18571857
the running binary. This form uses the caller's PATH when pasted.
18581858

18591859
The installed `xmd-dev` launcher supplies its absolute invocation path and
1860-
fixed Deno launch profile. It resolves the installation symlink for its
1861-
default checkout and accepts `XMD_DEV_ROOT` as an override. The reopen command
1862-
pins the checkout and Deno executable used for the original launch. The
1860+
fixed Deno launch profile. The installation example records the default
1861+
checkout in the launcher. `XMD_DEV_ROOT` selects another checkout. The reopen
1862+
command pins the checkout and Deno executable used for the original launch. The
18631863
repository's `deno task xmd` declares its fixed Deno profile in the task
18641864
definition. Its reopen command preserves the task's runtime flags and
18651865
launch directory. A direct

0 commit comments

Comments
 (0)