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

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,164 +1,168 @@
1
- import { readFile as d } from "node:fs/promises";
2
- import { log as c } from "@arcgis/toolkit/log";
3
- import { l as $, m as l, n as p } from "./classification.js";
4
- import { c as g, i as f } from "./format.js";
5
- import { collectOutput as h } from "@arcgis/node-toolkit/shell";
6
- class w {
7
- constructor(s, e = !1) {
8
- this.changes = [], this.#i = /* @__PURE__ */ new Map(), this.#n = -1;
9
- const [i, t, o, ...a] = s.split("/");
10
- if (i === void 0 || t === void 0 || o === void 0 || a.length > 0)
11
- throw new Error(`Invalid repository: ${s}`);
12
- this.#e = i, this.#s = `${t}/${o}`, this.dryRun = e;
13
- }
14
- #e;
15
- #s;
16
- #i;
17
- #n;
18
- async #t(s, e, i) {
19
- if (process.env.VITEST !== void 0)
20
- throw new Error("GitHub requests are disabled while running Vitest.");
21
- const t = await h(
22
- "gh",
23
- ["api", "--hostname", this.#e, "--method", s, e, ...i === void 0 ? [] : ["--input", "-"]],
24
- i === void 0 ? {} : { input: JSON.stringify(i) }
25
- );
26
- return t === "" ? void 0 : JSON.parse(t);
27
- }
28
- async listOpenIssues(s) {
29
- const e = await h("gh", [
30
- "api",
31
- "--hostname",
32
- this.#e,
33
- "--method",
34
- "GET",
35
- "--paginate",
36
- "--slurp",
37
- "-f",
38
- `q="${s}" in:title repo:${this.#s} is:issue is:open`,
39
- "-f",
40
- "per_page=100",
41
- "/search/issues"
42
- ]);
43
- return JSON.parse(e).flatMap(({ items: i }) => i);
44
- }
45
- async createIssue(s, e, i, t) {
46
- if (this.dryRun) {
47
- const o = this.#n--;
48
- return this.#i.set(o, s), this.changes.push(`CREATE issue: ${s}`), { number: o, title: s, body: e, assignees: i.map((a) => ({ login: a })) };
49
- }
50
- return await this.#t("POST", `/repos/${this.#s}/issues`, {
51
- title: s,
52
- body: e,
53
- assignees: i,
54
- labels: t,
55
- type: $
56
- });
57
- }
58
- async updateIssueBody(s, e) {
59
- if (this.dryRun) {
60
- this.changes.push(`UPDATE issue #${s} body`);
61
- return;
62
- }
63
- await this.#t("PATCH", `/repos/${this.#s}/issues/${s}`, { body: e });
64
- }
65
- async listComments(s) {
66
- if (this.#i.has(s))
67
- return [];
68
- const e = await h("gh", [
69
- "api",
70
- "--hostname",
71
- this.#e,
72
- "--method",
73
- "GET",
74
- "--paginate",
75
- "--slurp",
76
- `/repos/${this.#s}/issues/${s}/comments?per_page=100`
77
- ]);
78
- return JSON.parse(e).flat();
79
- }
80
- async createComment(s, e) {
81
- if (this.dryRun) {
82
- const i = this.#i.get(s), t = i === void 0 ? `issue #${s}` : `new issue: ${i}`;
83
- this.changes.push(`ADD comment to ${t}`);
84
- return;
85
- }
86
- await this.#t("POST", `/repos/${this.#s}/issues/${s}/comments`, { body: e });
87
- }
88
- async updateComment(s, e) {
89
- if (this.dryRun) {
90
- this.changes.push(`UPDATE comment #${s}`);
91
- return;
1
+ import { readFile as E } from "node:fs/promises";
2
+ import { log as f } from "@arcgis/toolkit/log";
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)}`);
92
19
  }
93
- await this.#t("PATCH", `/repos/${this.#s}/issues/comments/${s}`, { body: e });
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);
94
26
  }
95
- async deleteComment(s) {
96
- if (this.dryRun) {
97
- this.changes.push(`REMOVE comment #${s}`);
98
- return;
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}.`);
99
43
  }
100
- await this.#t("DELETE", `/repos/${this.#s}/issues/comments/${s}`);
101
- }
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));
102
53
  }
103
- const y = /^( (?:- )?https:\/\/[^/\s]+\/[^/\s]+\/[^/\s]+\/blob\/)[a-f0-9]{40}(\/\S+#L\d+)$/gmu;
104
- async function A(n, s, e = 0, i, t = []) {
105
- const o = l(await d(n, "utf8")), a = E(g(o), e, i), r = new w(o.repository, s);
106
- await I(a, r, t), s && process.stdout.write(`${T(a)}
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(`
57
+ `)}
107
58
  `);
108
59
  }
109
- function E(n, s, e) {
110
- return n.slice(s, e === void 0 ? void 0 : s + e);
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)
71
+ throw new Error("--close-resolved cannot be used with --offset or --limit.");
72
+ return s.complete !== !0 ? (f(
73
+ "warn",
74
+ d,
75
+ "Skipping --close-resolved: the report is not a complete, unfiltered repository-root audit. Issue creation and updates will continue."
76
+ ), !1) : !0;
111
77
  }
112
- async function I(n, s, e = []) {
113
- const i = /* @__PURE__ */ new Map();
114
- for (const t of n) {
115
- let o = i.get(t.title);
116
- o === void 0 && (o = await s.listOpenIssues(t.title), i.set(t.title, o));
117
- const a = C(o, t);
118
- let r;
119
- a === void 0 ? (r = (await s.createIssue(t.title, t.chunks[0], t.assignees, e)).number, s.dryRun || c("info", p, `Created issue #${r}: ${t.title}`)) : (r = a.number, u(a.body) !== u(t.chunks[0]) && (await s.updateIssueBody(r, t.chunks[0]), s.dryRun || c("info", p, `Updated issue #${r}: ${t.title}`))), await v(s, r, t.chunks.slice(1)), t.changes.push(...s.changes.splice(0));
78
+ function q(s, e, r) {
79
+ return s.slice(e, r === void 0 ? void 0 : e + r);
80
+ }
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));
120
104
  }
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);
121
108
  }
122
- function T(n) {
123
- return n.map(
124
- (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("; ")}
125
112
 
126
- CODEOWNERS: ${s.owners.length === 0 ? "unowned" : s.owners.join(", ")}
127
- ASSIGNEES: ${s.assignees.length === 0 ? "none" : s.assignees.join(", ")}
128
- 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}
129
117
 
130
- ${s.chunks.map((e, i) => `--- ${i === 0 ? "BODY" : "COMMENT"} (${i + 1}/${s.chunks.length}) ---
131
- ${e}`).join(`
118
+ ${e.chunks.map((r, n) => `--- ${n === 0 ? "BODY" : "COMMENT"} (${n + 1}/${e.chunks.length}) ---
119
+ ${r}`).join(`
132
120
 
133
121
  `)}`
134
122
  ).join(`
135
123
 
136
124
  `);
137
125
  }
138
- function C(n, s) {
139
- const e = m(s.chunks[0]);
140
- return n.find((i) => i.title === s.title && m(i.body) === e);
141
- }
142
- function m(n) {
143
- const s = n?.split(`
144
- `, 1)[0];
145
- return s?.startsWith(f) === !0 ? s : void 0;
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
146
  }
147
- function u(n) {
148
- return n?.replace(y, "$1<sha>$2");
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);
149
158
  }
150
- async function v(n, s, e) {
151
- const i = (await n.listComments(s)).filter(({ body: t }) => t.startsWith(f));
152
- for (const [t, o] of e.entries()) {
153
- const a = i[t];
154
- a === void 0 ? await n.createComment(s, o) : u(a.body) !== u(o) && await n.updateComment(a.id, o);
155
- }
156
- for (const t of i.slice(e.length))
157
- await n.deleteComment(t.id);
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 };
158
162
  }
159
163
  export {
160
- T as formatDryRun,
161
- E as sliceIssuePlans,
162
- A as syncDeprecationIssues,
163
- I as synchronizeIssuePlans
164
+ H as formatDryRun,
165
+ q as sliceIssuePlans,
166
+ se as syncDeprecationIssues,
167
+ F as synchronizeIssuePlans
164
168
  };
@@ -0,0 +1,42 @@
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(`
14
+ `)}
15
+
16
+ ${o.join(`
17
+
18
+ `)}
19
+ `
20
+ );
21
+ }
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]) };
27
+ }
28
+ function l(e, t = u) {
29
+ const n = `${a}
30
+
31
+ `;
32
+ return p(e, t - n.length).map((s) => n + s);
33
+ }
34
+ function k(e) {
35
+ return e.split(`
36
+ `, 1)[0] === a;
37
+ }
38
+ export {
39
+ l as createMarkdownComments,
40
+ k as isMarkdownComment,
41
+ M as syncMarkdown
42
+ };
@@ -1,20 +1,23 @@
1
1
  import { Project as p } from "ts-morph";
2
- import { log as d } from "@arcgis/toolkit/log";
3
- import { path as a } from "@arcgis/node-toolkit/path";
4
- import { g as i, a as m } from "./cli.js";
5
- import { styleText as s } from "node:util";
6
- function v(e, l = !0) {
7
- if (i.project !== void 0)
2
+ import { g as t, c as a, i as m } from "./cli.js";
3
+ import { log as g } from "@arcgis/toolkit/log";
4
+ import { path as u } from "@arcgis/node-toolkit/path";
5
+ import { styleText as n } from "node:util";
6
+ function S(e, l = !0, f) {
7
+ if (t.project !== void 0)
8
8
  throw Error(
9
9
  "A different ts-morph Project is already in use. Dispose of it before creating a new one. Example: using project = createProjectInstance(...)"
10
10
  );
11
- const n = i.codemod.meta.needsTypeInformation, t = new p({
11
+ const s = t.codemod.meta.needsTypeInformation, i = new p({
12
12
  // If tsconfig is missing, or project is untyped, use a permissive and
13
13
  // compatible default config
14
- compilerOptions: e.typeScriptConfig?.compilerOptions ?? {
15
- ...m,
16
- // Read types from JSDoc annotations if present
17
- checkJs: n
14
+ compilerOptions: {
15
+ ...e.typeScriptConfig?.compilerOptions ?? {
16
+ ...a,
17
+ // Read types from JSDoc annotations if present
18
+ checkJs: s
19
+ },
20
+ ...f
18
21
  },
19
22
  // We take care of reading the config file
20
23
  tsConfigFilePath: void 0,
@@ -22,30 +25,30 @@ function v(e, l = !0) {
22
25
  skipAddingFilesFromTsConfig: !0,
23
26
  // We call this manually if needed below.
24
27
  skipFileDependencyResolution: !0,
25
- skipLoadingLibFiles: !n
26
- }), f = e.filePaths.flatMap((o) => {
27
- const c = t.addSourceFileAtPathIfExists(o);
28
+ skipLoadingLibFiles: !s
29
+ }), d = e.filePaths.filter(m).flatMap((o) => {
30
+ const c = i.addSourceFileAtPathIfExists(o);
28
31
  return c === void 0 ? [] : [c];
29
32
  });
30
- if (n && t.resolveSourceFileDependencies(), l) {
31
- const o = a.relative(process.cwd(), e.cwd);
32
- process.stdout.write(""), d(
33
+ if (s && i.resolveSourceFileDependencies(), l) {
34
+ const o = u.relative(process.cwd(), e.cwd);
35
+ process.stdout.write(""), g(
33
36
  "info",
34
- s("blue", o === "" ? process.cwd() : o),
35
- `Running the codemod on ${s("blue", String(e.filePaths.length))} file${e.filePaths.length !== 1 ? "s" : ""}${e.packageJson?.contents.name === void 0 ? "" : ` from ${s("blue", e.packageJson.contents.name)}`}`
37
+ n("blue", o === "" ? process.cwd() : o),
38
+ `Running the codemod on ${n("blue", String(e.filePaths.length))} file${e.filePaths.length !== 1 ? "s" : ""}${e.packageJson?.contents.name === void 0 ? "" : ` from ${n("blue", e.packageJson.contents.name)}`}`
36
39
  );
37
40
  }
38
41
  const r = {
39
42
  [Symbol.dispose]() {
40
- t.saveSync(), t.getRootDirectories().forEach((o) => o.forget()), i.project = void 0;
43
+ i.saveSync(), i.getRootDirectories().forEach((o) => o.forget()), t.project = void 0;
41
44
  },
42
45
  projectData: e,
43
46
  // Resolved dependencies support type checking but are not codemod targets.
44
- getCodemodFiles: () => f,
45
- tsMorph: t
47
+ getCodemodFiles: () => d,
48
+ tsMorph: i
46
49
  };
47
- return i.project = r, r;
50
+ return t.project = r, r;
48
51
  }
49
52
  export {
50
- v as c
53
+ S as c
51
54
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/codemod",
3
- "version": "6.0.0-next.3",
3
+ "version": "6.0.0-next.31",
4
4
  "description": "A codemod toolkit for updating and modernizing ArcGIS Maps SDK for JavaScript codebases.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -11,15 +11,18 @@
11
11
  ],
12
12
  "license": "SEE LICENSE IN LICENSE.md",
13
13
  "dependencies": {
14
- "@arcgis/api-extractor": "6.0.0-next.3",
15
- "@arcgis/node-toolkit": "6.0.0-next.3",
16
- "@arcgis/toolkit": "6.0.0-next.3",
14
+ "@arcgis/api-extractor": "6.0.0-next.31",
15
+ "@arcgis/node-toolkit": "6.0.0-next.31",
16
+ "@arcgis/toolkit": "6.0.0-next.31",
17
17
  "@commander-js/extra-typings": "^15.0.0",
18
18
  "commander": "^15.0.0",
19
+ "picomatch": "^4.0.4",
20
+ "semver": "^7.7.3",
19
21
  "tinyglobby": "~0.2.17",
20
22
  "ts-morph": "^28.0.0",
21
23
  "tslib": "^2.8.1",
22
- "typescript": "~6.0.3"
24
+ "typescript": "~6.0.3",
25
+ "yaml": "^2.8.3"
23
26
  },
24
27
  "bin": {
25
28
  "codemod": "./bin/cli.js"