@roomi-fields/grillhouse 0.53.0 → 0.54.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +54 -0
  3. package/cadre/templates/projet/docs/agents/issue-tracker.md +2 -2
  4. package/charte.md +12 -0
  5. package/dist/temporal/circuit/deroule.js +5 -9
  6. package/dist/temporal/circuit/deroule.js.map +1 -1
  7. package/dist/temporal/installation.d.ts +15 -2
  8. package/dist/temporal/installation.js +69 -17
  9. package/dist/temporal/installation.js.map +1 -1
  10. package/docs/INTERFACE.md +21 -1
  11. package/docs/architecture/circuit.md +3 -3
  12. package/docs/architecture/entree.md +4 -4
  13. package/docs/architecture/greffon.md +28 -17
  14. package/docs/architecture/installation.md +21 -11
  15. package/docs/architecture/machine.md +1 -1
  16. package/docs/architecture/tests.md +1 -1
  17. package/hooks/register.tsx +50 -24
  18. package/package.json +1 -1
  19. package/scripts/aiguillage.mjs +4 -2
  20. package/scripts/bd-garde.mjs +69 -0
  21. package/scripts/ci-de-main.mjs +259 -56
  22. package/scripts/circuit.mjs +20 -5
  23. package/scripts/commandes-composees.mjs +1 -1
  24. package/scripts/droits.mjs +11 -4
  25. package/scripts/file-des-tickets.mjs +27 -9
  26. package/scripts/greffons.mjs +282 -17
  27. package/scripts/langages/c/commandes.mjs +1 -1
  28. package/scripts/langages/cargo/commandes.mjs +1 -1
  29. package/scripts/langages/cargo/tailles-des-tests.mjs +115 -6
  30. package/scripts/langages/python/commandes.mjs +1 -1
  31. package/scripts/langages/typescript/code-mort.mjs +36 -3
  32. package/scripts/langages/typescript/migrations/configurations-en-commonjs.mjs +95 -24
  33. package/scripts/langages/typescript/mise-a-jour.mjs +49 -12
  34. package/scripts/langages/typescript/parcours.mjs +5 -1
  35. package/scripts/langages.d.mts +6 -0
  36. package/scripts/langages.mjs +6 -0
  37. package/scripts/lire.mjs +236 -0
  38. package/scripts/migrations/cout-des-jetons-au-registre.mjs +136 -0
  39. package/scripts/migrations/lire-un-ticket.mjs +46 -0
  40. package/scripts/migrations.mjs +4 -0
  41. package/scripts/montee.mjs +123 -47
  42. package/scripts/nuit.sh +21 -12
  43. package/scripts/registre.d.mts +7 -1
  44. package/scripts/registre.mjs +114 -102
  45. package/scripts/resultats.mjs +15 -5
  46. package/scripts/retirer-copie.sh +7 -0
  47. package/scripts/sous-commandes.mjs +1 -0
  48. package/scripts/suiveur.mjs +12 -4
  49. package/scripts/superviseur.mjs +111 -31
  50. package/scripts/tableau.mjs +527 -119
  51. package/scripts/tarifs.mjs +67 -0
  52. package/scripts/ticket-du-circuit.mjs +3 -4
  53. package/scripts/transitions.d.mts +0 -5
  54. package/scripts/transitions.mjs +3 -13
  55. package/scripts/verdict-de-la-nuit.mjs +2 -2
  56. package/skills/explorateur/SKILL.md +10 -5
  57. package/skills/mesure/SKILL.md +4 -3
  58. package/skills/pitmaster/SKILL.md +18 -4
  59. package/skills/pitmaster/references/erreurs.md +4 -2
  60. package/skills/pitmaster/references/tour.md +11 -4
  61. package/types/index.d.ts +3 -1
  62. package/scripts/base-des-workflows.mjs +0 -58
@@ -5,8 +5,12 @@
5
5
  //
6
6
  // - Converted: a refused `vitest.config.*` made of static imports, plain statements and one
7
7
  // `export default`, that no file reads by its name, becomes the `vitest.config.cjs` of its
8
- // directory, its imports by `await import()` and its default export the value of the promise it
9
- // exports; the former file is removed. Its types are stripped by Node.
8
+ // directory, its default export the value of the promise it exports; the former file is removed.
9
+ // Its types are stripped by Node.
10
+ // - Its imports: a relative import whose file is TypeScript (`.ts`, `.mts`, `.cts`, `.tsx`) by
11
+ // `require()` of that file under its real name, any other by `await import()`. Before its
12
+ // `require()` calls, a resolution hook (`registerHooks`) resolves to its `.ts` a relative `.js`
13
+ // import no file answers, as TypeScript writes it: knip loads the configuration so.
10
14
  // - Left intact, each named with its reason and the way out, then inscribed in the guard's debt,
11
15
  // frozen: a configuration another file reads by its name (an import or a require, a path in the
12
16
  // code, a script of a package.json or a shell script, a flow, `files` or a literal `include`
@@ -15,15 +19,17 @@
15
19
  // Node cannot strip, a directory with a `vitest.config.cjs` already or several refused
16
20
  // configurations, and every refused file not named `vitest.config.*` (an ESM `vite.config`, a
17
21
  // configuration `--config` names). The migration writes no reader.
22
+ // - Its readers: Vite's temporary files are not read, a file gone between the listing and its
23
+ // read names none, and any other fault of a read stops the migration.
18
24
  // - Replayable without effect: a configuration the debt holds is left, and nothing is returned.
19
- import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
25
+ import { existsSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
20
26
  import { createRequire, stripTypeScriptTypes } from 'node:module';
21
27
  import path from 'node:path';
22
28
  import { FICHIER, lire, trancher } from '../../../dette.mjs';
23
29
  import { paquets } from '../../../paquets.mjs';
24
30
  import { sources } from '../../../services-du-noyau.mjs';
25
31
  import { configurationsRefusees, GARDE } from '../configurations-de-vitest.mjs';
26
- import { parcourir } from '../parcours.mjs';
32
+ import { estTemporaireDeVite, lireSiPresent, parcourir } from '../parcours.mjs';
27
33
 
28
34
  export const version = '0.53.0';
29
35
  export const nom = 'configurations en commonjs';
@@ -32,6 +38,28 @@ const CONFIGURATION = /^vitest\.config\.(?:[mc]?ts|m?js)$/;
32
38
  // The directories no reader of a configuration lives in.
33
39
  const HORS = new Set(['node_modules', '.git', 'dist', 'coverage', '.claude', '.turbo']);
34
40
  const MOTIF = /[*?{}[\]]/;
41
+ const TYPESCRIPT = /\.(?:[mc]?ts|tsx)$/;
42
+ // The TypeScript files an import written in JavaScript names.
43
+ const SOURCES = { '.js': ['.ts', '.tsx'], '.jsx': ['.tsx'], '.mjs': ['.mts'], '.cjs': ['.cts'] };
44
+ // The extensions an import may leave out, in the order Vite tries them.
45
+ const OMISES = ['.mjs', '.js', '.mts', '.ts', '.jsx', '.tsx', '.json'];
46
+ // Resolves a relative `.js` import no file answers to its `.ts`.
47
+ const CROCHET = `require('node:module').registerHooks({
48
+ resolve(specifier, context, nextResolve) {
49
+ try {
50
+ return nextResolve(specifier, context);
51
+ } catch (erreur) {
52
+ if (!/^\\.\\.?\\/.*\\.js$/.test(specifier)) {
53
+ throw erreur;
54
+ }
55
+ try {
56
+ return nextResolve(specifier.replace(/js$/, 'ts'), context);
57
+ } catch {
58
+ throw erreur;
59
+ }
60
+ }
61
+ },
62
+ });`;
35
63
  // The files that name paths without being code (cheminsNommes).
36
64
  const ENUMERE =
37
65
  /(?:^|\/)(?:package\.json|tsconfig[^/]*\.json|vitest\.workspace\.json)$|^(?:\.github\/.*\.ya?ml|\.gitlab-ci\.yml)$|\.sh$/;
@@ -57,7 +85,7 @@ function chaines(ts, f, texte) {
57
85
  }
58
86
 
59
87
  // The paths, from the root, that the file `f` names: each `{ chemin, module }`, `module` when an
60
- // import can name it without its extension.
88
+ // import can name it without its extension. A file gone since it was listed names none.
61
89
  function cheminsNommes(ts, projet, f, espaces) {
62
90
  const nomDuFichier = path.posix.basename(f);
63
91
  const ici = path.posix.dirname(f);
@@ -67,12 +95,15 @@ function cheminsNommes(ts, projet, f, espaces) {
67
95
  .split(SEPARATEURS)
68
96
  .filter(m => m && !MOTIF.test(m))
69
97
  .flatMap(m => bases.map(b => ({ chemin: joindre(b, m) })));
70
- const lu = () => readFileSync(path.join(projet, f), 'utf8');
98
+ const lu = lireSiPresent(path.join(projet, f));
99
+ if (lu === null) {
100
+ return [];
101
+ }
71
102
  if (nomDuFichier === 'package.json') {
72
103
  // A manifest that is not JSON (a fixture) names no script.
73
104
  let scripts;
74
105
  try {
75
- scripts = Object.values(JSON.parse(lu()).scripts ?? {});
106
+ scripts = Object.values(JSON.parse(lu).scripts ?? {});
76
107
  } catch {
77
108
  return [];
78
109
  }
@@ -82,20 +113,20 @@ function cheminsNommes(ts, projet, f, espaces) {
82
113
  });
83
114
  }
84
115
  if (/^tsconfig.*\.json$/.test(nomDuFichier)) {
85
- const { config } = ts.parseConfigFileTextToJson(f, lu());
116
+ const { config } = ts.parseConfigFileTextToJson(f, lu);
86
117
  return [...(config?.files ?? []), ...(config?.include ?? [])]
87
118
  .filter(m => typeof m === 'string' && !MOTIF.test(m))
88
119
  .map(m => ({ chemin: joindre(ici, m) }));
89
120
  }
90
121
  if (/^vitest\.workspace\.json$/.test(nomDuFichier)) {
91
- return mots(lu(), [ici]);
122
+ return mots(lu, [ici]);
92
123
  }
93
124
  if (/^(\.github\/.*\.ya?ml|\.gitlab-ci\.yml)$/.test(f) || f.endsWith('.sh')) {
94
- const texte = lu().replace(/(^|\s)#.*$/gm, '$1');
125
+ const texte = lu.replace(/(^|\s)#.*$/gm, '$1');
95
126
  const dossiers = [...texte.matchAll(/working-directory:\s*["']?([^\s"']+)/g)].map(m => m[1]);
96
127
  return mots(texte, ['.', ici, ...dossiers]);
97
128
  }
98
- return chaines(ts, f, lu()).flatMap(m => {
129
+ return chaines(ts, f, lu).flatMap(m => {
99
130
  if (!m || MOTIF.test(m) || /\s/.test(m)) {
100
131
  return [];
101
132
  }
@@ -118,7 +149,8 @@ function lecteursDe(ts, projet, cibles) {
118
149
  const autres = parcourir(projet, p => HORS.has(path.basename(p)))
119
150
  .map(p => posix(path.relative(projet, p)))
120
151
  .filter(f => ENUMERE.test(f));
121
- for (const f of [...new Set([...sources(projet), ...autres])].sort()) {
152
+ const code = sources(projet).filter(f => !estTemporaireDeVite(f));
153
+ for (const f of [...new Set([...code, ...autres])].sort()) {
122
154
  const nommes = cheminsNommes(ts, projet, f, espaces);
123
155
  for (const c of cibles) {
124
156
  const lit = nommes.some(
@@ -136,12 +168,46 @@ function lecteursDe(ts, projet, cibles) {
136
168
  return out;
137
169
  }
138
170
 
139
- // The declaration of the names an import binds, by `await import()`.
140
- function importation(ts, n) {
141
- const attributs = n.attributes
142
- ? `, { with: { ${n.attributes.elements.map(e => e.getText()).join(', ')} } }`
143
- : '';
144
- const appel = `await import(${n.moduleSpecifier.getText()}${attributs})`;
171
+ // The real name, from `dossier`, of the TypeScript file the relative import `specifier` reads, or
172
+ // null when it reads anything else, or no file.
173
+ function sourceTypeScript(dossier, specifier) {
174
+ if (!/^\.\.?\//.test(specifier)) {
175
+ return null;
176
+ }
177
+ const vise = path.resolve(dossier, specifier);
178
+ const extension = path.extname(vise);
179
+ const lu = [
180
+ vise,
181
+ ...(SOURCES[extension] ?? []).map(e => vise.slice(0, -extension.length) + e),
182
+ ...OMISES.map(e => vise + e),
183
+ ...OMISES.map(e => path.join(vise, `index${e}`)),
184
+ ].find(f => statSync(f, { throwIfNoEntry: false })?.isFile());
185
+ if (!lu || !TYPESCRIPT.test(lu)) {
186
+ return null;
187
+ }
188
+ const relatif = posix(path.relative(dossier, lu));
189
+ return relatif.startsWith('../') ? relatif : `./${relatif}`;
190
+ }
191
+
192
+ // The call that reads the module an import of a file of `dossier` names.
193
+ function lecture(n, dossier) {
194
+ const reel = sourceTypeScript(dossier, n.moduleSpecifier.text);
195
+ if (reel === null) {
196
+ const attributs = n.attributes
197
+ ? `, { with: { ${n.attributes.elements.map(e => e.getText()).join(', ')} } }`
198
+ : '';
199
+ return { appel: `await import(${n.moduleSpecifier.getText()}${attributs})`, requis: false };
200
+ }
201
+ const appel = `require(${JSON.stringify(reel).replaceAll('"', "'")})`;
202
+ // A `.cts` is CommonJS: its default import is its `module.exports`, as `import()` gives it.
203
+ return {
204
+ appel: reel.endsWith('.cts') ? `{ ...${appel}, default: ${appel} }` : appel,
205
+ requis: true,
206
+ };
207
+ }
208
+
209
+ // The declaration of the names the import `n` binds to what `appel` reads.
210
+ function importation(ts, n, appel) {
145
211
  const { name: defaut, namedBindings: liaisons } = n.importClause ?? {};
146
212
  if (liaisons && ts.isNamespaceImport(liaisons)) {
147
213
  const espace = `const ${liaisons.name.text} = ${appel};`;
@@ -156,9 +222,9 @@ function importation(ts, n) {
156
222
  return noms.length ? `const { ${noms.join(', ')} } = ${appel};` : `${appel};`;
157
223
  }
158
224
 
159
- // The CommonJS form of the ESM configuration `source` of the file `f`, or null when it holds
160
- // more than static imports, plain statements and one default export.
161
- function enCommonJs(ts, f, source) {
225
+ // The CommonJS form of the ESM configuration `source` of the file `f` of `dossier`, or null when
226
+ // it holds more than static imports, plain statements and one default export.
227
+ function enCommonJs(ts, dossier, f, source) {
162
228
  let texte = source;
163
229
  if (/ts$/.test(f)) {
164
230
  try {
@@ -182,6 +248,7 @@ function enCommonJs(ts, f, source) {
182
248
  };
183
249
  visiter(arbre);
184
250
  const imports = [];
251
+ let requis = false;
185
252
  const retouches = [];
186
253
  let defauts = 0;
187
254
  let valeur = 'configurationParDefaut';
@@ -190,7 +257,9 @@ function enCommonJs(ts, f, source) {
190
257
  const exporte = modificateurs.find(m => m.kind === ts.SyntaxKind.ExportKeyword);
191
258
  const defaut = modificateurs.find(m => m.kind === ts.SyntaxKind.DefaultKeyword);
192
259
  if (ts.isImportDeclaration(n)) {
193
- imports.push(importation(ts, n));
260
+ const lu = lecture(n, dossier);
261
+ requis ||= lu.requis;
262
+ imports.push(importation(ts, n, lu.appel));
194
263
  retouches.push([n.getStart(), n.end, '']);
195
264
  } else if (ts.isExportAssignment(n) && !n.isExportEquals) {
196
265
  defauts += 1;
@@ -225,6 +294,7 @@ function enCommonJs(ts, f, source) {
225
294
  }
226
295
  corps += indenter(depuis, texte.length);
227
296
  const lignes = [
297
+ ...(requis ? CROCHET.split('\n').map(l => ` ${l}`) : []),
228
298
  ...imports.flatMap(i => i.split('\n')).map(l => ` ${l}`),
229
299
  '',
230
300
  ` ${corps.trim()}`,
@@ -267,7 +337,8 @@ export function migrer(projet) {
267
337
  ) {
268
338
  raisons.set(fichier, 'plusieurs configurations de Vitest dans son dossier');
269
339
  } else {
270
- const neuf = enCommonJs(ts, fichier, readFileSync(path.join(projet, fichier), 'utf8'));
340
+ const source = readFileSync(path.join(projet, fichier), 'utf8');
341
+ const neuf = enCommonJs(ts, path.join(projet, dossier), fichier, source);
271
342
  if (neuf === null) {
272
343
  raisons.set(
273
344
  fichier,
@@ -291,7 +362,7 @@ export function migrer(projet) {
291
362
  for (const [fichier, raison] of raisons) {
292
363
  const cjs = path.posix.join(path.posix.dirname(fichier), 'vitest.config.cjs');
293
364
  lignes.push(
294
- `${fichier} : laissée, ${raison} ; elle peut échouer en EROFS quand son paquet est hors du plan. Pour la convertir : écris ${cjs} (\`module.exports = (async () => { … })();\`, chaque import par \`await import()\`), et fais-le nommer par ses lecteurs. Inscrite dans ${FICHIER} (${GARDE}), gelée : une neuve est refusée`
365
+ `${fichier} : laissée, ${raison} ; elle peut échouer en EROFS quand son paquet est hors du plan. Pour la convertir : écris ${cjs} (\`module.exports = (async () => { … })();\`, un fichier TypeScript relatif par \`require()\` sous son nom réel, après un crochet \`registerHooks\` de \`node:module\` quand ses voisins se nomment en \`.js\`, tout autre import par \`await import()\`), et fais-le nommer par ses lecteurs. Inscrite dans ${FICHIER} (${GARDE}), gelée : une neuve est refusée`
295
366
  );
296
367
  }
297
368
  }
@@ -29,16 +29,18 @@
29
29
  // - A package of the frame whose code imports the frame's package (a file of its `src/` out of the
30
30
  // tests, its imports read by TypeScript's `preProcessFile`) declares it in its `dependencies`, as
31
31
  // npm puts there what the published code imports: a declaration in its `devDependencies` moves
32
- // there with its range, else the range the root declares (else `^<version>`).
32
+ // there with its range, else the range the root declares (else `^<version>`). The frame's package
33
+ // declares itself nowhere.
33
34
  // - The frame's base configuration of Vitest is the package's (`@roomi-fields/grillhouse/vitest-config`),
34
35
  // which each Vitest configuration imports by its name: in a project with `workspaces`, each
35
- // package of the frame that plays tests (`joueDesTests`: its script `test:unit`) declares the
36
- // frame's package in its `devDependencies`, at the range the root declares (else `^<version>`),
36
+ // package of the frame that plays tests (`joueDesTests`: its script `test:unit`) by Vitest (that
37
+ // script calls `vitest`, or the package holds a `vitest.config.*`), the frame's own left out,
38
+ // declares the frame's package in its `devDependencies`, at the range the root declares (else `^<version>`),
37
39
  // a declaration it holds kept (at its range, brought up as above). The update writes no Vitest configuration.
38
40
  // - The typing: each package of TypeScript (a `tsconfig.json`) that has no `typecheck` script
39
41
  // receives the template's, `tsc -p tsconfig.json --noEmit`: each package of the frame in a
40
42
  // project with `workspaces` (the root's `typecheck` stays the project's), the root in a project
41
- // without.
43
+ // without. A `tsconfig.json` that extends a relative file the copy does not hold receives none.
42
44
  // - `turbo.json` is the project's own file. A project with no `turbo.json` receives the frame's
43
45
  // template of its form: `templates/turbo/paquets.json` when its package.json declares
44
46
  // `workspaces`, else `templates/turbo/sans-paquets.json`. A `turbo.json` present is never written
@@ -46,7 +48,7 @@
46
48
  // - The generators: the boundaries' configuration (`.dependency-cruiser.cjs`), the index of the
47
49
  // interfaces, and the turbo.json of each package in a repository with `workspaces`.
48
50
  import { spawnSync } from 'node:child_process';
49
- import { existsSync, readFileSync, writeFileSync } from 'node:fs';
51
+ import { existsSync, readFileSync, statSync, writeFileSync } from 'node:fs';
50
52
  import { createRequire } from 'node:module';
51
53
  import path from 'node:path';
52
54
  import { CODE, paquets, TYPAGE } from '../../paquets.mjs';
@@ -59,6 +61,9 @@ const CONFIG_VITEST = `${PAQUET_DU_CADRE}/vitest-config`;
59
61
  // The root scripts of the tests, written together from the template.
60
62
  const SCRIPTS_DES_TESTS = ['test', SCRIPT_DES_TESTS, 'test:forcer', 'verifier'];
61
63
  const CHAMPS_INSTALLES = ['dependencies', 'devDependencies', 'optionalDependencies'];
64
+ const CONFIGURATIONS_DE_VITEST = ['ts', 'mts', 'cts', 'js', 'mjs', 'cjs'].map(
65
+ e => `vitest.config.${e}`
66
+ );
62
67
  // The frame's templates of `turbo.json`, one per form of repository, read in the source.
63
68
  const TURBO = {
64
69
  fichier: 'turbo.json',
@@ -198,7 +203,8 @@ function declarerDependanceDuCadre(projet, p, version) {
198
203
  const declare = ['dependencies', 'optionalDependencies'].some(
199
204
  c => pkg[c]?.[PAQUET_DU_CADRE] !== undefined
200
205
  );
201
- if (hors || declare || !codeImporteLeCadre(projet, dossier)) {
206
+ const soi = pkg.name === PAQUET_DU_CADRE;
207
+ if (hors || soi || declare || !codeImporteLeCadre(projet, dossier)) {
202
208
  continue;
203
209
  }
204
210
  const { [PAQUET_DU_CADRE]: dev, ...autres } = pkg.devDependencies ?? {};
@@ -215,9 +221,15 @@ function declarerDependanceDuCadre(projet, p, version) {
215
221
  return declarants.length > 0 ? { nom: PAQUET_DU_CADRE, paquets: declarants } : null;
216
222
  }
217
223
 
224
+ // Whether the tests of the package.json <pkg>, read at <dossier>, run by Vitest: its `test:unit`
225
+ // calls it, or the directory holds a configuration of it.
226
+ const testeParVitest = (dossier, pkg) =>
227
+ /\bvitest\b/.test(pkg.scripts?.[SCRIPT_DES_TESTS] ?? '') ||
228
+ CONFIGURATIONS_DE_VITEST.some(f => existsSync(path.join(dossier, f)));
229
+
218
230
  // Declares the frame's package, whose base configuration of Vitest each Vitest configuration
219
- // imports, in the devDependencies of each package of the frame that plays tests (see the header):
220
- // { nom, paquets }, or null when nothing changes.
231
+ // imports, in the devDependencies of each package of the frame that plays its tests by Vitest (see
232
+ // the header): { nom, paquets }, or null when nothing changes.
221
233
  function poserConfigVitest(projet, p, version, joueDesTests) {
222
234
  if (p.workspaces === undefined) {
223
235
  return null;
@@ -225,6 +237,8 @@ function poserConfigVitest(projet, p, version, joueDesTests) {
225
237
  const testes = paquets(projet).filter(
226
238
  ({ dossier, pkg, hors }) =>
227
239
  !hors &&
240
+ pkg.name !== PAQUET_DU_CADRE &&
241
+ testeParVitest(path.join(projet, dossier), pkg) &&
228
242
  joueDesTests(projet, {
229
243
  dossier: path.join(projet, dossier),
230
244
  nom: path.basename(dossier),
@@ -247,13 +261,34 @@ function poserConfigVitest(projet, p, version, joueDesTests) {
247
261
  return declarants.length > 0 ? { nom: PAQUET_DU_CADRE, paquets: declarants } : null;
248
262
  }
249
263
 
264
+ const estUnFichier = f => statSync(f, { throwIfNoEntry: false })?.isFile() === true;
265
+
266
+ // Whether each relative file the tsconfig.json at <fichier> extends is there, as TypeScript resolves
267
+ // it (the path, else the path with `.json`); a base named by a package counts as there. Read by
268
+ // TypeScript, which accepts comments.
269
+ function basesPresentes(fichier) {
270
+ const texte = readFileSync(fichier, 'utf8');
271
+ if (!texte.includes('"extends"')) {
272
+ return true;
273
+ }
274
+ const ts = createRequire(import.meta.url)('typescript');
275
+ const bases = [ts.parseConfigFileTextToJson(fichier, texte).config?.extends ?? []].flat();
276
+ return bases
277
+ .filter(b => typeof b === 'string' && (b.startsWith('.') || path.isAbsolute(b)))
278
+ .map(b => path.resolve(path.dirname(fichier), b))
279
+ .every(b => estUnFichier(b) || estUnFichier(`${b}.json`));
280
+ }
281
+
250
282
  // Gives the typing script of the template, <script>, to each package of TypeScript that has none
251
283
  // (see the header): { script, paquets } (`.` for the root), or null when nothing changes.
252
284
  function poserTypage(projet, p, script) {
253
285
  if (typeof script !== 'string') {
254
286
  return null;
255
287
  }
256
- const types = dossier => existsSync(path.join(projet, dossier, 'tsconfig.json'));
288
+ const types = dossier => {
289
+ const f = path.join(projet, dossier, 'tsconfig.json');
290
+ return existsSync(f) && basesPresentes(f);
291
+ };
257
292
  const sans = pkg => typeof pkg.scripts?.[TYPAGE] !== 'string';
258
293
  const declarants = [];
259
294
  if (p.workspaces === undefined) {
@@ -333,6 +368,10 @@ function appliquer(projet, { p, modele, source, version }, joueDesTests) {
333
368
  typage: poserTypage(projet, p, modele.scripts?.[TYPAGE]),
334
369
  turbo: poserLeGabaritAbsent(projet, source, p, TURBO),
335
370
  };
371
+ const sansVerifier = () =>
372
+ bilan.vitest
373
+ ? 'La ligne « Vitest : » ci-dessus dit pourquoi : installe à la racine le Vitest que le cadre exige, puis relance `npx grillhouse maj`, qui écrit le script.'
374
+ : 'La mise à jour l’écrit dans un projet testé par Vitest ; sinon, écris-le pour ses tests.';
336
375
  return {
337
376
  bilan,
338
377
  lignes: rapport(bilan),
@@ -341,9 +380,7 @@ function appliquer(projet, { p, modele, source, version }, joueDesTests) {
341
380
  bilan.plageDuCadre !== null ||
342
381
  bilan.configVitest !== null ||
343
382
  bilan.dependanceDuCadre !== null,
344
- sansVerifier: bilan.vitest
345
- ? 'La ligne « Vitest : » ci-dessus dit pourquoi : installe à la racine le Vitest que le cadre exige, puis relance `npx grillhouse maj`, qui écrit le script.'
346
- : 'La mise à jour l’écrit dans un projet testé par Vitest ; sinon, écris-le pour ses tests.',
383
+ sansVerifier: typeof p.scripts.verifier === 'string' ? null : sansVerifier(),
347
384
  };
348
385
  }
349
386
 
@@ -23,6 +23,10 @@ function siPresent(lire, f, absent) {
23
23
  }
24
24
  }
25
25
 
26
+ /** Whether the path <f> is one of Vite's temporary files, for a listing `parcourir` did not
27
+ * make. */
28
+ export const estTemporaireDeVite = f => TEMPORAIRE_DE_VITE.test(f);
29
+
26
30
  /**
27
31
  * The files under <chemin> (a directory, or a file), each its absolute path: an entry below it
28
32
  * whose path <sauter> keeps out is neither entered nor listed, and Vite's temporary files are
@@ -35,7 +39,7 @@ export function parcourir(chemin, sauter = () => false) {
35
39
  const out = [];
36
40
  const walk = (p, dossier) => {
37
41
  if (!dossier) {
38
- if (!TEMPORAIRE_DE_VITE.test(p)) {
42
+ if (!estTemporaireDeVite(p)) {
39
43
  out.push(p);
40
44
  }
41
45
  return;
@@ -20,3 +20,9 @@ export function langagesDe(racine: string): Langage[];
20
20
  export function langageDe(racine: string): Composition;
21
21
  /** The join of the copy <copie>, its readings played in the main tree when they throw in it. */
22
22
  export function langageDeLaCopie(copie: string, principal?: () => string | null): Composition;
23
+
24
+ /** The components of the repository at <racine>, read by `langageDeLaCopie`, and the packages out
25
+ * of the frame a plan may name, each `dossier` relative to it. */
26
+ export function composantsLisibles(
27
+ racine: string
28
+ ): { dossier: string; pkg: { name: string }; hors: boolean }[];
@@ -38,6 +38,7 @@ import { spawnSync } from 'node:child_process';
38
38
  import { createRequire } from 'node:module';
39
39
  import path from 'node:path';
40
40
  import { composer } from './composition-des-langages.mjs';
41
+ import { paquetsDuLangage } from './enveloppe/paquets-du-plan.mjs';
41
42
  import { matieresDeclarees, sousUneMatiere } from './matieres-lues.mjs';
42
43
  import { paquets } from './paquets.mjs';
43
44
  import {
@@ -256,3 +257,8 @@ export function langageDeLaCopie(copie, principal = () => arbrePrincipal(copie))
256
257
  manifestes: { ...langage.manifestes, horsDesTests: tolerer(langage.manifestes.horsDesTests) },
257
258
  });
258
259
  }
260
+
261
+ // The components of the repository at <racine>, as `paquetsDuLangage` gives them, still read in a
262
+ // copy its tool no longer loads (`langageDeLaCopie`): what an act of the circuit reads to open on
263
+ // its ticket, so that it writes its stop and resumes, and what the title of a defect of main names.
264
+ export const composantsLisibles = racine => paquetsDuLangage(langageDeLaCopie(racine), racine);
@@ -0,0 +1,236 @@
1
+ #!/usr/bin/env node
2
+ // Reads a ticket, its summary first, as `gh issue view` gives the comments on demand:
3
+ // `grillhouse lire <ticket> [<numéro> | --description | --tout]` (USAGE).
4
+ //
5
+ // - Without option, the summary: the id and the title; the status, the reason of the closure, the
6
+ // labels, the parent and each other dependency, each when the ticket has it; the children by
7
+ // their count per status and the command that lists them; the description up to the end of its
8
+ // section of criteria (a `##` heading that begins with « Critères »; the whole description
9
+ // without one), each section left out named by its title and the presence of notes said, with
10
+ // `--description`; one line per comment: its number (from 1, in the order Beads gives), its
11
+ // author, its date and its first non blank line, cut at 200 characters.
12
+ // - A number gives that comment whole; `--description` the whole description and the notes;
13
+ // `--tout` the summary with the whole description, the notes and every comment whole.
14
+ // - Beads is read, never written: `bd show <ticket> --json`, `bd comments <ticket> --json` and
15
+ // `bd list --parent <ticket> --all --limit 0 --json`, those the answer needs.
16
+ // - Exit codes: 0; 2 with the usage for a call that is not understood; 1 with the reason for a
17
+ // ticket Beads does not give, a reading that fails or a number without comment. A refusal
18
+ // writes nothing on the standard output.
19
+ import { pathToFileURL } from 'node:url';
20
+ import { lancerBd } from './ticket.mjs';
21
+
22
+ export const USAGE = [
23
+ 'Lit un ticket : son sommaire d’abord, la suite à la demande.',
24
+ ' grillhouse lire <ticket> le sommaire : titre, état, description jusqu’aux',
25
+ ' critères, une ligne par commentaire',
26
+ ' grillhouse lire <ticket> <numéro> ce commentaire en entier',
27
+ ' grillhouse lire <ticket> --description la description entière et les notes',
28
+ ' grillhouse lire <ticket> --tout le sommaire, la description entière, les notes et',
29
+ ' chaque commentaire en entier',
30
+ '',
31
+ ].join('\n');
32
+
33
+ // The characters of the first line of a comment the summary gives.
34
+ const COUPE = 200;
35
+ const OPTIONS = new Set(['--description', '--tout']);
36
+
37
+ /**
38
+ * @typedef {import('./ticket.mjs').Bd} Bd
39
+ * @typedef {{ id: string, status?: string, dependency_type?: string }} Dependance
40
+ * @typedef {{ id: string, title?: string, description?: string, notes?: string, status?: string, close_reason?: string, labels?: string[], parent?: string, dependencies?: Dependance[] }} Ticket
41
+ * @typedef {{ author?: string, created_at?: string, text?: string }} Commentaire
42
+ */
43
+
44
+ // What the call <args> of Beads answers, a list read from its JSON; throws, naming the call, when
45
+ // it fails or gives no list.
46
+ async function liste(bd, args) {
47
+ const nomme = `bd ${args.join(' ')}`;
48
+ const r = await bd(args);
49
+ if (r.status !== 0) {
50
+ const raison = String(r.stderr ?? '')
51
+ .trim()
52
+ .split('\n')[0];
53
+ throw new Error(`${nomme} : ${raison || `code ${r.status}`}`);
54
+ }
55
+ let lu;
56
+ try {
57
+ lu = JSON.parse(r.stdout ?? '');
58
+ } catch (e) {
59
+ throw new Error(`${nomme} : réponse illisible (${/** @type {Error} */ (e).message})`);
60
+ }
61
+ if (!Array.isArray(lu)) {
62
+ throw new Error(`${nomme} : aucune liste rendue`);
63
+ }
64
+ return lu;
65
+ }
66
+
67
+ // The description cut after its section of criteria: what the summary keeps, and the titles of
68
+ // the sections it leaves out. A heading inside a block of code is text.
69
+ function couper(description) {
70
+ const lignes = description.split('\n');
71
+ const titres = [];
72
+ let bloc = false;
73
+ lignes.forEach((ligne, i) => {
74
+ if (/^\s*(```|~~~)/.test(ligne)) {
75
+ bloc = !bloc;
76
+ return;
77
+ }
78
+ const m = bloc ? null : /^(##?)\s+(.*)$/.exec(ligne);
79
+ if (m) {
80
+ titres.push({ i, niveau: m[1].length, titre: m[2].trim() });
81
+ }
82
+ });
83
+ const criteres = titres.findIndex(t => t.niveau === 2 && t.titre.startsWith('Critères'));
84
+ const ecartes = criteres < 0 ? [] : titres.slice(criteres + 1);
85
+ const gardees = ecartes.length > 0 ? lignes.slice(0, ecartes[0].i) : lignes;
86
+ return { gardee: gardees.join('\n').trimEnd(), ecartees: ecartes.map(t => t.titre) };
87
+ }
88
+
89
+ // The head of the summary: the id and the title, then each fact of the state the ticket has.
90
+ /** @param {Ticket} t @param {Ticket[]} enfants */
91
+ function tete(t, enfants) {
92
+ const lignes = [`${t.id} — ${t.title ?? ''}`];
93
+ if (t.status) {
94
+ lignes.push(`Statut : ${t.status}`);
95
+ }
96
+ if (t.close_reason) {
97
+ lignes.push(`Motif de fermeture : ${t.close_reason}`);
98
+ }
99
+ if (t.labels?.length) {
100
+ lignes.push(`Étiquettes : ${t.labels.join(', ')}`);
101
+ }
102
+ if (t.parent) {
103
+ lignes.push(`Parent : ${t.parent}`);
104
+ }
105
+ const autres = (t.dependencies ?? []).filter(
106
+ d => !(d.dependency_type === 'parent-child' && d.id === t.parent)
107
+ );
108
+ if (autres.length > 0) {
109
+ lignes.push('Dépendances :');
110
+ lignes.push(...autres.map(d => `- ${d.id} · ${d.dependency_type} · ${d.status}`));
111
+ }
112
+ if (enfants.length > 0) {
113
+ const comptes = new Map();
114
+ for (const e of enfants) {
115
+ comptes.set(e.status, (comptes.get(e.status) ?? 0) + 1);
116
+ }
117
+ const dits = [...comptes].map(([statut, n]) => `${n} ${statut}`).join(', ');
118
+ lignes.push(`Enfants : ${dits} ; leur liste : \`bd list --parent ${t.id}\``);
119
+ }
120
+ return lignes.join('\n');
121
+ }
122
+
123
+ // The description of <t>, whole, with its notes.
124
+ /** @param {Ticket} t */
125
+ function entiere(t) {
126
+ return [t.description ?? '', ...(t.notes ? [`## Notes\n\n${t.notes}`] : [])].join('\n\n');
127
+ }
128
+
129
+ // The comment of number <n> whole, under its number, its author and its date.
130
+ /** @param {Commentaire} c @param {number} n */
131
+ function commentaire(c, n) {
132
+ return `### Commentaire ${n} · ${c.author} · ${c.created_at}\n\n${c.text ?? ''}`;
133
+ }
134
+
135
+ // The line of the summary for the comment of number <n>.
136
+ /** @param {Commentaire} c @param {number} n */
137
+ function ligneDuCommentaire(c, n) {
138
+ const premiere = [
139
+ ...(String(c.text ?? '')
140
+ .split('\n')
141
+ .find(l => l.trim() !== '')
142
+ ?.trim() ?? ''),
143
+ ];
144
+ const dite =
145
+ premiere.length > COUPE ? `${premiere.slice(0, COUPE).join('')}…` : premiere.join('');
146
+ return `${n}. ${c.author} · ${c.created_at} · ${dite}`;
147
+ }
148
+
149
+ /** @param {Ticket} t @param {Commentaire[]} commentaires @param {Ticket[]} enfants */
150
+ function sommaire(t, commentaires, enfants) {
151
+ const { gardee, ecartees } = couper(t.description ?? '');
152
+ const blocs = [tete(t, enfants), gardee];
153
+ const hors = [
154
+ ...(ecartees.length > 0 ? [`les sections ${ecartees.map(s => `« ${s} »`).join(', ')}`] : []),
155
+ ...(t.notes ? ['des notes'] : []),
156
+ ];
157
+ if (hors.length > 0) {
158
+ blocs.push(
159
+ `Hors du sommaire : ${hors.join(' ; ')}. \`npx grillhouse lire ${t.id} --description\` les rend.`
160
+ );
161
+ }
162
+ blocs.push(
163
+ commentaires.length === 0
164
+ ? 'Commentaires : aucun commentaire.'
165
+ : [
166
+ `Commentaires (\`npx grillhouse lire ${t.id} <numéro>\` en rend un en entier) :`,
167
+ ...commentaires.map((c, i) => ligneDuCommentaire(c, i + 1)),
168
+ ].join('\n')
169
+ );
170
+ return blocs.join('\n\n');
171
+ }
172
+
173
+ // What the call asks of the ticket <id>: the text to write.
174
+ async function repondre(id, demande, bd) {
175
+ const [t] = /** @type {Ticket[]} */ (await liste(bd, ['show', id, '--json']));
176
+ if (!t) {
177
+ throw new Error('Beads ne le rend pas');
178
+ }
179
+ if (demande === '--description') {
180
+ return entiere(t);
181
+ }
182
+ const commentaires = /** @type {Commentaire[]} */ (await liste(bd, ['comments', id, '--json']));
183
+ if (demande !== undefined && demande !== '--tout') {
184
+ const n = Number(demande);
185
+ const c = commentaires[n - 1];
186
+ if (!c) {
187
+ throw new Error(
188
+ `aucun commentaire de numéro ${demande} (le ticket en porte ${commentaires.length})`
189
+ );
190
+ }
191
+ return commentaire(c, n);
192
+ }
193
+ const enfants = /** @type {Ticket[]} */ (
194
+ await liste(bd, ['list', '--parent', id, '--all', '--limit', '0', '--json'])
195
+ );
196
+ if (demande === undefined) {
197
+ return sommaire(t, commentaires, enfants);
198
+ }
199
+ return [
200
+ tete(t, enfants),
201
+ entiere(t),
202
+ commentaires.length === 0
203
+ ? 'Commentaires : aucun commentaire.'
204
+ : commentaires.map((c, i) => commentaire(c, i + 1)).join('\n\n'),
205
+ ].join('\n\n');
206
+ }
207
+
208
+ /**
209
+ * The reading the arguments <args> of the command ask of Beads: its exit code and what it writes
210
+ * on each output, nothing written here.
211
+ * @param {string[]} args
212
+ * @param {{ bd: Bd }} options
213
+ * @returns {Promise<{ status: number, stdout: string, stderr: string }>}
214
+ */
215
+ export async function lireLeTicket(args, { bd }) {
216
+ const [id, demande] = args;
217
+ const comprise = demande === undefined || OPTIONS.has(demande) || /^[1-9]\d*$/.test(demande);
218
+ if (args.length > 2 || !id || id.startsWith('-') || !comprise) {
219
+ return { status: 2, stdout: '', stderr: USAGE };
220
+ }
221
+ try {
222
+ return { status: 0, stdout: `${await repondre(id, demande, bd)}\n`, stderr: '' };
223
+ } catch (e) {
224
+ const raison = /** @type {Error} */ (e).message;
225
+ return { status: 1, stdout: '', stderr: `grillhouse lire ${id} : ${raison}\n` };
226
+ }
227
+ }
228
+
229
+ if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
230
+ const r = await lireLeTicket(process.argv.slice(2), {
231
+ bd: args => lancerBd(args, process.cwd()),
232
+ });
233
+ process.stdout.write(r.stdout);
234
+ process.stderr.write(r.stderr);
235
+ process.exitCode = r.status;
236
+ }