From 4e5f25206a416177fdc8e3ff0a7bb4dfa7ef8e11 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Tue, 19 Jan 2021 14:45:03 +0000 Subject: [PATCH] Ensure component index has been written before renaming This ensures we correctly wait for `component-index.js.tmp` to be written to disk before trying to rename into place. This fixes an issue where stray temp files were being strewn about the repos after renaming failures. --- scripts/reskindex.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/reskindex.js b/scripts/reskindex.js index e3ebefd78d..1770073aad 100755 --- a/scripts/reskindex.js +++ b/scripts/reskindex.js @@ -2,6 +2,7 @@ const fs = require('fs'); const path = require('path'); const glob = require('glob'); +const util = require('util'); const args = require('minimist')(process.argv); const chokidar = require('chokidar'); @@ -12,7 +13,7 @@ const componentJsGlob = '**/*.js'; const componentTsGlob = '**/*.tsx'; let prevFiles = []; -function reskindex() { +async function reskindex() { const jsFiles = glob.sync(componentJsGlob, {cwd: componentsDir}).sort(); const tsFiles = glob.sync(componentTsGlob, {cwd: componentsDir}).sort(); const files = [...tsFiles, ...jsFiles]; @@ -51,7 +52,8 @@ function reskindex() { } strm.write("export {components};\n"); - strm.end(); + // Ensure the file has been fully written to disk before proceeding + await util.promisify(strm.end); fs.rename(componentIndexTmp, componentIndex, function(err) { if (err) { console.error("Error moving new index into place: " + err);