paperlint 18.5.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 +3 -3
- 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/hotcrp/portal.io.d.ts.map +1 -1
- package/dist/adapters/hotcrp/portal.io.js +1 -0
- package/dist/adapters/hotcrp/portal.io.js.map +1 -1
- package/dist/adapters/hotcrp/response.d.ts.map +1 -1
- package/dist/adapters/hotcrp/response.js +15 -0
- package/dist/adapters/hotcrp/response.js.map +1 -1
- 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 +47 -9
- package/dist/cli.js.map +1 -1
- package/dist/domain/submission.d.ts +4 -0
- package/dist/domain/submission.d.ts.map +1 -1
- package/dist/domain/submission.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/dist/submission.d.ts +19 -2
- package/dist/submission.d.ts.map +1 -1
- package/dist/submission.js +121 -17
- package/dist/submission.js.map +1 -1
- 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/docs/submission.md +19 -4
- 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/hotcrp/portal.io.ts +1 -0
- package/src/adapters/hotcrp/portal.test.ts +43 -2
- package/src/adapters/hotcrp/response.ts +21 -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 +80 -7
- package/src/domain/submission.ts +4 -0
- 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
- package/src/submission-fields-run.test.ts +1 -0
- package/src/submission-prior-reviews.test.ts +9 -1
- package/src/submission-show.test.ts +81 -0
- package/src/submission-update.test.ts +164 -6
- package/src/submission.ts +208 -24
|
@@ -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
|
+
});
|
|
@@ -102,6 +102,7 @@ export function changeObject(
|
|
|
102
102
|
object: "paper",
|
|
103
103
|
pid: id,
|
|
104
104
|
...(c.pdf === null ? {} : { submission: { content_file: CONTENT_FIELD } }),
|
|
105
|
+
...(c.title === null ? {} : { title: c.title }),
|
|
105
106
|
...(c.abstract === null ? {} : { abstract: c.abstract }),
|
|
106
107
|
...(c.submit ? { status: "submitted" } : {}),
|
|
107
108
|
...c.fields,
|
|
@@ -203,6 +203,13 @@ test("show: GET /api/paper?p=<id>&word_limit=hard with the bearer token, parsed
|
|
|
203
203
|
paperType: "Example paper type",
|
|
204
204
|
topics: ["Example topic one", "Example topic two"],
|
|
205
205
|
abstract: "An example abstract of exactly ten words for the test.",
|
|
206
|
+
authors: [
|
|
207
|
+
{
|
|
208
|
+
name: "A. Author",
|
|
209
|
+
email: "author@example.org",
|
|
210
|
+
affiliation: "Example University",
|
|
211
|
+
},
|
|
212
|
+
],
|
|
206
213
|
pdf: {
|
|
207
214
|
sha256: CASSETTE_HEX,
|
|
208
215
|
hash: `sha2-${CASSETTE_HEX}`,
|
|
@@ -237,6 +244,7 @@ test("show: a submission without a PDF, fields absent, a paper type that is not
|
|
|
237
244
|
paperType: "2",
|
|
238
245
|
topics: [],
|
|
239
246
|
abstract: null,
|
|
247
|
+
authors: null,
|
|
240
248
|
pdf: {
|
|
241
249
|
sha256: null,
|
|
242
250
|
hash: "sha2-short",
|
|
@@ -260,6 +268,25 @@ test("show: a null paper type and a null submission read as none", async () => {
|
|
|
260
268
|
assert.deepEqual(r.ok && [r.value.paperType, r.value.pdf], [null, null]);
|
|
261
269
|
});
|
|
262
270
|
|
|
271
|
+
test("show: an author HotCRP names by one part, or without an email, reads with what it has", async () => {
|
|
272
|
+
answer(200, {
|
|
273
|
+
ok: true,
|
|
274
|
+
paper: {
|
|
275
|
+
pid: 7,
|
|
276
|
+
status: "draft",
|
|
277
|
+
authors: [
|
|
278
|
+
{ email: "ada@example.org", family_name: "Lovelace" },
|
|
279
|
+
{ given_name: "Bob" },
|
|
280
|
+
],
|
|
281
|
+
},
|
|
282
|
+
});
|
|
283
|
+
const r = await portal().show(7);
|
|
284
|
+
assert.deepEqual(r.ok && r.value.authors, [
|
|
285
|
+
{ name: "Lovelace", email: "ada@example.org", affiliation: null },
|
|
286
|
+
{ name: "Bob", email: "", affiliation: null },
|
|
287
|
+
]);
|
|
288
|
+
});
|
|
289
|
+
|
|
263
290
|
test("🔴 show: 401 surfaces HotCRP's own message, and the token is in no part of it", async () => {
|
|
264
291
|
seen.length = 0;
|
|
265
292
|
reply = { status: 401, body: cassette("get-noauth") };
|
|
@@ -278,6 +305,7 @@ test("🔴 show: 401 surfaces HotCRP's own message, and the token is in no part
|
|
|
278
305
|
|
|
279
306
|
const CHANGE: SubmissionChange = {
|
|
280
307
|
pdf: { name: "paper.pdf", bytes: PDF },
|
|
308
|
+
title: "A New Title",
|
|
281
309
|
abstract: "new abstract",
|
|
282
310
|
submit: true,
|
|
283
311
|
fields: {},
|
|
@@ -301,6 +329,7 @@ test("update: a dry run by default — dry_run=1, the json field, the PDF under
|
|
|
301
329
|
object: "paper",
|
|
302
330
|
pid: 7,
|
|
303
331
|
submission: { content_file: CONTENT_FIELD },
|
|
332
|
+
title: "A New Title",
|
|
304
333
|
abstract: "new abstract",
|
|
305
334
|
status: "submitted",
|
|
306
335
|
});
|
|
@@ -573,7 +602,13 @@ test("a portal that does not answer is unreachable, with the network's words", a
|
|
|
573
602
|
|
|
574
603
|
test("changeObject: only what changes is sent", () => {
|
|
575
604
|
assert.deepEqual(
|
|
576
|
-
changeObject(7, {
|
|
605
|
+
changeObject(7, {
|
|
606
|
+
pdf: null,
|
|
607
|
+
title: null,
|
|
608
|
+
abstract: null,
|
|
609
|
+
submit: false,
|
|
610
|
+
fields: {},
|
|
611
|
+
}),
|
|
577
612
|
{ object: "paper", pid: 7 },
|
|
578
613
|
);
|
|
579
614
|
});
|
|
@@ -585,7 +620,13 @@ test("changeObject and createObject: the venue's fields go in as submission-obje
|
|
|
585
620
|
ACMCorAut: "ada@example.org",
|
|
586
621
|
};
|
|
587
622
|
assert.deepEqual(
|
|
588
|
-
changeObject(7, {
|
|
623
|
+
changeObject(7, {
|
|
624
|
+
pdf: null,
|
|
625
|
+
title: null,
|
|
626
|
+
abstract: null,
|
|
627
|
+
submit: false,
|
|
628
|
+
fields,
|
|
629
|
+
}),
|
|
589
630
|
{ object: "paper", pid: 7, ...fields },
|
|
590
631
|
);
|
|
591
632
|
const created = createObject({ ...NEW, fields });
|
|
@@ -12,6 +12,7 @@ import { z } from "zod";
|
|
|
12
12
|
import { err, ok, type Result } from "../../domain/result.ts";
|
|
13
13
|
import { parseSha256, type Sha256 } from "../../domain/sha256.ts";
|
|
14
14
|
import type {
|
|
15
|
+
Author,
|
|
15
16
|
CreateOutcome,
|
|
16
17
|
PortalDocument,
|
|
17
18
|
PortalFailure,
|
|
@@ -42,6 +43,16 @@ const Paper = z.object({
|
|
|
42
43
|
abstract: z.string().optional(),
|
|
43
44
|
paper_type: z.unknown().optional(),
|
|
44
45
|
topics: z.array(z.string()).optional(),
|
|
46
|
+
authors: z
|
|
47
|
+
.array(
|
|
48
|
+
z.object({
|
|
49
|
+
email: z.string().optional(),
|
|
50
|
+
given_name: z.string().optional(),
|
|
51
|
+
family_name: z.string().optional(),
|
|
52
|
+
affiliation: z.string().optional(),
|
|
53
|
+
}),
|
|
54
|
+
)
|
|
55
|
+
.optional(),
|
|
45
56
|
submission: Document.nullable().optional(),
|
|
46
57
|
submitted_at: z.number().optional(),
|
|
47
58
|
modified_at: z.number().optional(),
|
|
@@ -115,6 +126,15 @@ const typeText = (v: unknown): string | null =>
|
|
|
115
126
|
? v
|
|
116
127
|
: JSON.stringify(v);
|
|
117
128
|
|
|
129
|
+
/** An author as HotCRP sends one — the name in two parts — in the paper's terms. */
|
|
130
|
+
const authorOf = (
|
|
131
|
+
a: Readonly<NonNullable<z.infer<typeof Paper>["authors"]>[number]>,
|
|
132
|
+
): Author => ({
|
|
133
|
+
name: `${a.given_name ?? ""} ${a.family_name ?? ""}`.trim(),
|
|
134
|
+
email: a.email ?? "",
|
|
135
|
+
affiliation: a.affiliation ?? null,
|
|
136
|
+
});
|
|
137
|
+
|
|
118
138
|
function viewOf(b: Readonly<z.infer<typeof ShowBody>>): SubmissionView {
|
|
119
139
|
const p = b.paper;
|
|
120
140
|
return {
|
|
@@ -124,6 +144,7 @@ function viewOf(b: Readonly<z.infer<typeof ShowBody>>): SubmissionView {
|
|
|
124
144
|
paperType: typeText(p.paper_type),
|
|
125
145
|
topics: p.topics ?? [],
|
|
126
146
|
abstract: p.abstract ?? null,
|
|
147
|
+
authors: p.authors === undefined ? null : p.authors.map(authorOf),
|
|
127
148
|
pdf: documentOf(p.submission),
|
|
128
149
|
submittedAt: p.submitted_at ?? null,
|
|
129
150
|
modifiedAt: p.modified_at ?? null,
|
|
@@ -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": "{}",
|