@roomi-fields/grillhouse 0.52.0 → 0.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +1 -1
- package/CHANGELOG.md +96 -0
- package/agents/direct.md +1 -1
- package/cadre/templates/projet/docs/agents/issue-tracker.md +2 -2
- package/cadre/templates/projet/vitest.config.cjs +45 -0
- package/charte/superviseur.md +36 -37
- package/charte.md +13 -1
- package/dist/temporal/circuit/appel.d.ts +2 -0
- package/dist/temporal/circuit/appel.js +24 -2
- package/dist/temporal/circuit/appel.js.map +1 -1
- package/dist/temporal/circuit/client.d.ts +14 -5
- package/dist/temporal/circuit/client.js +41 -9
- package/dist/temporal/circuit/client.js.map +1 -1
- package/dist/temporal/circuit/commande.js +17 -6
- package/dist/temporal/circuit/commande.js.map +1 -1
- package/dist/temporal/circuit/contrat.d.ts +9 -0
- package/dist/temporal/circuit/contrat.js +6 -0
- package/dist/temporal/circuit/contrat.js.map +1 -1
- package/dist/temporal/circuit/deroule.js +29 -12
- package/dist/temporal/circuit/deroule.js.map +1 -1
- package/dist/temporal/client.d.ts +35 -1
- package/dist/temporal/client.js +144 -1
- package/dist/temporal/client.js.map +1 -1
- package/dist/temporal/commande.js +31 -13
- package/dist/temporal/commande.js.map +1 -1
- package/dist/temporal/etat.d.ts +3 -1
- package/dist/temporal/etat.js +31 -17
- package/dist/temporal/etat.js.map +1 -1
- package/dist/temporal/file/activites.js +1 -1
- package/dist/temporal/file/activites.js.map +1 -1
- package/dist/temporal/file/contrat.d.ts +4 -5
- package/dist/temporal/file/contrat.js +2 -2
- package/dist/temporal/file/contrat.js.map +1 -1
- package/dist/temporal/file/deroule.js +7 -5
- package/dist/temporal/file/deroule.js.map +1 -1
- package/dist/temporal/installation.d.ts +116 -53
- package/dist/temporal/installation.js +898 -241
- package/dist/temporal/installation.js.map +1 -1
- package/dist/temporal/nuits/deroule.js +3 -1
- package/dist/temporal/nuits/deroule.js.map +1 -1
- package/dist/temporal/places/deroule.js +2 -1
- package/dist/temporal/places/deroule.js.map +1 -1
- package/dist/temporal/sonde/deroule.js +2 -1
- package/dist/temporal/sonde/deroule.js.map +1 -1
- package/dist/temporal/tickets/deroule.js +4 -3
- package/dist/temporal/tickets/deroule.js.map +1 -1
- package/dist/temporal/travailleur.d.ts +7 -1
- package/dist/temporal/travailleur.js +49 -25
- package/dist/temporal/travailleur.js.map +1 -1
- package/docs/INTERFACE.md +37 -12
- package/docs/architecture/circuit.md +21 -18
- package/docs/architecture/entree.md +10 -11
- package/docs/architecture/greffon.md +45 -27
- package/docs/architecture/installation.md +92 -59
- package/docs/architecture/machine.md +2 -2
- package/docs/architecture/tests.md +15 -6
- package/docs/lexique.md +2 -2
- package/hooks/hooks.json +10 -0
- package/hooks/register.tsx +59 -39
- package/package.json +3 -2
- package/scripts/activites.mjs +5 -4
- package/scripts/aiguillage.mjs +5 -2
- package/scripts/bd-garde.mjs +69 -0
- package/scripts/ci-de-main.mjs +259 -56
- package/scripts/circuit.mjs +274 -47
- package/scripts/circuits-du-serveur.mjs +3 -2
- package/scripts/circuits-tenus.d.mts +7 -0
- package/scripts/circuits-tenus.mjs +17 -0
- package/scripts/commandes-composees.mjs +1 -1
- package/scripts/copie-de-montee.mjs +354 -0
- package/scripts/copies-du-depot.d.mts +13 -0
- package/scripts/copies-du-depot.mjs +66 -0
- package/scripts/copies-finies.mjs +6 -40
- package/scripts/crochets.mjs +16 -2
- package/scripts/direct.mjs +2 -2
- package/scripts/droits.mjs +13 -6
- package/scripts/engendres.mjs +5 -3
- package/scripts/enveloppe/travail-de-la-copie.mjs +77 -0
- package/scripts/etapes.mjs +11 -3
- package/scripts/faits-du-circuit.mjs +12 -5
- package/scripts/file-des-tickets.d.mts +13 -2
- package/scripts/file-des-tickets.mjs +71 -21
- package/scripts/greffons.mjs +42 -27
- package/scripts/grillhouse-maj.mjs +105 -85
- package/scripts/init.mjs +1 -1
- package/scripts/integration/file.mjs +5 -2
- package/scripts/integration/integrer.mjs +14 -4
- package/scripts/jointure.d.ts +16 -0
- package/scripts/langages/c/commandes.mjs +18 -8
- package/scripts/langages/cargo/commandes.mjs +88 -35
- package/scripts/langages/cargo/index.mjs +6 -3
- package/scripts/langages/cargo/sccache.mjs +15 -12
- package/scripts/langages/cargo/tailles-des-tests.mjs +115 -6
- package/scripts/langages/python/commandes.mjs +19 -9
- package/scripts/langages/python/squelette.mjs +2 -2
- package/scripts/langages/typescript/code-mort.mjs +36 -3
- package/scripts/langages/typescript/configurations-de-vitest.mjs +118 -0
- package/scripts/langages/typescript/index.mjs +2 -0
- package/scripts/langages/typescript/migrations/configurations-en-commonjs.mjs +370 -0
- package/scripts/langages/typescript/mise-a-jour.mjs +49 -12
- package/scripts/langages/typescript/parcours.mjs +5 -1
- package/scripts/langages/typescript/squelette.mjs +20 -17
- package/scripts/langages/typescript/tests-de-nuit.mjs +3 -3
- package/scripts/langages/typescript/turbo-des-paquets.mjs +24 -37
- package/scripts/langages/typescript/vitest-config/base.mjs +1 -1
- package/scripts/langages/typescript/vitest-config/bornes.mjs +1 -1
- package/scripts/langages/typescript/vitest-config/cibles.mjs +2 -2
- package/scripts/langages/typescript/{vitest.nuit.config.mjs → vitest.nuit.config.cjs} +61 -50
- package/scripts/langages.d.mts +6 -0
- package/scripts/langages.mjs +6 -0
- package/scripts/lire.mjs +236 -0
- package/scripts/mesure/pression.mjs +5 -3
- package/scripts/migrations/cout-des-jetons-au-registre.mjs +136 -0
- package/scripts/migrations/lire-un-ticket.mjs +46 -0
- package/scripts/migrations.mjs +4 -0
- package/scripts/montee.mjs +588 -0
- package/scripts/nuit.sh +21 -12
- package/scripts/outil.mjs +5 -3
- package/scripts/paquet-npm.mjs +22 -0
- package/scripts/paquet.mjs +5 -5
- package/scripts/pre-compact.mjs +25 -0
- package/scripts/registre.d.mts +7 -1
- package/scripts/registre.mjs +114 -102
- package/scripts/reponses-du-circuit.d.mts +17 -2
- package/scripts/reponses-du-circuit.mjs +78 -20
- package/scripts/resultats.mjs +55 -17
- package/scripts/retirer-les-copies-finies.mjs +4 -7
- package/scripts/seances.mjs +28 -3
- package/scripts/services-du-noyau.mjs +7 -2
- package/scripts/session-start.sh +18 -11
- package/scripts/sortie.mjs +4 -7
- package/scripts/sous-commandes.mjs +2 -0
- package/scripts/suiveur.mjs +12 -4
- package/scripts/superviseur.mjs +135 -84
- package/scripts/tableau.mjs +651 -224
- package/scripts/tarifs.mjs +67 -0
- package/scripts/ticket-du-circuit.mjs +25 -4
- package/scripts/transitions.d.mts +6 -14
- package/scripts/transitions.mjs +126 -49
- package/scripts/verdict-de-la-nuit.mjs +2 -2
- package/scripts/verrou-de-fichier.d.mts +11 -0
- package/skills/direct/SKILL.md +21 -11
- package/skills/explorateur/SKILL.md +16 -6
- package/skills/grill/SKILL.md +9 -7
- package/skills/grill/references/paquets.md +4 -4
- package/skills/mesure/SKILL.md +4 -3
- package/skills/pitmaster/SKILL.md +56 -35
- package/skills/pitmaster/references/consigne-agent.md +1 -1
- package/skills/pitmaster/references/erreurs.md +4 -2
- package/skills/pitmaster/references/tour.md +11 -4
- package/skills/relecteur/SKILL.md +8 -1
- package/skills/testwriter/SKILL.md +1 -1
- package/types/index.d.ts +3 -1
- package/cadre/templates/projet/vitest.config.ts +0 -44
- package/scripts/base-des-workflows.mjs +0 -58
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
// project's debt (`grillhouse-dette.json`, see `dette.mjs`) passes, keyed by its file and knip's
|
|
8
8
|
// kind of issue (`files`, `exports`, `types`, `dependencies`…).
|
|
9
9
|
// - A knip that measured nothing (it failed, or its output is not its report) refuses too: an
|
|
10
|
-
// empty green is the worst green.
|
|
10
|
+
// empty green is the worst green. So does a partial measure, before the debt is judged: a run
|
|
11
|
+
// that writes « ERROR: Error loading <file> » on stderr, its report readable or not, or that
|
|
12
|
+
// ends on another exit code than 0 and 1.
|
|
11
13
|
// - A finding that is not dead (a format's full table, a public name a consumer outside the
|
|
12
14
|
// repository reads) leaves by its name in `knip.json`, with its reason, never by a wide pattern.
|
|
13
15
|
// - The packages listed out of the frame (`docs/agents/hors-cadre.txt`, read by `horsCadre` of
|
|
@@ -43,6 +45,7 @@ import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'no
|
|
|
43
45
|
import { tmpdir } from 'node:os';
|
|
44
46
|
import path from 'node:path';
|
|
45
47
|
import { pathToFileURL } from 'node:url';
|
|
48
|
+
import { stripVTControlCharacters } from 'node:util';
|
|
46
49
|
import { fournisseursDuPaquet } from '../../services-du-noyau.mjs';
|
|
47
50
|
import { horsCadre, paquets as paquetsDuDepot } from '../../paquets.mjs';
|
|
48
51
|
import { MODE, trancher } from '../../dette.mjs';
|
|
@@ -348,9 +351,35 @@ function knip(racine, config, include) {
|
|
|
348
351
|
}
|
|
349
352
|
}
|
|
350
353
|
|
|
354
|
+
// Why the runs of knip <passes> (spawn results) measured only a part of the repository, as the
|
|
355
|
+
// lines of the refusal; null when every run is complete. First every « ERROR: Error loading » line
|
|
356
|
+
// any of them writes on stderr, colour sequences taken off: knip then reports without what that
|
|
357
|
+
// configuration declares. Else the first run that ends on another exit code than 0 (nothing found)
|
|
358
|
+
// and 1 (findings), or without one, with what it says.
|
|
359
|
+
function mesureIncomplete(passes) {
|
|
360
|
+
const nonCharges = new Set(
|
|
361
|
+
passes
|
|
362
|
+
.flatMap(p => stripVTControlCharacters(p.stderr ?? '').split(/\r?\n/))
|
|
363
|
+
.filter(l => l.includes('ERROR: Error loading '))
|
|
364
|
+
);
|
|
365
|
+
if (nonCharges.size) {
|
|
366
|
+
return [
|
|
367
|
+
"⛔ CODE MORT — knip n'a pas chargé une configuration : sa mesure est incomplète, et la dette ne l'absorbe pas. La configuration que knip nomme se corrige pour qu'il la charge, ou son greffon se règle dans knip.json avec sa raison.",
|
|
368
|
+
...[...nonCharges].map(l => ` ${l}`),
|
|
369
|
+
];
|
|
370
|
+
}
|
|
371
|
+
const fautive = passes.find(p => p.status !== 0 && p.status !== 1);
|
|
372
|
+
if (!fautive) {
|
|
373
|
+
return null;
|
|
374
|
+
}
|
|
375
|
+
const fin = fautive.status ?? fautive.signal ?? fautive.error?.code;
|
|
376
|
+
const dit = fautive.stderr || fautive.error?.message || fautive.stdout || '';
|
|
377
|
+
return [`⛔ CODE MORT — knip n'a pas fini sa mesure (fin : ${fin}) :\n${dit}`];
|
|
378
|
+
}
|
|
379
|
+
|
|
351
380
|
// The report of the dead-code check at <racine>: `lignes`, what the command writes on stderr (each
|
|
352
|
-
// refusal and the debt's lines), and `code`, its exit code (1 on a refusal
|
|
353
|
-
//
|
|
381
|
+
// refusal and the debt's lines), and `code`, its exit code (1 on a refusal, a knip it cannot read
|
|
382
|
+
// or an incomplete measure, which the debt is then never judged on). The functional core of the command: it runs knip and git and reads the project's debt, and
|
|
354
383
|
// writes nothing to the standard streams; the command below is its shell. The refusals reach SARIF
|
|
355
384
|
// through `trancher` under the results directory <env> names (scripts/resultats.mjs); without it none
|
|
356
385
|
// is written, and the debt's mode is <env>'s `GRILLHOUSE_DETTE`.
|
|
@@ -394,6 +423,10 @@ export async function codeMort(racine, env = process.env) {
|
|
|
394
423
|
DEPS.join(',')
|
|
395
424
|
)
|
|
396
425
|
: null;
|
|
426
|
+
const incomplete = mesureIncomplete(second ? [premier, second] : [premier]);
|
|
427
|
+
if (incomplete) {
|
|
428
|
+
return { lignes: [...lignes, ...incomplete], code: 1 };
|
|
429
|
+
}
|
|
397
430
|
const c2 = second ? constats(second.stdout ?? '', DEPS) : null;
|
|
398
431
|
let c = null;
|
|
399
432
|
if (c1 && (c2 || !second)) {
|
|
@@ -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);
|
|
@@ -78,6 +78,7 @@ import * as binaireDeJour from './migrations/0.33.0-binaire-de-jour.mjs';
|
|
|
78
78
|
import * as testsDuPoste from './migrations/0.33.0-tests-du-poste.mjs';
|
|
79
79
|
import * as cacheDesOutils from './migrations/0.34.1-cache-des-outils.mjs';
|
|
80
80
|
import * as testsEquipes from './migrations/0.49.0-tests-equipes.mjs';
|
|
81
|
+
import * as configurationsEnCommonJs from './migrations/configurations-en-commonjs.mjs';
|
|
81
82
|
import { COMMANDE as COMMANDE_DU_VERROU } from './verrou-des-dependances.mjs';
|
|
82
83
|
|
|
83
84
|
// The scripts of this module, beside this file.
|
|
@@ -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,370 @@
|
|
|
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 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.
|
|
14
|
+
// - Left intact, each named with its reason and the way out, then inscribed in the guard's debt,
|
|
15
|
+
// frozen: a configuration another file reads by its name (an import or a require, a path in the
|
|
16
|
+
// code, a script of a package.json or a shell script, a flow, `files` or a literal `include`
|
|
17
|
+
// of a tsconfig, a workspace of Vitest; a comment, a document or a pattern reads nothing), a
|
|
18
|
+
// configuration that reads such a one, one that uses `import.meta`, another export or a syntax
|
|
19
|
+
// Node cannot strip, a directory with a `vitest.config.cjs` already or several refused
|
|
20
|
+
// configurations, and every refused file not named `vitest.config.*` (an ESM `vite.config`, a
|
|
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.
|
|
24
|
+
// - Replayable without effect: a configuration the debt holds is left, and nothing is returned.
|
|
25
|
+
import { existsSync, readFileSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
26
|
+
import { createRequire, stripTypeScriptTypes } from 'node:module';
|
|
27
|
+
import path from 'node:path';
|
|
28
|
+
import { FICHIER, lire, trancher } from '../../../dette.mjs';
|
|
29
|
+
import { paquets } from '../../../paquets.mjs';
|
|
30
|
+
import { sources } from '../../../services-du-noyau.mjs';
|
|
31
|
+
import { configurationsRefusees, GARDE } from '../configurations-de-vitest.mjs';
|
|
32
|
+
import { estTemporaireDeVite, lireSiPresent, parcourir } from '../parcours.mjs';
|
|
33
|
+
|
|
34
|
+
export const version = '0.53.0';
|
|
35
|
+
export const nom = 'configurations en commonjs';
|
|
36
|
+
|
|
37
|
+
const CONFIGURATION = /^vitest\.config\.(?:[mc]?ts|m?js)$/;
|
|
38
|
+
// The directories no reader of a configuration lives in.
|
|
39
|
+
const HORS = new Set(['node_modules', '.git', 'dist', 'coverage', '.claude', '.turbo']);
|
|
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
|
+
});`;
|
|
63
|
+
// The files that name paths without being code (cheminsNommes).
|
|
64
|
+
const ENUMERE =
|
|
65
|
+
/(?:^|\/)(?:package\.json|tsconfig[^/]*\.json|vitest\.workspace\.json)$|^(?:\.github\/.*\.ya?ml|\.gitlab-ci\.yml)$|\.sh$/;
|
|
66
|
+
// The characters that separate the words of a command line, a flow or a JSON of paths.
|
|
67
|
+
const SEPARATEURS = /[\s"'`=,;()[\]|&<>]+/;
|
|
68
|
+
|
|
69
|
+
const posix = f => f.split(path.sep).join('/');
|
|
70
|
+
const sansExtension = f => f.replace(/\.[^./]+$/, '');
|
|
71
|
+
// TypeScript, a tool of every project of the module.
|
|
72
|
+
const typescript = () => createRequire(import.meta.url)('typescript');
|
|
73
|
+
|
|
74
|
+
// The string literals of the code `texte` of the file `f`, comments left out.
|
|
75
|
+
function chaines(ts, f, texte) {
|
|
76
|
+
const out = [];
|
|
77
|
+
const visiter = n => {
|
|
78
|
+
if (ts.isStringLiteralLike(n)) {
|
|
79
|
+
out.push(n.text);
|
|
80
|
+
}
|
|
81
|
+
ts.forEachChild(n, visiter);
|
|
82
|
+
};
|
|
83
|
+
visiter(ts.createSourceFile(f, texte, ts.ScriptTarget.Latest, true));
|
|
84
|
+
return out;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// The paths, from the root, that the file `f` names: each `{ chemin, module }`, `module` when an
|
|
88
|
+
// import can name it without its extension. A file gone since it was listed names none.
|
|
89
|
+
function cheminsNommes(ts, projet, f, espaces) {
|
|
90
|
+
const nomDuFichier = path.posix.basename(f);
|
|
91
|
+
const ici = path.posix.dirname(f);
|
|
92
|
+
const joindre = (base, m) => posix(path.relative(projet, path.resolve(projet, base, m)));
|
|
93
|
+
const mots = (texte, bases) =>
|
|
94
|
+
texte
|
|
95
|
+
.split(SEPARATEURS)
|
|
96
|
+
.filter(m => m && !MOTIF.test(m))
|
|
97
|
+
.flatMap(m => bases.map(b => ({ chemin: joindre(b, m) })));
|
|
98
|
+
const lu = lireSiPresent(path.join(projet, f));
|
|
99
|
+
if (lu === null) {
|
|
100
|
+
return [];
|
|
101
|
+
}
|
|
102
|
+
if (nomDuFichier === 'package.json') {
|
|
103
|
+
// A manifest that is not JSON (a fixture) names no script.
|
|
104
|
+
let scripts;
|
|
105
|
+
try {
|
|
106
|
+
scripts = Object.values(JSON.parse(lu).scripts ?? {});
|
|
107
|
+
} catch {
|
|
108
|
+
return [];
|
|
109
|
+
}
|
|
110
|
+
return scripts.flatMap(s => {
|
|
111
|
+
const racines = [...String(s).matchAll(/(?:--root|--prefix|--dir|-C)[ =]+([^\s"']+)/g)];
|
|
112
|
+
return mots(String(s), [ici, ...racines.map(r => path.posix.join(ici, r[1]))]);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
if (/^tsconfig.*\.json$/.test(nomDuFichier)) {
|
|
116
|
+
const { config } = ts.parseConfigFileTextToJson(f, lu);
|
|
117
|
+
return [...(config?.files ?? []), ...(config?.include ?? [])]
|
|
118
|
+
.filter(m => typeof m === 'string' && !MOTIF.test(m))
|
|
119
|
+
.map(m => ({ chemin: joindre(ici, m) }));
|
|
120
|
+
}
|
|
121
|
+
if (/^vitest\.workspace\.json$/.test(nomDuFichier)) {
|
|
122
|
+
return mots(lu, [ici]);
|
|
123
|
+
}
|
|
124
|
+
if (/^(\.github\/.*\.ya?ml|\.gitlab-ci\.yml)$/.test(f) || f.endsWith('.sh')) {
|
|
125
|
+
const texte = lu.replace(/(^|\s)#.*$/gm, '$1');
|
|
126
|
+
const dossiers = [...texte.matchAll(/working-directory:\s*["']?([^\s"']+)/g)].map(m => m[1]);
|
|
127
|
+
return mots(texte, ['.', ici, ...dossiers]);
|
|
128
|
+
}
|
|
129
|
+
return chaines(ts, f, lu).flatMap(m => {
|
|
130
|
+
if (!m || MOTIF.test(m) || /\s/.test(m)) {
|
|
131
|
+
return [];
|
|
132
|
+
}
|
|
133
|
+
const paquet = espaces.find(e => m.startsWith(`${e.nom}/`));
|
|
134
|
+
if (paquet) {
|
|
135
|
+
return [{ chemin: joindre(paquet.dossier, m.slice(paquet.nom.length + 1)), module: true }];
|
|
136
|
+
}
|
|
137
|
+
const relatif = m.startsWith('.');
|
|
138
|
+
const bases = relatif || !m.includes('/') ? [ici] : [ici, '.'];
|
|
139
|
+
return bases.map(b => ({ chemin: joindre(b, m), module: relatif }));
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// The files of the project that read each of `cibles` by its name: Map cible → files.
|
|
144
|
+
function lecteursDe(ts, projet, cibles) {
|
|
145
|
+
const espaces = paquets(projet)
|
|
146
|
+
.filter(p => typeof p.pkg.name === 'string')
|
|
147
|
+
.map(p => ({ nom: p.pkg.name, dossier: p.dossier }));
|
|
148
|
+
const out = new Map(cibles.map(c => [c, []]));
|
|
149
|
+
const autres = parcourir(projet, p => HORS.has(path.basename(p)))
|
|
150
|
+
.map(p => posix(path.relative(projet, p)))
|
|
151
|
+
.filter(f => ENUMERE.test(f));
|
|
152
|
+
const code = sources(projet).filter(f => !estTemporaireDeVite(f));
|
|
153
|
+
for (const f of [...new Set([...code, ...autres])].sort()) {
|
|
154
|
+
const nommes = cheminsNommes(ts, projet, f, espaces);
|
|
155
|
+
for (const c of cibles) {
|
|
156
|
+
const lit = nommes.some(
|
|
157
|
+
({ chemin, module }) =>
|
|
158
|
+
chemin === c ||
|
|
159
|
+
(module &&
|
|
160
|
+
(chemin === sansExtension(c) ||
|
|
161
|
+
(/\.[mc]?js$/.test(chemin) && sansExtension(chemin) === sansExtension(c))))
|
|
162
|
+
);
|
|
163
|
+
if (c !== f && lit) {
|
|
164
|
+
out.get(c).push(f);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return out;
|
|
169
|
+
}
|
|
170
|
+
|
|
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) {
|
|
211
|
+
const { name: defaut, namedBindings: liaisons } = n.importClause ?? {};
|
|
212
|
+
if (liaisons && ts.isNamespaceImport(liaisons)) {
|
|
213
|
+
const espace = `const ${liaisons.name.text} = ${appel};`;
|
|
214
|
+
return defaut ? `${espace}\nconst { default: ${defaut.text} } = ${liaisons.name.text};` : espace;
|
|
215
|
+
}
|
|
216
|
+
const noms = [
|
|
217
|
+
...(defaut ? [`default: ${defaut.text}`] : []),
|
|
218
|
+
...(liaisons?.elements ?? []).map(e =>
|
|
219
|
+
e.propertyName ? `${e.propertyName.getText()}: ${e.name.text}` : e.name.text
|
|
220
|
+
),
|
|
221
|
+
];
|
|
222
|
+
return noms.length ? `const { ${noms.join(', ')} } = ${appel};` : `${appel};`;
|
|
223
|
+
}
|
|
224
|
+
|
|
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) {
|
|
228
|
+
let texte = source;
|
|
229
|
+
if (/ts$/.test(f)) {
|
|
230
|
+
try {
|
|
231
|
+
texte = stripTypeScriptTypes(source);
|
|
232
|
+
} catch {
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
const arbre = ts.createSourceFile('c.mjs', texte, ts.ScriptTarget.Latest, true, ts.ScriptKind.JS);
|
|
237
|
+
let intraduisible = arbre.parseDiagnostics.length > 0;
|
|
238
|
+
// The ranges of the template literals, whose lines keep their indentation.
|
|
239
|
+
const gabarits = [];
|
|
240
|
+
const visiter = n => {
|
|
241
|
+
if (ts.isMetaProperty(n) && n.keywordToken === ts.SyntaxKind.ImportKeyword) {
|
|
242
|
+
intraduisible = true;
|
|
243
|
+
}
|
|
244
|
+
if (ts.isTemplateExpression(n) || ts.isStringLiteralLike(n)) {
|
|
245
|
+
gabarits.push([n.getStart(), n.end]);
|
|
246
|
+
}
|
|
247
|
+
ts.forEachChild(n, visiter);
|
|
248
|
+
};
|
|
249
|
+
visiter(arbre);
|
|
250
|
+
const imports = [];
|
|
251
|
+
let requis = false;
|
|
252
|
+
const retouches = [];
|
|
253
|
+
let defauts = 0;
|
|
254
|
+
let valeur = 'configurationParDefaut';
|
|
255
|
+
for (const n of arbre.statements) {
|
|
256
|
+
const modificateurs = ts.canHaveModifiers(n) ? (ts.getModifiers(n) ?? []) : [];
|
|
257
|
+
const exporte = modificateurs.find(m => m.kind === ts.SyntaxKind.ExportKeyword);
|
|
258
|
+
const defaut = modificateurs.find(m => m.kind === ts.SyntaxKind.DefaultKeyword);
|
|
259
|
+
if (ts.isImportDeclaration(n)) {
|
|
260
|
+
const lu = lecture(n, dossier);
|
|
261
|
+
requis ||= lu.requis;
|
|
262
|
+
imports.push(importation(ts, n, lu.appel));
|
|
263
|
+
retouches.push([n.getStart(), n.end, '']);
|
|
264
|
+
} else if (ts.isExportAssignment(n) && !n.isExportEquals) {
|
|
265
|
+
defauts += 1;
|
|
266
|
+
retouches.push([n.getStart(), n.expression.getFullStart(), `const ${valeur} =`]);
|
|
267
|
+
} else if (exporte && defaut) {
|
|
268
|
+
defauts += 1;
|
|
269
|
+
if (n.name) {
|
|
270
|
+
valeur = n.name.text;
|
|
271
|
+
retouches.push([exporte.getStart(), defaut.end + 1, '']);
|
|
272
|
+
} else {
|
|
273
|
+
retouches.push([exporte.getStart(), defaut.end, `const ${valeur} =`]);
|
|
274
|
+
}
|
|
275
|
+
} else if (exporte || ts.isExportDeclaration(n) || ts.isExportAssignment(n)) {
|
|
276
|
+
intraduisible = true;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if (intraduisible || defauts !== 1) {
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
// The comments at the head of the file stay at its head.
|
|
283
|
+
const debut = arbre.statements[0].getStart();
|
|
284
|
+
let corps = '';
|
|
285
|
+
let depuis = debut;
|
|
286
|
+
const indenter = (de, a) =>
|
|
287
|
+
texte.slice(de, a).replace(/\n(?=[^\n])/g, (saut, i) => {
|
|
288
|
+
const ou = de + i + 1;
|
|
289
|
+
return gabarits.some(([x, y]) => ou > x && ou < y) ? saut : '\n ';
|
|
290
|
+
});
|
|
291
|
+
for (const [de, a, neuf] of retouches) {
|
|
292
|
+
corps += indenter(depuis, de) + neuf;
|
|
293
|
+
depuis = neuf === '' && texte[a] === '\n' ? a + 1 : a;
|
|
294
|
+
}
|
|
295
|
+
corps += indenter(depuis, texte.length);
|
|
296
|
+
const lignes = [
|
|
297
|
+
...(requis ? CROCHET.split('\n').map(l => ` ${l}`) : []),
|
|
298
|
+
...imports.flatMap(i => i.split('\n')).map(l => ` ${l}`),
|
|
299
|
+
'',
|
|
300
|
+
` ${corps.trim()}`,
|
|
301
|
+
` return ${valeur};`,
|
|
302
|
+
];
|
|
303
|
+
return `${texte.slice(0, debut)}module.exports = (async () => {\n${lignes.join('\n')}\n})();\n`;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** Converts the configurations of Vitest of `projet` to CommonJS, the rest inscribed in the debt. */
|
|
307
|
+
export function migrer(projet) {
|
|
308
|
+
const inscrites = lire(projet)[GARDE] ?? {};
|
|
309
|
+
const neuves = () => configurationsRefusees(projet).filter(c => !inscrites[c.fichier]?.[c.regle]);
|
|
310
|
+
const refusees = neuves();
|
|
311
|
+
if (refusees.length === 0) {
|
|
312
|
+
return [];
|
|
313
|
+
}
|
|
314
|
+
const ts = typescript();
|
|
315
|
+
const toutes = configurationsRefusees(projet).map(c => c.fichier);
|
|
316
|
+
const lecteurs = lecteursDe(ts, projet, toutes);
|
|
317
|
+
const quiLisent = new Set([...lecteurs.values()].flat());
|
|
318
|
+
const lignes = [];
|
|
319
|
+
const raisons = new Map();
|
|
320
|
+
const aConvertir = [];
|
|
321
|
+
for (const { fichier } of refusees) {
|
|
322
|
+
const dossier = path.posix.dirname(fichier);
|
|
323
|
+
const cjs = path.posix.join(dossier, 'vitest.config.cjs');
|
|
324
|
+
const lue = lecteurs.get(fichier);
|
|
325
|
+
if (lue.length) {
|
|
326
|
+
raisons.set(fichier, `lue par son nom par ${lue.join(', ')}`);
|
|
327
|
+
} else if (!CONFIGURATION.test(path.posix.basename(fichier))) {
|
|
328
|
+
raisons.set(fichier, 'la migration ne convertit que `vitest.config.*`');
|
|
329
|
+
} else if (quiLisent.has(fichier)) {
|
|
330
|
+
raisons.set(fichier, "elle lit une autre configuration refusée, et la migration n'écrit aucun lecteur");
|
|
331
|
+
} else if (existsSync(path.join(projet, cjs))) {
|
|
332
|
+
raisons.set(fichier, `\`${cjs}\` est déjà là`);
|
|
333
|
+
} else if (
|
|
334
|
+
toutes.filter(
|
|
335
|
+
f => path.posix.dirname(f) === dossier && CONFIGURATION.test(path.posix.basename(f))
|
|
336
|
+
).length > 1
|
|
337
|
+
) {
|
|
338
|
+
raisons.set(fichier, 'plusieurs configurations de Vitest dans son dossier');
|
|
339
|
+
} else {
|
|
340
|
+
const source = readFileSync(path.join(projet, fichier), 'utf8');
|
|
341
|
+
const neuf = enCommonJs(ts, path.join(projet, dossier), fichier, source);
|
|
342
|
+
if (neuf === null) {
|
|
343
|
+
raisons.set(
|
|
344
|
+
fichier,
|
|
345
|
+
'sa forme dépasse les imports statiques et un `export default` (`import.meta`, un autre export, une syntaxe que Node ne retire pas)'
|
|
346
|
+
);
|
|
347
|
+
} else {
|
|
348
|
+
aConvertir.push({ fichier, cjs, neuf });
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
for (const { fichier, cjs, neuf } of aConvertir) {
|
|
353
|
+
writeFileSync(path.join(projet, cjs), neuf);
|
|
354
|
+
rmSync(path.join(projet, fichier));
|
|
355
|
+
lignes.push(
|
|
356
|
+
`${fichier} : remplacée par ${cjs}, que Vite charge sans rien écrire à côté ; relis sa mise en forme`
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
const restantes = configurationsRefusees(projet);
|
|
360
|
+
if (restantes.some(c => raisons.has(c.fichier))) {
|
|
361
|
+
trancher(projet, GARDE, restantes, 'inscrire', {});
|
|
362
|
+
for (const [fichier, raison] of raisons) {
|
|
363
|
+
const cjs = path.posix.join(path.posix.dirname(fichier), 'vitest.config.cjs');
|
|
364
|
+
lignes.push(
|
|
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`
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
return lignes;
|
|
370
|
+
}
|