@roomi-fields/grillhouse 0.24.4 → 0.24.5

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.
@@ -5,5 +5,5 @@
5
5
  "author": {
6
6
  "name": "Romain Peyrichou"
7
7
  },
8
- "version": "0.24.4"
8
+ "version": "0.24.5"
9
9
  }
@@ -24,10 +24,17 @@ hit, replaying logs »), et cette relecture vaut un lancement. Une passe se mesu
24
24
  dernier vert, l'arbre de la dernière passe verte de sa branche, celle de main pour une copie
25
25
  qui n'en a pas encore, comme `vitest --changed` : un paquet que Turborepo rejoue joue les seuls tests que Vitest relie aux fichiers changés depuis,
26
26
  et tous ses tests quand un changement sort du graphe de Vitest (un fichier supprimé, une
27
- configuration, un fichier qu'aucun module n'importe, le code d'un paquet dont il dépend, un
28
- chemin que ses tests déclarent lire, `grillhouse.lit`) ; sans vert connu, la passe est
29
- complète, et `npm run verifier -- --tout` la joue pour de vrai, comme la nuit. Ainsi un test ne
30
- tourne qu'une fois tant que rien ne change, et corriger un test ne rejoue que lui.
27
+ configuration, un fichier qu'aucun module n'importe, un fichier, changé ou supprimé, que lit
28
+ la construction d'un paquet dont il dépend, un chemin que ses tests déclarent lire,
29
+ `grillhouse.lit`) ; la construction d'un voisin lit les entrées du `build` de son turbo.json,
30
+ lues comme Turborepo les lit (`$TURBO_DEFAULT$` : tous les fichiers du paquet, `docs/`
31
+ compris ; `$TURBO_EXTENDS$` : les entrées du `build` de la racine), et, quand elles n'en
32
+ nomment aucune, son code et sa configuration hors de son `docs/` ; jamais un test ; sans vert
33
+ connu, la passe est complète, et `npm run verifier -- --tout` la joue pour de vrai, comme la
34
+ nuit. Un fichier que le commit du vert ne suit pas vit dans le seul arbre qui l'a gardé :
35
+ absent d'une copie mesurée contre le vert de main, il n'est pas supprimé, comme Nx et
36
+ Turborepo mesurent contre un commit. Ainsi un test ne tourne qu'une fois tant que rien ne
37
+ change, et corriger un test ne rejoue que lui.
31
38
 
32
39
  **Tout se lit, le plan s'écrit** : un agent de rôle travaille dans l'enveloppe de sa copie
33
40
  (`packages/grillhouse/scripts/enveloppe/`, un bac à sable bubblewrap) ; il lit toute la copie,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roomi-fields/grillhouse",
3
- "version": "0.24.4",
3
+ "version": "0.24.5",
4
4
  "description": "Roomi's Grillhouse: the frame's scripts, called by one command, grillhouse <sous-commande>",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -18,6 +18,12 @@
18
18
  // the repository. Then the changes are the files that differ between its tree and the tree of the
19
19
  // working tree now (`git diff --raw --no-renames`): the files changed or added, and those
20
20
  // removed. Any two trees compare: the ancestry keeps the measure to the history it belongs to.
21
+ // - A file the last green holds and its commit does not track (untracked, not ignored) lives in
22
+ // the working tree that kept it alone: measured against the last green of another branch (main's,
23
+ // from a copy or from the queue's detached replay), its absence is no removal, as Nx affected and
24
+ // Turborepo's `--filter=[ref]` measure against a commit. Against the branch's own, it is one: the
25
+ // copy created that file, then removed it. Witness: BPScript 320.3.2.1, 54 `.rapport-suite.json`
26
+ // untracked on main, each seen removed by every package of a copy, which played whole 264 times.
21
27
  // - No last green counts without git, before the first commit, and while a submodule differs
22
28
  // from the commit its parent records (its files changed, or its HEAD moved) or the changes
23
29
  // reach a submodule: git's tree holds a submodule's commit, not its files. The pass is then
@@ -169,6 +175,21 @@ function difference(racine, avant, apres) {
169
175
  return out;
170
176
  }
171
177
 
178
+ // The files the commit <commit> of the repository at <racine> tracks that the tree <arbre> no longer
179
+ // holds, as a Set of paths from its top; null when git fails.
180
+ function supprimesDuCommit(racine, commit, arbre) {
181
+ const r = git(racine, [
182
+ 'diff',
183
+ '--name-only',
184
+ '--no-renames',
185
+ '--diff-filter=D',
186
+ '-z',
187
+ commit,
188
+ arbre,
189
+ ]);
190
+ return r.status === 0 ? new Set(r.stdout.split('\0').filter(Boolean)) : null;
191
+ }
192
+
172
193
  // What a pass in <racine> measures itself against: `{ etat, env, ligne, retirer }`, the state to
173
194
  // keep once green (null when none can count), the variables to add to the pass's environment (the
174
195
  // changes since the last green, none for a complete pass), the line that says which, and the
@@ -192,6 +213,11 @@ export function mesure(racine, { tout = false, dans = os.tmpdir() } = {}) {
192
213
  if (ch.sousModules.length) {
193
214
  return { ...complete(`un sous-module a changé (${ch.sousModules[0]})`), etat: null };
194
215
  }
216
+ if (vert.branche !== etat.branche) {
217
+ const suivis = supprimesDuCommit(etat.racine, vert.commit, etat.arbre);
218
+ if (!suivis) return complete('git échoue');
219
+ ch.supprimes = ch.supprimes.filter(f => suivis.has(f));
220
+ }
195
221
  const dir = mkdtempSync(path.join(dans, 'grillhouse-changements-'));
196
222
  const fichier = path.join(dir, 'changements.json');
197
223
  writeFileSync(
@@ -16,7 +16,8 @@
16
16
  // - The graph of a test is the test file and the modules it imports, statically or dynamically,
17
17
  // node_modules left out (`getTestDependencies` of Vitest). Vitest does not see what lies out of
18
18
  // it, and the package plays whole (`entier`) when a change lies there, the reason written:
19
- // 1. a file removed, in the package or in a package it depends on: no graph of today holds it;
19
+ // 1. a file removed in the package: no graph of today holds it (one removed in a package it
20
+ // depends on, as 6 has it);
20
21
  // 2. the frame's base configuration (this directory), which every configuration extends;
21
22
  // 3. the configuration of the repository at its top: `package.json`, `package-lock.json`,
22
23
  // `turbo.json`, `turbo.jsonc`, `tsconfig*.json`;
@@ -25,10 +26,18 @@
25
26
  // `globalSetup`, which Vitest runs beside the graph;
26
27
  // 5. a path its tests declare they read (`grillhouse.lit` of its package.json, from the top):
27
28
  // a script they run, a file they read, as Bazel's `data`;
28
- // 6. a file of a package it depends on (its `dependencies`, `devDependencies`,
29
- // `optionalDependencies` and `peerDependencies` that resolve to a directory of the repository,
30
- // out of node_modules, transitively), a test file of that package aside: its tests read that
31
- // package built, not the source git follows;
29
+ // 6. a file, changed or removed, that the build of a package it depends on reads (its
30
+ // `dependencies`, `devDependencies`, `optionalDependencies` and `peerDependencies` that
31
+ // resolve to a directory of the repository, out of node_modules, transitively): its tests read
32
+ // that package built, not the source git follows. As Turborepo hashes the inputs of a
33
+ // neighbour's `build` task and Bazel the `srcs` of its target, the build reads the inputs of
34
+ // the `build` of the neighbour's turbo.json, the one scripts/turbo-des-paquets.mjs generates,
35
+ // as Turborepo reads them: each pattern from the package, `$TURBO_ROOT$/…` from the top, `!…`
36
+ // an exclusion, `<x>/**` covering `<x>` itself, `$TURBO_DEFAULT$` every file of the package,
37
+ // `$TURBO_EXTENDS$` the inputs of the root's `build` (turbo.json or turbo.jsonc). When they
38
+ // name none (no turbo.json, no inputs), its files of code and configuration (the extension of
39
+ // a module), out of its `docs/`, its exclusions kept. A test file of the neighbour is never
40
+ // one: its build does not compile it;
32
41
  // 7. a file of the package that no graph can hold, its extension not that of a module (`.js`,
33
42
  // `.mjs`, `.cjs`, `.ts`, `.mts`, `.cts`, `.jsx`, `.tsx`, `.json`): data, a template, a
34
43
  // script of the shell, a document, which a test reads without importing it.
@@ -39,8 +48,10 @@
39
48
  // plays, changed or not. A package where none relates plays none and passes
40
49
  // (`passWithNoTests`), as Vitest's `--changed` has it.
41
50
  //
42
- // This module uses Node alone.
51
+ // This module's top level uses Node alone (./cibles.mjs, scripts/tests.mjs import it); a
52
+ // turbo.json is read with jsonc-parser, the frame's reader of JSON with comments, loaded then.
43
53
  import { existsSync, readFileSync, realpathSync } from 'node:fs';
54
+ import { createRequire } from 'node:module';
44
55
  import path from 'node:path';
45
56
  import { fileURLToPath } from 'node:url';
46
57
 
@@ -79,6 +90,46 @@ export function lireChangements(chemin) {
79
90
  return c;
80
91
  }
81
92
 
93
+ // The prefix of a pattern of Turborepo written from the top of the repository.
94
+ const DU_HAUT = '$TURBO_ROOT$/';
95
+
96
+ // The inputs of the `build` of the Turborepo configuration in <dir> (its <noms>, the first
97
+ // present): the patterns, an empty list when it names none or does not read.
98
+ function entreesDuBuild(dir, noms) {
99
+ const f = noms.map(n => path.join(dir, n)).find(n => existsSync(n));
100
+ if (!f) return [];
101
+ try {
102
+ const { parse } = createRequire(import.meta.url)('jsonc-parser');
103
+ const inputs = parse(readFileSync(f, 'utf8'), [], { allowTrailingComma: true })?.tasks?.build
104
+ ?.inputs;
105
+ return Array.isArray(inputs) ? inputs.filter(m => typeof m === 'string') : [];
106
+ } catch {
107
+ return [];
108
+ }
109
+ }
110
+
111
+ // Whether the build of the package at <d>, in the repository at <racine>, reads the file at the
112
+ // absolute path <a>, which lies in it (6 above).
113
+ function construit(racine, d, a) {
114
+ const r = path.relative(d, a);
115
+ if (TEST.test(r)) return false;
116
+ const motifs = entreesDuBuild(d, ['turbo.json']).flatMap(m =>
117
+ m === '$TURBO_EXTENDS$' ? entreesDuBuild(racine, ['turbo.json', 'turbo.jsonc']) : [m]
118
+ );
119
+ // <m> covers <rel>, `<x>/**` covering `<x>` as Turborepo has it.
120
+ const couvre = (rel, m) =>
121
+ path.matchesGlob(rel, m) || (m.endsWith('/**') && path.matchesGlob(rel, m.slice(0, -3)));
122
+ const lu = m =>
123
+ m === '$TURBO_DEFAULT$' ||
124
+ (m.startsWith(DU_HAUT)
125
+ ? couvre(path.relative(racine, a), m.slice(DU_HAUT.length))
126
+ : couvre(r, m));
127
+ if (motifs.some(m => m.startsWith('!') && lu(m.slice(1)))) return false;
128
+ const positifs = motifs.filter(m => !m.startsWith('!'));
129
+ if (positifs.length) return positifs.some(lu);
130
+ return MODULE.test(r) && r.split(path.sep)[0] !== 'docs';
131
+ }
132
+
82
133
  // The directories of the packages of the repository at <racine> that the package at <dossier>
83
134
  // depends on, transitively, itself left out.
84
135
  function dependances(racine, dossier) {
@@ -129,7 +180,8 @@ function paquetEntier(ch, dossier, test = {}) {
129
180
  .filter(f => typeof f === 'string')
130
181
  .map(f => path.resolve(dossier, f));
131
182
  for (const f of ch.supprimes) {
132
- if ([dossier, ...deps].some(d => sous(abs(f), d))) {
183
+ const a = abs(f);
184
+ if (sous(a, dossier) || deps.some(d => sous(a, d) && construit(racine, d, a))) {
133
185
  return { raison: 'un fichier supprimé, que le graphe des tests ne tient plus', fichier: f };
134
186
  }
135
187
  }
@@ -145,7 +197,7 @@ function paquetEntier(ch, dossier, test = {}) {
145
197
  ? 'un fichier de préparation des tests'
146
198
  : lit.some(l => f === l || f.startsWith(`${l}/`))
147
199
  ? 'un chemin que ses tests déclarent lire (grillhouse.lit)'
148
- : deps.some(d => sous(a, d)) && !TEST.test(f)
200
+ : deps.some(d => sous(a, d) && construit(racine, d, a))
149
201
  ? 'le code d’un paquet dont il dépend, que ses tests lisent construit'
150
202
  : sous(a, dossier) && !MODULE.test(f)
151
203
  ? 'un fichier qu’aucun module n’importe, qu’un test lit sans l’importer'