@roomi-fields/grillhouse 0.24.0 → 0.24.2

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.0"
8
+ "version": "0.24.2"
9
9
  }
@@ -71,7 +71,6 @@
71
71
  "zod": "^3.22.0"
72
72
  },
73
73
  "devDependencies": {
74
- "@microsoft/api-extractor": "7.59.2",
75
74
  "@types/node": "^20.0.0",
76
75
  "@typescript-eslint/eslint-plugin": "^7.0.0",
77
76
  "@typescript-eslint/parser": "^7.0.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
3
- "extends": ["@microsoft/api-extractor/extends/tsdoc-base.json"],
3
+ "extends": ["@roomi-fields/grillhouse/tsdoc-base.json"],
4
4
  "tagDefinitions": [{ "tagName": "@faute", "syntaxKind": "block", "allowMultiple": true }],
5
5
  "supportForTags": { "@faute": true }
6
6
  }
@@ -211,6 +211,13 @@ la fonction, sans réexport, avec sa déclaration de types à côté (`scripts/<
211
211
  `@roomi-fields/grillhouse/consommateurs` (`matieres`, les paquets de la matière de test
212
212
  partagée), `@roomi-fields/grillhouse/paquets` (`horsCadre`, les paquets hors cadre), et la
213
213
  configuration de base de Vitest, `@roomi-fields/grillhouse/vitest-config` et
214
- `@roomi-fields/grillhouse/vitest-config/mesure`. Une entrée s'ajoute ou se retire avec ce
215
- paragraphe, que `tests/unit/paquet-publie.spec.ts` confronte au champ `exports`. Ainsi une
216
- version du paquet dit ce qu'un projet peut importer, et ce qu'elle lui retire.
214
+ `@roomi-fields/grillhouse/vitest-config/mesure`, et la base TSDoc,
215
+ `@roomi-fields/grillhouse/tsdoc-base.json`, dont hérite le `tsdoc.json` d'un projet : elle hérite
216
+ de celle d'API Extractor, que le paquet déclare, comme un rig de Rushstack porte la configuration
217
+ de base à côté de la dépendance qu'elle nomme ; TSDoc lit un `extends` par son chemin sous le
218
+ paquet, sans le champ `exports`, et le fichier se tient donc à la racine du paquet. Une entrée s'ajoute ou se retire avec ce
219
+ paragraphe, que `tests/unit/paquet-publie.spec.ts` confronte au champ `exports`. Un paquet du
220
+ projet dont le code de `src/` hors des tests importe une entrée déclare le paquet du cadre dans
221
+ ses `dependencies`, comme npm y met ce que le code publié importe : `npx grillhouse maj` l'y
222
+ place, ses imports lus par TypeScript. Ainsi une version du paquet dit ce qu'un projet peut
223
+ importer, et ce qu'elle lui retire.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roomi-fields/grillhouse",
3
- "version": "0.24.0",
3
+ "version": "0.24.2",
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",
@@ -23,6 +23,7 @@
23
23
  "hooks",
24
24
  "scripts",
25
25
  "skills",
26
+ "tsdoc-base.json",
26
27
  "types"
27
28
  ],
28
29
  "bin": {
@@ -49,7 +50,8 @@
49
50
  "./vitest-config/mesure": {
50
51
  "types": "./scripts/vitest-config/mesure.d.ts",
51
52
  "default": "./scripts/vitest-config/mesure.mjs"
52
- }
53
+ },
54
+ "./tsdoc-base.json": "./tsdoc-base.json"
53
55
  },
54
56
  "scripts": {
55
57
  "prepack": "node scripts/cadre.mjs --empaqueter",
package/scripts/cadre.mjs CHANGED
@@ -39,8 +39,11 @@ const INSTALLE = PAQUET.split(path.sep).includes('node_modules');
39
39
  /** The frame's files the package reads under CADRE, which `--empaqueter` copies under cadre/. */
40
40
  export const FICHIERS_DU_CADRE = ['templates'];
41
41
 
42
- /** The entries the package publishes of its own; `docs/` holds the architecture the charter names. */
43
- export const PROPRES_DU_PAQUET = ['bin', 'cadre', 'docs', 'scripts'];
42
+ /**
43
+ * The entries the package publishes of its own; `docs/` holds the architecture the charter names,
44
+ * `tsdoc-base.json` the TSDoc base a project's tsdoc.json extends.
45
+ */
46
+ export const PROPRES_DU_PAQUET = ['bin', 'cadre', 'docs', 'scripts', 'tsdoc-base.json'];
44
47
 
45
48
  /** The entries of the plugin's source the package leaves out. */
46
49
  export const HORS_DU_GREFFON = ['tests', 'tsconfig.json'];
@@ -47,8 +47,10 @@ import { trancher } from './dette.mjs';
47
47
 
48
48
  export const CONFIGURATION = '.dependency-cruiser.cjs';
49
49
  export const RACINES = ['src', 'packages'];
50
- const TESTS = '(^|/)(test|tests|__tests__)/|[.](test|spec)[.][a-z]+$';
51
- const CODE = '^src/|^packages/[^/]+/src/';
50
+ /** The test files, as a pattern of a path from the repository's root. */
51
+ export const TESTS = '(^|/)(test|tests|__tests__)/|[.](test|spec)[.][a-z]+$';
52
+ /** The code of `src/` (the root's, or a package's under `packages/`), as a pattern of such a path. */
53
+ export const CODE = '^src/|^packages/[^/]+/src/';
52
54
  const REGLE_OUTILS = 'pas-d-outil-de-developpement-dans-le-code';
53
55
  // The environment variable naming the file that holds the pattern of the published files.
54
56
  const JUGES = 'GRILLHOUSE_JUGES';
@@ -19,7 +19,7 @@
19
19
  // the project keeps the version it recorded, so that the next update plays that migration again.
20
20
  // Last, after the update and the regeneration, what stays to the project (`restes` of a
21
21
  // migration played, scripts/migrations.mjs: in 0.24.0, a file that still calls a former copy of
22
- // the frame) is reported on the standard output, « reste au projet », with no effect on the exit
22
+ // the frame; in 0.24.2, API Extractor still declared by the project) is reported on the standard output, « reste au projet », with no effect on the exit
23
23
  // code nor on the version recorded.
24
24
  // - The frame copies no file into a project: its scripts are the package's, its skills, agents,
25
25
  // hooks of Claude Code, common charter and meta-frame the plugin's, which the package carries
@@ -65,15 +65,17 @@
65
65
  // A `turbo.json` present is never written again by the update; only the generator of the
66
66
  // packages' turbo.json (below) writes in it the `dependsOn` of the guard tasks, and adds one it
67
67
  // lacks.
68
- // - The tools the frame's checks run as commands (API Extractor, whose TSDoc base the project's
69
- // `tsdoc.json` extends, dependency-cruiser, knip, Turborepo) are added to the project's
70
- // `devDependencies` at the version the template's `devDependencies` give; a tool the project
71
- // already declares in `dependencies`, `devDependencies` or `optionalDependencies` keeps its
72
- // declaration, one a previous version added stays, and `devDependencies` are written sorted by
73
- // name. The report names each tool added and `npm install`, which installs them. What the
74
- // package's scripts import, it declares itself (its `dependencies`, and Vitest and TypeScript as
75
- // peers). A project without `packageManager` receives the template's (Turborepo requires it), and
76
- // a `.gitignore` that does not ignore `.turbo/` (Turborepo's runs and cache) receives the line.
68
+ // - The tools the frame's checks run as commands (dependency-cruiser, knip, Turborepo) are added
69
+ // to the project's `devDependencies` at the version the template's `devDependencies` give; a
70
+ // tool the project already declares in `dependencies`, `devDependencies` or
71
+ // `optionalDependencies` keeps its declaration, one a previous version added stays, and
72
+ // `devDependencies` are written sorted by name. The report names each tool added and
73
+ // `npm install`, which installs them. What the package's scripts import, it declares itself (its
74
+ // `dependencies`, API Extractor among them; Vitest and TypeScript as peers), as npm leaves to a
75
+ // package what it imports; the project's `tsdoc.json` extends the package's TSDoc base
76
+ // (`@roomi-fields/grillhouse/tsdoc-base.json`), which extends API Extractor's. A project without
77
+ // `packageManager` receives the template's (Turborepo requires it), and a `.gitignore` that does
78
+ // not ignore `.turbo/` (Turborepo's runs and cache) receives the line.
77
79
  // - A project that runs Vitest (its `test` script names it, or `vitest` is in the `dependencies` or
78
80
  // `devDependencies` of its root `package.json` or of one of its packages, the workspaces as npm
79
81
  // maps them, read by `paquets` of scripts/paquets.mjs, the frame's one list of the
@@ -97,6 +99,13 @@
97
99
  // `^<version>` of the package), a declaration it holds kept; a package out of the frame is not
98
100
  // touched. The report names the packages that received it, `npm install`, which links it, and the
99
101
  // import; the update writes no Vitest configuration.
102
+ // - A package of the frame whose code imports the frame's package (a file of its `src/` out of the
103
+ // tests, the files whose development dependencies the guard of the boundaries refuses,
104
+ // scripts/frontieres.mjs; its imports read by TypeScript's `preProcessFile`) declares it in its
105
+ // `dependencies`, as npm puts there what the published code imports: a declaration in its
106
+ // `devDependencies` moves there with its range, else the range the root declares (else
107
+ // `^<version>`); this comes first, so that the declaration of the Vitest base above keeps it.
108
+ // The report names the packages and `npm install`.
100
109
  // - The git hooks: both of the frame (commit-msg « a closed ticket refuses a second commit, a reopened ticket takes its corrections », pre-push night branch
101
110
  // guard) are placed by scripts/crochets.mjs, the mechanism `grillhouse hooks` (the project's
102
111
  // `prepare`) also runs, in the hooks folder git reads for the project (`core.hooksPath`, else the
@@ -122,6 +131,7 @@
122
131
  // - The report names the version of the frame, « Cadre 0.23.0. », the package's.
123
132
  import { spawnSync } from 'node:child_process';
124
133
  import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs';
134
+ import { createRequire } from 'node:module';
125
135
  import path from 'node:path';
126
136
  import { pathToFileURL } from 'node:url';
127
137
  import semver from 'semver';
@@ -129,7 +139,9 @@ import { CADRE, VERSION } from './cadre.mjs';
129
139
  import { poserCrochets } from './crochets.mjs';
130
140
  import { installerGreffons } from './greffons.mjs';
131
141
  import { migrer, restesAuProjet } from './migrations.mjs';
142
+ import { CODE, TESTS } from './frontieres.mjs';
132
143
  import { paquets } from './paquets.mjs';
144
+ import { sources } from './sources.mjs';
133
145
 
134
146
  const SCRIPTS = {
135
147
  tableau: 'grillhouse tableau --texte',
@@ -148,7 +160,7 @@ export const LIGNE_ETAT = '"$CLAUDE_PROJECT_DIR/node_modules/.bin/grillhouse" li
148
160
 
149
161
  // The frame's tools a project runs as commands: their names are the frame's, their versions are
150
162
  // read in the template.
151
- const OUTILS_DU_CADRE = ['@microsoft/api-extractor', 'dependency-cruiser', 'knip', 'turbo'];
163
+ const OUTILS_DU_CADRE = ['dependency-cruiser', 'knip', 'turbo'];
152
164
  // The root scripts of the tests, written together from the template.
153
165
  const SCRIPTS_DES_TESTS = ['test', 'test:vitest', 'test:forcer', 'verifier'];
154
166
  const CHAMPS_INSTALLES = ['dependencies', 'devDependencies', 'optionalDependencies'];
@@ -219,6 +231,64 @@ function poserTurbo(projet, source) {
219
231
  return gabarit;
220
232
  }
221
233
 
234
+ // <deps> written sorted by name, as npm writes them.
235
+ const trie = deps =>
236
+ Object.fromEntries(Object.entries(deps).sort(([a], [b]) => a.localeCompare(b, 'en')));
237
+ // The range at which the root package.json <p> declares the frame's package, or undefined.
238
+ const plageDeLaRacine = p =>
239
+ CHAMPS_INSTALLES.map(c => p[c]?.[PAQUET_DU_CADRE]).find(v => v !== undefined);
240
+
241
+ // Whether the code of the package at <dossier> of <projet> imports the frame's package (an entry of
242
+ // it): a file of its `src/` out of the tests (CODE and TESTS of scripts/frontieres.mjs, the files
243
+ // whose development dependencies its guard refuses), its imports read by TypeScript
244
+ // (`preProcessFile`), a comment or a string importing nothing.
245
+ function codeImporteLeCadre(projet, dossier) {
246
+ const ts = createRequire(import.meta.url)('typescript');
247
+ return sources(path.join(projet, dossier))
248
+ .map(f => `${dossier}/${f}`)
249
+ .filter(f => new RegExp(CODE).test(f) && !new RegExp(TESTS).test(f))
250
+ .some(f =>
251
+ ts
252
+ .preProcessFile(readFileSync(path.join(projet, f), 'utf8'), true, true)
253
+ .importedFiles.some(
254
+ ({ fileName: m }) => m === PAQUET_DU_CADRE || m.startsWith(`${PAQUET_DU_CADRE}/`)
255
+ )
256
+ );
257
+ }
258
+
259
+ // Declares the frame's package in the dependencies of each package of the frame of the project of
260
+ // packages at <projet> (root package.json <p>) whose code imports it (codeImporteLeCadre), as npm
261
+ // puts what the published code imports: a declaration in its devDependencies moves there with its
262
+ // range, else the range the root declares (else `^<version>` of the package); one already in its
263
+ // dependencies or optionalDependencies stays. Returns { nom, paquets } (paquets: the packages
264
+ // whose dependencies received it), or null when nothing changes.
265
+ function declarerDependanceDuCadre(projet, p) {
266
+ if (p.workspaces === undefined) {
267
+ return null;
268
+ }
269
+ const racine = plageDeLaRacine(p);
270
+ const declarants = [];
271
+ for (const { dossier, pkg, hors } of paquets(projet)) {
272
+ const declare = ['dependencies', 'optionalDependencies'].some(
273
+ c => pkg[c]?.[PAQUET_DU_CADRE] !== undefined
274
+ );
275
+ if (hors || declare || !codeImporteLeCadre(projet, dossier)) {
276
+ continue;
277
+ }
278
+ const { [PAQUET_DU_CADRE]: dev, ...autres } = pkg.devDependencies ?? {};
279
+ pkg.dependencies = trie({
280
+ ...(pkg.dependencies ?? {}),
281
+ [PAQUET_DU_CADRE]: dev ?? racine ?? `^${VERSION}`,
282
+ });
283
+ if (dev !== undefined) {
284
+ pkg.devDependencies = autres;
285
+ }
286
+ writeFileSync(path.join(projet, dossier, 'package.json'), `${JSON.stringify(pkg, null, 2)}\n`);
287
+ declarants.push(dossier);
288
+ }
289
+ return declarants.length > 0 ? { nom: PAQUET_DU_CADRE, paquets: declarants } : null;
290
+ }
291
+
222
292
  // Declares the frame's package, whose base configuration of Vitest each Vitest configuration
223
293
  // imports, in the devDependencies of each package of the frame of the project of packages at
224
294
  // <projet> (root package.json <p>) whose scripts hold `test:vitest`, at the range the root declares
@@ -230,16 +300,14 @@ function poserConfigVitest(projet, p) {
230
300
  const testes = paquets(projet).filter(
231
301
  ({ pkg, hors }) => !hors && typeof pkg.scripts?.['test:vitest'] === 'string'
232
302
  );
233
- const racine = CHAMPS_INSTALLES.map(c => p[c]?.[PAQUET_DU_CADRE]).find(v => v !== undefined);
303
+ const racine = plageDeLaRacine(p);
234
304
  const declarants = [];
235
305
  for (const { dossier, pkg } of testes) {
236
306
  if (CHAMPS_INSTALLES.some(c => pkg[c]?.[PAQUET_DU_CADRE] !== undefined)) continue;
237
- pkg.devDependencies = Object.fromEntries(
238
- Object.entries({
239
- ...(pkg.devDependencies ?? {}),
240
- [PAQUET_DU_CADRE]: racine ?? `^${VERSION}`,
241
- }).sort(([a], [b]) => a.localeCompare(b, 'en'))
242
- );
307
+ pkg.devDependencies = trie({
308
+ ...(pkg.devDependencies ?? {}),
309
+ [PAQUET_DU_CADRE]: racine ?? `^${VERSION}`,
310
+ });
243
311
  writeFileSync(path.join(projet, dossier, 'package.json'), `${JSON.stringify(pkg, null, 2)}\n`);
244
312
  declarants.push(dossier);
245
313
  }
@@ -303,6 +371,7 @@ export function mettreAJour(projet, source, { inscrite = VERSION } = {}) {
303
371
  vitest: null,
304
372
  turbo: null,
305
373
  configVitest: null,
374
+ dependanceDuCadre: null,
306
375
  gardes: null,
307
376
  ligneEtat: false,
308
377
  greffon: false,
@@ -362,9 +431,7 @@ export function mettreAJour(projet, source, { inscrite = VERSION } = {}) {
362
431
  }
363
432
  }
364
433
  if (p.devDependencies) {
365
- p.devDependencies = Object.fromEntries(
366
- Object.entries(p.devDependencies).sort(([a], [b]) => a.localeCompare(b, 'en'))
367
- );
434
+ p.devDependencies = trie(p.devDependencies);
368
435
  }
369
436
  if (typeof pkgSource.packageManager === 'string' && typeof p.packageManager !== 'string') {
370
437
  p.packageManager = pkgSource.packageManager;
@@ -403,6 +470,7 @@ export function mettreAJour(projet, source, { inscrite = VERSION } = {}) {
403
470
  bilan.gardes = { deplace: false };
404
471
  }
405
472
  }
473
+ bilan.dependanceDuCadre = declarerDependanceDuCadre(projet, p);
406
474
  bilan.configVitest = poserConfigVitest(projet, p);
407
475
  writeFileSync(pkg, `${JSON.stringify(p, null, 2)}\n`);
408
476
  }
@@ -462,6 +530,12 @@ export function rapport(b) {
462
530
  `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}'\`.`
463
531
  );
464
532
  }
533
+ if (b.dependanceDuCadre) {
534
+ const { nom, paquets: declarants } = b.dependanceDuCadre;
535
+ lignes.push(
536
+ `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.`
537
+ );
538
+ }
465
539
  if (b.turbo) {
466
540
  lignes.push(
467
541
  `turbo.json écrit depuis le gabarit du cadre ${b.turbo} ; il est au projet, la mise à jour n'y touche plus.`
@@ -27,7 +27,8 @@
27
27
  // named, not rewritten.
28
28
  // - A dependency of the project's root that a copy removed imported, that the package declares in
29
29
  // its own `dependencies`, that the template of a project does not declare, and that no source of
30
- // the project still imports, is named, not removed: the project decides.
30
+ // the project still imports, is named, not removed: the project decides. API Extractor is named
31
+ // by the migration of 0.24.2 alone (`DU_PAQUET` of 0.24.2-api-extractor-du-paquet.mjs), once.
31
32
  // - A project without `fichiers.txt` and `empreintes.json` is not written: a second pass finds
32
33
  // neither, or finds only the copies left to the project, which it names again.
33
34
  import { createHash } from 'node:crypto';
@@ -35,10 +36,11 @@ import { existsSync, readdirSync, readFileSync, rmSync, writeFileSync } from 'no
35
36
  import path from 'node:path';
36
37
  import { CADRE, PAQUET } from '../cadre.mjs';
37
38
  import { paquets } from '../paquets.mjs';
38
- import { sources } from '../sources.mjs';
39
+ import { importe, sources } from '../sources.mjs';
39
40
  import { SOUS_COMMANDES } from '../sous-commandes.mjs';
40
41
  import { formesAnterieures } from './0.23.0-config-vitest.mjs';
41
42
  import { deRoleSupprime } from './0.24.0-circuit-simplifie.mjs';
43
+ import { dependanceDuPaquet, DU_PAQUET } from './0.24.2-api-extractor-du-paquet.mjs';
42
44
 
43
45
  export const version = '0.23.2';
44
46
  export const nom = 'copies du cadre';
@@ -56,12 +58,6 @@ const GENERE = /^\/\/ Généré par `[^`\n]*turbo-des-paquets[^`\n]*`/;
56
58
 
57
59
  const hacher = octets => createHash('sha256').update(octets).digest('hex');
58
60
  const lireJson = f => JSON.parse(readFileSync(f, 'utf8'));
59
- const echapper = t => t.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&');
60
- // Whether the source text <texte> imports the package <dep> (or a path into it).
61
- const importe = (texte, dep) =>
62
- new RegExp(
63
- `(?:\\bfrom\\s*|\\bimport\\s*\\(?\\s*|\\brequire\\s*\\(\\s*)(['"])${echapper(dep)}(?:/[^'"]*)?\\1`
64
- ).test(texte);
65
61
 
66
62
  // The subcommand that runs each script of the package, by the path of its former copy.
67
63
  const PAR_COPIE = new Map(Object.entries(SOUS_COMMANDES).map(([n, s]) => [`scripts/${s}`, n]));
@@ -188,14 +184,12 @@ export function migrer(projet) {
188
184
  const duPaquet = Object.keys(lireJson(path.join(PAQUET, 'package.json')).dependencies ?? {});
189
185
  const gabarit = lireJson(path.join(CADRE, GABARIT, 'package.json'));
190
186
  const textes = sources(projet).map(f => readFileSync(path.join(projet, f), 'utf8'));
191
- for (const dep of duPaquet) {
187
+ for (const dep of duPaquet.filter(d => d !== DU_PAQUET)) {
192
188
  if (!CHAMPS.some(c => pkg[c]?.[dep] !== undefined)) continue;
193
189
  if (CHAMPS.some(c => gabarit[c]?.[dep] !== undefined)) continue;
194
190
  if (![...retires.values()].some(t => importe(t, dep))) continue;
195
191
  if (textes.some(t => importe(t, dep))) continue;
196
- sortie.push(
197
- `package.json : la dépendance ${dep} n'est plus importée que par le paquet, qui la déclare lui-même ; \`npm uninstall ${dep}\` la retire si le projet n'en a pas l'usage`
198
- );
192
+ sortie.push(dependanceDuPaquet(dep));
199
193
  }
200
194
  return sortie;
201
195
  }
@@ -21,12 +21,15 @@
21
21
  // - What stays to the project (`restes`, which the update plays after its own update and its
22
22
  // regeneration, so that it sees the final state): a tracked file of the project (`git ls-files`,
23
23
  // node_modules and the changelogs aside) that still calls or names a script of the frame at its former address under `scripts/`
24
- // (`node scripts/<script>`, `$RACINE/scripts/<script>`, `path.join(…, 'scripts', '<script>')`;
25
- // a tracked path that is no regular file, a submodule or a link, is skipped),
26
- // where the project holds no such file any more, is named with its file:line and what replaces
27
- // it: the subcommand (`SOUS_COMMANDES` of scripts/sous-commandes.mjs), the hook
24
+ // (`node scripts/<script>`, `$RACINE/scripts/<script>`, `file://$1/scripts/<script>`,
25
+ // `path.join(…, '..', 'scripts', '<dossier>', '<script>')`, found by its words, sousScripts; a
26
+ // `scripts/` under a literal directory, a package of the project or the installed package, is
27
+ // another's, `.` and `..` naming none; a tracked path that is no regular file, a submodule or a
28
+ // link, is skipped), where the project holds no such file any more, is named with its file:line
29
+ // and what replaces it: the subcommand (`SOUS_COMMANDES` of scripts/sous-commandes.mjs), the hook
28
30
  // (`grillhouse hook <nom>`, `CROCHETS` of scripts/crochets.mjs) or the named entry (the
29
- // `exports` of the package). The project's scripts are its own: none is rewritten, and the
31
+ // `exports` of the package). A script of the package that has none of them is named with « aucune
32
+ // entrée publiée ne la remplace ». The project's scripts are its own: none is rewritten, and the
30
33
  // lines are a report, which never holds back the version the project records, as a codemod
31
34
  // reports what it leaves without failing.
32
35
  // - No version of the update wrote a setting of a role in `.claude/settings.json` or under
@@ -37,7 +40,7 @@
37
40
  // to the project.
38
41
  import { execFileSync } from 'node:child_process';
39
42
  import { createHash } from 'node:crypto';
40
- import { existsSync, lstatSync, readFileSync, writeFileSync } from 'node:fs';
43
+ import { existsSync, lstatSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
41
44
  import path from 'node:path';
42
45
  import { CADRE, PAQUET } from '../cadre.mjs';
43
46
  import { CROCHETS } from '../crochets.mjs';
@@ -154,7 +157,7 @@ function copies(projet) {
154
157
  }
155
158
 
156
159
  // What replaces each script of the frame, by its path under `scripts/`: its subcommand, its hook,
157
- // its named entry.
160
+ // its named entry; none for a script of the package that has none of them.
158
161
  function remplacants() {
159
162
  const r = new Map();
160
163
  const ajouter = (script, quoi) => r.set(script, [...(r.get(script) ?? []), quoi]);
@@ -164,20 +167,64 @@ function remplacants() {
164
167
  for (const [n, c] of Object.entries(CROCHETS)) {
165
168
  ajouter(c.garde, `\`grillhouse hook ${n}\``);
166
169
  }
167
- const { exports = {} } = JSON.parse(readFileSync(path.join(PAQUET, 'package.json'), 'utf8'));
170
+ const { name, exports = {} } = JSON.parse(
171
+ readFileSync(path.join(PAQUET, 'package.json'), 'utf8')
172
+ );
168
173
  for (const [entree, cible] of Object.entries(exports)) {
169
174
  const d = typeof cible === 'string' ? cible : cible?.default;
170
175
  if (typeof d === 'string' && d.startsWith('./scripts/')) {
171
- ajouter(d.slice('./scripts/'.length), `\`@roomi-fields/grillhouse${entree.slice(1)}\``);
176
+ ajouter(d.slice('./scripts/'.length), `\`${name}${entree.slice(1)}\``);
177
+ }
178
+ }
179
+ const scripts = path.join(PAQUET, 'scripts');
180
+ for (const e of readdirSync(scripts, { recursive: true, withFileTypes: true })) {
181
+ const s = path.relative(scripts, path.join(e.parentPath, e.name)).split(path.sep).join('/');
182
+ if (e.isFile() && SCRIPT.test(s) && !r.has(s)) {
183
+ r.set(s, []);
172
184
  }
173
185
  }
174
186
  return r;
175
187
  }
176
- // A script named at its former address: `scripts/<chemin>`, alone or after `./` or `$VAR/`.
177
- const ADRESSE = /(?<![\w./-])(?:\.\/|\$\{?\w+\}?\/)?scripts\/([\w./-]+?\.(?:mjs|sh))(?![\w.-])/g;
178
- // The same, as the segments of a path.join: `'scripts', 'dette.mjs'`.
179
- const SEGMENTS = /(['"])scripts\1((?:\s*,\s*(['"])[\w.-]+\3)+)/g;
188
+ const SCRIPT = /\.(?:mjs|sh)$/;
180
189
  const SANS = /(^|\/)(?:node_modules\/|CHANGELOG\.md$)/;
190
+ // What separates the words of a line, and the arguments of a call.
191
+ const BLANCS = /[\s'"`();|&<>=,]+/;
192
+ const APPELS = /[();]/;
193
+ const cite = a => a.length >= 2 && /^['"`]$/.test(a[0]) && a.at(-1) === a[0];
194
+ // Whether a piece of a path names a directory: `.` and `..` name none, only a step.
195
+ const dossier = m => m !== '.' && m !== '..';
196
+
197
+ // The paths under `scripts/` that the line <ligne> names at a project's root, each as its pieces
198
+ // after `scripts`: a word cut at its `/` (`scripts/x.mjs`, `./scripts/x.mjs`, `../scripts/x.mjs`,
199
+ // `$RACINE/scripts/x.mjs`, `file://$1/scripts/x.mjs`), whose piece before `scripts` is none, a
200
+ // step (`.`, `..`) or a variable; the arguments of a call (`path.join(RACINE, 'scripts', 'd',
201
+ // 'x.mjs')`, `path.join(dir, '..', 'scripts', 'x.mjs')`), whose argument before `'scripts'` is
202
+ // none, no literal or a step, the literals after it its pieces. A `scripts/` under a literal
203
+ // directory (`packages/a/scripts/`, the installed package) is another's.
204
+ function sousScripts(ligne) {
205
+ const chemins = [];
206
+ for (const mot of ligne.split(BLANCS)) {
207
+ const p = mot.split('/');
208
+ p.forEach((m, i) => {
209
+ if (m === 'scripts' && (i === 0 || !dossier(p[i - 1]) || p[i - 1].startsWith('$'))) {
210
+ chemins.push(p.slice(i + 1));
211
+ }
212
+ });
213
+ }
214
+ for (const appel of ligne.split(APPELS)) {
215
+ const a = appel.split(',').map(x => x.trim());
216
+ a.forEach((x, i) => {
217
+ const avant = a[i - 1];
218
+ const libre = i === 0 || !cite(avant) || !dossier(avant.slice(1, -1));
219
+ if (cite(x) && x.slice(1, -1) === 'scripts' && libre) {
220
+ const suite = a.slice(i + 1);
221
+ const fin = suite.findIndex(y => !cite(y));
222
+ chemins.push(suite.slice(0, fin === -1 ? suite.length : fin).map(y => y.slice(1, -1)));
223
+ }
224
+ });
225
+ }
226
+ return chemins;
227
+ }
181
228
 
182
229
  /** The lines of the tracked files of <projet> that still reach a script of the frame at its former address. */
183
230
  export function restes(projet) {
@@ -202,23 +249,19 @@ export function restes(projet) {
202
249
  continue;
203
250
  }
204
251
  texte.split('\n').forEach((ligne, i) => {
205
- const scripts = [
206
- ...[...ligne.matchAll(ADRESSE)].map(m => m[1]),
207
- ...[...ligne.matchAll(SEGMENTS)].map(m =>
208
- m[2]
209
- .split(',')
210
- .map(s => s.trim().slice(1, -1))
211
- .filter(Boolean)
212
- .join('/')
213
- ),
214
- ];
252
+ const scripts = sousScripts(ligne).flatMap(pieces =>
253
+ pieces.map((_, n) => pieces.slice(0, n + 1).join('/')).filter(s => par.has(s))
254
+ );
215
255
  for (const s of new Set(scripts)) {
216
- if (!par.has(s) || existsSync(path.join(projet, 'scripts', s))) {
256
+ const quoi = par.get(s);
257
+ if (existsSync(path.join(projet, 'scripts', s))) {
217
258
  continue;
218
259
  }
219
- sortie.push(
220
- `${f}:${i + 1} : appelle scripts/${s}, copie du cadre retirée ; ${par.get(s).join(' ou ')} la remplace`
221
- );
260
+ const suite =
261
+ quoi.length > 0
262
+ ? `${quoi.join(' ou ')} la remplace`
263
+ : 'aucune entrée publiée ne la remplace';
264
+ sortie.push(`${f}:${i + 1} : appelle scripts/${s}, copie du cadre retirée ; ${suite}`);
222
265
  }
223
266
  });
224
267
  }
@@ -0,0 +1,68 @@
1
+ // API Extractor is the package's dependency, not the project's: the package imports it as a library
2
+ // (scripts/interfaces-contre-code.mjs) and declares it in its own `dependencies`, and no command of
3
+ // a project runs it, as npm leaves to a package what it imports. The update of 0.23.0 to 0.24.1
4
+ // added it to the devDependencies of a project's root as a tool the project runs, and
5
+ // `grillhouse code-mort` then refused it as a development dependency without use. The project's
6
+ // `tsdoc.json` extended its TSDoc base, resolved only when npm hoists API Extractor to the root:
7
+ // the package now publishes its own base (`tsdoc-base.json`, which extends API Extractor's), as a
8
+ // rig of Rushstack carries the base configuration beside the dependency it names.
9
+ //
10
+ // - The `tsdoc.json` of the project's root whose `extends` names the base of API Extractor
11
+ // (ANCIENNE_BASE) extends the package's (BASE): that name is rewritten in place, the rest of the
12
+ // file kept byte for byte. A `tsdoc.json` that extends another base, or none, is not written.
13
+ // - What stays to the project (`restes`, which the update plays after its own update, so after the
14
+ // rewrite above): a root `package.json` that declares `@microsoft/api-extractor`
15
+ // (`dependencies`, `devDependencies` or `optionalDependencies`), while no source of the project
16
+ // imports it (scripts/sources.mjs), hears the line of the other dependencies only the package
17
+ // imports (`dependanceDuPaquet`), with `npm uninstall`. The dependency is named, never removed:
18
+ // the project decides. The migration of the copies (0.23.2-copies-du-cadre.mjs) leaves it to this
19
+ // one (DU_PAQUET), so that it is named once.
20
+ // - A project already in the new form is not written, and a second pass returns no line.
21
+ import { existsSync, readFileSync, writeFileSync } from 'node:fs';
22
+ import path from 'node:path';
23
+ import { importe, sources } from '../sources.mjs';
24
+
25
+ export const version = '0.24.2';
26
+ export const nom = 'API Extractor du paquet';
27
+
28
+ /** The dependency this migration names, which the migration of the copies leaves to it. */
29
+ export const DU_PAQUET = '@microsoft/api-extractor';
30
+ const CHAMPS = ['dependencies', 'devDependencies', 'optionalDependencies'];
31
+ const TSDOC = 'tsdoc.json';
32
+ const ANCIENNE_BASE = `${DU_PAQUET}/extends/tsdoc-base.json`;
33
+ const BASE = '@roomi-fields/grillhouse/tsdoc-base.json';
34
+
35
+ /** The line that names <dep>, a dependency of a project only the package imports. */
36
+ export const dependanceDuPaquet = dep =>
37
+ `package.json : la dépendance ${dep} n'est plus importée que par le paquet, qui la déclare lui-même ; \`npm uninstall ${dep}\` la retire si le projet n'en a pas l'usage`;
38
+
39
+ /** The line naming API Extractor when the project at <projet> declares it without importing it. */
40
+ export function restes(projet) {
41
+ const f = path.join(projet, 'package.json');
42
+ if (!existsSync(f)) {
43
+ return [];
44
+ }
45
+ const pkg = JSON.parse(readFileSync(f, 'utf8'));
46
+ if (!CHAMPS.some(c => pkg[c]?.[DU_PAQUET] !== undefined)) {
47
+ return [];
48
+ }
49
+ const importee = sources(projet).some(s =>
50
+ importe(readFileSync(path.join(projet, s), 'utf8'), DU_PAQUET)
51
+ );
52
+ return importee ? [] : [dependanceDuPaquet(DU_PAQUET)];
53
+ }
54
+
55
+ /** Brings the `extends` of the project's tsdoc.json at <projet> to the package's base. */
56
+ export function migrer(projet) {
57
+ const f = path.join(projet, TSDOC);
58
+ if (!existsSync(f)) {
59
+ return [];
60
+ }
61
+ const texte = readFileSync(f, 'utf8');
62
+ const { extends: bases } = JSON.parse(texte);
63
+ if (!Array.isArray(bases) || !bases.includes(ANCIENNE_BASE)) {
64
+ return [];
65
+ }
66
+ writeFileSync(f, texte.replace(`"${ANCIENNE_BASE}"`, `"${BASE}"`));
67
+ return [`${TSDOC} : hérite de ${BASE}, la base TSDoc du paquet, au lieu de ${ANCIENNE_BASE}`];
68
+ }
@@ -25,6 +25,7 @@ import * as crochetsDeSeance from './migrations/0.23.0-crochets-de-seance.mjs';
25
25
  import * as marcheDuProjet from './migrations/0.23.0-marche-du-projet.mjs';
26
26
  import * as copiesDuCadre from './migrations/0.23.2-copies-du-cadre.mjs';
27
27
  import * as circuitSimplifie from './migrations/0.24.0-circuit-simplifie.mjs';
28
+ import * as apiExtractorDuPaquet from './migrations/0.24.2-api-extractor-du-paquet.mjs';
28
29
 
29
30
  /** The migrations of the package. */
30
31
  export const MIGRATIONS = [
@@ -34,6 +35,7 @@ export const MIGRATIONS = [
34
35
  charteImportee,
35
36
  copiesDuCadre,
36
37
  circuitSimplifie,
38
+ apiExtractorDuPaquet,
37
39
  ];
38
40
 
39
41
  /**
@@ -1,7 +1,7 @@
1
1
  // The source files of a project, as the migrations read them (scripts/migrations/): each `.ts`,
2
2
  // `.mts`, `.cts`, `.js`, `.mjs`, `.cjs` under its root, as a path from it, the directories of
3
3
  // tools and of what is installed or built (node_modules, .git, dist, coverage, .turbo, .claude,
4
- // .beads, .codegraph, .rtfm) left out.
4
+ // .beads, .codegraph, .rtfm) left out; and whether a source text imports a package (`importe`).
5
5
  import { readdirSync } from 'node:fs';
6
6
  import path from 'node:path';
7
7
 
@@ -26,3 +26,10 @@ export function sources(racine, rel = '') {
26
26
  return e.isFile() && EXTENSIONS.test(e.name) ? [r] : [];
27
27
  });
28
28
  }
29
+
30
+ const echapper = t => t.replace(/[.*+?^${}()|[\]\\/]/g, '\\$&');
31
+ /** Whether the source text <texte> imports the package <dep> (or a path into it). */
32
+ export const importe = (texte, dep) =>
33
+ new RegExp(
34
+ `(?:\\bfrom\\s*|\\bimport\\s*\\(?\\s*|\\brequire\\s*\\(\\s*)(['"])${echapper(dep)}(?:/[^'"]*)?\\1`
35
+ ).test(texte);
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://developer.microsoft.com/json-schemas/tsdoc/v0/tsdoc.schema.json",
3
+ "extends": ["@microsoft/api-extractor/extends/tsdoc-base.json"]
4
+ }