@arcgis/codemod 6.0.0-next.3 → 6.0.0-next.30

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.
@@ -0,0 +1,258 @@
1
+ import k from "typescript";
2
+ import { findPath as S, asyncFindPath as y } from "@arcgis/node-toolkit/file";
3
+ import { path as p } from "@arcgis/node-toolkit/path";
4
+ import { retrievePackageJson as v, asyncRetrievePackageJson as E } from "@arcgis/node-toolkit/packageJson";
5
+ import { log as b } from "@arcgis/toolkit/log";
6
+ import { realpath as h, readFile as x, readdir as j } from "node:fs/promises";
7
+ import { f as D } from "./log.js";
8
+ import { b as $ } from "./cli.js";
9
+ import { s as M } from "./classification.js";
10
+ function V(e) {
11
+ return typeof e == "string" ? e : e.map((n) => n.kind === k.SyntaxKind.JSDocText ? n.text : O(n.getText())).join("");
12
+ }
13
+ function W(e) {
14
+ return e === void 0 ? void 0 : N(k.displayPartsToString([...e]));
15
+ }
16
+ function N(e) {
17
+ return e.replace(
18
+ /\{@link(?:code|plain)?\s+([\s\S]*?)\}/gu,
19
+ (n, s) => P(s)
20
+ );
21
+ }
22
+ function O(e) {
23
+ const n = /^\{@link(?:code|plain)?\s+([\s\S]*?)\}$/u.exec(e)?.[1];
24
+ return n === void 0 ? e : P(n);
25
+ }
26
+ function P(e) {
27
+ const n = e.trim().replace(/^(\S+)\s+([/:#!.])/u, "$1$2"), s = n.indexOf("|");
28
+ if (s !== -1)
29
+ return n.slice(s + 1).trim() || n.slice(0, s).trim();
30
+ const [a, ...i] = n.split(/\s+/u);
31
+ return i.join(" ") || a;
32
+ }
33
+ function q(e, n) {
34
+ const s = S("package.json", e);
35
+ return s === void 0 ? n : v(p.dirname(s)).name ?? n;
36
+ }
37
+ const m = {
38
+ docsLegacyDependencyLocations: /* @__PURE__ */ new Map([
39
+ ["@arcgis/coding-components", "packages/coding-packages/coding-components"],
40
+ ["@arcgis/core", "packages/core-packages/core/output/npm/esm"],
41
+ ["@arcgis/lumina", "packages/support-packages/lit"],
42
+ ["@arcgis/map-components", "packages/map-packages/map-components"],
43
+ ["@arcgis/toolkit", "packages/support-packages/toolkit"],
44
+ ["@esri/calcite-components", "packages/map-packages/map-components/node_modules/@esri/calcite-components"],
45
+ ["@esri/calcite-components-react", "packages/docs/app/node_modules/@esri/calcite-components-react"],
46
+ ["monaco-editor", "packages/docs/app/node_modules/monaco-editor"]
47
+ ]),
48
+ excludedPackageNames: /* @__PURE__ */ new Set(),
49
+ excludedPathFragments: ["/.astro/"],
50
+ excludedDefinitionPathFragments: ["test-package", "packages/docs/lumina-code-samples/", "packages/starter-packages/"],
51
+ ignoreDeprecatedApis: [],
52
+ ignoredDeprecationsByIncludes: []
53
+ };
54
+ function G(e) {
55
+ const n = /* @__PURE__ */ new Map(), s = {};
56
+ if (e?.contents.name !== "@webgis/docs")
57
+ return { packages: n, paths: s };
58
+ const a = p.dirname(e.filePath), i = p.resolve(a, "../../..");
59
+ if (p.relative(i, a) !== "packages/docs/app" || !k.sys.fileExists(p.join(i, "pnpm-workspace.yaml")))
60
+ return { packages: n, paths: s };
61
+ const o = new Set(
62
+ Object.entries({
63
+ ...e.contents.dependencies,
64
+ ...e.contents.devDependencies,
65
+ ...e.contents.peerDependencies,
66
+ ...e.contents.optionalDependencies
67
+ }).filter(([, t]) => t === "catalog:legacyStarshipDeps").map(([t]) => t)
68
+ );
69
+ if (o.size === 0)
70
+ throw Error(
71
+ "Didn't find any catalog:legacyStarshipDeps in @webgis/docs. Update special handling in @arcgis/codemod"
72
+ );
73
+ for (const t of o) {
74
+ const r = m.docsLegacyDependencyLocations.get(t);
75
+ if (r === void 0)
76
+ throw new Error(
77
+ `Unmapped legacy dependency ${t} in @webgis/docs. Update special handling in @arcgis/codemod.`
78
+ );
79
+ const c = p.join(i, r), d = p.join(c, "package.json");
80
+ if (!k.sys.fileExists(d))
81
+ throw new Error(
82
+ `Missing audit dependency ${t} at ${d}. Install dependencies and build workspace packages before auditing usages.`
83
+ );
84
+ const u = v(c);
85
+ n.set(t, d);
86
+ for (const [f, l] of Object.entries(
87
+ u.exports ?? { ".": u.types ?? "./index.d.ts", "./*": "./*" }
88
+ )) {
89
+ const w = typeof l == "string" ? l : l.types;
90
+ w !== void 0 && (s[f === "." ? t : `${t}/${f.slice(2)}`] = [p.resolve(c, w)]);
91
+ }
92
+ }
93
+ return { packages: n, paths: s };
94
+ }
95
+ function H(e) {
96
+ return e !== void 0 && m.excludedPackageNames.has(e);
97
+ }
98
+ function T(e) {
99
+ return m.excludedPathFragments.some((n) => `/${e}`.includes(n));
100
+ }
101
+ function Q(e) {
102
+ return T(e) || m.excludedDefinitionPathFragments.some((n) => e.includes(n));
103
+ }
104
+ function X(e, n) {
105
+ return m.ignoreDeprecatedApis.some((s) => s === e) || n != null && m.ignoredDeprecationsByIncludes.some((s) => n.includes(s));
106
+ }
107
+ function C(e, n, s) {
108
+ const a = JSON.parse(e), i = { modulePaths: /* @__PURE__ */ new Map(), definitions: [], components: /* @__PURE__ */ new Set() };
109
+ for (const o of a.modules) {
110
+ o.sourcePath !== void 0 && i.modulePaths.set(M(o.sourcePath), o.path);
111
+ for (const t of o.declarations ?? []) {
112
+ let r = function(d, u, f, l) {
113
+ f !== !0 && typeof f != "string" || i.definitions.push({
114
+ package: s,
115
+ module: o.path,
116
+ name: l ?? d,
117
+ kind: l === void 0 ? u : "field",
118
+ memberOf: l === void 0 ? u === "element" ? void 0 : c : t.name,
119
+ ...l === void 0 ? {} : { attribute: { tagName: c, name: d } },
120
+ provenance: "manifest",
121
+ reason: typeof f == "string" ? f : void 0,
122
+ sourceFileName: n,
123
+ line: 1,
124
+ column: 1
125
+ });
126
+ };
127
+ if (!("tagName" in t) || t.tagName === void 0)
128
+ continue;
129
+ const c = t.tagName;
130
+ i.components.add(c), r(c, "element", t.deprecated);
131
+ for (const [d, u] of [
132
+ ["cssProperties", "css-property"],
133
+ ["cssParts", "css-part"],
134
+ ["cssStates", "css-state"],
135
+ ["slots", "slot"]
136
+ ])
137
+ for (const f of t[d] ?? [])
138
+ d === "slots" && f.name === "" || r(f.name, u, f.deprecated);
139
+ for (const d of t.attributes ?? [])
140
+ r(d.name, "attribute", d.deprecated, d.fieldName);
141
+ }
142
+ }
143
+ return i;
144
+ }
145
+ function Y(e) {
146
+ const n = e.flatMap((o) => o.definitions), s = /* @__PURE__ */ new Map();
147
+ for (const o of e)
148
+ for (const t of o.components) {
149
+ const r = s.get(t) ?? [];
150
+ r.push(o), s.set(t, r);
151
+ }
152
+ const a = /* @__PURE__ */ new Map(), i = Map.groupBy(
153
+ n.filter(({ kind: o }) => o === "css-property"),
154
+ ({ name: o }) => o
155
+ );
156
+ for (const [o, t] of i)
157
+ new Set(t.map((r) => r.package)).size === 1 && a.set(o, t[0]);
158
+ return { hasDeprecatedApis: n.length > 0, components: s, cssVariables: a };
159
+ }
160
+ function Z(e = "warn", n) {
161
+ const s = /* @__PURE__ */ new Map();
162
+ return async (a) => {
163
+ const i = await h(a);
164
+ let o = s.get(i);
165
+ return o === void 0 && (o = F(i, n).catch((t) => {
166
+ if (n?.(), e === "throw")
167
+ throw new Error(
168
+ `Unable to read component manifest for ${i}. Build the package before auditing definitions.`,
169
+ { cause: t }
170
+ );
171
+ b("warn", D(i), `Unable to read component manifest: ${String(t)}`);
172
+ }), s.set(i, o)), await o;
173
+ };
174
+ }
175
+ async function ee(e, n, s, a) {
176
+ const i = /* @__PURE__ */ new Set([
177
+ ...Object.keys(e.contents.dependencies ?? {}),
178
+ ...Object.keys(e.contents.devDependencies ?? {}),
179
+ ...Object.keys(e.contents.peerDependencies ?? {}),
180
+ ...Object.keys(e.contents.optionalDependencies ?? {})
181
+ ]), o = await Promise.all(
182
+ [...i].filter((t) => t !== e.contents.name && (!s || $(t))).map(async (t) => {
183
+ const r = a?.get(t) ?? await y(p.join("node_modules", t, "package.json"), p.dirname(e.filePath));
184
+ if (r === void 0)
185
+ return [];
186
+ const c = await n(r), d = t === "@esri/calcite-components" ? await y(
187
+ "node_modules/@esri/calcite-design-tokens/package.json",
188
+ p.dirname(await h(r))
189
+ ) : void 0;
190
+ return [c, d === void 0 ? void 0 : await n(d)];
191
+ })
192
+ );
193
+ return [...new Set(o.flat().filter((t) => t !== void 0))];
194
+ }
195
+ async function F(e, n) {
196
+ const s = p.dirname(e), a = await E(s);
197
+ if (a.name === "@esri/calcite-design-tokens")
198
+ try {
199
+ return await L(s, a.name);
200
+ } catch (t) {
201
+ n?.(), b("error", D(s), `Calcite design tokens integration is out of date: ${String(t)}`);
202
+ return;
203
+ }
204
+ const i = typeof a.customElements == "string" ? a.customElements : a.customElements?.[0];
205
+ if (i === void 0)
206
+ return;
207
+ const o = await h(p.resolve(s, i));
208
+ return C(await x(o, "utf8"), o, a.name);
209
+ }
210
+ async function L(e, n) {
211
+ const s = p.join(e, "dist/docs"), a = /* @__PURE__ */ new Map(), i = (await j(s)).filter((o) => o.endsWith(".json")).sort();
212
+ if (i.length === 0)
213
+ throw new Error(`Missing token documentation JSON files in ${s}`);
214
+ for (const o of i) {
215
+ const t = await h(p.join(s, o)), r = JSON.parse(await x(t, "utf8"));
216
+ if (!g(r) || !Array.isArray(r.tokens))
217
+ throw new Error(`Expected a tokens array in ${t}`);
218
+ for (const c of r.tokens) {
219
+ if (!g(c) || !g(c.attributes) || c.attributes.docs !== void 0 && typeof c.attributes.docs != "string" || c.attributes.status !== void 0 && typeof c.attributes.status != "string" || !g(c.attributes.names) || typeof c.attributes.names.css != "string" || !/^var\(--[-\w]+\)$/u.test(c.attributes.names.css))
220
+ throw new Error(`Expected token attributes.docs/status and attributes.names.css in ${t}`);
221
+ if (c.attributes.docs !== "deprecated" && c.attributes.status !== "deprecated")
222
+ continue;
223
+ const d = c.$description ?? c.description;
224
+ if (typeof d != "string")
225
+ throw new Error(`Expected a deprecated token's $description or description in ${t}`);
226
+ const u = c.attributes.names.css.slice(4, -1);
227
+ a.has(u) || a.set(u, {
228
+ package: n,
229
+ name: u,
230
+ kind: "css-property",
231
+ provenance: "manifest",
232
+ reason: d,
233
+ sourceFileName: t,
234
+ line: 1,
235
+ column: 1
236
+ });
237
+ }
238
+ }
239
+ if (a.size === 0)
240
+ throw new Error(`Expected tokens marked with attributes.docs or attributes.status = "deprecated" in ${s}`);
241
+ return { modulePaths: /* @__PURE__ */ new Map(), definitions: [...a.values()], components: /* @__PURE__ */ new Set() };
242
+ }
243
+ function g(e) {
244
+ return typeof e == "object" && e !== null && !Array.isArray(e);
245
+ }
246
+ export {
247
+ T as a,
248
+ X as b,
249
+ Y as c,
250
+ q as d,
251
+ Z as e,
252
+ V as f,
253
+ G as g,
254
+ W as h,
255
+ Q as i,
256
+ ee as l,
257
+ H as s
258
+ };
@@ -1,70 +1,71 @@
1
- import { d as f } from "./cli.js";
2
- import { o as b, q as m, r as P, s as D, c as O, a as d, b as B } from "./classification.js";
3
- const h = `<!-- ${m} -->`, J = `<!-- ${m}`, w = 65536;
4
- function Q(e) {
5
- const n = k(e, e.findings);
6
- return `${n.summary.trim().replace(/^### /u, "## ")}
1
+ import { h as D, k as d, l as b, m as v, d as w } from "./cli.js";
2
+ import { g as B, i as K, b as $, d as k } from "./classification.js";
3
+ import { markdownTextLimit as y, splitMarkdown as O } from "@arcgis/node-toolkit/markdown";
4
+ const M = `<!-- ${d} -->`, X = `<!-- ${d}`;
5
+ function Y(n) {
6
+ const e = j(n, n.findings);
7
+ return `${e.summary.trim().replace(/^### /u, "## ")}
7
8
 
8
- ${n.details}`;
9
+ ${e.details}`;
9
10
  }
10
- function V(e) {
11
- const n = /* @__PURE__ */ new Map();
12
- for (const o of e.findings) {
13
- const r = $(o.codeowners), i = r.join(","), t = n.get(i) ?? [];
14
- t.push({ ...o, codeowners: r }), n.set(i, t);
11
+ function Z(n) {
12
+ const e = /* @__PURE__ */ new Map();
13
+ for (const o of n.findings) {
14
+ const s = f(o.codeowners), r = s.join(","), t = e.get(r) ?? [];
15
+ t.push({ ...o, codeowners: s }), e.set(r, t);
15
16
  }
16
- return [...n.entries()].map(([o, r]) => {
17
- const i = o === "" ? [] : o.split(","), t = K(e, r);
17
+ return [...e.entries()].map(([o, s]) => {
18
+ const r = o === "" ? [] : o.split(","), t = L(n, s);
18
19
  return {
19
20
  changes: [],
20
- title: b[e.kind],
21
- owners: i,
22
- assignees: i.filter((s) => /^@[^/@\s]+$/u.test(s)).map((s) => s.slice(1)),
23
- chunks: v(t, w, N(i))
21
+ title: D[n.auditKind],
22
+ owners: r,
23
+ assignees: r.filter((a) => /^@[^/@\s]+$/u.test(a)).map((a) => a.slice(1)),
24
+ chunks: _(t, y, G(r))
24
25
  };
25
- }).sort((o, r) => o.title.localeCompare(r.title));
26
+ }).sort((o, s) => o.owners.join(",").localeCompare(s.owners.join(",")));
26
27
  }
27
- function K(e, n) {
28
- const o = $(n.flatMap((i) => i.codeowners)).filter(
29
- (i) => /^@[^/@\s]+\/[^@\s]+$/u.test(i)
30
- ), r = o.length === 0 ? "" : `
28
+ function L(n, e) {
29
+ const o = f(e.flatMap((r) => r.codeowners)).filter(
30
+ (r) => /^@[^/@\s]+\/[^@\s]+$/u.test(r)
31
+ ), s = o.length === 0 ? "" : `
31
32
 
32
33
  CODEOWNERS: ${o.join(", ")}`;
33
- return L(e, n, r);
34
+ return U(n, e, s);
34
35
  }
35
- function L(e, n, o) {
36
- const r = P[e.kind], i = k(e, n);
37
- return `${r}${o}${i.summary}
36
+ function U(n, e, o) {
37
+ const s = b[n.auditKind], r = j(n, e);
38
+ return `${s}${o}${r.summary}
38
39
 
39
- ${D}
40
+ ${v}
40
41
 
41
- ${i.details}`;
42
+ ${r.details}`;
42
43
  }
43
- function k(e, n) {
44
- return e.kind === "usages" ? U(e, n) : z(e, n);
44
+ function j(n, e) {
45
+ return n.auditKind === "usages" ? z(n, e) : E(n, e);
45
46
  }
46
- function U(e, n) {
47
- const o = y(n, "usages"), r = O(n, (s) => s), i = r.map(({ categoryName: s, count: c, packages: a }) => {
48
- const u = a.map(({ packageName: p, count: l }) => ` - \`${p}\`: ${l}`).join(`
47
+ function z(n, e) {
48
+ const o = x(e, "usages"), s = B(e, (a) => a), r = s.map(({ categoryName: a, count: c, packages: m }) => {
49
+ const u = m.map(({ displayName: p, count: i }) => ` - \`${p}\`: ${i}`).join(`
49
50
  `);
50
- return `- **${f[s].label}**: ${c}
51
+ return `- **${w[a].label}**: ${c}
51
52
  ${u}`;
52
53
  }).join(`
53
- `), t = r.map(({ categoryName: s, count: c, packages: a }) => {
54
- const u = a.map(({ packageName: j, count: A, apis: S }) => {
55
- const C = S.flatMap(
56
- ({ items: R }) => M(e, R, "usages", o)
54
+ `), t = s.map(({ categoryName: a, count: c, packages: m }) => {
55
+ const u = m.map(({ displayName: l, count: A, apis: C }) => {
56
+ const P = C.flatMap(
57
+ ({ items: R }) => I(n, R, "usages", o)
57
58
  );
58
- return `#### ${j} (${A})
59
+ return `#### ${l} (${A})
59
60
 
60
- ${C.join(`
61
+ ${P.join(`
61
62
  `)}`;
62
63
  }).join(`
63
64
 
64
- `), p = f[s], l = "description" in p ? `
65
+ `), p = w[a], i = "description" in p ? `
65
66
 
66
67
  ${p.description}` : "";
67
- return `### ${p.label} (${c})${l}
68
+ return `### ${p.label} (${c})${i}
68
69
 
69
70
  ${u}`;
70
71
  }).join(`
@@ -75,24 +76,27 @@ ${u}`;
75
76
 
76
77
  ### Deprecation summary
77
78
 
78
- ${i}`,
79
+ ${r}`,
79
80
  details: `## Deprecation details
80
81
 
81
82
  ${t}`
82
83
  };
83
84
  }
84
- function y(e, n) {
85
+ function x(n, e) {
85
86
  const o = /* @__PURE__ */ new Map();
86
- for (const r of e) {
87
- const i = d(r), t = o.get(i) ?? /* @__PURE__ */ new Set();
88
- t.add(`${r.package}\0${I(n, r)}`), o.set(i, t);
87
+ for (const s of n) {
88
+ const r = $(s), t = o.get(r) ?? /* @__PURE__ */ new Set();
89
+ t.add(`${s.package}\0${S(e, s)}`), o.set(r, t);
89
90
  }
90
- return new Set([...o].filter(([, r]) => r.size > 1).map(([r]) => r));
91
- }
92
- function z(e, n) {
93
- const o = y(n, "definitions");
94
- return { summary: "", details: [...Map.groupBy(n, (t) => t.package).entries()].sort(([t], [s]) => t.localeCompare(s)).map(([t, s]) => {
95
- const c = M(e, s, "definitions", o);
91
+ return new Set([...o].filter(([, s]) => s.size > 1).map(([s]) => s));
92
+ }
93
+ function E(n, e) {
94
+ const o = x(e, "definitions");
95
+ return { summary: "", details: [...Map.groupBy(
96
+ e,
97
+ (t) => K(t.package, t.module ?? g("definitions", t))
98
+ ).entries()].sort(([t], [a]) => t.localeCompare(a)).map(([t, a]) => {
99
+ const c = I(n, a, "definitions", o);
96
100
  return `#### ${t}'s deprecations
97
101
 
98
102
  ${c.join(`
@@ -101,84 +105,84 @@ ${c.join(`
101
105
 
102
106
  `) };
103
107
  }
104
- function M(e, n, o, r) {
105
- const i = [...Map.groupBy(n, (t) => I(o, t))];
106
- return o === "definitions" && i.sort(([t], [s]) => t.localeCompare(s)), i.map(([, t]) => {
107
- const s = d(t[0]), c = x(o, t[0]), a = c !== void 0 && r.has(s) ? `${c} ${s}` : s, u = T(t);
108
- return o === "usages" && u.sort((p, l) => p.localeCompare(l)), E(e, a, u, t);
108
+ function I(n, e, o, s) {
109
+ const r = [...Map.groupBy(e, (t) => S(o, t))];
110
+ return r.sort(([t], [a]) => t.localeCompare(a)), r.map(([, t]) => {
111
+ const a = $(t[0]), c = g(o, t[0]), m = c !== void 0 && s.has(a) ? `${c} ${a}` : a, u = T(t);
112
+ return u.sort((p, i) => p.localeCompare(i)), N(n, m, u, t, o);
109
113
  });
110
114
  }
111
- function E(e, n, o, r) {
112
- const i = o.length === 0 ? "" : ` - ${o.map(q).join(" ")}`, t = [
115
+ function N(n, e, o, s, r) {
116
+ const t = o.length === 0 ? "" : ` - ${o.map(q).join(" ")}`, a = [
117
+ ...new Set(
118
+ s.filter((i) => r === "usages" || i.provenance !== "manifest").toSorted((i, l) => i.file.localeCompare(l.file) || i.line - l.line).map((i) => H(n.repository, n.ref, i.file, i.line))
119
+ )
120
+ ], c = a.length === 1 ? ` ${a[0]}` : a.map((i) => ` - ${i}`).join(`
121
+ `), m = s[0].kind, u = [
113
122
  ...new Set(
114
- r.toSorted((a, u) => a.file.localeCompare(u.file) || a.line - u.line).map((a) => G(e.repository, e.ref, a.file, a.line))
123
+ s.filter(
124
+ (i) => r === "definitions" && i.provenance === "manifest" && i.kind === "css-property"
125
+ ).flatMap(({ memberOf: i }) => i === void 0 ? [] : [i])
115
126
  )
116
- ], s = t.length === 1 ? ` ${t[0]}` : t.map((a) => ` - ${a}`).join(`
117
- `), c = r[0].apiKind;
118
- return `- [ ] \`${n}\`${B(c)}${i}
119
- ${s}`;
127
+ ].sort(), p = u.length === 0 ? "" : ` (components: ${u.map((i) => `\`<${i}>\``).join(", ")})`;
128
+ return `- [ ] \`${e}\`${k(m)}${p}${t}${c === "" ? "" : `
129
+ ${c}`}`;
120
130
  }
121
- function T(e) {
131
+ function T(n) {
122
132
  return [
123
133
  ...new Set(
124
- e.map(({ reason: n }) => n).filter((n) => n !== null && n !== "")
134
+ n.map(({ deprecated: e }) => e).filter((e) => typeof e == "string" && e !== "")
125
135
  )
126
136
  ];
127
137
  }
128
- function v(e, n = w, o = h) {
129
- const r = `${o}
130
- `, i = n - r.length;
131
- if (i < 1)
138
+ function _(n, e = y, o = M) {
139
+ const s = `${o}
140
+ `, r = e - s.length;
141
+ if (r < 1)
132
142
  throw new Error("Issue content limit is too small for the managed marker.");
133
- const t = [];
134
- let s = e;
135
- for (; s.length > i; ) {
136
- const c = s.lastIndexOf(`
137
- `, i), a = c > 0 ? c : i;
138
- t.push(r + s.slice(0, a)), s = s.slice(a + (c > 0 ? 1 : 0));
139
- }
140
- return t.push(r + s), t;
143
+ return O(n, r).map((t) => s + t);
141
144
  }
142
- function N(e) {
143
- return e.length === 0 ? h : `<!-- ${m} ${$(e).join(",")} -->`;
145
+ function G(n) {
146
+ return n.length === 0 ? M : `<!-- ${d} ${f(n).join(",")} -->`;
144
147
  }
145
- function $(e) {
146
- return [...new Set(e)].sort((n, o) => n.localeCompare(o));
148
+ function f(n) {
149
+ return [...new Set(n)].sort((e, o) => e.localeCompare(o));
147
150
  }
148
- function I(e, n) {
149
- return `${d(n)}\0${x(e, n) ?? ""}`;
151
+ function S(n, e) {
152
+ return `${$(e)}${k(e.kind)}\0${g(n, e) ?? ""}`;
150
153
  }
151
- function x(e, n) {
152
- return e === "definitions" ? _(n.file) : n.module;
154
+ function g(n, e) {
155
+ return n === "definitions" && e.provenance !== "manifest" ? W(e.file) : e.module;
153
156
  }
154
- function _(e) {
155
- const n = "/src/", o = "/dist/", r = e.lastIndexOf(n), i = e.lastIndexOf(o), t = Math.max(r, i), s = i > r ? o : n;
156
- return (t === -1 ? e : e.slice(t + s.length)).replace(/\.(?:d\.)?(?:[cm]?ts|tsx)$/u, "");
157
+ function W(n) {
158
+ const e = "/src/", o = "/dist/", s = n.lastIndexOf(e), r = n.lastIndexOf(o), t = Math.max(s, r), a = r > s ? o : e;
159
+ return (t === -1 ? n : n.slice(t + a.length)).replace(/\.(?:d\.)?(?:[cm]?ts|tsx)$/u, "");
157
160
  }
158
- function q(e) {
159
- const n = [], o = (t) => `\0${n.push(t) - 1}\0`, i = e.replaceAll(`\r
161
+ function q(n) {
162
+ const e = [], o = (t) => `\0${e.push(t) - 1}\0`, r = n.replaceAll(`\r
160
163
  `, `
161
164
  `).replaceAll("\r", `
162
165
  `).replace(
163
166
  /\[([^\]\n]+)\]\((https?:\/\/(?:[^()\s]|\([^()\s]*\))+?)\)/gu,
164
- (t, s, c) => o(`[${g(s)}](${c})`)
167
+ (t, a, c) => o(`[${h(a)}](${c})`)
165
168
  ).replace(/https?:\/\/[^\s<>()]+/gu, (t) => {
166
- const s = /[.,;:!?]+$/u.exec(t)?.[0] ?? "";
167
- return `${o(t.slice(0, -s.length || void 0))}${s}`;
169
+ const a = /[.,;:!?]+$/u.exec(t)?.[0] ?? "";
170
+ return `${o(t.slice(0, -a.length || void 0))}${a}`;
168
171
  });
169
- return g(i).replace(/\0(\d+)\0/gu, (t, s) => n[Number(s)]).replaceAll(`
172
+ return h(r).replace(/\0(\d+)\0/gu, (t, a) => e[Number(a)]).replaceAll(`
170
173
  `, `
171
174
  `);
172
175
  }
173
- function g(e) {
174
- return e.replace(/^(\s*)(#{1,6})(?=\s)/gmu, "$1\\$2").replace(/#(?=\d)/gu, "# ");
176
+ function h(n) {
177
+ return n.replace(/^(\s*)(#{1,6})(?=\s)/gmu, "$1\\$2").replace(/#(?=\d)/gu, "# ");
175
178
  }
176
- function G(e, n, o, r) {
177
- const i = n.split("/").map(encodeURIComponent).join("/"), t = o.split("/").map(encodeURIComponent).join("/");
178
- return `https://${e}/blob/${i}/${t}#L${r}`;
179
+ function H(n, e, o, s) {
180
+ const r = e.split("/").map(encodeURIComponent).join("/"), t = o.split("/").map(encodeURIComponent).join("/");
181
+ return `https://${n}/blob/${r}/${t}#L${s}`;
179
182
  }
180
183
  export {
181
- V as c,
182
- Q as f,
183
- J as i
184
+ M as a,
185
+ Z as c,
186
+ Y as f,
187
+ X as i
184
188
  };
@@ -0,0 +1,124 @@
1
+ import { collectOutput as h } from "@arcgis/node-toolkit/shell";
2
+ import { j as c } from "./cli.js";
3
+ const p = /^( (?:- )?https:\/\/[^/\s]+\/[^/\s]+\/[^/\s]+\/blob\/)[a-f0-9]{40}(\/\S+#L\d+)$/gmu;
4
+ class $ {
5
+ constructor(s, t = !1) {
6
+ this.changes = [], this.#i = /* @__PURE__ */ new Map(), this.#n = -1;
7
+ const [e, i, n, ...o] = s.split("/");
8
+ if (e === void 0 || i === void 0 || n === void 0 || o.length > 0)
9
+ throw new Error(`Invalid repository: ${s}`);
10
+ this.#e = e, this.#s = `${i}/${n}`, this.dryRun = t;
11
+ }
12
+ #e;
13
+ #s;
14
+ #i;
15
+ #n;
16
+ async #t(s, t, e) {
17
+ if (process.env.VITEST !== void 0)
18
+ throw new Error("GitHub requests are disabled while running Vitest.");
19
+ const i = await h(
20
+ "gh",
21
+ ["api", "--hostname", this.#e, "--method", s, t, ...e === void 0 ? [] : ["--input", "-"]],
22
+ e === void 0 ? {} : { input: JSON.stringify(e) }
23
+ );
24
+ return i === "" ? void 0 : JSON.parse(i);
25
+ }
26
+ async listOpenIssues(s) {
27
+ const t = await h("gh", [
28
+ "api",
29
+ "--hostname",
30
+ this.#e,
31
+ "--method",
32
+ "GET",
33
+ "--paginate",
34
+ "--slurp",
35
+ "-f",
36
+ `q="${s}" in:title repo:${this.#s} is:issue is:open`,
37
+ "-f",
38
+ "per_page=100",
39
+ "/search/issues"
40
+ ]);
41
+ return JSON.parse(t).flatMap(({ items: e }) => e);
42
+ }
43
+ async createIssue(s, t, e, i) {
44
+ if (this.dryRun) {
45
+ const n = this.#n--;
46
+ return this.#i.set(n, s), this.changes.push(`CREATE issue: ${s}`), { number: n, title: s, body: t, assignees: e.map((o) => ({ login: o })) };
47
+ }
48
+ return await this.#t("POST", `/repos/${this.#s}/issues`, {
49
+ title: s,
50
+ body: t,
51
+ assignees: e,
52
+ labels: i,
53
+ type: c
54
+ });
55
+ }
56
+ async updateIssueBody(s, t) {
57
+ if (this.dryRun) {
58
+ this.changes.push(`UPDATE issue #${s} body`);
59
+ return;
60
+ }
61
+ await this.#t("PATCH", `/repos/${this.#s}/issues/${s}`, { body: t });
62
+ }
63
+ async closeIssue(s) {
64
+ if (this.dryRun) {
65
+ this.changes.push(`CLOSE issue #${s}`);
66
+ return;
67
+ }
68
+ await this.#t("PATCH", `/repos/${this.#s}/issues/${s}`, { state: "closed" });
69
+ }
70
+ async listComments(s) {
71
+ if (this.#i.has(s))
72
+ return [];
73
+ const t = await h("gh", [
74
+ "api",
75
+ "--hostname",
76
+ this.#e,
77
+ "--method",
78
+ "GET",
79
+ "--paginate",
80
+ "--slurp",
81
+ `/repos/${this.#s}/issues/${s}/comments?per_page=100`
82
+ ]);
83
+ return JSON.parse(t).flat();
84
+ }
85
+ async createComment(s, t) {
86
+ if (this.dryRun) {
87
+ const e = this.#i.get(s), i = e === void 0 ? `issue #${s}` : `new issue: ${e}`;
88
+ this.changes.push(`ADD comment to ${i}`);
89
+ return;
90
+ }
91
+ await this.#t("POST", `/repos/${this.#s}/issues/${s}/comments`, { body: t });
92
+ }
93
+ async updateComment(s, t) {
94
+ if (this.dryRun) {
95
+ this.changes.push(`UPDATE comment #${s}`);
96
+ return;
97
+ }
98
+ await this.#t("PATCH", `/repos/${this.#s}/issues/comments/${s}`, { body: t });
99
+ }
100
+ async deleteComment(s) {
101
+ if (this.dryRun) {
102
+ this.changes.push(`REMOVE comment #${s}`);
103
+ return;
104
+ }
105
+ await this.#t("DELETE", `/repos/${this.#s}/issues/comments/${s}`);
106
+ }
107
+ }
108
+ async function f(a, s, t, e) {
109
+ const i = (await a.listComments(s)).filter(({ body: n }) => e(n));
110
+ for (const [n, o] of t.entries()) {
111
+ const r = i[n];
112
+ r === void 0 ? await a.createComment(s, o) : u(r.body) !== u(o) && await a.updateComment(r.id, o);
113
+ }
114
+ for (const n of i.slice(t.length))
115
+ await a.deleteComment(n.id);
116
+ }
117
+ function u(a) {
118
+ return a?.replace(p, "$1<sha>$2");
119
+ }
120
+ export {
121
+ $ as G,
122
+ u as n,
123
+ f as s
124
+ };