mirror of
https://github.com/vercel/next.js.git
synced 2026-09-20 02:25:18 +08:00
007058ef60
Follow-up to #96860, addressing @lukesandberg's review. That PR moved `devlow-bench` into `packages/`, where the root eslint config applies for the first time, and exempted the package from the three rules it didn't satisfy rather than fixing the violations. This drops the exemption block: - **`import/no-extraneous-dependencies`** — had no violations. The exemption was unnecessary. - **`@typescript-eslint/consistent-type-imports`** — 13 violations, all autofixable. - **`@typescript-eslint/no-shadow`** — 17 violations, renamed by hand. The shadow fixes are mostly loop variables and callback parameters that restated their outer binding. Two worth a look: - `table.ts` — `getValue(data, ...)` took a single entry but shadowed the `data` array it indexes into. Renamed the parameter to `entry`, and the `row`/`column` grouping keys to `rowKey`/`columnKey` so the loop variables can keep the shorter names. - `shell.ts` — `command(command, args)` shadowed the exported function with its own first parameter. Renamed to `executable`, which also fixes the `[SHELL]` debug log that was interpolating the function rather than the argument. ## Verification - `eslint` clean under both the root config and the package's own `lint` script - `tsc` compiles, `pnpm run --filter=devlow-bench test` 3/3 - prettier clean <!-- NEXT_JS_LLM --> --------- Co-authored-by: Luke Sandberg <lukesandberg@users.noreply.github.com>
61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import { watch } from 'fs'
|
|
import { access, constants } from 'fs/promises'
|
|
import { dirname } from 'path'
|
|
|
|
export async function waitForFile(
|
|
path: string,
|
|
timeout: number
|
|
): Promise<void> {
|
|
let currentAction = ''
|
|
let timeoutRef
|
|
const timeoutPromise = new Promise<void>((_resolve, reject) => {
|
|
timeoutRef = setTimeout(() => {
|
|
reject(
|
|
new Error(`Timed out waiting for file ${path} (${currentAction}))`)
|
|
)
|
|
}, timeout || 60000)
|
|
})
|
|
const elements: string[] = []
|
|
let current = path
|
|
while (true) {
|
|
elements.push(current)
|
|
const parent = dirname(current)
|
|
if (parent === current) {
|
|
break
|
|
}
|
|
current = parent
|
|
}
|
|
elements.reverse()
|
|
try {
|
|
for (const element of elements) {
|
|
const checkAccess = () =>
|
|
access(element, constants.F_OK)
|
|
.then(() => true)
|
|
.catch(() => false)
|
|
if (!(await checkAccess())) {
|
|
let resolveCheckAgain = () => {}
|
|
const watcher = watch(dirname(element), () => {
|
|
resolveCheckAgain()
|
|
})
|
|
currentAction = `waiting for ${element}`
|
|
let checkAgainPromise = new Promise<void>((resolve) => {
|
|
resolveCheckAgain = resolve
|
|
})
|
|
try {
|
|
do {
|
|
await Promise.race([timeoutPromise, checkAgainPromise])
|
|
// eslint-disable-next-line no-loop-func
|
|
checkAgainPromise = new Promise<void>((resolve) => {
|
|
resolveCheckAgain = resolve
|
|
})
|
|
} while (!(await checkAccess()))
|
|
} finally {
|
|
watcher.close()
|
|
}
|
|
}
|
|
}
|
|
} finally {
|
|
clearTimeout(timeoutRef)
|
|
}
|
|
}
|