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

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,272 @@
1
+ import l from "typescript";
2
+ import { findPath as P, asyncFindPath as y } from "@arcgis/node-toolkit/file";
3
+ import { path as p } from "@arcgis/node-toolkit/path";
4
+ import { retrievePackageJson as w, asyncRetrievePackageJson as E } from "@arcgis/node-toolkit/packageJson";
5
+ import { s as $, e as j } from "./cli.js";
6
+ import { log as v } from "@arcgis/toolkit/log";
7
+ import { realpath as k, readFile as b, readdir as M } from "node:fs/promises";
8
+ import { f as x } from "./log.js";
9
+ import { m as N } from "./classification.js";
10
+ function V(e) {
11
+ return typeof e == "string" ? e : e.map((n) => n.kind === l.SyntaxKind.JSDocText ? n.text : T(n.getText())).join("");
12
+ }
13
+ function q(e) {
14
+ return e === void 0 ? void 0 : O(l.displayPartsToString([...e]));
15
+ }
16
+ function O(e) {
17
+ return e.replace(
18
+ /\{@link(?:code|plain)?\s+([\s\S]*?)\}/gu,
19
+ (n, s) => D(s)
20
+ );
21
+ }
22
+ function T(e) {
23
+ const n = /^\{@link(?:code|plain)?\s+([\s\S]*?)\}$/u.exec(e)?.[1];
24
+ return n === void 0 ? e : D(n);
25
+ }
26
+ function D(e) {
27
+ const n = e.trim().replace(/^(\S+)\s+([/:#!.])/u, "$1$2"), s = n.indexOf("|");
28
+ if (s !== -1)
29
+ return n.slice(s + 1).trim() || n.slice(0, s).trim();
30
+ const [a, ...i] = n.split(/\s+/u);
31
+ return i.join(" ") || a;
32
+ }
33
+ function G(e, n) {
34
+ const s = P("package.json", e);
35
+ return s === void 0 ? n : w(p.dirname(s)).name ?? n;
36
+ }
37
+ const S = {
38
+ docsLegacyDependencyLocations: /* @__PURE__ */ new Map([
39
+ ["@arcgis/coding-components", "packages/coding-packages/coding-components"],
40
+ ["@arcgis/core", "packages/core-packages/core/output/npm/esm"],
41
+ ["@arcgis/lumina", "packages/support-packages/lit"],
42
+ ["@arcgis/map-components", "packages/map-packages/map-components"],
43
+ ["@arcgis/toolkit", "packages/support-packages/toolkit"],
44
+ ["@esri/calcite-components", "packages/map-packages/map-components/node_modules/@esri/calcite-components"],
45
+ ["@esri/calcite-components-react", "packages/docs/app/node_modules/@esri/calcite-components-react"],
46
+ ["monaco-editor", "packages/docs/app/node_modules/monaco-editor"]
47
+ ]),
48
+ excludedDefinitionPathFragments: ["test-package", "packages/docs/lumina-code-samples/", "packages/starter-packages/"]
49
+ };
50
+ function H(e) {
51
+ const n = /* @__PURE__ */ new Map(), s = {};
52
+ if (e?.contents.name !== "@webgis/docs")
53
+ return { packages: n, paths: s };
54
+ const a = p.dirname(e.filePath), i = p.resolve(a, "../../..");
55
+ if (p.relative(i, a) !== "packages/docs/app" || !l.sys.fileExists(p.join(i, "pnpm-workspace.yaml")))
56
+ return { packages: n, paths: s };
57
+ const o = new Set(
58
+ Object.entries({
59
+ ...e.contents.dependencies,
60
+ ...e.contents.devDependencies,
61
+ ...e.contents.peerDependencies,
62
+ ...e.contents.optionalDependencies
63
+ }).filter(([, t]) => t === "catalog:legacyStarshipDeps").map(([t]) => t)
64
+ );
65
+ if (o.size === 0)
66
+ throw Error(
67
+ "Didn't find any catalog:legacyStarshipDeps in @webgis/docs. Update special handling in @arcgis/codemod"
68
+ );
69
+ for (const t of o) {
70
+ const d = S.docsLegacyDependencyLocations.get(t);
71
+ if (d === void 0)
72
+ throw new Error(
73
+ `Unmapped legacy dependency ${t} in @webgis/docs. Update special handling in @arcgis/codemod.`
74
+ );
75
+ const c = p.join(i, d), r = p.join(c, "package.json");
76
+ if (!l.sys.fileExists(r))
77
+ throw new Error(
78
+ `Missing audit dependency ${t} at ${r}. Install dependencies and build workspace packages before auditing usages.`
79
+ );
80
+ const f = w(c);
81
+ n.set(t, r);
82
+ for (const [m, u] of Object.entries(
83
+ f.exports ?? { ".": f.types ?? "./index.d.ts", "./*": "./*" }
84
+ )) {
85
+ const h = typeof u == "string" ? u : u.types;
86
+ h !== void 0 && (s[m === "." ? t : `${t}/${m.slice(2)}`] = [p.resolve(c, h)]);
87
+ }
88
+ }
89
+ return { packages: n, paths: s };
90
+ }
91
+ function Q(e) {
92
+ return $(e) || S.excludedDefinitionPathFragments.some((n) => e.includes(n));
93
+ }
94
+ function C(e, n, s, a) {
95
+ const i = [];
96
+ for (const o of e.events ?? [])
97
+ o.deprecated !== !0 && typeof o.deprecated != "string" || i.push({
98
+ package: a,
99
+ module: n,
100
+ name: o.name,
101
+ kind: "field",
102
+ memberOf: e.name,
103
+ event: { tagName: e.tagName, name: o.name },
104
+ provenance: "manifest",
105
+ reason: typeof o.deprecated == "string" ? o.deprecated : void 0,
106
+ sourceFileName: s,
107
+ line: 1,
108
+ column: 1
109
+ });
110
+ return i;
111
+ }
112
+ function X(e, n, s, a) {
113
+ const i = e.tagName.getText(n), o = s.components.get(i);
114
+ if (o?.length === 1)
115
+ for (const t of e.attributes.properties) {
116
+ if (!l.isJsxAttribute(t))
117
+ continue;
118
+ const d = t.name.getText(n), c = o[0].definitions.find(
119
+ ({ event: r }) => r?.tagName === i && (d === `on${r.name}` || d === `on${r.name[0].toUpperCase()}${r.name.slice(1)}`)
120
+ );
121
+ c !== void 0 && a(c, t.name.getStart(n), t.name.getWidth(n));
122
+ }
123
+ }
124
+ function L(e, n, s) {
125
+ const a = JSON.parse(e), i = { modulePaths: /* @__PURE__ */ new Map(), definitions: [], components: /* @__PURE__ */ new Set() };
126
+ for (const o of a.modules) {
127
+ o.sourcePath !== void 0 && i.modulePaths.set(N(o.sourcePath), o.path);
128
+ for (const t of o.declarations ?? []) {
129
+ let d = function(r, f, m, u) {
130
+ m !== !0 && typeof m != "string" || i.definitions.push({
131
+ package: s,
132
+ module: o.path,
133
+ name: u ?? r,
134
+ kind: u === void 0 ? f : "field",
135
+ memberOf: u === void 0 ? f === "element" ? void 0 : c : t.name,
136
+ ...u === void 0 ? {} : { attribute: { tagName: c, name: r } },
137
+ provenance: "manifest",
138
+ reason: typeof m == "string" ? m : void 0,
139
+ sourceFileName: n,
140
+ line: 1,
141
+ column: 1
142
+ });
143
+ };
144
+ if (!("tagName" in t) || t.tagName === void 0)
145
+ continue;
146
+ const c = t.tagName;
147
+ i.components.add(c), d(c, "element", t.deprecated);
148
+ for (const [r, f] of [
149
+ ["cssProperties", "css-property"],
150
+ ["cssParts", "css-part"],
151
+ ["cssStates", "css-state"],
152
+ ["slots", "slot"]
153
+ ])
154
+ for (const m of t[r] ?? [])
155
+ r === "slots" && m.name === "" || d(m.name, f, m.deprecated);
156
+ for (const r of t.attributes ?? [])
157
+ d(r.name, "attribute", r.deprecated, r.fieldName);
158
+ i.definitions.push(...C(t, o.path, n, s));
159
+ }
160
+ }
161
+ return i;
162
+ }
163
+ function Y(e) {
164
+ const n = e.flatMap((o) => o.definitions), s = /* @__PURE__ */ new Map();
165
+ for (const o of e)
166
+ for (const t of o.components) {
167
+ const d = s.get(t) ?? [];
168
+ d.push(o), s.set(t, d);
169
+ }
170
+ const a = /* @__PURE__ */ new Map(), i = Map.groupBy(
171
+ n.filter(({ kind: o }) => o === "css-property"),
172
+ ({ name: o }) => o
173
+ );
174
+ for (const [o, t] of i)
175
+ new Set(t.map((d) => d.package)).size === 1 && a.set(o, t[0]);
176
+ return { hasDeprecatedApis: n.length > 0, components: s, cssVariables: a };
177
+ }
178
+ function Z(e = "warn", n) {
179
+ const s = /* @__PURE__ */ new Map();
180
+ return async (a) => {
181
+ const i = await k(a);
182
+ let o = s.get(i);
183
+ return o === void 0 && (o = J(i, n).catch((t) => {
184
+ if (n?.(), e === "throw")
185
+ throw new Error(
186
+ `Unable to read component manifest for ${i}. Build the package before auditing definitions.`,
187
+ { cause: t }
188
+ );
189
+ v("warn", x(i), `Unable to read component manifest: ${String(t)}`);
190
+ }), s.set(i, o)), await o;
191
+ };
192
+ }
193
+ async function ee(e, n, s, a) {
194
+ const i = /* @__PURE__ */ new Set([
195
+ ...Object.keys(e.contents.dependencies ?? {}),
196
+ ...Object.keys(e.contents.devDependencies ?? {}),
197
+ ...Object.keys(e.contents.peerDependencies ?? {}),
198
+ ...Object.keys(e.contents.optionalDependencies ?? {})
199
+ ]), o = await Promise.all(
200
+ [...i].filter((t) => t !== e.contents.name && (!s || j(t))).map(async (t) => {
201
+ const d = a?.get(t) ?? await y(p.join("node_modules", t, "package.json"), p.dirname(e.filePath));
202
+ if (d === void 0)
203
+ return [];
204
+ const c = await n(d), r = t === "@esri/calcite-components" ? await y(
205
+ "node_modules/@esri/calcite-design-tokens/package.json",
206
+ p.dirname(await k(d))
207
+ ) : void 0;
208
+ return [c, r === void 0 ? void 0 : await n(r)];
209
+ })
210
+ );
211
+ return [...new Set(o.flat().filter((t) => t !== void 0))];
212
+ }
213
+ async function J(e, n) {
214
+ const s = p.dirname(e), a = await E(s);
215
+ if (a.name === "@esri/calcite-design-tokens")
216
+ try {
217
+ return await A(s, a.name);
218
+ } catch (t) {
219
+ n?.(), v("error", x(s), `Calcite design tokens integration is out of date: ${String(t)}`);
220
+ return;
221
+ }
222
+ const i = typeof a.customElements == "string" ? a.customElements : a.customElements?.[0];
223
+ if (i === void 0)
224
+ return;
225
+ const o = await k(p.resolve(s, i));
226
+ return L(await b(o, "utf8"), o, a.name);
227
+ }
228
+ async function A(e, n) {
229
+ const s = p.join(e, "dist/docs"), a = /* @__PURE__ */ new Map(), i = (await M(s)).filter((o) => o.endsWith(".json")).sort();
230
+ if (i.length === 0)
231
+ throw new Error(`Missing token documentation JSON files in ${s}`);
232
+ for (const o of i) {
233
+ const t = await k(p.join(s, o)), d = JSON.parse(await b(t, "utf8"));
234
+ if (!g(d) || !Array.isArray(d.tokens))
235
+ throw new Error(`Expected a tokens array in ${t}`);
236
+ for (const c of d.tokens) {
237
+ if (!g(c) || !g(c.attributes) || c.attributes.docs !== void 0 && typeof c.attributes.docs != "string" || c.attributes.status !== void 0 && typeof c.attributes.status != "string" || !g(c.attributes.names) || typeof c.attributes.names.css != "string" || !/^var\(--[-\w]+\)$/u.test(c.attributes.names.css))
238
+ throw new Error(`Expected token attributes.docs/status and attributes.names.css in ${t}`);
239
+ if (c.attributes.docs !== "deprecated" && c.attributes.status !== "deprecated")
240
+ continue;
241
+ const r = c.$description ?? c.description;
242
+ if (typeof r != "string")
243
+ throw new Error(`Expected a deprecated token's $description or description in ${t}`);
244
+ const f = c.attributes.names.css.slice(4, -1);
245
+ a.has(f) || a.set(f, {
246
+ package: n,
247
+ name: f,
248
+ kind: "css-property",
249
+ provenance: "manifest",
250
+ reason: r,
251
+ sourceFileName: t,
252
+ line: 1,
253
+ column: 1
254
+ });
255
+ }
256
+ }
257
+ return { modulePaths: /* @__PURE__ */ new Map(), definitions: [...a.values()], components: /* @__PURE__ */ new Set() };
258
+ }
259
+ function g(e) {
260
+ return typeof e == "object" && e !== null && !Array.isArray(e);
261
+ }
262
+ export {
263
+ G as a,
264
+ V as b,
265
+ Y as c,
266
+ q as d,
267
+ Z as e,
268
+ Q as f,
269
+ H as g,
270
+ ee as l,
271
+ X as s
272
+ };
@@ -1,70 +1,81 @@
1
- import { d as f } from "./cli.js";
2
- import { o as b, q as m, r as P, s as D, c as O, a as d, b as B } from "./classification.js";
3
- const h = `<!-- ${m} -->`, J = `<!-- ${m}`, w = 65536;
4
- function Q(e) {
5
- const n = k(e, e.findings);
6
- return `${n.summary.trim().replace(/^### /u, "## ")}
1
+ import { j as D, k as P, l as K, d as w } from "./cli.js";
2
+ import { o as h, b as B, f, h as y } from "./classification.js";
3
+ import { markdownTextLimit as M, splitMarkdown as L } from "@arcgis/node-toolkit/markdown";
4
+ const $ = {
5
+ usages: "arcgisCodemodAuditUsages",
6
+ definitions: "arcgisCodemodAuditDefinitions"
7
+ };
8
+ function X(n) {
9
+ const e = j(n, n.findings);
10
+ return `${e.summary.trim().replace(/^### /u, "## ")}
7
11
 
8
- ${n.details}`;
12
+ ${e.details}`;
9
13
  }
10
- function V(e) {
11
- const n = /* @__PURE__ */ new Map();
12
- for (const o of e.findings) {
13
- const r = $(o.codeowners), i = r.join(","), t = n.get(i) ?? [];
14
- t.push({ ...o, codeowners: r }), n.set(i, t);
14
+ function Y(n, e = () => []) {
15
+ const o = /* @__PURE__ */ new Map();
16
+ for (const s of n.findings) {
17
+ const r = d(s.codeowners), t = r.join(","), i = o.get(t) ?? [];
18
+ i.push({ ...s, codeowners: r }), o.set(t, i);
15
19
  }
16
- return [...n.entries()].map(([o, r]) => {
17
- const i = o === "" ? [] : o.split(","), t = K(e, r);
20
+ return [...o.entries()].map(([s, r]) => {
21
+ const t = s === "" ? [] : s.split(","), i = T(n, r);
18
22
  return {
19
23
  changes: [],
20
- title: b[e.kind],
21
- owners: i,
22
- assignees: i.filter((s) => /^@[^/@\s]+$/u.test(s)).map((s) => s.slice(1)),
23
- chunks: v(t, w, N(i))
24
+ title: O(n.auditKind, r),
25
+ owners: t,
26
+ assignees: t.filter((c) => /^@[^/@\s]+$/u.test(c)).map((c) => c.slice(1)),
27
+ labels: e([...new Set(r.map((c) => c.file))]),
28
+ chunks: G(i, M, x(t, n.auditKind))
24
29
  };
25
- }).sort((o, r) => o.title.localeCompare(r.title));
26
- }
27
- function K(e, n) {
28
- const o = $(n.flatMap((i) => i.codeowners)).filter(
29
- (i) => /^@[^/@\s]+\/[^@\s]+$/u.test(i)
30
- ), r = o.length === 0 ? "" : `
30
+ }).sort((s, r) => s.owners.join(",").localeCompare(r.owners.join(",")));
31
+ }
32
+ function O(n, e) {
33
+ const o = [...new Set(e.map((i) => h(i.package, i.module)))].sort(
34
+ (i, c) => i.localeCompare(c)
35
+ ), s = o.slice(0, 3).join(", "), r = o.length > 3 ? ` +${o.length - 3} more` : "", t = `${D[n]}: ${s}${r}`;
36
+ return t.length > 256 ? `${t.slice(0, 253)}...` : t;
37
+ }
38
+ function T(n, e) {
39
+ const o = d(e.flatMap((r) => r.codeowners)).filter(
40
+ (r) => /^@[^/@\s]+\/[^@\s]+$/u.test(r)
41
+ ), s = o.length === 0 ? "" : `
31
42
 
32
43
  CODEOWNERS: ${o.join(", ")}`;
33
- return L(e, n, r);
44
+ return U(n, e, s);
34
45
  }
35
- function L(e, n, o) {
36
- const r = P[e.kind], i = k(e, n);
37
- return `${r}${o}${i.summary}
46
+ function U(n, e, o) {
47
+ const s = P[n.auditKind], r = j(n, e);
48
+ return `${s}${o}${r.summary}
38
49
 
39
- ${D}
50
+ ${K}
40
51
 
41
- ${i.details}`;
52
+ ${r.details}`;
42
53
  }
43
- function k(e, n) {
44
- return e.kind === "usages" ? U(e, n) : z(e, n);
54
+ function j(n, e) {
55
+ return n.auditKind === "usages" ? z(n, e) : E(n, e);
45
56
  }
46
- function U(e, n) {
47
- const o = y(n, "usages"), r = O(n, (s) => s), i = r.map(({ categoryName: s, count: c, packages: a }) => {
48
- const u = a.map(({ packageName: p, count: l }) => ` - \`${p}\`: ${l}`).join(`
57
+ function z(n, e) {
58
+ const o = I(e, "usages"), s = B(e, (i) => i), r = s.map(({ categoryName: i, count: c, packages: m }) => {
59
+ const u = m.map(({ displayName: p, count: a }) => ` - \`${p}\`: ${a}`).join(`
49
60
  `);
50
- return `- **${f[s].label}**: ${c}
61
+ return `- **${w[i].label}**: ${c}
51
62
  ${u}`;
52
63
  }).join(`
53
- `), t = r.map(({ categoryName: s, count: c, packages: a }) => {
54
- const u = a.map(({ packageName: j, count: A, apis: S }) => {
55
- const C = S.flatMap(
56
- ({ items: R }) => M(e, R, "usages", o)
64
+ `), t = s.map(({ categoryName: i, count: c, packages: m }) => {
65
+ const u = m.map(({ displayName: l, count: C, apis: v }) => {
66
+ const R = v.flatMap(
67
+ ({ items: b }) => S(n, b, "usages", o)
57
68
  );
58
- return `#### ${j} (${A})
69
+ return `#### ${l} (${C})
59
70
 
60
- ${C.join(`
71
+ ${R.join(`
61
72
  `)}`;
62
73
  }).join(`
63
74
 
64
- `), p = f[s], l = "description" in p ? `
75
+ `), p = w[i], a = "description" in p ? `
65
76
 
66
77
  ${p.description}` : "";
67
- return `### ${p.label} (${c})${l}
78
+ return `### ${p.label} (${c})${a}
68
79
 
69
80
  ${u}`;
70
81
  }).join(`
@@ -75,24 +86,27 @@ ${u}`;
75
86
 
76
87
  ### Deprecation summary
77
88
 
78
- ${i}`,
89
+ ${r}`,
79
90
  details: `## Deprecation details
80
91
 
81
92
  ${t}`
82
93
  };
83
94
  }
84
- function y(e, n) {
95
+ function I(n, e) {
85
96
  const o = /* @__PURE__ */ new Map();
86
- for (const r of e) {
87
- const i = d(r), t = o.get(i) ?? /* @__PURE__ */ new Set();
88
- t.add(`${r.package}\0${I(n, r)}`), o.set(i, t);
97
+ for (const s of n) {
98
+ const r = f(s), t = o.get(r) ?? /* @__PURE__ */ new Set();
99
+ t.add(`${s.package}\0${A(e, s)}`), o.set(r, t);
89
100
  }
90
- return new Set([...o].filter(([, r]) => r.size > 1).map(([r]) => r));
91
- }
92
- function z(e, n) {
93
- const o = y(n, "definitions");
94
- return { summary: "", details: [...Map.groupBy(n, (t) => t.package).entries()].sort(([t], [s]) => t.localeCompare(s)).map(([t, s]) => {
95
- const c = M(e, s, "definitions", o);
101
+ return new Set([...o].filter(([, s]) => s.size > 1).map(([s]) => s));
102
+ }
103
+ function E(n, e) {
104
+ const o = I(e, "definitions");
105
+ return { summary: "", details: [...Map.groupBy(
106
+ e,
107
+ (t) => h(t.package, t.module ?? g("definitions", t))
108
+ ).entries()].sort(([t], [i]) => t.localeCompare(i)).map(([t, i]) => {
109
+ const c = S(n, i, "definitions", o);
96
110
  return `#### ${t}'s deprecations
97
111
 
98
112
  ${c.join(`
@@ -101,84 +115,98 @@ ${c.join(`
101
115
 
102
116
  `) };
103
117
  }
104
- function M(e, n, o, r) {
105
- const i = [...Map.groupBy(n, (t) => I(o, t))];
106
- return o === "definitions" && i.sort(([t], [s]) => t.localeCompare(s)), i.map(([, t]) => {
107
- const s = d(t[0]), c = x(o, t[0]), a = c !== void 0 && r.has(s) ? `${c} ${s}` : s, u = T(t);
108
- return o === "usages" && u.sort((p, l) => p.localeCompare(l)), E(e, a, u, t);
118
+ function S(n, e, o, s) {
119
+ const r = [...Map.groupBy(e, (t) => A(o, t))];
120
+ return r.sort(([t], [i]) => t.localeCompare(i)), r.map(([, t]) => {
121
+ const i = f(t[0]), c = g(o, t[0]), m = c !== void 0 && s.has(i) ? `${c} ${i}` : i, u = _(t);
122
+ return u.sort((p, a) => p.localeCompare(a)), N(n, m, u, t, o);
109
123
  });
110
124
  }
111
- function E(e, n, o, r) {
112
- const i = o.length === 0 ? "" : ` - ${o.map(q).join(" ")}`, t = [
125
+ function N(n, e, o, s, r) {
126
+ const t = o.length === 0 ? "" : ` - ${o.map(q).join(" ")}`, i = [
113
127
  ...new Set(
114
- r.toSorted((a, u) => a.file.localeCompare(u.file) || a.line - u.line).map((a) => G(e.repository, e.ref, a.file, a.line))
128
+ s.filter((a) => r === "usages" || a.provenance !== "manifest").toSorted((a, l) => a.file.localeCompare(l.file) || a.line - l.line).map((a) => H(n.repository, n.ref, a.file, a.line))
115
129
  )
116
- ], s = t.length === 1 ? ` ${t[0]}` : t.map((a) => ` - ${a}`).join(`
117
- `), c = r[0].apiKind;
118
- return `- [ ] \`${n}\`${B(c)}${i}
119
- ${s}`;
130
+ ], c = i.length === 1 ? ` ${i[0]}` : i.map((a) => ` - ${a}`).join(`
131
+ `), m = s[0].kind, u = [
132
+ ...new Set(
133
+ s.filter(
134
+ (a) => r === "definitions" && a.provenance === "manifest" && a.kind === "css-property"
135
+ ).flatMap(({ memberOf: a }) => a === void 0 ? [] : [a])
136
+ )
137
+ ].sort(), p = u.length === 0 ? "" : ` (components: ${u.map((a) => `\`<${a}>\``).join(", ")})`;
138
+ return `- [ ] \`${e}\`${y(m)}${p}${t}${c === "" ? "" : `
139
+ ${c}`}`;
120
140
  }
121
- function T(e) {
141
+ function _(n) {
122
142
  return [
123
143
  ...new Set(
124
- e.map(({ reason: n }) => n).filter((n) => n !== null && n !== "")
144
+ n.map(({ deprecated: e }) => e).filter((e) => typeof e == "string" && e !== "")
125
145
  )
126
146
  ];
127
147
  }
128
- function v(e, n = w, o = h) {
129
- const r = `${o}
130
- `, i = n - r.length;
131
- if (i < 1)
148
+ function G(n, e = M, o = x([])) {
149
+ const s = `${o}
150
+ `, r = e - s.length;
151
+ if (r < 1)
132
152
  throw new Error("Issue content limit is too small for the managed marker.");
133
- const t = [];
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;
141
- }
142
- function N(e) {
143
- return e.length === 0 ? h : `<!-- ${m} ${$(e).join(",")} -->`;
144
- }
145
- function $(e) {
146
- return [...new Set(e)].sort((n, o) => n.localeCompare(o));
147
- }
148
- function I(e, n) {
149
- return `${d(n)}\0${x(e, n) ?? ""}`;
150
- }
151
- function x(e, n) {
152
- return e === "definitions" ? _(n.file) : n.module;
153
- }
154
- function _(e) {
155
- const n = "/src/", o = "/dist/", r = e.lastIndexOf(n), i = e.lastIndexOf(o), t = Math.max(r, i), s = i > r ? o : n;
156
- return (t === -1 ? e : e.slice(t + s.length)).replace(/\.(?:d\.)?(?:[cm]?ts|tsx)$/u, "");
157
- }
158
- function q(e) {
159
- const n = [], o = (t) => `\0${n.push(t) - 1}\0`, i = e.replaceAll(`\r
153
+ return L(n, r).map((t) => s + t);
154
+ }
155
+ function x(n, e = "usages") {
156
+ const o = d(n).join(",");
157
+ return `<!-- ${$[e]}${o === "" ? "" : ` owners=${o}`} -->`;
158
+ }
159
+ function Z(n) {
160
+ const e = n?.split(`
161
+ `, 1)[0];
162
+ if (e === void 0)
163
+ return;
164
+ const o = /^<!-- (\S+)(?: owners=(@[^\s,]+(?:,@[^\s,]+)*))? -->$/u.exec(e);
165
+ if (o === null)
166
+ return;
167
+ const [, s, r] = o, t = s === $.usages ? "usages" : s === $.definitions ? "definitions" : void 0;
168
+ if (t !== void 0)
169
+ return { kind: t, owners: r === void 0 ? [] : d(r.split(",")) };
170
+ }
171
+ function d(n) {
172
+ return [...new Set(n)].sort((e, o) => e.localeCompare(o));
173
+ }
174
+ function A(n, e) {
175
+ return `${f(e)}${y(e.kind)}\0${g(n, e) ?? ""}`;
176
+ }
177
+ function g(n, e) {
178
+ return n === "definitions" && e.provenance !== "manifest" ? W(e.file) : e.module;
179
+ }
180
+ function W(n) {
181
+ const e = "/src/", o = "/dist/", s = n.lastIndexOf(e), r = n.lastIndexOf(o), t = Math.max(s, r), i = r > s ? o : e;
182
+ return (t === -1 ? n : n.slice(t + i.length)).replace(/\.(?:d\.)?(?:[cm]?ts|tsx)$/u, "");
183
+ }
184
+ function q(n) {
185
+ const e = [], o = (t) => `\0${e.push(t) - 1}\0`, r = n.replaceAll(`\r
160
186
  `, `
161
187
  `).replaceAll("\r", `
162
188
  `).replace(
163
189
  /\[([^\]\n]+)\]\((https?:\/\/(?:[^()\s]|\([^()\s]*\))+?)\)/gu,
164
- (t, s, c) => o(`[${g(s)}](${c})`)
190
+ (t, i, c) => o(`[${k(i)}](${c})`)
165
191
  ).replace(/https?:\/\/[^\s<>()]+/gu, (t) => {
166
- const s = /[.,;:!?]+$/u.exec(t)?.[0] ?? "";
167
- return `${o(t.slice(0, -s.length || void 0))}${s}`;
192
+ const i = /[.,;:!?]+$/u.exec(t)?.[0] ?? "";
193
+ return `${o(t.slice(0, -i.length || void 0))}${i}`;
168
194
  });
169
- return g(i).replace(/\0(\d+)\0/gu, (t, s) => n[Number(s)]).replaceAll(`
195
+ return k(r).replace(/\0(\d+)\0/gu, (t, i) => e[Number(i)]).replaceAll(`
170
196
  `, `
171
197
  `);
172
198
  }
173
- function g(e) {
174
- return e.replace(/^(\s*)(#{1,6})(?=\s)/gmu, "$1\\$2").replace(/#(?=\d)/gu, "# ");
199
+ function k(n) {
200
+ return n.replace(/^(\s*)(#{1,6})(?=\s)/gmu, "$1\\$2").replace(/#(?=\d)/gu, "# ");
175
201
  }
176
- function G(e, n, o, r) {
177
- const i = n.split("/").map(encodeURIComponent).join("/"), t = o.split("/").map(encodeURIComponent).join("/");
178
- return `https://${e}/blob/${i}/${t}#L${r}`;
202
+ function H(n, e, o, s) {
203
+ const r = e.split("/").map(encodeURIComponent).join("/"), t = o.split("/").map(encodeURIComponent).join("/");
204
+ return `https://${n}/blob/${r}/${t}#L${s}`;
179
205
  }
180
206
  export {
181
- V as c,
182
- Q as f,
183
- J as i
207
+ $ as a,
208
+ x as b,
209
+ Y as c,
210
+ X as f,
211
+ Z as p
184
212
  };