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

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,210 @@
1
+ import { collectOutput as u } from "@arcgis/node-toolkit/shell";
2
+ import { l as m, f as l, j as p } from "./cli.js";
3
+ import { log as f } from "@arcgis/toolkit/log";
4
+ const g = /^( (?:- )?https:\/\/[^/\s]+\/[^/\s]+\/[^/\s]+\/blob\/)[a-f0-9]{40}(\/\S+#L\d+)$/gmu;
5
+ class v {
6
+ constructor(s, t = !1) {
7
+ this.changes = [], this.#i = /* @__PURE__ */ new Map(), this.#n = -1;
8
+ const [e, i, o, ...a] = s.split("/");
9
+ if (e === void 0 || i === void 0 || o === void 0 || a.length > 0)
10
+ throw new Error(`Invalid repository: ${s}`);
11
+ this.#e = e, this.#s = `${i}/${o}`, this.dryRun = t;
12
+ }
13
+ #e;
14
+ #s;
15
+ #i;
16
+ #n;
17
+ async #t(s, t, e) {
18
+ if (process.env.VITEST !== void 0)
19
+ throw new Error("GitHub requests are disabled while running Vitest.");
20
+ const i = await u(
21
+ "gh",
22
+ ["api", "--hostname", this.#e, "--method", s, t, ...e === void 0 ? [] : ["--input", "-"]],
23
+ e === void 0 ? {} : { input: JSON.stringify(e) }
24
+ );
25
+ return i === "" ? void 0 : JSON.parse(i);
26
+ }
27
+ async listOpenIssues(s) {
28
+ const t = await u("gh", [
29
+ "api",
30
+ "--hostname",
31
+ this.#e,
32
+ "--method",
33
+ "GET",
34
+ "--paginate",
35
+ "--slurp",
36
+ "-f",
37
+ `q="${s}" in:body repo:${this.#s} is:issue is:open`,
38
+ "-f",
39
+ "per_page=100",
40
+ "/search/issues"
41
+ ]), e = JSON.parse(t);
42
+ if (e.some(
43
+ ({ incomplete_results: i, total_count: o }) => i || o > 1e3
44
+ ))
45
+ throw new Error(`Incomplete issue search for ${s}; refusing to synchronize issues.`);
46
+ return e.flatMap(({ items: i }) => i);
47
+ }
48
+ async readLabelerConfig(s) {
49
+ const t = await this.#t(
50
+ "GET",
51
+ `/repos/${this.#s}/contents/.github?ref=${encodeURIComponent(s)}`
52
+ ), e = t.find(({ name: o }) => o === "labeler.yml") ?? t.find(({ name: o }) => o === "labeler.yaml");
53
+ if (e === void 0)
54
+ return;
55
+ const { content: i } = await this.#t(
56
+ "GET",
57
+ `/repos/${this.#s}/contents/.github/${e.name}?ref=${encodeURIComponent(s)}`
58
+ );
59
+ return Buffer.from(i, "base64").toString("utf8");
60
+ }
61
+ async listLabels() {
62
+ const s = await u("gh", [
63
+ "api",
64
+ "--hostname",
65
+ this.#e,
66
+ "--method",
67
+ "GET",
68
+ "--paginate",
69
+ "--slurp",
70
+ `/repos/${this.#s}/labels?per_page=100`
71
+ ]);
72
+ return JSON.parse(s).flat().map(({ name: t }) => t);
73
+ }
74
+ async addLabels(s, t) {
75
+ if (this.dryRun) {
76
+ this.changes.push(`ADD labels to issue #${s}: ${t.join(", ")}`);
77
+ return;
78
+ }
79
+ await this.#t("POST", `/repos/${this.#s}/issues/${s}/labels`, { labels: t });
80
+ }
81
+ async createIssue(s, t, e, i) {
82
+ if (this.dryRun) {
83
+ const o = this.#n--;
84
+ return this.#i.set(o, s), this.changes.push(`CREATE issue: ${s}`), {
85
+ number: o,
86
+ title: s,
87
+ body: t,
88
+ assignees: e.map((a) => ({ login: a })),
89
+ labels: i.map((a) => ({ name: a }))
90
+ };
91
+ }
92
+ return await this.#t("POST", `/repos/${this.#s}/issues`, {
93
+ title: s,
94
+ body: t,
95
+ assignees: e,
96
+ labels: i,
97
+ type: m
98
+ });
99
+ }
100
+ async updateIssueBody(s, t) {
101
+ if (this.dryRun) {
102
+ this.changes.push(`UPDATE issue #${s} body`);
103
+ return;
104
+ }
105
+ await this.#t("PATCH", `/repos/${this.#s}/issues/${s}`, { body: t });
106
+ }
107
+ async closeIssue(s) {
108
+ if (this.dryRun) {
109
+ this.changes.push(`CLOSE issue #${s}`);
110
+ return;
111
+ }
112
+ await this.#t("PATCH", `/repos/${this.#s}/issues/${s}`, { state: "closed" });
113
+ }
114
+ async listComments(s) {
115
+ if (this.#i.has(s))
116
+ return [];
117
+ const t = await u("gh", [
118
+ "api",
119
+ "--hostname",
120
+ this.#e,
121
+ "--method",
122
+ "GET",
123
+ "--paginate",
124
+ "--slurp",
125
+ `/repos/${this.#s}/issues/${s}/comments?per_page=100`
126
+ ]);
127
+ return JSON.parse(t).flat();
128
+ }
129
+ async createComment(s, t) {
130
+ if (this.dryRun) {
131
+ const e = this.#i.get(s), i = e === void 0 ? `issue #${s}` : `new issue: ${e}`;
132
+ this.changes.push(`ADD comment to ${i}`);
133
+ return;
134
+ }
135
+ await this.#t("POST", `/repos/${this.#s}/issues/${s}/comments`, { body: t });
136
+ }
137
+ async updateComment(s, t) {
138
+ if (this.dryRun) {
139
+ this.changes.push(`UPDATE comment #${s}`);
140
+ return;
141
+ }
142
+ await this.#t("PATCH", `/repos/${this.#s}/issues/comments/${s}`, { body: t });
143
+ }
144
+ async deleteComment(s) {
145
+ if (this.dryRun) {
146
+ this.changes.push(`REMOVE comment #${s}`);
147
+ return;
148
+ }
149
+ await this.#t("DELETE", `/repos/${this.#s}/issues/comments/${s}`);
150
+ }
151
+ }
152
+ async function E(n, s, t, e) {
153
+ const i = (await n.listComments(s)).filter(({ body: o }) => e(o));
154
+ for (const [o, a] of t.entries()) {
155
+ const r = i[o];
156
+ r === void 0 ? await n.createComment(s, a) : d(r.body) !== d(a) && await n.updateComment(r.id, a);
157
+ }
158
+ for (const o of i.slice(t.length))
159
+ await n.deleteComment(o.id);
160
+ }
161
+ function d(n) {
162
+ return n?.replace(g, "$1<sha>$2");
163
+ }
164
+ const c = "@arcgis/codemod", y = `<!-- ${c} -->`;
165
+ async function T(n) {
166
+ const s = await n.listOpenIssues(c);
167
+ for (const t of s) {
168
+ const e = h(t.body);
169
+ e !== void 0 && e.kind === void 0 && f(
170
+ "warn",
171
+ l,
172
+ `Cannot determine audit kind for legacy issue #${t.number}; leaving it unchanged.`
173
+ );
174
+ }
175
+ return s;
176
+ }
177
+ function h(n) {
178
+ const s = n?.split(`
179
+ `, 1)[0], t = s === void 0 ? null : /^<!-- (\S+)(?: (@[^\s,]+(?:,@[^\s,]+)*))? -->$/u.exec(s);
180
+ if (t?.[1] !== c)
181
+ return;
182
+ const e = n?.split(`
183
+ `, 2)[1], i = e === p.usages ? "usages" : e === p.definitions ? "definitions" : void 0, o = t[2] === void 0 ? [] : [...new Set(t[2].split(","))].sort((a, r) => a.localeCompare(r));
184
+ return { kind: i, owners: o };
185
+ }
186
+ function I(n, s) {
187
+ const t = h(n.body);
188
+ if (t !== void 0 && t.kind === void 0 && t.owners.join(",") === s.join(","))
189
+ throw new Error(
190
+ `Cannot determine audit kind for legacy issue #${n.number}. Restore its generated introduction before synchronizing.`
191
+ );
192
+ }
193
+ function S(n, s) {
194
+ const t = h(n);
195
+ return t !== void 0 && (t.owners.length === 0 || t.owners.join(",") === s.join(","));
196
+ }
197
+ function b(n) {
198
+ return n.split(`
199
+ `, 1)[0] === y;
200
+ }
201
+ export {
202
+ v as G,
203
+ I as a,
204
+ b,
205
+ S as i,
206
+ T as l,
207
+ d as n,
208
+ h as p,
209
+ E as s
210
+ };
@@ -1,66 +1,168 @@
1
- import { readFile as w } from "node:fs/promises";
1
+ import { readFile as E } from "node:fs/promises";
2
2
  import { log as f } from "@arcgis/toolkit/log";
3
- import { b as I } from "./artifact.js";
4
- import { f as d, h as $ } from "./cli.js";
5
- import { c as v, i as g } from "./format.js";
6
- import { G as y, n as p, s as b } from "./github.js";
7
- async function D(t, s, o = 0, n, u = {}) {
8
- const { labels: c = [], closeResolved: l = !1 } = u, r = I(await w(t, "utf8")), e = l && k(r, o, n), a = C(v(r), o, n), i = new y(r.repository, s), h = await S(a, i, c, e ? r.auditKind : void 0);
9
- s && process.stdout.write(`${[E(a), ...h].filter(Boolean).join(`
3
+ import { n as A } from "./classification.js";
4
+ import { f as d } from "./cli.js";
5
+ import { c as j, a as M, p as I, b as $ } from "./format.js";
6
+ import { G as x, l as O, n as L, s as N, p as R, a as T, i as z } from "./legacyCompatibility.js";
7
+ import B from "picomatch";
8
+ import { parse as D } from "yaml";
9
+ function G(s) {
10
+ const e = D(s);
11
+ if (typeof e != "object" || e === null || Array.isArray(e))
12
+ throw new Error("Expected a label-to-rule mapping in the labeler config.");
13
+ const r = [];
14
+ for (const [n, t] of Object.entries(e))
15
+ try {
16
+ r.push({ label: n, matches: S(t) });
17
+ } catch (o) {
18
+ f("warn", d, `Skipping labeler rule for ${n}: ${String(o)}`);
19
+ }
20
+ return (n) => r.filter(({ matches: t }) => n.some(t)).map(({ label: t }) => t);
21
+ }
22
+ function S(s, e = !1) {
23
+ if (typeof s == "string") {
24
+ const n = B(s, { dot: !0 });
25
+ return (t) => n(t);
26
+ }
27
+ if (Array.isArray(s))
28
+ return h(s, e);
29
+ if (typeof s != "object" || s === null || Object.keys(s).length === 0)
30
+ throw new Error("Expected a glob or a match object.");
31
+ const r = Object.entries(s).map(([n, t]) => {
32
+ switch (n) {
33
+ case "any":
34
+ return h(t, Array.isArray(t) && t.every((o) => typeof o == "string"));
35
+ case "all":
36
+ return h(t, !0);
37
+ case "changed-files":
38
+ return h(t, e);
39
+ case "any-glob-to-any-file":
40
+ return h(t, !1);
41
+ default:
42
+ throw new Error(`Unsupported labeler condition: ${n}.`);
43
+ }
44
+ });
45
+ return (n) => r.every((t) => t(n));
46
+ }
47
+ function h(s, e) {
48
+ const r = Array.isArray(s) ? s : [s];
49
+ if (r.length === 0)
50
+ throw new Error("Expected a nonempty rule list.");
51
+ const n = r.map((t) => S(t, e));
52
+ return (t) => e ? n.every((o) => o(t)) : n.some((o) => o(t));
53
+ }
54
+ async function se(s, e, r = 0, n, t = {}) {
55
+ const { labels: o = [], closeResolved: c = !1 } = t, p = A(await E(s, "utf8")), g = c && U(p, r, n), m = new x(p.repository, e), a = await P(m, p.ref), i = q(j(p, a), r, n), u = await F(i, m, o, g ? p.auditKind : void 0);
56
+ e && process.stdout.write(`${[H(i), ...u].filter(Boolean).join(`
10
57
  `)}
11
58
  `);
12
59
  }
13
- function k(t, s, o) {
14
- if (s !== 0 || o !== void 0)
60
+ async function P(s, e) {
61
+ try {
62
+ const r = await s.readLabelerConfig(e);
63
+ return r === void 0 ? void 0 : G(r);
64
+ } catch (r) {
65
+ f("warn", d, `Skipping labeling based on .github/labeler.yml due to an error: ${String(r)}`);
66
+ return;
67
+ }
68
+ }
69
+ function U(s, e, r) {
70
+ if (e !== 0 || r !== void 0)
15
71
  throw new Error("--close-resolved cannot be used with --offset or --limit.");
16
- return t.complete !== !0 ? (f(
72
+ return s.complete !== !0 ? (f(
17
73
  "warn",
18
74
  d,
19
75
  "Skipping --close-resolved: the report is not a complete, unfiltered repository-root audit. Issue creation and updates will continue."
20
76
  ), !1) : !0;
21
77
  }
22
- function C(t, s, o) {
23
- return t.slice(s, o === void 0 ? void 0 : s + o);
78
+ function q(s, e, r) {
79
+ return s.slice(e, r === void 0 ? void 0 : e + r);
24
80
  }
25
- async function S(t, s, o = [], n) {
26
- const u = n === void 0 ? t[0]?.title : $[n], c = u === void 0 ? [] : await s.listOpenIssues(u), l = n === void 0 ? [] : c.filter((e) => e.title === u && m(e.body) !== void 0), r = /* @__PURE__ */ new Set();
27
- for (const e of t) {
28
- const a = j(c, e);
29
- let i;
30
- a === void 0 ? (i = (await s.createIssue(e.title, e.chunks[0], e.assignees, o)).number, s.dryRun || f("info", d, `Created issue #${i}: ${e.title}`)) : (i = a.number, p(a.body) !== p(e.chunks[0]) && (await s.updateIssueBody(i, e.chunks[0]), s.dryRun || f("info", d, `Updated issue #${i}: ${e.title}`))), await b(s, i, e.chunks.slice(1), (h) => h.startsWith(g)), r.add(i), e.changes.push(...s.changes.splice(0));
81
+ async function F(s, e, r = [], n) {
82
+ await W(s, e, r);
83
+ const t = n ?? b(s[0]?.chunks[0] ?? null)?.kind, o = t === void 0 ? [] : [...await e.listOpenIssues(M[t]), ...await O(e)], c = [...new Map(o.map((a) => [a.number, a])).values()], p = n === void 0 ? [] : c.filter((a) => b(a.body)?.kind === n), g = s.map((a) => ({ plan: a, issues: Y(c, a) })), m = /* @__PURE__ */ new Set();
84
+ for (const a of g) {
85
+ const { plan: i } = a;
86
+ let u = a.issues[0];
87
+ u === void 0 ? (u = await e.createIssue(i.title, i.chunks[0], i.assignees, []), e.dryRun || f("info", d, `Created issue #${u.number}: ${i.title}`)) : L(u.body) !== L(i.chunks[0]) && (await e.updateIssueBody(u.number, i.chunks[0]), e.dryRun || f("info", d, `Updated issue #${u.number}: ${i.title}`));
88
+ const w = u.number, v = b(i.chunks[0]);
89
+ await N(e, w, i.chunks.slice(1), (l) => {
90
+ const k = I(l);
91
+ return k?.kind === v?.kind && k?.owners.join(",") === i.owners.join(",") || z(l, i.owners);
92
+ });
93
+ const C = new Set(u.labels.map(({ name: l }) => l.toLowerCase())), y = i.labels.filter((l) => !C.has(l.toLowerCase()));
94
+ if (y.length > 0)
95
+ try {
96
+ await e.addLabels(w, y);
97
+ } catch (l) {
98
+ f("warn", d, `Unable to add labels to issue #${w}: ${String(l)}`);
99
+ }
100
+ m.add(w);
101
+ for (const l of a.issues)
102
+ m.add(l.number);
103
+ i.changes.push(...e.changes.splice(0));
31
104
  }
32
- for (const e of l)
33
- r.has(e.number) || (await s.closeIssue(e.number), s.dryRun || f("info", d, `Closed stale issue #${e.number}: ${e.title}`));
34
- return s.changes.splice(0);
105
+ for (const a of p)
106
+ m.has(a.number) || (await e.closeIssue(a.number), e.dryRun || f("info", d, `Closed stale issue #${a.number}: ${a.title}`));
107
+ return e.changes.splice(0);
35
108
  }
36
- function E(t) {
37
- return t.map(
38
- (s) => `ACTIONS: ${s.changes.length === 0 ? "No changes" : s.changes.join("; ")}
109
+ function H(s) {
110
+ return s.map(
111
+ (e) => `ACTIONS: ${e.changes.length === 0 ? "No changes" : e.changes.join("; ")}
39
112
 
40
- CODEOWNERS: ${s.owners.length === 0 ? "unowned" : s.owners.join(", ")}
41
- ASSIGNEES: ${s.assignees.length === 0 ? "none" : s.assignees.join(", ")}
42
- TITLE: ${s.title}
113
+ CODEOWNERS: ${e.owners.length === 0 ? "unowned" : e.owners.join(", ")}
114
+ ASSIGNEES: ${e.assignees.length === 0 ? "none" : e.assignees.join(", ")}
115
+ LABELS: ${e.labels.length === 0 ? "none" : e.labels.join(", ")}
116
+ TITLE: ${e.title}
43
117
 
44
- ${s.chunks.map((o, n) => `--- ${n === 0 ? "BODY" : "COMMENT"} (${n + 1}/${s.chunks.length}) ---
45
- ${o}`).join(`
118
+ ${e.chunks.map((r, n) => `--- ${n === 0 ? "BODY" : "COMMENT"} (${n + 1}/${e.chunks.length}) ---
119
+ ${r}`).join(`
46
120
 
47
121
  `)}`
48
122
  ).join(`
49
123
 
50
124
  `);
51
125
  }
52
- function j(t, s) {
53
- const o = m(s.chunks[0]);
54
- return t.find((n) => n.title === s.title && m(n.body) === o);
126
+ async function W(s, e, r) {
127
+ const n = new Set(s.flatMap((t) => [...r, ...t.labels]));
128
+ if (n.size !== 0)
129
+ try {
130
+ const t = new Map((await e.listLabels()).map((o) => [o.toLowerCase(), o]));
131
+ for (const o of n)
132
+ t.has(o.toLowerCase()) || f(
133
+ "warn",
134
+ d,
135
+ `.github/labeler.yml specifies a label that doesn't exist in the repository. Skipping: ${o}`
136
+ );
137
+ for (const o of s)
138
+ o.labels = [
139
+ ...new Set([...r, ...o.labels].flatMap((c) => t.get(c.toLowerCase()) ?? []))
140
+ ];
141
+ } catch (t) {
142
+ f("warn", d, `Skipping labels: unable to read repository labels: ${String(t)}`);
143
+ for (const o of s)
144
+ o.labels = [];
145
+ }
146
+ }
147
+ function Y(s, e) {
148
+ const r = b(e.chunks[0]);
149
+ if (r === void 0)
150
+ throw new Error("Expected an audit marker in issue plan.");
151
+ const n = $(r.owners, r.kind);
152
+ for (const o of s)
153
+ T(o, r.owners);
154
+ return s.filter((o) => {
155
+ const c = b(o.body);
156
+ return c !== void 0 && $(c.owners, c.kind) === n;
157
+ }).sort((o, c) => o.number - c.number);
55
158
  }
56
- function m(t) {
57
- const s = t?.split(`
58
- `, 1)[0];
59
- return s?.startsWith(g) === !0 ? s : void 0;
159
+ function b(s) {
160
+ const e = I(s) ?? R(s);
161
+ return e?.kind === void 0 ? void 0 : { kind: e.kind, owners: e.owners };
60
162
  }
61
163
  export {
62
- E as formatDryRun,
63
- C as sliceIssuePlans,
64
- D as syncDeprecationIssues,
65
- S as synchronizeIssuePlans
164
+ H as formatDryRun,
165
+ q as sliceIssuePlans,
166
+ se as syncDeprecationIssues,
167
+ F as synchronizeIssuePlans
66
168
  };
@@ -1,11 +1,16 @@
1
- import { readFile as u } from "node:fs/promises";
2
- import { markdownTextLimit as c, splitMarkdown as m } from "@arcgis/node-toolkit/markdown";
3
- import { G as p, s as f } from "./github.js";
4
- import { a as h, i as l } from "./format.js";
5
- async function x(t, s, e = !1) {
6
- const { repository: r, issueNumber: i } = w(s), n = new p(r, e), o = $(await u(t, "utf8"));
7
- await f(n, i, o, (a) => a.startsWith(l)), e && process.stdout.write(
8
- `${n.changes.length === 0 ? "No changes" : n.changes.join(`
1
+ import { readFile as m } from "node:fs/promises";
2
+ import { markdownTextLimit as u, splitMarkdown as p } from "@arcgis/node-toolkit/markdown";
3
+ import { G as f, s as w, b as d } from "./legacyCompatibility.js";
4
+ const a = "<!-- arcgisCodemodSyncMarkdown -->";
5
+ async function M(e, t, n = !1) {
6
+ const { repository: s, issueNumber: c } = h(t), r = new f(s, n), o = l(await m(e, "utf8"));
7
+ await w(
8
+ r,
9
+ c,
10
+ o,
11
+ (i) => k(i) || d(i)
12
+ ), n && process.stdout.write(
13
+ `${r.changes.length === 0 ? "No changes" : r.changes.join(`
9
14
  `)}
10
15
 
11
16
  ${o.join(`
@@ -14,19 +19,24 @@ ${o.join(`
14
19
  `
15
20
  );
16
21
  }
17
- function w(t) {
18
- const s = new URL(t), e = /^\/([^/]+)\/([^/]+)\/issues\/([1-9]\d*)\/?$/u.exec(s.pathname);
19
- if (s.protocol !== "https:" || e === null || !Number.isSafeInteger(Number(e[3])))
20
- throw new Error(`Expected an HTTPS GitHub issue URL: ${t}`);
21
- return { repository: `${s.host}/${e[1]}/${e[2]}`, issueNumber: Number(e[3]) };
22
+ function h(e) {
23
+ const t = new URL(e), n = /^\/([^/]+)\/([^/]+)\/issues\/([1-9]\d*)\/?$/u.exec(t.pathname);
24
+ if (t.protocol !== "https:" || n === null || !Number.isSafeInteger(Number(n[3])))
25
+ throw new Error(`Expected an HTTPS GitHub issue URL: ${e}`);
26
+ return { repository: `${t.host}/${n[1]}/${n[2]}`, issueNumber: Number(n[3]) };
22
27
  }
23
- function $(t, s = c) {
24
- const e = `${h}
28
+ function l(e, t = u) {
29
+ const n = `${a}
25
30
 
26
31
  `;
27
- return m(t, s - e.length).map((r) => e + r);
32
+ return p(e, t - n.length).map((s) => n + s);
33
+ }
34
+ function k(e) {
35
+ return e.split(`
36
+ `, 1)[0] === a;
28
37
  }
29
38
  export {
30
- $ as createMarkdownComments,
31
- x as syncMarkdown
39
+ l as createMarkdownComments,
40
+ k as isMarkdownComment,
41
+ M as syncMarkdown
32
42
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/codemod",
3
- "version": "6.0.0-next.30",
3
+ "version": "6.0.0-next.32",
4
4
  "description": "A codemod toolkit for updating and modernizing ArcGIS Maps SDK for JavaScript codebases.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -11,11 +11,12 @@
11
11
  ],
12
12
  "license": "SEE LICENSE IN LICENSE.md",
13
13
  "dependencies": {
14
- "@arcgis/api-extractor": "6.0.0-next.30",
15
- "@arcgis/node-toolkit": "6.0.0-next.30",
16
- "@arcgis/toolkit": "6.0.0-next.30",
14
+ "@arcgis/api-extractor": "6.0.0-next.32",
15
+ "@arcgis/node-toolkit": "6.0.0-next.32",
16
+ "@arcgis/toolkit": "6.0.0-next.32",
17
17
  "@commander-js/extra-typings": "^15.0.0",
18
18
  "commander": "^15.0.0",
19
+ "picomatch": "^4.0.4",
19
20
  "semver": "^7.7.3",
20
21
  "tinyglobby": "~0.2.17",
21
22
  "ts-morph": "^28.0.0",
@@ -1,48 +0,0 @@
1
- import { findPath as c } from "@arcgis/node-toolkit/file";
2
- import { path as s, toPosixPathSeparators as p } from "@arcgis/node-toolkit/path";
3
- import { collectOutputSync as i } from "@arcgis/node-toolkit/shell";
4
- const f = "6.0.0-next.30";
5
- function w(o, e) {
6
- return o.package.localeCompare(e.package) || o.file.localeCompare(e.file) || o.line - e.line || o.column - e.column || t(o.module, e.module) || t(o.memberOf, e.memberOf) || o.name.localeCompare(e.name) || t(o.kind, e.kind) || t(o.category, e.category) || t(o.provenance, e.provenance) || String(o.deprecated).localeCompare(String(e.deprecated));
7
- }
8
- const t = (o, e) => (o ?? "").localeCompare(e ?? "");
9
- function $(o) {
10
- const e = JSON.parse(o);
11
- if (typeof e != "object" || e === null || !("auditKind" in e) || e.auditKind !== "usages" && e.auditKind !== "definitions")
12
- throw new Error("Invalid deprecation audit JSON.");
13
- return e;
14
- }
15
- function h() {
16
- const o = c(".git");
17
- if (o === void 0)
18
- throw new Error("Unable to find a Git repository for the deprecation audit.");
19
- const e = s.dirname(o), r = i("git", ["remote", "get-url", "origin"], { cwd: e }), n = i("git", ["rev-parse", "HEAD"], { cwd: e }), a = process.env.GITHUB_HEAD_REF || process.env.GITHUB_REF_NAME || i("git", ["branch", "--show-current"], { cwd: e });
20
- return { repository: u(r), repositoryRoot: e, ref: n, branch: a };
21
- }
22
- function g(o, e) {
23
- return p(s.relative(e, o));
24
- }
25
- function v(o, e, r, n) {
26
- const a = o === "usages" ? "usage" : "definition";
27
- process.stderr.write(
28
- `Deprecations: ${e} ${a}${e === 1 ? "" : "s"} across ${r} file${r === 1 ? "" : "s"} from ${n} package${n === 1 ? "" : "s"}.
29
- `
30
- );
31
- }
32
- function u(o) {
33
- const e = o.replace(/\.git$/u, "");
34
- if (e.startsWith("http://") || e.startsWith("https://"))
35
- return new URL(e).href.replace(/^https?:\/\//u, "").replace(/\/$/u, "");
36
- const r = /^(?:ssh:\/\/)?git@([^/:]+)[:/](.+)$/u.exec(e);
37
- if (r !== null)
38
- return `${r[1]}/${r[2]}`;
39
- throw new Error(`Unsupported Git remote URL: ${o}`);
40
- }
41
- export {
42
- g as a,
43
- $ as b,
44
- w as c,
45
- h as g,
46
- v as p,
47
- f as s
48
- };
@@ -1,124 +0,0 @@
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
- };