@roomi-fields/grillhouse 0.24.15 → 0.25.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/bin/grillhouse.mjs +40 -12
- package/cadre/templates/cargo/.config/nextest.toml +8 -0
- package/cadre/templates/cargo/deny.toml +36 -0
- package/cadre/templates/cargo/package.json +15 -0
- package/cadre/templates/cargo/rust-toolchain.toml +6 -0
- package/cadre/templates/projet/package.json +5 -1
- package/cadre/templates/turbo/paquets.json +1 -1
- package/cadre/templates/turbo/sans-paquets.json +1 -1
- package/charte.md +16 -0
- package/docs/ARCHITECTURE.md +157 -54
- package/docs/CADRE.md +47 -0
- package/docs/INTERFACE.md +168 -0
- package/package.json +62 -13
- package/scripts/arbitrages.mjs +23 -0
- package/scripts/avancement.mjs +15 -29
- package/scripts/circuit.mjs +89 -97
- package/scripts/commande-du-langage.mjs +56 -0
- package/scripts/composants-affectes.mjs +47 -170
- package/scripts/conformite.d.ts +27 -0
- package/scripts/conformite.mjs +226 -0
- package/scripts/demon.mjs +1 -1
- package/scripts/dernier-vert.mjs +11 -9
- package/scripts/droits.mjs +27 -21
- package/scripts/enveloppe/enveloppe.mjs +206 -64
- package/scripts/enveloppe/lancer.sh +20 -91
- package/scripts/enveloppe/paquets-du-plan.mjs +24 -2
- package/scripts/etapes.mjs +2 -2
- package/scripts/gardes-du-cadre.mjs +12 -18
- package/scripts/grillhouse-maj.mjs +246 -389
- package/scripts/init.mjs +2 -1
- package/scripts/integration/file.mjs +3 -3
- package/scripts/integration/integrer.mjs +13 -10
- package/scripts/integration/rejeu.mjs +36 -7
- package/scripts/jointure.d.ts +304 -0
- package/scripts/langages/cargo/binaires.json +4 -0
- package/scripts/langages/cargo/binaires.mjs +60 -0
- package/scripts/langages/cargo/clippy.mjs +103 -0
- package/scripts/langages/cargo/commandes.mjs +378 -0
- package/scripts/langages/cargo/composants.mjs +191 -0
- package/scripts/langages/cargo/elements-du-lot.mjs +139 -0
- package/scripts/langages/cargo/exemples.mjs +357 -0
- package/scripts/langages/cargo/frontieres.mjs +84 -0
- package/scripts/langages/cargo/index-interfaces.mjs +138 -0
- package/scripts/langages/cargo/index.mjs +115 -0
- package/scripts/langages/cargo/mise-a-jour.mjs +93 -0
- package/scripts/langages/cargo/nextest.toml +5 -0
- package/scripts/langages/cargo/touches.mjs +93 -0
- package/scripts/langages/cargo/verdict.mjs +85 -0
- package/scripts/langages/typescript/chemins-des-tests.mjs +68 -0
- package/scripts/{code-mort.mjs → langages/typescript/code-mort.mjs} +5 -5
- package/scripts/langages/typescript/composants.mjs +64 -0
- package/scripts/{consommateurs-arbitres.mjs → langages/typescript/consommateurs-arbitres.mjs} +6 -24
- package/scripts/{consommateurs.mjs → langages/typescript/consommateurs.mjs} +13 -71
- package/scripts/langages/typescript/construire.mjs +176 -0
- package/scripts/{elements-du-lot.mjs → langages/typescript/elements-du-lot.mjs} +2 -2
- package/scripts/langages/typescript/exemples.mjs +289 -0
- package/scripts/{frontieres.mjs → langages/typescript/frontieres.mjs} +3 -5
- package/scripts/{index-interfaces.mjs → langages/typescript/index-interfaces.mjs} +3 -3
- package/scripts/langages/typescript/index.mjs +335 -0
- package/scripts/{interfaces-contre-code.mjs → langages/typescript/interfaces-contre-code.mjs} +2 -2
- package/scripts/langages/typescript/lecteurs.mjs +179 -0
- package/scripts/{migrations → langages/typescript/migrations}/0.23.0-config-vitest.mjs +14 -29
- package/scripts/{migrations → langages/typescript/migrations}/0.24.4-noms-declares-inutilises.mjs +2 -2
- package/scripts/{migrations → langages/typescript/migrations}/0.24.6-lignes-mal-formees.mjs +2 -2
- package/scripts/{migrations → langages/typescript/migrations}/0.24.7-matiere-dans-les-tests.mjs +2 -2
- package/scripts/langages/typescript/migrations/0.25.0-chemins-des-tests.mjs +27 -0
- package/scripts/langages/typescript/migrations/0.25.0-tailles-des-tests.mjs +31 -0
- package/scripts/langages/typescript/mise-a-jour.mjs +320 -0
- package/scripts/{references-par-les-types.mjs → langages/typescript/references-par-les-types.mjs} +3 -3
- package/scripts/langages/typescript/regle-des-tests.mjs +39 -0
- package/scripts/{resumes.mjs → langages/typescript/resumes.mjs} +4 -4
- package/scripts/langages/typescript/script-des-tests.mjs +6 -0
- package/scripts/langages/typescript/tailles-des-tests.mjs +219 -0
- package/scripts/langages/typescript/tests-de-nuit.mjs +57 -0
- package/scripts/{tests.mjs → langages/typescript/tests.mjs} +41 -32
- package/scripts/{turbo-des-paquets.mjs → langages/typescript/turbo-des-paquets.mjs} +49 -23
- package/scripts/langages/typescript/verdict.mjs +105 -0
- package/scripts/{verifier.mjs → langages/typescript/verifier.mjs} +53 -34
- package/scripts/{vitest-config → langages/typescript/vitest-config}/avancement.reporter.mjs +10 -2
- package/scripts/{vitest-config → langages/typescript/vitest-config}/base.mjs +63 -9
- package/scripts/{vitest-config → langages/typescript/vitest-config}/changements.mjs +18 -11
- package/scripts/{vitest-config → langages/typescript/vitest-config}/cibles.mjs +7 -6
- package/scripts/{vitest-config → langages/typescript/vitest-config}/duree.reporter.mjs +6 -1
- package/scripts/langages/typescript/vitest-config/lances.mjs +473 -0
- package/scripts/{vitest-config → langages/typescript/vitest-config}/mesure.setup.mjs +1 -1
- package/scripts/{vitest-config → langages/typescript/vitest-config}/resultats.mjs +5 -5
- package/scripts/{vitest-config → langages/typescript/vitest-config}/resultats.setup.mjs +4 -3
- package/scripts/{vitest.nuit.config.mjs → langages/typescript/vitest.nuit.config.mjs} +2 -2
- package/scripts/langages.mjs +85 -0
- package/scripts/{vitest-config → mesure}/avancement.mjs +4 -13
- package/scripts/{vitest-config → mesure}/base-de-passe.mjs +70 -33
- package/scripts/{vitest-config → mesure}/pression.mjs +5 -6
- package/scripts/migrations/0.23.2-copies-du-cadre.mjs +29 -6
- package/scripts/migrations/0.24.0-circuit-simplifie.mjs +13 -6
- package/scripts/migrations/0.25.0-script-des-tests.mjs +92 -0
- package/scripts/migrations.mjs +17 -13
- package/scripts/nuit.sh +59 -63
- package/scripts/paquets.d.ts +5 -0
- package/scripts/paquets.mjs +24 -2
- package/scripts/resultats.mjs +8 -82
- package/scripts/services-du-noyau.mjs +30 -0
- package/scripts/session-start.sh +17 -9
- package/scripts/sources.mjs +35 -13
- package/scripts/sous-commandes.mjs +57 -17
- package/scripts/superviseur.mjs +1 -1
- package/scripts/tableau.mjs +1 -1
- package/scripts/un-commit-par-ticket.mjs +48 -14
- package/scripts/verrou-de-fichier.mjs +1 -1
- package/scripts/verrou-de-machine.mjs +4 -4
- package/scripts/verrous/verrou.mjs +28 -37
- package/skills/developpeur/SKILL.md +2 -2
- package/skills/explorateur/SKILL.md +13 -5
- package/skills/grill/SKILL.md +2 -2
- package/skills/pitmaster/references/cadre.md +1 -1
- package/skills/pitmaster/references/consigne-agent.md +10 -3
- package/skills/redacteur/references/documents-d-un-composant.md +4 -4
- package/skills/relecteur/SKILL.md +4 -1
- package/skills/testwriter/SKILL.md +20 -6
- /package/scripts/{consommateurs.d.ts → langages/typescript/consommateurs.d.ts} +0 -0
- /package/scripts/{vitest-config → langages/typescript/vitest-config}/base.d.ts +0 -0
- /package/scripts/{vitest-config → langages/typescript/vitest-config}/machine.setup.mjs +0 -0
- /package/scripts/{vitest-config → langages/typescript/vitest-config}/mesure.d.ts +0 -0
- /package/scripts/{vitest-config → langages/typescript/vitest-config}/mesure.mjs +0 -0
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
// What the module typescript brings to the update of a project (`grillhouse maj`,
|
|
2
|
+
// scripts/grillhouse-maj.mjs), the demand `miseAJour` of the join (scripts/jointure.d.ts), as the
|
|
3
|
+
// `init` generator of a plugin of Nx brings its tool to a workspace. The core writes the root
|
|
4
|
+
// package.json after, and reports the lines.
|
|
5
|
+
//
|
|
6
|
+
// - The template: `templates/projet/` of the frame's files, whose package.json gives the frame's
|
|
7
|
+
// scripts and the versions of the tools.
|
|
8
|
+
// - A project that runs Vitest (its `test` script names it, or `vitest` is in the `dependencies` or
|
|
9
|
+
// `devDependencies` of its root `package.json` or of one of its packages, the workspaces as npm
|
|
10
|
+
// maps them, read by `paquets` of scripts/paquets.mjs: a package out of the frame
|
|
11
|
+
// (`docs/agents/hors-cadre.txt`), which Turborepo never tests, counts for nothing) has its root
|
|
12
|
+
// scripts `test`, `test:unit`, `test:forcer` and `verifier` become the template's (`npm test`, the
|
|
13
|
+
// tests as Turborepo's tasks with its cache; `npm run test:forcer`, the same played for real;
|
|
14
|
+
// `npm run verifier`, ./verifier.mjs, the guards and the tests beside each other), when the
|
|
15
|
+
// Vitest of the project's root (`npx --no-install vitest`, the one `test:unit` calls) satisfies
|
|
16
|
+
// the range the template declares for `vitest`. Where the root resolves no Vitest or another
|
|
17
|
+
// version, the project's scripts stay (the frame's included) and the report names the version
|
|
18
|
+
// found and the range required. A `test` that runs anything else stays. A repository of packages
|
|
19
|
+
// keeps its tests in its packages: its root gets no `test:unit`, and the frame's own leaves.
|
|
20
|
+
// - A package of the frame whose code imports the frame's package (a file of its `src/` out of the
|
|
21
|
+
// tests, its imports read by TypeScript's `preProcessFile`) declares it in its `dependencies`, as
|
|
22
|
+
// npm puts there what the published code imports: a declaration in its `devDependencies` moves
|
|
23
|
+
// there with its range, else the range the root declares (else `^<version>`).
|
|
24
|
+
// - The frame's base configuration of Vitest is the package's (`@roomi-fields/grillhouse/vitest-config`),
|
|
25
|
+
// which each Vitest configuration imports by its name: in a project with `workspaces`, each
|
|
26
|
+
// package of the frame that plays tests (`joueDesTests`: its script `test:unit`) declares the
|
|
27
|
+
// frame's package in its `devDependencies`, at the range the root declares (else `^<version>`),
|
|
28
|
+
// a declaration it holds kept. The update writes no Vitest configuration.
|
|
29
|
+
// - The typing: each package of TypeScript (a `tsconfig.json`) that has no `typecheck` script
|
|
30
|
+
// receives the template's, `tsc -p tsconfig.json --noEmit`: each package of the frame in a
|
|
31
|
+
// project with `workspaces` (the root's `typecheck` stays the project's), the root in a project
|
|
32
|
+
// without. Witness: BPScript 320.21.4, whose type errors in test/ showed only at night.
|
|
33
|
+
// - `turbo.json` is the project's own file. A project with no `turbo.json` receives the frame's
|
|
34
|
+
// template of its form: `templates/turbo/paquets.json` when its package.json declares
|
|
35
|
+
// `workspaces`, else `templates/turbo/sans-paquets.json`. A `turbo.json` present is never written
|
|
36
|
+
// again; only the generator of the packages' turbo.json writes in it.
|
|
37
|
+
// - The generators: the boundaries' configuration (`.dependency-cruiser.cjs`), the index of the
|
|
38
|
+
// interfaces, and the turbo.json of each package in a repository with `workspaces`.
|
|
39
|
+
import { spawnSync } from 'node:child_process';
|
|
40
|
+
import { copyFileSync, existsSync, readFileSync, writeFileSync } from 'node:fs';
|
|
41
|
+
import { createRequire } from 'node:module';
|
|
42
|
+
import path from 'node:path';
|
|
43
|
+
import { CODE, paquets, TYPAGE } from '../../paquets.mjs';
|
|
44
|
+
import { sources } from '../../services-du-noyau.mjs';
|
|
45
|
+
import { estUnTest } from './regle-des-tests.mjs';
|
|
46
|
+
import { SCRIPT_DES_TESTS } from './script-des-tests.mjs';
|
|
47
|
+
|
|
48
|
+
// The frame's package, as a project declares it, and its base configuration of Vitest.
|
|
49
|
+
const PAQUET_DU_CADRE = '@roomi-fields/grillhouse';
|
|
50
|
+
const CONFIG_VITEST = `${PAQUET_DU_CADRE}/vitest-config`;
|
|
51
|
+
// The root scripts of the tests, written together from the template.
|
|
52
|
+
const SCRIPTS_DES_TESTS = ['test', SCRIPT_DES_TESTS, 'test:forcer', 'verifier'];
|
|
53
|
+
const CHAMPS_INSTALLES = ['dependencies', 'devDependencies', 'optionalDependencies'];
|
|
54
|
+
// The frame's templates of `turbo.json`, one per form of repository, read in the source.
|
|
55
|
+
const TURBO_PAQUETS = 'templates/turbo/paquets.json';
|
|
56
|
+
const TURBO_SANS_PAQUETS = 'templates/turbo/sans-paquets.json';
|
|
57
|
+
|
|
58
|
+
const ecrireJson = (f, v) => writeFileSync(f, `${JSON.stringify(v, null, 2)}\n`);
|
|
59
|
+
// <deps> written sorted by name, as npm writes them.
|
|
60
|
+
const trie = deps =>
|
|
61
|
+
Object.fromEntries(Object.entries(deps).sort(([a], [b]) => a.localeCompare(b, 'en')));
|
|
62
|
+
// The range at which the root package.json <p> declares the frame's package, or undefined.
|
|
63
|
+
const plageDeLaRacine = p =>
|
|
64
|
+
CHAMPS_INSTALLES.map(c => p[c]?.[PAQUET_DU_CADRE]).find(v => v !== undefined);
|
|
65
|
+
|
|
66
|
+
// Whether `vitest` is declared in the dependencies of the package.json <p> (read at <dossier>) or of
|
|
67
|
+
// one of its packages of the frame.
|
|
68
|
+
const declareVitest = (dossier, p) => {
|
|
69
|
+
const a = pkg => Boolean(pkg?.dependencies?.vitest ?? pkg?.devDependencies?.vitest);
|
|
70
|
+
return a(p) || paquets(dossier).some(({ pkg, hors }) => !hors && a(pkg));
|
|
71
|
+
};
|
|
72
|
+
// The version of the Vitest the project's root resolves, as `test:unit` calls it
|
|
73
|
+
// (`npx --no-install vitest --version`); null when it answers none.
|
|
74
|
+
const vitestDeLaRacine = projet => {
|
|
75
|
+
const r = spawnSync('npx', ['--no-install', 'vitest', '--version'], {
|
|
76
|
+
cwd: projet,
|
|
77
|
+
encoding: 'utf8',
|
|
78
|
+
});
|
|
79
|
+
return r.status === 0 ? (/vitest\/(\d+\.\d+\.\d+\S*)/.exec(r.stdout)?.[1] ?? null) : null;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// The frame's tests (Turborepo's tasks) in place of a project's own test that runs Vitest, in the
|
|
83
|
+
// root package.json <p>, from the template's <modele>: `{ test, vitest }`, each null when nothing
|
|
84
|
+
// is said.
|
|
85
|
+
function poserLesTests(projet, p, modele) {
|
|
86
|
+
const testDuCadre = modele.scripts?.test;
|
|
87
|
+
const testDuProjet = p.scripts?.test;
|
|
88
|
+
const vitestExige = modele.devDependencies?.vitest ?? modele.dependencies?.vitest;
|
|
89
|
+
const lanceVitest =
|
|
90
|
+
typeof testDuCadre === 'string' &&
|
|
91
|
+
typeof testDuProjet === 'string' &&
|
|
92
|
+
(testDuProjet === testDuCadre || /\bvitest\b/.test(testDuProjet) || declareVitest(projet, p));
|
|
93
|
+
if (!lanceVitest) {
|
|
94
|
+
return { test: null, vitest: null };
|
|
95
|
+
}
|
|
96
|
+
// semver, required here alone: the module loads where the package's dependencies are not
|
|
97
|
+
// installed (a copy of the frame's scripts, the night of a trial), and only this update reads it.
|
|
98
|
+
const semver = createRequire(import.meta.url)('semver');
|
|
99
|
+
// The root must resolve the Vitest the frame requires (`test:unit` calls it).
|
|
100
|
+
const trouvee = typeof vitestExige === 'string' ? vitestDeLaRacine(projet) : null;
|
|
101
|
+
const convient =
|
|
102
|
+
typeof vitestExige !== 'string' || (trouvee !== null && semver.satisfies(trouvee, vitestExige));
|
|
103
|
+
if (!convient) {
|
|
104
|
+
return { test: null, vitest: { trouvee, exigee: vitestExige } };
|
|
105
|
+
}
|
|
106
|
+
for (const nom of SCRIPTS_DES_TESTS) {
|
|
107
|
+
const script = modele.scripts?.[nom];
|
|
108
|
+
if (typeof script !== 'string') {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
// A repository of packages keeps its tests in its packages, as Turborepo does.
|
|
112
|
+
if (p.workspaces !== undefined && nom === SCRIPT_DES_TESTS) {
|
|
113
|
+
if (p.scripts[nom] === script) {
|
|
114
|
+
delete p.scripts[nom];
|
|
115
|
+
}
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
p.scripts[nom] = script;
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
test: testDuProjet !== testDuCadre ? { ancien: testDuProjet, nouveau: testDuCadre } : null,
|
|
122
|
+
vitest: null,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// Whether the code of the package at <dossier> of <projet> imports the frame's package (an entry of
|
|
127
|
+
// it): a file of its `src/` (CODE) out of the tests, its imports read by TypeScript
|
|
128
|
+
// (`preProcessFile`), a comment or a string importing nothing.
|
|
129
|
+
function codeImporteLeCadre(projet, dossier) {
|
|
130
|
+
const ts = createRequire(import.meta.url)('typescript');
|
|
131
|
+
return sources(projet, dossier)
|
|
132
|
+
.filter(f => new RegExp(CODE).test(f) && !estUnTest(f, projet)?.test)
|
|
133
|
+
.some(f =>
|
|
134
|
+
ts
|
|
135
|
+
.preProcessFile(readFileSync(path.join(projet, f), 'utf8'), true, true)
|
|
136
|
+
.importedFiles.some(
|
|
137
|
+
({ fileName: m }) => m === PAQUET_DU_CADRE || m.startsWith(`${PAQUET_DU_CADRE}/`)
|
|
138
|
+
)
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Declares the frame's package in the dependencies of each package of the frame whose code imports
|
|
143
|
+
// it (see the header): { nom, paquets }, or null when nothing changes.
|
|
144
|
+
function declarerDependanceDuCadre(projet, p, version) {
|
|
145
|
+
if (p.workspaces === undefined) {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
const racine = plageDeLaRacine(p);
|
|
149
|
+
const declarants = [];
|
|
150
|
+
for (const { dossier, pkg, hors } of paquets(projet)) {
|
|
151
|
+
const declare = ['dependencies', 'optionalDependencies'].some(
|
|
152
|
+
c => pkg[c]?.[PAQUET_DU_CADRE] !== undefined
|
|
153
|
+
);
|
|
154
|
+
if (hors || declare || !codeImporteLeCadre(projet, dossier)) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
const { [PAQUET_DU_CADRE]: dev, ...autres } = pkg.devDependencies ?? {};
|
|
158
|
+
pkg.dependencies = trie({
|
|
159
|
+
...(pkg.dependencies ?? {}),
|
|
160
|
+
[PAQUET_DU_CADRE]: dev ?? racine ?? `^${version}`,
|
|
161
|
+
});
|
|
162
|
+
if (dev !== undefined) {
|
|
163
|
+
pkg.devDependencies = autres;
|
|
164
|
+
}
|
|
165
|
+
ecrireJson(path.join(projet, dossier, 'package.json'), pkg);
|
|
166
|
+
declarants.push(dossier);
|
|
167
|
+
}
|
|
168
|
+
return declarants.length > 0 ? { nom: PAQUET_DU_CADRE, paquets: declarants } : null;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Declares the frame's package, whose base configuration of Vitest each Vitest configuration
|
|
172
|
+
// imports, in the devDependencies of each package of the frame that plays tests (see the header):
|
|
173
|
+
// { nom, paquets }, or null when nothing changes.
|
|
174
|
+
function poserConfigVitest(projet, p, version, joueDesTests) {
|
|
175
|
+
if (p.workspaces === undefined) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
const testes = paquets(projet).filter(
|
|
179
|
+
({ dossier, pkg, hors }) =>
|
|
180
|
+
!hors &&
|
|
181
|
+
joueDesTests(projet, {
|
|
182
|
+
dossier: path.join(projet, dossier),
|
|
183
|
+
nom: path.basename(dossier),
|
|
184
|
+
paquet: pkg.name ?? null,
|
|
185
|
+
})
|
|
186
|
+
);
|
|
187
|
+
const racine = plageDeLaRacine(p);
|
|
188
|
+
const declarants = [];
|
|
189
|
+
for (const { dossier, pkg } of testes) {
|
|
190
|
+
if (CHAMPS_INSTALLES.some(c => pkg[c]?.[PAQUET_DU_CADRE] !== undefined)) {
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
pkg.devDependencies = trie({
|
|
194
|
+
...(pkg.devDependencies ?? {}),
|
|
195
|
+
[PAQUET_DU_CADRE]: racine ?? `^${version}`,
|
|
196
|
+
});
|
|
197
|
+
ecrireJson(path.join(projet, dossier, 'package.json'), pkg);
|
|
198
|
+
declarants.push(dossier);
|
|
199
|
+
}
|
|
200
|
+
return declarants.length > 0 ? { nom: PAQUET_DU_CADRE, paquets: declarants } : null;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Gives the typing script of the template, <script>, to each package of TypeScript that has none
|
|
204
|
+
// (see the header): { script, paquets } (`.` for the root), or null when nothing changes.
|
|
205
|
+
function poserTypage(projet, p, script) {
|
|
206
|
+
if (typeof script !== 'string') {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
const types = dossier => existsSync(path.join(projet, dossier, 'tsconfig.json'));
|
|
210
|
+
const sans = pkg => typeof pkg.scripts?.[TYPAGE] !== 'string';
|
|
211
|
+
const declarants = [];
|
|
212
|
+
if (p.workspaces === undefined) {
|
|
213
|
+
if (types('.') && sans(p)) {
|
|
214
|
+
p.scripts = { ...(p.scripts ?? {}), [TYPAGE]: script };
|
|
215
|
+
declarants.push('.');
|
|
216
|
+
}
|
|
217
|
+
} else {
|
|
218
|
+
for (const { dossier, pkg, hors } of paquets(projet)) {
|
|
219
|
+
if (hors || !types(dossier) || !sans(pkg)) {
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
pkg.scripts = { ...(pkg.scripts ?? {}), [TYPAGE]: script };
|
|
223
|
+
ecrireJson(path.join(projet, dossier, 'package.json'), pkg);
|
|
224
|
+
declarants.push(dossier);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return declarants.length > 0 ? { script, paquets: declarants } : null;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
// Writes the `turbo.json` of the project at <projet>, when it has none, from the source's template
|
|
231
|
+
// of its form (`workspaces` declared in <p>); the template written, or null.
|
|
232
|
+
function poserTurbo(projet, p, source) {
|
|
233
|
+
const f = path.join(projet, 'turbo.json');
|
|
234
|
+
if (existsSync(f)) {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
const gabarit = p.workspaces !== undefined ? TURBO_PAQUETS : TURBO_SANS_PAQUETS;
|
|
238
|
+
if (!existsSync(path.join(source, gabarit))) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
copyFileSync(path.join(source, gabarit), f);
|
|
242
|
+
return gabarit;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// The lines of the report of the share <b>.
|
|
246
|
+
function rapport(b) {
|
|
247
|
+
const lignes = [];
|
|
248
|
+
if (b.configVitest) {
|
|
249
|
+
const { nom, paquets: declarants } = b.configVitest;
|
|
250
|
+
lignes.push(
|
|
251
|
+
`Configuration de base de Vitest : ${nom} déclaré dans les devDependencies de ${declarants.join(', ')}. \`npm install\` relie le paquet. La configuration Vitest de chaque paquet l'importe par son nom : \`import base from '${CONFIG_VITEST}'\`.`
|
|
252
|
+
);
|
|
253
|
+
}
|
|
254
|
+
if (b.dependanceDuCadre) {
|
|
255
|
+
const { nom, paquets: declarants } = b.dependanceDuCadre;
|
|
256
|
+
lignes.push(
|
|
257
|
+
`Dépendance d'exécution : ${nom} déclaré dans les dependencies de ${declarants.join(', ')}, dont le code hors des tests importe une entrée du paquet. \`npm install\` relie le paquet.`
|
|
258
|
+
);
|
|
259
|
+
}
|
|
260
|
+
if (b.typage) {
|
|
261
|
+
lignes.push(
|
|
262
|
+
`Typage : \`${b.typage.script}\` écrit dans ${b.typage.paquets.join(', ')} (le script typecheck, ses sources et ses tests, que son tsconfig.json inclut) ; \`npm run verifier\` le joue à côté des gardes et des tests.`
|
|
263
|
+
);
|
|
264
|
+
}
|
|
265
|
+
if (b.turbo) {
|
|
266
|
+
lignes.push(
|
|
267
|
+
`turbo.json écrit depuis le gabarit du cadre ${b.turbo} ; il est au projet, la mise à jour n'y touche plus.`
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
if (b.vitest) {
|
|
271
|
+
lignes.push(
|
|
272
|
+
`Vitest : la racine résout ${b.vitest.trouvee ?? 'aucune version'}, le cadre exige ${b.vitest.exigee} ; le script test du projet reste tel quel.`
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
if (b.test) {
|
|
276
|
+
lignes.push(
|
|
277
|
+
`Script test : \`${b.test.ancien}\` remplacé par le test du cadre \`${b.test.nouveau}\` (Turborepo : construction, puis tests ; une tâche dont rien n'a bougé est relue de son cache ; \`npm run verifier\` joue les gardes et les tests).`
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
return lignes;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/** @type {import('../../jointure.js').MiseAJour['appliquer']} */
|
|
284
|
+
function appliquer(projet, { p, modele, source, version }, joueDesTests) {
|
|
285
|
+
p.scripts ??= {};
|
|
286
|
+
const { test, vitest } = poserLesTests(projet, p, modele);
|
|
287
|
+
const bilan = {
|
|
288
|
+
test,
|
|
289
|
+
vitest,
|
|
290
|
+
dependanceDuCadre: declarerDependanceDuCadre(projet, p, version),
|
|
291
|
+
configVitest: poserConfigVitest(projet, p, version, joueDesTests),
|
|
292
|
+
typage: poserTypage(projet, p, modele.scripts?.[TYPAGE]),
|
|
293
|
+
turbo: poserTurbo(projet, p, source),
|
|
294
|
+
};
|
|
295
|
+
return {
|
|
296
|
+
bilan,
|
|
297
|
+
lignes: rapport(bilan),
|
|
298
|
+
installer: bilan.configVitest !== null || bilan.dependanceDuCadre !== null,
|
|
299
|
+
sansVerifier: bilan.vitest
|
|
300
|
+
? '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.'
|
|
301
|
+
: 'La mise à jour l’écrit dans un projet testé par Vitest ; sinon, écris-le pour ses tests.',
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* The share of the module typescript in the update, its components playing tests by <joueDesTests>.
|
|
307
|
+
* @param {(racine: string, c: import('../../jointure.js').Composant) => boolean} joueDesTests
|
|
308
|
+
* @returns {import('../../jointure.js').MiseAJour}
|
|
309
|
+
*/
|
|
310
|
+
export const miseAJour = joueDesTests => ({
|
|
311
|
+
gabarit: 'templates/projet',
|
|
312
|
+
appliquer: (projet, o) => appliquer(projet, o, joueDesTests),
|
|
313
|
+
generateurs: [
|
|
314
|
+
{ commande: 'frontieres', args: ['--ecrire'], sortie: '.dependency-cruiser.cjs' },
|
|
315
|
+
{ commande: 'index-interfaces', args: [], sortie: 'docs/agents/index-des-interfaces.md' },
|
|
316
|
+
{ commande: 'turbo-des-paquets', args: ['--ecrire'], sortie: null },
|
|
317
|
+
],
|
|
318
|
+
// No binary of the machine: nothing to install.
|
|
319
|
+
installation: null,
|
|
320
|
+
});
|
package/scripts/{references-par-les-types.mjs → langages/typescript/references-par-les-types.mjs}
RENAMED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
// repository's code (a declaration of a package, a member of a type, a function internal to a
|
|
4
4
|
// package), and its references are those the language service resolves to that symbol, never a
|
|
5
5
|
// text that happens to bear its name. scripts/composants-affectes.mjs runs it beside its survey
|
|
6
|
-
// by the names; scripts/elements-du-lot.mjs reads the declarations and the exports of a lot
|
|
6
|
+
// by the names; scripts/langages/typescript/elements-du-lot.mjs reads the declarations and the exports of a lot
|
|
7
7
|
// through the same service (`leService`).
|
|
8
8
|
//
|
|
9
9
|
// - The code read is the files of each component's `tsconfig.json` (its `include`), in one
|
|
10
10
|
// language service, so that a reference crosses packages. A workspace package's import resolves
|
|
11
11
|
// to its sources: the target of its `exports` (`.`), read back through its `tsconfig*.json` when
|
|
12
|
-
// it names a built file (`sorties` of scripts/frontieres.mjs), else `src/index.ts`.
|
|
12
|
+
// it names a built file (`sorties` of scripts/langages/typescript/frontieres.mjs), else `src/index.ts`.
|
|
13
13
|
// - An element (`A`, `A.b`, `f()`, `a().b`) resolves, from its last two names, to the member `b`
|
|
14
14
|
// of a type, interface or class `A` declared in a component; else, from its first name, to a
|
|
15
15
|
// declaration of that name at the top of a component's source, else to the members of that
|
|
@@ -216,7 +216,7 @@ function service(ts, racine, tous) {
|
|
|
216
216
|
// the production sources it reads (each `{ sf, c }`, the tests and the declaration files left
|
|
217
217
|
// out), `entree(c)` the source of the entry of the component <c> (or null), `publie(c, noeud)`
|
|
218
218
|
// whether that entry exports the symbol whose name is the node <noeud>; or `{ raison }` when it
|
|
219
|
-
// cannot run. scripts/elements-du-lot.mjs reads it.
|
|
219
|
+
// cannot run. scripts/langages/typescript/elements-du-lot.mjs reads it.
|
|
220
220
|
export function leService(racine, tous) {
|
|
221
221
|
const ts = requis('typescript');
|
|
222
222
|
const s = service(ts, racine, tous);
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// The rule of a test file of the module typescript, the fourth demand of the join
|
|
2
|
+
// (scripts/jointure.d.ts, `estUnTest`): what the testwriter writes, as Pants tells `python_tests`
|
|
3
|
+
// from `python_test_utils`. A file the testwriter writes is, one or several of:
|
|
4
|
+
//
|
|
5
|
+
// - `joue`: a test Vitest plays, its name `*.test.*` or `*.spec.*` of a module (`NOM_DE_TEST` of
|
|
6
|
+
// scripts/langages/typescript/consommateurs.mjs), wherever it lies;
|
|
7
|
+
// - `test`: a test file, or any file of a folder of tests (`test`, `tests`, `__tests__`), a helper
|
|
8
|
+
// the tests import (`isTestFile`);
|
|
9
|
+
// - `matiere`: a file of a package of the shared test material, a component of the repository
|
|
10
|
+
// whose package exports `./test-fixtures` (`matieres` of scripts/langages/typescript/consommateurs.mjs).
|
|
11
|
+
//
|
|
12
|
+
// Any other file is none of them: null.
|
|
13
|
+
import path from 'node:path';
|
|
14
|
+
import { matieres, NOM_DE_TEST } from './consommateurs.mjs';
|
|
15
|
+
|
|
16
|
+
const DOSSIERS = new Set(['test', 'tests', '__tests__']);
|
|
17
|
+
|
|
18
|
+
// Whether <file> (a path from the repository root) is a test file or a file of a folder of tests,
|
|
19
|
+
// read from the path alone.
|
|
20
|
+
export function isTestFile(file) {
|
|
21
|
+
const parts = file.split(/[\\/]/);
|
|
22
|
+
return parts.slice(0, -1).some(d => DOSSIERS.has(d)) || NOM_DE_TEST.test(parts.at(-1));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// True when <file> lies strictly under the directory <dir>.
|
|
26
|
+
function isInside(file, dir) {
|
|
27
|
+
const rel = path.relative(path.resolve(dir), file);
|
|
28
|
+
return rel !== '' && !rel.startsWith('..') && !path.isAbsolute(rel);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// What the testwriter writes in <chemin>, absolute or from the repository root <racine>:
|
|
32
|
+
// `{ joue, test, matiere }`, or null for a file it does not write.
|
|
33
|
+
export function estUnTest(chemin, racine) {
|
|
34
|
+
const abs = path.resolve(racine, chemin);
|
|
35
|
+
const joue = NOM_DE_TEST.test(path.basename(abs));
|
|
36
|
+
const test = isTestFile(path.relative(path.resolve(racine), abs));
|
|
37
|
+
const matiere = matieres(racine).some(m => isInside(abs, m.dir));
|
|
38
|
+
return joue || test || matiere ? { joue, test, matiere } : null;
|
|
39
|
+
}
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
// lintian holds a package's synopsis (`synopsis-too-long`) and clippy a doc's first paragraph
|
|
4
4
|
// (`too_long_first_doc_paragraph`). The index of the interfaces (`docs/agents/index-des-interfaces.md`)
|
|
5
5
|
// and the section « Ce que les composants d'avant publient » of a role agent's instruction carry
|
|
6
|
-
// that sentence for every element (scripts/index-interfaces.mjs).
|
|
6
|
+
// that sentence for every element (scripts/langages/typescript/index-interfaces.mjs).
|
|
7
7
|
//
|
|
8
8
|
// npx grillhouse resumes run from the repository root (a guard of grillhouse:gardes)
|
|
9
9
|
//
|
|
10
10
|
// - An element is an entry of the generated part of a component's `docs/INTERFACE.md`; its
|
|
11
|
-
// sentence is the one the index keeps (`lire` of scripts/index-interfaces.mjs), measured in
|
|
11
|
+
// sentence is the one the index keeps (`lire` of scripts/langages/typescript/index-interfaces.mjs), measured in
|
|
12
12
|
// characters. The generated part is the TSDoc summary of the export, which
|
|
13
|
-
// scripts/interfaces-contre-code.mjs keeps equal to the code.
|
|
13
|
+
// scripts/langages/typescript/interfaces-contre-code.mjs keeps equal to the code.
|
|
14
14
|
// - A refusal names the element at its interface (`<INTERFACE.md> § <element>`): the sentence is
|
|
15
15
|
// written in the documentation comment of the export, and `npm run api` carries it over.
|
|
16
16
|
// - A refusal inscribed in the project's debt (`grillhouse-dette.json`, see `dette.mjs`) passes,
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
import { existsSync, readFileSync } from 'node:fs';
|
|
20
20
|
import path from 'node:path';
|
|
21
21
|
import { pathToFileURL } from 'node:url';
|
|
22
|
-
import { trancher } from '
|
|
22
|
+
import { trancher } from '../../dette.mjs';
|
|
23
23
|
import { lire } from './index-interfaces.mjs';
|
|
24
24
|
import { aVerifier } from './interfaces-contre-code.mjs';
|
|
25
25
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// The script of the tests of a package of the module typescript, and its task of Turborepo: the one
|
|
2
|
+
// name the module reads and runs (`joueDesTests` of ./index.mjs, ./tests.mjs, ./verifier.mjs,
|
|
3
|
+
// ./verdict.mjs, ./turbo-des-paquets.mjs), neutral for every language (decision 4 of grillhouse-pkl).
|
|
4
|
+
|
|
5
|
+
/** The name of the script and of the task of the tests. */
|
|
6
|
+
export const SCRIPT_DES_TESTS = 'test:unit';
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The size of each test, on the model of the test pyramid of Google (Software Engineering at
|
|
3
|
+
// Google, ch. 11 and 14: small ~80 %, medium ~15 %, large ~5 %) and of Bazel's `size` (small,
|
|
4
|
+
// medium, large): a large test of the day is refused, as it belongs to the night.
|
|
5
|
+
//
|
|
6
|
+
// npx grillhouse tailles-des-tests run from the repository root (a guard of grillhouse:gardes)
|
|
7
|
+
//
|
|
8
|
+
// - The test files are those git lists in the repository, tracked or not, the ignored ones left
|
|
9
|
+
// out (`git ls-files -co --exclude-standard`), that Vitest's default `include` names; out of
|
|
10
|
+
// git, the files under the root, node_modules, dist, .git, .turbo and .claude left out.
|
|
11
|
+
// - A test is classed by a static reading of its text and of the test material it imports,
|
|
12
|
+
// followed from file to file: a file under a directory `test`, `tests` or `__tests__` imported by
|
|
13
|
+
// a relative path, or a package of the shared test material (whose package.json exports
|
|
14
|
+
// `./test-fixtures`, ./composants.mjs `matieres`) imported by its name
|
|
15
|
+
// (`@roomi-fields/grillhouse-matiere/test-fixtures`) or by a relative path, each of its files
|
|
16
|
+
// followed; a module of the product it imports is counted, not read: what it starts is its
|
|
17
|
+
// own. Bazel declares `size` by hand; the frame reads it from the text, so that every existing
|
|
18
|
+
// test is classed the day the rule arrives.
|
|
19
|
+
// - large (`grand`): it mounts a trial repository (git's `init`, `clone` or `worktree add`) and
|
|
20
|
+
// starts there something else than git (node, npm, a shell, a binary of the product);
|
|
21
|
+
// - medium (`moyen`): it starts a process (it imports `child_process`, `execa` or `zx`), or it
|
|
22
|
+
// imports several modules of the repository;
|
|
23
|
+
// - small (`petit`): it imports one module of the repository at most, and starts no process.
|
|
24
|
+
// - A large test of the day is a finding, `{ fichier, regle: 'grand-de-jour', message }`; a night
|
|
25
|
+
// test or a time budget bench (HORS_DU_JOUR, ./vitest-config/cibles.mjs) is never one. A finding
|
|
26
|
+
// inscribed in the project's debt (`grillhouse-dette.json`, ./dette.mjs) passes: the large tests
|
|
27
|
+
// of the day that exist when the rule arrives are inscribed there by the update
|
|
28
|
+
// (./migrations/0.25.0-tailles-des-tests.mjs), the count never rises, and a new one is refused.
|
|
29
|
+
// - The guard writes on its error stream the count of each size, the night's included.
|
|
30
|
+
import { spawnSync } from 'node:child_process';
|
|
31
|
+
import { globSync, readFileSync } from 'node:fs';
|
|
32
|
+
import path from 'node:path';
|
|
33
|
+
import { pathToFileURL } from 'node:url';
|
|
34
|
+
import { trancher } from '../../dette.mjs';
|
|
35
|
+
import { matieres } from './composants.mjs';
|
|
36
|
+
import { HORS_DU_JOUR } from './vitest-config/cibles.mjs';
|
|
37
|
+
import {
|
|
38
|
+
IMPORT,
|
|
39
|
+
lireLeDisque,
|
|
40
|
+
MATIERE,
|
|
41
|
+
resoudreRelatif as resoudre,
|
|
42
|
+
TEST,
|
|
43
|
+
} from './vitest-config/lances.mjs';
|
|
44
|
+
|
|
45
|
+
export const GARDE = 'tailles-des-tests';
|
|
46
|
+
export const GRAND_DE_JOUR = 'grand-de-jour';
|
|
47
|
+
|
|
48
|
+
// The import of a way to start a process.
|
|
49
|
+
const PROCESSUS = /['"](?:node:)?child_process['"]|['"]execa['"]|['"]zx['"]/;
|
|
50
|
+
// A trial repository mounted: git's `init`, `clone` or `worktree add`, as an argument or a command.
|
|
51
|
+
const DEPOT_D_ESSAI =
|
|
52
|
+
/['"`](?:init|clone)['"`]|\bgit\s+(?:-C\s+\S+\s+)?(?:init|clone)\b|['"`]worktree['"`]\s*,\s*['"`]add['"`]|\bworktree\s+add\b/;
|
|
53
|
+
// A call that starts a process, its first argument captured; `.exec(` (a regular expression) is
|
|
54
|
+
// none.
|
|
55
|
+
const APPEL =
|
|
56
|
+
/(?:(?<![\w$])(?:spawnSync|spawn|execFileSync|execFile|execSync|fork|execaSync|execa)|(?<![.\w$])exec)\s*\(\s*([^,)\n]*)/g;
|
|
57
|
+
// A first argument that names git.
|
|
58
|
+
const GIT = /^['"`]git(?:['"`]|\s)/;
|
|
59
|
+
// A re-export of a whole module.
|
|
60
|
+
const TOUT_REEXPORTE = /\bexport\s*\*\s*from\b/;
|
|
61
|
+
// The names an import clause <clause> takes in braces (`import { a, b as c }` gives a and b);
|
|
62
|
+
// null for a clause without braces (a namespace, a default), which takes the whole module.
|
|
63
|
+
function nomsImportes(clause) {
|
|
64
|
+
const b = /\{([^}]*)\}/.exec(clause);
|
|
65
|
+
if (!b) return null;
|
|
66
|
+
return b[1]
|
|
67
|
+
.split(',')
|
|
68
|
+
.map(p =>
|
|
69
|
+
p
|
|
70
|
+
.replace(/^\s*type\s+/, '')
|
|
71
|
+
.split(/\s+as\s+/)[0]
|
|
72
|
+
.trim()
|
|
73
|
+
)
|
|
74
|
+
.filter(Boolean);
|
|
75
|
+
}
|
|
76
|
+
// Whether the text <texte> declares and exports the name <nom>.
|
|
77
|
+
const declare = (texte, nom) =>
|
|
78
|
+
new RegExp(
|
|
79
|
+
`\\bexport\\s+(?:declare\\s+)?(?:async\\s+)?(?:function\\*?|const|let|var|class|type|interface|enum)\\s+${nom}\\b|\\bexport\\s*\\{[^}]*\\b${nom}\\b[^}]*\\}`
|
|
80
|
+
).test(texte);
|
|
81
|
+
|
|
82
|
+
// The entry `./test-fixtures` of the package.json <paquet>, a path from its directory: its value,
|
|
83
|
+
// or its condition `import`, `default` or `require`; null without one.
|
|
84
|
+
function entreeDeLaMatiere(paquet) {
|
|
85
|
+
const v = paquet?.exports?.['./test-fixtures'];
|
|
86
|
+
const e = typeof v === 'string' ? v : (v?.import ?? v?.default ?? v?.require);
|
|
87
|
+
return typeof e === 'string' ? e : null;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// The packages of the shared test material of the repository at <racine>: `[{ nom, dir, entree }]`,
|
|
91
|
+
// `nom` the name by which a test imports it, `dir` its directory and `entree` the file of its
|
|
92
|
+
// entry `./test-fixtures`, absolute.
|
|
93
|
+
function lesMatieres(racine) {
|
|
94
|
+
return matieres(racine).flatMap(({ dir, paquet }) => {
|
|
95
|
+
let pkg;
|
|
96
|
+
try {
|
|
97
|
+
pkg = JSON.parse(readFileSync(path.join(dir, 'package.json'), 'utf8'));
|
|
98
|
+
} catch {
|
|
99
|
+
return [];
|
|
100
|
+
}
|
|
101
|
+
const e = entreeDeLaMatiere(pkg);
|
|
102
|
+
return paquet && e ? [{ nom: paquet, dir, entree: path.resolve(dir, e) }] : [];
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* The size of the test file <fichier> (absolute), read by <lire> (a path → its text, null when it
|
|
108
|
+
* does not read), in the repository at <racine>, whose packages of the shared test material are
|
|
109
|
+
* <lesMatieres> (`[{ nom, dir, entree }]`, absolute paths): `{ taille, modules }`, `taille` one of
|
|
110
|
+
* `petit`, `moyen`, `grand`, `modules` the modules of the repository it imports (the test material
|
|
111
|
+
* followed, not counted).
|
|
112
|
+
*/
|
|
113
|
+
export function classer(fichier, lire, racine = path.parse(fichier).root, lesMatieres = []) {
|
|
114
|
+
const dansUneMatiere = f =>
|
|
115
|
+
lesMatieres.some(m => {
|
|
116
|
+
const r = path.relative(m.dir, f);
|
|
117
|
+
return r !== '' && !r.startsWith('..') && !path.isAbsolute(r);
|
|
118
|
+
});
|
|
119
|
+
const textes = [];
|
|
120
|
+
const modules = new Set();
|
|
121
|
+
const vus = new Set();
|
|
122
|
+
// <f> followed; with <noms>, the names a test imports of it, its re-exports of a whole module
|
|
123
|
+
// (`export * from`) are followed only to a module that declares one of them.
|
|
124
|
+
const suivre = (f, noms = null) => {
|
|
125
|
+
const cle = noms ? `${f}#${noms.join(',')}` : f;
|
|
126
|
+
if (vus.has(f) || vus.has(cle)) return;
|
|
127
|
+
vus.add(cle);
|
|
128
|
+
const texte = lire(f) ?? '';
|
|
129
|
+
textes.push(texte);
|
|
130
|
+
for (const m of texte.matchAll(IMPORT)) {
|
|
131
|
+
const spec = m[1] ?? m[2] ?? m[3] ?? m[4];
|
|
132
|
+
const parSonNom = lesMatieres.find(x => spec === `${x.nom}/test-fixtures`);
|
|
133
|
+
if (parSonNom) {
|
|
134
|
+
suivre(parSonNom.entree, nomsImportes(m[0]));
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (!spec?.startsWith('.')) continue;
|
|
138
|
+
const cible = resoudre(f, spec, lire);
|
|
139
|
+
if (!cible) continue;
|
|
140
|
+
if (noms && TOUT_REEXPORTE.test(m[0]) && !noms.some(n => declare(lire(cible) ?? '', n))) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
const rel = path.relative(racine, cible).split(path.sep).join('/');
|
|
144
|
+
if ((MATIERE.test(rel) || dansUneMatiere(cible)) && !TEST.test(rel)) suivre(cible);
|
|
145
|
+
else modules.add(cible);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
suivre(fichier);
|
|
149
|
+
const tout = textes.join('\n');
|
|
150
|
+
const processus = PROCESSUS.test(tout);
|
|
151
|
+
const autreQueGit = [...tout.matchAll(APPEL)].some(m => !GIT.test(m[1].trim()));
|
|
152
|
+
const taille =
|
|
153
|
+
processus && autreQueGit && DEPOT_D_ESSAI.test(tout)
|
|
154
|
+
? 'grand'
|
|
155
|
+
: processus || modules.size > 1
|
|
156
|
+
? 'moyen'
|
|
157
|
+
: 'petit';
|
|
158
|
+
return { taille, modules: [...modules] };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Whether <r>, a path from the root, is a night test or a time budget bench.
|
|
162
|
+
const horsDuJour = r => HORS_DU_JOUR.some(p => path.matchesGlob(r, p));
|
|
163
|
+
|
|
164
|
+
// The directories a listing out of git leaves out.
|
|
165
|
+
const HORS = /(?:^|\/)(?:node_modules|dist|\.git|\.turbo|\.claude)$/;
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* The test files of the repository at <racine>, as git lists them (out of git, the files under it,
|
|
169
|
+
* node_modules, dist, .git, .turbo and .claude left out), each path from its root, sorted.
|
|
170
|
+
*/
|
|
171
|
+
export function testsDuDepot(racine) {
|
|
172
|
+
const r = spawnSync('git', ['-C', racine, 'ls-files', '-co', '--exclude-standard', '-z'], {
|
|
173
|
+
encoding: 'utf8',
|
|
174
|
+
maxBuffer: 256 * 1024 * 1024,
|
|
175
|
+
});
|
|
176
|
+
const fichiers =
|
|
177
|
+
r.status === 0
|
|
178
|
+
? r.stdout.split('\0')
|
|
179
|
+
: globSync('**/*', { cwd: racine, exclude: d => HORS.test(d) });
|
|
180
|
+
return [...new Set(fichiers.filter(f => TEST.test(f)))].sort();
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** Each test file of the repository at <racine> and its size: `[{ fichier, taille, nuit }]`. */
|
|
184
|
+
export function tailles(racine) {
|
|
185
|
+
const m = lesMatieres(racine);
|
|
186
|
+
return testsDuDepot(racine).map(fichier => ({
|
|
187
|
+
fichier,
|
|
188
|
+
taille: classer(path.join(racine, fichier), lireLeDisque, racine, m).taille,
|
|
189
|
+
nuit: horsDuJour(fichier),
|
|
190
|
+
}));
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* The findings of the repository at <racine>: one `{ fichier, regle, message }` per large test of
|
|
195
|
+
* the day, in the debt's form (./dette.mjs).
|
|
196
|
+
*/
|
|
197
|
+
export function verifier(racine) {
|
|
198
|
+
return tailles(racine)
|
|
199
|
+
.filter(t => t.taille === 'grand' && !t.nuit)
|
|
200
|
+
.map(({ fichier }) => ({
|
|
201
|
+
fichier,
|
|
202
|
+
regle: GRAND_DE_JOUR,
|
|
203
|
+
message: `${fichier} : un grand test (il monte un dépôt d'essai et y lance le produit ou le cadre) est un test de nuit, jamais joué au fil du travail ; il se renomme en *.nuit.test.*, ou il se réduit à la plus petite taille qui prouve son critère.`,
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
|
|
208
|
+
const racine = process.cwd();
|
|
209
|
+
const toutes = tailles(racine);
|
|
210
|
+
const compte = t => toutes.filter(x => x.taille === t).length;
|
|
211
|
+
const nuit = toutes.filter(x => x.nuit).length;
|
|
212
|
+
const { refus, lignes } = trancher(racine, GARDE, verifier(racine));
|
|
213
|
+
for (const r of refus) process.stderr.write(`⛔ ${r.message}\n`);
|
|
214
|
+
for (const l of lignes) process.stderr.write(`${l}\n`);
|
|
215
|
+
process.stderr.write(
|
|
216
|
+
`ℹ️ ${GARDE} : ${toutes.length} fichier(s) de tests, ${compte('petit')} petit(s), ${compte('moyen')} moyen(s), ${compte('grand')} grand(s) ; ${nuit} de nuit ou de banc.\n`
|
|
217
|
+
);
|
|
218
|
+
process.exitCode = refus.length ? 1 : 0;
|
|
219
|
+
}
|