From b0a549923f6b007e5863e9d3e17dd855e18548fe Mon Sep 17 00:00:00 2001 From: Jordan Pittman Date: Fri, 26 Aug 2022 14:35:08 -0400 Subject: [PATCH] Handle when `watchedPath` is a file and not directory --- src/cli.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cli.js b/src/cli.js index e8beca6e6..0797be2f2 100644 --- a/src/cli.js +++ b/src/cli.js @@ -904,11 +904,11 @@ async function build() { * @throws {Error} If the file is still missing or busy after the specified number of tries */ async function readFileWithRetries(path, tries = 5) { - for (let n = 0; n < tries; n++) { + for (let n = 0; n <= tries; n++) { try { return await fs.promises.readFile(path, 'utf8') } catch (err) { - if (n < tries) { + if (n !== tries) { if (err.code === 'ENOENT' || err.code === 'EBUSY') { await new Promise((resolve) => setTimeout(resolve, 10)) @@ -935,7 +935,11 @@ async function build() { return } - filePath = path.resolve(meta.watchedPath, filePath) + let watchedPath = path.resolve(meta.watchedPath) + + // Watched path might be the file itself + // Or the directory it is in + filePath = watchedPath.endsWith(filePath) ? watchedPath : path.resolve(watchedPath, filePath) // Skip since we've already queued a rebuild for this file that hasn't happened yet if (pendingRebuilds.has(filePath)) {