forked from runxhq/runx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-boundaries.mjs
More file actions
executable file
·702 lines (629 loc) · 22.9 KB
/
Copy pathcheck-boundaries.mjs
File metadata and controls
executable file
·702 lines (629 loc) · 22.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
#!/usr/bin/env node
import { readFile, readdir, stat } from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
const workspaceRoot = path.resolve(
process.env.RUNX_BOUNDARY_WORKSPACE_ROOT ?? fileURLToPath(new URL("..", import.meta.url)),
);
const boundaryGuardPath = path.resolve(fileURLToPath(import.meta.url));
const sourceExtensions = new Set([".ts", ".tsx", ".mts", ".cts"]);
const activeTypeScriptJavaScriptExtensions = new Set([
".ts",
".tsx",
".mts",
".cts",
".js",
".jsx",
".mjs",
".cjs",
]);
const activeCredentialContractExtensions = new Set([
".ts",
".tsx",
".mts",
".cts",
".js",
".jsx",
".mjs",
".cjs",
".rs",
".json",
]);
const ignoredDirectoryNames = new Set([
".git",
".turbo",
"node_modules",
"dist",
".build",
"coverage",
"target",
]);
const hostedConnectBrokerageScanRoots = ["packages", "plugins", "scripts", "tests"];
const hostedCredentialContractScanRoots = [
"packages",
"plugins",
"scripts",
"tests",
"fixtures/contracts",
"schemas",
"crates/runx-contracts/src",
"crates/runx-contracts/tests",
"crates/runx-runtime/src",
"crates/runx-core/src",
];
const literalName = (...parts) => parts.join("");
const literalPattern = (...parts) => new RegExp(literalName(...parts));
const privateProviderGatewayUpstreamPattern = new RegExp("nan" + "go", "i");
const legacyRunxConnectPrivateUpstreamEnvPattern = new RegExp(`RUNX_CONNECT_${"NAN"}${"GO"}`);
const hostedOAuthAuthModePattern = /["']?auth_mode["']?\s*[:=]\s*["']oauth(?:_bearer)?["']/;
const legacyProviderReferenceValuePattern = new RegExp("\\bco" + "nn_[A-Za-z0-9_:-]+");
const forbiddenHostedConnectBrokerageTerms = [
{ name: "private provider gateway upstream", pattern: privateProviderGatewayUpstreamPattern },
{ name: literalName("oauth", "_required"), pattern: literalPattern("oauth", "_required") },
{ name: literalName("authorize", "_url"), pattern: literalPattern("authorize", "_url") },
{ name: literalName("Connect", "Session"), pattern: literalPattern("Connect", "Session") },
{ name: literalName("Hosted", "Provider", "Reference"), pattern: literalPattern("Hosted", "Provider", "Reference") },
{ name: literalName("connect", "-http"), pattern: literalPattern("connect", "-http") },
{ name: literalName("create", "Http", "Connect", "Service"), pattern: literalPattern("create", "Http", "Connect", "Service") },
{ name: "legacy private provider gateway env", pattern: legacyRunxConnectPrivateUpstreamEnvPattern },
{
name: literalName("RUNX_CONNECT_PROVIDER", "_GATEWAY"),
pattern: literalPattern("RUNX_CONNECT_PROVIDER", "_GATEWAY"),
},
];
const forbiddenHostedCredentialContractTerms = [
{ name: "hosted OAuth auth_mode", pattern: hostedOAuthAuthModePattern },
{ name: "legacy conn_ provider reference value", pattern: legacyProviderReferenceValuePattern },
{ name: literalName("opaque", "_connection"), pattern: literalPattern("opaque", "_connection") },
{ name: literalName("redact", "_connect", "_text"), pattern: literalPattern("redact", "_connect", "_text") },
{ name: literalName("credential_delivery", ".broker", "_response"), pattern: literalPattern("credential_delivery", "\\.broker", "_response") },
{ name: literalName("credential_delivery", "_broker", "_response"), pattern: literalPattern("credential_delivery", "_broker", "_response") },
{ name: literalName("credential-delivery", "-broker", "-response"), pattern: literalPattern("credential-delivery", "-broker", "-response") },
{ name: literalName("CredentialDelivery", "Broker", "Response"), pattern: literalPattern("CredentialDelivery", "Broker", "Response") },
];
const retiredCorePackageName = ["@runxhq", "core"].join("/");
const forbiddenPureNodeImports = new Set([
"fs",
"fs/promises",
"node:fs",
"node:fs/promises",
"path",
"node:path",
"child_process",
"node:child_process",
"http",
"node:http",
"https",
"node:https",
"net",
"node:net",
"tls",
"node:tls",
"dgram",
"node:dgram",
"dns",
"node:dns",
"worker_threads",
"node:worker_threads",
]);
const sunsetTsPackageNames = new Set(["runtime-local", "adapters"]);
const sunsetTsPackageImportPrefixes = ["@runxhq/runtime-local", "@runxhq/adapters"];
const forbiddenCompatibilityPackageNames = new Set([
"@runxhq/runtime-local-v2",
"@runxhq/adapters-v2",
"@runxhq/runtime-local-shim",
"@runxhq/adapters-shim",
"@runxhq/runtime-local-compat",
"@runxhq/adapters-compat",
"@runxhq/runtime-local-compatibility",
"@runxhq/adapters-compatibility",
"runtime-local-v2",
"adapters-v2",
"runtime-local-shim",
"adapters-shim",
"runtime-local-compat",
"adapters-compat",
"runtime-local-compatibility",
"adapters-compatibility",
]);
const forbiddenCompatibilityPackageDirectoryNames = new Set([
"runtime-local-v2",
"adapters-v2",
"runtime-local-shim",
"adapters-shim",
"runtime-local-compat",
"adapters-compat",
"runtime-local-compatibility",
"adapters-compatibility",
]);
const packageDependencyFields = ["dependencies", "devDependencies", "peerDependencies", "optionalDependencies"];
const aliasConfigFiles = ["tsconfig.base.json", "vitest.workspace-aliases.ts"];
const forbiddenPackageImports = {
"runtime-local": {
prefixes: [
"@runxhq/adapters",
"@runxhq/cli",
"@runxhq/host-adapters",
"@runxhq/langchain",
],
reason: "@runxhq/runtime-local must not depend on downstream adapters, CLI, or host packages.",
},
adapters: {
prefixes: [
"@runxhq/cli",
"@runxhq/host-adapters",
"@runxhq/langchain",
],
reason: "@runxhq/adapters must stay below host, CLI, and framework packages.",
},
"host-adapters": {
prefixes: [
"@runxhq/adapters",
"@runxhq/cli",
"@runxhq/langchain",
],
reason: "@runxhq/host-adapters must not depend on adapters, CLI, or framework packages.",
},
langchain: {
prefixes: [
"@runxhq/adapters",
"@runxhq/cli",
"@runxhq/host-adapters",
],
reason: "@runxhq/langchain must not depend on adapters, CLI, or host packages.",
},
};
const pureCoreDomains = ["parser", "policy", "state-machine"];
const relativeRuntimeDomainPattern = /(^|\/)(runner-local|harness|sdk|mcp)(\/|$)/;
const staticSpecifierPattern =
/\b(?:import|export)\s+(?:type\s+)?(?:[^'";]*?\s+from\s+)?["']([^"']+)["']|import\s*\(\s*["']([^"']+)["']\s*\)/g;
const findings = [];
const packageManifestCache = new Map();
const workspacePackageNames = await readWorkspacePackageNames();
await checkRetiredCorePackageDeleted();
await checkForbiddenCompatibilityPackages();
await checkForbiddenCompatibilityAliases();
await checkForbiddenHostedConnectBrokerage();
await checkForbiddenHostedCredentialContracts();
for (const filePath of await findSourceFiles(workspaceRoot)) {
await checkSourceFile(filePath);
}
if (findings.length > 0) {
console.error("Boundary check failed:");
for (const finding of findings) {
console.error(`- ${finding}`);
}
process.exit(1);
}
console.log("Boundary check passed.");
async function checkRetiredCorePackageDeleted() {
const corePackagePath = path.join(workspaceRoot, "packages", "core");
if (await statIfExists(corePackagePath)) {
findings.push(`packages/core still exists; ${retiredCorePackageName} is retired and must not be restored.`);
}
for (const sunsetPath of ["packages/runtime-local/package.json", "packages/adapters/package.json"]) {
if (await readJsonIfExists(path.join(workspaceRoot, sunsetPath))) {
findings.push(`${sunsetPath} still exists; local execution is Rust-owned.`);
}
}
}
async function checkForbiddenCompatibilityPackages() {
const packagesDir = path.join(workspaceRoot, "packages");
const manifestPaths = [path.join(workspaceRoot, "package.json")];
for (const entry of await readdir(packagesDir, { withFileTypes: true })) {
if (!entry.isDirectory()) {
continue;
}
if (forbiddenCompatibilityPackageDirectoryNames.has(entry.name)) {
findings.push(`packages/${entry.name} uses a compatibility package directory; runtime-local/adapters shims are not allowed.`);
}
if (sunsetTsPackageNames.has(entry.name)) {
findings.push(`packages/${entry.name} is a sunset TypeScript executor package and must be deleted.`);
}
manifestPaths.push(path.join(packagesDir, entry.name, "package.json"));
}
for (const manifestPath of manifestPaths) {
const manifest = await readJsonIfExists(manifestPath);
if (!manifest) {
continue;
}
const rel = toPosix(path.relative(workspaceRoot, manifestPath));
if (isForbiddenCompatibilityPackageName(manifest.name)) {
findings.push(`${rel} names ${manifest.name}; runtime-local/adapters compatibility packages are not allowed.`);
}
if (manifest.name === "@runxhq/runtime-local" || manifest.name === "@runxhq/adapters") {
findings.push(`${rel} names sunset TypeScript executor package ${manifest.name}.`);
}
for (const field of packageDependencyFields) {
const dependencies = manifest[field];
if (!dependencies || typeof dependencies !== "object" || Array.isArray(dependencies)) {
continue;
}
for (const dependencyName of Object.keys(dependencies)) {
if (isForbiddenCompatibilityPackageName(dependencyName)) {
findings.push(`${rel} declares ${dependencyName} in ${field}; runtime-local/adapters compatibility packages are not allowed.`);
}
}
}
}
}
async function checkForbiddenCompatibilityAliases() {
for (const relativePath of aliasConfigFiles) {
const absolutePath = path.join(workspaceRoot, relativePath);
const source = await readFile(absolutePath, "utf8");
if (relativePath.endsWith(".json")) {
checkJsonAliasConfig(relativePath, JSON.parse(source));
continue;
}
checkTextAliasConfig(relativePath, source);
}
}
function checkJsonAliasConfig(rel, config) {
const paths = config?.compilerOptions?.paths;
if (!paths || typeof paths !== "object" || Array.isArray(paths)) {
return;
}
for (const [alias, targets] of Object.entries(paths)) {
checkAliasToken(rel, alias);
const targetList = Array.isArray(targets) ? targets : [targets];
for (const target of targetList) {
if (typeof target === "string") {
checkAliasToken(rel, target);
}
}
}
}
function checkTextAliasConfig(rel, source) {
for (const token of extractStringLiterals(source)) {
checkAliasToken(rel, token);
}
}
function checkAliasToken(rel, token) {
const normalized = toPosix(token);
const packageName = packageSpecifierName(normalized.replace(/\/\*$/, ""));
if (isForbiddenCompatibilityPackageName(packageName)) {
findings.push(`${rel} aliases ${token}; runtime-local/adapters compatibility aliases are not allowed.`);
return;
}
for (const segment of normalized.split(/[\/\\]/)) {
if (forbiddenCompatibilityPackageDirectoryNames.has(segment)) {
findings.push(`${rel} aliases ${token}; runtime-local/adapters compatibility aliases are not allowed.`);
return;
}
}
}
async function checkForbiddenHostedConnectBrokerage() {
for (const rootName of hostedConnectBrokerageScanRoots) {
const rootPath = path.join(workspaceRoot, rootName);
const entry = await statIfExists(rootPath);
if (!entry?.isDirectory()) {
continue;
}
for (const filePath of await findActiveTypeScriptJavaScriptFiles(rootPath)) {
const rel = toPosix(path.relative(workspaceRoot, filePath));
checkForbiddenHostedConnectBrokerageInText(rel, rel, "path");
const source = await readFile(filePath, "utf8");
checkForbiddenHostedConnectBrokerageInSource(rel, source);
}
}
}
function checkForbiddenHostedConnectBrokerageInSource(rel, source) {
const lines = source.split(/\r?\n/);
for (const [index, line] of lines.entries()) {
checkForbiddenHostedConnectBrokerageInText(rel, line, `line ${index + 1}`);
}
}
function checkForbiddenHostedConnectBrokerageInText(rel, text, location) {
for (const term of forbiddenHostedConnectBrokerageTerms) {
if (term.pattern.test(text)) {
findings.push(`${rel} contains forbidden hosted connect/OAuth brokerage term ${term.name} in ${location}.`);
}
}
}
async function checkForbiddenHostedCredentialContracts() {
for (const rootName of hostedCredentialContractScanRoots) {
const rootPath = path.join(workspaceRoot, rootName);
const entry = await statIfExists(rootPath);
if (!entry?.isDirectory()) {
continue;
}
for (const filePath of await findActiveCredentialContractFiles(rootPath)) {
const rel = toPosix(path.relative(workspaceRoot, filePath));
const source = await readFile(filePath, "utf8");
const lines = source.split(/\r?\n/);
for (const [index, line] of lines.entries()) {
for (const term of forbiddenHostedCredentialContractTerms) {
if (term.pattern.test(line)) {
findings.push(`${rel} contains forbidden hosted OAuth credential contract term ${term.name} in line ${index + 1}.`);
}
}
}
}
}
}
async function checkSourceFile(filePath) {
const source = await readFile(filePath, "utf8");
const specifiers = extractSpecifiers(source);
const rel = toPosix(path.relative(workspaceRoot, filePath));
const packageSource = getPackageSource(rel);
for (const specifier of specifiers) {
if (specifierMatchesPackageName(specifier, retiredCorePackageName)) {
findings.push(`${rel} imports ${specifier}; ${retiredCorePackageName} is retired and must not be restored.`);
}
if (packageSource) {
if (!checkSurvivingTsPackageImport(rel, packageSource.packageName, specifier)) {
checkForbiddenPackageImport(rel, packageSource.packageName, specifier);
}
await checkDeclaredWorkspaceImport(rel, packageSource.packageName, specifier);
}
checkForbiddenCompatibilityImport(rel, specifier);
if (packageSource?.packageName === "core") {
checkCoreImport(rel, packageSource.domain, specifier);
}
if (rel.startsWith("packages/") && isCloudSpecifier(specifier)) {
findings.push(`${rel} imports cloud code; oss must not depend on cloud.`);
}
}
}
function checkCoreImport(rel, domain, specifier) {
if (specifier.startsWith(".") && relativeRuntimeDomainPattern.test(toPosix(path.normalize(path.join(path.dirname(rel), specifier))))) {
findings.push(`${rel} imports ${specifier}; core cannot reach removed runtime-local domains by relative path.`);
}
if (pureCoreDomains.includes(domain)) {
if (forbiddenPureNodeImports.has(specifier)) {
findings.push(`${rel} imports ${specifier}; ${domain} must remain pure and deterministic.`);
}
if (specifierTargetsDomain(rel, specifier, "executor") || specifierTargetsDomain(rel, specifier, "tool-catalogs")) {
findings.push(`${rel} imports ${specifier}; ${domain} cannot depend on execution or catalog boundaries.`);
}
}
if (domain === "executor") {
if (specifierTargetsDomain(rel, specifier, "adapters")) {
findings.push(`${rel} imports ${specifier}; executor must stay protocol-agnostic and avoid concrete adapters.`);
}
}
if (domain === "parser" && specifierTargetsDomain(rel, specifier, "adapters")) {
findings.push(`${rel} imports ${specifier}; parser cannot depend on concrete adapters.`);
}
}
function checkSurvivingTsPackageImport(rel, packageName, specifier) {
if (sunsetTsPackageNames.has(packageName)) {
return false;
}
if (sunsetTsPackageImportPrefixes.some((prefix) => specifierMatchesPackageName(specifier, prefix))) {
findings.push(`${rel} imports ${specifier}; surviving TypeScript packages must not depend on sunset @runxhq/runtime-local or @runxhq/adapters packages.`);
return true;
}
return false;
}
function checkForbiddenPackageImport(rel, packageName, specifier) {
const rule = forbiddenPackageImports[packageName];
if (!rule) {
return;
}
if (rule.prefixes.some((prefix) => specifierMatchesPackageName(specifier, prefix))) {
findings.push(`${rel} imports ${specifier}; ${rule.reason}`);
}
}
function checkForbiddenCompatibilityImport(rel, specifier) {
const packageName = packageSpecifierName(specifier);
if (isForbiddenCompatibilityPackageName(packageName)) {
findings.push(`${rel} imports ${specifier}; runtime-local/adapters compatibility packages are not allowed.`);
}
}
async function checkDeclaredWorkspaceImport(rel, packageName, specifier) {
const dependencyName = workspaceDependencyName(specifier);
if (!dependencyName || !workspacePackageNames.has(dependencyName)) {
return;
}
const manifest = await readPackageManifest(packageName);
if (!manifest || manifest.name === dependencyName) {
return;
}
if (packageName === "cli" && isNativeCliArtifactManifest(manifest)) {
return;
}
const declared = {
...manifest.dependencies,
...manifest.devDependencies,
...manifest.peerDependencies,
...manifest.optionalDependencies,
};
if (!Object.hasOwn(declared, dependencyName)) {
findings.push(`${rel} imports ${specifier}; ${manifest.name} must declare ${dependencyName} in package.json.`);
}
}
function isNativeCliArtifactManifest(manifest) {
const bin = typeof manifest.bin === "string" ? manifest.bin : manifest.bin?.runx;
const files = Array.isArray(manifest.files) ? manifest.files : [];
const includesFileOrDirectory = (entry) => files.includes(entry) || files.some((file) => file.startsWith(`${entry}/`));
return manifest.name === "@runxhq/cli"
&& bin === "./bin/runx"
&& includesFileOrDirectory("bin")
&& includesFileOrDirectory("native")
&& !files.includes("src")
&& !files.includes("dist")
&& !files.includes("tools");
}
function extractSpecifiers(source) {
const specifiers = [];
let match;
while ((match = staticSpecifierPattern.exec(source)) !== null) {
specifiers.push(match[1] ?? match[2]);
}
return specifiers;
}
function extractStringLiterals(source) {
const literals = [];
const stringLiteralPattern = /["']([^"']+)["']/g;
let match;
while ((match = stringLiteralPattern.exec(source)) !== null) {
literals.push(match[1]);
}
return literals;
}
function getPackageSource(rel) {
const parts = rel.split("/");
if (parts[0] !== "packages" || parts[2] !== "src") {
return undefined;
}
return {
packageName: parts[1],
domain: parts[3] ?? "",
};
}
function workspaceDependencyName(specifier) {
const match = /^(@runxhq\/[^/]+)/.exec(specifier);
return match?.[1];
}
function packageSpecifierName(specifier) {
if (specifier.startsWith(".")) {
return undefined;
}
const parts = specifier.split("/");
if (specifier.startsWith("@")) {
return parts.length >= 2 ? `${parts[0]}/${parts[1]}` : specifier;
}
return parts[0];
}
function specifierMatchesPackageName(specifier, packageName) {
return specifier === packageName || specifier.startsWith(`${packageName}/`);
}
function isForbiddenCompatibilityPackageName(packageName) {
return typeof packageName === "string" && forbiddenCompatibilityPackageNames.has(packageName);
}
async function readWorkspacePackageNames() {
const packagesDir = path.join(workspaceRoot, "packages");
const names = new Set();
for (const entry of await readdir(packagesDir, { withFileTypes: true })) {
if (!entry.isDirectory()) {
continue;
}
const manifest = await readPackageManifest(entry.name);
if (manifest?.name) {
names.add(manifest.name);
}
}
return names;
}
async function readPackageManifest(packageName) {
if (packageManifestCache.has(packageName)) {
return packageManifestCache.get(packageName);
}
const manifestPath = path.join(workspaceRoot, "packages", packageName, "package.json");
const manifest = await readJsonIfExists(manifestPath);
packageManifestCache.set(packageName, manifest);
return manifest;
}
function specifierTargetsDomain(rel, specifier, domain) {
if (specifier === `@runxhq/${domain}` || specifier.startsWith(`@runxhq/${domain}/`)) {
return true;
}
if (!specifier.startsWith(".")) {
return false;
}
const target = toPosix(path.normalize(path.join(path.dirname(rel), specifier)));
return target.split("/").includes(domain);
}
function isCloudSpecifier(specifier) {
return specifier === "cloud" || specifier.startsWith("cloud/") || specifier.includes("/cloud/");
}
async function findSourceFiles(root) {
const files = [];
await walk(root, files);
return files;
}
async function findActiveTypeScriptJavaScriptFiles(root) {
const files = [];
await walkActiveTypeScriptJavaScript(root, files);
return files;
}
async function findActiveCredentialContractFiles(root) {
const files = [];
await walkActiveCredentialContract(root, files);
return files;
}
async function walkActiveTypeScriptJavaScript(directory, files) {
for (const entry of await readdir(directory, { withFileTypes: true })) {
if (entry.isDirectory()) {
if (!isIgnoredDirectoryName(entry.name)) {
await walkActiveTypeScriptJavaScript(path.join(directory, entry.name), files);
}
continue;
}
if (!entry.isFile() || !activeTypeScriptJavaScriptExtensions.has(path.extname(entry.name))) {
continue;
}
const filePath = path.join(directory, entry.name);
if (path.resolve(filePath) === boundaryGuardPath) {
continue;
}
files.push(filePath);
}
}
async function walkActiveCredentialContract(directory, files) {
for (const entry of await readdir(directory, { withFileTypes: true })) {
if (entry.isDirectory()) {
if (!isIgnoredDirectoryName(entry.name)) {
await walkActiveCredentialContract(path.join(directory, entry.name), files);
}
continue;
}
if (!entry.isFile() || !activeCredentialContractExtensions.has(path.extname(entry.name))) {
continue;
}
const filePath = path.join(directory, entry.name);
if (path.resolve(filePath) === boundaryGuardPath) {
continue;
}
files.push(filePath);
}
}
async function walk(directory, files) {
for (const entry of await readdir(directory, { withFileTypes: true })) {
if (entry.isDirectory()) {
if (!isIgnoredDirectoryName(entry.name)) {
await walk(path.join(directory, entry.name), files);
}
continue;
}
if (!entry.isFile() || !sourceExtensions.has(path.extname(entry.name)) || isTestFile(entry.name)) {
continue;
}
files.push(path.join(directory, entry.name));
}
}
async function statIfExists(filePath) {
try {
return await stat(filePath);
} catch (error) {
if (isNotFound(error)) {
return undefined;
}
throw error;
}
}
async function readJsonIfExists(filePath) {
let contents;
try {
contents = await readFile(filePath, "utf8");
} catch (error) {
if (isNotFound(error)) {
return undefined;
}
throw error;
}
return JSON.parse(contents);
}
function isNotFound(error) {
return Boolean(error && typeof error === "object" && "code" in error && error.code === "ENOENT");
}
function isTestFile(fileName) {
return /\.(test|spec)\.(ts|tsx|mts|cts)$/.test(fileName);
}
function isIgnoredDirectoryName(name) {
return ignoredDirectoryNames.has(name) || name.startsWith("target-");
}
function toPosix(input) {
return input.split(path.sep).join("/");
}