@arcgis/codemod 6.0.0-next.2 → 6.0.0-next.4

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,143 +1,160 @@
1
- var k = (e, o) => (o = Symbol[e]) ? o : /* @__PURE__ */ Symbol.for("Symbol." + e), N = (e) => {
2
- throw TypeError(e);
1
+ var N = (a, o) => (o = Symbol[a]) ? o : /* @__PURE__ */ Symbol.for("Symbol." + a), h = (a) => {
2
+ throw TypeError(a);
3
3
  };
4
- var h = (e, o, a) => {
4
+ var D = (a, o, t) => {
5
5
  if (o != null) {
6
- typeof o != "object" && typeof o != "function" && N("Object expected");
7
- var s, t;
8
- a && (s = o[k("asyncDispose")]), s === void 0 && (s = o[k("dispose")], a && (t = s)), typeof s != "function" && N("Object not disposable"), t && (s = function() {
6
+ typeof o != "object" && typeof o != "function" && h("Object expected");
7
+ var c, e;
8
+ t && (c = o[N("asyncDispose")]), c === void 0 && (c = o[N("dispose")], t && (e = c)), typeof c != "function" && h("Object not disposable"), e && (c = function() {
9
9
  try {
10
- t.call(this);
11
- } catch (c) {
12
- return Promise.reject(c);
10
+ e.call(this);
11
+ } catch (i) {
12
+ return Promise.reject(i);
13
13
  }
14
- }), e.push([a, s, o]);
15
- } else a && e.push([a]);
14
+ }), a.push([t, c, o]);
15
+ } else t && a.push([t]);
16
16
  return o;
17
- }, w = (e, o, a) => {
18
- var s = typeof SuppressedError == "function" ? SuppressedError : function(n, p, r, m) {
19
- return m = Error(r), m.name = "SuppressedError", m.error = n, m.suppressed = p, m;
20
- }, t = (n) => o = a ? new s(n, o, "An error was suppressed during disposal") : (a = !0, n), c = (n) => {
21
- for (; n = e.pop(); )
17
+ }, w = (a, o, t) => {
18
+ var c = typeof SuppressedError == "function" ? SuppressedError : function(s, r, m, d) {
19
+ return d = Error(m), d.name = "SuppressedError", d.error = s, d.suppressed = r, d;
20
+ }, e = (s) => o = t ? new c(s, o, "An error was suppressed during disposal") : (t = !0, s), i = (s) => {
21
+ for (; s = a.pop(); )
22
22
  try {
23
- var p = n[1] && n[1].call(n[2]);
24
- if (n[0]) return Promise.resolve(p).then(c, (r) => (t(r), c()));
25
- } catch (r) {
26
- t(r);
23
+ var r = s[1] && s[1].call(s[2]);
24
+ if (s[0]) return Promise.resolve(r).then(i, (m) => (e(m), i()));
25
+ } catch (m) {
26
+ e(m);
27
27
  }
28
- if (a) throw o;
28
+ if (t) throw o;
29
29
  };
30
- return c();
30
+ return i();
31
31
  };
32
- import { log as D } from "@arcgis/toolkit/log";
33
- import { path as S } from "@arcgis/node-toolkit/path";
34
- import { styleText as $ } from "node:util";
32
+ import { log as y } from "@arcgis/toolkit/log";
33
+ import { path as $ } from "@arcgis/node-toolkit/path";
34
+ import { styleText as b } from "node:util";
35
35
  import P from "typescript";
36
- import { f as g } from "./log.js";
37
- import { r as v } from "./cli.js";
38
- import { c as x } from "./useProjectInstance.js";
39
- import { g as C, s as T, e as R, a as y, b, p as j, f as E } from "./hardcodedBehavior.js";
40
- import { loadCodeowners as F } from "@arcgis/node-toolkit/codeowners";
41
- async function V(e, o) {
42
- await v(
36
+ import { f as u } from "./log.js";
37
+ import { r as x } from "./cli.js";
38
+ import { c as J } from "./useProjectInstance.js";
39
+ import { g as O, e as S, a as v, b as C, p as T, d as A, f as K, h as R, j } from "./classification.js";
40
+ import { loadCodeowners as M } from "@arcgis/node-toolkit/codeowners";
41
+ import { s as E, d as z, g as F, b as I } from "./hardcodedBehavior.js";
42
+ async function oe(a, o) {
43
+ await x(
43
44
  {
44
45
  meta: { needsTypeInformation: !0, needsFooter: !1 },
45
- run(a) {
46
- O(a, o);
46
+ run(t) {
47
+ L(t, o);
47
48
  }
48
49
  },
49
50
  "deprecations audit-definitions",
50
- e
51
+ a
51
52
  );
52
53
  }
53
- function O(e, o) {
54
- const a = [], s = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Set(), c = C();
55
- for (const i of e) {
56
- var n = [];
54
+ function L(a, o) {
55
+ const t = [], c = /* @__PURE__ */ new Map(), e = /* @__PURE__ */ new Set(), i = O();
56
+ for (const n of a) {
57
+ var s = [];
57
58
  try {
58
- if (T(i.packageJson?.contents.name)) {
59
- const d = i.packageJson?.filePath;
60
- d !== void 0 && !t.has(d) && (t.add(d), D(
59
+ if (E(n.packageJson?.contents.name)) {
60
+ const p = n.packageJson?.filePath;
61
+ p !== void 0 && !e.has(p) && (e.add(p), y(
61
62
  "warn",
62
- g(d),
63
- `Skipping excluded package \`${i.packageJson?.contents.name ?? i.cwd}\`.`
63
+ u(p),
64
+ `Skipping excluded package \`${n.packageJson?.contents.name ?? n.cwd}\`.`
64
65
  ));
65
66
  continue;
66
67
  }
67
- const f = h(n, x(i, !1));
68
- const J = i.packageJson?.contents.name ?? g(i.cwd);
69
- for (const d of f.getCodemodFiles()) {
70
- if (R(
71
- y(d.compilerNode.fileName, c.repositoryRoot)
68
+ const l = D(s, J(n, !1));
69
+ const f = n.packageJson?.contents.name ?? u(n.cwd);
70
+ for (const p of l.getCodemodFiles()) {
71
+ if (z(
72
+ S(p.compilerNode.fileName, i.repositoryRoot)
72
73
  ))
73
74
  continue;
74
- const l = S.dirname(d.compilerNode.fileName), u = s.get(l) ?? b(l, J);
75
- s.set(l, u), a.push(...z(d.compilerNode, u));
75
+ const g = $.dirname(p.compilerNode.fileName), k = c.get(g) ?? F(g, f);
76
+ c.set(g, k), t.push(...Q(p.compilerNode, k));
76
77
  }
77
- } catch (p) {
78
- var r = p, m = !0;
78
+ } catch (r) {
79
+ var m = r, d = !0;
79
80
  } finally {
80
- w(n, r, m);
81
+ w(s, m, d);
81
82
  }
82
83
  }
83
84
  if (o)
84
- I(a, c);
85
+ q(t, i);
85
86
  else
86
- for (const i of a) {
87
- const f = $(
87
+ for (const n of t) {
88
+ const l = b(
88
89
  "blue",
89
- `${g(i.sourceFileName)}:${i.line}:${i.column}`
90
- );
91
- D("warn", f, `\`${i.name}\` is deprecated.${i.reason ? ` ${i.reason}` : ""}`);
90
+ `${u(n.sourceFileName)}:${n.line}:${n.column}`
91
+ ), f = v({
92
+ api: n.name,
93
+ memberOf: n.memberOf,
94
+ apiKind: n.apiKind
95
+ }), p = C(n.apiKind, "parentheses");
96
+ y("warn", l, `\`${f}\`${p} is deprecated.${n.reason ? ` ${n.reason}` : ""}`);
92
97
  }
93
- j(
98
+ T(
94
99
  "definitions",
95
- a.length,
96
- new Set(a.map(({ sourceFileName: i }) => i)).size,
97
- new Set(a.map(({ package: i }) => i)).size
100
+ t.length,
101
+ new Set(t.map(({ sourceFileName: n }) => n)).size,
102
+ new Set(t.map(({ package: n }) => n)).size
98
103
  );
99
104
  }
100
- function z(e, o) {
101
- const a = /* @__PURE__ */ new Map();
102
- function s(t) {
103
- const c = P.getJSDocDeprecatedTag(t), n = A(t);
104
- if (c !== void 0 && n !== void 0) {
105
- const p = n.getStart(e), { line: r, character: m } = e.getLineAndCharacterOfPosition(p);
106
- a.set(`${p}:${n.getWidth(e)}`, {
105
+ function Q(a, o) {
106
+ const t = /* @__PURE__ */ new Map(), c = A([a.fileName], o);
107
+ function e(i) {
108
+ const s = P.getJSDocDeprecatedTag(i), r = W(i);
109
+ if (s !== void 0 && r !== void 0) {
110
+ const m = r.getStart(a), { line: d, character: n } = a.getLineAndCharacterOfPosition(m);
111
+ t.set(`${m}:${r.getWidth(a)}`, {
107
112
  package: o,
108
- name: n.getText(e),
109
- reason: c.comment === void 0 ? void 0 : E(c.comment),
110
- sourceFileName: e.fileName,
111
- line: r + 1,
112
- column: m + 1
113
+ module: c,
114
+ name: j(i, r.getText(a)),
115
+ ...R(i),
116
+ reason: s.comment === void 0 ? void 0 : I(s.comment),
117
+ sourceFileName: a.fileName,
118
+ line: d + 1,
119
+ column: n + 1
113
120
  });
114
121
  }
115
- P.forEachChild(t, s);
122
+ P.forEachChild(i, e);
116
123
  }
117
- return s(e), [...a.values()].sort((t, c) => t.line - c.line || t.column - c.column);
124
+ return e(a), [...t.values()].sort((i, s) => i.line - s.line || i.column - s.column);
118
125
  }
119
- function A(e) {
120
- return e.name;
126
+ function W(a) {
127
+ return a.name;
121
128
  }
122
- function I(e, o) {
123
- const a = F(), s = {
129
+ function q(a, o) {
130
+ const t = M(), c = {
124
131
  kind: "definitions",
125
132
  repository: o.repository,
126
133
  ref: o.ref,
127
- findings: e.map((t) => ({
128
- package: t.package,
129
- api: t.name,
130
- reason: t.reason ?? null,
131
- file: y(t.sourceFileName, o.repositoryRoot),
132
- line: t.line,
133
- column: t.column,
134
- codeowners: a?.getOwners(t.sourceFileName) ?? []
134
+ findings: a.map((e) => ({
135
+ package: e.package,
136
+ api: e.name,
137
+ module: e.module,
138
+ apiKind: e.apiKind,
139
+ memberOf: e.memberOf,
140
+ category: K({
141
+ package: e.package,
142
+ api: e.name,
143
+ memberOf: e.memberOf,
144
+ module: e.module,
145
+ reason: e.reason ?? null
146
+ }),
147
+ reason: e.reason ?? null,
148
+ file: S(e.sourceFileName, o.repositoryRoot),
149
+ line: e.line,
150
+ column: e.column,
151
+ codeowners: t?.getOwners(e.sourceFileName) ?? []
135
152
  }))
136
153
  };
137
- process.stdout.write(`${JSON.stringify(s, void 0, 2)}
154
+ process.stdout.write(`${JSON.stringify(c, void 0, 2)}
138
155
  `);
139
156
  }
140
157
  export {
141
- V as auditDeprecatedDefinitions,
142
- z as collectDeprecatedApiDefinitions
158
+ oe as auditDeprecatedDefinitions,
159
+ Q as collectDeprecatedApiDefinitions
143
160
  };
@@ -1,12 +1,13 @@
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 {
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 {
6
7
  constructor(s, e = !1) {
7
8
  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)
9
+ const [i, t, o, ...a] = s.split("/");
10
+ if (i === void 0 || t === void 0 || o === void 0 || a.length > 0)
10
11
  throw new Error(`Invalid repository: ${s}`);
11
12
  this.#e = i, this.#s = `${t}/${o}`, this.dryRun = e;
12
13
  }
@@ -17,7 +18,7 @@ class l {
17
18
  async #t(s, e, i) {
18
19
  if (process.env.VITEST !== void 0)
19
20
  throw new Error("GitHub requests are disabled while running Vitest.");
20
- const t = await u(
21
+ const t = await h(
21
22
  "gh",
22
23
  ["api", "--hostname", this.#e, "--method", s, e, ...i === void 0 ? [] : ["--input", "-"]],
23
24
  i === void 0 ? {} : { input: JSON.stringify(i) }
@@ -25,7 +26,7 @@ class l {
25
26
  return t === "" ? void 0 : JSON.parse(t);
26
27
  }
27
28
  async listOpenIssues(s) {
28
- const e = await u("gh", [
29
+ const e = await h("gh", [
29
30
  "api",
30
31
  "--hostname",
31
32
  this.#e,
@@ -44,14 +45,14 @@ class l {
44
45
  async createIssue(s, e, i, t) {
45
46
  if (this.dryRun) {
46
47
  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
+ return this.#i.set(o, s), this.changes.push(`CREATE issue: ${s}`), { number: o, title: s, body: e, assignees: i.map((a) => ({ login: a })) };
48
49
  }
49
50
  return await this.#t("POST", `/repos/${this.#s}/issues`, {
50
51
  title: s,
51
52
  body: e,
52
53
  assignees: i,
53
54
  labels: t,
54
- type: m
55
+ type: $
55
56
  });
56
57
  }
57
58
  async updateIssueBody(s, e) {
@@ -64,7 +65,7 @@ class l {
64
65
  async listComments(s) {
65
66
  if (this.#i.has(s))
66
67
  return [];
67
- const e = await u("gh", [
68
+ const e = await h("gh", [
68
69
  "api",
69
70
  "--hostname",
70
71
  this.#e,
@@ -99,31 +100,26 @@ class l {
99
100
  await this.#t("DELETE", `/repos/${this.#s}/issues/comments/${s}`);
100
101
  }
101
102
  }
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)}
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)}
105
107
  `);
106
108
  }
107
- function y(n, s, e) {
109
+ function E(n, s, e) {
108
110
  return n.slice(s, e === void 0 ? void 0 : s + e);
109
111
  }
110
- async function $(n, s, e = []) {
112
+ async function I(n, s, e = []) {
111
113
  const i = /* @__PURE__ */ new Map();
112
114
  for (const t of n) {
113
115
  let o = i.get(t.title);
114
116
  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));
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));
118
120
  }
119
121
  }
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;
125
- }
126
- function E(n) {
122
+ function T(n) {
127
123
  return n.map(
128
124
  (s) => `ACTIONS: ${s.changes.length === 0 ? "No changes" : s.changes.join("; ")}
129
125
 
@@ -139,27 +135,30 @@ ${e}`).join(`
139
135
 
140
136
  `);
141
137
  }
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);
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);
145
141
  }
146
- function p(n) {
142
+ function m(n) {
147
143
  const s = n?.split(`
148
144
  `, 1)[0];
149
- return s?.startsWith(d) === !0 ? s : void 0;
145
+ return s?.startsWith(f) === !0 ? s : void 0;
146
+ }
147
+ function u(n) {
148
+ return n?.replace(y, "$1<sha>$2");
150
149
  }
151
- async function T(n, s, e) {
152
- const i = (await n.listComments(s)).filter(({ body: t }) => t.startsWith(d));
150
+ async function v(n, s, e) {
151
+ const i = (await n.listComments(s)).filter(({ body: t }) => t.startsWith(f));
153
152
  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);
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);
156
155
  }
157
156
  for (const t of i.slice(e.length))
158
157
  await n.deleteComment(t.id);
159
158
  }
160
159
  export {
161
- E as formatDryRun,
162
- y as sliceIssuePlans,
163
- k as syncDeprecationIssues,
164
- $ as synchronizeIssuePlans
160
+ T as formatDryRun,
161
+ E as sliceIssuePlans,
162
+ A as syncDeprecationIssues,
163
+ I as synchronizeIssuePlans
165
164
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/codemod",
3
- "version": "6.0.0-next.2",
3
+ "version": "6.0.0-next.4",
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.2",
15
- "@arcgis/node-toolkit": "6.0.0-next.2",
16
- "@arcgis/toolkit": "6.0.0-next.2",
14
+ "@arcgis/api-extractor": "6.0.0-next.4",
15
+ "@arcgis/node-toolkit": "6.0.0-next.4",
16
+ "@arcgis/toolkit": "6.0.0-next.4",
17
17
  "@commander-js/extra-typings": "^15.0.0",
18
18
  "commander": "^15.0.0",
19
19
  "tinyglobby": "~0.2.17",