@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.
@@ -1,164 +1,66 @@
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;
92
- }
93
- await this.#t("PATCH", `/repos/${this.#s}/issues/comments/${s}`, { body: e });
94
- }
95
- async deleteComment(s) {
96
- if (this.dryRun) {
97
- this.changes.push(`REMOVE comment #${s}`);
98
- return;
99
- }
100
- await this.#t("DELETE", `/repos/${this.#s}/issues/comments/${s}`);
101
- }
102
- }
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)}
1
+ import { readFile as w } from "node:fs/promises";
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(`
10
+ `)}
107
11
  `);
108
12
  }
109
- function E(n, s, e) {
110
- return n.slice(s, e === void 0 ? void 0 : s + e);
13
+ function k(t, s, o) {
14
+ if (s !== 0 || o !== void 0)
15
+ throw new Error("--close-resolved cannot be used with --offset or --limit.");
16
+ return t.complete !== !0 ? (f(
17
+ "warn",
18
+ d,
19
+ "Skipping --close-resolved: the report is not a complete, unfiltered repository-root audit. Issue creation and updates will continue."
20
+ ), !1) : !0;
21
+ }
22
+ function C(t, s, o) {
23
+ return t.slice(s, o === void 0 ? void 0 : s + o);
111
24
  }
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));
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));
120
31
  }
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);
121
35
  }
122
- function T(n) {
123
- return n.map(
36
+ function E(t) {
37
+ return t.map(
124
38
  (s) => `ACTIONS: ${s.changes.length === 0 ? "No changes" : s.changes.join("; ")}
125
39
 
126
40
  CODEOWNERS: ${s.owners.length === 0 ? "unowned" : s.owners.join(", ")}
127
41
  ASSIGNEES: ${s.assignees.length === 0 ? "none" : s.assignees.join(", ")}
128
42
  TITLE: ${s.title}
129
43
 
130
- ${s.chunks.map((e, i) => `--- ${i === 0 ? "BODY" : "COMMENT"} (${i + 1}/${s.chunks.length}) ---
131
- ${e}`).join(`
44
+ ${s.chunks.map((o, n) => `--- ${n === 0 ? "BODY" : "COMMENT"} (${n + 1}/${s.chunks.length}) ---
45
+ ${o}`).join(`
132
46
 
133
47
  `)}`
134
48
  ).join(`
135
49
 
136
50
  `);
137
51
  }
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);
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);
141
55
  }
142
- function m(n) {
143
- const s = n?.split(`
56
+ function m(t) {
57
+ const s = t?.split(`
144
58
  `, 1)[0];
145
- return s?.startsWith(f) === !0 ? s : void 0;
146
- }
147
- function u(n) {
148
- return n?.replace(y, "$1<sha>$2");
149
- }
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);
59
+ return s?.startsWith(g) === !0 ? s : void 0;
158
60
  }
159
61
  export {
160
- T as formatDryRun,
161
- E as sliceIssuePlans,
162
- A as syncDeprecationIssues,
163
- I as synchronizeIssuePlans
62
+ E as formatDryRun,
63
+ C as sliceIssuePlans,
64
+ D as syncDeprecationIssues,
65
+ S as synchronizeIssuePlans
164
66
  };
@@ -0,0 +1,32 @@
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(`
9
+ `)}
10
+
11
+ ${o.join(`
12
+
13
+ `)}
14
+ `
15
+ );
16
+ }
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
+ }
23
+ function $(t, s = c) {
24
+ const e = `${h}
25
+
26
+ `;
27
+ return m(t, s - e.length).map((r) => e + r);
28
+ }
29
+ export {
30
+ $ as createMarkdownComments,
31
+ x as syncMarkdown
32
+ };
@@ -1,20 +1,20 @@
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)
1
+ import { Project as d } from "ts-morph";
2
+ import { g as t, c as p, i as a } from "./cli.js";
3
+ import { log as m } from "@arcgis/toolkit/log";
4
+ import { path as g } from "@arcgis/node-toolkit/path";
5
+ import { styleText as n } from "node:util";
6
+ function y(e, l = !0) {
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 d({
12
12
  // If tsconfig is missing, or project is untyped, use a permissive and
13
13
  // compatible default config
14
14
  compilerOptions: e.typeScriptConfig?.compilerOptions ?? {
15
- ...m,
15
+ ...p,
16
16
  // Read types from JSDoc annotations if present
17
- checkJs: n
17
+ checkJs: s
18
18
  },
19
19
  // We take care of reading the config file
20
20
  tsConfigFilePath: void 0,
@@ -22,30 +22,30 @@ function v(e, l = !0) {
22
22
  skipAddingFilesFromTsConfig: !0,
23
23
  // We call this manually if needed below.
24
24
  skipFileDependencyResolution: !0,
25
- skipLoadingLibFiles: !n
26
- }), f = e.filePaths.flatMap((o) => {
27
- const c = t.addSourceFileAtPathIfExists(o);
25
+ skipLoadingLibFiles: !s
26
+ }), f = e.filePaths.filter(a).flatMap((o) => {
27
+ const c = i.addSourceFileAtPathIfExists(o);
28
28
  return c === void 0 ? [] : [c];
29
29
  });
30
- if (n && t.resolveSourceFileDependencies(), l) {
31
- const o = a.relative(process.cwd(), e.cwd);
32
- process.stdout.write(""), d(
30
+ if (s && i.resolveSourceFileDependencies(), l) {
31
+ const o = g.relative(process.cwd(), e.cwd);
32
+ process.stdout.write(""), m(
33
33
  "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)}`}`
34
+ n("blue", o === "" ? process.cwd() : o),
35
+ `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
36
  );
37
37
  }
38
38
  const r = {
39
39
  [Symbol.dispose]() {
40
- t.saveSync(), t.getRootDirectories().forEach((o) => o.forget()), i.project = void 0;
40
+ i.saveSync(), i.getRootDirectories().forEach((o) => o.forget()), t.project = void 0;
41
41
  },
42
42
  projectData: e,
43
43
  // Resolved dependencies support type checking but are not codemod targets.
44
44
  getCodemodFiles: () => f,
45
- tsMorph: t
45
+ tsMorph: i
46
46
  };
47
- return i.project = r, r;
47
+ return t.project = r, r;
48
48
  }
49
49
  export {
50
- v as c
50
+ y as c
51
51
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/codemod",
3
- "version": "6.0.0-next.6",
3
+ "version": "6.0.0-next.7",
4
4
  "description": "A codemod toolkit for updating and modernizing ArcGIS Maps SDK for JavaScript codebases.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -11,9 +11,9 @@
11
11
  ],
12
12
  "license": "SEE LICENSE IN LICENSE.md",
13
13
  "dependencies": {
14
- "@arcgis/api-extractor": "6.0.0-next.6",
15
- "@arcgis/node-toolkit": "6.0.0-next.6",
16
- "@arcgis/toolkit": "6.0.0-next.6",
14
+ "@arcgis/api-extractor": "6.0.0-next.7",
15
+ "@arcgis/node-toolkit": "6.0.0-next.7",
16
+ "@arcgis/toolkit": "6.0.0-next.7",
17
17
  "@commander-js/extra-typings": "^15.0.0",
18
18
  "commander": "^15.0.0",
19
19
  "tinyglobby": "~0.2.17",
@@ -1,63 +0,0 @@
1
- import i from "typescript";
2
- import { findPath as s } from "@arcgis/node-toolkit/file";
3
- import { path as d } from "@arcgis/node-toolkit/path";
4
- import { retrievePackageJson as u } from "@arcgis/node-toolkit/packageJson";
5
- function h(e) {
6
- return typeof e == "string" ? e : e.map((t) => t.kind === i.SyntaxKind.JSDocText ? t.text : g(t.getText())).join("");
7
- }
8
- function D(e) {
9
- return e === void 0 ? void 0 : p(i.displayPartsToString([...e]));
10
- }
11
- function p(e) {
12
- return e.replace(
13
- /\{@link(?:code|plain)?\s+([\s\S]*?)\}/gu,
14
- (t, n) => c(n)
15
- );
16
- }
17
- function g(e) {
18
- const t = /^\{@link(?:code|plain)?\s+([\s\S]*?)\}$/u.exec(e)?.[1];
19
- return t === void 0 ? e : c(t);
20
- }
21
- function c(e) {
22
- const t = e.trim().replace(/^(\S+)\s+([/:#!.])/u, "$1$2"), n = t.indexOf("|");
23
- if (n !== -1)
24
- return t.slice(n + 1).trim() || t.slice(0, n).trim();
25
- const [r, ...a] = t.split(/\s+/u);
26
- return a.join(" ") || r;
27
- }
28
- function S(e, t) {
29
- const n = s("package.json", e);
30
- return n === void 0 ? t : u(d.dirname(n)).name ?? t;
31
- }
32
- const o = {
33
- excludedPackageNames: /* @__PURE__ */ new Set([
34
- "@arcgis/charts-components-react",
35
- "@arcgis/coding-components-react",
36
- "@arcgis/components-build-utils",
37
- "@arcgis/map-components-react",
38
- "@arcgis/portal-components-react",
39
- "@arcgis-test/lit-components-react"
40
- ]),
41
- excludedDefinitionPathFragments: ["test-package"],
42
- ignoreDeprecatedApis: ["getReactWrapperOptions"],
43
- ignoredDeprecationsByIncludes: ["React wrappers are not needed in React 19 or above"]
44
- };
45
- function k(e) {
46
- return e !== void 0 && o.excludedPackageNames.has(e);
47
- }
48
- function P(e) {
49
- return o.excludedDefinitionPathFragments.some(
50
- (t) => e.includes(t)
51
- );
52
- }
53
- function v(e, t) {
54
- return o.ignoreDeprecatedApis.some((n) => n === e) || t != null && o.ignoredDeprecationsByIncludes.some((n) => t.includes(n));
55
- }
56
- export {
57
- v as a,
58
- h as b,
59
- D as c,
60
- P as d,
61
- S as g,
62
- k as s
63
- };