@arcgis/codemod 6.0.0-next.0 → 6.0.0-next.10

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,158 @@
1
+ import u from "typescript";
2
+ import { findPath as v, asyncFindPath as y } from "@arcgis/node-toolkit/file";
3
+ import { path as d } from "@arcgis/node-toolkit/path";
4
+ import { retrievePackageJson as k, asyncRetrievePackageJson as x } from "@arcgis/node-toolkit/packageJson";
5
+ import { log as w } from "@arcgis/toolkit/log";
6
+ import { realpath as g, readFile as S } from "node:fs/promises";
7
+ import { f as D } from "./log.js";
8
+ import { b as P } from "./cli.js";
9
+ function L(e) {
10
+ return typeof e == "string" ? e : e.map((t) => t.kind === u.SyntaxKind.JSDocText ? t.text : J(t.getText())).join("");
11
+ }
12
+ function $(e) {
13
+ return e === void 0 ? void 0 : b(u.displayPartsToString([...e]));
14
+ }
15
+ function b(e) {
16
+ return e.replace(
17
+ /\{@link(?:code|plain)?\s+([\s\S]*?)\}/gu,
18
+ (t, n) => h(n)
19
+ );
20
+ }
21
+ function J(e) {
22
+ const t = /^\{@link(?:code|plain)?\s+([\s\S]*?)\}$/u.exec(e)?.[1];
23
+ return t === void 0 ? e : h(t);
24
+ }
25
+ function h(e) {
26
+ const t = e.trim().replace(/^(\S+)\s+([/:#!.])/u, "$1$2"), n = t.indexOf("|");
27
+ if (n !== -1)
28
+ return t.slice(n + 1).trim() || t.slice(0, n).trim();
29
+ const [i, ...s] = t.split(/\s+/u);
30
+ return s.join(" ") || i;
31
+ }
32
+ function R(e, t) {
33
+ const n = v("package.json", e);
34
+ return n === void 0 ? t : k(d.dirname(n)).name ?? t;
35
+ }
36
+ const m = {
37
+ excludedPackageNames: /* @__PURE__ */ new Set([
38
+ "@arcgis/charts-components-react",
39
+ "@arcgis/coding-components-react",
40
+ "@arcgis/components-build-utils",
41
+ "@arcgis/map-components-react",
42
+ "@arcgis/portal-components-react",
43
+ "@arcgis-test/lit-components-react"
44
+ ]),
45
+ excludedDefinitionPathFragments: ["test-package", "packages/docs/lumina-code-samples/", "packages/starter-packages/"],
46
+ ignoreDeprecatedApis: ["getReactWrapperOptions"],
47
+ ignoredDeprecationsByIncludes: ["React wrappers are not needed in React 19 or above"]
48
+ };
49
+ function U(e) {
50
+ return e !== void 0 && m.excludedPackageNames.has(e);
51
+ }
52
+ function A(e) {
53
+ return m.excludedDefinitionPathFragments.some(
54
+ (t) => e.includes(t)
55
+ );
56
+ }
57
+ function z(e, t) {
58
+ return m.ignoreDeprecatedApis.some((n) => n === e) || t != null && m.ignoredDeprecationsByIncludes.some((n) => t.includes(n));
59
+ }
60
+ function N(e, t, n) {
61
+ const i = JSON.parse(e), s = { definitions: [], components: /* @__PURE__ */ new Set() };
62
+ for (const o of i.modules)
63
+ for (const a of o.declarations ?? []) {
64
+ let r = function(p, f, c) {
65
+ c !== !0 && typeof c != "string" || s.definitions.push({
66
+ package: n,
67
+ module: o.path,
68
+ name: p,
69
+ kind: f,
70
+ memberOf: f === "element" ? void 0 : l,
71
+ provenance: "manifest",
72
+ reason: typeof c == "string" ? c : void 0,
73
+ sourceFileName: t,
74
+ line: 1,
75
+ column: 1
76
+ });
77
+ };
78
+ if (!("tagName" in a) || a.tagName === void 0)
79
+ continue;
80
+ const l = a.tagName;
81
+ s.components.add(l), r(l, "element", a.deprecated);
82
+ for (const [p, f] of [
83
+ ["cssProperties", "css-property"],
84
+ ["cssParts", "css-part"],
85
+ ["cssStates", "css-state"],
86
+ ["slots", "slot"],
87
+ ["attributes", "attribute"]
88
+ ])
89
+ for (const c of a[p] ?? [])
90
+ p === "slots" && c.name === "" || r(c.name, f, c.deprecated);
91
+ }
92
+ return s;
93
+ }
94
+ function _(e) {
95
+ const t = e.flatMap((o) => o.definitions), n = /* @__PURE__ */ new Map();
96
+ for (const o of e)
97
+ for (const a of o.components) {
98
+ const r = n.get(a) ?? [];
99
+ r.push(o), n.set(a, r);
100
+ }
101
+ const i = /* @__PURE__ */ new Map(), s = Map.groupBy(
102
+ t.filter(({ kind: o }) => o === "css-property"),
103
+ ({ name: o }) => o
104
+ );
105
+ for (const [o, a] of s)
106
+ new Set(a.map((r) => r.package)).size === 1 && i.set(o, a[0]);
107
+ return { hasDeprecatedApis: t.length > 0, components: n, cssVariables: i };
108
+ }
109
+ function K(e = "warn", t) {
110
+ const n = /* @__PURE__ */ new Map();
111
+ return async (i) => {
112
+ const s = await g(i);
113
+ let o = n.get(s);
114
+ return o === void 0 && (o = j(s).catch((a) => {
115
+ if (t?.(), e === "throw")
116
+ throw new Error(
117
+ `Unable to read component manifest for ${s}. Build the package before auditing definitions.`,
118
+ { cause: a }
119
+ );
120
+ w("warn", D(s), `Unable to read component manifest: ${String(a)}`);
121
+ }), n.set(s, o)), await o;
122
+ };
123
+ }
124
+ async function V(e, t, n) {
125
+ const i = /* @__PURE__ */ new Set([
126
+ ...Object.keys(e.contents.dependencies ?? {}),
127
+ ...Object.keys(e.contents.devDependencies ?? {}),
128
+ ...Object.keys(e.contents.peerDependencies ?? {}),
129
+ ...Object.keys(e.contents.optionalDependencies ?? {})
130
+ ]), s = await Promise.all(
131
+ [...i].filter((o) => o !== e.contents.name && (!n || P(o))).map(async (o) => {
132
+ const a = await y(
133
+ d.join("node_modules", o, "package.json"),
134
+ d.dirname(e.filePath)
135
+ );
136
+ return a === void 0 ? void 0 : await t(a);
137
+ })
138
+ );
139
+ return [...new Set(s.filter((o) => o !== void 0))];
140
+ }
141
+ async function j(e) {
142
+ const t = d.dirname(e), n = await x(t), i = typeof n.customElements == "string" ? n.customElements : n.customElements?.[0];
143
+ if (i === void 0)
144
+ return;
145
+ const s = await g(d.resolve(t, i));
146
+ return N(await S(s, "utf8"), s, n.name);
147
+ }
148
+ export {
149
+ z as a,
150
+ K as b,
151
+ _ as c,
152
+ L as d,
153
+ $ as e,
154
+ A as f,
155
+ R as g,
156
+ V as l,
157
+ U as s
158
+ };
@@ -1,157 +1,73 @@
1
- import { d as h } from "./cli.js";
2
- const I = /(?:esri|arcgis)/iu, y = "@arcgis/codemod", x = {
3
- usages: "Refactor-out deprecated API usages",
4
- definitions: "Remove deprecated APIs in next breaking changes release"
5
- }, P = {
6
- usages: "The following deprecated APIs are used in files owned by assigned CODEOWNERS. Refactor them before the APIs are removed.",
7
- definitions: "The following deprecated APIs are owned by assigned CODEOWNERS. Remove them in the next breaking changes release."
8
- }, R = "This issue is autogenerated and updated regularly based on remaining items. Feel free to add comments and labels, update assignees, set milestone, or create sub-issues. Close it once completed. A new issue will be created if new findings are detected.", J = "Task", K = "deprecations sync-issues";
9
- function A(e) {
10
- return I.test(e);
11
- }
12
- const L = /* @__PURE__ */ new Set([
13
- "MessageBundleLoader",
14
- "createJSONLoader",
15
- "fetchMessageBundle",
16
- "messageBundle",
17
- "normalizeMessageBundleLocale",
18
- "registerMessageBundleLoader"
19
- ]), O = /* @__PURE__ */ new Set([
20
- "AreaMeasurement2D",
21
- "AreaMeasurement3D",
22
- "BasemapGallery",
23
- "BasemapToggle",
24
- "BatchAttributeForm",
25
- "BinaryColorSizeSlider",
26
- "ClassedColorSlider",
27
- "ColorSlider",
28
- "ColorSizeSlider",
29
- "CoordinateConversion",
30
- "Daylight",
31
- "DirectLineMeasurement3D",
32
- "DistanceMeasurement2D",
33
- "Editor",
34
- "FeatureForm",
35
- "FeatureTable",
36
- "GridControls",
37
- "HeatmapSlider",
38
- "Home",
39
- "HistogramRangeSlider",
40
- "LayerList",
41
- "Legend",
42
- "LineOfSight",
43
- "Locate",
44
- "NavigationToggle",
45
- "OpacitySlider",
46
- "OrientedImageryViewer",
47
- "Print",
48
- "ScaleBar",
49
- "Search",
50
- "Sketch",
51
- "SketchLabelOptions",
52
- "SketchTooltipOptions",
53
- "Slice",
54
- "SizeSlider",
55
- "Slider",
56
- "SnappingOptions",
57
- "TableList",
58
- "useLegacyCreateTools"
59
- ]);
60
- function D({
61
- packageName: e,
62
- api: n,
63
- reason: s
64
- }) {
65
- const r = e.toLowerCase(), t = s?.toLowerCase() ?? "";
66
- return e === "@arcgis/core" && (O.has(n) || t.includes("components-transition-plan")) ? "coreWidgets" : e === "@arcgis/core" && (n === "geometryEngine" || n === "extendedSpatialReferenceInfo" || t.includes("geometry/operators")) ? "coreGeometryEngine" : /\bcodemod\b/iu.test(t) ? "codemod" : e === "@arcgis/core" && (L.has(n) || t.includes("widget translations")) ? "coreIntl" : r.includes("calcite") ? "calcite" : e === "@arcgis/core" || r.startsWith("@arcgis/") && r.includes("components") ? "arcgisCoreComponents" : A(e) ? "otherEsri" : "nonEsri";
67
- }
68
- function j(e, n) {
69
- const s = Map.groupBy(e, (r) => D(n(r)));
70
- return Object.keys(h).flatMap((r) => {
71
- const t = s.get(r);
72
- if (t === void 0)
73
- return [];
74
- const i = [...Map.groupBy(t, (a) => n(a).packageName)].map(([a, c]) => {
75
- const p = [...Map.groupBy(c, (d) => n(d).api)].map(([d, m]) => {
76
- const g = m.map((u) => n(u).reason).filter((u) => u != null && u !== ""), f = [...new Set(g)].sort((u, $) => u.localeCompare($));
77
- return { api: d, reasons: f, items: m };
78
- });
79
- return p.sort((d, m) => m.items.length - d.items.length || d.api.localeCompare(m.api)), { packageName: a, count: c.length, apis: p };
80
- });
81
- return i.sort((a, c) => c.count - a.count || a.packageName.localeCompare(c.packageName)), [{ categoryName: r, count: t.length, packages: i }];
82
- });
83
- }
84
- const S = `<!-- ${y} -->`, V = `<!-- ${y}`, M = 65536;
85
- function Q(e) {
86
- const n = C(e, e.findings);
87
- return `${n.summary.trim().replace(/^### /u, "## ")}
1
+ import { h as R, k as d, l as D, m as b, d as h } from "./cli.js";
2
+ import { g as v, i as B, b as $, d as K } from "./classification.js";
3
+ import { markdownTextLimit as k, splitMarkdown as O } from "@arcgis/node-toolkit/markdown";
4
+ const y = `<!-- ${d} -->`, X = `<!-- ${d}`;
5
+ function Y(e) {
6
+ const t = M(e, e.findings);
7
+ return `${t.summary.trim().replace(/^### /u, "## ")}
88
8
 
89
- ${n.details}`;
9
+ ${t.details}`;
90
10
  }
91
- function X(e) {
92
- const n = /* @__PURE__ */ new Map();
93
- for (const s of e.findings) {
94
- const r = k(s.codeowners), t = r.join(","), o = n.get(t) ?? [];
95
- o.push({ ...s, codeowners: r }), n.set(t, o);
11
+ function Z(e) {
12
+ const t = /* @__PURE__ */ new Map();
13
+ for (const n of e.findings) {
14
+ const s = f(n.codeowners), r = s.join(","), o = t.get(r) ?? [];
15
+ o.push({ ...n, codeowners: s }), t.set(r, o);
96
16
  }
97
- return [...n.entries()].map(([s, r]) => {
98
- const t = s === "" ? [] : s.split(","), o = T(e, r);
17
+ return [...t.entries()].map(([n, s]) => {
18
+ const r = n === "" ? [] : n.split(","), o = L(e, s);
99
19
  return {
100
20
  changes: [],
101
- title: x[e.kind],
102
- owners: t,
103
- assignees: t.filter((i) => /^@[^/@\s]+$/u.test(i)).map((i) => i.slice(1)),
104
- chunks: F(o, M, G(t))
21
+ title: R[e.auditKind],
22
+ owners: r,
23
+ assignees: r.filter((a) => /^@[^/@\s]+$/u.test(a)).map((a) => a.slice(1)),
24
+ chunks: _(o, k, G(r))
105
25
  };
106
- }).sort((s, r) => s.title.localeCompare(r.title));
26
+ }).sort((n, s) => n.title.localeCompare(s.title));
107
27
  }
108
- function T(e, n) {
109
- const s = k(n.flatMap((t) => t.codeowners)).filter(
110
- (t) => /^@[^/@\s]+\/[^@\s]+$/u.test(t)
111
- ), r = s.length === 0 ? "" : `
28
+ function L(e, t) {
29
+ const n = f(t.flatMap((r) => r.codeowners)).filter(
30
+ (r) => /^@[^/@\s]+\/[^@\s]+$/u.test(r)
31
+ ), s = n.length === 0 ? "" : `
112
32
 
113
- CODEOWNERS: ${s.join(", ")}`;
114
- return E(e, n, r);
33
+ CODEOWNERS: ${n.join(", ")}`;
34
+ return U(e, t, s);
115
35
  }
116
- function E(e, n, s) {
117
- const r = P[e.kind], t = C(e, n);
118
- return `${r}${s}${t.summary}
36
+ function U(e, t, n) {
37
+ const s = D[e.auditKind], r = M(e, t);
38
+ return `${s}${n}${r.summary}
119
39
 
120
- ${R}
40
+ ${b}
121
41
 
122
- ${t.details}`;
42
+ ${r.details}`;
123
43
  }
124
- function C(e, n) {
125
- return e.kind === "usages" ? v(e, n) : z(e, n);
44
+ function M(e, t) {
45
+ return e.auditKind === "usages" ? z(e, t) : E(e, t);
126
46
  }
127
- function v(e, n) {
128
- const s = j(n, ({ package: o, api: i, reason: a }) => ({
129
- packageName: o,
130
- api: i,
131
- reason: a
132
- })), r = s.map(({ categoryName: o, count: i, packages: a }) => {
133
- const c = a.map(({ packageName: l, count: p }) => ` - \`${l}\`: ${p}`).join(`
47
+ function z(e, t) {
48
+ const n = x(t, "usages"), s = v(t, (a) => a), r = s.map(({ categoryName: a, count: c, packages: m }) => {
49
+ const u = m.map(({ displayName: p, count: i }) => ` - \`${p}\`: ${i}`).join(`
134
50
  `);
135
- return `- **${h[o].label}**: ${i}
136
- ${c}`;
51
+ return `- **${h[a].label}**: ${c}
52
+ ${u}`;
137
53
  }).join(`
138
- `), t = s.map(({ categoryName: o, count: i, packages: a }) => {
139
- const c = a.map(({ packageName: d, count: m, apis: g }) => {
140
- const f = g.map(
141
- ({ api: u, reasons: $, items: b }) => B(e, u, $, b)
54
+ `), o = s.map(({ categoryName: a, count: c, packages: m }) => {
55
+ const u = m.map(({ displayName: l, count: S, apis: A }) => {
56
+ const C = A.flatMap(
57
+ ({ items: P }) => I(e, P, "usages", n)
142
58
  );
143
- return `#### ${d} (${m})
59
+ return `#### ${l} (${S})
144
60
 
145
- ${f.join(`
61
+ ${C.join(`
146
62
  `)}`;
147
63
  }).join(`
148
64
 
149
- `), l = h[o], p = "description" in l ? `
65
+ `), p = h[a], i = "description" in p ? `
150
66
 
151
- ${l.description}` : "";
152
- return `### ${l.label} (${i})${p}
67
+ ${p.description}` : "";
68
+ return `### ${p.label} (${c})${i}
153
69
 
154
- ${c}`;
70
+ ${u}`;
155
71
  }).join(`
156
72
 
157
73
  `);
@@ -163,93 +79,110 @@ ${c}`;
163
79
  ${r}`,
164
80
  details: `## Deprecation details
165
81
 
166
- ${t}`
82
+ ${o}`
167
83
  };
168
84
  }
169
- function z(e, n) {
170
- return { summary: "", details: [...Map.groupBy(n, (t) => t.package).entries()].sort(([t], [o]) => t.localeCompare(o)).map(([t, o]) => {
171
- const a = [...Map.groupBy(o, (c) => N(e.kind, c)).entries()].sort(([c], [l]) => c.localeCompare(l)).map(([, c]) => B(e, c[0].api, W(c), c));
172
- return `#### ${t}'s deprecations
85
+ function x(e, t) {
86
+ const n = /* @__PURE__ */ new Map();
87
+ for (const s of e) {
88
+ const r = $(s), o = n.get(r) ?? /* @__PURE__ */ new Set();
89
+ o.add(`${s.package}\0${j(t, s)}`), n.set(r, o);
90
+ }
91
+ return new Set([...n].filter(([, s]) => s.size > 1).map(([s]) => s));
92
+ }
93
+ function E(e, t) {
94
+ const n = x(t, "definitions");
95
+ return { summary: "", details: [...Map.groupBy(
96
+ t,
97
+ (o) => B(o.package, o.module ?? g("definitions", o))
98
+ ).entries()].sort(([o], [a]) => o.localeCompare(a)).map(([o, a]) => {
99
+ const c = I(e, a, "definitions", n);
100
+ return `#### ${o}'s deprecations
173
101
 
174
- ${a.join(`
102
+ ${c.join(`
175
103
  `)}`;
176
104
  }).join(`
177
105
 
178
106
  `) };
179
107
  }
180
- function B(e, n, s, r) {
181
- const t = s.length === 0 ? "" : ` - ${s.map(H).join(" ")}`, o = [
108
+ function I(e, t, n, s) {
109
+ const r = [...Map.groupBy(t, (o) => j(n, o))];
110
+ return n === "definitions" && r.sort(([o], [a]) => o.localeCompare(a)), r.map(([, o]) => {
111
+ const a = $(o[0]), c = g(n, o[0]), m = c !== void 0 && s.has(a) ? `${c} ${a}` : a, u = T(o);
112
+ return n === "usages" && u.sort((p, i) => p.localeCompare(i)), N(e, m, u, o, n);
113
+ });
114
+ }
115
+ function N(e, t, n, s, r) {
116
+ const o = n.length === 0 ? "" : ` - ${n.map(q).join(" ")}`, a = [
182
117
  ...new Set(
183
- r.toSorted((a, c) => a.file.localeCompare(c.file) || a.line - c.line).map((a) => _(e.repository, e.ref, a.file, a.line))
118
+ s.filter((i) => r === "usages" || i.provenance !== "manifest").toSorted((i, l) => i.file.localeCompare(l.file) || i.line - l.line).map((i) => H(e.repository, e.ref, i.file, i.line))
184
119
  )
185
- ], i = o.length === 1 ? ` ${o[0]}` : o.map((a) => ` - ${a}`).join(`
186
- `);
187
- return `- [ ] \`${n}\`${t}
188
- ${i}`;
120
+ ], c = a.length === 1 ? ` ${a[0]}` : a.map((i) => ` - ${i}`).join(`
121
+ `), m = s[0].kind, u = [
122
+ ...new Set(
123
+ s.filter(
124
+ (i) => r === "definitions" && i.provenance === "manifest" && i.kind === "css-property"
125
+ ).flatMap(({ memberOf: i }) => i === void 0 ? [] : [i])
126
+ )
127
+ ].sort(), p = u.length === 0 ? "" : ` (components: ${u.map((i) => `\`<${i}>\``).join(", ")})`;
128
+ return `- [ ] \`${t}\`${K(m)}${p}${o}${c === "" ? "" : `
129
+ ${c}`}`;
189
130
  }
190
- function W(e) {
131
+ function T(e) {
191
132
  return [
192
133
  ...new Set(
193
- e.map(({ reason: n }) => n).filter((n) => n !== null && n !== "")
134
+ e.map(({ deprecated: t }) => t).filter((t) => typeof t == "string" && t !== "")
194
135
  )
195
136
  ];
196
137
  }
197
- function F(e, n = M, s = S) {
198
- const r = `${s}
199
- `, t = n - r.length;
200
- if (t < 1)
138
+ function _(e, t = k, n = y) {
139
+ const s = `${n}
140
+ `, r = t - s.length;
141
+ if (r < 1)
201
142
  throw new Error("Issue content limit is too small for the managed marker.");
202
- const o = [];
203
- let i = e;
204
- for (; i.length > t; ) {
205
- const a = i.lastIndexOf(`
206
- `, t), c = a > 0 ? a : t;
207
- o.push(r + i.slice(0, c)), i = i.slice(c + (a > 0 ? 1 : 0));
208
- }
209
- return o.push(r + i), o;
143
+ return O(e, r).map((o) => s + o);
210
144
  }
211
145
  function G(e) {
212
- return e.length === 0 ? S : `<!-- ${y} ${k(e).join(",")} -->`;
146
+ return e.length === 0 ? y : `<!-- ${d} ${f(e).join(",")} -->`;
213
147
  }
214
- function k(e) {
215
- return [...new Set(e)].sort((n, s) => n.localeCompare(s));
148
+ function f(e) {
149
+ return [...new Set(e)].sort((t, n) => t.localeCompare(n));
216
150
  }
217
- function N(e, n) {
218
- return e === "definitions" ? `${n.api}\0${U(n.file)}` : n.api;
151
+ function j(e, t) {
152
+ return `${$(t)}\0${g(e, t) ?? ""}`;
219
153
  }
220
- function U(e) {
221
- const n = "/src/", s = "/dist/", r = e.lastIndexOf(n), t = e.lastIndexOf(s), o = Math.max(r, t), i = t > r ? s : n;
222
- return (o === -1 ? e : e.slice(o + i.length)).replace(/\.(?:d\.)?(?:[cm]?ts|tsx)$/u, "");
154
+ function g(e, t) {
155
+ return e === "definitions" && t.provenance !== "manifest" ? W(t.file) : t.module;
156
+ }
157
+ function W(e) {
158
+ const t = "/src/", n = "/dist/", s = e.lastIndexOf(t), r = e.lastIndexOf(n), o = Math.max(s, r), a = r > s ? n : t;
159
+ return (o === -1 ? e : e.slice(o + a.length)).replace(/\.(?:d\.)?(?:[cm]?ts|tsx)$/u, "");
223
160
  }
224
- function H(e) {
225
- const n = [], s = (o) => `\0${n.push(o) - 1}\0`, t = e.replaceAll(`\r
161
+ function q(e) {
162
+ const t = [], n = (o) => `\0${t.push(o) - 1}\0`, r = e.replaceAll(`\r
226
163
  `, `
227
164
  `).replaceAll("\r", `
228
165
  `).replace(
229
166
  /\[([^\]\n]+)\]\((https?:\/\/(?:[^()\s]|\([^()\s]*\))+?)\)/gu,
230
- (o, i, a) => s(`[${w(i)}](${a})`)
167
+ (o, a, c) => n(`[${w(a)}](${c})`)
231
168
  ).replace(/https?:\/\/[^\s<>()]+/gu, (o) => {
232
- const i = /[.,;:!?]+$/u.exec(o)?.[0] ?? "";
233
- return `${s(o.slice(0, -i.length || void 0))}${i}`;
169
+ const a = /[.,;:!?]+$/u.exec(o)?.[0] ?? "";
170
+ return `${n(o.slice(0, -a.length || void 0))}${a}`;
234
171
  });
235
- return w(t).replace(/\0(\d+)\0/gu, (o, i) => n[Number(i)]).replaceAll(`
172
+ return w(r).replace(/\0(\d+)\0/gu, (o, a) => t[Number(a)]).replaceAll(`
236
173
  `, `
237
174
  `);
238
175
  }
239
176
  function w(e) {
240
177
  return e.replace(/^(\s*)(#{1,6})(?=\s)/gmu, "$1\\$2").replace(/#(?=\d)/gu, "# ");
241
178
  }
242
- function _(e, n, s, r) {
243
- const t = n.split("/").map(encodeURIComponent).join("/"), o = s.split("/").map(encodeURIComponent).join("/");
244
- return `https://${e}/blob/${t}/${o}#L${r}`;
179
+ function H(e, t, n, s) {
180
+ const r = t.split("/").map(encodeURIComponent).join("/"), o = n.split("/").map(encodeURIComponent).join("/");
181
+ return `https://${e}/blob/${r}/${o}#L${s}`;
245
182
  }
246
183
  export {
247
- J as a,
248
- X as b,
249
- D as c,
250
- K as d,
251
- V as e,
252
- Q as f,
253
- j as g,
254
- A as i
184
+ y as a,
185
+ Z as c,
186
+ Y as f,
187
+ X as i
255
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
+ };