paperlint 18.6.0 → 18.7.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/CLAUDE.md +2 -2
- package/CONTRIBUTING.md +5 -2
- package/README.md +6 -6
- package/dist/adapters/clack/index.d.ts +3 -0
- package/dist/adapters/clack/index.d.ts.map +1 -0
- package/dist/adapters/clack/index.js +3 -0
- package/dist/adapters/clack/index.js.map +1 -0
- package/dist/adapters/clack/prompts.io.d.ts +8 -0
- package/dist/adapters/clack/prompts.io.d.ts.map +1 -0
- package/dist/adapters/clack/prompts.io.js +20 -0
- package/dist/adapters/clack/prompts.io.js.map +1 -0
- package/dist/adapters/package-manager/index.d.ts +4 -0
- package/dist/adapters/package-manager/index.d.ts.map +1 -0
- package/dist/adapters/package-manager/index.js +4 -0
- package/dist/adapters/package-manager/index.js.map +1 -0
- package/dist/adapters/package-manager/install.io.d.ts +3 -0
- package/dist/adapters/package-manager/install.io.d.ts.map +1 -0
- package/dist/adapters/package-manager/install.io.js +23 -0
- package/dist/adapters/package-manager/install.io.js.map +1 -0
- package/dist/adapters/package-manager/manager.d.ts +13 -0
- package/dist/adapters/package-manager/manager.d.ts.map +1 -0
- package/dist/adapters/package-manager/manager.js +22 -0
- package/dist/adapters/package-manager/manager.js.map +1 -0
- package/dist/adapters/study-registry/index.d.ts +2 -2
- package/dist/cli.d.ts +4 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +42 -6
- package/dist/cli.js.map +1 -1
- package/dist/init.d.ts +38 -15
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +99 -39
- package/dist/init.js.map +1 -1
- package/dist/ports/project-install.d.ts +19 -0
- package/dist/ports/project-install.d.ts.map +1 -0
- package/dist/ports/project-install.js +2 -0
- package/dist/ports/project-install.js.map +1 -0
- package/dist/ports/prompts.d.ts +31 -0
- package/dist/ports/prompts.d.ts.map +1 -0
- package/dist/ports/prompts.js +2 -0
- package/dist/ports/prompts.js.map +1 -0
- package/dist/self-install.d.ts +65 -0
- package/dist/self-install.d.ts.map +1 -0
- package/dist/self-install.js +145 -0
- package/dist/self-install.js.map +1 -0
- package/dist/skill-chunks/chunk-65X5HVIJ.js +26462 -0
- package/dist/skill-chunks/chunk-6NU6CXUS.js +258 -0
- package/dist/skill-chunks/chunk-GRSXIWYF.js +352 -0
- package/dist/skill-chunks/chunk-IREAROCV.js +84 -0
- package/dist/skill-chunks/chunk-KWK6RT4T.js +24267 -0
- package/dist/skill-chunks/chunk-NPQVDEE4.js +19681 -0
- package/dist/skill-chunks/chunk-PJ4KNV4J.js +45 -0
- package/dist/skill-chunks/dist-UPCJMLBM.js +385 -0
- package/dist/skill-chunks/pdfjs-LUMEFOH2.js +39518 -0
- package/docs/e2e.md +10 -0
- package/docs/install.md +27 -16
- package/docs/prior-art/README.md +2 -0
- package/docs/prior-art/one-command-install.md +33 -0
- package/docs/prior-art/prompt-libraries.md +32 -0
- package/eslint.config.mjs +1 -0
- package/lib/skill-checks.mjs +17 -9
- package/lib/skill-checks.test.mjs +28 -15
- package/lib/skill-corpus.mjs +5 -2
- package/package.json +5 -3
- package/scripts/bundle-skills.test.ts +226 -0
- package/scripts/bundle-skills.ts +304 -0
- package/skills/argument-arc/SKILL.md +2 -2
- package/skills/argument-arc/SKILL.md.spec.ts +1 -1
- package/skills/argument-arc/scripts/headings.js +57 -13
- package/skills/build-label-page/scripts/label-page.js +2005 -93
- package/skills/cold-read-diff/scripts/cold-read.js +221 -14
- package/skills/label-agent-runs/scripts/labels.js +272 -348
- package/skills/paper-pipeline/scripts/extract-ref-facts.js +304 -0
- package/skills/pc-panel-review/scripts/prior-reviews.js +7244 -12
- package/skills/run-agent-grid/scripts/grid-guard.js +562 -627
- package/skills/verify-citations/SKILL.md +9 -9
- package/skills/verify-citations/SKILL.md.spec.ts +8 -8
- package/skills/verify-citations/scripts/bib-authors.js +228 -0
- package/skills/verify-citations/scripts/verify-cites.js +816 -0
- package/src/adapters/clack/index.ts +2 -0
- package/src/adapters/clack/prompts.io.ts +35 -0
- package/src/adapters/clack/prompts.test.ts +58 -0
- package/src/adapters/package-manager/index.test.ts +67 -0
- package/src/adapters/package-manager/index.ts +3 -0
- package/src/adapters/package-manager/install.io.ts +27 -0
- package/src/adapters/package-manager/manager.ts +33 -0
- package/src/cli.harness.mjs +41 -26
- package/src/cli.test.ts +93 -2
- package/src/cli.ts +75 -4
- package/src/init.test.ts +138 -27
- package/src/init.ts +128 -72
- package/src/ports/project-install.ts +18 -0
- package/src/ports/prompts.ts +27 -0
- package/src/self-install.test.ts +267 -0
- package/src/self-install.ts +224 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `Prompts` port drawn by @clack/prompts, the one prompt library of this package (chosen on
|
|
3
|
+
* 2026-11-22: `docs/prior-art/prompt-libraries.md`). Clack's cancel (Ctrl+C, Esc) is a symbol;
|
|
4
|
+
* it becomes the port's `cancel`, so nothing outside this folder knows the symbol exists.
|
|
5
|
+
*/
|
|
6
|
+
import { confirm, select, text } from "@clack/prompts";
|
|
7
|
+
import type { Readable, Writable } from "node:stream";
|
|
8
|
+
import type { Answer, Prompts } from "../../ports/prompts.ts";
|
|
9
|
+
|
|
10
|
+
/** Clack answers with the value or with its one symbol, the cancel (`isCancel` tests the same). */
|
|
11
|
+
const answer = <T extends string | boolean>(value: T | symbol): Answer<T> =>
|
|
12
|
+
typeof value === "symbol" ? { kind: "cancel" } : { kind: "answer", value };
|
|
13
|
+
|
|
14
|
+
/** The terminal's streams by default; a test passes its own. */
|
|
15
|
+
export const clackPrompts = (
|
|
16
|
+
streams: { readonly input?: Readable; readonly output?: Writable } = {},
|
|
17
|
+
): Prompts => ({
|
|
18
|
+
confirm: async ({ message, initial }) =>
|
|
19
|
+
answer<boolean>(
|
|
20
|
+
await confirm({ ...streams, message, initialValue: initial }),
|
|
21
|
+
),
|
|
22
|
+
select: async ({ message, options, initial }) =>
|
|
23
|
+
answer<string>(
|
|
24
|
+
await select({
|
|
25
|
+
...streams,
|
|
26
|
+
message,
|
|
27
|
+
options: options.map((value) => ({ value, label: value })),
|
|
28
|
+
initialValue: initial,
|
|
29
|
+
}),
|
|
30
|
+
),
|
|
31
|
+
text: async ({ message, placeholder }) =>
|
|
32
|
+
answer<string>(
|
|
33
|
+
await text({ ...streams, message, placeholder, defaultValue: "" }),
|
|
34
|
+
),
|
|
35
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { PassThrough } from "node:stream";
|
|
2
|
+
import { describe, expect, it } from "vitest";
|
|
3
|
+
import { clackPrompts } from "./index.ts";
|
|
4
|
+
|
|
5
|
+
/** Clack over in-memory streams: the keys are typed once the prompt has drawn itself. */
|
|
6
|
+
const typed = (...keys: readonly string[]) => {
|
|
7
|
+
const input = new PassThrough();
|
|
8
|
+
const output = new PassThrough();
|
|
9
|
+
Object.assign(input, { isTTY: true, setRawMode: () => input });
|
|
10
|
+
output.on("data", () => undefined);
|
|
11
|
+
setTimeout(() => {
|
|
12
|
+
for (const k of keys) input.write(k);
|
|
13
|
+
}, 20);
|
|
14
|
+
return clackPrompts({ input, output });
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const ENTER = "\r";
|
|
18
|
+
const DOWN = "\u001b[B";
|
|
19
|
+
const CTRL_C = "\u0003";
|
|
20
|
+
|
|
21
|
+
describe("clackPrompts — the Prompts port over @clack/prompts", () => {
|
|
22
|
+
it("confirm: Enter takes the initial value, `n` answers no", async () => {
|
|
23
|
+
expect(
|
|
24
|
+
await typed(ENTER).confirm({ message: "q?", initial: true }),
|
|
25
|
+
).toEqual({ kind: "answer", value: true });
|
|
26
|
+
expect(
|
|
27
|
+
await typed("n", ENTER).confirm({ message: "q?", initial: true }),
|
|
28
|
+
).toEqual({ kind: "answer", value: false });
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("select: the arrow moves off the initial option", async () => {
|
|
32
|
+
expect(
|
|
33
|
+
await typed(DOWN, ENTER).select({
|
|
34
|
+
message: "which?",
|
|
35
|
+
options: ["a", "b", "c"],
|
|
36
|
+
initial: "a",
|
|
37
|
+
}),
|
|
38
|
+
).toEqual({ kind: "answer", value: "b" });
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("text: what was typed; an empty line is the empty string", async () => {
|
|
42
|
+
expect(
|
|
43
|
+
await typed("draft", ENTER).text({
|
|
44
|
+
message: "name?",
|
|
45
|
+
placeholder: "skip",
|
|
46
|
+
}),
|
|
47
|
+
).toEqual({ kind: "answer", value: "draft" });
|
|
48
|
+
expect(
|
|
49
|
+
await typed(ENTER).text({ message: "name?", placeholder: "skip" }),
|
|
50
|
+
).toEqual({ kind: "answer", value: "" });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("🔴 Ctrl+C is a cancel, never an answer", async () => {
|
|
54
|
+
expect(
|
|
55
|
+
await typed(CTRL_C).confirm({ message: "q?", initial: true }),
|
|
56
|
+
).toEqual({ kind: "cancel" });
|
|
57
|
+
});
|
|
58
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { writeFileSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { describe, expect, it } from "vitest";
|
|
4
|
+
import { absolutePath } from "../../domain/paths.ts";
|
|
5
|
+
import { useTempDir } from "../../../test/support.ts";
|
|
6
|
+
import { addCommand, managerOf, projectInstall } from "./index.ts";
|
|
7
|
+
|
|
8
|
+
describe("the package manager, read from the lockfile", () => {
|
|
9
|
+
it("each lockfile names its manager; none is npm", () => {
|
|
10
|
+
const of = (file: string) => managerOf((f) => f === file);
|
|
11
|
+
expect([
|
|
12
|
+
of("package-lock.json"),
|
|
13
|
+
of("pnpm-lock.yaml"),
|
|
14
|
+
of("yarn.lock"),
|
|
15
|
+
of("bun.lock"),
|
|
16
|
+
of("bun.lockb"),
|
|
17
|
+
of("nothing"),
|
|
18
|
+
]).toEqual(["npm", "pnpm", "yarn", "bun", "bun", "npm"]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("each manager adds a devDependency saved exact", () => {
|
|
22
|
+
expect(
|
|
23
|
+
(["npm", "pnpm", "yarn", "bun"] as const).map((m) =>
|
|
24
|
+
addCommand(m, "paperlint@1.2.3").join(" "),
|
|
25
|
+
),
|
|
26
|
+
).toEqual([
|
|
27
|
+
"npm install --save-dev --save-exact paperlint@1.2.3",
|
|
28
|
+
"pnpm add --save-dev --save-exact paperlint@1.2.3",
|
|
29
|
+
"yarn add --dev --exact paperlint@1.2.3",
|
|
30
|
+
"bun add --dev --exact paperlint@1.2.3",
|
|
31
|
+
]);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
describe("projectInstall — the disk and the manager's program", () => {
|
|
36
|
+
it("the command follows the lockfile in the project root", () => {
|
|
37
|
+
const root = useTempDir("paperlint-pm-");
|
|
38
|
+
writeFileSync(join(root, "pnpm-lock.yaml"), "");
|
|
39
|
+
expect(projectInstall.command(absolutePath(root), "x@1")).toEqual([
|
|
40
|
+
"pnpm",
|
|
41
|
+
"add",
|
|
42
|
+
"--save-dev",
|
|
43
|
+
"--save-exact",
|
|
44
|
+
"x@1",
|
|
45
|
+
]);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("runs in the root: exit 0 is ok, any other exit and a missing program are failures", () => {
|
|
49
|
+
const root = absolutePath(useTempDir("paperlint-pm-"));
|
|
50
|
+
const node = process.execPath;
|
|
51
|
+
expect([
|
|
52
|
+
projectInstall.run(root, [node, "-e", "process.exit(0)"]),
|
|
53
|
+
projectInstall.run(root, [node, "-e", "process.exit(3)"]),
|
|
54
|
+
projectInstall.run(root, [
|
|
55
|
+
node,
|
|
56
|
+
"-e",
|
|
57
|
+
"process.kill(process.pid, 'SIGTERM')",
|
|
58
|
+
]),
|
|
59
|
+
projectInstall.run(root, ["paperlint-no-such-program"]),
|
|
60
|
+
]).toEqual([
|
|
61
|
+
{ ok: true },
|
|
62
|
+
{ ok: false, reason: "exited 3" },
|
|
63
|
+
{ ok: false, reason: "killed by SIGTERM" },
|
|
64
|
+
{ ok: false, reason: "spawnSync paperlint-no-such-program ENOENT" },
|
|
65
|
+
]);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `ProjectInstall` over the disk and the package manager's own program: the lockfiles are looked
|
|
3
|
+
* for in the project root, and the command runs there with the terminal's streams, so its progress
|
|
4
|
+
* and its errors reach the person who ran `paperlint init`.
|
|
5
|
+
*/
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
7
|
+
import { existsSync } from "node:fs";
|
|
8
|
+
import { join } from "node:path";
|
|
9
|
+
import type { ProjectInstall } from "../../ports/project-install.ts";
|
|
10
|
+
import { addCommand, managerOf } from "./manager.ts";
|
|
11
|
+
|
|
12
|
+
export const projectInstall: ProjectInstall = {
|
|
13
|
+
command: (root, spec) =>
|
|
14
|
+
addCommand(
|
|
15
|
+
managerOf((file) => existsSync(join(root, file))),
|
|
16
|
+
spec,
|
|
17
|
+
),
|
|
18
|
+
run: (root, [file, ...args]) => {
|
|
19
|
+
const r = spawnSync(file, args, { cwd: root, stdio: "inherit" });
|
|
20
|
+
if (r.error) return { ok: false, reason: r.error.message };
|
|
21
|
+
if (r.signal !== null)
|
|
22
|
+
return { ok: false, reason: `killed by ${r.signal}` };
|
|
23
|
+
return r.status === 0
|
|
24
|
+
? { ok: true }
|
|
25
|
+
: { ok: false, reason: `exited ${String(r.status)}` };
|
|
26
|
+
},
|
|
27
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which package manager a project uses, read from its lockfile, and how that manager adds a
|
|
3
|
+
* devDependency saved at an exact version. npm when no lockfile is there: it ships with Node.
|
|
4
|
+
*/
|
|
5
|
+
import type { Argv } from "../../ports/project-install.ts";
|
|
6
|
+
|
|
7
|
+
export type Manager = "npm" | "pnpm" | "yarn" | "bun";
|
|
8
|
+
|
|
9
|
+
/** Each lockfile and its manager, in the order they are looked for. */
|
|
10
|
+
export const LOCKFILES: readonly (readonly [string, Manager])[] = [
|
|
11
|
+
["package-lock.json", "npm"],
|
|
12
|
+
["pnpm-lock.yaml", "pnpm"],
|
|
13
|
+
["yarn.lock", "yarn"],
|
|
14
|
+
["bun.lock", "bun"],
|
|
15
|
+
["bun.lockb", "bun"],
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
/** The manager of the first lockfile `present` says is there; npm when none is. */
|
|
19
|
+
export const managerOf = (present: (file: string) => boolean): Manager =>
|
|
20
|
+
LOCKFILES.find(([file]) => present(file))?.[1] ?? "npm";
|
|
21
|
+
|
|
22
|
+
const ADD: Readonly<Record<Manager, Argv>> = {
|
|
23
|
+
npm: ["npm", "install", "--save-dev", "--save-exact"],
|
|
24
|
+
pnpm: ["pnpm", "add", "--save-dev", "--save-exact"],
|
|
25
|
+
yarn: ["yarn", "add", "--dev", "--exact"],
|
|
26
|
+
bun: ["bun", "add", "--dev", "--exact"],
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** The command that adds `spec` to devDependencies with `manager`. */
|
|
30
|
+
export const addCommand = (manager: Manager, spec: string): Argv => {
|
|
31
|
+
const [file, ...flags] = ADD[manager];
|
|
32
|
+
return [file, ...flags, spec];
|
|
33
|
+
};
|
package/src/cli.harness.mjs
CHANGED
|
@@ -42,6 +42,24 @@ const { PROGRAMS } = await import(join(HERE, "doctor.ts"));
|
|
|
42
42
|
// loads vigiles without recording a check is reported as having verified nothing.
|
|
43
43
|
const check = createChecker();
|
|
44
44
|
|
|
45
|
+
/**
|
|
46
|
+
* init's `Prompts` port answered by `reply(message, options)`: a value, `undefined` (Enter: the
|
|
47
|
+
* initial value) or an Error (the stream ended). Every message asked lands in `asked`.
|
|
48
|
+
*/
|
|
49
|
+
const answering = (reply, asked = []) => {
|
|
50
|
+
const one = async (message, initial, options) => {
|
|
51
|
+
asked.push(message);
|
|
52
|
+
const r = reply(message, options);
|
|
53
|
+
if (r instanceof Error) throw r;
|
|
54
|
+
return { kind: "answer", value: r === undefined ? initial : r };
|
|
55
|
+
};
|
|
56
|
+
return {
|
|
57
|
+
confirm: ({ message, initial }) => one(message, initial),
|
|
58
|
+
select: ({ message, initial, options }) => one(message, initial, options),
|
|
59
|
+
text: ({ message }) => one(message, ""),
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
45
63
|
/** A paper.tex whose whole body is `body`. */
|
|
46
64
|
const tex = (body) =>
|
|
47
65
|
`\\documentclass{article}\n\\begin{document}\n${body}\n\\end{document}\n`;
|
|
@@ -71,6 +89,11 @@ async function cli(args, cwd) {
|
|
|
71
89
|
const code = await run(args, {
|
|
72
90
|
log: (...a) => stdout.push(a.join(" ")),
|
|
73
91
|
err: (...a) => stderr.push(a.join(" ")),
|
|
92
|
+
// `init` never spawns a package manager here.
|
|
93
|
+
install: {
|
|
94
|
+
command: (_r, spec) => ["npm", spec],
|
|
95
|
+
run: () => ({ ok: true }),
|
|
96
|
+
},
|
|
74
97
|
});
|
|
75
98
|
return {
|
|
76
99
|
code,
|
|
@@ -463,10 +486,7 @@ check(
|
|
|
463
486
|
const asked = [];
|
|
464
487
|
const wf = await offerWorkflow(dir, {
|
|
465
488
|
interactive: true,
|
|
466
|
-
|
|
467
|
-
asked.push(q);
|
|
468
|
-
return "y";
|
|
469
|
-
},
|
|
489
|
+
prompts: answering(() => true, asked),
|
|
470
490
|
});
|
|
471
491
|
check(
|
|
472
492
|
"saying yes WRITES the workflow",
|
|
@@ -489,7 +509,7 @@ check(
|
|
|
489
509
|
check("the question is asked exactly once", asked.length === 1);
|
|
490
510
|
const again = await offerWorkflow(dir, {
|
|
491
511
|
interactive: true,
|
|
492
|
-
|
|
512
|
+
prompts: answering(() => true),
|
|
493
513
|
});
|
|
494
514
|
check(
|
|
495
515
|
"an existing workflow is neither overwritten nor asked about again",
|
|
@@ -500,7 +520,7 @@ check(
|
|
|
500
520
|
const dir = project("ci-no", { papers: ["writing"] });
|
|
501
521
|
const no = await offerWorkflow(dir, {
|
|
502
522
|
interactive: true,
|
|
503
|
-
|
|
523
|
+
prompts: answering(() => undefined),
|
|
504
524
|
});
|
|
505
525
|
check(
|
|
506
526
|
"an empty answer is a NO, and no file appears",
|
|
@@ -515,9 +535,7 @@ check(
|
|
|
515
535
|
// i.e. the real defect would look like a hole in the test rather than a caught one.
|
|
516
536
|
const aborted = await offerWorkflow(dir, {
|
|
517
537
|
interactive: true,
|
|
518
|
-
|
|
519
|
-
throw new Error("Aborted with Ctrl+D");
|
|
520
|
-
},
|
|
538
|
+
prompts: answering(() => new Error("Aborted with Ctrl+D")),
|
|
521
539
|
}).catch((e) => `THREW: ${e?.message ?? e}`);
|
|
522
540
|
check(
|
|
523
541
|
"🔴 an interrupted question does NOT crash the command — it means the default",
|
|
@@ -530,7 +548,7 @@ check(
|
|
|
530
548
|
const dir = project("many", { papers: ["alpha", "beta"] });
|
|
531
549
|
const picked = await choosePapers(dir, {
|
|
532
550
|
interactive: true,
|
|
533
|
-
|
|
551
|
+
prompts: answering((_q, options) => options?.[1]),
|
|
534
552
|
});
|
|
535
553
|
check(
|
|
536
554
|
"🔴 the human's answer DECIDES, it does not just decorate the output",
|
|
@@ -543,9 +561,7 @@ check(
|
|
|
543
561
|
);
|
|
544
562
|
const aborted = await choosePapers(dir, {
|
|
545
563
|
interactive: true,
|
|
546
|
-
|
|
547
|
-
throw new Error("Aborted with Ctrl+D");
|
|
548
|
-
},
|
|
564
|
+
prompts: answering(() => new Error("Aborted with Ctrl+D")),
|
|
549
565
|
}).catch((e) => ({
|
|
550
566
|
how: `THREW: ${e?.message ?? e}`,
|
|
551
567
|
papers: null,
|
|
@@ -1510,14 +1526,14 @@ console.log(
|
|
|
1510
1526
|
await init(dir, {
|
|
1511
1527
|
...quiet,
|
|
1512
1528
|
interactive: true,
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1529
|
+
prompts: answering(
|
|
1530
|
+
(q) => (/wire the paper hooks/.test(q) ? false : undefined),
|
|
1531
|
+
asked,
|
|
1532
|
+
),
|
|
1517
1533
|
});
|
|
1518
1534
|
check(
|
|
1519
|
-
"a human is asked
|
|
1520
|
-
asked.some((q) => /wire the paper hooks
|
|
1535
|
+
"a human is asked about the hooks",
|
|
1536
|
+
asked.some((q) => /wire the paper hooks/.test(q)),
|
|
1521
1537
|
);
|
|
1522
1538
|
check("and a no is respected", !existsSync(settings(dir)));
|
|
1523
1539
|
}
|
|
@@ -1526,7 +1542,7 @@ console.log(
|
|
|
1526
1542
|
await init(dir, {
|
|
1527
1543
|
...quiet,
|
|
1528
1544
|
interactive: true,
|
|
1529
|
-
|
|
1545
|
+
prompts: answering(() => undefined),
|
|
1530
1546
|
});
|
|
1531
1547
|
check(
|
|
1532
1548
|
"an empty answer is the stated default, YES",
|
|
@@ -1562,11 +1578,10 @@ console.log(
|
|
|
1562
1578
|
...base,
|
|
1563
1579
|
log: () => {},
|
|
1564
1580
|
interactive: true,
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
},
|
|
1581
|
+
prompts: answering(
|
|
1582
|
+
(q) => (/create a first paper/.test(q) ? "first" : undefined),
|
|
1583
|
+
asked,
|
|
1584
|
+
),
|
|
1570
1585
|
createPaper: async (papersRoot, name) => {
|
|
1571
1586
|
made.push({ papersRoot, name });
|
|
1572
1587
|
return 0;
|
|
@@ -1619,7 +1634,7 @@ console.log(
|
|
|
1619
1634
|
...base,
|
|
1620
1635
|
log: () => {},
|
|
1621
1636
|
interactive: true,
|
|
1622
|
-
|
|
1637
|
+
prompts: answering(() => undefined, asked),
|
|
1623
1638
|
createPaper: async () => 0,
|
|
1624
1639
|
});
|
|
1625
1640
|
check(
|
package/src/cli.test.ts
CHANGED
|
@@ -6,7 +6,13 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import assert from "node:assert/strict";
|
|
8
8
|
import { spawn } from "node:child_process";
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
existsSync,
|
|
11
|
+
mkdirSync,
|
|
12
|
+
readdirSync,
|
|
13
|
+
readFileSync,
|
|
14
|
+
symlinkSync,
|
|
15
|
+
} from "node:fs";
|
|
10
16
|
import { createServer } from "node:http";
|
|
11
17
|
import { dirname, join } from "node:path";
|
|
12
18
|
import { test, vi } from "vitest";
|
|
@@ -43,7 +49,10 @@ const root = useTempDir("cli-test-");
|
|
|
43
49
|
async function cli(
|
|
44
50
|
argv: string[],
|
|
45
51
|
cwd: string,
|
|
46
|
-
deps: Pick<
|
|
52
|
+
deps: Pick<
|
|
53
|
+
NonNullable<Parameters<typeof run>[1]>,
|
|
54
|
+
"loadTexLanguage" | "install"
|
|
55
|
+
> = {},
|
|
47
56
|
) {
|
|
48
57
|
const out: string[] = [];
|
|
49
58
|
const err: string[] = [];
|
|
@@ -52,6 +61,11 @@ async function cli(
|
|
|
52
61
|
err: (...a: unknown[]) => err.push(a.join(" ")),
|
|
53
62
|
cwd,
|
|
54
63
|
now: () => 0,
|
|
64
|
+
// `init` never spawns a package manager here: adding paperlint is `src/self-install.test.ts`'s.
|
|
65
|
+
install: {
|
|
66
|
+
command: (_root, spec) => ["npm", spec],
|
|
67
|
+
run: () => ({ ok: true }),
|
|
68
|
+
},
|
|
55
69
|
...deps,
|
|
56
70
|
});
|
|
57
71
|
return { code, out: out.join("\n"), err: err.join("\n") };
|
|
@@ -739,6 +753,83 @@ test("init with no path sets up the current directory, and its first paper is pa
|
|
|
739
753
|
assert.equal(made.includes("main.tex"), false);
|
|
740
754
|
});
|
|
741
755
|
|
|
756
|
+
test("init's step 0 that fails stops the run with 2: init itself never starts", async () => {
|
|
757
|
+
const dir = writeTree(join(root, "self-failed"), { "package.json": "{}" });
|
|
758
|
+
const r = await cli(["init", "--yes", "--no-hooks"], dir, {
|
|
759
|
+
install: {
|
|
760
|
+
command: (_root, spec) => ["npm", spec],
|
|
761
|
+
run: () => ({ ok: false, reason: "exit 1" }),
|
|
762
|
+
},
|
|
763
|
+
});
|
|
764
|
+
assert.deepEqual(
|
|
765
|
+
{
|
|
766
|
+
code: r.code,
|
|
767
|
+
out: r.out.split("\n"),
|
|
768
|
+
paperlintJson: existsSync(join(dir, "paperlint.json")),
|
|
769
|
+
},
|
|
770
|
+
{
|
|
771
|
+
code: 2,
|
|
772
|
+
out: [
|
|
773
|
+
"",
|
|
774
|
+
"paperlint in this project",
|
|
775
|
+
" → npm paperlint@0.0.0-semantically-released",
|
|
776
|
+
" ✗ npm paperlint@0.0.0-semantically-released failed (exit 1) — nothing else was done. Run it yourself, then `npx paperlint init` again",
|
|
777
|
+
],
|
|
778
|
+
paperlintJson: false,
|
|
779
|
+
},
|
|
780
|
+
);
|
|
781
|
+
});
|
|
782
|
+
|
|
783
|
+
test("init's step 0 reads the project's own copy: this checkout is present, another version is said and kept", async () => {
|
|
784
|
+
const pkg = (dir: string) => join(dir, "node_modules", "paperlint");
|
|
785
|
+
const own = writeTree(join(root, "self-own"), { "package.json": "{}" });
|
|
786
|
+
mkdirSync(join(own, "node_modules"));
|
|
787
|
+
symlinkSync(dirname(import.meta.dirname), pkg(own));
|
|
788
|
+
const older = writeTree(join(root, "self-older"), {
|
|
789
|
+
"package.json": "{}",
|
|
790
|
+
"node_modules/paperlint/package.json":
|
|
791
|
+
'{"name":"paperlint","version":"0.0.1"}',
|
|
792
|
+
});
|
|
793
|
+
const unversioned = writeTree(join(root, "self-unversioned"), {
|
|
794
|
+
"package.json": "{}",
|
|
795
|
+
"node_modules/paperlint/package.json": '{"name":"paperlint"}',
|
|
796
|
+
});
|
|
797
|
+
const head = async (dir: string) =>
|
|
798
|
+
(await cli(["init", "--yes", "--no-hooks"], dir)).out
|
|
799
|
+
.split("\n")
|
|
800
|
+
.slice(0, 4);
|
|
801
|
+
assert.deepEqual(
|
|
802
|
+
[await head(own), await head(older), await head(unversioned)],
|
|
803
|
+
[
|
|
804
|
+
[
|
|
805
|
+
"",
|
|
806
|
+
"paperlint init — each decision below says HOW it was decided",
|
|
807
|
+
"",
|
|
808
|
+
"papers directory",
|
|
809
|
+
],
|
|
810
|
+
[
|
|
811
|
+
"",
|
|
812
|
+
"paperlint in this project",
|
|
813
|
+
" ⚠ paperlint 0.0.1 is installed in this project, and this command is 0.0.0-semantically-released: kept 0.0.1, nothing up- or downgraded",
|
|
814
|
+
" to move the project to 0.0.0-semantically-released: npm paperlint@0.0.0-semantically-released",
|
|
815
|
+
],
|
|
816
|
+
[
|
|
817
|
+
"",
|
|
818
|
+
"paperlint in this project",
|
|
819
|
+
" → npm paperlint@0.0.0-semantically-released",
|
|
820
|
+
" ✓ added paperlint to devDependencies",
|
|
821
|
+
],
|
|
822
|
+
],
|
|
823
|
+
);
|
|
824
|
+
// What is added can be named instead: the install e2e adds the packed tarball.
|
|
825
|
+
vi.stubEnv("PAPERLINT_INSTALL_SPEC", "/tmp/p.tgz");
|
|
826
|
+
try {
|
|
827
|
+
assert.equal((await head(unversioned))[2], " → npm /tmp/p.tgz");
|
|
828
|
+
} finally {
|
|
829
|
+
vi.unstubAllEnvs();
|
|
830
|
+
}
|
|
831
|
+
});
|
|
832
|
+
|
|
742
833
|
test("init and doctor with a declaration that names no directory: nothing to compare", async () => {
|
|
743
834
|
const dir = writeTree(join(root, "init-empty"), {
|
|
744
835
|
"package.json": "{}",
|
package/src/cli.ts
CHANGED
|
@@ -24,7 +24,14 @@
|
|
|
24
24
|
* replaced it: silently breaking someone else's workflow is worse than asking them to fix a line.
|
|
25
25
|
*/
|
|
26
26
|
import { ESLint, type Linter } from "eslint";
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
readFileSync,
|
|
29
|
+
readdirSync,
|
|
30
|
+
existsSync,
|
|
31
|
+
realpathSync,
|
|
32
|
+
statSync,
|
|
33
|
+
} from "node:fs";
|
|
34
|
+
import { absolutePath } from "./domain/paths.ts";
|
|
28
35
|
import { createRequire } from "node:module";
|
|
29
36
|
import { stripVTControlCharacters } from "node:util";
|
|
30
37
|
import { spawnSync } from "node:child_process";
|
|
@@ -155,6 +162,8 @@ import { doctor } from "./doctor.ts";
|
|
|
155
162
|
import {
|
|
156
163
|
askOnTerminal,
|
|
157
164
|
askOrDefault,
|
|
165
|
+
CANCELLED_CODE,
|
|
166
|
+
CANCELLED_LINE,
|
|
158
167
|
init,
|
|
159
168
|
processInteractivity,
|
|
160
169
|
} from "./init.ts";
|
|
@@ -233,7 +242,19 @@ import {
|
|
|
233
242
|
recordTold,
|
|
234
243
|
} from "./hooks-notice.ts";
|
|
235
244
|
import { unwiredHooks } from "./hooks-settings.ts";
|
|
236
|
-
import {
|
|
245
|
+
import {
|
|
246
|
+
linkSkills,
|
|
247
|
+
locatePackage,
|
|
248
|
+
unlinkedSkills,
|
|
249
|
+
type LinkReport,
|
|
250
|
+
} from "./link-skills.ts";
|
|
251
|
+
import { projectInstall } from "./adapters/package-manager/index.ts";
|
|
252
|
+
import type { ProjectInstall } from "./ports/project-install.ts";
|
|
253
|
+
import {
|
|
254
|
+
selfInstallStep,
|
|
255
|
+
versionOf,
|
|
256
|
+
type SelfInstallDeps,
|
|
257
|
+
} from "./self-install.ts";
|
|
237
258
|
import {
|
|
238
259
|
lintEditedHook,
|
|
239
260
|
type LintResult,
|
|
@@ -2381,7 +2402,13 @@ async function runInit(
|
|
|
2381
2402
|
log,
|
|
2382
2403
|
err,
|
|
2383
2404
|
cwd,
|
|
2384
|
-
|
|
2405
|
+
install,
|
|
2406
|
+
}: {
|
|
2407
|
+
log: typeof console.log;
|
|
2408
|
+
err: typeof console.error;
|
|
2409
|
+
cwd: string;
|
|
2410
|
+
install: ProjectInstall;
|
|
2411
|
+
},
|
|
2385
2412
|
): Promise<number> {
|
|
2386
2413
|
// Deferred, not implemented: named and refused, rather than read as the directory argument.
|
|
2387
2414
|
if (a.hooksMode !== null) {
|
|
@@ -2391,10 +2418,22 @@ async function runInit(
|
|
|
2391
2418
|
);
|
|
2392
2419
|
return 2;
|
|
2393
2420
|
}
|
|
2421
|
+
// Loaded here, not at the top: every hook runs through this file, and none of them asks anything.
|
|
2422
|
+
const { clackPrompts } = await import("./adapters/clack/index.ts");
|
|
2423
|
+
const prompts = clackPrompts();
|
|
2424
|
+
// Step 0, before init: paperlint itself, in the project's devDependencies (`self-install.ts`).
|
|
2425
|
+
const stop = await selfInstallStep(
|
|
2426
|
+
absolutePath(resolve(cwd, a.paths[0] ?? ".")),
|
|
2427
|
+
selfInstallDeps(install),
|
|
2428
|
+
{ prompts, interactive: processInteractivity(a.yes).interactive, log },
|
|
2429
|
+
{ code: CANCELLED_CODE, line: CANCELLED_LINE },
|
|
2430
|
+
);
|
|
2431
|
+
if (stop !== null) return stop;
|
|
2394
2432
|
return await init(a.paths[0] ?? ".", {
|
|
2395
2433
|
log,
|
|
2396
2434
|
err,
|
|
2397
2435
|
cwd,
|
|
2436
|
+
prompts,
|
|
2398
2437
|
yes: a.yes,
|
|
2399
2438
|
hooks: !a.noHooks,
|
|
2400
2439
|
paper: a.paper,
|
|
@@ -2407,6 +2446,35 @@ async function runInit(
|
|
|
2407
2446
|
});
|
|
2408
2447
|
}
|
|
2409
2448
|
|
|
2449
|
+
/** This copy of paperlint: its real directory and its version. */
|
|
2450
|
+
const runningCopy = (): { readonly dir: string; readonly version: string } => ({
|
|
2451
|
+
dir: realpathSync(fileURLToPath(new URL("..", import.meta.url))),
|
|
2452
|
+
version: packageVersion(),
|
|
2453
|
+
});
|
|
2454
|
+
|
|
2455
|
+
/**
|
|
2456
|
+
* What `init` needs to add paperlint to a project. `PAPERLINT_INSTALL_SPEC` replaces what is added
|
|
2457
|
+
* (a tarball, for the install e2e: an unreleased build's version is on no registry).
|
|
2458
|
+
*/
|
|
2459
|
+
const selfInstallDeps = (install: ProjectInstall): SelfInstallDeps => {
|
|
2460
|
+
const running = runningCopy();
|
|
2461
|
+
return {
|
|
2462
|
+
running,
|
|
2463
|
+
installed: (root) => {
|
|
2464
|
+
const at = locatePackage(root);
|
|
2465
|
+
if ("error" in at) return null;
|
|
2466
|
+
const version = versionOf(
|
|
2467
|
+
nodeFiles.readBytes(absolutePath(join(at.dir, "package.json"))),
|
|
2468
|
+
);
|
|
2469
|
+
return version === null ? null : { dir: at.dir, version };
|
|
2470
|
+
},
|
|
2471
|
+
files: nodeFiles,
|
|
2472
|
+
install,
|
|
2473
|
+
spec:
|
|
2474
|
+
process.env["PAPERLINT_INSTALL_SPEC"] ?? `paperlint@${running.version}`,
|
|
2475
|
+
};
|
|
2476
|
+
};
|
|
2477
|
+
|
|
2410
2478
|
/** The LaTeX language, loaded when a lint needs it: only `lint` and the `lint-edited` hook do. */
|
|
2411
2479
|
const loadLatexLanguage = async (): Promise<unknown> =>
|
|
2412
2480
|
(await import("#eslint-rules/latex-language")).texLanguage;
|
|
@@ -2421,10 +2489,13 @@ export async function run(
|
|
|
2421
2489
|
checkReferences = onlineReferences,
|
|
2422
2490
|
loadTexLanguage = loadLatexLanguage,
|
|
2423
2491
|
skillLinks = readSkillLinks,
|
|
2492
|
+
install = projectInstall,
|
|
2424
2493
|
}: {
|
|
2425
2494
|
log?: typeof console.log;
|
|
2426
2495
|
err?: typeof console.error;
|
|
2427
2496
|
cwd?: string;
|
|
2497
|
+
/** How `init` adds paperlint to a project: the package manager by default; a test hands a fake. */
|
|
2498
|
+
install?: ProjectInstall;
|
|
2428
2499
|
/** The clock `lint` times itself with, in milliseconds; a test hands one that answers fixed values. */
|
|
2429
2500
|
now?: () => number;
|
|
2430
2501
|
/**
|
|
@@ -2466,7 +2537,7 @@ export async function run(
|
|
|
2466
2537
|
// `init` asks the CLI's OWN reader what it would lint, so the two sides `doctor` compares are
|
|
2467
2538
|
// not two implementations of the same question. A second resolver here is the defect the
|
|
2468
2539
|
// comparison exists to catch.
|
|
2469
|
-
if (a.cmd === "init") return await runInit(a, { log, err, cwd });
|
|
2540
|
+
if (a.cmd === "init") return await runInit(a, { log, err, cwd, install });
|
|
2470
2541
|
// `doctor` reads the config but must NOT die on a broken one — reporting that the config is
|
|
2471
2542
|
// broken is precisely its job. So a failed read becomes "the CLI would lint nothing", which is
|
|
2472
2543
|
// what it prints, rather than an early exit that tells the reader nothing about the hooks.
|