@anarchitects/governance-adapter-typescript 0.0.1

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.
Files changed (39) hide show
  1. package/README.md +155 -0
  2. package/dist/detect-typescript-workspace.d.ts +3 -0
  3. package/dist/detect-typescript-workspace.d.ts.map +1 -0
  4. package/dist/diagnostics.d.ts +26 -0
  5. package/dist/diagnostics.d.ts.map +1 -0
  6. package/dist/import-graph.d.ts +8 -0
  7. package/dist/import-graph.d.ts.map +1 -0
  8. package/dist/index.d.ts +10 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +1637 -0
  11. package/dist/map-imports-to-projects.d.ts +8 -0
  12. package/dist/map-imports-to-projects.d.ts.map +1 -0
  13. package/dist/normalize-path-aliases.d.ts +9 -0
  14. package/dist/normalize-path-aliases.d.ts.map +1 -0
  15. package/dist/normalize-workspace-patterns.d.ts +7 -0
  16. package/dist/normalize-workspace-patterns.d.ts.map +1 -0
  17. package/dist/parse-imports.d.ts +11 -0
  18. package/dist/parse-imports.d.ts.map +1 -0
  19. package/dist/parse-package-manager-workspace.d.ts +3 -0
  20. package/dist/parse-package-manager-workspace.d.ts.map +1 -0
  21. package/dist/parse-tsconfig.d.ts +3 -0
  22. package/dist/parse-tsconfig.d.ts.map +1 -0
  23. package/dist/project-discovery.d.ts +3 -0
  24. package/dist/project-discovery.d.ts.map +1 -0
  25. package/dist/project-naming.d.ts +9 -0
  26. package/dist/project-naming.d.ts.map +1 -0
  27. package/dist/resolve-tsconfig-extends.d.ts +13 -0
  28. package/dist/resolve-tsconfig-extends.d.ts.map +1 -0
  29. package/dist/resolve-workspace-packages.d.ts +2 -0
  30. package/dist/resolve-workspace-packages.d.ts.map +1 -0
  31. package/dist/source-file-discovery.d.ts +4 -0
  32. package/dist/source-file-discovery.d.ts.map +1 -0
  33. package/dist/tag-mapping.d.ts +10 -0
  34. package/dist/tag-mapping.d.ts.map +1 -0
  35. package/dist/types.d.ts +70 -0
  36. package/dist/types.d.ts.map +1 -0
  37. package/dist/workspace-adapter.d.ts +22 -0
  38. package/dist/workspace-adapter.d.ts.map +1 -0
  39. package/package.json +60 -0
package/dist/index.js ADDED
@@ -0,0 +1,1637 @@
1
+ import { existsSync as m, readFileSync as k, readdirSync as q } from "node:fs";
2
+ import p from "node:path";
3
+ import * as g from "typescript";
4
+ import { parseDocument as ie } from "yaml";
5
+ import { minimatch as H } from "minimatch";
6
+ const f = "governance.typescript_adapter";
7
+ function D(t) {
8
+ return {
9
+ code: "governance.typescript_adapter.invalid_package_json",
10
+ message: `Failed to parse package.json file "${t}".`,
11
+ source: f,
12
+ path: "/package.json"
13
+ };
14
+ }
15
+ function ce(t) {
16
+ return {
17
+ code: "governance.typescript_adapter.partial_workspace_detection",
18
+ message: "Repository has TypeScript or JavaScript indicators but no explicit workspace-manager indicator.",
19
+ source: f,
20
+ details: {
21
+ detectedIndicators: Pe(t)
22
+ }
23
+ };
24
+ }
25
+ function pe() {
26
+ return {
27
+ code: "governance.typescript_adapter.no_workspace_indicators",
28
+ message: "Repository does not contain supported TypeScript or JavaScript workspace indicators.",
29
+ source: f
30
+ };
31
+ }
32
+ function $(t, e) {
33
+ return {
34
+ code: "governance.typescript_adapter.invalid_workspace_config",
35
+ message: e,
36
+ source: f,
37
+ path: t
38
+ };
39
+ }
40
+ function b(t, e) {
41
+ return {
42
+ code: "governance.typescript_adapter.unsupported_workspace_format",
43
+ message: e,
44
+ source: f,
45
+ path: t
46
+ };
47
+ }
48
+ function ue(t) {
49
+ return {
50
+ code: "governance.typescript_adapter.no_workspace_packages_found",
51
+ message: "Workspace patterns did not resolve to any package roots.",
52
+ source: f,
53
+ details: {
54
+ patterns: [...t]
55
+ }
56
+ };
57
+ }
58
+ function S(t, e) {
59
+ return {
60
+ code: "governance.typescript_adapter.invalid_tsconfig",
61
+ message: e,
62
+ source: f,
63
+ path: t
64
+ };
65
+ }
66
+ function x(t, e) {
67
+ return {
68
+ code: "governance.typescript_adapter.invalid_tsconfig_extends",
69
+ message: e,
70
+ source: f,
71
+ path: t
72
+ };
73
+ }
74
+ function le(t, e) {
75
+ return {
76
+ code: "governance.typescript_adapter.circular_tsconfig_extends",
77
+ message: "Circular tsconfig extends chain detected.",
78
+ source: f,
79
+ path: t,
80
+ details: {
81
+ chain: [...e]
82
+ }
83
+ };
84
+ }
85
+ function z(t, e) {
86
+ return {
87
+ code: "governance.typescript_adapter.invalid_path_alias",
88
+ message: e,
89
+ source: f,
90
+ path: t
91
+ };
92
+ }
93
+ function A(t, e) {
94
+ return {
95
+ code: "governance.typescript_adapter.invalid_discovery_pattern",
96
+ message: e,
97
+ source: f,
98
+ path: t
99
+ };
100
+ }
101
+ function de(t, e) {
102
+ return {
103
+ code: "governance.typescript_adapter.discovery_pattern_no_matches",
104
+ message: `Discovery pattern "${t}" did not match any package roots.`,
105
+ source: f,
106
+ path: e
107
+ };
108
+ }
109
+ function fe(t, e) {
110
+ return {
111
+ code: "governance.typescript_adapter.duplicate_project_root",
112
+ message: `Duplicate discovered project root "${t}" is not allowed.`,
113
+ source: f,
114
+ path: e
115
+ };
116
+ }
117
+ function ge(t, e) {
118
+ return {
119
+ code: "governance.typescript_adapter.duplicate_project_name",
120
+ message: `Duplicate discovered project name "${t}" is not allowed.`,
121
+ source: f,
122
+ path: e
123
+ };
124
+ }
125
+ function O(t, e) {
126
+ return {
127
+ code: "governance.typescript_adapter.invalid_tag_template",
128
+ message: e,
129
+ source: f,
130
+ path: t
131
+ };
132
+ }
133
+ function me(t, e) {
134
+ return {
135
+ code: "governance.typescript_adapter.invalid_project_name_template",
136
+ message: e,
137
+ source: f,
138
+ path: t
139
+ };
140
+ }
141
+ function he(t, e) {
142
+ return {
143
+ code: "governance.typescript_adapter.source_file_parse_error",
144
+ message: e,
145
+ source: f,
146
+ path: t
147
+ };
148
+ }
149
+ function L(t, e) {
150
+ return {
151
+ code: "governance.typescript_adapter.unresolved_import",
152
+ message: e,
153
+ source: f,
154
+ path: t
155
+ };
156
+ }
157
+ function ve(t) {
158
+ return {
159
+ code: "governance.typescript_adapter.non_literal_dynamic_import",
160
+ message: "Dynamic import specifier must be a string literal for deterministic analysis.",
161
+ source: f,
162
+ path: t
163
+ };
164
+ }
165
+ function ye(t, e) {
166
+ return {
167
+ code: "governance.typescript_adapter.unsupported_import_syntax",
168
+ message: e,
169
+ source: f,
170
+ path: t
171
+ };
172
+ }
173
+ function ke(t, e) {
174
+ return {
175
+ code: "governance.typescript_adapter.source_file_outside_project",
176
+ message: `Source file "${e}" does not belong to a discovered project.`,
177
+ source: f,
178
+ path: t
179
+ };
180
+ }
181
+ function U(t, e) {
182
+ return {
183
+ code: "governance.typescript_adapter.resolved_import_outside_project",
184
+ message: `Resolved import file "${e}" does not belong to a discovered project.`,
185
+ source: f,
186
+ path: t
187
+ };
188
+ }
189
+ function je(t, e, r) {
190
+ return {
191
+ code: "governance.typescript_adapter.unresolved_internal_import",
192
+ message: `Internal import specifier "${r}" from "${e}" could not be mapped to a discovered project.`,
193
+ source: f,
194
+ path: t
195
+ };
196
+ }
197
+ function w(t, e, r) {
198
+ return {
199
+ code: "governance.typescript_adapter.ambiguous_project_match",
200
+ message: `File "${e}" matched multiple discovered projects.`,
201
+ source: f,
202
+ path: t,
203
+ details: {
204
+ projectIds: [...r]
205
+ }
206
+ };
207
+ }
208
+ function Pe(t) {
209
+ const e = [];
210
+ return t.packageJson && e.push("packageJson"), t.pnpmWorkspace && e.push("pnpmWorkspace"), t.packageManagerWorkspaces && e.push("packageManagerWorkspaces"), t.tsconfig && e.push("tsconfig"), t.tsconfigBase && e.push("tsconfigBase"), e;
211
+ }
212
+ function _e(t) {
213
+ const e = p.resolve(t), r = p.join(e, "package.json"), n = p.join(e, "pnpm-workspace.yaml"), o = p.join(e, "tsconfig.json"), i = p.join(e, "tsconfig.base.json"), s = {
214
+ packageJson: m(r),
215
+ pnpmWorkspace: m(n),
216
+ packageManagerWorkspaces: !1,
217
+ tsconfig: m(o),
218
+ tsconfigBase: m(i)
219
+ }, a = [];
220
+ let c = !1;
221
+ if (s.packageJson) {
222
+ const d = Se(r);
223
+ d ? (c = !0, s.packageManagerWorkspaces = $e(
224
+ d.workspaces
225
+ )) : a.push(D(r));
226
+ }
227
+ const u = be({
228
+ hasExplicitWorkspaceIndicator: s.pnpmWorkspace || s.packageManagerWorkspaces,
229
+ hasPartialWorkspaceIndicator: c || s.tsconfig || s.tsconfigBase
230
+ });
231
+ return u === "partial" && a.push(ce(s)), u === "unsupported" && a.push(pe()), {
232
+ status: u,
233
+ supported: u !== "unsupported",
234
+ workspaceRoot: e,
235
+ indicators: s,
236
+ diagnostics: a
237
+ };
238
+ }
239
+ function Se(t) {
240
+ try {
241
+ const e = JSON.parse(k(t, "utf8"));
242
+ return Q(e);
243
+ } catch {
244
+ return;
245
+ }
246
+ }
247
+ function $e(t) {
248
+ if (Array.isArray(t))
249
+ return t.length > 0 && t.every(G);
250
+ const e = Q(t);
251
+ return e ? Array.isArray(e.packages) && e.packages.length > 0 && e.packages.every(G) : !1;
252
+ }
253
+ function be({
254
+ hasExplicitWorkspaceIndicator: t,
255
+ hasPartialWorkspaceIndicator: e
256
+ }) {
257
+ return t ? "supported" : e ? "partial" : "unsupported";
258
+ }
259
+ function Q(t) {
260
+ return typeof t == "object" && t !== null && !Array.isArray(t) ? t : void 0;
261
+ }
262
+ function G(t) {
263
+ return typeof t == "string" && t.trim().length > 0;
264
+ }
265
+ function We(t, e) {
266
+ const r = g.createSourceFile(
267
+ e,
268
+ t,
269
+ g.ScriptTarget.Latest,
270
+ !0,
271
+ Ae(e)
272
+ ), n = [], o = [], i = r.parseDiagnostics ?? [];
273
+ return o.push(
274
+ ...i.map(
275
+ (a) => he(
276
+ T(e),
277
+ `Failed to parse source file "${e}": ${g.flattenDiagnosticMessageText(
278
+ a.messageText,
279
+ `
280
+ `
281
+ )}`
282
+ )
283
+ )
284
+ ), s(r), {
285
+ imports: n.sort((a, c) => a.specifier.localeCompare(c.specifier) || a.kind.localeCompare(c.kind)),
286
+ diagnostics: o
287
+ };
288
+ function s(a) {
289
+ if (g.isImportDeclaration(a) && a.moduleSpecifier && g.isStringLiteralLike(a.moduleSpecifier)) {
290
+ n.push({
291
+ specifier: a.moduleSpecifier.text,
292
+ kind: "static-import"
293
+ });
294
+ return;
295
+ }
296
+ if (g.isExportDeclaration(a) && a.moduleSpecifier && g.isStringLiteralLike(a.moduleSpecifier)) {
297
+ n.push({
298
+ specifier: a.moduleSpecifier.text,
299
+ kind: "re-export"
300
+ });
301
+ return;
302
+ }
303
+ if (g.isImportEqualsDeclaration(a) && g.isExternalModuleReference(a.moduleReference)) {
304
+ o.push(
305
+ ye(
306
+ T(e),
307
+ `Import-equals syntax is not supported for deterministic analysis in "${e}".`
308
+ )
309
+ );
310
+ return;
311
+ }
312
+ if (g.isCallExpression(a) && a.expression.kind === g.SyntaxKind.ImportKeyword) {
313
+ const c = xe(a, e);
314
+ n.push(...c.imports), o.push(...c.diagnostics);
315
+ return;
316
+ }
317
+ g.forEachChild(a, s);
318
+ }
319
+ }
320
+ function xe(t, e) {
321
+ const [r] = t.arguments;
322
+ return r && g.isStringLiteralLike(r) ? {
323
+ imports: [
324
+ {
325
+ specifier: r.text,
326
+ kind: "dynamic-import"
327
+ }
328
+ ],
329
+ diagnostics: []
330
+ } : {
331
+ imports: [],
332
+ diagnostics: [ve(T(e))]
333
+ };
334
+ }
335
+ function Ae(t) {
336
+ return t.endsWith(".tsx") ? g.ScriptKind.TSX : t.endsWith(".jsx") ? g.ScriptKind.JSX : t.endsWith(".js") ? g.ScriptKind.JS : g.ScriptKind.TS;
337
+ }
338
+ function T(t) {
339
+ return `/${Ce(t)}`;
340
+ }
341
+ function Ce(t) {
342
+ return t.replaceAll("~", "~0").replaceAll("/", "~1");
343
+ }
344
+ const Fe = /* @__PURE__ */ new Set([".ts", ".tsx", ".js", ".jsx"]), De = /* @__PURE__ */ new Set([
345
+ "build",
346
+ "coverage",
347
+ "dist",
348
+ "node_modules",
349
+ "out"
350
+ ]);
351
+ function we(t, e) {
352
+ const r = [], n = /* @__PURE__ */ new Set(), o = [...e].sort(
353
+ (i, s) => (i.root ?? "").localeCompare(s.root ?? "") || (i.name ?? i.id).localeCompare(s.name ?? s.id)
354
+ );
355
+ for (const i of o) {
356
+ if (!i.root)
357
+ continue;
358
+ const s = p.resolve(t, i.root);
359
+ m(s) && Z({
360
+ workspaceRoot: t,
361
+ currentDirectory: s,
362
+ projectName: i.name ?? i.id,
363
+ files: r,
364
+ seenFiles: n
365
+ });
366
+ }
367
+ return r.sort(
368
+ (i, s) => i.filePath.localeCompare(s.filePath)
369
+ );
370
+ }
371
+ function Z({
372
+ workspaceRoot: t,
373
+ currentDirectory: e,
374
+ projectName: r,
375
+ files: n,
376
+ seenFiles: o
377
+ }) {
378
+ const i = q(e, {
379
+ withFileTypes: !0
380
+ }).sort((s, a) => s.name.localeCompare(a.name));
381
+ for (const s of i) {
382
+ if (s.isDirectory()) {
383
+ if (De.has(s.name))
384
+ continue;
385
+ Z({
386
+ workspaceRoot: t,
387
+ currentDirectory: p.join(e, s.name),
388
+ projectName: r,
389
+ files: n,
390
+ seenFiles: o
391
+ });
392
+ continue;
393
+ }
394
+ if (!s.isFile() || !Te(s.name))
395
+ continue;
396
+ const a = p.join(e, s.name), c = Ie(
397
+ t,
398
+ a
399
+ );
400
+ o.has(c) || (o.add(c), n.push({
401
+ filePath: c,
402
+ projectName: r
403
+ }));
404
+ }
405
+ }
406
+ function Te(t) {
407
+ return t.endsWith(".d.ts") ? !1 : Fe.has(p.extname(t).toLowerCase());
408
+ }
409
+ function Ie(t, e) {
410
+ return p.relative(t, e).split(p.sep).join("/");
411
+ }
412
+ const K = [".ts", ".tsx", ".js", ".jsx"];
413
+ function Re(t) {
414
+ const e = p.resolve(t.workspaceRoot), r = we(e, t.projects), n = [], o = [];
415
+ for (const i of r) {
416
+ const s = p.resolve(e, i.filePath), a = k(s, "utf8"), c = We(a, i.filePath);
417
+ n.push(...c.diagnostics);
418
+ for (let u = 0; u < c.imports.length; u += 1) {
419
+ const d = c.imports[u], l = Ee({
420
+ workspaceRoot: e,
421
+ sourceFile: i.filePath,
422
+ specifier: d.specifier,
423
+ tsconfig: t.tsconfig
424
+ });
425
+ n.push(...l.diagnostics), o.push({
426
+ sourceFile: i.filePath,
427
+ specifier: d.specifier,
428
+ kind: d.kind,
429
+ external: l.external,
430
+ ...l.resolvedFile ? { resolvedFile: l.resolvedFile } : {}
431
+ });
432
+ }
433
+ }
434
+ return {
435
+ workspaceRoot: e,
436
+ files: Le(r),
437
+ imports: Ue(o),
438
+ diagnostics: n
439
+ };
440
+ }
441
+ function Ee({
442
+ workspaceRoot: t,
443
+ sourceFile: e,
444
+ specifier: r,
445
+ tsconfig: n
446
+ }) {
447
+ if (Ge(r) || r.startsWith("/")) {
448
+ const s = Ne(
449
+ t,
450
+ e,
451
+ r
452
+ );
453
+ return s ? { resolvedFile: s, external: !1, diagnostics: [] } : {
454
+ external: !1,
455
+ diagnostics: [
456
+ L(
457
+ B(e, r),
458
+ `Import specifier "${r}" from "${e}" could not be resolved.`
459
+ )
460
+ ]
461
+ };
462
+ }
463
+ const o = Oe(
464
+ t,
465
+ r,
466
+ n
467
+ );
468
+ if (o.matched)
469
+ return o.resolvedFile ? {
470
+ resolvedFile: o.resolvedFile,
471
+ external: !1,
472
+ diagnostics: []
473
+ } : {
474
+ external: !1,
475
+ diagnostics: [
476
+ L(
477
+ B(e, r),
478
+ `Import specifier "${r}" from "${e}" could not be resolved.`
479
+ )
480
+ ]
481
+ };
482
+ const i = Je(
483
+ t,
484
+ r,
485
+ n
486
+ );
487
+ return i ? {
488
+ resolvedFile: i,
489
+ external: !1,
490
+ diagnostics: []
491
+ } : {
492
+ external: !0,
493
+ diagnostics: []
494
+ };
495
+ }
496
+ function Ne(t, e, r) {
497
+ const n = p.dirname(p.resolve(t, e)), o = p.resolve(n, r);
498
+ return J(t, o);
499
+ }
500
+ function Oe(t, e, r) {
501
+ if (!r)
502
+ return { matched: !1 };
503
+ const n = Object.entries(r.pathAliases).sort(
504
+ ([o], [i]) => {
505
+ const s = o.includes("*"), a = i.includes("*");
506
+ return s !== a ? s ? 1 : -1 : i.length - o.length || o.localeCompare(i);
507
+ }
508
+ );
509
+ for (const [o, i] of n) {
510
+ const s = Me(o, e);
511
+ if (s !== void 0) {
512
+ for (const a of i) {
513
+ const c = a.includes("*") ? a.replaceAll("*", s) : a, u = J(
514
+ t,
515
+ p.resolve(t, c)
516
+ );
517
+ if (u)
518
+ return {
519
+ matched: !0,
520
+ resolvedFile: u
521
+ };
522
+ }
523
+ return { matched: !0 };
524
+ }
525
+ }
526
+ return { matched: !1 };
527
+ }
528
+ function Je(t, e, r) {
529
+ if (r?.baseUrl)
530
+ return J(
531
+ t,
532
+ p.resolve(t, r.baseUrl, e)
533
+ );
534
+ }
535
+ function Me(t, e) {
536
+ if (!t.includes("*"))
537
+ return t === e ? "" : void 0;
538
+ const [r, n] = t.split("*");
539
+ if (!(!e.startsWith(r) || !e.endsWith(n)))
540
+ return e.slice(r.length, e.length - n.length);
541
+ }
542
+ function J(t, e) {
543
+ const r = ze(e);
544
+ for (const n of r)
545
+ if (m(n) && !n.endsWith(".d.ts"))
546
+ return Ke(t, n);
547
+ }
548
+ function ze(t) {
549
+ const e = [t];
550
+ if (p.extname(t))
551
+ return e;
552
+ for (const r of K)
553
+ e.push(`${t}${r}`);
554
+ for (const r of K)
555
+ e.push(p.join(t, `index${r}`));
556
+ return e;
557
+ }
558
+ function Le(t) {
559
+ return [...t].sort(
560
+ (e, r) => e.filePath.localeCompare(r.filePath) || (e.projectName ?? "").localeCompare(r.projectName ?? "")
561
+ );
562
+ }
563
+ function Ue(t) {
564
+ return [...t].sort((e, r) => e.sourceFile.localeCompare(r.sourceFile) || e.specifier.localeCompare(r.specifier) || e.kind.localeCompare(r.kind) || (e.resolvedFile ?? "").localeCompare(r.resolvedFile ?? "") || Number(e.external) - Number(r.external));
565
+ }
566
+ function Ge(t) {
567
+ return t.startsWith("./") || t.startsWith("../");
568
+ }
569
+ function Ke(t, e) {
570
+ return p.relative(t, e).split(p.sep).join("/");
571
+ }
572
+ function B(t, e) {
573
+ return `/${V(t)}/imports/${V(
574
+ e
575
+ )}`;
576
+ }
577
+ function V(t) {
578
+ return t.replaceAll("~", "~0").replaceAll("/", "~1");
579
+ }
580
+ function Be(t) {
581
+ const e = p.resolve(t.workspaceRoot), r = [], n = [], o = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Map(), s = Xe(
582
+ e,
583
+ t.projects
584
+ );
585
+ for (const a of t.importGraph.files) {
586
+ const c = I(a.filePath, t.projects);
587
+ i.set(a.filePath, c), c.status === "outside" ? r.push(
588
+ ke(
589
+ X(a.filePath),
590
+ a.filePath
591
+ )
592
+ ) : c.status === "ambiguous" && r.push(
593
+ w(
594
+ X(a.filePath),
595
+ a.filePath,
596
+ c.projects.map((u) => u.id)
597
+ )
598
+ );
599
+ }
600
+ for (const a of t.importGraph.imports) {
601
+ const c = i.get(a.sourceFile) ?? I(a.sourceFile, t.projects);
602
+ if (c.status !== "matched")
603
+ continue;
604
+ const u = Ve({
605
+ workspaceRoot: e,
606
+ edge: a,
607
+ projects: t.projects,
608
+ packageNameToProject: s,
609
+ diagnostics: r
610
+ });
611
+ if (!u || u.id === c.project.id)
612
+ continue;
613
+ const d = He(
614
+ c.project.id,
615
+ u.id,
616
+ a
617
+ ), l = [
618
+ d.sourceProjectId,
619
+ d.targetProjectId,
620
+ d.type ?? "unknown"
621
+ ].join("::");
622
+ o.has(l) || (o.add(l), n.push(d));
623
+ }
624
+ return {
625
+ dependencies: n.sort((a, c) => a.sourceProjectId.localeCompare(c.sourceProjectId) || a.targetProjectId.localeCompare(c.targetProjectId) || (a.type ?? "").localeCompare(c.type ?? "") || (a.sourceFile ?? "").localeCompare(c.sourceFile ?? "")),
626
+ diagnostics: r
627
+ };
628
+ }
629
+ function Ve({
630
+ workspaceRoot: t,
631
+ edge: e,
632
+ projects: r,
633
+ packageNameToProject: n,
634
+ diagnostics: o
635
+ }) {
636
+ if (e.resolvedFile) {
637
+ const c = I(e.resolvedFile, r);
638
+ if (c.status === "matched")
639
+ return c.project;
640
+ if (c.status === "outside") {
641
+ o.push(
642
+ U(
643
+ _(e.sourceFile, e.specifier),
644
+ e.resolvedFile
645
+ )
646
+ );
647
+ return;
648
+ }
649
+ o.push(
650
+ w(
651
+ _(e.sourceFile, e.specifier),
652
+ e.resolvedFile,
653
+ c.projects.map((u) => u.id)
654
+ )
655
+ );
656
+ return;
657
+ }
658
+ if (!e.external) {
659
+ o.push(
660
+ je(
661
+ _(e.sourceFile, e.specifier),
662
+ e.sourceFile,
663
+ e.specifier
664
+ )
665
+ );
666
+ return;
667
+ }
668
+ const i = qe(e.specifier);
669
+ if (!i)
670
+ return;
671
+ const s = n.get(i) ?? [];
672
+ if (s.length === 0)
673
+ return;
674
+ if (s.length > 1) {
675
+ o.push(
676
+ w(
677
+ _(e.sourceFile, e.specifier),
678
+ e.specifier,
679
+ s.map((c) => c.id)
680
+ )
681
+ );
682
+ return;
683
+ }
684
+ const [a] = s;
685
+ if (!a.root || !m(p.resolve(t, a.root))) {
686
+ o.push(
687
+ U(
688
+ _(e.sourceFile, e.specifier),
689
+ e.specifier
690
+ )
691
+ );
692
+ return;
693
+ }
694
+ return a;
695
+ }
696
+ function I(t, e) {
697
+ const r = j(t), n = e.filter((o) => {
698
+ const i = j(o.root ?? "");
699
+ return i.length > 0 && Qe(r, i);
700
+ }).sort((o, i) => {
701
+ const s = j(o.root ?? ""), a = j(i.root ?? "");
702
+ return a.length - s.length || s.localeCompare(a) || o.id.localeCompare(i.id);
703
+ });
704
+ return n.length === 0 ? { status: "outside" } : n.length > 1 ? { status: "ambiguous", projects: n } : { status: "matched", project: n[0] };
705
+ }
706
+ function Xe(t, e) {
707
+ const r = /* @__PURE__ */ new Map(), n = [...e].sort((o, i) => {
708
+ const s = j(o.root ?? ""), a = j(i.root ?? "");
709
+ return s.localeCompare(a) || o.id.localeCompare(i.id);
710
+ });
711
+ for (const o of n) {
712
+ const i = o.root ? p.resolve(t, o.root) : void 0;
713
+ if (!i)
714
+ continue;
715
+ const s = p.join(i, "package.json");
716
+ if (!m(s))
717
+ continue;
718
+ const a = Ye(s);
719
+ if (!a)
720
+ continue;
721
+ const c = r.get(a) ?? [];
722
+ c.push(o), r.set(a, c);
723
+ }
724
+ return r;
725
+ }
726
+ function Ye(t) {
727
+ try {
728
+ const e = JSON.parse(k(t, "utf8"));
729
+ if (typeof e != "object" || e === null || Array.isArray(e) || typeof e.name != "string")
730
+ return;
731
+ const r = e.name.trim();
732
+ return r.length > 0 ? r : void 0;
733
+ } catch {
734
+ return;
735
+ }
736
+ }
737
+ function qe(t) {
738
+ const e = t.split("/");
739
+ return t.startsWith("@") ? e.length >= 2 ? `${e[0]}/${e[1]}` : void 0 : e[0] || void 0;
740
+ }
741
+ function He(t, e, r) {
742
+ return {
743
+ sourceProjectId: t,
744
+ targetProjectId: e,
745
+ type: r.kind === "dynamic-import" ? "dynamic" : "static",
746
+ sourceFile: r.sourceFile
747
+ };
748
+ }
749
+ function Qe(t, e) {
750
+ return t === e || t.startsWith(`${e}/`);
751
+ }
752
+ function j(t) {
753
+ return t.replaceAll("\\", "/").replace(/^\.\/+/u, "").replace(/\/{2,}/gu, "/");
754
+ }
755
+ function X(t) {
756
+ return `/${R(t)}`;
757
+ }
758
+ function _(t, e) {
759
+ return `/${R(t)}/imports/${R(
760
+ e
761
+ )}`;
762
+ }
763
+ function R(t) {
764
+ return t.replaceAll("~", "~0").replaceAll("/", "~1");
765
+ }
766
+ function E(t, e) {
767
+ const r = [], n = [], o = /* @__PURE__ */ new Set();
768
+ return t.forEach((i, s) => {
769
+ const a = `${e}/${s}`;
770
+ if (typeof i != "string") {
771
+ n.push(
772
+ $(
773
+ a,
774
+ "Workspace pattern must be a non-empty string."
775
+ )
776
+ );
777
+ return;
778
+ }
779
+ const c = Ze(i);
780
+ if (!c) {
781
+ n.push(
782
+ $(
783
+ a,
784
+ "Workspace pattern must be a non-empty string."
785
+ )
786
+ );
787
+ return;
788
+ }
789
+ o.has(c) || (o.add(c), r.push(c));
790
+ }), {
791
+ patterns: r,
792
+ diagnostics: n
793
+ };
794
+ }
795
+ function Ze(t) {
796
+ let e = t.trim().replaceAll("\\", "/");
797
+ for (; e.startsWith("./"); )
798
+ e = e.slice(2);
799
+ for (e = e.replace(/\/{2,}/g, "/"); e.length > 1 && e.endsWith("/"); )
800
+ e = e.slice(0, -1);
801
+ if (e.length !== 0)
802
+ return e;
803
+ }
804
+ const et = /* @__PURE__ */ new Set([
805
+ ".git",
806
+ ".nx",
807
+ ".yarn",
808
+ "node_modules"
809
+ ]);
810
+ function tt(t, e) {
811
+ const r = rt(t), n = [], o = /* @__PURE__ */ new Set();
812
+ for (const i of e)
813
+ for (const s of r)
814
+ H(s, i, {
815
+ dot: !0,
816
+ nocase: !1
817
+ }) && !o.has(s) && (o.add(s), n.push(s));
818
+ return n;
819
+ }
820
+ function rt(t) {
821
+ const e = [];
822
+ return ee(t, t, e), e.sort((r, n) => r.localeCompare(n));
823
+ }
824
+ function ee(t, e, r) {
825
+ m(p.join(e, "package.json")) && r.push(nt(t, e));
826
+ const n = q(e, {
827
+ withFileTypes: !0
828
+ }).sort((o, i) => o.name.localeCompare(i.name));
829
+ for (const o of n)
830
+ !o.isDirectory() || et.has(o.name) || ee(
831
+ t,
832
+ p.join(e, o.name),
833
+ r
834
+ );
835
+ }
836
+ function nt(t, e) {
837
+ const r = p.relative(t, e);
838
+ return r ? r.split(p.sep).join("/") : ".";
839
+ }
840
+ function ot(t) {
841
+ const e = p.resolve(t), r = p.join(e, "pnpm-workspace.yaml"), n = p.join(e, "package.json");
842
+ return m(r) ? st(e, r) : m(n) ? at(e, n) : {
843
+ workspaceRoot: e,
844
+ patterns: [],
845
+ packageRoots: [],
846
+ diagnostics: [
847
+ b(
848
+ "/",
849
+ "Repository does not contain a supported package-manager workspace configuration."
850
+ )
851
+ ]
852
+ };
853
+ }
854
+ function st(t, e) {
855
+ const r = [], n = it(e, r);
856
+ if (!n)
857
+ return {
858
+ packageManager: "pnpm",
859
+ workspaceRoot: t,
860
+ patterns: [],
861
+ packageRoots: [],
862
+ diagnostics: r
863
+ };
864
+ const o = pt(n, r);
865
+ return te({
866
+ packageManager: "pnpm",
867
+ workspaceRoot: t,
868
+ patterns: o,
869
+ diagnostics: r
870
+ });
871
+ }
872
+ function at(t, e) {
873
+ const r = [], n = ct(e, r);
874
+ if (!n)
875
+ return {
876
+ workspaceRoot: t,
877
+ patterns: [],
878
+ packageRoots: [],
879
+ diagnostics: r
880
+ };
881
+ const o = lt(
882
+ t,
883
+ n
884
+ ), i = ut(n, r);
885
+ return te({
886
+ packageManager: o,
887
+ workspaceRoot: t,
888
+ patterns: i,
889
+ diagnostics: r
890
+ });
891
+ }
892
+ function te({
893
+ packageManager: t,
894
+ workspaceRoot: e,
895
+ patterns: r,
896
+ diagnostics: n
897
+ }) {
898
+ const o = r.length > 0 ? tt(e, r) : [];
899
+ return r.length > 0 && o.length === 0 && n.push(ue(r)), {
900
+ packageManager: t,
901
+ workspaceRoot: e,
902
+ patterns: r,
903
+ packageRoots: o,
904
+ diagnostics: n
905
+ };
906
+ }
907
+ function it(t, e) {
908
+ try {
909
+ const r = ie(k(t, "utf8"), {
910
+ merge: !1,
911
+ strict: !0,
912
+ uniqueKeys: !1
913
+ });
914
+ if (r.errors.length > 0) {
915
+ e.push(
916
+ $(
917
+ "/pnpm-workspace.yaml",
918
+ `Failed to parse pnpm workspace file "${t}".`
919
+ )
920
+ );
921
+ return;
922
+ }
923
+ return M(r.toJS());
924
+ } catch {
925
+ e.push(
926
+ $(
927
+ "/pnpm-workspace.yaml",
928
+ `Failed to parse pnpm workspace file "${t}".`
929
+ )
930
+ );
931
+ return;
932
+ }
933
+ }
934
+ function ct(t, e) {
935
+ try {
936
+ const r = JSON.parse(k(t, "utf8")), n = M(r);
937
+ if (!n) {
938
+ e.push(D(t));
939
+ return;
940
+ }
941
+ return n;
942
+ } catch {
943
+ e.push(D(t));
944
+ return;
945
+ }
946
+ }
947
+ function pt(t, e) {
948
+ if (!("packages" in t))
949
+ return e.push(
950
+ b(
951
+ "/packages",
952
+ 'pnpm-workspace.yaml must define a "packages" array.'
953
+ )
954
+ ), [];
955
+ if (!Array.isArray(t.packages))
956
+ return e.push(
957
+ $(
958
+ "/packages",
959
+ 'pnpm workspace "packages" must be an array of patterns.'
960
+ )
961
+ ), [];
962
+ const r = E(
963
+ t.packages,
964
+ "/packages"
965
+ );
966
+ return e.push(...r.diagnostics), r.patterns;
967
+ }
968
+ function ut(t, e) {
969
+ const r = t.workspaces;
970
+ if (Array.isArray(r)) {
971
+ const i = E(r, "/workspaces");
972
+ return e.push(...i.diagnostics), i.patterns;
973
+ }
974
+ const n = M(r);
975
+ if (!n)
976
+ return e.push(
977
+ b(
978
+ "/workspaces",
979
+ 'package.json must define "workspaces" as an array or as an object with a "packages" array.'
980
+ )
981
+ ), [];
982
+ if (!Array.isArray(n.packages))
983
+ return e.push(
984
+ b(
985
+ "/workspaces",
986
+ 'package.json object-style workspaces must define a "packages" array.'
987
+ )
988
+ ), [];
989
+ const o = E(
990
+ n.packages,
991
+ "/workspaces/packages"
992
+ );
993
+ return e.push(...o.diagnostics), o.patterns;
994
+ }
995
+ function lt(t, e) {
996
+ return typeof e.packageManager == "string" && e.packageManager.trim().toLowerCase().startsWith("yarn@") || m(p.join(t, "yarn.lock")) ? "yarn" : "npm";
997
+ }
998
+ function M(t) {
999
+ return typeof t == "object" && t !== null && !Array.isArray(t) ? t : void 0;
1000
+ }
1001
+ function dt(t, e, r) {
1002
+ const n = [...r], o = /* @__PURE__ */ new Map();
1003
+ let i;
1004
+ for (const s of e) {
1005
+ const a = Y(s.value.compilerOptions);
1006
+ if (s.value.compilerOptions !== void 0 && a === void 0) {
1007
+ n.push(
1008
+ S(
1009
+ `${s.jsonPath}/compilerOptions`,
1010
+ "compilerOptions must be an object when present."
1011
+ )
1012
+ );
1013
+ continue;
1014
+ }
1015
+ if (!a)
1016
+ continue;
1017
+ "baseUrl" in a && (typeof a.baseUrl != "string" || a.baseUrl.trim().length === 0 ? n.push(
1018
+ S(
1019
+ `${s.jsonPath}/compilerOptions/baseUrl`,
1020
+ "compilerOptions.baseUrl must be a non-empty string when present."
1021
+ )
1022
+ ) : i = re(
1023
+ t,
1024
+ p.dirname(s.filePath),
1025
+ a.baseUrl
1026
+ ));
1027
+ const c = a.paths;
1028
+ if (c === void 0)
1029
+ continue;
1030
+ const u = Y(c);
1031
+ if (!u) {
1032
+ n.push(
1033
+ S(
1034
+ `${s.jsonPath}/compilerOptions/paths`,
1035
+ "compilerOptions.paths must be an object when present."
1036
+ )
1037
+ );
1038
+ continue;
1039
+ }
1040
+ const d = i ? p.resolve(t, i) : p.dirname(s.filePath);
1041
+ for (const l of Object.keys(u).sort(
1042
+ (h, v) => h.localeCompare(v)
1043
+ )) {
1044
+ const h = `${s.jsonPath}/compilerOptions/paths/${gt(l)}`, v = ft(
1045
+ t,
1046
+ d,
1047
+ u[l],
1048
+ h,
1049
+ n
1050
+ );
1051
+ v && o.set(l, v);
1052
+ }
1053
+ }
1054
+ return {
1055
+ workspaceRoot: t,
1056
+ configFiles: e.map(
1057
+ (s) => ne(t, s.filePath)
1058
+ ),
1059
+ ...i ? { baseUrl: i } : {},
1060
+ pathAliases: Object.fromEntries(
1061
+ [...o.entries()].sort(
1062
+ ([s], [a]) => s.localeCompare(a)
1063
+ )
1064
+ ),
1065
+ diagnostics: n
1066
+ };
1067
+ }
1068
+ function ft(t, e, r, n, o) {
1069
+ if (!Array.isArray(r)) {
1070
+ o.push(
1071
+ z(
1072
+ n,
1073
+ "Path alias targets must be an array of non-empty strings."
1074
+ )
1075
+ );
1076
+ return;
1077
+ }
1078
+ const i = [], s = /* @__PURE__ */ new Set();
1079
+ return r.forEach((a, c) => {
1080
+ if (typeof a != "string" || a.trim().length === 0) {
1081
+ o.push(
1082
+ z(
1083
+ `${n}/${c}`,
1084
+ "Path alias target must be a non-empty string."
1085
+ )
1086
+ );
1087
+ return;
1088
+ }
1089
+ const u = re(
1090
+ t,
1091
+ e,
1092
+ a
1093
+ );
1094
+ s.has(u) || (s.add(u), i.push(u));
1095
+ }), i;
1096
+ }
1097
+ function re(t, e, r) {
1098
+ const n = p.resolve(e, r.trim());
1099
+ return ne(t, n);
1100
+ }
1101
+ function ne(t, e) {
1102
+ const r = p.relative(t, e);
1103
+ return r ? r.split(p.sep).join("/") : ".";
1104
+ }
1105
+ function Y(t) {
1106
+ return typeof t == "object" && t !== null && !Array.isArray(t) ? t : void 0;
1107
+ }
1108
+ function gt(t) {
1109
+ return t.replaceAll("~", "~0").replaceAll("/", "~1");
1110
+ }
1111
+ function mt(t, e) {
1112
+ return oe(
1113
+ p.resolve(e),
1114
+ t,
1115
+ [],
1116
+ /* @__PURE__ */ new Set()
1117
+ );
1118
+ }
1119
+ function oe(t, e, r, n) {
1120
+ const o = [], i = p.resolve(t), s = W(e, t), a = `/${N(s)}`;
1121
+ if (n.has(i))
1122
+ return {
1123
+ configs: [],
1124
+ diagnostics: [
1125
+ le(`${a}/extends`, [
1126
+ ...r.map(
1127
+ (y) => W(e, y)
1128
+ ),
1129
+ s
1130
+ ])
1131
+ ]
1132
+ };
1133
+ const c = ht(i, e);
1134
+ if (!c.value)
1135
+ return {
1136
+ configs: [],
1137
+ diagnostics: c.diagnostics
1138
+ };
1139
+ const u = new Set(n);
1140
+ u.add(i);
1141
+ const d = [...r, i], l = c.value.extends;
1142
+ if (l === void 0)
1143
+ return {
1144
+ configs: [
1145
+ {
1146
+ filePath: i,
1147
+ jsonPath: a,
1148
+ value: c.value
1149
+ }
1150
+ ],
1151
+ diagnostics: o
1152
+ };
1153
+ if (typeof l != "string" || l.trim().length === 0)
1154
+ return o.push(
1155
+ x(
1156
+ `${a}/extends`,
1157
+ '"extends" must be a non-empty relative or absolute path string.'
1158
+ )
1159
+ ), {
1160
+ configs: [
1161
+ {
1162
+ filePath: i,
1163
+ jsonPath: a,
1164
+ value: c.value
1165
+ }
1166
+ ],
1167
+ diagnostics: o
1168
+ };
1169
+ const h = vt(
1170
+ i,
1171
+ l
1172
+ );
1173
+ if (!h)
1174
+ return o.push(
1175
+ x(
1176
+ `${a}/extends`,
1177
+ `Unsupported tsconfig extends path "${l}". Only relative or absolute paths are supported in this MVP.`
1178
+ )
1179
+ ), {
1180
+ configs: [
1181
+ {
1182
+ filePath: i,
1183
+ jsonPath: a,
1184
+ value: c.value
1185
+ }
1186
+ ],
1187
+ diagnostics: o
1188
+ };
1189
+ if (!m(h))
1190
+ return o.push(
1191
+ x(
1192
+ `${a}/extends`,
1193
+ `Extended tsconfig "${l}" could not be resolved.`
1194
+ )
1195
+ ), {
1196
+ configs: [
1197
+ {
1198
+ filePath: i,
1199
+ jsonPath: a,
1200
+ value: c.value
1201
+ }
1202
+ ],
1203
+ diagnostics: o
1204
+ };
1205
+ const v = oe(
1206
+ h,
1207
+ e,
1208
+ d,
1209
+ u
1210
+ );
1211
+ return {
1212
+ configs: [
1213
+ ...v.configs,
1214
+ {
1215
+ filePath: i,
1216
+ jsonPath: a,
1217
+ value: c.value
1218
+ }
1219
+ ],
1220
+ diagnostics: [...v.diagnostics, ...o]
1221
+ };
1222
+ }
1223
+ function ht(t, e) {
1224
+ try {
1225
+ const r = JSON.parse(k(t, "utf8"));
1226
+ return typeof r != "object" || r === null || Array.isArray(r) ? {
1227
+ diagnostics: [
1228
+ S(
1229
+ `/${N(
1230
+ W(e, t)
1231
+ )}`,
1232
+ `Failed to parse tsconfig file "${t}".`
1233
+ )
1234
+ ]
1235
+ } : {
1236
+ value: r,
1237
+ diagnostics: []
1238
+ };
1239
+ } catch {
1240
+ return {
1241
+ diagnostics: [
1242
+ S(
1243
+ `/${N(
1244
+ W(e, t)
1245
+ )}`,
1246
+ `Failed to parse tsconfig file "${t}".`
1247
+ )
1248
+ ]
1249
+ };
1250
+ }
1251
+ }
1252
+ function vt(t, e) {
1253
+ if (!e.startsWith(".") && !p.isAbsolute(e))
1254
+ return;
1255
+ const r = p.isAbsolute(e) ? e : p.resolve(p.dirname(t), e);
1256
+ return p.extname(r) ? r : `${r}.json`;
1257
+ }
1258
+ function W(t, e) {
1259
+ const r = p.relative(t, e);
1260
+ return r ? r.split(p.sep).join("/") : ".";
1261
+ }
1262
+ function N(t) {
1263
+ return t.replaceAll("~", "~0").replaceAll("/", "~1");
1264
+ }
1265
+ function yt(t, e) {
1266
+ const r = p.resolve(t), n = kt(r, e);
1267
+ if (!n)
1268
+ return {
1269
+ workspaceRoot: r,
1270
+ configFiles: [],
1271
+ pathAliases: {},
1272
+ diagnostics: []
1273
+ };
1274
+ const o = mt(r, n);
1275
+ return dt(
1276
+ r,
1277
+ o.configs,
1278
+ o.diagnostics
1279
+ );
1280
+ }
1281
+ function kt(t, e) {
1282
+ if (e)
1283
+ return p.isAbsolute(e) ? e : p.resolve(t, e);
1284
+ const r = p.join(t, "tsconfig.json");
1285
+ if (m(r))
1286
+ return r;
1287
+ const n = p.join(t, "tsconfig.base.json");
1288
+ if (m(n))
1289
+ return n;
1290
+ }
1291
+ const jt = /\{segment:(?<segmentIndex>[1-9]\d*)\}/g;
1292
+ function Pt(t, e, r, n) {
1293
+ return t ? se({
1294
+ template: t,
1295
+ wildcardSegments: e,
1296
+ path: n,
1297
+ kind: "name"
1298
+ }) : {
1299
+ value: r,
1300
+ diagnostics: []
1301
+ };
1302
+ }
1303
+ function _t(t, e, r) {
1304
+ return se({
1305
+ template: t,
1306
+ wildcardSegments: e,
1307
+ path: r,
1308
+ kind: "tag"
1309
+ });
1310
+ }
1311
+ function se({
1312
+ template: t,
1313
+ wildcardSegments: e,
1314
+ path: r,
1315
+ kind: n
1316
+ }) {
1317
+ const o = [], i = [...t.matchAll(jt)];
1318
+ let s = t;
1319
+ if (t.includes("{segment:") && i.length === 0)
1320
+ return o.push(
1321
+ C(
1322
+ n,
1323
+ r,
1324
+ `Template "${t}" contains an invalid {segment:N} placeholder.`
1325
+ )
1326
+ ), { diagnostics: o };
1327
+ for (const c of i) {
1328
+ const u = Number(c.groups?.segmentIndex ?? ""), d = e[u - 1];
1329
+ if (!d)
1330
+ return o.push(
1331
+ C(
1332
+ n,
1333
+ r,
1334
+ `Template "${t}" references missing segment ${u}.`
1335
+ )
1336
+ ), { diagnostics: o };
1337
+ s = s.replace(c[0], d);
1338
+ }
1339
+ const a = s.trim();
1340
+ return a.length === 0 ? (o.push(
1341
+ C(
1342
+ n,
1343
+ r,
1344
+ `Template "${t}" resolved to an empty string.`
1345
+ )
1346
+ ), { diagnostics: o }) : {
1347
+ value: a,
1348
+ diagnostics: o
1349
+ };
1350
+ }
1351
+ function C(t, e, r) {
1352
+ return t === "name" ? me(e, r) : O(e, r);
1353
+ }
1354
+ function St(t, e, r) {
1355
+ const n = [], o = [], i = /* @__PURE__ */ new Set();
1356
+ for (let s = 0; s < (t?.length ?? 0); s += 1) {
1357
+ const a = t?.[s];
1358
+ if (typeof a != "string") {
1359
+ n.push(
1360
+ O(
1361
+ `${r}/tags/${s}`,
1362
+ "Discovery tag template must be a string."
1363
+ )
1364
+ );
1365
+ continue;
1366
+ }
1367
+ const c = _t(
1368
+ a,
1369
+ e,
1370
+ `${r}/tags/${s}`
1371
+ );
1372
+ n.push(...c.diagnostics), !(!c.value || i.has(c.value)) && (i.add(c.value), o.push(c.value));
1373
+ }
1374
+ return {
1375
+ tags: o,
1376
+ domain: F(o, "domain"),
1377
+ layer: F(o, "layer"),
1378
+ scope: F(o, "scope"),
1379
+ diagnostics: n
1380
+ };
1381
+ }
1382
+ function F(t, e) {
1383
+ return t.find((n) => n.startsWith(`${e}:`))?.slice(e.length + 1);
1384
+ }
1385
+ function $t(t, e) {
1386
+ const r = [], n = [], o = /* @__PURE__ */ new Set(), i = /* @__PURE__ */ new Set();
1387
+ return Array.isArray(e.projects) ? (e.projects.forEach((s, a) => {
1388
+ const c = `/projects/${a}`, u = Wt(s.pattern);
1389
+ if (!u) {
1390
+ r.push(
1391
+ A(
1392
+ `${c}/pattern`,
1393
+ "Discovery pattern must be a non-empty string."
1394
+ )
1395
+ );
1396
+ return;
1397
+ }
1398
+ if (s.tags !== void 0 && !Array.isArray(s.tags)) {
1399
+ r.push(
1400
+ O(
1401
+ `${c}/tags`,
1402
+ "Discovery rule tags must be an array of strings when present."
1403
+ )
1404
+ );
1405
+ return;
1406
+ }
1407
+ const d = t.packageRoots.filter(
1408
+ (l) => H(l, u, {
1409
+ dot: !0,
1410
+ nocase: !1
1411
+ })
1412
+ ).sort((l, h) => l.localeCompare(h));
1413
+ if (d.length === 0) {
1414
+ r.push(
1415
+ de(u, `${c}/pattern`)
1416
+ );
1417
+ return;
1418
+ }
1419
+ for (const l of d) {
1420
+ const h = xt(u, l);
1421
+ if (!h) {
1422
+ r.push(
1423
+ A(
1424
+ `${c}/pattern`,
1425
+ `Discovery pattern "${u}" could not derive wildcard segments for "${l}".`
1426
+ )
1427
+ );
1428
+ continue;
1429
+ }
1430
+ const v = l.split("/").at(-1) ?? l, y = Pt(
1431
+ s.name,
1432
+ h,
1433
+ v,
1434
+ `${c}/name`
1435
+ );
1436
+ if (r.push(...y.diagnostics), !y.value)
1437
+ continue;
1438
+ const P = St(s.tags, h, c);
1439
+ if (r.push(...P.diagnostics), o.has(l)) {
1440
+ r.push(
1441
+ fe(l, `${c}/pattern`)
1442
+ );
1443
+ continue;
1444
+ }
1445
+ if (i.has(y.value)) {
1446
+ r.push(
1447
+ ge(y.value, `${c}/name`)
1448
+ );
1449
+ continue;
1450
+ }
1451
+ o.add(l), i.add(y.value), n.push(
1452
+ bt({
1453
+ root: l,
1454
+ name: y.value,
1455
+ tags: P.tags,
1456
+ domain: P.domain,
1457
+ layer: P.layer,
1458
+ scope: P.scope
1459
+ })
1460
+ );
1461
+ }
1462
+ }), {
1463
+ workspaceRoot: t.workspaceRoot,
1464
+ projects: n.sort((s, a) => {
1465
+ const c = s.root ?? "", u = a.root ?? "";
1466
+ return c.localeCompare(u) || s.id.localeCompare(a.id);
1467
+ }),
1468
+ diagnostics: r
1469
+ }) : {
1470
+ workspaceRoot: t.workspaceRoot,
1471
+ projects: [],
1472
+ diagnostics: [
1473
+ A(
1474
+ "/projects",
1475
+ 'Discovery config must define a "projects" array.'
1476
+ )
1477
+ ]
1478
+ };
1479
+ }
1480
+ function bt({
1481
+ root: t,
1482
+ name: e,
1483
+ tags: r,
1484
+ domain: n,
1485
+ layer: o,
1486
+ scope: i
1487
+ }) {
1488
+ return {
1489
+ id: e,
1490
+ name: e,
1491
+ root: t,
1492
+ type: "unknown",
1493
+ tags: r,
1494
+ ...n ? { domain: n } : {},
1495
+ ...o ? { layer: o } : {},
1496
+ ...i ? { scope: i } : {},
1497
+ metadata: {}
1498
+ };
1499
+ }
1500
+ function Wt(t) {
1501
+ if (typeof t != "string")
1502
+ return;
1503
+ let e = t.trim().replaceAll("\\", "/");
1504
+ for (; e.startsWith("./"); )
1505
+ e = e.slice(2);
1506
+ for (e = e.replace(/\/{2,}/g, "/"); e.length > 1 && e.endsWith("/"); )
1507
+ e = e.slice(0, -1);
1508
+ return e.length > 0 ? e : void 0;
1509
+ }
1510
+ function xt(t, e) {
1511
+ const r = t.split("/"), n = e.split("/"), o = [];
1512
+ let i = 0, s = 0;
1513
+ for (; i < r.length && s < n.length; ) {
1514
+ const a = r[i];
1515
+ if (a === "**") {
1516
+ const u = r.length - i - 1, d = n.length - s - u;
1517
+ if (d < 0)
1518
+ return;
1519
+ o.push(
1520
+ n.slice(s, s + d).join("/")
1521
+ ), s += d, i += 1;
1522
+ continue;
1523
+ }
1524
+ const c = n[s];
1525
+ if (a === "*")
1526
+ o.push(c);
1527
+ else if (a !== c)
1528
+ return;
1529
+ i += 1, s += 1;
1530
+ }
1531
+ if (!(i !== r.length || s !== n.length))
1532
+ return o;
1533
+ }
1534
+ const At = {
1535
+ projects: [
1536
+ { pattern: "packages/*" },
1537
+ { pattern: "packages/*/*" },
1538
+ { pattern: "apps/*" },
1539
+ { pattern: "apps/*/*" },
1540
+ { pattern: "libs/*" },
1541
+ { pattern: "libs/*/*" },
1542
+ { pattern: "services/*" },
1543
+ { pattern: "services/*/*" },
1544
+ { pattern: "tools/*" },
1545
+ { pattern: "tools/*/*" }
1546
+ ]
1547
+ };
1548
+ function Ct(t) {
1549
+ return {
1550
+ id: t.adapterId ?? "governance-adapter:typescript",
1551
+ probe(e) {
1552
+ const r = _e(e);
1553
+ return {
1554
+ supported: r.supported,
1555
+ confidence: r.supported ? r.status === "supported" ? "high" : "low" : "none",
1556
+ reasons: Dt(r),
1557
+ diagnostics: r.diagnostics,
1558
+ metadata: {
1559
+ status: r.status,
1560
+ indicators: r.indicators
1561
+ }
1562
+ };
1563
+ },
1564
+ loadWorkspace(e) {
1565
+ const r = p.resolve(e), n = ot(r), o = $t(
1566
+ n,
1567
+ t.discoveryConfig
1568
+ ), i = yt(
1569
+ r,
1570
+ t.tsconfigPath
1571
+ ), s = Re({
1572
+ workspaceRoot: r,
1573
+ projects: o.projects,
1574
+ tsconfig: i
1575
+ }), a = Be({
1576
+ workspaceRoot: r,
1577
+ projects: o.projects,
1578
+ importGraph: s
1579
+ });
1580
+ return {
1581
+ workspaceId: wt(r),
1582
+ workspaceName: ae(r),
1583
+ workspaceRoot: ".",
1584
+ projects: o.projects,
1585
+ dependencies: a.dependencies,
1586
+ diagnostics: [
1587
+ ...n.diagnostics,
1588
+ ...o.diagnostics,
1589
+ ...i.diagnostics,
1590
+ ...s.diagnostics,
1591
+ ...a.diagnostics
1592
+ ]
1593
+ };
1594
+ }
1595
+ };
1596
+ }
1597
+ function Ft(t = {}) {
1598
+ return Ct({
1599
+ discoveryConfig: t.discoveryConfig ?? At,
1600
+ ...t.tsconfigPath ? { tsconfigPath: t.tsconfigPath } : {},
1601
+ ...t.adapterId ? { adapterId: t.adapterId } : {}
1602
+ });
1603
+ }
1604
+ const Nt = Ft();
1605
+ function Dt(t) {
1606
+ const e = [];
1607
+ return t.indicators.pnpmWorkspace && e.push("pnpm-workspace.yaml is present"), t.indicators.packageManagerWorkspaces && e.push("package.json declares package-manager workspaces"), t.indicators.tsconfig && e.push("tsconfig.json is present"), t.indicators.tsconfigBase && e.push("tsconfig.base.json is present"), e.length === 0 && e.push("no TypeScript workspace indicators were found"), e;
1608
+ }
1609
+ function wt(t) {
1610
+ return ae(t);
1611
+ }
1612
+ function ae(t) {
1613
+ const e = p.join(t, "package.json");
1614
+ try {
1615
+ const r = JSON.parse(k(e, "utf8"));
1616
+ if (typeof r == "object" && r !== null && !Array.isArray(r) && typeof r.name == "string") {
1617
+ const n = r.name.trim();
1618
+ if (n.length > 0)
1619
+ return n;
1620
+ }
1621
+ } catch {
1622
+ }
1623
+ return p.basename(t);
1624
+ }
1625
+ export {
1626
+ At as DEFAULT_TYPESCRIPT_PROJECT_DISCOVERY_CONFIG,
1627
+ Re as buildTypeScriptImportGraph,
1628
+ Ft as createGovernanceWorkspaceAdapter,
1629
+ Ct as createTypeScriptWorkspaceAdapter,
1630
+ St as deriveProjectTags,
1631
+ _e as detectTypeScriptWorkspace,
1632
+ $t as discoverTypeScriptProjects,
1633
+ Nt as governanceWorkspaceAdapter,
1634
+ Be as mapTypeScriptImportsToGovernanceDependencies,
1635
+ ot as parsePackageManagerWorkspace,
1636
+ yt as parseTsConfigResolution
1637
+ };