Skip to content

Commit b0a5499

Browse files
committed
Handle when watchedPath is a file and not directory
1 parent ad7dbda commit b0a5499

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/cli.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,11 +904,11 @@ async function build() {
904904
* @throws {Error} If the file is still missing or busy after the specified number of tries
905905
*/
906906
async function readFileWithRetries(path, tries = 5) {
907-
for (let n = 0; n < tries; n++) {
907+
for (let n = 0; n <= tries; n++) {
908908
try {
909909
return await fs.promises.readFile(path, 'utf8')
910910
} catch (err) {
911-
if (n < tries) {
911+
if (n !== tries) {
912912
if (err.code === 'ENOENT' || err.code === 'EBUSY') {
913913
await new Promise((resolve) => setTimeout(resolve, 10))
914914

@@ -935,7 +935,11 @@ async function build() {
935935
return
936936
}
937937

938-
filePath = path.resolve(meta.watchedPath, filePath)
938+
let watchedPath = path.resolve(meta.watchedPath)
939+
940+
// Watched path might be the file itself
941+
// Or the directory it is in
942+
filePath = watchedPath.endsWith(filePath) ? watchedPath : path.resolve(watchedPath, filePath)
939943

940944
// Skip since we've already queued a rebuild for this file that hasn't happened yet
941945
if (pendingRebuilds.has(filePath)) {

0 commit comments

Comments
 (0)