runtime-pin-check 0.0.0-stage → 0.1.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.
@@ -0,0 +1,577 @@
1
+ // src/constraint.ts
2
+ import semver from "semver";
3
+ var FLOATING = /* @__PURE__ */ new Set(["latest", "node", "stable", "current", "system", "oldstable"]);
4
+ var ALIAS = /^(lts\/\*|lts\/[a-z][a-z-]*|lts|latest|node|stable|current|system|oldstable)$/i;
5
+ var DOCKER_VARIANTS = /* @__PURE__ */ new Set([
6
+ "alpine",
7
+ "slim",
8
+ "bookworm",
9
+ "bullseye",
10
+ "buster",
11
+ "stretch",
12
+ "jessie",
13
+ "trixie",
14
+ "noble",
15
+ "jammy",
16
+ "focal",
17
+ "windowsservercore",
18
+ "nanoserver"
19
+ ]);
20
+ function isFloatingAlias(alias) {
21
+ return FLOATING.has(alias.toLowerCase());
22
+ }
23
+ var EXACT = /^\d+\.\d+\.\d+$/;
24
+ var PARTIAL = /^(\d+)(?:\.(\d+))?(?:\.[xX*])?$/;
25
+ function versionPart(text, runtime) {
26
+ let t = text.trim();
27
+ if (runtime === "go") t = t.replace(/^go(?=\d)/, "");
28
+ if (runtime === "python") {
29
+ t = t.replace(/^python-?(?=\d)/i, "");
30
+ t = t.replace(/^(\d+\.\d+(?:\.\d+)?)t$/i, "$1");
31
+ }
32
+ return t.replace(/^[vV](?=\d)/, "");
33
+ }
34
+ function plainVersion(text) {
35
+ if (EXACT.test(text)) return { kind: "exact", version: text };
36
+ const m = PARTIAL.exec(text);
37
+ if (m) return { kind: "partial", version: m[2] === void 0 ? m[1] : `${m[1]}.${m[2]}` };
38
+ return void 0;
39
+ }
40
+ function pad(version) {
41
+ const parts = version.split(".");
42
+ while (parts.length < 3) parts.push("0");
43
+ return parts.slice(0, 3).join(".");
44
+ }
45
+ function pythonClause(clause) {
46
+ const m = /^(~=|===|==|!=|<=|>=|<|>|\^|~)?\s*(\d+(?:\.\d+){0,3})(\.\*)?$/.exec(clause.trim());
47
+ if (!m) return void 0;
48
+ const op = m[1] ?? "==";
49
+ const version = m[2];
50
+ const wildcard = m[3] !== void 0;
51
+ const parts = version.split(".").map(Number);
52
+ if (parts.length > 3) return void 0;
53
+ if (wildcard && op !== "==" && op !== "!=") return void 0;
54
+ switch (op) {
55
+ case "===":
56
+ return void 0;
57
+ case "!=":
58
+ return "";
59
+ case "==":
60
+ return wildcard ? partialRange(version) : `=${pad(version)}`;
61
+ case "~=": {
62
+ if (parts.length < 2) return void 0;
63
+ const upper = parts.slice(0, -1);
64
+ upper[upper.length - 1] = upper[upper.length - 1] + 1;
65
+ return `>=${pad(version)} <${pad(upper.join("."))}-0`;
66
+ }
67
+ case "<":
68
+ return `<${pad(version)}-0`;
69
+ case "<=":
70
+ return `<=${pad(version)}`;
71
+ case ">":
72
+ return `>${pad(version)}`;
73
+ case ">=":
74
+ return `>=${pad(version)}`;
75
+ case "^":
76
+ case "~":
77
+ return semver.validRange(`${op}${version}`) ?? void 0;
78
+ default:
79
+ return void 0;
80
+ }
81
+ }
82
+ function pythonRange(text) {
83
+ const alternatives = [];
84
+ for (const alt of text.split(/\|\|?/)) {
85
+ const clauses = alt.split(",").map((c) => c.trim()).filter((c) => c !== "");
86
+ if (clauses.length === 0) return void 0;
87
+ const converted = [];
88
+ for (const clause of clauses) {
89
+ const r = pythonClause(clause);
90
+ if (r === void 0) return void 0;
91
+ if (r !== "") converted.push(r);
92
+ }
93
+ alternatives.push(converted.length > 0 ? converted.join(" ") : "*");
94
+ }
95
+ return semver.validRange(alternatives.join(" || ")) ?? void 0;
96
+ }
97
+ function parseConstraint(raw, runtime) {
98
+ const text = versionPart(raw, runtime);
99
+ if (text === "") return { kind: "unknown", reason: "empty value" };
100
+ if (ALIAS.test(text)) return { kind: "alias", alias: text.toLowerCase() };
101
+ if (runtime === "python" && /^(pypy|graalpy)/i.test(text)) {
102
+ return { kind: "unknown", reason: "a PyPy/GraalPy build; its version is not compared with CPython pins" };
103
+ }
104
+ const plain = plainVersion(text);
105
+ if (plain) return plain;
106
+ if (/\$\{|\$\(|\{\{/.test(text)) return { kind: "unknown", reason: "contains a variable or template expression" };
107
+ const range = runtime === "python" ? pythonRange(text) : semver.validRange(text);
108
+ if (range) return { kind: "range", range };
109
+ return { kind: "unknown", reason: `not a ${runtime} version or version range` };
110
+ }
111
+ function dockerTagConstraint(tag, runtime) {
112
+ const t = (tag ?? "").split("@")[0]?.trim() ?? "";
113
+ if (t === "") return { kind: "alias", alias: "latest" };
114
+ if (/\$\{?[A-Za-z_]/.test(t)) return { kind: "unknown", reason: "tag contains an unresolved variable" };
115
+ const head = t.split("-")[0];
116
+ const plain = plainVersion(versionPart(head, runtime));
117
+ if (plain) return plain;
118
+ const word = head.toLowerCase();
119
+ if (DOCKER_VARIANTS.has(word.replace(/[\d.]+$/, ""))) return { kind: "alias", alias: "latest" };
120
+ if (ALIAS.test(word)) return { kind: "alias", alias: word };
121
+ if (runtime === "node" && /^[a-z]+$/.test(word)) return { kind: "alias", alias: `lts/${word}` };
122
+ return { kind: "unknown", reason: "tag has no recognisable version" };
123
+ }
124
+ function partialRange(version) {
125
+ const parts = version.split(".").map(Number);
126
+ if (parts.length === 1) return `>=${parts[0]}.0.0 <${parts[0] + 1}.0.0-0`;
127
+ if (parts.length === 2) return `>=${parts[0]}.${parts[1]}.0 <${parts[0]}.${parts[1] + 1}.0-0`;
128
+ return `=${pad(version)}`;
129
+ }
130
+ function toRange(c) {
131
+ switch (c.kind) {
132
+ case "exact":
133
+ return c.version;
134
+ case "partial":
135
+ return partialRange(c.version);
136
+ case "range":
137
+ return c.range;
138
+ default:
139
+ return void 0;
140
+ }
141
+ }
142
+ function describeConstraint(c) {
143
+ switch (c.kind) {
144
+ case "exact":
145
+ case "partial":
146
+ return c.version;
147
+ case "range":
148
+ return c.range;
149
+ case "alias":
150
+ return c.alias;
151
+ case "unknown":
152
+ return `unparseable (${c.reason})`;
153
+ }
154
+ }
155
+
156
+ // src/compare.ts
157
+ import semver2 from "semver";
158
+ var MANIFESTS = /* @__PURE__ */ new Set(["package.json", "pyproject.toml", "go.mod"]);
159
+ function dirOf(file) {
160
+ const i = file.lastIndexOf("/");
161
+ return i < 0 ? "." : file.slice(0, i);
162
+ }
163
+ function baseOf(file) {
164
+ return file.slice(file.lastIndexOf("/") + 1);
165
+ }
166
+ function normalizeDir(dir) {
167
+ const d = dir.replace(/\\/g, "/").replace(/^\.\/+/, "").replace(/\/+$/, "");
168
+ return d === "" ? "." : d;
169
+ }
170
+ function isSharedFile(file) {
171
+ const f = file.replace(/\\/g, "/");
172
+ if (/^\.github\//i.test(f)) return true;
173
+ if (f.includes("/")) return false;
174
+ const base = baseOf(f);
175
+ if (MANIFESTS.has(base)) return false;
176
+ if (/^dockerfile/i.test(base) || /\.dockerfile$/i.test(base)) return false;
177
+ return true;
178
+ }
179
+ function deepestRoot(dir, roots) {
180
+ let best = ".";
181
+ for (const r of roots) {
182
+ if (r === ".") continue;
183
+ if ((dir === r || dir.startsWith(`${r}/`)) && r.length > best.length) best = r;
184
+ }
185
+ return best;
186
+ }
187
+ function scopesOf(source, roots) {
188
+ if (source.boundTo !== void 0) return [...source.boundTo];
189
+ const all = roots.length > 0 ? [...roots] : ["."];
190
+ if (isSharedFile(source.file)) {
191
+ if (source.workingDirectory === void 0) return all;
192
+ return [deepestRoot(normalizeDir(source.workingDirectory), all)];
193
+ }
194
+ return [deepestRoot(dirOf(source.file.replace(/\\/g, "/")), all)];
195
+ }
196
+ function toolPinKind(file) {
197
+ const base = baseOf(file);
198
+ if (base === ".nvmrc" || base === ".node-version" || base === ".python-version" || base === ".tool-versions") return base;
199
+ if (/^\.?mise(\.[\w-]+)?\.toml$/i.test(base)) return "mise";
200
+ return void 0;
201
+ }
202
+ function isRootCiFile(file) {
203
+ return /^\.github\//i.test(file) || /^\.gitlab-ci\.ya?ml$/i.test(file);
204
+ }
205
+ function isContainerFile(file) {
206
+ const base = baseOf(file);
207
+ return /^dockerfile/i.test(base) || /\.dockerfile$/i.test(base) || /^(docker-)?compose(\.[\w-]+)*\.ya?ml$/i.test(base);
208
+ }
209
+ function isGlobPath(path) {
210
+ return /[*?[{]/.test(path);
211
+ }
212
+ function dirsBetween(dir, stop) {
213
+ const out = [];
214
+ let d = dir;
215
+ while (d !== stop && d !== ".") {
216
+ out.push(d);
217
+ const i = d.lastIndexOf("/");
218
+ d = i < 0 ? "." : d.slice(0, i);
219
+ }
220
+ return out;
221
+ }
222
+ function bindSources(sources, roots, manifests) {
223
+ const all = roots.length > 0 ? [...roots] : ["."];
224
+ const pinDirs = /* @__PURE__ */ new Set();
225
+ for (const s of sources) {
226
+ const kind = toolPinKind(s.file);
227
+ if (kind) pinDirs.add(`${s.runtime}\0${kind}\0${dirOf(s.file)}`);
228
+ }
229
+ const bindOne = (s) => {
230
+ const file = s.file.replace(/\\/g, "/");
231
+ const dir = dirOf(file);
232
+ const kind = toolPinKind(file);
233
+ if (isRootCiFile(file) || !kind && isContainerFile(file) && deepestRoot(dir, all) === ".") {
234
+ if (s.workingDirectory !== void 0) return [deepestRoot(normalizeDir(s.workingDirectory), all)];
235
+ if (manifests.get(".")?.has(s.runtime)) return ["."];
236
+ const named = (s.paths ?? []).filter((p) => !isGlobPath(p)).map((p) => deepestRoot(normalizeDir(p), all));
237
+ return [...new Set(named)].sort();
238
+ }
239
+ if (kind) {
240
+ const below = all.filter((r) => r === dir || dir === "." || r.startsWith(`${dir}/`));
241
+ if (below.length === 0) return [deepestRoot(dir, all)];
242
+ return below.filter((r) => !dirsBetween(r, dir).some((d) => pinDirs.has(`${s.runtime}\0${kind}\0${d}`)));
243
+ }
244
+ return [deepestRoot(dir, all)];
245
+ };
246
+ return sources.map((s) => ({ ...s, boundTo: bindOne(s) }));
247
+ }
248
+ function groupByScope(sources, roots) {
249
+ const groups = /* @__PURE__ */ new Map();
250
+ for (const source of sources) {
251
+ for (const root of scopesOf(source, roots)) {
252
+ const key = `${root}\0${source.runtime}`;
253
+ let g = groups.get(key);
254
+ if (!g) groups.set(key, g = { root, runtime: source.runtime, sources: [] });
255
+ g.sources.push(source);
256
+ }
257
+ }
258
+ return [...groups.values()].sort((a, b) => a.root === b.root ? a.runtime.localeCompare(b.runtime) : a.root < b.root ? -1 : 1);
259
+ }
260
+ function ref(s) {
261
+ return { file: s.file, line: s.line, raw: s.raw, constraint: s.constraint };
262
+ }
263
+ function where(s) {
264
+ return `${s.file}:${s.line}`;
265
+ }
266
+ function byPosition(a, b) {
267
+ return a.file === b.file ? a.line - b.line : a.file < b.file ? -1 : 1;
268
+ }
269
+ var SEVERITY = {
270
+ VERSION_CONFLICT: "error",
271
+ OUTSIDE_RANGE: "error",
272
+ PRECISION_MISMATCH: "info",
273
+ EOL_RUNTIME: "warning",
274
+ EOL_SOON: "info",
275
+ FLOATING_ALIAS: "info",
276
+ UNPARSEABLE: "info"
277
+ };
278
+ var SEVERITY_ORDER = { error: 0, warning: 1, info: 2 };
279
+ function comparable(source, options) {
280
+ const c = source.constraint;
281
+ if (c.kind === "alias") {
282
+ if (isFloatingAlias(c.alias)) return void 0;
283
+ const range2 = options.resolveAlias?.(source.runtime, c.alias);
284
+ return range2 && semver2.validRange(range2) ? { source, range: range2, pin: true } : void 0;
285
+ }
286
+ const range = toRange(c);
287
+ if (range === void 0) return void 0;
288
+ return { source, range, pin: c.kind === "exact" || c.kind === "partial" };
289
+ }
290
+ function overlaps(a, b) {
291
+ try {
292
+ return semver2.intersects(a, b);
293
+ } catch {
294
+ return true;
295
+ }
296
+ }
297
+ function pinText(s) {
298
+ return `${s.runtime} ${describeConstraint(s.constraint)}`;
299
+ }
300
+ var Collector = class {
301
+ found = /* @__PURE__ */ new Map();
302
+ /** `scope` undefined = an UNBOUND source: the finding gets no scope. */
303
+ add(code, runtime, sources, scope, message) {
304
+ const ordered = [...sources].sort(byPosition);
305
+ const key = `${code}\0${runtime}\0${ordered.map((s) => `${where(s)}\0${s.raw}`).join("")}`;
306
+ const existing = this.found.get(key);
307
+ if (existing) {
308
+ if (scope !== void 0 && !existing.scopes.includes(scope)) existing.scopes.push(scope);
309
+ return;
310
+ }
311
+ this.found.set(key, { code, severity: SEVERITY[code], runtime, sources: ordered.map(ref), scopes: scope === void 0 ? [] : [scope], message });
312
+ }
313
+ findings() {
314
+ const list = [...this.found.values()];
315
+ for (const f of list) f.scopes.sort();
316
+ return list.sort(
317
+ (a, b) => SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity] || (a.sources[0]?.file ?? "").localeCompare(b.sources[0]?.file ?? "") || (a.sources[0]?.line ?? 0) - (b.sources[0]?.line ?? 0) || a.code.localeCompare(b.code)
318
+ );
319
+ }
320
+ };
321
+ function outsideRange(out, scope, pin, range) {
322
+ if (overlaps(pin.range, range.range)) return;
323
+ out.add(
324
+ "OUTSIDE_RANGE",
325
+ scope.runtime,
326
+ [pin.source, range.source],
327
+ scope.root,
328
+ `${where(pin.source)} pins ${pinText(pin.source)}, outside the range ${describeConstraint(range.source.constraint)} required by ${where(range.source)}.`
329
+ );
330
+ }
331
+ function anyDisjoint(list) {
332
+ for (let i = 0; i < list.length; i++) {
333
+ for (let j = i + 1; j < list.length; j++) if (!overlaps(list[i].range, list[j].range)) return true;
334
+ }
335
+ return false;
336
+ }
337
+ function groupedList(sources) {
338
+ const groups = /* @__PURE__ */ new Map();
339
+ for (const s of [...sources].sort(byPosition)) {
340
+ const key = describeConstraint(s.constraint);
341
+ const list = groups.get(key);
342
+ if (list) list.push(s);
343
+ else groups.set(key, [s]);
344
+ }
345
+ const text = [...groups].map(([version, list]) => `${version} (${list.map(where).join(", ")})`).join(", ");
346
+ return { text, groups: groups.size, files: new Set(sources.map((s) => s.file)).size };
347
+ }
348
+ function plural(n, word) {
349
+ return `${n} ${word}${n === 1 ? "" : "s"}`;
350
+ }
351
+ function versionConflict(out, scope, pins, ranges) {
352
+ const involved = [];
353
+ if (anyDisjoint(pins)) involved.push(...pins.map((p) => p.source));
354
+ if (anyDisjoint(ranges)) involved.push(...ranges.map((r) => r.source));
355
+ if (involved.length === 0) return;
356
+ const { text, groups, files } = groupedList(involved);
357
+ out.add(
358
+ "VERSION_CONFLICT",
359
+ scope.runtime,
360
+ involved,
361
+ scope.root,
362
+ `${scope.runtime}: ${groups} different versions across ${plural(files, "file")}: ${text}; no version satisfies all of them.`
363
+ );
364
+ }
365
+ function precisionOf(c) {
366
+ return c.kind === "exact" ? 3 : c.kind === "partial" ? c.version.split(".").length : 0;
367
+ }
368
+ function precisionMismatch(out, scope, pins) {
369
+ const plain = pins.filter((p) => precisionOf(p.source.constraint) > 0);
370
+ const groups = [];
371
+ for (const coarse of [...plain].sort((a, b) => byPosition(a.source, b.source))) {
372
+ const level = precisionOf(coarse.source.constraint);
373
+ if (level === 3) continue;
374
+ const finer = plain.filter((p) => precisionOf(p.source.constraint) > level && overlaps(coarse.range, p.range)).map((p) => p.source).sort(byPosition);
375
+ const covered = groups.some((g) => g.finer.includes(coarse.source) && finer.every((f) => g.finer.includes(f)));
376
+ if (finer.length > 0 && !covered) groups.push({ coarse: coarse.source, finer });
377
+ }
378
+ if (groups.length === 0) return;
379
+ const involved = /* @__PURE__ */ new Set();
380
+ for (const g of groups) {
381
+ involved.add(g.coarse);
382
+ for (const f of g.finer) involved.add(f);
383
+ }
384
+ const pin = (s) => `${describeConstraint(s.constraint)} (${where(s)})`;
385
+ const text = groups.map((g) => `${pin(g.coarse)} includes ${g.finer.map(pin).join(", ")}`).join("; ");
386
+ out.add(
387
+ "PRECISION_MISMATCH",
388
+ scope.runtime,
389
+ [...involved],
390
+ scope.root,
391
+ `${scope.runtime}: pins that agree but are written at different precision: ${text}.`
392
+ );
393
+ }
394
+ function checkAlone(out, source, scope, options) {
395
+ const c = source.constraint;
396
+ if (c.kind === "unknown") {
397
+ out.add("UNPARSEABLE", source.runtime, [source], scope, `${where(source)}: could not read "${source.raw}" as a ${source.runtime} version (${c.reason}).`);
398
+ return void 0;
399
+ }
400
+ if (c.kind === "alias" && isFloatingAlias(c.alias)) {
401
+ out.add(
402
+ "FLOATING_ALIAS",
403
+ source.runtime,
404
+ [source],
405
+ scope,
406
+ `${where(source)} pins ${source.runtime} to "${source.raw}", which moves with every new release; pin a version instead.`
407
+ );
408
+ return void 0;
409
+ }
410
+ const cmp = comparable(source, options);
411
+ if (!cmp && c.kind === "alias" && options.resolveAlias) {
412
+ out.add(
413
+ "UNPARSEABLE",
414
+ source.runtime,
415
+ [source],
416
+ scope,
417
+ `${where(source)}: the ${source.runtime} alias "${source.raw}" does not match any release line in the bundled data.`
418
+ );
419
+ }
420
+ return cmp;
421
+ }
422
+ function compareSources(sources, roots = ["."], options = {}) {
423
+ const out = new Collector();
424
+ for (const source of [...sources].sort(byPosition)) {
425
+ if (source.boundTo !== void 0 && source.boundTo.length === 0) checkAlone(out, source, void 0, options);
426
+ }
427
+ for (const scope of groupByScope(sources, roots)) {
428
+ const pins = [];
429
+ const matrix = [];
430
+ for (const source of [...scope.sources].sort(byPosition)) {
431
+ const cmp = checkAlone(out, source, scope.root, options);
432
+ if (cmp) (source.matrix ? matrix : pins).push(cmp);
433
+ }
434
+ const fixed = pins.filter((p) => p.pin);
435
+ const ranges = pins.filter((p) => !p.pin);
436
+ for (const p of [...fixed, ...matrix]) for (const r of ranges) outsideRange(out, scope, p, r);
437
+ versionConflict(out, scope, fixed, ranges);
438
+ precisionMismatch(out, scope, fixed);
439
+ }
440
+ return out.findings();
441
+ }
442
+
443
+ // src/scan.ts
444
+ import { readdir } from "fs/promises";
445
+ import { join } from "path";
446
+ var IGNORED_DIRS = /* @__PURE__ */ new Set(["node_modules", ".git", "dist", "build", "vendor", ".venv"]);
447
+ var MANIFEST_RUNTIME = {
448
+ "package.json": "node",
449
+ "pyproject.toml": "python",
450
+ "setup.py": "python",
451
+ "setup.cfg": "python",
452
+ "go.mod": "go"
453
+ };
454
+ function manifestRuntimesOf(files) {
455
+ const out = /* @__PURE__ */ new Map();
456
+ for (const file of files) {
457
+ const i = file.lastIndexOf("/");
458
+ const runtime = MANIFEST_RUNTIME[file.slice(i + 1)];
459
+ if (!runtime) continue;
460
+ const dir = i < 0 ? "." : file.slice(0, i);
461
+ let set = out.get(dir);
462
+ if (!set) out.set(dir, set = /* @__PURE__ */ new Set());
463
+ set.add(runtime);
464
+ }
465
+ return out;
466
+ }
467
+ var ROOT_MARKERS = /* @__PURE__ */ new Set(["package.json", "pyproject.toml", "go.mod"]);
468
+ var FIXTURE_DIR = /^(_?test[-_]?data|test[-_]?fixtures?|__fixtures__|fixtures?|testdata)$/i;
469
+ function isFixtureDir(name) {
470
+ return FIXTURE_DIR.test(name);
471
+ }
472
+ function escapeRegex(text) {
473
+ return text.replace(/[.+^${}()|[\]\\]/g, "\\$&");
474
+ }
475
+ function globMatcher(glob) {
476
+ const pattern = glob.trim().replace(/\\/g, "/").replace(/^\.\//, "").replace(/\/+$/, "");
477
+ let re = "";
478
+ for (let i = 0; i < pattern.length; i++) {
479
+ const c = pattern[i];
480
+ if (c === "*") {
481
+ if (pattern[i + 1] === "*") {
482
+ i++;
483
+ if (pattern[i + 1] === "/") {
484
+ i++;
485
+ re += "(?:.*/)?";
486
+ } else {
487
+ re += ".*";
488
+ }
489
+ } else {
490
+ re += "[^/]*";
491
+ }
492
+ } else if (c === "?") {
493
+ re += "[^/]";
494
+ } else {
495
+ re += escapeRegex(c);
496
+ }
497
+ }
498
+ const regex = new RegExp(`^${re}$`);
499
+ if (!pattern.includes("/")) return (path) => regex.test(path.slice(path.lastIndexOf("/") + 1));
500
+ return (path) => regex.test(path);
501
+ }
502
+ async function countFiles(abs) {
503
+ let n = 0;
504
+ for (const entry of await readdir(abs, { withFileTypes: true })) {
505
+ if (entry.isSymbolicLink()) continue;
506
+ if (entry.isDirectory()) n += await countFiles(join(abs, entry.name));
507
+ else if (entry.isFile()) n++;
508
+ }
509
+ return n;
510
+ }
511
+ async function scanFiles(dir, options = {}) {
512
+ const files = [];
513
+ let excluded = 0;
514
+ const matchers = (options.exclude ?? []).filter((g) => g.trim() !== "").map(globMatcher);
515
+ const skip = (path) => matchers.some((m) => m(path));
516
+ async function visit(rel) {
517
+ const abs = rel === "" ? dir : join(dir, rel);
518
+ const entries = await readdir(abs, { withFileTypes: true });
519
+ for (const entry of entries) {
520
+ if (entry.isSymbolicLink()) continue;
521
+ const path = rel === "" ? entry.name : `${rel}/${entry.name}`;
522
+ if (entry.isDirectory()) {
523
+ if (IGNORED_DIRS.has(entry.name)) continue;
524
+ if (!options.includeFixtures && isFixtureDir(entry.name) || skip(path)) {
525
+ excluded += await countFiles(join(abs, entry.name));
526
+ continue;
527
+ }
528
+ await visit(path);
529
+ } else if (entry.isFile()) {
530
+ if (skip(path)) excluded++;
531
+ else files.push(path);
532
+ }
533
+ }
534
+ }
535
+ await visit("");
536
+ return { files: files.sort(), excluded };
537
+ }
538
+ async function walkFiles(dir, options = {}) {
539
+ return (await scanFiles(dir, options)).files;
540
+ }
541
+ async function findProjectRoots(dir, files) {
542
+ const list = files ?? await walkFiles(dir);
543
+ return projectRootsOf(list);
544
+ }
545
+ function projectRootsOf(files) {
546
+ const roots = /* @__PURE__ */ new Set(["."]);
547
+ for (const file of files) {
548
+ const i = file.lastIndexOf("/");
549
+ const base = file.slice(i + 1);
550
+ if (!ROOT_MARKERS.has(base)) continue;
551
+ const parts = file.split("/").slice(0, -1);
552
+ if (parts.some((p) => IGNORED_DIRS.has(p))) continue;
553
+ roots.add(i < 0 ? "." : file.slice(0, i));
554
+ }
555
+ return [...roots].sort();
556
+ }
557
+
558
+ export {
559
+ isFloatingAlias,
560
+ parseConstraint,
561
+ dockerTagConstraint,
562
+ toRange,
563
+ describeConstraint,
564
+ isSharedFile,
565
+ scopesOf,
566
+ bindSources,
567
+ groupByScope,
568
+ compareSources,
569
+ IGNORED_DIRS,
570
+ manifestRuntimesOf,
571
+ ROOT_MARKERS,
572
+ scanFiles,
573
+ walkFiles,
574
+ findProjectRoots,
575
+ projectRootsOf
576
+ };
577
+ //# sourceMappingURL=chunk-TRO76P2I.js.map