Skip to content

Commit 6bba239

Browse files
authored
refactor: js_run_devserver file deletions based on watch protocol (#2271)
1 parent b7e014a commit 6bba239

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

js/private/js_run_devserver.mjs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,6 @@ async function runWatchProtocol(
650650
}
651651

652652
async function watchProtocolCycle(config, entriesPath, sandbox, cycle) {
653-
const oldFiles = config.previous_entries || []
654-
655653
// Re-parse the config file to get the latest list of data files to copy
656654
const newFiles = await fs.promises.readFile(entriesPath).then(JSON.parse)
657655

@@ -660,21 +658,26 @@ async function watchProtocolCycle(config, entriesPath, sandbox, cycle) {
660658
cycle.sources.hasOwnProperty(`${JS_BINARY__WORKSPACE}/${f}`)
661659
)
662660

663-
await Promise.all([
664-
// Remove files that were previously synced but are no longer in the updated list of files to sync
665-
deleteFiles(oldFiles, newFiles, sandbox),
661+
// The files marked for deletion in this cycle
662+
const toDelete = []
663+
for (const l in cycle.sources) {
664+
if (cycle.sources[l] === null) {
665+
toDelete.push([
666+
l.slice(JS_BINARY__WORKSPACE.length + 1),
667+
/*isDirectory=*/ false,
668+
])
669+
}
670+
}
666671

667-
// Sync changed files
672+
await Promise.all([
673+
deleteFiles(toDelete, [], sandbox),
668674
syncFiles(
669675
filesToSync,
670676
sandbox,
671677
config.grant_sandbox_write_permissions,
672678
cycleSyncRecurse.bind(null, cycle)
673679
),
674680
])
675-
676-
// The latest state of copied data files
677-
config.previous_entries = newFiles
678681
}
679682

680683
async function cycleSyncRecurse(cycle, file, isDirectory, sandbox, writePerm) {

0 commit comments

Comments
 (0)