(root: string)
| 229 | // pages/, every script, as pages/__tests__/user.test.js. It follows a link |
| 230 | // to a directory, so the read does too |
| 231 | const treeOf = (root: string): Tree => { |
| 232 | const tree: Tree = { scripts: [], foreign: undefined } |
| 233 | const scripts = new Set<string>() |
| 234 | // each directory as each kind it's walked as, as a link may lead into one |
| 235 | // walked otherwise, or around to one it's in |
| 236 | const walked = new Set<string>() |
| 237 | const routes = routeDirs.map(dir => join(root, dir)) |
| 238 | const pages = pagesDirs.map(dir => join(root, dir)) |
| 239 | const isUnder = (path: string, dirs: string[]) => |
| 240 | dirs.some(dir => path === dir || path.startsWith(`${dir}${sep}`)) |
| 241 | // a file reached through a link is read as Turbopack reads it, by where it is |
| 242 | const walk = (dir: string, isLinked: boolean) => { |
| 243 | const isRoot = dir === root |
| 244 | const isRoutes = isUnder(dir, routes) |
| 245 | const isPages = isUnder(dir, pages) |
| 246 | const key = `${isRoot}${isRoutes}${isPages}${realPathOf(dir)}` |
| 247 | if (walked.has(key)) return |
| 248 | walked.add(key) |
| 249 | for (const entry of readdirSync(dir, { withFileTypes: true })) { |
| 250 | const path = join(dir, entry.name) |
| 251 | const isLink = entry.isSymbolicLink() |
| 252 | const stats = isLink ? statOf(path) : entry |
| 253 | if (!stats || entry.name === "node_modules") continue |
| 254 | if (!isPages) { |
| 255 | if (entry.name.startsWith(".") && (isRoot || !isRoutes)) continue |
| 256 | if (isRoot && skippedAtRoot.has(entry.name)) continue |
| 257 | } |
| 258 | if (stats.isDirectory()) { |
| 259 | if (isPages || !testDirs.has(entry.name)) walk(path, isLinked || isLink) |
| 260 | } else if (stats.isFile()) { |
| 261 | if (scriptFile.test(entry.name)) { |
| 262 | if ( |
| 263 | !declarationFile.test(entry.name) && |
| 264 | (isPages || !unbuiltFile.test(entry.name)) |
| 265 | ) |
| 266 | scripts.add(isLinked || isLink ? realPathOf(path) : path) |
| 267 | } else if (foreignFile.test(entry.name)) tree.foreign ??= path |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | walk(root, false) |
| 272 | tree.scripts = [...scripts].sort() |
| 273 | return tree |
| 274 | } |
| 275 | |
| 276 | // what a link points to, or nothing where it points nowhere |
| 277 | const statOf = (path: string) => { |
no test coverage detected