@ucm-kit/cli 0.1.44 → 0.1.45

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/README.md CHANGED
@@ -16,7 +16,7 @@ matches them.
16
16
  Requires Node 20 or later. At the root of the repository:
17
17
 
18
18
  ```sh
19
- npx --yes @ucm-kit/cli@0.1.44 init
19
+ npx --yes @ucm-kit/cli@0.1.45 init
20
20
  ```
21
21
 
22
22
  1. Commit and push the files `init` wrote.
@@ -27,7 +27,7 @@ npx --yes @ucm-kit/cli@0.1.44 init
27
27
  To run the check locally:
28
28
 
29
29
  ```sh
30
- npx --yes @ucm-kit/cli@0.1.44 check --report ci-report.md
30
+ npx --yes @ucm-kit/cli@0.1.45 check --report ci-report.md
31
31
  ```
32
32
 
33
33
  `--yes` skips the npx confirmation prompt. Pin an exact version, without `^`:
@@ -78,7 +78,7 @@ contract would resolve to the same file. A repository that does not write React
78
78
  states its own extension:
79
79
 
80
80
  ```sh
81
- npx --yes @ucm-kit/cli@0.1.44 init --components Sources/DesignSystem --implementation '{dir}/{id}.swift'
81
+ npx --yes @ucm-kit/cli@0.1.45 init --components Sources/DesignSystem --implementation '{dir}/{id}.swift'
82
82
  ```
83
83
 
84
84
  The three path options act only on a first install. `ucm init` never overwrites
@@ -188,7 +188,7 @@ directory. It writes a minimal report when the check stopped before writing
188
188
  one, then posts the report:
189
189
 
190
190
  ```sh
191
- npx --yes @ucm-kit/cli@0.1.44 rapport-gitlab --projet "$CI_PROJECT_ID" --merge-request "$CI_MERGE_REQUEST_IID" --fichier "$CI_PROJECT_DIR/ci-report.md" --api "$CI_API_V4_URL"
191
+ npx --yes @ucm-kit/cli@0.1.45 rapport-gitlab --projet "$CI_PROJECT_ID" --merge-request "$CI_MERGE_REQUEST_IID" --fichier "$CI_PROJECT_DIR/ci-report.md" --api "$CI_API_V4_URL"
192
192
  ```
193
193
 
194
194
  | Option | Effect |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ucm-kit/cli",
3
- "version": "0.1.44",
3
+ "version": "0.1.45",
4
4
  "description": "La ligne de commande UCM : initialiser un repository, lister ce qu'il doit couvrir.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -29,7 +29,7 @@
29
29
  "test": "node scripts/run-tests.cjs"
30
30
  },
31
31
  "dependencies": {
32
- "@ucm-kit/core": "0.1.38"
32
+ "@ucm-kit/core": "0.1.39"
33
33
  },
34
34
  "devDependencies": {
35
35
  "yaml": "^2.9.1"
package/src/check.mjs CHANGED
@@ -59,7 +59,7 @@ export function releveDuDiff(racine, base, sourceTokens, executer = execFileSync
59
59
  let contratsModifies;
60
60
  try {
61
61
  contratsModifies = git([
62
- "diff", "--name-only", base, "HEAD", "--", ":(glob)**/*.contract.json",
62
+ "diff", "--name-only", "-z", base, "HEAD", "--", ":(glob)**/*.contract.json",
63
63
  ]);
64
64
  } catch (erreur) {
65
65
  return {
@@ -79,7 +79,7 @@ export function releveDuDiff(racine, base, sourceTokens, executer = execFileSync
79
79
  tokensModifies = true;
80
80
  }
81
81
 
82
- return { contratsModifies, tokensModifies };
82
+ return { contratsModifies: contratsModifies.replaceAll("\0", "\n"), tokensModifies };
83
83
  }
84
84
 
85
85
  /**
package/src/init.mjs CHANGED
@@ -520,8 +520,16 @@ function workflow(version) {
520
520
  " # --edit-last met à jour le commentaire précédent au lieu d'en empiler",
521
521
  " # un nouveau à chaque push ; s'il n'en existe pas encore, on en crée un.",
522
522
  " run: |",
523
- ' gh pr comment "$NUMERO" -R "$GITHUB_REPOSITORY" --body-file ci-report.md --edit-last \\',
524
- ' || gh pr comment "$NUMERO" -R "$GITHUB_REPOSITORY" --body-file ci-report.md',
523
+ ' printf "<!-- ucm-rapport -->\\n" > ucm-report.md',
524
+ ' cat ci-report.md >> ucm-report.md',
525
+ ' COMPTE="$(gh api user --jq .login)"',
526
+ ' NOTE="$(gh api "repos/$GITHUB_REPOSITORY/issues/$NUMERO/comments" --paginate \\',
527
+ ' --jq ".[] | select(.user.login == \\\"$COMPTE\\\") | select(.body | startswith(\\\"<!-- ucm-rapport -->\\\")) | .id" | tail -n 1)"',
528
+ ' if [ -n "$NOTE" ]; then',
529
+ ' gh api --method PATCH "repos/$GITHUB_REPOSITORY/issues/comments/$NOTE" -f body="$(cat ucm-report.md)"',
530
+ ' else',
531
+ ' gh pr comment "$NUMERO" -R "$GITHUB_REPOSITORY" --body-file ucm-report.md',
532
+ ' fi',
525
533
  "",
526
534
  ].join("\n");
527
535
  }
@@ -608,7 +616,7 @@ function workflowGitlab(version) {
608
616
  " allow_failure: true",
609
617
  " variables:",
610
618
  " # Aucun clone : ni .npmrc ni node_modules du repository.",
611
- " GIT_STRATEGY: none",
619
+ " GIT_STRATEGY: empty",
612
620
  ' NPM_CONFIG_IGNORE_SCRIPTS: "true"',
613
621
  " script:",
614
622
  " # Filet : sans rapport, `ucm` s'est arrêté avant le contrôle (clone,",
@@ -660,14 +668,15 @@ function lignesGitlab(racine) {
660
668
  try {
661
669
  const ci = readFileSync(join(racine, ".gitlab-ci.yml"), "utf8");
662
670
  const stages = blocDeRacine(ci, "stages");
663
- if (stages !== null && !/\btest\b/.test(stages)) {
671
+ if (stages !== null && !/(?:^|[\s,\[])(?:-\s*)?test(?=$|[\s,\]])/m.test(stages)) {
664
672
  lignes.push({
665
673
  fichier: ".gitlab-ci.yml",
666
674
  ligne: "ajoutez `test` à `stages:`. Le job ucm s'y range, et GitLab refuse un pipeline dont un job vise un stage absent.",
667
675
  });
668
676
  }
669
677
  const workflow = blocDeRacine(ci, "workflow");
670
- if (workflow !== null && /^[ \t]+rules:/m.test(workflow) && !workflow.includes("merge_request_event")) {
678
+ const exclutLesMr = /if:\s*[^\n]*merge_request_event[\s\S]{0,160}?when:\s*never/.test(workflow ?? '');
679
+ if (workflow !== null && /^[ \t]+rules:/m.test(workflow) && (!workflow.includes("merge_request_event") || exclutLesMr)) {
671
680
  lignes.push({
672
681
  fichier: ".gitlab-ci.yml",
673
682
  ligne: "ajoutez `- if: $CI_PIPELINE_SOURCE == \"merge_request_event\"` en tête de `workflow:rules`. Sans cette règle, GitLab ne crée aucun pipeline de merge request et le job ucm ne contrôle aucun export.",
@@ -20,6 +20,14 @@ import { resolve } from "node:path";
20
20
 
21
21
  export const MARQUEUR_RAPPORT = "<!-- ucm-rapport -->";
22
22
 
23
+ function neutraliserActionsRapides(texte) {
24
+ return texte.replace(/^([ \t]*)(\/\S.*)$/gm, (_entier, avant, action) => {
25
+ const longueur = Math.max(0, ...[...action.matchAll(/`+/g)].map(([suite]) => suite.length)) + 1;
26
+ const borne = "`".repeat(longueur);
27
+ return `${avant}${borne}${action}${borne}`;
28
+ });
29
+ }
30
+
23
31
  const API_PAR_DEFAUT = "https://gitlab.com/api/v4";
24
32
 
25
33
  const USAGE = "ucm rapport-gitlab --projet <id> --merge-request <iid> --fichier <chemin> [--api <url>]";
@@ -105,7 +113,7 @@ export async function rapportGitlab(arguments_, {
105
113
  alerter(`Le rapport ${valeurs.fichier} ne se lit pas (${erreurLecture?.code ?? erreurLecture?.message}) : aucune note n'est publiée.`);
106
114
  return 1;
107
115
  }
108
- const corps = `${MARQUEUR_RAPPORT}\n${rapport}`;
116
+ const corps = `${MARQUEUR_RAPPORT}\n${neutraliserActionsRapides(rapport)}`;
109
117
  const projet = encodeURIComponent(valeurs.projet);
110
118
  const notes = `${valeurs.api}/projects/${projet}/merge_requests/${encodeURIComponent(valeurs.mergeRequest)}/notes`;
111
119
 
@@ -114,23 +122,36 @@ export async function rapportGitlab(arguments_, {
114
122
  try {
115
123
  reponse = await requete(url, {
116
124
  ...init,
125
+ redirect: "manual",
117
126
  headers: { "PRIVATE-TOKEN": jeton, "Content-Type": "application/json" },
118
127
  });
119
128
  } catch (panne) {
120
- throw new RefusGitlab(null, `La requête vers GitLab n'a pas abouti en voulant ${action} (${panne?.message ?? panne}). Relancez le job.`);
129
+ throw new RefusGitlab(null, `La requête vers GitLab n'a pas abouti en voulant ${action}. Relancez le job.`);
130
+ }
131
+ if (reponse.status >= 300 && reponse.status < 400) {
132
+ throw new RefusGitlab(reponse.status, `GitLab a redirige la requete en voulant ${action}.`);
121
133
  }
122
134
  if (!reponse.ok) throw new RefusGitlab(reponse.status, gesteDuStatut(reponse.status, action));
123
135
  return reponse;
124
136
  }
125
137
 
126
138
  try {
127
- const compte = await (await appeler(`${valeurs.api}/user`, "lire le compte du jeton")).json();
139
+ let compte;
140
+ try {
141
+ compte = await (await appeler(`${valeurs.api}/user`, "lire le compte du jeton")).json();
142
+ } catch (error) {
143
+ if (error instanceof RefusGitlab) throw error;
144
+ throw new RefusGitlab(null, "GitLab a rendu une réponse illisible en lisant le compte du jeton. Relancez le job.");
145
+ }
128
146
 
129
147
  let existante = null;
130
148
  let page = "1";
131
149
  while (page && !existante) {
132
150
  const reponse = await appeler(`${notes}?per_page=100&sort=asc&page=${page}`, "lire les notes de la merge request");
133
- const lues = await reponse.json();
151
+ let lues;
152
+ try { lues = await reponse.json(); } catch {
153
+ throw new RefusGitlab(null, "GitLab a rendu une réponse illisible en lisant les notes de la merge request. Relancez le job.");
154
+ }
134
155
  existante = lues.find((note) => !note.system && note.author?.id === compte.id
135
156
  && typeof note.body === "string" && note.body.includes(MARQUEUR_RAPPORT)) ?? null;
136
157
  page = reponse.headers.get("x-next-page");
@@ -293,6 +293,10 @@ export function feuilleDesTokens(document, { axes = [], attributs = new Map(), r
293
293
  const parNom = new Map();
294
294
  for (const chemin of index.keys()) {
295
295
  const nom = tokenCssVariable(chemin);
296
+ if (nom === "--") {
297
+ refus.push(`La feuille « ${chemin} » ne donne aucun nom CSS.`);
298
+ continue;
299
+ }
296
300
  if (nom.startsWith(PREFIXE_DES_INTERMEDIAIRES)) {
297
301
  refus.push(`La feuille « ${chemin} » donne la propriété « ${nom} », dont le préfixe ${PREFIXE_DES_INTERMEDIAIRES} est réservé aux collections étendues.`);
298
302
  }
@@ -569,7 +573,8 @@ export function tokensCss(arguments_, {
569
573
  return 2;
570
574
  };
571
575
 
572
- const enTete = `/* Généré par ucm tokens css depuis ${configuration.tokens}. Relancer la commande plutôt que modifier ce fichier. */\n`;
576
+ const cheminDansLEnTete = configuration.tokens.replaceAll("*/", "* /");
577
+ const enTete = `/* Généré par ucm tokens css depuis ${cheminDansLEnTete}. Relancer la commande plutôt que modifier ce fichier. */\n`;
573
578
 
574
579
  if (!existsSync(source)) {
575
580
  const cites = contratsQuiCitentDesTokens(racine, configuration.components);
package/src/ucm.mjs CHANGED
@@ -4,7 +4,8 @@
4
4
  * publient les décisions du noyau sans dupliquer son orchestration.
5
5
  * Codes : 0 succès, 1 contrôles rouges, 2 invocation ou configuration fautive.
6
6
  */
7
- import { realpathSync } from "node:fs";
7
+ import { existsSync, realpathSync } from "node:fs";
8
+ import { dirname, resolve } from "node:path";
8
9
  import process from "node:process";
9
10
  import { pathToFileURL } from "node:url";
10
11
 
@@ -113,6 +114,18 @@ function executerCommande(arguments_, {
113
114
  ecrire = console.log,
114
115
  ...sorties
115
116
  } = {}) {
117
+ const racineInitiale = racine;
118
+ for (let candidate = resolve(racine); ; candidate = dirname(candidate)) {
119
+ if (existsSync(resolve(candidate, "ucm.config.json")) || existsSync(resolve(candidate, ".git"))) {
120
+ racine = candidate;
121
+ break;
122
+ }
123
+ const parent = dirname(candidate);
124
+ if (parent === candidate) {
125
+ racine = racineInitiale;
126
+ break;
127
+ }
128
+ }
116
129
  const [commande] = arguments_;
117
130
 
118
131
  if (commande === undefined || commande === "--help" || commande === "-h") {