|
1 | 1 | #!/usr/bin/env node |
| 2 | +import { spawnSync } from "node:child_process"; |
2 | 3 | import fs from "node:fs"; |
3 | 4 | import path from "node:path"; |
4 | 5 | import { fileURLToPath } from "node:url"; |
@@ -64,13 +65,83 @@ function walkFiles(rootDir) { |
64 | 65 | } |
65 | 66 |
|
66 | 67 | export function collectAllLiveTestFiles(repoRoot = process.cwd()) { |
| 68 | + const externalFiles = listExternalLiveTestFiles(repoRoot); |
| 69 | + if (externalFiles) { |
| 70 | + return externalFiles; |
| 71 | + } |
67 | 72 | return ["src", "test", "extensions"] |
68 | 73 | .flatMap((dir) => walkFiles(path.join(repoRoot, dir))) |
69 | 74 | .map((file) => path.relative(repoRoot, file).split(path.sep).join("/")) |
70 | 75 | .filter((file) => file.endsWith(LIVE_TEST_SUFFIX)) |
71 | 76 | .toSorted((a, b) => a.localeCompare(b)); |
72 | 77 | } |
73 | 78 |
|
| 79 | +function listExternalLiveTestFiles(repoRoot) { |
| 80 | + return listGitLiveTestFiles(repoRoot) ?? listFindLiveTestFiles(repoRoot); |
| 81 | +} |
| 82 | + |
| 83 | +function listGitLiveTestFiles(repoRoot) { |
| 84 | + const result = spawnSync("git", ["ls-files", "--", "src", "test", "extensions"], { |
| 85 | + cwd: repoRoot, |
| 86 | + encoding: "utf8", |
| 87 | + maxBuffer: 1024 * 1024 * 4, |
| 88 | + stdio: ["ignore", "pipe", "ignore"], |
| 89 | + }); |
| 90 | + if (result.status !== 0) { |
| 91 | + return null; |
| 92 | + } |
| 93 | + return result.stdout |
| 94 | + .split("\n") |
| 95 | + .map((line) => line.trim()) |
| 96 | + .filter((file) => file.endsWith(LIVE_TEST_SUFFIX)) |
| 97 | + .toSorted((a, b) => a.localeCompare(b)); |
| 98 | +} |
| 99 | + |
| 100 | +function listFindLiveTestFiles(repoRoot) { |
| 101 | + const roots = ["src", "test", "extensions"].map((dir) => path.join(repoRoot, dir)); |
| 102 | + const result = spawnSync( |
| 103 | + "find", |
| 104 | + [ |
| 105 | + ...roots, |
| 106 | + "(", |
| 107 | + "-name", |
| 108 | + "node_modules", |
| 109 | + "-o", |
| 110 | + "-name", |
| 111 | + "dist", |
| 112 | + "-o", |
| 113 | + "-name", |
| 114 | + "vendor", |
| 115 | + "-o", |
| 116 | + "-name", |
| 117 | + "fixtures", |
| 118 | + ")", |
| 119 | + "-prune", |
| 120 | + "-o", |
| 121 | + "-type", |
| 122 | + "f", |
| 123 | + "-name", |
| 124 | + `*${LIVE_TEST_SUFFIX}`, |
| 125 | + "-print", |
| 126 | + ], |
| 127 | + { |
| 128 | + cwd: repoRoot, |
| 129 | + encoding: "utf8", |
| 130 | + maxBuffer: 1024 * 1024 * 4, |
| 131 | + stdio: ["ignore", "pipe", "ignore"], |
| 132 | + }, |
| 133 | + ); |
| 134 | + if (result.status !== 0) { |
| 135 | + return null; |
| 136 | + } |
| 137 | + return result.stdout |
| 138 | + .split("\n") |
| 139 | + .map((line) => line.trim()) |
| 140 | + .filter((file) => file.length > 0) |
| 141 | + .map((file) => path.relative(repoRoot, file).split(path.sep).join("/")) |
| 142 | + .toSorted((a, b) => a.localeCompare(b)); |
| 143 | +} |
| 144 | + |
74 | 145 | function extensionKey(file) { |
75 | 146 | const relative = file.slice("extensions/".length); |
76 | 147 | return relative.split("/", 1)[0]?.toLowerCase() ?? ""; |
|
0 commit comments