@blzsky/variant 0.2.0 → 0.3.0-canary.0

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 (49) hide show
  1. package/README.md +241 -136
  2. package/dist/{build-2LO7GD2S.js → build-GKWNLU4Q.js} +11 -10
  3. package/dist/{check-ZTKGGF4M.js → check-KO5VY67Z.js} +9 -9
  4. package/dist/{chunk-4LLK2S4R.js → chunk-7NC7AO75.js} +19 -32
  5. package/dist/{chunk-RVXUCJYA.js → chunk-ACTY42RE.js} +27 -0
  6. package/dist/{chunk-SWPVR2DF.js → chunk-CN25SRKD.js} +9 -9
  7. package/dist/{chunk-LXKLCLL6.js → chunk-CWF6QXEW.js} +1 -1
  8. package/dist/{chunk-MZZOE7L4.js → chunk-DMDAJPFJ.js} +1 -1
  9. package/dist/{chunk-O4LZKXNZ.js → chunk-DSQDMFQ6.js} +59 -2
  10. package/dist/{chunk-V22IPJ7A.js → chunk-EISTWXDW.js} +5 -1
  11. package/dist/chunk-H5C4SE73.js +184 -0
  12. package/dist/chunk-IFFZ46YS.js +575 -0
  13. package/dist/chunk-IHXJ72XA.js +31 -0
  14. package/dist/chunk-KCEGA56S.js +670 -0
  15. package/dist/{chunk-LJDDS4RR.js → chunk-MAK3HG46.js} +54 -8
  16. package/dist/chunk-MT4BOAAV.js +167 -0
  17. package/dist/{chunk-VTJ67TT5.js → chunk-NFFXYYM6.js} +122 -27
  18. package/dist/{chunk-ISRF5F3Q.js → chunk-QRPI6TJE.js} +1 -1
  19. package/dist/{chunk-RGD422OM.js → chunk-RJBFCURK.js} +1 -1
  20. package/dist/{chunk-XUBWCTJZ.js → chunk-RSIOYQOQ.js} +85 -8
  21. package/dist/chunk-SGP5JX6I.js +377 -0
  22. package/dist/chunk-X3VVGTEV.js +268 -0
  23. package/dist/{chunk-NSNZOH5P.js → chunk-YII4TAKS.js} +10 -3
  24. package/dist/cli.js +76 -37
  25. package/dist/{diff-GFI6RAEA.js → diff-A3TQWWUJ.js} +9 -5
  26. package/dist/{doctor-GH4RZVEH.js → doctor-6ONS6LKY.js} +5 -5
  27. package/dist/{env-QORDD6FQ.js → env-XF2US3CB.js} +8 -8
  28. package/dist/git-W6N3WMYQ.js +24 -0
  29. package/dist/impact-DPZIAJR4.js +263 -0
  30. package/dist/index.js +2 -2
  31. package/dist/init-VNK5E4H3.js +777 -0
  32. package/dist/{insight-DZ5NQY6D.js → insight-LNYVMCAE.js} +9 -9
  33. package/dist/pr-6CYMM2XU.js +707 -0
  34. package/dist/{run-6PNH4QRA.js → run-44PKMOV5.js} +11 -10
  35. package/dist/{symbol-graph-YYUEMZGR.js → symbol-graph-OB4AJCLW.js} +3 -3
  36. package/dist/{tsconfig-paths-E3UEDGXZ.js → tsconfig-paths-SV3PULCW.js} +3 -1
  37. package/dist/vitest.cjs +629 -0
  38. package/dist/vitest.d.cts +181 -0
  39. package/dist/vitest.d.ts +181 -0
  40. package/dist/vitest.js +356 -0
  41. package/dist/workspace-PIQXG4ZD.js +65 -0
  42. package/package.json +15 -4
  43. package/dist/chunk-DRMASVYN.js +0 -25
  44. package/dist/chunk-KSHWC2XN.js +0 -78
  45. package/dist/chunk-XTYVVUWW.js +0 -279
  46. package/dist/impact-AF453PLK.js +0 -702
  47. package/dist/init-KJIUNGAN.js +0 -158
  48. package/dist/pr-UFZRZX6S.js +0 -152
  49. package/dist/workspace-X5FUBTY3.js +0 -186
@@ -1,279 +0,0 @@
1
- import {
2
- matchPathAlias
3
- } from "./chunk-KSHWC2XN.js";
4
-
5
- // src/core/graph/import-graph.ts
6
- import path2 from "path";
7
-
8
- // src/core/graph/package-exports.ts
9
- import path from "path";
10
- var BUILD_DIRS = ["dist", "lib", "build", "out", "es", "esm", "cjs"];
11
- var SOURCE_DIRS = ["src", "lib", "source", ""];
12
- var CONDITIONS = [
13
- "source",
14
- "development",
15
- "import",
16
- "module",
17
- "require",
18
- "types",
19
- "node",
20
- "default"
21
- ];
22
- var MAX_CONDITION_DEPTH = 8;
23
- function targetsOf(value, depth = 0) {
24
- if (depth > MAX_CONDITION_DEPTH) return [];
25
- if (typeof value === "string") return [value];
26
- if (Array.isArray(value)) {
27
- return value.flatMap((entry) => targetsOf(entry, depth + 1));
28
- }
29
- if (typeof value !== "object" || value === null) return [];
30
- const record = value;
31
- const out = [];
32
- for (const condition of CONDITIONS) {
33
- if (condition in record) {
34
- out.push(...targetsOf(record[condition], depth + 1));
35
- }
36
- }
37
- for (const [key, nested] of Object.entries(record)) {
38
- if (!CONDITIONS.includes(key) && !key.startsWith(".")) {
39
- out.push(...targetsOf(nested, depth + 1));
40
- }
41
- }
42
- return out;
43
- }
44
- function clean(target) {
45
- if (!target.startsWith("./")) return void 0;
46
- return target.slice(2);
47
- }
48
- function resolveExportsSubpath(exportsField, subpath) {
49
- if (exportsField === void 0 || exportsField === null) return [];
50
- const request = subpath === "" ? "." : `./${subpath}`;
51
- const isSubpathMap = typeof exportsField === "object" && !Array.isArray(exportsField) && Object.keys(exportsField).some(
52
- (k) => k.startsWith(".")
53
- );
54
- if (!isSubpathMap) {
55
- return request === "." ? targetsOf(exportsField).map(clean).filter((t) => t !== void 0) : [];
56
- }
57
- const map = exportsField;
58
- if (request in map) {
59
- return targetsOf(map[request]).map(clean).filter((t) => t !== void 0);
60
- }
61
- const patterns = Object.keys(map).filter((key) => key.startsWith("./") && key.includes("*")).sort((a, b) => b.length - a.length);
62
- for (const pattern of patterns) {
63
- const [prefix = "", suffix = ""] = pattern.split("*");
64
- if (request.length < prefix.length + suffix.length || !request.startsWith(prefix) || !request.endsWith(suffix)) {
65
- continue;
66
- }
67
- const captured = request.slice(
68
- prefix.length,
69
- request.length - suffix.length
70
- );
71
- const targets = targetsOf(map[pattern]).map((t) => clean(t.replace("*", captured))).filter((t) => t !== void 0);
72
- if (targets.length > 0) return targets;
73
- }
74
- return [];
75
- }
76
- function toSourceCandidates(target) {
77
- const withoutExtension = stripExtension(target);
78
- const segments = withoutExtension.split("/");
79
- const head = segments[0];
80
- const bodies = head !== void 0 && BUILD_DIRS.includes(head) && segments.length > 1 ? [segments.slice(1).join("/")] : [withoutExtension];
81
- const out = [];
82
- for (const body of bodies) {
83
- for (const dir of SOURCE_DIRS) {
84
- out.push(dir === "" ? body : `${dir}/${body}`);
85
- }
86
- }
87
- return [...new Set(out)];
88
- }
89
- function stripExtension(target) {
90
- if (target.endsWith(".d.ts")) return target.slice(0, -".d.ts".length);
91
- const ext = path.posix.extname(target);
92
- return ext === "" ? target : target.slice(0, -ext.length);
93
- }
94
- function exportsCandidates(exportsField, subpath) {
95
- const targets = resolveExportsSubpath(exportsField, subpath);
96
- if (targets.length === 0) return [];
97
- const out = [];
98
- for (const target of targets) out.push(stripExtension(target));
99
- for (const target of targets) out.push(...toSourceCandidates(target));
100
- return [...new Set(out)];
101
- }
102
-
103
- // src/core/graph/import-graph.ts
104
- var TS_EXTENSIONS = [".ts", ".tsx", ".mts", ".cts"];
105
- var JS_TO_TS = {
106
- ".js": [".ts", ".tsx"],
107
- ".mjs": [".mts"],
108
- ".cjs": [".cts"],
109
- ".jsx": [".tsx"]
110
- };
111
- function buildImportGraph(symbolGraph, options = {}) {
112
- const files = new Set(Object.keys(symbolGraph.files));
113
- const packageDirs = options.packageDirs ?? {};
114
- const pathAliases = options.pathAliases ?? [];
115
- const packageExports = options.packageExports ?? {};
116
- const imports = /* @__PURE__ */ new Map();
117
- const dependents = /* @__PURE__ */ new Map();
118
- const externals = /* @__PURE__ */ new Map();
119
- const unresolved = /* @__PURE__ */ new Map();
120
- const edges = /* @__PURE__ */ new Map();
121
- for (const file of [...files].sort()) {
122
- imports.set(file, /* @__PURE__ */ new Set());
123
- dependents.set(file, /* @__PURE__ */ new Set());
124
- externals.set(file, /* @__PURE__ */ new Set());
125
- unresolved.set(file, /* @__PURE__ */ new Set());
126
- edges.set(file, /* @__PURE__ */ new Map());
127
- }
128
- const addEdge = (from, to, imp) => {
129
- imports.get(from)?.add(to);
130
- const perFile = edges.get(from);
131
- if (perFile === void 0) return;
132
- let edge = perFile.get(to);
133
- if (edge === void 0) {
134
- edge = { names: /* @__PURE__ */ new Set(), typeOnly: true, dynamic: false };
135
- perFile.set(to, edge);
136
- }
137
- for (const name of imp.names) edge.names.add(name);
138
- if (imp.kind === "dynamic") edge.dynamic = true;
139
- edge.typeOnly = edge.typeOnly && imp.typeOnly;
140
- };
141
- for (const file of [...files].sort()) {
142
- const index = symbolGraph.files[file];
143
- if (index === void 0) continue;
144
- for (const imp of index.imports) {
145
- const spec = imp.module;
146
- if (spec.startsWith("./") || spec.startsWith("../")) {
147
- const resolved = resolveRelativeImport(file, spec, files);
148
- if (resolved === void 0) unresolved.get(file)?.add(spec);
149
- else addEdge(file, resolved, imp);
150
- continue;
151
- }
152
- if (spec.startsWith("node:")) {
153
- externals.get(file)?.add(spec);
154
- continue;
155
- }
156
- const pkg = matchWorkspacePackage(spec, packageDirs);
157
- if (pkg !== void 0) {
158
- const resolved = resolvePackageImport(
159
- pkg.dir,
160
- pkg.subpath,
161
- files,
162
- packageExports[pkg.name]
163
- );
164
- if (resolved === void 0) unresolved.get(file)?.add(spec);
165
- else addEdge(file, resolved, imp);
166
- continue;
167
- }
168
- const aliased = resolveAliasImport(spec, pathAliases, files);
169
- if (aliased !== void 0) {
170
- addEdge(file, aliased, imp);
171
- continue;
172
- }
173
- if (matchPathAlias(spec, pathAliases).length > 0) {
174
- unresolved.get(file)?.add(spec);
175
- continue;
176
- }
177
- externals.get(file)?.add(spec);
178
- }
179
- }
180
- for (const [file, targets] of imports) {
181
- for (const target of targets) {
182
- dependents.get(target)?.add(file);
183
- }
184
- }
185
- return { imports, dependents, externals, unresolved, edges };
186
- }
187
- function computeAffectedFiles(changed, graph) {
188
- const affected = /* @__PURE__ */ new Set();
189
- for (const file of changed) affected.add(toPosix(file));
190
- let frontier = new Set(affected);
191
- while (frontier.size > 0) {
192
- const next = /* @__PURE__ */ new Set();
193
- for (const file of frontier) {
194
- for (const dependent of graph.dependents.get(file) ?? []) {
195
- if (!affected.has(dependent)) {
196
- affected.add(dependent);
197
- next.add(dependent);
198
- }
199
- }
200
- }
201
- frontier = next;
202
- }
203
- return affected;
204
- }
205
- function resolveRelativeImport(fromFile, spec, files) {
206
- const base = path2.posix.normalize(
207
- path2.posix.join(path2.posix.dirname(fromFile), spec)
208
- );
209
- if (base.startsWith("../")) return void 0;
210
- return firstExisting(candidatePaths(base), files);
211
- }
212
- function resolvePackageImport(pkgDir, subpath, files, exportsField) {
213
- const fromExports = exportsCandidates(exportsField, subpath);
214
- const candidates = fromExports.flatMap(
215
- (base) => candidatePaths(path2.posix.join(pkgDir, base))
216
- );
217
- if (subpath === "") {
218
- candidates.push(
219
- ...candidatePaths(`${pkgDir}/src/index`),
220
- ...candidatePaths(`${pkgDir}/index`)
221
- );
222
- } else {
223
- candidates.push(
224
- ...candidatePaths(path2.posix.join(pkgDir, subpath)),
225
- ...candidatePaths(path2.posix.join(pkgDir, "src", subpath))
226
- );
227
- }
228
- return firstExisting(candidates, files);
229
- }
230
- function resolveAliasImport(spec, aliases, files) {
231
- for (const base of matchPathAlias(spec, aliases)) {
232
- const resolved = firstExisting(candidatePaths(base), files);
233
- if (resolved !== void 0) return resolved;
234
- }
235
- return void 0;
236
- }
237
- function matchWorkspacePackage(spec, packageDirs) {
238
- const segments = spec.split("/");
239
- const nameLength = spec.startsWith("@") ? 2 : 1;
240
- if (segments.length < nameLength) return void 0;
241
- const name = segments.slice(0, nameLength).join("/");
242
- const dir = packageDirs[name];
243
- if (dir === void 0) return void 0;
244
- return {
245
- name,
246
- dir: toPosix(dir),
247
- subpath: segments.slice(nameLength).join("/")
248
- };
249
- }
250
- function candidatePaths(base) {
251
- const ext = path2.posix.extname(base);
252
- if (TS_EXTENSIONS.includes(ext)) {
253
- return [base];
254
- }
255
- const tsExts = JS_TO_TS[ext];
256
- if (tsExts !== void 0) {
257
- const stem = base.slice(0, -ext.length);
258
- return tsExts.map((e) => stem + e);
259
- }
260
- return [
261
- ...TS_EXTENSIONS.map((e) => base + e),
262
- ...TS_EXTENSIONS.map((e) => `${base}/index${e}`)
263
- ];
264
- }
265
- function firstExisting(candidates, files) {
266
- for (const c of candidates) {
267
- if (files.has(c)) return c;
268
- }
269
- return void 0;
270
- }
271
- function toPosix(p) {
272
- return p.replace(/\\/g, "/");
273
- }
274
-
275
- export {
276
- buildImportGraph,
277
- computeAffectedFiles,
278
- resolveRelativeImport
279
- };