@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.
@@ -1,165 +1,66 @@
1
- import { readFile as f } from "node:fs/promises";
2
- import { log as h } from "@arcgis/toolkit/log";
3
- import { a as m, b as g, d as c, e as d } from "./format.js";
4
- import { collectOutput as u } from "@arcgis/node-toolkit/shell";
5
- class l {
6
- constructor(s, e = !1) {
7
- this.changes = [], this.#i = /* @__PURE__ */ new Map(), this.#n = -1;
8
- const [i, t, o, ...r] = s.split("/");
9
- if (i === void 0 || t === void 0 || o === void 0 || r.length > 0)
10
- throw new Error(`Invalid repository: ${s}`);
11
- this.#e = i, this.#s = `${t}/${o}`, this.dryRun = e;
12
- }
13
- #e;
14
- #s;
15
- #i;
16
- #n;
17
- async #t(s, e, i) {
18
- if (process.env.VITEST !== void 0)
19
- throw new Error("GitHub requests are disabled while running Vitest.");
20
- const t = await u(
21
- "gh",
22
- ["api", "--hostname", this.#e, "--method", s, e, ...i === void 0 ? [] : ["--input", "-"]],
23
- i === void 0 ? {} : { input: JSON.stringify(i) }
24
- );
25
- return t === "" ? void 0 : JSON.parse(t);
26
- }
27
- async listOpenIssues(s) {
28
- const e = await u("gh", [
29
- "api",
30
- "--hostname",
31
- this.#e,
32
- "--method",
33
- "GET",
34
- "--paginate",
35
- "--slurp",
36
- "-f",
37
- `q="${s}" in:title repo:${this.#s} is:issue is:open`,
38
- "-f",
39
- "per_page=100",
40
- "/search/issues"
41
- ]);
42
- return JSON.parse(e).flatMap(({ items: i }) => i);
43
- }
44
- async createIssue(s, e, i, t) {
45
- if (this.dryRun) {
46
- const o = this.#n--;
47
- return this.#i.set(o, s), this.changes.push(`CREATE issue: ${s}`), { number: o, title: s, body: e, assignees: i.map((r) => ({ login: r })) };
48
- }
49
- return await this.#t("POST", `/repos/${this.#s}/issues`, {
50
- title: s,
51
- body: e,
52
- assignees: i,
53
- labels: t,
54
- type: m
55
- });
56
- }
57
- async updateIssueBody(s, e) {
58
- if (this.dryRun) {
59
- this.changes.push(`UPDATE issue #${s} body`);
60
- return;
61
- }
62
- await this.#t("PATCH", `/repos/${this.#s}/issues/${s}`, { body: e });
63
- }
64
- async listComments(s) {
65
- if (this.#i.has(s))
66
- return [];
67
- const e = await u("gh", [
68
- "api",
69
- "--hostname",
70
- this.#e,
71
- "--method",
72
- "GET",
73
- "--paginate",
74
- "--slurp",
75
- `/repos/${this.#s}/issues/${s}/comments?per_page=100`
76
- ]);
77
- return JSON.parse(e).flat();
78
- }
79
- async createComment(s, e) {
80
- if (this.dryRun) {
81
- const i = this.#i.get(s), t = i === void 0 ? `issue #${s}` : `new issue: ${i}`;
82
- this.changes.push(`ADD comment to ${t}`);
83
- return;
84
- }
85
- await this.#t("POST", `/repos/${this.#s}/issues/${s}/comments`, { body: e });
86
- }
87
- async updateComment(s, e) {
88
- if (this.dryRun) {
89
- this.changes.push(`UPDATE comment #${s}`);
90
- return;
91
- }
92
- await this.#t("PATCH", `/repos/${this.#s}/issues/comments/${s}`, { body: e });
93
- }
94
- async deleteComment(s) {
95
- if (this.dryRun) {
96
- this.changes.push(`REMOVE comment #${s}`);
97
- return;
98
- }
99
- await this.#t("DELETE", `/repos/${this.#s}/issues/comments/${s}`);
100
- }
101
- }
102
- async function k(n, s, e = 0, i, t = []) {
103
- const o = w(await f(n, "utf8")), r = y(g(o), e, i), a = new l(o.repository, s);
104
- await $(r, a, t), s && process.stdout.write(`${E(r)}
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
+ `)}
105
11
  `);
106
12
  }
107
- function y(n, s, e) {
108
- 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;
109
21
  }
110
- async function $(n, s, e = []) {
111
- const i = /* @__PURE__ */ new Map();
112
- for (const t of n) {
113
- let o = i.get(t.title);
114
- o === void 0 && (o = await s.listOpenIssues(t.title), i.set(t.title, o));
115
- const r = I(o, t);
116
- let a;
117
- r === void 0 ? (a = (await s.createIssue(t.title, t.chunks[0], t.assignees, e)).number, s.dryRun || h("info", c, `Created issue #${a}: ${t.title}`)) : (a = r.number, r.body !== t.chunks[0] && (await s.updateIssueBody(a, t.chunks[0]), s.dryRun || h("info", c, `Updated issue #${a}: ${t.title}`))), await T(s, a, t.chunks.slice(1)), t.changes.push(...s.changes.splice(0));
118
- }
22
+ function C(t, s, o) {
23
+ return t.slice(s, o === void 0 ? void 0 : s + o);
119
24
  }
120
- function w(n) {
121
- const s = JSON.parse(n);
122
- if (s.kind !== "usages" && s.kind !== "definitions" || typeof s.repository != "string" || typeof s.ref != "string" || !Array.isArray(s.findings))
123
- throw new Error("Invalid deprecation audit JSON.");
124
- return s;
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));
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);
125
35
  }
126
- function E(n) {
127
- return n.map(
36
+ function E(t) {
37
+ return t.map(
128
38
  (s) => `ACTIONS: ${s.changes.length === 0 ? "No changes" : s.changes.join("; ")}
129
39
 
130
40
  CODEOWNERS: ${s.owners.length === 0 ? "unowned" : s.owners.join(", ")}
131
41
  ASSIGNEES: ${s.assignees.length === 0 ? "none" : s.assignees.join(", ")}
132
42
  TITLE: ${s.title}
133
43
 
134
- ${s.chunks.map((e, i) => `--- ${i === 0 ? "BODY" : "COMMENT"} (${i + 1}/${s.chunks.length}) ---
135
- ${e}`).join(`
44
+ ${s.chunks.map((o, n) => `--- ${n === 0 ? "BODY" : "COMMENT"} (${n + 1}/${s.chunks.length}) ---
45
+ ${o}`).join(`
136
46
 
137
47
  `)}`
138
48
  ).join(`
139
49
 
140
50
  `);
141
51
  }
142
- function I(n, s) {
143
- const e = p(s.chunks[0]);
144
- return n.find((i) => i.title === s.title && p(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);
145
55
  }
146
- function p(n) {
147
- const s = n?.split(`
56
+ function m(t) {
57
+ const s = t?.split(`
148
58
  `, 1)[0];
149
- return s?.startsWith(d) === !0 ? s : void 0;
150
- }
151
- async function T(n, s, e) {
152
- const i = (await n.listComments(s)).filter(({ body: t }) => t.startsWith(d));
153
- for (const [t, o] of e.entries()) {
154
- const r = i[t];
155
- r === void 0 ? await n.createComment(s, o) : r.body !== o && await n.updateComment(r.id, o);
156
- }
157
- for (const t of i.slice(e.length))
158
- await n.deleteComment(t.id);
59
+ return s?.startsWith(g) === !0 ? s : void 0;
159
60
  }
160
61
  export {
161
62
  E as formatDryRun,
162
- y as sliceIssuePlans,
163
- k as syncDeprecationIssues,
164
- $ as synchronizeIssuePlans
63
+ C as sliceIssuePlans,
64
+ D as syncDeprecationIssues,
65
+ S as synchronizeIssuePlans
165
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.0",
3
+ "version": "6.0.0-next.10",
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.0",
15
- "@arcgis/node-toolkit": "6.0.0-next.0",
16
- "@arcgis/toolkit": "6.0.0-next.0",
14
+ "@arcgis/api-extractor": "6.0.0-next.10",
15
+ "@arcgis/node-toolkit": "6.0.0-next.10",
16
+ "@arcgis/toolkit": "6.0.0-next.10",
17
17
  "@commander-js/extra-typings": "^15.0.0",
18
18
  "commander": "^15.0.0",
19
19
  "tinyglobby": "~0.2.17",
@@ -1,93 +0,0 @@
1
- import { findPath as a } from "@arcgis/node-toolkit/file";
2
- import { path as s, toPosixPathSeparators as d } from "@arcgis/node-toolkit/path";
3
- import { collectOutputSync as c } from "@arcgis/node-toolkit/shell";
4
- import u from "typescript";
5
- import { retrievePackageJson as g } from "@arcgis/node-toolkit/packageJson";
6
- function P() {
7
- const t = a(".git");
8
- if (t === void 0)
9
- throw new Error("Unable to find a Git repository for the deprecation audit.");
10
- const e = s.dirname(t), o = c("git", ["remote", "get-url", "origin"], { cwd: e }), n = c("git", ["rev-parse", "HEAD"], { cwd: e });
11
- return { repository: l(o), repositoryRoot: e, ref: n };
12
- }
13
- function v(t, e) {
14
- return d(s.relative(e, t));
15
- }
16
- function y(t, e, o, n) {
17
- const i = t === "usages" ? "usage" : "definition";
18
- process.stderr.write(
19
- `Deprecations: ${e} ${i}${e === 1 ? "" : "s"} across ${o} file${o === 1 ? "" : "s"} from ${n} package${n === 1 ? "" : "s"}.
20
- `
21
- );
22
- }
23
- function l(t) {
24
- const e = t.replace(/\.git$/u, "");
25
- if (e.startsWith("http://") || e.startsWith("https://"))
26
- return new URL(e).href.replace(/^https?:\/\//u, "").replace(/\/$/u, "");
27
- const o = /^(?:ssh:\/\/)?git@([^/:]+)[:/](.+)$/u.exec(e);
28
- if (o !== null)
29
- return `${o[1]}/${o[2]}`;
30
- throw new Error(`Unsupported Git remote URL: ${t}`);
31
- }
32
- function w(t) {
33
- return typeof t == "string" ? t : t.map((e) => e.kind === u.SyntaxKind.JSDocText ? e.text : m(e.getText())).join("");
34
- }
35
- function k(t) {
36
- return t === void 0 ? void 0 : f(u.displayPartsToString([...t]));
37
- }
38
- function f(t) {
39
- return t.replace(
40
- /\{@link(?:code|plain)?\s+([\s\S]*?)\}/gu,
41
- (e, o) => p(o)
42
- );
43
- }
44
- function m(t) {
45
- const e = /^\{@link(?:code|plain)?\s+([\s\S]*?)\}$/u.exec(t)?.[1];
46
- return e === void 0 ? t : p(e);
47
- }
48
- function p(t) {
49
- const e = t.trim().replace(/^(\S+)\s+([/:#!.])/u, "$1$2"), o = e.indexOf("|");
50
- if (o !== -1)
51
- return e.slice(o + 1).trim() || e.slice(0, o).trim();
52
- const [n, ...i] = e.split(/\s+/u);
53
- return i.join(" ") || n;
54
- }
55
- function R(t, e) {
56
- const o = a("package.json", t);
57
- return o === void 0 ? e : g(s.dirname(o)).name ?? e;
58
- }
59
- const r = {
60
- excludedPackageNames: /* @__PURE__ */ new Set([
61
- "@arcgis/charts-components-react",
62
- "@arcgis/coding-components-react",
63
- "@arcgis/components-build-utils",
64
- "@arcgis/map-components-react",
65
- "@arcgis/portal-components-react",
66
- "@arcgis-test/lit-components-react"
67
- ]),
68
- excludedDefinitionPathFragments: ["test-package"],
69
- ignoreDeprecatedApis: ["getReactWrapperOptions"],
70
- ignoredDeprecationsByIncludes: ["React wrappers are not needed in React 19 or above"]
71
- };
72
- function J(t) {
73
- return t !== void 0 && r.excludedPackageNames.has(t);
74
- }
75
- function T(t) {
76
- return r.excludedDefinitionPathFragments.some(
77
- (e) => t.includes(e)
78
- );
79
- }
80
- function E(t, e) {
81
- return r.ignoreDeprecatedApis.some((o) => o === t) || e != null && r.ignoredDeprecationsByIncludes.some((o) => e.includes(o));
82
- }
83
- export {
84
- v as a,
85
- R as b,
86
- E as c,
87
- k as d,
88
- T as e,
89
- w as f,
90
- P as g,
91
- y as p,
92
- J as s
93
- };