@roomi-fields/grillhouse 0.51.0 → 0.53.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 (149) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +68 -0
  3. package/agents/direct.md +1 -1
  4. package/cadre/templates/projet/vitest.config.cjs +45 -0
  5. package/charte/plan.md +47 -0
  6. package/charte/preuve.md +39 -0
  7. package/charte/superviseur.md +60 -0
  8. package/charte/tests.md +38 -0
  9. package/charte.md +23 -178
  10. package/dist/temporal/circuit/appel.d.ts +2 -0
  11. package/dist/temporal/circuit/appel.js +24 -2
  12. package/dist/temporal/circuit/appel.js.map +1 -1
  13. package/dist/temporal/circuit/client.d.ts +15 -7
  14. package/dist/temporal/circuit/client.js +42 -11
  15. package/dist/temporal/circuit/client.js.map +1 -1
  16. package/dist/temporal/circuit/commande.js +17 -6
  17. package/dist/temporal/circuit/commande.js.map +1 -1
  18. package/dist/temporal/circuit/contrat.d.ts +9 -0
  19. package/dist/temporal/circuit/contrat.js +6 -0
  20. package/dist/temporal/circuit/contrat.js.map +1 -1
  21. package/dist/temporal/circuit/deroule.js +25 -4
  22. package/dist/temporal/circuit/deroule.js.map +1 -1
  23. package/dist/temporal/client.d.ts +35 -1
  24. package/dist/temporal/client.js +144 -1
  25. package/dist/temporal/client.js.map +1 -1
  26. package/dist/temporal/commande.js +31 -13
  27. package/dist/temporal/commande.js.map +1 -1
  28. package/dist/temporal/etat.d.ts +3 -1
  29. package/dist/temporal/etat.js +31 -17
  30. package/dist/temporal/etat.js.map +1 -1
  31. package/dist/temporal/file/activites.js +1 -1
  32. package/dist/temporal/file/activites.js.map +1 -1
  33. package/dist/temporal/file/contrat.d.ts +4 -5
  34. package/dist/temporal/file/contrat.js +2 -2
  35. package/dist/temporal/file/contrat.js.map +1 -1
  36. package/dist/temporal/file/deroule.js +7 -5
  37. package/dist/temporal/file/deroule.js.map +1 -1
  38. package/dist/temporal/installation.d.ts +103 -53
  39. package/dist/temporal/installation.js +842 -237
  40. package/dist/temporal/installation.js.map +1 -1
  41. package/dist/temporal/nuits/deroule.js +3 -1
  42. package/dist/temporal/nuits/deroule.js.map +1 -1
  43. package/dist/temporal/places/deroule.js +2 -1
  44. package/dist/temporal/places/deroule.js.map +1 -1
  45. package/dist/temporal/sonde/deroule.js +2 -1
  46. package/dist/temporal/sonde/deroule.js.map +1 -1
  47. package/dist/temporal/tickets/deroule.js +4 -3
  48. package/dist/temporal/tickets/deroule.js.map +1 -1
  49. package/dist/temporal/travailleur.d.ts +7 -1
  50. package/dist/temporal/travailleur.js +49 -25
  51. package/dist/temporal/travailleur.js.map +1 -1
  52. package/docs/INTERFACE.md +20 -14
  53. package/docs/architecture/circuit.md +19 -16
  54. package/docs/architecture/entree.md +8 -9
  55. package/docs/architecture/greffon.md +54 -20
  56. package/docs/architecture/installation.md +99 -60
  57. package/docs/architecture/machine.md +31 -4
  58. package/docs/architecture/tests.md +22 -8
  59. package/docs/lexique.md +12 -3
  60. package/hooks/hooks.json +10 -10
  61. package/hooks/register.tsx +84 -2
  62. package/package.json +4 -2
  63. package/scripts/activites.mjs +25 -9
  64. package/scripts/aiguillage.mjs +1 -1
  65. package/scripts/attente-au-tour.mjs +2 -3
  66. package/scripts/bilan.mjs +116 -56
  67. package/scripts/bilans-gardes.mjs +37 -0
  68. package/scripts/circuit.mjs +256 -42
  69. package/scripts/circuits-du-serveur.mjs +3 -2
  70. package/scripts/circuits-tenus.d.mts +7 -0
  71. package/scripts/circuits-tenus.mjs +17 -0
  72. package/scripts/copie-de-montee.mjs +354 -0
  73. package/scripts/copies-du-depot.d.mts +13 -0
  74. package/scripts/copies-du-depot.mjs +66 -0
  75. package/scripts/copies-finies.mjs +6 -40
  76. package/scripts/crochets.mjs +16 -2
  77. package/scripts/direct.mjs +2 -2
  78. package/scripts/droits.mjs +117 -38
  79. package/scripts/engendres.mjs +5 -3
  80. package/scripts/entree-de-seance.mjs +35 -0
  81. package/scripts/enveloppe/enveloppe.mjs +23 -16
  82. package/scripts/enveloppe/lancer.sh +32 -22
  83. package/scripts/enveloppe/travail-de-la-copie.mjs +154 -0
  84. package/scripts/etapes.mjs +11 -3
  85. package/scripts/faits-du-circuit.mjs +12 -5
  86. package/scripts/file-des-tickets.d.mts +13 -2
  87. package/scripts/file-des-tickets.mjs +44 -12
  88. package/scripts/greffons.mjs +42 -27
  89. package/scripts/grillhouse-maj.mjs +105 -85
  90. package/scripts/init.mjs +1 -1
  91. package/scripts/integration/file.mjs +5 -2
  92. package/scripts/integration/integrer.mjs +14 -4
  93. package/scripts/jointure.d.ts +18 -1
  94. package/scripts/langages/c/commandes.mjs +17 -7
  95. package/scripts/langages/cargo/commandes.mjs +87 -34
  96. package/scripts/langages/cargo/index.mjs +6 -3
  97. package/scripts/langages/cargo/sccache.mjs +15 -12
  98. package/scripts/langages/python/commandes.mjs +68 -15
  99. package/scripts/langages/python/squelette.mjs +4 -3
  100. package/scripts/langages/typescript/configurations-de-vitest.mjs +118 -0
  101. package/scripts/langages/typescript/index.mjs +14 -12
  102. package/scripts/langages/typescript/migrations/configurations-en-commonjs.mjs +299 -0
  103. package/scripts/langages/typescript/squelette.mjs +20 -17
  104. package/scripts/langages/typescript/tests-de-nuit.mjs +3 -3
  105. package/scripts/langages/typescript/turbo-des-paquets.mjs +76 -39
  106. package/scripts/langages/typescript/verifier.mjs +27 -2
  107. package/scripts/langages/typescript/vitest-config/base.mjs +1 -1
  108. package/scripts/langages/typescript/vitest-config/bornes.mjs +1 -1
  109. package/scripts/langages/typescript/vitest-config/cibles.mjs +2 -2
  110. package/scripts/langages/typescript/{vitest.nuit.config.mjs → vitest.nuit.config.cjs} +61 -50
  111. package/scripts/mesure/pression.mjs +5 -3
  112. package/scripts/migrations/serveurs-de-l-index.mjs +1 -1
  113. package/scripts/migrations/suivi-du-superviseur-retire.mjs +56 -0
  114. package/scripts/migrations.mjs +2 -0
  115. package/scripts/montee.mjs +524 -0
  116. package/scripts/nuit.sh +3 -2
  117. package/scripts/outil.mjs +5 -3
  118. package/scripts/paquet-npm.mjs +22 -0
  119. package/scripts/paquet.mjs +5 -5
  120. package/scripts/pre-compact.mjs +25 -0
  121. package/scripts/reponses-du-circuit.d.mts +17 -2
  122. package/scripts/reponses-du-circuit.mjs +78 -20
  123. package/scripts/resultats.mjs +42 -14
  124. package/scripts/retirer-les-copies-finies.mjs +4 -7
  125. package/scripts/seances.mjs +81 -29
  126. package/scripts/services-du-noyau.mjs +7 -2
  127. package/scripts/session-start.sh +19 -10
  128. package/scripts/sortie-de-seance.mjs +70 -0
  129. package/scripts/sortie.mjs +4 -7
  130. package/scripts/sous-commandes.mjs +1 -1
  131. package/scripts/superviseur.mjs +417 -159
  132. package/scripts/tableau.mjs +249 -152
  133. package/scripts/ticket-du-circuit.mjs +22 -0
  134. package/scripts/transitions.d.mts +6 -9
  135. package/scripts/transitions.mjs +123 -36
  136. package/scripts/verrou-de-fichier.d.mts +11 -0
  137. package/skills/direct/SKILL.md +21 -11
  138. package/skills/explorateur/SKILL.md +8 -3
  139. package/skills/grill/SKILL.md +11 -8
  140. package/skills/grill/references/paquets.md +4 -4
  141. package/skills/pitmaster/SKILL.md +99 -53
  142. package/skills/pitmaster/references/cadre.md +1 -1
  143. package/skills/pitmaster/references/consigne-agent.md +1 -1
  144. package/skills/pitmaster/references/tour.md +6 -5
  145. package/skills/relecteur/SKILL.md +9 -2
  146. package/skills/testwriter/SKILL.md +3 -3
  147. package/cadre/templates/projet/pitmaster/SUIVI.md +0 -22
  148. package/cadre/templates/projet/vitest.config.ts +0 -44
  149. package/scripts/attente-a-l-arret.mjs +0 -114
@@ -0,0 +1,118 @@
1
+ // The configurations of Vitest of a repository, the part of the guard `turbo-des-paquets`
2
+ // (./turbo-des-paquets.mjs) that has a known debt. The envelope of a role shows a package out of
3
+ // its plan read-only, and Vite 5 bundles an ESM configuration into a file beside it
4
+ // (`vitest.config.ts.timestamp-<n>.mjs`) to load it; a `.cjs` one is loaded in memory.
5
+ // Mechanism: packages/grillhouse/docs/architecture/tests.md, §5.1.
6
+ //
7
+ // Judged: the root of the repository and each of its packages (hors-cadre.txt aside), one finding
8
+ // per refused file:
9
+ // - a `vitest.config.*` other than `.cjs`, whatever the `type` of the manifest;
10
+ // - the configuration the script `test:unit` names (`--config`, `-c`) when it is not a `.cjs`;
11
+ // - in a package that plays tests (`test:unit`) without `vitest.config.*` nor named
12
+ // configuration, the `vite.config.*` they play under when Vite loads it as ESM: it asks for a
13
+ // `vitest.config.cjs` beside it, `vite.config` staying as it is for the build.
14
+ // A finding inscribed in the project's debt (`grillhouse-dette.json`, ../../dette.mjs) passes.
15
+ import { existsSync, readFileSync, statSync } from 'node:fs';
16
+ import path from 'node:path';
17
+ import { trancher } from '../../dette.mjs';
18
+ import { paquets } from '../../paquets.mjs';
19
+
20
+ export const GARDE = 'turbo-des-paquets';
21
+ export const REGLE = 'config-hors-cjs';
22
+ // The extensions of a configuration, in the order Vitest looks for them, `.cjs` the only one
23
+ // that passes.
24
+ const REFUSEES = ['ts', 'mts', 'cts', 'js', 'mjs'];
25
+ const EXTENSIONS = [...REFUSEES, 'cjs'];
26
+ const POURQUOI =
27
+ "Vite écrit un fichier à côté d'une configuration ESM pour la charger, et l'enveloppe montre en lecture seule un paquet hors du plan";
28
+
29
+ const posix = f => f.split(path.sep).join('/');
30
+ const manifeste = dir => {
31
+ const f = path.join(dir, 'package.json');
32
+ return existsSync(f) ? JSON.parse(readFileSync(f, 'utf8')) : {};
33
+ };
34
+
35
+ // The configurations the command line `script` gives Vitest by `--config` or `-c`.
36
+ function configurationsNommees(script) {
37
+ const noms = [];
38
+ for (const commande of script.split(/&&|\|\||;|\|/)) {
39
+ if (!/\bvitest\b/.test(commande)) {
40
+ continue;
41
+ }
42
+ const mots = commande.split(/\s+/).map(m => m.replace(/["']/g, ''));
43
+ mots.forEach((m, i) => {
44
+ const colle = /^(?:--config|-c)=(.+)$/.exec(m)?.[1];
45
+ const nom = colle ?? (m === '--config' || m === '-c' ? mots[i + 1] : undefined);
46
+ if (nom) {
47
+ noms.push(nom);
48
+ }
49
+ });
50
+ }
51
+ return noms;
52
+ }
53
+
54
+ // Whether Vite loads the file `f` of a package of manifest `pkg` as ESM.
55
+ const enEsm = (f, pkg) => /\.m[jt]s$/.test(f) || (/\.[jt]s$/.test(f) && pkg.type === 'module');
56
+
57
+ /**
58
+ * The refused configurations of Vitest of the repository at `racine`, one finding per file.
59
+ * @param {string} racine
60
+ * @returns {{ fichier: string, regle: string, message: string }[]}
61
+ */
62
+ export function configurationsRefusees(racine) {
63
+ const dossiers = [
64
+ '',
65
+ ...(existsSync(path.join(racine, 'package.json'))
66
+ ? paquets(racine)
67
+ .filter(p => !p.hors)
68
+ .map(p => p.dossier)
69
+ : []),
70
+ ];
71
+ const constats = new Map();
72
+ const refuser = (fichier, message) =>
73
+ constats.set(fichier, { fichier, regle: REGLE, message: `⛔ ${fichier} : ${message}` });
74
+ const enCjs = (fichier, attendu) =>
75
+ refuser(
76
+ fichier,
77
+ `la configuration de Vitest s'écrit en CommonJS, \`${attendu}\` (la base du cadre par \`await import()\`) ; ${POURQUOI}.`
78
+ );
79
+ for (const dossier of new Set(dossiers)) {
80
+ const dir = path.join(racine, dossier);
81
+ const pkg = manifeste(dir);
82
+ const ici = nom => posix(path.join(dossier, nom));
83
+ const presents = base =>
84
+ EXTENSIONS.map(ext => `${base}.${ext}`).filter(f => existsSync(path.join(dir, f)));
85
+ const deVitest = presents('vitest.config');
86
+ for (const f of deVitest.filter(f => !f.endsWith('.cjs'))) {
87
+ enCjs(ici(f), 'vitest.config.cjs');
88
+ }
89
+ const script = pkg.scripts?.['test:unit'];
90
+ if (typeof script !== 'string') {
91
+ continue;
92
+ }
93
+ const nommees = configurationsNommees(script);
94
+ for (const nom of nommees) {
95
+ const f = path.join(dir, nom);
96
+ if (!nom.endsWith('.cjs') && existsSync(f) && statSync(f).isFile()) {
97
+ const { dir: d, name } = path.posix.parse(posix(nom));
98
+ enCjs(ici(nom), path.posix.join(d, `${name}.cjs`));
99
+ }
100
+ }
101
+ if (nommees.length === 0 && deVitest.length === 0) {
102
+ const vite = presents('vite.config')[0];
103
+ if (vite && enEsm(vite, pkg)) {
104
+ refuser(
105
+ ici(vite),
106
+ `les tests jouent sous cette configuration ESM : ajoute un \`vitest.config.cjs\` à côté, que Vitest préfère, ce fichier restant celui de la construction ; ${POURQUOI}.`
107
+ );
108
+ }
109
+ }
110
+ }
111
+ return [...constats.values()];
112
+ }
113
+
114
+ /**
115
+ * The findings of the guard `turbo-des-paquets` at `racine` judged against the known debt, in the
116
+ * mode of the run (`trancher`, ../../dette.mjs): `{ refus, lignes }`.
117
+ */
118
+ export const trancherLaGarde = (racine, constats) => trancher(racine, GARDE, constats);
@@ -37,9 +37,10 @@
37
37
  // - The migrations of a project of TypeScript (./migrations/): the base configuration of Vitest,
38
38
  // and the ones that replay a guard of this module, which the update plays with the core's
39
39
  // (scripts/migrations.mjs), as each plugin of Nx carries its own.
40
- // - No binary of the machine (`binaires`); what its tools write in a project, `.turbo`
41
- // (`ignorer`); its share of the update (./mise-a-jour.mjs, `miseAJour`): the tests by Vitest,
42
- // the frame's package declared, the typing, the turbo.json, and the generators.
40
+ // - No binary of the machine (`binaires`); what its tools write in a project, Vitest's reports
41
+ // and the cache of the tools (`ignorer`); its share of the update (./mise-a-jour.mjs,
42
+ // `miseAJour`): the tests by Vitest, the frame's package declared, the typing, the turbo.json,
43
+ // and the generators.
43
44
  // - The skeleton of a new package (./squelette.mjs, `squelette`), which `grillhouse paquet` writes.
44
45
  import { spawnSync } from 'node:child_process';
45
46
  import { mkdtempSync, readFileSync, rmSync } from 'node:fs';
@@ -77,6 +78,7 @@ import * as binaireDeJour from './migrations/0.33.0-binaire-de-jour.mjs';
77
78
  import * as testsDuPoste from './migrations/0.33.0-tests-du-poste.mjs';
78
79
  import * as cacheDesOutils from './migrations/0.34.1-cache-des-outils.mjs';
79
80
  import * as testsEquipes from './migrations/0.49.0-tests-equipes.mjs';
81
+ import * as configurationsEnCommonJs from './migrations/configurations-en-commonjs.mjs';
80
82
  import { COMMANDE as COMMANDE_DU_VERROU } from './verrou-des-dependances.mjs';
81
83
 
82
84
  // The scripts of this module, beside this file.
@@ -219,16 +221,15 @@ export default {
219
221
  // runs and cache (`.turbo`) are the frame's, every language playing by it: IGNORES_DU_CADRE of
220
222
  // scripts/grillhouse-maj.mjs ignores them.
221
223
  ignorer: ['.vitest-reports', '.cache-outils'],
222
- // Where its tools write: the cache of Turborepo in the main tree, shared by every copy, written;
223
- // the logs of Turborepo's tasks (`.turbo/turbo-<task>.log`, written on every run, a task replayed
224
- // from its cache included, and which no option of Turborepo sends elsewhere) and the cache of
225
- // Vite, where Vitest writes the results of a run (`.cache-outils/vite/vitest/`, the `cacheDir` of
226
- // the base configurations: a copy's `node_modules` is a link, so nothing under it is a clean
227
- // output) and whose failure fails it; and the cache of ESLint and Prettier (`.cache-outils/`),
228
- // proper to the session, an empty one costing a whole reading, as without a cache.
224
+ // Where its tools write, Turborepo's outputs being the core's (`sortiesDuLangage` of
225
+ // scripts/enveloppe/enveloppe.mjs): the cache of Vite, where Vitest writes the results of a run
226
+ // (`.cache-outils/vite/vitest/`, the `cacheDir` of the base configurations: a copy's
227
+ // `node_modules` is a link, so nothing under it is a clean output) and whose failure fails it;
228
+ // and the cache of ESLint and Prettier (`.cache-outils/`), proper to the session, an empty one
229
+ // costing a whole reading, as without a cache.
229
230
  sorties: {
230
- ecrites: ['//.turbo/cache/'],
231
- propres: ['.turbo', '.cache-outils'],
231
+ ecrites: [],
232
+ propres: ['.cache-outils'],
232
233
  lues: [],
233
234
  },
234
235
  // The test tool run directly, Vitest or Turborepo that plays it: `npm test` and `npm run
@@ -377,6 +378,7 @@ export default {
377
378
  testsDuPoste,
378
379
  cacheDesOutils,
379
380
  testsEquipes,
381
+ configurationsEnCommonJs,
380
382
  ],
381
383
  miseAJour: miseAJour(joueDesTests),
382
384
  squelette,
@@ -0,0 +1,299 @@
1
+ // The migration of the configurations of Vitest of a project to CommonJS, which the guard
2
+ // `turbo-des-paquets` asks (../configurations-de-vitest.mjs): Vite 5 writes a file beside an ESM
3
+ // configuration to load it, and fails in a package the envelope shows read-only. Migrations:
4
+ // packages/grillhouse/docs/architecture/installation.md §5.4.
5
+ //
6
+ // - Converted: a refused `vitest.config.*` made of static imports, plain statements and one
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.
10
+ // - Left intact, each named with its reason and the way out, then inscribed in the guard's debt,
11
+ // frozen: a configuration another file reads by its name (an import or a require, a path in the
12
+ // code, a script of a package.json or a shell script, a flow, `files` or a literal `include`
13
+ // of a tsconfig, a workspace of Vitest; a comment, a document or a pattern reads nothing), a
14
+ // configuration that reads such a one, one that uses `import.meta`, another export or a syntax
15
+ // Node cannot strip, a directory with a `vitest.config.cjs` already or several refused
16
+ // configurations, and every refused file not named `vitest.config.*` (an ESM `vite.config`, a
17
+ // configuration `--config` names). The migration writes no reader.
18
+ // - Replayable without effect: a configuration the debt holds is left, and nothing is returned.
19
+ import { existsSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
20
+ import { createRequire, stripTypeScriptTypes } from 'node:module';
21
+ import path from 'node:path';
22
+ import { FICHIER, lire, trancher } from '../../../dette.mjs';
23
+ import { paquets } from '../../../paquets.mjs';
24
+ import { sources } from '../../../services-du-noyau.mjs';
25
+ import { configurationsRefusees, GARDE } from '../configurations-de-vitest.mjs';
26
+ import { parcourir } from '../parcours.mjs';
27
+
28
+ export const version = '0.53.0';
29
+ export const nom = 'configurations en commonjs';
30
+
31
+ const CONFIGURATION = /^vitest\.config\.(?:[mc]?ts|m?js)$/;
32
+ // The directories no reader of a configuration lives in.
33
+ const HORS = new Set(['node_modules', '.git', 'dist', 'coverage', '.claude', '.turbo']);
34
+ const MOTIF = /[*?{}[\]]/;
35
+ // The files that name paths without being code (cheminsNommes).
36
+ const ENUMERE =
37
+ /(?:^|\/)(?:package\.json|tsconfig[^/]*\.json|vitest\.workspace\.json)$|^(?:\.github\/.*\.ya?ml|\.gitlab-ci\.yml)$|\.sh$/;
38
+ // The characters that separate the words of a command line, a flow or a JSON of paths.
39
+ const SEPARATEURS = /[\s"'`=,;()[\]|&<>]+/;
40
+
41
+ const posix = f => f.split(path.sep).join('/');
42
+ const sansExtension = f => f.replace(/\.[^./]+$/, '');
43
+ // TypeScript, a tool of every project of the module.
44
+ const typescript = () => createRequire(import.meta.url)('typescript');
45
+
46
+ // The string literals of the code `texte` of the file `f`, comments left out.
47
+ function chaines(ts, f, texte) {
48
+ const out = [];
49
+ const visiter = n => {
50
+ if (ts.isStringLiteralLike(n)) {
51
+ out.push(n.text);
52
+ }
53
+ ts.forEachChild(n, visiter);
54
+ };
55
+ visiter(ts.createSourceFile(f, texte, ts.ScriptTarget.Latest, true));
56
+ return out;
57
+ }
58
+
59
+ // The paths, from the root, that the file `f` names: each `{ chemin, module }`, `module` when an
60
+ // import can name it without its extension.
61
+ function cheminsNommes(ts, projet, f, espaces) {
62
+ const nomDuFichier = path.posix.basename(f);
63
+ const ici = path.posix.dirname(f);
64
+ const joindre = (base, m) => posix(path.relative(projet, path.resolve(projet, base, m)));
65
+ const mots = (texte, bases) =>
66
+ texte
67
+ .split(SEPARATEURS)
68
+ .filter(m => m && !MOTIF.test(m))
69
+ .flatMap(m => bases.map(b => ({ chemin: joindre(b, m) })));
70
+ const lu = () => readFileSync(path.join(projet, f), 'utf8');
71
+ if (nomDuFichier === 'package.json') {
72
+ // A manifest that is not JSON (a fixture) names no script.
73
+ let scripts;
74
+ try {
75
+ scripts = Object.values(JSON.parse(lu()).scripts ?? {});
76
+ } catch {
77
+ return [];
78
+ }
79
+ return scripts.flatMap(s => {
80
+ const racines = [...String(s).matchAll(/(?:--root|--prefix|--dir|-C)[ =]+([^\s"']+)/g)];
81
+ return mots(String(s), [ici, ...racines.map(r => path.posix.join(ici, r[1]))]);
82
+ });
83
+ }
84
+ if (/^tsconfig.*\.json$/.test(nomDuFichier)) {
85
+ const { config } = ts.parseConfigFileTextToJson(f, lu());
86
+ return [...(config?.files ?? []), ...(config?.include ?? [])]
87
+ .filter(m => typeof m === 'string' && !MOTIF.test(m))
88
+ .map(m => ({ chemin: joindre(ici, m) }));
89
+ }
90
+ if (/^vitest\.workspace\.json$/.test(nomDuFichier)) {
91
+ return mots(lu(), [ici]);
92
+ }
93
+ if (/^(\.github\/.*\.ya?ml|\.gitlab-ci\.yml)$/.test(f) || f.endsWith('.sh')) {
94
+ const texte = lu().replace(/(^|\s)#.*$/gm, '$1');
95
+ const dossiers = [...texte.matchAll(/working-directory:\s*["']?([^\s"']+)/g)].map(m => m[1]);
96
+ return mots(texte, ['.', ici, ...dossiers]);
97
+ }
98
+ return chaines(ts, f, lu()).flatMap(m => {
99
+ if (!m || MOTIF.test(m) || /\s/.test(m)) {
100
+ return [];
101
+ }
102
+ const paquet = espaces.find(e => m.startsWith(`${e.nom}/`));
103
+ if (paquet) {
104
+ return [{ chemin: joindre(paquet.dossier, m.slice(paquet.nom.length + 1)), module: true }];
105
+ }
106
+ const relatif = m.startsWith('.');
107
+ const bases = relatif || !m.includes('/') ? [ici] : [ici, '.'];
108
+ return bases.map(b => ({ chemin: joindre(b, m), module: relatif }));
109
+ });
110
+ }
111
+
112
+ // The files of the project that read each of `cibles` by its name: Map cible → files.
113
+ function lecteursDe(ts, projet, cibles) {
114
+ const espaces = paquets(projet)
115
+ .filter(p => typeof p.pkg.name === 'string')
116
+ .map(p => ({ nom: p.pkg.name, dossier: p.dossier }));
117
+ const out = new Map(cibles.map(c => [c, []]));
118
+ const autres = parcourir(projet, p => HORS.has(path.basename(p)))
119
+ .map(p => posix(path.relative(projet, p)))
120
+ .filter(f => ENUMERE.test(f));
121
+ for (const f of [...new Set([...sources(projet), ...autres])].sort()) {
122
+ const nommes = cheminsNommes(ts, projet, f, espaces);
123
+ for (const c of cibles) {
124
+ const lit = nommes.some(
125
+ ({ chemin, module }) =>
126
+ chemin === c ||
127
+ (module &&
128
+ (chemin === sansExtension(c) ||
129
+ (/\.[mc]?js$/.test(chemin) && sansExtension(chemin) === sansExtension(c))))
130
+ );
131
+ if (c !== f && lit) {
132
+ out.get(c).push(f);
133
+ }
134
+ }
135
+ }
136
+ return out;
137
+ }
138
+
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})`;
145
+ const { name: defaut, namedBindings: liaisons } = n.importClause ?? {};
146
+ if (liaisons && ts.isNamespaceImport(liaisons)) {
147
+ const espace = `const ${liaisons.name.text} = ${appel};`;
148
+ return defaut ? `${espace}\nconst { default: ${defaut.text} } = ${liaisons.name.text};` : espace;
149
+ }
150
+ const noms = [
151
+ ...(defaut ? [`default: ${defaut.text}`] : []),
152
+ ...(liaisons?.elements ?? []).map(e =>
153
+ e.propertyName ? `${e.propertyName.getText()}: ${e.name.text}` : e.name.text
154
+ ),
155
+ ];
156
+ return noms.length ? `const { ${noms.join(', ')} } = ${appel};` : `${appel};`;
157
+ }
158
+
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) {
162
+ let texte = source;
163
+ if (/ts$/.test(f)) {
164
+ try {
165
+ texte = stripTypeScriptTypes(source);
166
+ } catch {
167
+ return null;
168
+ }
169
+ }
170
+ const arbre = ts.createSourceFile('c.mjs', texte, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
171
+ let intraduisible = arbre.parseDiagnostics.length > 0;
172
+ // The ranges of the template literals, whose lines keep their indentation.
173
+ const gabarits = [];
174
+ const visiter = n => {
175
+ if (ts.isMetaProperty(n) && n.keywordToken === ts.SyntaxKind.ImportKeyword) {
176
+ intraduisible = true;
177
+ }
178
+ if (ts.isTemplateExpression(n) || ts.isStringLiteralLike(n)) {
179
+ gabarits.push([n.getStart(), n.end]);
180
+ }
181
+ ts.forEachChild(n, visiter);
182
+ };
183
+ visiter(arbre);
184
+ const imports = [];
185
+ const retouches = [];
186
+ let defauts = 0;
187
+ let valeur = 'configurationParDefaut';
188
+ for (const n of arbre.statements) {
189
+ const modificateurs = ts.canHaveModifiers(n) ? (ts.getModifiers(n) ?? []) : [];
190
+ const exporte = modificateurs.find(m => m.kind === ts.SyntaxKind.ExportKeyword);
191
+ const defaut = modificateurs.find(m => m.kind === ts.SyntaxKind.DefaultKeyword);
192
+ if (ts.isImportDeclaration(n)) {
193
+ imports.push(importation(ts, n));
194
+ retouches.push([n.getStart(), n.end, '']);
195
+ } else if (ts.isExportAssignment(n) && !n.isExportEquals) {
196
+ defauts += 1;
197
+ retouches.push([n.getStart(), n.expression.getFullStart(), `const ${valeur} =`]);
198
+ } else if (exporte && defaut) {
199
+ defauts += 1;
200
+ if (n.name) {
201
+ valeur = n.name.text;
202
+ retouches.push([exporte.getStart(), defaut.end + 1, '']);
203
+ } else {
204
+ retouches.push([exporte.getStart(), defaut.end, `const ${valeur} =`]);
205
+ }
206
+ } else if (exporte || ts.isExportDeclaration(n) || ts.isExportAssignment(n)) {
207
+ intraduisible = true;
208
+ }
209
+ }
210
+ if (intraduisible || defauts !== 1) {
211
+ return null;
212
+ }
213
+ // The comments at the head of the file stay at its head.
214
+ const debut = arbre.statements[0].getStart();
215
+ let corps = '';
216
+ let depuis = debut;
217
+ const indenter = (de, a) =>
218
+ texte.slice(de, a).replace(/\n(?=[^\n])/g, (saut, i) => {
219
+ const ou = de + i + 1;
220
+ return gabarits.some(([x, y]) => ou > x && ou < y) ? saut : '\n ';
221
+ });
222
+ for (const [de, a, neuf] of retouches) {
223
+ corps += indenter(depuis, de) + neuf;
224
+ depuis = neuf === '' && texte[a] === '\n' ? a + 1 : a;
225
+ }
226
+ corps += indenter(depuis, texte.length);
227
+ const lignes = [
228
+ ...imports.flatMap(i => i.split('\n')).map(l => ` ${l}`),
229
+ '',
230
+ ` ${corps.trim()}`,
231
+ ` return ${valeur};`,
232
+ ];
233
+ return `${texte.slice(0, debut)}module.exports = (async () => {\n${lignes.join('\n')}\n})();\n`;
234
+ }
235
+
236
+ /** Converts the configurations of Vitest of `projet` to CommonJS, the rest inscribed in the debt. */
237
+ export function migrer(projet) {
238
+ const inscrites = lire(projet)[GARDE] ?? {};
239
+ const neuves = () => configurationsRefusees(projet).filter(c => !inscrites[c.fichier]?.[c.regle]);
240
+ const refusees = neuves();
241
+ if (refusees.length === 0) {
242
+ return [];
243
+ }
244
+ const ts = typescript();
245
+ const toutes = configurationsRefusees(projet).map(c => c.fichier);
246
+ const lecteurs = lecteursDe(ts, projet, toutes);
247
+ const quiLisent = new Set([...lecteurs.values()].flat());
248
+ const lignes = [];
249
+ const raisons = new Map();
250
+ const aConvertir = [];
251
+ for (const { fichier } of refusees) {
252
+ const dossier = path.posix.dirname(fichier);
253
+ const cjs = path.posix.join(dossier, 'vitest.config.cjs');
254
+ const lue = lecteurs.get(fichier);
255
+ if (lue.length) {
256
+ raisons.set(fichier, `lue par son nom par ${lue.join(', ')}`);
257
+ } else if (!CONFIGURATION.test(path.posix.basename(fichier))) {
258
+ raisons.set(fichier, 'la migration ne convertit que `vitest.config.*`');
259
+ } else if (quiLisent.has(fichier)) {
260
+ raisons.set(fichier, "elle lit une autre configuration refusée, et la migration n'écrit aucun lecteur");
261
+ } else if (existsSync(path.join(projet, cjs))) {
262
+ raisons.set(fichier, `\`${cjs}\` est déjà là`);
263
+ } else if (
264
+ toutes.filter(
265
+ f => path.posix.dirname(f) === dossier && CONFIGURATION.test(path.posix.basename(f))
266
+ ).length > 1
267
+ ) {
268
+ raisons.set(fichier, 'plusieurs configurations de Vitest dans son dossier');
269
+ } else {
270
+ const neuf = enCommonJs(ts, fichier, readFileSync(path.join(projet, fichier), 'utf8'));
271
+ if (neuf === null) {
272
+ raisons.set(
273
+ fichier,
274
+ 'sa forme dépasse les imports statiques et un `export default` (`import.meta`, un autre export, une syntaxe que Node ne retire pas)'
275
+ );
276
+ } else {
277
+ aConvertir.push({ fichier, cjs, neuf });
278
+ }
279
+ }
280
+ }
281
+ for (const { fichier, cjs, neuf } of aConvertir) {
282
+ writeFileSync(path.join(projet, cjs), neuf);
283
+ rmSync(path.join(projet, fichier));
284
+ lignes.push(
285
+ `${fichier} : remplacée par ${cjs}, que Vite charge sans rien écrire à côté ; relis sa mise en forme`
286
+ );
287
+ }
288
+ const restantes = configurationsRefusees(projet);
289
+ if (restantes.some(c => raisons.has(c.fichier))) {
290
+ trancher(projet, GARDE, restantes, 'inscrire', {});
291
+ for (const [fichier, raison] of raisons) {
292
+ const cjs = path.posix.join(path.posix.dirname(fichier), 'vitest.config.cjs');
293
+ 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`
295
+ );
296
+ }
297
+ }
298
+ return lignes;
299
+ }
@@ -9,8 +9,8 @@
9
9
  // name has one, as Nx names a library after the workspace's scope; private; an ES module; its
10
10
  // script `test:unit`, which makes it a package that plays tests, and the tools of its tests and
11
11
  // of its typing the root does not declare, TypeScript, Vitest and Node's types, at the versions of
12
- // the module's template); its tsconfig.json, which types its sources, its tests and its
13
- // configuration, nothing emitted; its vitest.config.ts, the frame's base configuration by its
12
+ // the module's template); its tsconfig.json, which types its sources and its tests, nothing
13
+ // emitted; its vitest.config.cjs, the frame's base configuration by its
14
14
  // name, which passes while the package has no test yet, as the configuration of a library that
15
15
  // Nx generates (`passWithNoTests`); `src/index.ts`, an empty module; `tests/.gitkeep`, its folder
16
16
  // of tests. The update gives it its script `typecheck` and the frame's package in its
@@ -19,7 +19,7 @@
19
19
  // when the root has none), unless a pattern there covers it already.
20
20
  // - The lock of the versions: `npm install`, at the root.
21
21
  // - A folder that already holds code is taken as it is when its code lies under `src/` and
22
- // `tests/`, which its tsconfig.json and its vitest.config.ts cover, each file present kept; a
22
+ // `tests/`, which its tsconfig.json and its vitest.config.cjs cover, each file present kept; a
23
23
  // file of code out of them (`.ts`, `.tsx`, `.mts`, `.cts`, `.js`, `.jsx`, `.mjs`, `.cjs`), which
24
24
  // neither its typing nor its tests would reach, is refused by its name, nothing written, the
25
25
  // layout named, in place of a skeleton beside it.
@@ -59,21 +59,24 @@ const TSCONFIG = {
59
59
  exclude: ['node_modules', 'dist'],
60
60
  };
61
61
 
62
- const VITEST = `import { defineConfig, mergeConfig } from 'vitest/config';
63
- import base from '@roomi-fields/grillhouse/vitest-config';
64
-
65
- // The tests of the package: the frame's base configuration, by its name, extended with what is the
62
+ const VITEST = `// The tests of the package: the frame's base configuration, by its name, extended with what is the
66
63
  // package's own. It passes while the package has no test yet, as the configuration of a library
67
64
  // that Nx generates; its first test plays as any other.
68
- export default mergeConfig(
69
- base,
70
- defineConfig({
71
- test: {
72
- include: ['src/**/*.{test,spec}.{ts,js,mjs}', 'tests/**/*.{test,spec}.{ts,js,mjs}'],
73
- passWithNoTests: true,
74
- },
75
- })
76
- );
65
+ // CommonJS: Vite writes a file beside an ESM configuration to load it, and the envelope shows a
66
+ // package out of a plan read-only.
67
+ module.exports = (async () => {
68
+ const { defineConfig, mergeConfig } = await import('vitest/config');
69
+ const { default: base } = await import('@roomi-fields/grillhouse/vitest-config');
70
+ return mergeConfig(
71
+ base,
72
+ defineConfig({
73
+ test: {
74
+ include: ['src/**/*.{test,spec}.{ts,js,mjs}', 'tests/**/*.{test,spec}.{ts,js,mjs}'],
75
+ passWithNoTests: true,
76
+ },
77
+ })
78
+ );
79
+ })();
77
80
  `;
78
81
 
79
82
  /** @type {import('../../jointure.js').Langage['squelette']} */
@@ -113,7 +116,7 @@ export function squelette(racine, { chemin, modele, existants }) {
113
116
  const fichiers = {
114
117
  [`${chemin}/package.json`]: json(pkg),
115
118
  [`${chemin}/tsconfig.json`]: json(TSCONFIG),
116
- [`${chemin}/vitest.config.ts`]: VITEST,
119
+ [`${chemin}/vitest.config.cjs`]: VITEST,
117
120
  [`${chemin}/src/index.ts`]: `// The entry of the package ${nom}: its interface, docs/INTERFACE.md, says what it exports.\nexport {};\n`,
118
121
  [`${chemin}/tests/.gitkeep`]: '',
119
122
  };
@@ -17,7 +17,7 @@
17
17
  // `*.budget.spec.*`) and the time witnesses (a test file that imports `mesurerAuRepos`,
18
18
  // `fichiersTemoins` of ./vitest-config/cibles.mjs): what `npm test` and the integration leave
19
19
  // out (./vitest-config/cibles.mjs). A copy with none plays nothing, and the exit code is 0.
20
- // - Vitest plays them with the frame's configuration (./vitest.nuit.config.mjs), from the root of
20
+ // - Vitest plays them with the frame's configuration (./vitest.nuit.config.cjs), from the root of
21
21
  // the copy: `npx --no-install vitest run --root <copie> --config <configuration>`, once for the
22
22
  // night tests (GRILLHOUSE_TESTS_DE_NUIT=nuit), then once for the measures alone, one file at a
23
23
  // time (GRILLHOUSE_TESTS_DE_NUIT=mesures), as Bazel plays a test tagged `exclusive` after the
@@ -26,7 +26,7 @@
26
26
  // - Each run plays one Vitest per unit: the root under the frame's configuration alone, and each
27
27
  // directory below it that holds a Vitest configuration (`vitest.config.*`, else `vite.config.*`)
28
28
  // with `--root` at that directory, under that configuration merged with the frame's, what the
29
- // night sets winning (./vitest.nuit.config.mjs, `unitesDeLaNuit`).
29
+ // night sets winning (./vitest.nuit.config.cjs, `unitesDeLaNuit`).
30
30
  // - With `--hors-du-poste`, the night of a shared machine: the night tests alone, but those that
31
31
  // bear the tag `@poste` (`porteLEtiquetteDuPoste` of ./vitest-config/cibles.mjs, which the guard
32
32
  // ./tests-du-poste.mjs asks of a night test that depends on the poste), in one run
@@ -116,7 +116,7 @@ export function lireLesArguments(args) {
116
116
  return { horsDuPoste, sansEquipement, duPoste, mesuresSeules, tranche };
117
117
  }
118
118
 
119
- const CONFIGURATION = fileURLToPath(new URL('./vitest.nuit.config.mjs', import.meta.url));
119
+ const CONFIGURATION = fileURLToPath(new URL('./vitest.nuit.config.cjs', import.meta.url));
120
120
  const HORS = new Set(['node_modules', 'dist', '.git']);
121
121
 
122
122
  // Whether a file that <est> (the rules of ./vitest-config/cibles.mjs) lies under <dossier>.