@brucesantos/design-space 0.14.0 → 0.14.1
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/CHANGELOG.md +12 -0
- package/README.md +8 -1
- package/dist/index.js +1 -1
- package/dist/pr.js +43 -37
- package/dist/pr.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,18 @@ Versionamento semântico. **Patch** para correção sem mudança de contrato,
|
|
|
6
6
|
Mudança estrutural — pasta obrigatória nova, schema de cenário alterado — exige
|
|
7
7
|
comando explícito e revisável, nunca merge silencioso.
|
|
8
8
|
|
|
9
|
+
## 0.14.1 (2026-11-18)
|
|
10
|
+
|
|
11
|
+
**Patch.** Correção na descrição do PR; nenhum contrato muda.
|
|
12
|
+
|
|
13
|
+
### Corrigido
|
|
14
|
+
|
|
15
|
+
- **A linha "Preview" do bloco do PR abre a tela do PR.** Antes ela trazia a
|
|
16
|
+
raiz do preview, que abre a primeira tela do produto. Com a base comparada,
|
|
17
|
+
ela agora leva à primeira tela que o PR toca, no primeiro cenário novo ou
|
|
18
|
+
alterado dela (ou no caminho de exemplo, se a tela não tem cenário). Sem
|
|
19
|
+
base, ou quando o PR não toca tela nenhuma, continua na raiz.
|
|
20
|
+
|
|
9
21
|
## 0.14.0 (2026-10-22)
|
|
10
22
|
|
|
11
23
|
**Minor.** Um entrypoint e um comando novos; sai o botão "Copiar para o PR".
|
package/README.md
CHANGED
|
@@ -251,8 +251,12 @@ registro do PR com o da base e reescreve a descrição (decisão 0018). O botão
|
|
|
251
251
|
|
|
252
252
|
```yaml
|
|
253
253
|
# no workflow do PR, com `permissions: pull-requests: write`
|
|
254
|
+
# fora de PR do Dependabot e de fork, cujo token é só de leitura
|
|
254
255
|
- name: Critérios de aceite na descrição do PR
|
|
255
|
-
if:
|
|
256
|
+
if: >-
|
|
257
|
+
github.event_name == 'pull_request' &&
|
|
258
|
+
github.actor != 'dependabot[bot]' &&
|
|
259
|
+
github.event.pull_request.head.repo.full_name == github.repository
|
|
256
260
|
run: pnpm exec design-space-pr --origin "<origem do preview deste PR>"
|
|
257
261
|
env:
|
|
258
262
|
GH_TOKEN: ${{ github.token }}
|
|
@@ -277,6 +281,9 @@ registro do PR com o da base e reescreve a descrição (decisão 0018). O botão
|
|
|
277
281
|
As funções puras estão em `@brucesantos/design-space/pr`: `buildPrSection`,
|
|
278
282
|
`mergePrBody`, `diffProducts` e `PR_MARKERS`. O texto segue `theme.labels.pr`.
|
|
279
283
|
|
|
284
|
+
O guia de handoff do template traz orientações para comunicar os ajustes em uma
|
|
285
|
+
revisão. [Como comunicar uma revisão](https://github.com/bananas-global/design-space/blob/main/packages/template/docs/handoff.md#como-comunicar-uma-revis%C3%A3o)
|
|
286
|
+
|
|
280
287
|
### O quadro
|
|
281
288
|
|
|
282
289
|
O chrome renderiza `<iframe data-ds-frame>` apontando para o mesmo endereço com
|
package/dist/index.js
CHANGED
|
@@ -321,7 +321,7 @@ function Dt(e) {
|
|
|
321
321
|
const t = Number.parseInt(e, 10);
|
|
322
322
|
return Number.isFinite(t) && t > 0 ? t : void 0;
|
|
323
323
|
}
|
|
324
|
-
const Kt = "@brucesantos/design-space", Re = "0.14.
|
|
324
|
+
const Kt = "@brucesantos/design-space", Re = "0.14.1", It = {
|
|
325
325
|
mobile: /* @__PURE__ */ b(V, { children: [
|
|
326
326
|
/* @__PURE__ */ n("rect", { x: "7", y: "2.5", width: "10", height: "19", rx: "2" }),
|
|
327
327
|
/* @__PURE__ */ n("path", { d: "M11 18.5h2" })
|
package/dist/pr.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { s as
|
|
2
|
-
import { a as w, r as
|
|
1
|
+
import { s as R } from "./index-CaxlsfFr.js";
|
|
2
|
+
import { a as w, r as C } from "./labels-BlpcrSph.js";
|
|
3
3
|
const v = {
|
|
4
4
|
start: "<!-- design-space:pr:start -->",
|
|
5
5
|
end: "<!-- design-space:pr:end -->"
|
|
6
6
|
};
|
|
7
|
-
function
|
|
7
|
+
function M(n, r) {
|
|
8
8
|
const e = w(n);
|
|
9
9
|
if (!r)
|
|
10
10
|
return {
|
|
@@ -12,20 +12,20 @@ function R(n, r) {
|
|
|
12
12
|
screens: e.screens.map((s) => ({ screen: s, changes: /* @__PURE__ */ new Map(), removed: [] })),
|
|
13
13
|
removedScreens: []
|
|
14
14
|
};
|
|
15
|
-
const
|
|
16
|
-
(r.scenarios ?? []).map((s) => [s.id, x(
|
|
17
|
-
), o = new Map(
|
|
15
|
+
const i = w(r), c = new Map(
|
|
16
|
+
(r.scenarios ?? []).map((s) => [s.id, x(i, s)])
|
|
17
|
+
), o = new Map(i.screens.map((s) => [s.route.path, s])), u = new Set((n.scenarios ?? []).map((s) => s.id)), p = [];
|
|
18
18
|
for (const s of e.screens) {
|
|
19
19
|
const d = o.get(s.route.path), h = /* @__PURE__ */ new Map();
|
|
20
20
|
for (const m of s.variations) {
|
|
21
21
|
const b = c.get(m.id);
|
|
22
22
|
b === void 0 ? h.set(m.id, "new") : b !== x(e, m) && h.set(m.id, "changed");
|
|
23
23
|
}
|
|
24
|
-
const f = d?.variations.filter((m) => !
|
|
25
|
-
(!d || k(d) !== k(s) || h.size > 0 || f.length > 0) &&
|
|
24
|
+
const f = d?.variations.filter((m) => !u.has(m.id)) ?? [];
|
|
25
|
+
(!d || k(d) !== k(s) || h.size > 0 || f.length > 0) && p.push({ screen: s, changes: h, removed: f });
|
|
26
26
|
}
|
|
27
|
-
const t = new Set(e.screens.map((s) => s.route.path)),
|
|
28
|
-
return { compared: !0, screens:
|
|
27
|
+
const t = new Set(e.screens.map((s) => s.route.path)), a = i.screens.filter((s) => !t.has(s.route.path)).map((s) => ({ name: s.name, path: s.route.path }));
|
|
28
|
+
return { compared: !0, screens: p, removedScreens: a };
|
|
29
29
|
}
|
|
30
30
|
function x(n, r) {
|
|
31
31
|
return JSON.stringify({ scenario: r, rules: n.rulesOf(r) });
|
|
@@ -33,38 +33,44 @@ function x(n, r) {
|
|
|
33
33
|
function k(n) {
|
|
34
34
|
return JSON.stringify(n.route);
|
|
35
35
|
}
|
|
36
|
-
function N({ head: n, base: r, origin: e, commit:
|
|
37
|
-
const o = w(n),
|
|
38
|
-
t &&
|
|
36
|
+
function N({ head: n, base: r, origin: e, commit: i, maxLength: c }) {
|
|
37
|
+
const o = w(n), u = M(n, r), p = C(n.theme?.labels).pr, t = e?.replace(/\/+$/, "") || void 0, a = [v.start, `## ${p.title}`, "", `> ${p.notice(i?.slice(0, 7))}`, ""];
|
|
38
|
+
t && a.push(`${p.preview}: ${j(u, t)}`, ""), u.screens.length === 0 && u.removedScreens.length === 0 ? a.push(p.nothingChanged, "") : a.push(u.compared ? p.scopeChanged : p.scopeAll, "");
|
|
39
39
|
const s = [];
|
|
40
|
-
if (
|
|
41
|
-
const f =
|
|
42
|
-
s.push(`**${
|
|
40
|
+
if (u.removedScreens.length > 0) {
|
|
41
|
+
const f = u.removedScreens.map((l) => `${g(l.name)} (\`${l.path}\`)`);
|
|
42
|
+
s.push(`**${p.removedScreens}:** ${f.join(", ")}`, "");
|
|
43
43
|
}
|
|
44
44
|
s.push(v.end);
|
|
45
45
|
const d = c === void 0 ? 1 / 0 : c - S(s) - 2e3, h = [];
|
|
46
|
-
for (const f of
|
|
47
|
-
const l =
|
|
48
|
-
h.length === 0 && S(
|
|
46
|
+
for (const f of u.screens) {
|
|
47
|
+
const l = E(f, o, p, t);
|
|
48
|
+
h.length === 0 && S(a) + S(l) <= d ? a.push(...l) : h.push(`${g(f.screen.name)} (\`${f.screen.route.path}\`)`);
|
|
49
49
|
}
|
|
50
|
-
return h.length > 0 &&
|
|
50
|
+
return h.length > 0 && a.push(`**${p.truncated}:** ${h.join(", ")}`, ""), a.push(...s), `${a.join(`
|
|
51
51
|
`)}
|
|
52
52
|
`;
|
|
53
53
|
}
|
|
54
|
+
function j(n, r) {
|
|
55
|
+
const e = n.compared ? n.screens[0] : void 0;
|
|
56
|
+
if (!e) return r;
|
|
57
|
+
const { screen: i, changes: c } = e, o = i.variations.find((u) => c.has(u.id)) ?? i.variations[0];
|
|
58
|
+
return o ? R(o, { origin: r }) : new URL(i.href, r).toString();
|
|
59
|
+
}
|
|
54
60
|
function S(n) {
|
|
55
61
|
return n.reduce((r, e) => r + e.length + 1, 0);
|
|
56
62
|
}
|
|
57
|
-
function
|
|
58
|
-
const { screen: c } = n, o = [`### ${g(c.name)}`, ""],
|
|
59
|
-
o.push(`\`${c.route.path}\`${
|
|
63
|
+
function E(n, r, e, i) {
|
|
64
|
+
const { screen: c } = n, o = [`### ${g(c.name)}`, ""], u = i && c.variations.length === 0 ? ` · [${e.open}](${new URL(c.href, i).toString()})` : "";
|
|
65
|
+
o.push(`\`${c.route.path}\`${u}`, ""), c.description && o.push($(c.description), ""), c.route.expected?.length && o.push(`**${e.screenExpected}**`, "", ...y(c.route.expected), "");
|
|
60
66
|
for (const t of c.variations) {
|
|
61
|
-
const
|
|
67
|
+
const a = n.changes.get(t.id), s = a === "new" ? e.statusNew : a === "changed" ? e.statusChanged : void 0;
|
|
62
68
|
o.push(
|
|
63
69
|
`#### ${g(t.title)} · \`${t.id}\`${s ? ` · ${s}` : ""}`,
|
|
64
70
|
""
|
|
65
71
|
);
|
|
66
72
|
const d = [];
|
|
67
|
-
|
|
73
|
+
i && d.push(`[${e.open}](${R(t, { origin: i })})`);
|
|
68
74
|
const h = r.persona(t.persona);
|
|
69
75
|
h && d.push(`${e.persona}: ${g(h.name)}`), t.ticket && d.push(`${e.ticket}: ${t.ticket}`), d.length > 0 && o.push(d.join(" · "), ""), t.intent && o.push($(t.intent), ""), t.preconditions?.length && o.push(`**${e.preconditions}**`, "", ...O(t.preconditions), ""), t.actions?.length && o.push(`**${e.actions}**`, "", ...O(t.actions), ""), o.push(`**${e.expected}**`, ""), o.push(...t.expected?.length ? y(t.expected) : [e.noExpected], "");
|
|
70
76
|
const f = r.rulesOf(t);
|
|
@@ -74,32 +80,32 @@ function j(n, r, e, u) {
|
|
|
74
80
|
o.push("");
|
|
75
81
|
}
|
|
76
82
|
}
|
|
77
|
-
const
|
|
78
|
-
if (
|
|
83
|
+
const p = r.componentsOfScreen(c);
|
|
84
|
+
if (p.length > 0) {
|
|
79
85
|
o.push(`**${e.components}**`, "", `| ${e.component} | ${e.source} |`, "| --- | --- |");
|
|
80
|
-
for (const t of
|
|
81
|
-
const
|
|
82
|
-
o.push(`| ${P(t.name)} (\`${t.id}\`) | ${
|
|
86
|
+
for (const t of p) {
|
|
87
|
+
const a = t.source ? `\`${P(t.source)}\`` : e.empty;
|
|
88
|
+
o.push(`| ${P(t.name)} (\`${t.id}\`) | ${a} |`);
|
|
83
89
|
}
|
|
84
90
|
o.push("");
|
|
85
91
|
}
|
|
86
92
|
if (n.removed.length > 0) {
|
|
87
|
-
const t = n.removed.map((
|
|
93
|
+
const t = n.removed.map((a) => `${g(a.title)} (\`${a.id}\`)`);
|
|
88
94
|
o.push(`**${e.removedScenarios}:** ${t.join(", ")}`, "");
|
|
89
95
|
}
|
|
90
96
|
return o;
|
|
91
97
|
}
|
|
92
98
|
function z(n, r) {
|
|
93
99
|
const e = (n ?? "").replace(/\r\n/g, `
|
|
94
|
-
`),
|
|
100
|
+
`), i = r.trim(), c = e.indexOf(v.start);
|
|
95
101
|
if (c !== -1) {
|
|
96
|
-
const o = e.indexOf(v.end, c),
|
|
97
|
-
return `${e.slice(0, c)}${
|
|
102
|
+
const o = e.indexOf(v.end, c), u = o === -1 ? "" : e.slice(o + v.end.length);
|
|
103
|
+
return `${e.slice(0, c)}${i}${u}`;
|
|
98
104
|
}
|
|
99
105
|
return e.trim() ? `${e.trimEnd()}
|
|
100
106
|
|
|
101
|
-
${
|
|
102
|
-
` : `${
|
|
107
|
+
${i}
|
|
108
|
+
` : `${i}
|
|
103
109
|
`;
|
|
104
110
|
}
|
|
105
111
|
function y(n) {
|
|
@@ -120,7 +126,7 @@ function g(n) {
|
|
|
120
126
|
export {
|
|
121
127
|
v as PR_MARKERS,
|
|
122
128
|
N as buildPrSection,
|
|
123
|
-
|
|
129
|
+
M as diffProducts,
|
|
124
130
|
z as mergePrBody
|
|
125
131
|
};
|
|
126
132
|
//# sourceMappingURL=pr.js.map
|
package/dist/pr.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pr.js","sources":["../src/pr/index.ts"],"sourcesContent":["/**\n * `@brucesantos/design-space/pr`\n *\n * A descrição do PR gerada do registro do produto. O critério de aceite é\n * escrito uma vez, no cenário (`intent`, `preconditions`, `actions`,\n * `expected`, `rules`), e chega ao PR por aqui, reescrito a cada push. Ninguém\n * copia nada à mão: cópia diverge na primeira mudança, e quem valida a entrega,\n * gente ou agente, precisa de uma fonte só. Ver a decisão 0018.\n *\n * Funções puras, sem Node nem DOM. Quem lê o produto do disco e fala com o\n * repositório é o comando `design-space-pr`.\n */\n\nimport { scenarioUrl } from \"../deploy/index.js\";\nimport { createRegistry, type Registry, type ScreenNode } from \"../registry/index.js\";\nimport { resolveLabels, type Labels } from \"../shell/labels.js\";\nimport type { ProductDefinition, Scenario } from \"../types/index.js\";\n\n/**\n * Marcas do bloco gerado. Tudo entre elas é reescrito a cada push; tudo fora\n * delas é de quem escreveu o PR e nunca é tocado.\n */\nexport const PR_MARKERS = {\n start: \"<!-- design-space:pr:start -->\",\n end: \"<!-- design-space:pr:end -->\",\n} as const;\n\nexport type PrChange = \"new\" | \"changed\";\n\nexport type PrScreen = {\n screen: ScreenNode;\n /** O que mudou em cada variação neste PR, por id. Ausente: sem mudança. */\n changes: Map<string, PrChange>;\n /** Variações que a base tinha nesta tela e o PR removeu. */\n removed: Scenario[];\n};\n\nexport type PrDiff = {\n /** `false` quando não houve base para comparar: aí todas as telas entram. */\n compared: boolean;\n /** Telas que o PR cria ou altera, na ordem do produto. */\n screens: PrScreen[];\n /** Telas que existiam na base e o PR removeu. */\n removedScreens: { name: string; path: string }[];\n};\n\n/**\n * Compara o registro do PR com o da base.\n *\n * Uma tela entra quando é nova, quando a rota mudou ou quando algum cenário\n * dela foi criado, alterado ou removido. Mudança no enunciado de uma regra\n * conta como mudança dos cenários que a citam. Mudança só no código da tela,\n * sem tocar no registro, não muda critério e não entra.\n */\nexport function diffProducts(head: ProductDefinition, base?: ProductDefinition): PrDiff {\n const registry = createRegistry(head);\n if (!base) {\n return {\n compared: false,\n screens: registry.screens.map((screen) => ({ screen, changes: new Map(), removed: [] })),\n removedScreens: [],\n };\n }\n\n const baseRegistry = createRegistry(base);\n const baseScenarios = new Map(\n (base.scenarios ?? []).map((scenario) => [scenario.id, scenarioPrint(baseRegistry, scenario)]),\n );\n const baseScreens = new Map(baseRegistry.screens.map((screen) => [screen.route.path, screen]));\n const headIds = new Set((head.scenarios ?? []).map((scenario) => scenario.id));\n\n const screens: PrScreen[] = [];\n for (const screen of registry.screens) {\n const before = baseScreens.get(screen.route.path);\n const changes = new Map<string, PrChange>();\n for (const variation of screen.variations) {\n const print = baseScenarios.get(variation.id);\n if (print === undefined) changes.set(variation.id, \"new\");\n else if (print !== scenarioPrint(registry, variation)) changes.set(variation.id, \"changed\");\n }\n const removed = before?.variations.filter((variation) => !headIds.has(variation.id)) ?? [];\n const routeChanged = !before || routePrint(before) !== routePrint(screen);\n if (routeChanged || changes.size > 0 || removed.length > 0) screens.push({ screen, changes, removed });\n }\n\n const headPaths = new Set(registry.screens.map((screen) => screen.route.path));\n const removedScreens = baseRegistry.screens\n .filter((screen) => !headPaths.has(screen.route.path))\n .map((screen) => ({ name: screen.name, path: screen.route.path }));\n\n return { compared: true, screens, removedScreens };\n}\n\n// Função não serializa: o componente da tela fica de fora, e o que sobra é o\n// que o registro declara.\nfunction scenarioPrint(registry: Registry, scenario: Scenario): string {\n return JSON.stringify({ scenario, rules: registry.rulesOf(scenario) });\n}\n\nfunction routePrint(screen: ScreenNode): string {\n return JSON.stringify(screen.route);\n}\n\nexport type PrSectionInput = {\n /** O produto como está no PR. */\n head: ProductDefinition;\n /** O produto na base do PR. Sem ela, todas as telas entram. */\n base?: ProductDefinition;\n /** Origem absoluta do preview deste PR. Sem ela, o bloco sai sem links. */\n origin?: string;\n /** Commit do PR que gerou o bloco. */\n commit?: string;\n /**\n * Tamanho máximo do bloco, em caracteres. As telas que não couberem saem só\n * pelo nome. A descrição de PR tem limite, e um bloco cortado no meio de um\n * critério é pior que um que diz o que ficou de fora.\n */\n maxLength?: number;\n};\n\n/** O bloco gerado, com as marcas. */\nexport function buildPrSection({ head, base, origin, commit, maxLength }: PrSectionInput): string {\n const registry = createRegistry(head);\n const diff = diffProducts(head, base);\n const pr = resolveLabels(head.theme?.labels).pr;\n const root = origin?.replace(/\\/+$/, \"\") || undefined;\n\n const lines: string[] = [PR_MARKERS.start, `## ${pr.title}`, \"\", `> ${pr.notice(commit?.slice(0, 7))}`, \"\"];\n if (root) lines.push(`${pr.preview}: ${root}`, \"\");\n\n if (diff.screens.length === 0 && diff.removedScreens.length === 0) {\n lines.push(pr.nothingChanged, \"\");\n } else {\n lines.push(diff.compared ? pr.scopeChanged : pr.scopeAll, \"\");\n }\n\n const tail: string[] = [];\n if (diff.removedScreens.length > 0) {\n const names = diff.removedScreens.map((screen) => `${escapeMarkdown(screen.name)} (\\`${screen.path}\\`)`);\n tail.push(`**${pr.removedScreens}:** ${names.join(\", \")}`, \"\");\n }\n tail.push(PR_MARKERS.end);\n\n // Folga para a linha das telas que ficarem de fora.\n const budget = maxLength === undefined ? Infinity : maxLength - size(tail) - 2000;\n const left: string[] = [];\n for (const item of diff.screens) {\n const chunk = screenLines(item, registry, pr, root);\n if (left.length === 0 && size(lines) + size(chunk) <= budget) lines.push(...chunk);\n else left.push(`${escapeMarkdown(item.screen.name)} (\\`${item.screen.route.path}\\`)`);\n }\n if (left.length > 0) lines.push(`**${pr.truncated}:** ${left.join(\", \")}`, \"\");\n\n lines.push(...tail);\n return `${lines.join(\"\\n\")}\\n`;\n}\n\nfunction size(lines: string[]): number {\n return lines.reduce((total, line) => total + line.length + 1, 0);\n}\n\nfunction screenLines(item: PrScreen, registry: Registry, pr: Labels[\"pr\"], origin: string | undefined): string[] {\n const { screen } = item;\n const lines = [`### ${escapeMarkdown(screen.name)}`, \"\"];\n // Com cenário, cada um tem o seu link; o da tela só faz falta quando não há\n // nenhum, e aí abre o caminho de exemplo (`params`).\n const link =\n origin && screen.variations.length === 0\n ? ` · [${pr.open}](${new URL(screen.href, origin).toString()})`\n : \"\";\n lines.push(`\\`${screen.route.path}\\`${link}`, \"\");\n if (screen.description) lines.push(oneLine(screen.description), \"\");\n if (screen.route.expected?.length) lines.push(`**${pr.screenExpected}**`, \"\", ...numbered(screen.route.expected), \"\");\n\n for (const variation of screen.variations) {\n const change = item.changes.get(variation.id);\n const status = change === \"new\" ? pr.statusNew : change === \"changed\" ? pr.statusChanged : undefined;\n lines.push(\n `#### ${escapeMarkdown(variation.title)} · \\`${variation.id}\\`${status ? ` · ${status}` : \"\"}`,\n \"\",\n );\n\n const meta: string[] = [];\n if (origin) meta.push(`[${pr.open}](${scenarioUrl(variation, { origin })})`);\n const persona = registry.persona(variation.persona);\n if (persona) meta.push(`${pr.persona}: ${escapeMarkdown(persona.name)}`);\n if (variation.ticket) meta.push(`${pr.ticket}: ${variation.ticket}`);\n if (meta.length > 0) lines.push(meta.join(\" · \"), \"\");\n\n if (variation.intent) lines.push(oneLine(variation.intent), \"\");\n if (variation.preconditions?.length) lines.push(`**${pr.preconditions}**`, \"\", ...bullets(variation.preconditions), \"\");\n if (variation.actions?.length) lines.push(`**${pr.actions}**`, \"\", ...bullets(variation.actions), \"\");\n lines.push(`**${pr.expected}**`, \"\");\n lines.push(...(variation.expected?.length ? numbered(variation.expected) : [pr.noExpected]), \"\");\n\n const rules = registry.rulesOf(variation);\n if (rules.length > 0) {\n lines.push(`**${pr.rules}**`, \"\");\n for (const rule of rules) lines.push(`- \\`${rule.id}\\` — ${oneLine(rule.statement)}`);\n lines.push(\"\");\n }\n }\n\n const components = registry.componentsOfScreen(screen);\n if (components.length > 0) {\n lines.push(`**${pr.components}**`, \"\", `| ${pr.component} | ${pr.source} |`, \"| --- | --- |\");\n for (const component of components) {\n const source = component.source ? `\\`${escapeCell(component.source)}\\`` : pr.empty;\n lines.push(`| ${escapeCell(component.name)} (\\`${component.id}\\`) | ${source} |`);\n }\n lines.push(\"\");\n }\n\n if (item.removed.length > 0) {\n const names = item.removed.map((variation) => `${escapeMarkdown(variation.title)} (\\`${variation.id}\\`)`);\n lines.push(`**${pr.removedScenarios}:** ${names.join(\", \")}`, \"\");\n }\n\n return lines;\n}\n\n/**\n * A descrição nova do PR.\n *\n * Com as marcas, troca só o que está entre elas. Sem as marcas, acrescenta o\n * bloco ao fim do que já houver. Em branco, a descrição é só o bloco: o PR não\n * tem seção para preencher à mão, e o formato é o mesmo em todo produto.\n */\nexport function mergePrBody(body: string | null | undefined, section: string): string {\n const current = (body ?? \"\").replace(/\\r\\n/g, \"\\n\");\n const block = section.trim();\n const start = current.indexOf(PR_MARKERS.start);\n if (start !== -1) {\n const end = current.indexOf(PR_MARKERS.end, start);\n // Marca de fim apagada à mão: o bloco vai até o fim da descrição.\n const after = end === -1 ? \"\" : current.slice(end + PR_MARKERS.end.length);\n return `${current.slice(0, start)}${block}${after}`;\n }\n return current.trim() ? `${current.trimEnd()}\\n\\n${block}\\n` : `${block}\\n`;\n}\n\nfunction numbered(items: string[]): string[] {\n return items.map((item, index) => `${index + 1}. ${oneLine(item)}`);\n}\n\nfunction bullets(items: string[]): string[] {\n return items.map((item) => `- ${oneLine(item)}`);\n}\n\nfunction oneLine(value: string): string {\n return value.replace(/\\s*\\n\\s*/g, \" \").trim();\n}\n\nfunction escapeCell(value: string): string {\n return oneLine(value).replace(/\\|/g, \"\\\\|\");\n}\n\nfunction escapeMarkdown(value: string): string {\n return oneLine(value).replace(/([*_[\\]`])/g, \"\\\\$1\");\n}\n"],"names":["PR_MARKERS","diffProducts","head","base","registry","createRegistry","screen","baseRegistry","baseScenarios","scenario","scenarioPrint","baseScreens","headIds","screens","before","changes","variation","print","removed","routePrint","headPaths","removedScreens","buildPrSection","origin","commit","maxLength","diff","pr","resolveLabels","root","lines","tail","names","escapeMarkdown","budget","size","left","item","chunk","screenLines","total","line","link","oneLine","numbered","change","status","meta","scenarioUrl","persona","bullets","rules","rule","components","component","source","escapeCell","mergePrBody","body","section","current","block","start","end","after","items","index","value"],"mappings":";;AAsBO,MAAMA,IAAa;AAAA,EACxB,OAAO;AAAA,EACP,KAAK;AACP;AA6BO,SAASC,EAAaC,GAAyBC,GAAkC;AACtF,QAAMC,IAAWC,EAAeH,CAAI;AACpC,MAAI,CAACC;AACH,WAAO;AAAA,MACL,UAAU;AAAA,MACV,SAASC,EAAS,QAAQ,IAAI,CAACE,OAAY,EAAE,QAAAA,GAAQ,6BAAa,IAAA,GAAO,SAAS,CAAA,IAAK;AAAA,MACvF,gBAAgB,CAAA;AAAA,IAAC;AAIrB,QAAMC,IAAeF,EAAeF,CAAI,GAClCK,IAAgB,IAAI;AAAA,KACvBL,EAAK,aAAa,CAAA,GAAI,IAAI,CAACM,MAAa,CAACA,EAAS,IAAIC,EAAcH,GAAcE,CAAQ,CAAC,CAAC;AAAA,EAAA,GAEzFE,IAAc,IAAI,IAAIJ,EAAa,QAAQ,IAAI,CAACD,MAAW,CAACA,EAAO,MAAM,MAAMA,CAAM,CAAC,CAAC,GACvFM,IAAU,IAAI,KAAKV,EAAK,aAAa,IAAI,IAAI,CAACO,MAAaA,EAAS,EAAE,CAAC,GAEvEI,IAAsB,CAAA;AAC5B,aAAWP,KAAUF,EAAS,SAAS;AACrC,UAAMU,IAASH,EAAY,IAAIL,EAAO,MAAM,IAAI,GAC1CS,wBAAc,IAAA;AACpB,eAAWC,KAAaV,EAAO,YAAY;AACzC,YAAMW,IAAQT,EAAc,IAAIQ,EAAU,EAAE;AAC5C,MAAIC,MAAU,SAAWF,EAAQ,IAAIC,EAAU,IAAI,KAAK,IAC/CC,MAAUP,EAAcN,GAAUY,CAAS,KAAGD,EAAQ,IAAIC,EAAU,IAAI,SAAS;AAAA,IAC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,KAAK;AAC5C;AAEA,SAASlC,EAAekC,GAAuB;AAC7C,SAAOxB,EAAQwB,CAAK,EAAE,QAAQ,eAAe,MAAM;AACrD;"}
|
|
1
|
+
{"version":3,"file":"pr.js","sources":["../src/pr/index.ts"],"sourcesContent":["/**\n * `@brucesantos/design-space/pr`\n *\n * A descrição do PR gerada do registro do produto. O critério de aceite é\n * escrito uma vez, no cenário (`intent`, `preconditions`, `actions`,\n * `expected`, `rules`), e chega ao PR por aqui, reescrito a cada push. Ninguém\n * copia nada à mão: cópia diverge na primeira mudança, e quem valida a entrega,\n * gente ou agente, precisa de uma fonte só. Ver a decisão 0018.\n *\n * Funções puras, sem Node nem DOM. Quem lê o produto do disco e fala com o\n * repositório é o comando `design-space-pr`.\n */\n\nimport { scenarioUrl } from \"../deploy/index.js\";\nimport { createRegistry, type Registry, type ScreenNode } from \"../registry/index.js\";\nimport { resolveLabels, type Labels } from \"../shell/labels.js\";\nimport type { ProductDefinition, Scenario } from \"../types/index.js\";\n\n/**\n * Marcas do bloco gerado. Tudo entre elas é reescrito a cada push; tudo fora\n * delas é de quem escreveu o PR e nunca é tocado.\n */\nexport const PR_MARKERS = {\n start: \"<!-- design-space:pr:start -->\",\n end: \"<!-- design-space:pr:end -->\",\n} as const;\n\nexport type PrChange = \"new\" | \"changed\";\n\nexport type PrScreen = {\n screen: ScreenNode;\n /** O que mudou em cada variação neste PR, por id. Ausente: sem mudança. */\n changes: Map<string, PrChange>;\n /** Variações que a base tinha nesta tela e o PR removeu. */\n removed: Scenario[];\n};\n\nexport type PrDiff = {\n /** `false` quando não houve base para comparar: aí todas as telas entram. */\n compared: boolean;\n /** Telas que o PR cria ou altera, na ordem do produto. */\n screens: PrScreen[];\n /** Telas que existiam na base e o PR removeu. */\n removedScreens: { name: string; path: string }[];\n};\n\n/**\n * Compara o registro do PR com o da base.\n *\n * Uma tela entra quando é nova, quando a rota mudou ou quando algum cenário\n * dela foi criado, alterado ou removido. Mudança no enunciado de uma regra\n * conta como mudança dos cenários que a citam. Mudança só no código da tela,\n * sem tocar no registro, não muda critério e não entra.\n */\nexport function diffProducts(head: ProductDefinition, base?: ProductDefinition): PrDiff {\n const registry = createRegistry(head);\n if (!base) {\n return {\n compared: false,\n screens: registry.screens.map((screen) => ({ screen, changes: new Map(), removed: [] })),\n removedScreens: [],\n };\n }\n\n const baseRegistry = createRegistry(base);\n const baseScenarios = new Map(\n (base.scenarios ?? []).map((scenario) => [scenario.id, scenarioPrint(baseRegistry, scenario)]),\n );\n const baseScreens = new Map(baseRegistry.screens.map((screen) => [screen.route.path, screen]));\n const headIds = new Set((head.scenarios ?? []).map((scenario) => scenario.id));\n\n const screens: PrScreen[] = [];\n for (const screen of registry.screens) {\n const before = baseScreens.get(screen.route.path);\n const changes = new Map<string, PrChange>();\n for (const variation of screen.variations) {\n const print = baseScenarios.get(variation.id);\n if (print === undefined) changes.set(variation.id, \"new\");\n else if (print !== scenarioPrint(registry, variation)) changes.set(variation.id, \"changed\");\n }\n const removed = before?.variations.filter((variation) => !headIds.has(variation.id)) ?? [];\n const routeChanged = !before || routePrint(before) !== routePrint(screen);\n if (routeChanged || changes.size > 0 || removed.length > 0) screens.push({ screen, changes, removed });\n }\n\n const headPaths = new Set(registry.screens.map((screen) => screen.route.path));\n const removedScreens = baseRegistry.screens\n .filter((screen) => !headPaths.has(screen.route.path))\n .map((screen) => ({ name: screen.name, path: screen.route.path }));\n\n return { compared: true, screens, removedScreens };\n}\n\n// Função não serializa: o componente da tela fica de fora, e o que sobra é o\n// que o registro declara.\nfunction scenarioPrint(registry: Registry, scenario: Scenario): string {\n return JSON.stringify({ scenario, rules: registry.rulesOf(scenario) });\n}\n\nfunction routePrint(screen: ScreenNode): string {\n return JSON.stringify(screen.route);\n}\n\nexport type PrSectionInput = {\n /** O produto como está no PR. */\n head: ProductDefinition;\n /** O produto na base do PR. Sem ela, todas as telas entram. */\n base?: ProductDefinition;\n /** Origem absoluta do preview deste PR. Sem ela, o bloco sai sem links. */\n origin?: string;\n /** Commit do PR que gerou o bloco. */\n commit?: string;\n /**\n * Tamanho máximo do bloco, em caracteres. As telas que não couberem saem só\n * pelo nome. A descrição de PR tem limite, e um bloco cortado no meio de um\n * critério é pior que um que diz o que ficou de fora.\n */\n maxLength?: number;\n};\n\n/** O bloco gerado, com as marcas. */\nexport function buildPrSection({ head, base, origin, commit, maxLength }: PrSectionInput): string {\n const registry = createRegistry(head);\n const diff = diffProducts(head, base);\n const pr = resolveLabels(head.theme?.labels).pr;\n const root = origin?.replace(/\\/+$/, \"\") || undefined;\n\n const lines: string[] = [PR_MARKERS.start, `## ${pr.title}`, \"\", `> ${pr.notice(commit?.slice(0, 7))}`, \"\"];\n if (root) lines.push(`${pr.preview}: ${previewUrl(diff, root)}`, \"\");\n\n if (diff.screens.length === 0 && diff.removedScreens.length === 0) {\n lines.push(pr.nothingChanged, \"\");\n } else {\n lines.push(diff.compared ? pr.scopeChanged : pr.scopeAll, \"\");\n }\n\n const tail: string[] = [];\n if (diff.removedScreens.length > 0) {\n const names = diff.removedScreens.map((screen) => `${escapeMarkdown(screen.name)} (\\`${screen.path}\\`)`);\n tail.push(`**${pr.removedScreens}:** ${names.join(\", \")}`, \"\");\n }\n tail.push(PR_MARKERS.end);\n\n // Folga para a linha das telas que ficarem de fora.\n const budget = maxLength === undefined ? Infinity : maxLength - size(tail) - 2000;\n const left: string[] = [];\n for (const item of diff.screens) {\n const chunk = screenLines(item, registry, pr, root);\n if (left.length === 0 && size(lines) + size(chunk) <= budget) lines.push(...chunk);\n else left.push(`${escapeMarkdown(item.screen.name)} (\\`${item.screen.route.path}\\`)`);\n }\n if (left.length > 0) lines.push(`**${pr.truncated}:** ${left.join(\", \")}`, \"\");\n\n lines.push(...tail);\n return `${lines.join(\"\\n\")}\\n`;\n}\n\n/**\n * Para onde a linha de preview leva. Com a base comparada, é a primeira tela\n * que o PR toca, no primeiro cenário novo ou alterado dela: a raiz do preview\n * abre a primeira tela do produto, que quase nunca é a do PR. Sem base, ou sem\n * tela tocada, não há tela a preferir e fica a raiz.\n */\nfunction previewUrl(diff: PrDiff, origin: string): string {\n const first = diff.compared ? diff.screens[0] : undefined;\n if (!first) return origin;\n const { screen, changes } = first;\n const variation = screen.variations.find((item) => changes.has(item.id)) ?? screen.variations[0];\n return variation ? scenarioUrl(variation, { origin }) : new URL(screen.href, origin).toString();\n}\n\nfunction size(lines: string[]): number {\n return lines.reduce((total, line) => total + line.length + 1, 0);\n}\n\nfunction screenLines(item: PrScreen, registry: Registry, pr: Labels[\"pr\"], origin: string | undefined): string[] {\n const { screen } = item;\n const lines = [`### ${escapeMarkdown(screen.name)}`, \"\"];\n // Com cenário, cada um tem o seu link; o da tela só faz falta quando não há\n // nenhum, e aí abre o caminho de exemplo (`params`).\n const link =\n origin && screen.variations.length === 0\n ? ` · [${pr.open}](${new URL(screen.href, origin).toString()})`\n : \"\";\n lines.push(`\\`${screen.route.path}\\`${link}`, \"\");\n if (screen.description) lines.push(oneLine(screen.description), \"\");\n if (screen.route.expected?.length) lines.push(`**${pr.screenExpected}**`, \"\", ...numbered(screen.route.expected), \"\");\n\n for (const variation of screen.variations) {\n const change = item.changes.get(variation.id);\n const status = change === \"new\" ? pr.statusNew : change === \"changed\" ? pr.statusChanged : undefined;\n lines.push(\n `#### ${escapeMarkdown(variation.title)} · \\`${variation.id}\\`${status ? ` · ${status}` : \"\"}`,\n \"\",\n );\n\n const meta: string[] = [];\n if (origin) meta.push(`[${pr.open}](${scenarioUrl(variation, { origin })})`);\n const persona = registry.persona(variation.persona);\n if (persona) meta.push(`${pr.persona}: ${escapeMarkdown(persona.name)}`);\n if (variation.ticket) meta.push(`${pr.ticket}: ${variation.ticket}`);\n if (meta.length > 0) lines.push(meta.join(\" · \"), \"\");\n\n if (variation.intent) lines.push(oneLine(variation.intent), \"\");\n if (variation.preconditions?.length) lines.push(`**${pr.preconditions}**`, \"\", ...bullets(variation.preconditions), \"\");\n if (variation.actions?.length) lines.push(`**${pr.actions}**`, \"\", ...bullets(variation.actions), \"\");\n lines.push(`**${pr.expected}**`, \"\");\n lines.push(...(variation.expected?.length ? numbered(variation.expected) : [pr.noExpected]), \"\");\n\n const rules = registry.rulesOf(variation);\n if (rules.length > 0) {\n lines.push(`**${pr.rules}**`, \"\");\n for (const rule of rules) lines.push(`- \\`${rule.id}\\` — ${oneLine(rule.statement)}`);\n lines.push(\"\");\n }\n }\n\n const components = registry.componentsOfScreen(screen);\n if (components.length > 0) {\n lines.push(`**${pr.components}**`, \"\", `| ${pr.component} | ${pr.source} |`, \"| --- | --- |\");\n for (const component of components) {\n const source = component.source ? `\\`${escapeCell(component.source)}\\`` : pr.empty;\n lines.push(`| ${escapeCell(component.name)} (\\`${component.id}\\`) | ${source} |`);\n }\n lines.push(\"\");\n }\n\n if (item.removed.length > 0) {\n const names = item.removed.map((variation) => `${escapeMarkdown(variation.title)} (\\`${variation.id}\\`)`);\n lines.push(`**${pr.removedScenarios}:** ${names.join(\", \")}`, \"\");\n }\n\n return lines;\n}\n\n/**\n * A descrição nova do PR.\n *\n * Com as marcas, troca só o que está entre elas. Sem as marcas, acrescenta o\n * bloco ao fim do que já houver. Em branco, a descrição é só o bloco: o PR não\n * tem seção para preencher à mão, e o formato é o mesmo em todo produto.\n */\nexport function mergePrBody(body: string | null | undefined, section: string): string {\n const current = (body ?? \"\").replace(/\\r\\n/g, \"\\n\");\n const block = section.trim();\n const start = current.indexOf(PR_MARKERS.start);\n if (start !== -1) {\n const end = current.indexOf(PR_MARKERS.end, start);\n // Marca de fim apagada à mão: o bloco vai até o fim da descrição.\n const after = end === -1 ? \"\" : current.slice(end + PR_MARKERS.end.length);\n return `${current.slice(0, start)}${block}${after}`;\n }\n return current.trim() ? `${current.trimEnd()}\\n\\n${block}\\n` : `${block}\\n`;\n}\n\nfunction numbered(items: string[]): string[] {\n return items.map((item, index) => `${index + 1}. ${oneLine(item)}`);\n}\n\nfunction bullets(items: string[]): string[] {\n return items.map((item) => `- ${oneLine(item)}`);\n}\n\nfunction oneLine(value: string): string {\n return value.replace(/\\s*\\n\\s*/g, \" \").trim();\n}\n\nfunction escapeCell(value: string): string {\n return oneLine(value).replace(/\\|/g, \"\\\\|\");\n}\n\nfunction escapeMarkdown(value: string): string {\n return oneLine(value).replace(/([*_[\\]`])/g, \"\\\\$1\");\n}\n"],"names":["PR_MARKERS","diffProducts","head","base","registry","createRegistry","screen","baseRegistry","baseScenarios","scenario","scenarioPrint","baseScreens","headIds","screens","before","changes","variation","print","removed","routePrint","headPaths","removedScreens","buildPrSection","origin","commit","maxLength","diff","pr","resolveLabels","root","lines","previewUrl","tail","names","escapeMarkdown","budget","size","left","item","chunk","screenLines","first","scenarioUrl","total","line","link","oneLine","numbered","change","status","meta","persona","bullets","rules","rule","components","component","source","escapeCell","mergePrBody","body","section","current","block","start","end","after","items","index","value"],"mappings":";;AAsBO,MAAMA,IAAa;AAAA,EACxB,OAAO;AAAA,EACP,KAAK;AACP;AA6BO,SAASC,EAAaC,GAAyBC,GAAkC;AACtF,QAAMC,IAAWC,EAAeH,CAAI;AACpC,MAAI,CAACC;AACH,WAAO;AAAA,MACL,UAAU;AAAA,MACV,SAASC,EAAS,QAAQ,IAAI,CAACE,OAAY,EAAE,QAAAA,GAAQ,6BAAa,IAAA,GAAO,SAAS,CAAA,IAAK;AAAA,MACvF,gBAAgB,CAAA;AAAA,IAAC;AAIrB,QAAMC,IAAeF,EAAeF,CAAI,GAClCK,IAAgB,IAAI;AAAA,KACvBL,EAAK,aAAa,CAAA,GAAI,IAAI,CAACM,MAAa,CAACA,EAAS,IAAIC,EAAcH,GAAcE,CAAQ,CAAC,CAAC;AAAA,EAAA,GAEzFE,IAAc,IAAI,IAAIJ,EAAa,QAAQ,IAAI,CAACD,MAAW,CAACA,EAAO,MAAM,MAAMA,CAAM,CAAC,CAAC,GACvFM,IAAU,IAAI,KAAKV,EAAK,aAAa,IAAI,IAAI,CAACO,MAAaA,EAAS,EAAE,CAAC,GAEvEI,IAAsB,CAAA;AAC5B,aAAWP,KAAUF,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MAAU,IAAI;AAChB,UAAMC,IAAMH,EAAQ,QAAQ9D,EAAW,KAAKgE,CAAK,GAE3CE,IAAQD,MAAQ,KAAK,KAAKH,EAAQ,MAAMG,IAAMjE,EAAW,IAAI,MAAM;AACzE,WAAO,GAAG8D,EAAQ,MAAM,GAAGE,CAAK,CAAC,GAAGD,CAAK,GAAGG,CAAK;AAAA,EACnD;AACA,SAAOJ,EAAQ,KAAA,IAAS,GAAGA,EAAQ,SAAS;AAAA;AAAA,EAAOC,CAAK;AAAA,IAAO,GAAGA,CAAK;AAAA;AACzE;AAEA,SAAShB,EAASoB,GAA2B;AAC3C,SAAOA,EAAM,IAAI,CAAC7B,GAAM8B,MAAU,GAAGA,IAAQ,CAAC,KAAKtB,EAAQR,CAAI,CAAC,EAAE;AACpE;AAEA,SAASc,EAAQe,GAA2B;AAC1C,SAAOA,EAAM,IAAI,CAAC7B,MAAS,KAAKQ,EAAQR,CAAI,CAAC,EAAE;AACjD;AAEA,SAASQ,EAAQuB,GAAuB;AACtC,SAAOA,EAAM,QAAQ,aAAa,GAAG,EAAE,KAAA;AACzC;AAEA,SAASX,EAAWW,GAAuB;AACzC,SAAOvB,EAAQuB,CAAK,EAAE,QAAQ,OAAO,KAAK;AAC5C;AAEA,SAASnC,EAAemC,GAAuB;AAC7C,SAAOvB,EAAQuB,CAAK,EAAE,QAAQ,eAAe,MAAM;AACrD;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brucesantos/design-space",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.1",
|
|
4
4
|
"description": "Motor neutro do Bananas Design Space: telas como rotas com variações, catálogo de componentes, chrome em preto e branco com a UI do produto num iframe, deep links e controles de persona/viewport/rede. Não contém UI de cliente.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|