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.
Files changed (117) hide show
  1. package/CLAUDE.md +3 -3
  2. package/CONTRIBUTING.md +5 -2
  3. package/README.md +6 -6
  4. package/dist/adapters/clack/index.d.ts +3 -0
  5. package/dist/adapters/clack/index.d.ts.map +1 -0
  6. package/dist/adapters/clack/index.js +3 -0
  7. package/dist/adapters/clack/index.js.map +1 -0
  8. package/dist/adapters/clack/prompts.io.d.ts +8 -0
  9. package/dist/adapters/clack/prompts.io.d.ts.map +1 -0
  10. package/dist/adapters/clack/prompts.io.js +20 -0
  11. package/dist/adapters/clack/prompts.io.js.map +1 -0
  12. package/dist/adapters/hotcrp/portal.io.d.ts.map +1 -1
  13. package/dist/adapters/hotcrp/portal.io.js +1 -0
  14. package/dist/adapters/hotcrp/portal.io.js.map +1 -1
  15. package/dist/adapters/hotcrp/response.d.ts.map +1 -1
  16. package/dist/adapters/hotcrp/response.js +15 -0
  17. package/dist/adapters/hotcrp/response.js.map +1 -1
  18. package/dist/adapters/package-manager/index.d.ts +4 -0
  19. package/dist/adapters/package-manager/index.d.ts.map +1 -0
  20. package/dist/adapters/package-manager/index.js +4 -0
  21. package/dist/adapters/package-manager/index.js.map +1 -0
  22. package/dist/adapters/package-manager/install.io.d.ts +3 -0
  23. package/dist/adapters/package-manager/install.io.d.ts.map +1 -0
  24. package/dist/adapters/package-manager/install.io.js +23 -0
  25. package/dist/adapters/package-manager/install.io.js.map +1 -0
  26. package/dist/adapters/package-manager/manager.d.ts +13 -0
  27. package/dist/adapters/package-manager/manager.d.ts.map +1 -0
  28. package/dist/adapters/package-manager/manager.js +22 -0
  29. package/dist/adapters/package-manager/manager.js.map +1 -0
  30. package/dist/adapters/study-registry/index.d.ts +2 -2
  31. package/dist/cli.d.ts +4 -1
  32. package/dist/cli.d.ts.map +1 -1
  33. package/dist/cli.js +47 -9
  34. package/dist/cli.js.map +1 -1
  35. package/dist/domain/submission.d.ts +4 -0
  36. package/dist/domain/submission.d.ts.map +1 -1
  37. package/dist/domain/submission.js.map +1 -1
  38. package/dist/init.d.ts +38 -15
  39. package/dist/init.d.ts.map +1 -1
  40. package/dist/init.js +99 -39
  41. package/dist/init.js.map +1 -1
  42. package/dist/ports/project-install.d.ts +19 -0
  43. package/dist/ports/project-install.d.ts.map +1 -0
  44. package/dist/ports/project-install.js +2 -0
  45. package/dist/ports/project-install.js.map +1 -0
  46. package/dist/ports/prompts.d.ts +31 -0
  47. package/dist/ports/prompts.d.ts.map +1 -0
  48. package/dist/ports/prompts.js +2 -0
  49. package/dist/ports/prompts.js.map +1 -0
  50. package/dist/self-install.d.ts +65 -0
  51. package/dist/self-install.d.ts.map +1 -0
  52. package/dist/self-install.js +145 -0
  53. package/dist/self-install.js.map +1 -0
  54. package/dist/skill-chunks/chunk-65X5HVIJ.js +26462 -0
  55. package/dist/skill-chunks/chunk-6NU6CXUS.js +258 -0
  56. package/dist/skill-chunks/chunk-GRSXIWYF.js +352 -0
  57. package/dist/skill-chunks/chunk-IREAROCV.js +84 -0
  58. package/dist/skill-chunks/chunk-KWK6RT4T.js +24267 -0
  59. package/dist/skill-chunks/chunk-NPQVDEE4.js +19681 -0
  60. package/dist/skill-chunks/chunk-PJ4KNV4J.js +45 -0
  61. package/dist/skill-chunks/dist-UPCJMLBM.js +385 -0
  62. package/dist/skill-chunks/pdfjs-LUMEFOH2.js +39518 -0
  63. package/dist/submission.d.ts +19 -2
  64. package/dist/submission.d.ts.map +1 -1
  65. package/dist/submission.js +121 -17
  66. package/dist/submission.js.map +1 -1
  67. package/docs/e2e.md +10 -0
  68. package/docs/install.md +27 -16
  69. package/docs/prior-art/README.md +2 -0
  70. package/docs/prior-art/one-command-install.md +33 -0
  71. package/docs/prior-art/prompt-libraries.md +32 -0
  72. package/docs/submission.md +19 -4
  73. package/eslint.config.mjs +1 -0
  74. package/lib/skill-checks.mjs +17 -9
  75. package/lib/skill-checks.test.mjs +28 -15
  76. package/lib/skill-corpus.mjs +5 -2
  77. package/package.json +5 -3
  78. package/scripts/bundle-skills.test.ts +226 -0
  79. package/scripts/bundle-skills.ts +304 -0
  80. package/skills/argument-arc/SKILL.md +2 -2
  81. package/skills/argument-arc/SKILL.md.spec.ts +1 -1
  82. package/skills/argument-arc/scripts/headings.js +57 -13
  83. package/skills/build-label-page/scripts/label-page.js +2005 -93
  84. package/skills/cold-read-diff/scripts/cold-read.js +221 -14
  85. package/skills/label-agent-runs/scripts/labels.js +272 -348
  86. package/skills/paper-pipeline/scripts/extract-ref-facts.js +304 -0
  87. package/skills/pc-panel-review/scripts/prior-reviews.js +7244 -12
  88. package/skills/run-agent-grid/scripts/grid-guard.js +562 -627
  89. package/skills/verify-citations/SKILL.md +9 -9
  90. package/skills/verify-citations/SKILL.md.spec.ts +8 -8
  91. package/skills/verify-citations/scripts/bib-authors.js +228 -0
  92. package/skills/verify-citations/scripts/verify-cites.js +816 -0
  93. package/src/adapters/clack/index.ts +2 -0
  94. package/src/adapters/clack/prompts.io.ts +35 -0
  95. package/src/adapters/clack/prompts.test.ts +58 -0
  96. package/src/adapters/hotcrp/portal.io.ts +1 -0
  97. package/src/adapters/hotcrp/portal.test.ts +43 -2
  98. package/src/adapters/hotcrp/response.ts +21 -0
  99. package/src/adapters/package-manager/index.test.ts +67 -0
  100. package/src/adapters/package-manager/index.ts +3 -0
  101. package/src/adapters/package-manager/install.io.ts +27 -0
  102. package/src/adapters/package-manager/manager.ts +33 -0
  103. package/src/cli.harness.mjs +41 -26
  104. package/src/cli.test.ts +93 -2
  105. package/src/cli.ts +80 -7
  106. package/src/domain/submission.ts +4 -0
  107. package/src/init.test.ts +138 -27
  108. package/src/init.ts +128 -72
  109. package/src/ports/project-install.ts +18 -0
  110. package/src/ports/prompts.ts +27 -0
  111. package/src/self-install.test.ts +267 -0
  112. package/src/self-install.ts +224 -0
  113. package/src/submission-fields-run.test.ts +1 -0
  114. package/src/submission-prior-reviews.test.ts +9 -1
  115. package/src/submission-show.test.ts +81 -0
  116. package/src/submission-update.test.ts +164 -6
  117. package/src/submission.ts +208 -24
@@ -0,0 +1,32 @@
1
+ # Which library draws `paperlint init`'s questions
2
+
3
+ `paperlint init` asked its questions through `node:readline` until 2026-11-22, typed as
4
+ `[Y/n]` text. They now go through one port (`src/ports/prompts.ts`: a yes/no, a choice, a line of
5
+ text), drawn by `@clack/prompts` in `src/adapters/clack/`.
6
+
7
+ ## The candidates, measured 2026-11-22
8
+
9
+ Each package installed alone into an empty directory with npm; downloads from api.npmjs.org for the
10
+ week 2026-11-14 to 2026-11-20.
11
+
12
+ | package | version | packages installed | on disk | downloads a week | last release |
13
+ | ------------------- | ------- | ------------------ | ------- | ---------------- | ------------ |
14
+ | `@clack/prompts` | 1.9.0 | 6 | 336 KB | 48.6 M | 2026-11-09 |
15
+ | `@inquirer/prompts` | 8.8.0 | 27 | 1900 KB | 66.4 M | |
16
+ | `@inquirer/confirm` | 6.4.0 | 13 | 672 KB | | |
17
+ | `prompts` | 2.4.2 | 3 | 476 KB | 98.2 M | 2023-10 |
18
+ | `enquirer` | 2.4.1 | 4 | 424 KB | 50.9 M | 2023-07 |
19
+
20
+ **Chosen: `@clack/prompts`**, pinned. The smallest on disk of the maintained ones (`prompts` and
21
+ `enquirer` have not released since 2023), and it has the three questions init asks
22
+ (`confirm`, `select`, `text`) plus a cancel value (`isCancel`).
23
+
24
+ ## Two behaviours, measured on a pseudo-terminal
25
+
26
+ - **Ctrl+C.** Under readline, Ctrl+C at a question rejected it, the rejection was read as "no
27
+ answer", and the question's default was taken: a Ctrl+C at the hooks question wired the hooks,
28
+ and the run went on and exited 0. Under clack it is a cancel: init prints one line, writes nothing
29
+ after that question, and exits 130 (`CANCELLED_CODE` in `src/init.ts`).
30
+ - **Width.** Clack redraws a question by moving the cursor up as many lines as it drew. On a
31
+ pseudo-terminal with no size set it counted every character as a line (`ESC[2280A`), so a test
32
+ that drives it on a pseudo-terminal sets the window size first.
@@ -119,10 +119,25 @@ then `match`: `yes` means the portal holds exactly the PDF you built (compared b
119
119
  deadlines in force for the current attempt, each with when and where it was read
120
120
  ([Deadlines](configuration.md#deadlines)). Exit 0 whenever the portal answered.
121
121
 
122
+ It also compares what the portal holds with the paper, and adds a line only where they differ:
123
+
124
+ - `paper title`, `paper abstract` — the paper's own (read as `new` reads them) is not the portal's;
125
+ `update` sends it;
126
+ - `paper authors` — `"authors"` in `paperlint.json` is not what the portal records (an author's
127
+ email in any case, name, affiliation, and their order). `update` does not change the authors;
128
+ change them on the site.
129
+
130
+ Spacing is not a difference. What paperlint cannot read, or a side that names no authors, is not
131
+ compared.
132
+
122
133
  ## `update`
123
134
 
124
- Sends the PDF, the paper's `"fields"`, and, when asked, a new abstract (`--abstract <file>`) and
125
- "submitted" (`--submit`).
135
+ Sends the PDF, the paper's `"fields"`, the paper's title and abstract each when the portal holds
136
+ another, and "submitted" when asked (`--submit`). `--abstract <file>` sends that file's text instead
137
+ of the paper's abstract, whatever the portal holds. One `title` and one `abstract` line say what
138
+ happens to each: `sends … — the portal has …`, `unchanged`, or `not checked` with the reason when
139
+ paperlint cannot read it, and then it sends none. Texts that differ only in spacing are the same. The
140
+ portal is read once for both, before the change is sent; a failed read stops the update.
126
141
  Without `--save` it is a dry run. It prints the portal's verdict and its messages; exit 1 when the
127
142
  portal would not take the change. Before sending, it asks you to open that exact PDF and check it
128
143
  against the venue's call for papers.
@@ -223,6 +238,6 @@ every client.
223
238
 
224
239
  ## What it does not do
225
240
 
226
- - It does not set a field the venue preset does not record, change the authors after `new`, or
227
- upload supplementary files.
241
+ - It does not set a field the venue preset does not record, change the authors after `new` (`show`
242
+ says when they differ), or upload supplementary files.
228
243
  - It does not run the rest of `paperlint lint`: only the venue rules, on the PDF.
package/eslint.config.mjs CHANGED
@@ -252,6 +252,7 @@ export const IO_MODULES = [
252
252
  * (`IO_MODULES`).
253
253
  */
254
254
  export const TOOL_PACKAGES = [
255
+ "@clack/prompts", // the terminal questions of `paperlint init`
255
256
  "@eslint/markdown", // ESLint's Markdown language
256
257
  "@eslint/plugin-kit",
257
258
  "@retorquere/bibtex-parser", // BibTeX
@@ -35,6 +35,8 @@ import {
35
35
  } from "../skills/paper-pipeline/scripts/consumer.mjs";
36
36
 
37
37
  const PIPELINE = pipelineScripts(scriptsRoot({ env: {}, cwd: ROOT }));
38
+ /** How a SKILL.md names its own directory in a command: Claude Code substitutes it wherever the skill is. */
39
+ const SKILL_DIR_VAR = "${CLAUDE_SKILL_DIR}/";
38
40
 
39
41
  /** How a skill names a file of the package's presets directory. */
40
42
  const PRESETS_PREFIX = "presets/";
@@ -113,18 +115,21 @@ export async function checkSkill(name) {
113
115
  // ═══════════════════════════════════════════════════════════════════════════════════════════════
114
116
  // 7. EVERY script path the skill instructs resolves.
115
117
  //
116
- // Scoped to paths that are unambiguously resolvable: `.claude/…` is repo-root-relative and
117
- // `scripts/…` is skill-relative (both conventions are used consistently across the corpus). Paths
118
+ // Scoped to paths that are unambiguously resolvable: `${CLAUDE_SKILL_DIR}/…` and `scripts/…` are
119
+ // skill-relative, `.claude/…` is repo-root-relative. A `.js` a skill runs is a build output
120
+ // (`npm run build`), so this checks the checkout as built. Paths
118
121
  // like `repro/build-submission.sh` are relative to a PAPER directory that does not exist at test
119
122
  // time, so they are excluded BY NAME rather than by a guess that would fire on correct text.
120
123
  // ═══════════════════════════════════════════════════════════════════════════════════════════════
121
124
  for (const s of skills) {
122
125
  for (const c of commands(s.src)) {
123
- const abs = c.script.startsWith(".claude/")
124
- ? join(ROOT, c.script)
125
- : c.script.startsWith("scripts/")
126
- ? join(SKILLS_DIR, s.name, c.script)
127
- : null;
126
+ const abs = c.script.startsWith(SKILL_DIR_VAR)
127
+ ? join(SKILLS_DIR, s.name, c.script.slice(SKILL_DIR_VAR.length))
128
+ : c.script.startsWith(".claude/")
129
+ ? join(ROOT, c.script)
130
+ : c.script.startsWith("scripts/")
131
+ ? join(SKILLS_DIR, s.name, c.script)
132
+ : null;
128
133
  if (!abs) continue;
129
134
  soft(() =>
130
135
  assert.ok(
@@ -144,8 +149,11 @@ export async function checkSkill(name) {
144
149
  // ═══════════════════════════════════════════════════════════════════════════════════════════════
145
150
  for (const s of skills) {
146
151
  for (const c of commands(s.src)) {
147
- // The pipeline's own scripts; any other command is the consumer's business.
148
- if (!c.script.startsWith(PIPELINE.prefix)) continue;
152
+ // The pipeline's own scripts, by either spelling; any other command is the consumer's business.
153
+ const own =
154
+ c.script.startsWith(PIPELINE.prefix) ||
155
+ c.script.startsWith(SKILL_DIR_VAR);
156
+ if (!own) continue;
149
157
  soft(() =>
150
158
  assert.ok(
151
159
  s.tools.some((t) => permits(t, c.cmd)),
@@ -186,7 +186,7 @@ test("checkSkill reports EVERY finding at once: a renamed skill with no descript
186
186
 
187
187
  test("checkSkill refuses an instructed script that does not exist", async () => {
188
188
  const lines = await brokenBy("verify-citations", (s) =>
189
- s.replaceAll("scripts/extract-ref-facts.mjs", "scripts/missing.mjs"),
189
+ s.replaceAll("scripts/extract-ref-facts.js", "scripts/missing.js"),
190
190
  );
191
191
  assert.equal(
192
192
  lines?.[0],
@@ -194,7 +194,22 @@ test("checkSkill refuses an instructed script that does not exist", async () =>
194
194
  );
195
195
  assert.match(
196
196
  lines?.[1] ?? "",
197
- /instructs `node .*missing\.mjs.*` but .*missing\.mjs does not exist/,
197
+ /instructs `node .*missing\.js.*` but .*missing\.js does not exist/,
198
+ );
199
+ });
200
+
201
+ test("checkSkill resolves a bare scripts/ path from the skill's own directory", async () => {
202
+ const spelled = (path) => (s) =>
203
+ s.replaceAll("${CLAUDE_SKILL_DIR}/scripts/bib-authors.js", path);
204
+ // Guards: a bare path to a script the skill has is accepted.
205
+ assert.equal(
206
+ await brokenBy("verify-citations", spelled("scripts/bib-authors.mjs")),
207
+ null,
208
+ );
209
+ // Guards: a bare path to a script it lacks is refused, once per line that names it.
210
+ assert.deepEqual(
211
+ (await brokenBy("verify-citations", spelled("scripts/missing.js")))?.[0],
212
+ '2 assertion(s) failed for skill "verify-citations":',
198
213
  );
199
214
  });
200
215
 
@@ -209,41 +224,39 @@ test("checkSkill refuses a pipeline script the skill's allowed-tools do not perm
209
224
  .join(", ")}]`,
210
225
  ),
211
226
  );
227
+ // Guards: each of the seven `node ${CLAUDE_SKILL_DIR}/…` lines is named, the first one first.
212
228
  assert.equal(
213
229
  lines?.[0],
214
- '2 assertion(s) failed for skill "verify-citations":',
230
+ '7 assertion(s) failed for skill "verify-citations":',
215
231
  );
216
232
  assert.match(
217
233
  lines?.[1] ?? "",
218
- /extract-ref-facts\.mjs.* permit no such Bash command/,
234
+ /verify-cites\.js.* permit no such Bash command/,
219
235
  );
220
236
  });
221
237
 
222
- test("a Bash entry narrowed to the instructed script permits it, and one narrowed elsewhere does not", async () => {
223
- const narrowTo = (script) => (s) =>
238
+ test("a Bash entry that covers the instructed scripts permits them, and one narrowed to another does not", async () => {
239
+ const narrowTo = (pattern) => (s) =>
224
240
  s.replace(
225
241
  /^allowed-tools: \[(.*)\]$/m,
226
242
  (_, list) =>
227
243
  `allowed-tools: [${list
228
244
  .split(", ")
229
245
  .map((t) =>
230
- t === "Bash"
231
- ? `"Bash(node .claude/skills/paper-pipeline/scripts/${script}:*)"`
232
- : t,
246
+ t === "Bash" ? `"Bash(node \${CLAUDE_SKILL_DIR}/${pattern}:*)"` : t,
233
247
  )
234
248
  .join(", ")}]`,
235
249
  );
236
- assert.equal(
237
- await brokenBy("verify-citations", narrowTo("extract-ref-facts.mjs")),
238
- null,
239
- );
250
+ // Guards: an entry that covers the skill's own scripts permits all seven commands.
251
+ assert.equal(await brokenBy("verify-citations", narrowTo("*")), null);
240
252
  const lines = await brokenBy(
241
253
  "verify-citations",
242
- narrowTo("generated-code.mjs"),
254
+ narrowTo("../paper-pipeline/scripts/extract-ref-facts.js"),
243
255
  );
256
+ // Guards: narrowed to one script, the other five commands (verify-cites.js, bib-authors.js) are named.
244
257
  assert.equal(
245
258
  lines?.[0],
246
- '2 assertion(s) failed for skill "verify-citations":',
259
+ '5 assertion(s) failed for skill "verify-citations":',
247
260
  );
248
261
  assert.match(lines?.[1] ?? "", /permit no such Bash command/);
249
262
  });
@@ -129,11 +129,14 @@ export function permits(entry, cmd) {
129
129
  return rx.test(cmd);
130
130
  }
131
131
 
132
- /** Every `node|bash|python3 <script>` line the SKILL.md instructs, with its full command text. */
132
+ /**
133
+ * Every `node|bash|python3 <script>` line the SKILL.md instructs, with its full command text. The
134
+ * script may start with `${CLAUDE_SKILL_DIR}/`, the skill's own directory wherever it is installed.
135
+ */
133
136
  export function commands(src) {
134
137
  return [
135
138
  ...src.matchAll(
136
- /^\s*(node|bash|python3?) +([A-Za-z0-9_./@-]+\.(?:mjs|js|sh|py))(.*)$/gm,
139
+ /^\s*(node|bash|python3?) +((?:\$\{CLAUDE_SKILL_DIR\}\/)?[A-Za-z0-9_./@-]+\.(?:mjs|js|sh|py))(.*)$/gm,
137
140
  ),
138
141
  ].map((m) => ({
139
142
  runner: m[1],
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "paperlint",
3
- "version": "18.5.0",
3
+ "version": "18.7.0",
4
4
  "description": "A linter for scientific papers written in LaTeX: catches mistakes before you submit to a conference or journal.",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
7
  "scripts": {
8
- "build": "tsc -b",
9
- "prepare": "tsc -b",
8
+ "build": "tsc -b && node scripts/bundle-skills.ts",
9
+ "prepare": "tsc -b && node scripts/bundle-skills.ts",
10
10
  "test": "node scripts/test.ts",
11
11
  "test:e2e": "vitest run --project 'e2e-*'",
12
12
  "test:e2e:install": "vitest run --project e2e-install",
@@ -23,6 +23,7 @@
23
23
  "site:build": "npm ci --prefix site && npm run lint --prefix site && npm run typecheck --prefix site && npm run test --prefix site && npm run build --prefix site"
24
24
  },
25
25
  "dependencies": {
26
+ "@clack/prompts": "1.9.0",
26
27
  "@eslint/markdown": "^8.0.3",
27
28
  "@eslint/plugin-kit": "^0.7.2",
28
29
  "@retorquere/bibtex-parser": "^10.0.1",
@@ -56,6 +57,7 @@
56
57
  "c8": "^12.0.0",
57
58
  "conventional-changelog-conventionalcommits": "9.3.1",
58
59
  "dependency-graph": "^1.0.0",
60
+ "esbuild": "0.28.2",
59
61
  "eslint-import-resolver-typescript": "^4.4.5",
60
62
  "eslint-plugin-boundaries": "^7.2.0",
61
63
  "eslint-plugin-functional": "^10.0.1",
@@ -0,0 +1,226 @@
1
+ /**
2
+ * The bundle step (`scripts/bundle-skills.ts`) on fixture trees of its own: it writes every bundle
3
+ * and nothing else, the bundles keep each module's own `import.meta`, and it refuses before writing
4
+ * anything when a run would overwrite a tracked file or break an entry. Then the real step on this
5
+ * checkout, as `npm run build` runs it.
6
+ */
7
+ import { execFileSync } from "node:child_process";
8
+ import { readdirSync, readFileSync, statSync, writeFileSync } from "node:fs";
9
+ import { dirname, join, relative } from "node:path";
10
+ import { fileURLToPath, pathToFileURL } from "node:url";
11
+ import { describe, expect, it } from "vitest";
12
+ import { runNode, useTempDir, writeTree } from "../test/support.ts";
13
+ import {
14
+ bundleSkills,
15
+ CHUNK_DIR,
16
+ gitTracked,
17
+ SKILL_ENTRIES,
18
+ type BundlePlan,
19
+ } from "./bundle-skills.ts";
20
+
21
+ const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
22
+
23
+ /** Every file under `root`, relative, with its contents. */
24
+ function snapshot(root: string): Readonly<Record<string, string>> {
25
+ const walk = (dir: string): readonly string[] =>
26
+ readdirSync(dir).flatMap((name) => {
27
+ const p = join(dir, name);
28
+ return statSync(p).isDirectory() ? walk(p) : [p];
29
+ });
30
+ return Object.fromEntries(
31
+ walk(root).map((p) => [relative(root, p), readFileSync(p, "utf8")]),
32
+ );
33
+ }
34
+
35
+ /** What changed between two snapshots. */
36
+ function delta(
37
+ before: Readonly<Record<string, string>>,
38
+ after: Readonly<Record<string, string>>,
39
+ ): { added: string[]; removed: string[]; changed: string[] } {
40
+ const keys = (o: object): string[] => Object.keys(o).sort();
41
+ return {
42
+ added: keys(after).filter((k) => !(k in before)),
43
+ removed: keys(before).filter((k) => !(k in after)),
44
+ changed: keys(after).filter((k) => k in before && before[k] !== after[k]),
45
+ };
46
+ }
47
+
48
+ /** A module that reports where it thinks it is. */
49
+ const WHERE = `export const where = { url: import.meta.url, dirname: import.meta.dirname, filename: import.meta.filename };\n`;
50
+
51
+ /** A module with a main guard of its own, the shape of `isMain(import.meta.url)`. */
52
+ const GUARDED = `import { pathToFileURL } from "node:url";
53
+ if (import.meta.url === pathToFileURL(process.argv[1]).href) console.log("guarded main ran");
54
+ `;
55
+
56
+ /** Two entries sharing `lib/where.mjs`; the first also imports a guarded module. */
57
+ function fixture(extra: Readonly<Record<string, string>> = {}): string {
58
+ return writeTree(useTempDir("paperlint-bundle-"), {
59
+ "package.json": `{ "type": "module" }\n`,
60
+ "app/one/main.ts": `import { where } from "../../lib/where.mjs";\nimport "../../lib/guarded.mjs";\nconst n: string = "one";\nconsole.log(JSON.stringify({ entry: n, ...where }));\n`,
61
+ "app/two/main.mjs": `import { where } from "../../lib/where.mjs";\nconsole.log(JSON.stringify({ entry: "two", ...where }));\n`,
62
+ "lib/where.mjs": WHERE,
63
+ "lib/guarded.mjs": GUARDED,
64
+ "out/chunks/stale.js": "stale\n",
65
+ ...extra,
66
+ });
67
+ }
68
+
69
+ const plan = (root: string, over: Partial<BundlePlan> = {}): BundlePlan => ({
70
+ root,
71
+ entries: ["app/one/main.ts", "app/two/main.mjs"],
72
+ chunkDir: "out/chunks",
73
+ tracked: () => [],
74
+ ...over,
75
+ });
76
+
77
+ /** What `lib/where.mjs` must report about itself, wherever its code was bundled. */
78
+ const whereOf = (root: string, entry: string): Record<string, string> => ({
79
+ entry,
80
+ url: pathToFileURL(join(root, "lib", "where.mjs")).href,
81
+ dirname: join(root, "lib"),
82
+ filename: join(root, "lib", "where.mjs"),
83
+ });
84
+
85
+ describe("bundleSkills writes", () => {
86
+ it("writes every entry's bundle beside its source and the shared chunks, and nothing else", async () => {
87
+ const root = fixture();
88
+ const before = snapshot(root);
89
+ const written = await bundleSkills(plan(root));
90
+ // Guards: the run's own report and the disk agree, the stale chunk is gone, no file was edited.
91
+ expect(delta(before, snapshot(root))).toEqual({
92
+ added: written,
93
+ removed: ["out/chunks/stale.js"],
94
+ changed: [],
95
+ });
96
+ // Guards: each entry's bundle sits beside its source as `.js`; every other output is a chunk.
97
+ expect({
98
+ entries: written.filter((p) => !p.startsWith("out/chunks/")),
99
+ chunks: written.filter((p) => p.startsWith("out/chunks/")).length > 0,
100
+ }).toEqual({
101
+ entries: ["app/one/main.js", "app/two/main.js"],
102
+ chunks: true,
103
+ });
104
+ });
105
+
106
+ it("runs only the entry's own main, and each module keeps its own location", async () => {
107
+ const root = fixture();
108
+ await bundleSkills(plan(root));
109
+ const run = (entry: string) =>
110
+ runNode(join(root, entry), [], { cwd: root });
111
+ // Guards: the guarded module's main did not run, and `where` names its own source, not the bundle.
112
+ expect([run("app/one/main.js"), run("app/two/main.js")]).toEqual([
113
+ {
114
+ status: 0,
115
+ stdout: `${JSON.stringify(whereOf(root, "one"))}\n`,
116
+ stderr: "",
117
+ },
118
+ {
119
+ status: 0,
120
+ stdout: `${JSON.stringify(whereOf(root, "two"))}\n`,
121
+ stderr: "",
122
+ },
123
+ ]);
124
+ });
125
+
126
+ it("keeps a module's location in a bundle written at the root itself", async () => {
127
+ const root = fixture({
128
+ "top.mjs": `import { where } from "./lib/where.mjs";\nconsole.log(JSON.stringify({ entry: "top", ...where }));\n`,
129
+ });
130
+ await bundleSkills(plan(root, { entries: ["top.mjs"] }));
131
+ // Guards: from a bundle in the root folder, `where` still names lib/where.mjs.
132
+ expect(runNode(join(root, "top.js"), [], { cwd: root })).toEqual({
133
+ status: 0,
134
+ stdout: `${JSON.stringify(whereOf(root, "top"))}\n`,
135
+ stderr: "",
136
+ });
137
+ });
138
+ });
139
+
140
+ describe("bundleSkills refuses", () => {
141
+ it("writing nothing, when an output is a tracked file", async () => {
142
+ const root = fixture();
143
+ const before = snapshot(root);
144
+ const tracked = (_: string, paths: readonly string[]): readonly string[] =>
145
+ paths.filter((p) => p === "app/one/main.js");
146
+ // Guards: the refusal names the tracked path, and the tree is byte-identical afterwards.
147
+ await expect(bundleSkills(plan(root, { tracked }))).rejects.toThrow(
148
+ "bundle-skills: refused\n app/one/main.js is tracked by git: a bundle must not overwrite it",
149
+ );
150
+ expect(snapshot(root)).toEqual(before);
151
+ });
152
+
153
+ it("an entry that another bundled module imports", async () => {
154
+ const root = fixture();
155
+ // Guards: an entry whose code would move into a chunk is named, not bundled.
156
+ await expect(
157
+ bundleSkills(
158
+ plan(root, { entries: ["app/one/main.ts", "lib/where.mjs"] }),
159
+ ),
160
+ ).rejects.toThrow(
161
+ "bundle-skills: refused\n lib/where.mjs is an entry and is imported by another bundled module: its code would leave its own file",
162
+ );
163
+ });
164
+
165
+ it.each([
166
+ [
167
+ "import.meta.resolve",
168
+ `export const where = { r: import.meta.resolve("./x.mjs") };\n`,
169
+ "import.meta.resolve",
170
+ ],
171
+ [
172
+ "a bare import.meta",
173
+ `export const where = { m: import.meta };\n`,
174
+ "import.meta",
175
+ ],
176
+ ])("%s in a module that is not the entry", async (_, source, named) => {
177
+ const root = fixture({ "lib/where.mjs": source });
178
+ // Guards: a use of import.meta the step cannot keep correct is refused with the module's path.
179
+ await expect(bundleSkills(plan(root))).rejects.toThrow(
180
+ `lib/where.mjs: ${named} cannot be kept correct inside a bundle`,
181
+ );
182
+ });
183
+ });
184
+
185
+ describe("gitTracked", () => {
186
+ it("names the tracked paths of those asked, and none outside a checkout", () => {
187
+ // Guards: a tracked file is reported, an absent one is not.
188
+ expect(gitTracked(ROOT, ["package.json", "no-such-file.js"])).toEqual([
189
+ "package.json",
190
+ ]);
191
+ // Guards: a source archive or a git-dependency install has no `.git`, and npm runs
192
+ // `prepare` there; with no checkout no output can overwrite a tracked file.
193
+ const bare = useTempDir("paperlint-nogit-");
194
+ writeFileSync(join(bare, "x"), "");
195
+ expect(gitTracked(bare, ["x"])).toEqual([]);
196
+ });
197
+ });
198
+
199
+ describe("npm run build's bundle step, on this checkout", () => {
200
+ it("writes every skill entry's bundle and touches no tracked file", () => {
201
+ const status = (): string =>
202
+ execFileSync("git", ["status", "--porcelain", "--untracked-files=no"], {
203
+ cwd: ROOT,
204
+ encoding: "utf8",
205
+ });
206
+ const before = status();
207
+ const r = runNode(join(ROOT, "scripts", "bundle-skills.ts"));
208
+ const listed = r.stderr
209
+ .split("\n")
210
+ .slice(1)
211
+ .map((l) => l.trim())
212
+ .filter(Boolean);
213
+ const bundles = SKILL_ENTRIES.map((e) => e.replace(/\.(ts|mjs)$/, ".js"));
214
+ // Guards: the step succeeded, kept stdout empty (npm pack --json), and wrote every entry's bundle.
215
+ expect({
216
+ status: r.status,
217
+ stdout: r.stdout,
218
+ bundles: bundles.filter((b) => listed.includes(b)),
219
+ others: listed.filter(
220
+ (p) => !bundles.includes(p) && !p.startsWith(`${CHUNK_DIR}/`),
221
+ ),
222
+ }).toEqual({ status: 0, stdout: "", bundles, others: [] });
223
+ // Guards: no tracked file changed.
224
+ expect(status()).toBe(before);
225
+ });
226
+ });