| 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 |