@arcgis/codemod 6.0.0-next.6 → 6.0.0-next.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunks/artifact.js +44 -0
- package/dist/chunks/classification.js +105 -134
- package/dist/chunks/cli.js +347 -212
- package/dist/chunks/componentAudit.js +158 -0
- package/dist/chunks/format.js +110 -106
- package/dist/chunks/github.js +124 -0
- package/dist/chunks/index.js +545 -315
- package/dist/chunks/index2.js +102 -88
- package/dist/chunks/index3.js +307 -0
- package/dist/chunks/sync.js +44 -142
- package/dist/chunks/syncMarkdown.js +32 -0
- package/dist/chunks/useProjectInstance.js +22 -22
- package/package.json +4 -4
- package/dist/chunks/hardcodedBehavior.js +0 -63
|
@@ -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
|
+
};
|
package/dist/chunks/format.js
CHANGED
|
@@ -1,70 +1,71 @@
|
|
|
1
|
-
import { d as
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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, "## ")}
|
|
7
8
|
|
|
8
|
-
${
|
|
9
|
+
${t.details}`;
|
|
9
10
|
}
|
|
10
|
-
function
|
|
11
|
-
const
|
|
12
|
-
for (const
|
|
13
|
-
const
|
|
14
|
-
|
|
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);
|
|
15
16
|
}
|
|
16
|
-
return [...
|
|
17
|
-
const
|
|
17
|
+
return [...t.entries()].map(([n, s]) => {
|
|
18
|
+
const r = n === "" ? [] : n.split(","), o = L(e, s);
|
|
18
19
|
return {
|
|
19
20
|
changes: [],
|
|
20
|
-
title:
|
|
21
|
-
owners:
|
|
22
|
-
assignees:
|
|
23
|
-
chunks:
|
|
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))
|
|
24
25
|
};
|
|
25
|
-
}).sort((
|
|
26
|
+
}).sort((n, s) => n.title.localeCompare(s.title));
|
|
26
27
|
}
|
|
27
|
-
function
|
|
28
|
-
const
|
|
29
|
-
(
|
|
30
|
-
),
|
|
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 ? "" : `
|
|
31
32
|
|
|
32
|
-
CODEOWNERS: ${
|
|
33
|
-
return
|
|
33
|
+
CODEOWNERS: ${n.join(", ")}`;
|
|
34
|
+
return U(e, t, s);
|
|
34
35
|
}
|
|
35
|
-
function
|
|
36
|
-
const
|
|
37
|
-
return `${
|
|
36
|
+
function U(e, t, n) {
|
|
37
|
+
const s = D[e.auditKind], r = M(e, t);
|
|
38
|
+
return `${s}${n}${r.summary}
|
|
38
39
|
|
|
39
|
-
${
|
|
40
|
+
${b}
|
|
40
41
|
|
|
41
|
-
${
|
|
42
|
+
${r.details}`;
|
|
42
43
|
}
|
|
43
|
-
function
|
|
44
|
-
return e.
|
|
44
|
+
function M(e, t) {
|
|
45
|
+
return e.auditKind === "usages" ? z(e, t) : E(e, t);
|
|
45
46
|
}
|
|
46
|
-
function
|
|
47
|
-
const
|
|
48
|
-
const u =
|
|
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(`
|
|
49
50
|
`);
|
|
50
|
-
return `- **${
|
|
51
|
+
return `- **${h[a].label}**: ${c}
|
|
51
52
|
${u}`;
|
|
52
53
|
}).join(`
|
|
53
|
-
`),
|
|
54
|
-
const u =
|
|
55
|
-
const C =
|
|
56
|
-
({ items:
|
|
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)
|
|
57
58
|
);
|
|
58
|
-
return `#### ${
|
|
59
|
+
return `#### ${l} (${S})
|
|
59
60
|
|
|
60
61
|
${C.join(`
|
|
61
62
|
`)}`;
|
|
62
63
|
}).join(`
|
|
63
64
|
|
|
64
|
-
`), p =
|
|
65
|
+
`), p = h[a], i = "description" in p ? `
|
|
65
66
|
|
|
66
67
|
${p.description}` : "";
|
|
67
|
-
return `### ${p.label} (${c})${
|
|
68
|
+
return `### ${p.label} (${c})${i}
|
|
68
69
|
|
|
69
70
|
${u}`;
|
|
70
71
|
}).join(`
|
|
@@ -75,25 +76,28 @@ ${u}`;
|
|
|
75
76
|
|
|
76
77
|
### Deprecation summary
|
|
77
78
|
|
|
78
|
-
${
|
|
79
|
+
${r}`,
|
|
79
80
|
details: `## Deprecation details
|
|
80
81
|
|
|
81
|
-
${
|
|
82
|
+
${o}`
|
|
82
83
|
};
|
|
83
84
|
}
|
|
84
|
-
function
|
|
85
|
-
const
|
|
86
|
-
for (const
|
|
87
|
-
const
|
|
88
|
-
|
|
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);
|
|
89
90
|
}
|
|
90
|
-
return new Set([...
|
|
91
|
-
}
|
|
92
|
-
function
|
|
93
|
-
const
|
|
94
|
-
return { summary: "", details: [...Map.groupBy(
|
|
95
|
-
|
|
96
|
-
|
|
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
|
|
97
101
|
|
|
98
102
|
${c.join(`
|
|
99
103
|
`)}`;
|
|
@@ -101,84 +105,84 @@ ${c.join(`
|
|
|
101
105
|
|
|
102
106
|
`) };
|
|
103
107
|
}
|
|
104
|
-
function
|
|
105
|
-
const
|
|
106
|
-
return
|
|
107
|
-
const
|
|
108
|
-
return
|
|
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);
|
|
109
113
|
});
|
|
110
114
|
}
|
|
111
|
-
function
|
|
112
|
-
const
|
|
115
|
+
function N(e, t, n, s, r) {
|
|
116
|
+
const o = n.length === 0 ? "" : ` - ${n.map(q).join(" ")}`, a = [
|
|
113
117
|
...new Set(
|
|
114
|
-
r.toSorted((
|
|
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))
|
|
115
119
|
)
|
|
116
|
-
],
|
|
117
|
-
`),
|
|
118
|
-
|
|
119
|
-
|
|
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}`}`;
|
|
120
130
|
}
|
|
121
131
|
function T(e) {
|
|
122
132
|
return [
|
|
123
133
|
...new Set(
|
|
124
|
-
e.map(({
|
|
134
|
+
e.map(({ deprecated: t }) => t).filter((t) => typeof t == "string" && t !== "")
|
|
125
135
|
)
|
|
126
136
|
];
|
|
127
137
|
}
|
|
128
|
-
function
|
|
129
|
-
const
|
|
130
|
-
`,
|
|
131
|
-
if (
|
|
138
|
+
function _(e, t = k, n = y) {
|
|
139
|
+
const s = `${n}
|
|
140
|
+
`, r = t - s.length;
|
|
141
|
+
if (r < 1)
|
|
132
142
|
throw new Error("Issue content limit is too small for the managed marker.");
|
|
133
|
-
|
|
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(e, r).map((o) => s + o);
|
|
141
144
|
}
|
|
142
|
-
function
|
|
143
|
-
return e.length === 0 ?
|
|
145
|
+
function G(e) {
|
|
146
|
+
return e.length === 0 ? y : `<!-- ${d} ${f(e).join(",")} -->`;
|
|
144
147
|
}
|
|
145
|
-
function
|
|
146
|
-
return [...new Set(e)].sort((
|
|
148
|
+
function f(e) {
|
|
149
|
+
return [...new Set(e)].sort((t, n) => t.localeCompare(n));
|
|
147
150
|
}
|
|
148
|
-
function
|
|
149
|
-
return `${
|
|
151
|
+
function j(e, t) {
|
|
152
|
+
return `${$(t)}\0${g(e, t) ?? ""}`;
|
|
150
153
|
}
|
|
151
|
-
function
|
|
152
|
-
return e === "definitions" ?
|
|
154
|
+
function g(e, t) {
|
|
155
|
+
return e === "definitions" && t.provenance !== "manifest" ? W(t.file) : t.module;
|
|
153
156
|
}
|
|
154
|
-
function
|
|
155
|
-
const
|
|
156
|
-
return (
|
|
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, "");
|
|
157
160
|
}
|
|
158
161
|
function q(e) {
|
|
159
|
-
const
|
|
162
|
+
const t = [], n = (o) => `\0${t.push(o) - 1}\0`, r = e.replaceAll(`\r
|
|
160
163
|
`, `
|
|
161
164
|
`).replaceAll("\r", `
|
|
162
165
|
`).replace(
|
|
163
166
|
/\[([^\]\n]+)\]\((https?:\/\/(?:[^()\s]|\([^()\s]*\))+?)\)/gu,
|
|
164
|
-
(
|
|
165
|
-
).replace(/https?:\/\/[^\s<>()]+/gu, (
|
|
166
|
-
const
|
|
167
|
-
return `${o
|
|
167
|
+
(o, a, c) => n(`[${w(a)}](${c})`)
|
|
168
|
+
).replace(/https?:\/\/[^\s<>()]+/gu, (o) => {
|
|
169
|
+
const a = /[.,;:!?]+$/u.exec(o)?.[0] ?? "";
|
|
170
|
+
return `${n(o.slice(0, -a.length || void 0))}${a}`;
|
|
168
171
|
});
|
|
169
|
-
return
|
|
172
|
+
return w(r).replace(/\0(\d+)\0/gu, (o, a) => t[Number(a)]).replaceAll(`
|
|
170
173
|
`, `
|
|
171
174
|
`);
|
|
172
175
|
}
|
|
173
|
-
function
|
|
176
|
+
function w(e) {
|
|
174
177
|
return e.replace(/^(\s*)(#{1,6})(?=\s)/gmu, "$1\\$2").replace(/#(?=\d)/gu, "# ");
|
|
175
178
|
}
|
|
176
|
-
function
|
|
177
|
-
const
|
|
178
|
-
return `https://${e}/blob/${
|
|
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}`;
|
|
179
182
|
}
|
|
180
183
|
export {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
+
y 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
|
+
};
|