From 776bf561947e0e6d1d82b8e73686452426539aa2 Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Fri, 18 Nov 2022 23:22:24 +0000 Subject: [PATCH 1/3] Fix dangling promise introduced in #33979 Co-authored-by: hyrious --- npm/install.js | 42 +++++++++++++++++++----------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/npm/install.js b/npm/install.js index 864ca633fd30f..a373670937f9e 100755 --- a/npm/install.js +++ b/npm/install.js @@ -70,29 +70,25 @@ function isInstalled () { // unzips and makes path.txt point at the correct executable function extractFile (zipPath) { - return new Promise((resolve, reject) => { - const distPath = process.env.ELECTRON_OVERRIDE_DIST_PATH || path.join(__dirname, 'dist'); - - extract(zipPath, { dir: path.join(__dirname, 'dist') }) - .then(() => { - // If the zip contains an "electron.d.ts" file, - // move that up - const srcTypeDefPath = path.join(distPath, 'electron.d.ts'); - const targetTypeDefPath = path.join(__dirname, 'electron.d.ts'); - const hasTypeDefinitions = fs.existsSync(srcTypeDefPath); - - if (hasTypeDefinitions) { - try { - fs.renameSync(srcTypeDefPath, targetTypeDefPath); - } catch (err) { - reject(err); - } - } - - // Write a "path.txt" file. - return fs.promises.writeFile(path.join(__dirname, 'path.txt'), platformPath); - }) - .catch((err) => reject(err)); + const distPath = process.env.ELECTRON_OVERRIDE_DIST_PATH || path.join(__dirname, 'dist'); + + return extract(zipPath, { dir: path.join(__dirname, 'dist') }).then(() => { + // If the zip contains an "electron.d.ts" file, + // move that up + const srcTypeDefPath = path.join(distPath, 'electron.d.ts'); + const targetTypeDefPath = path.join(__dirname, 'electron.d.ts'); + const hasTypeDefinitions = fs.existsSync(srcTypeDefPath); + + if (hasTypeDefinitions) { + try { + fs.renameSync(srcTypeDefPath, targetTypeDefPath); + } catch (err) { + reject(err); + } + } + + // Write a "path.txt" file. + return fs.promises.writeFile(path.join(__dirname, 'path.txt'), platformPath); }); } From 424a1d133486a5b8a25e459a76328137f6d8a50f Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Fri, 18 Nov 2022 23:22:26 +0000 Subject: [PATCH 2/3] fix reject in callback Co-authored-by: hyrious --- npm/install.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/npm/install.js b/npm/install.js index a373670937f9e..7f1fa23d7d723 100755 --- a/npm/install.js +++ b/npm/install.js @@ -83,7 +83,7 @@ function extractFile (zipPath) { try { fs.renameSync(srcTypeDefPath, targetTypeDefPath); } catch (err) { - reject(err); + throw err; } } From 2efdc85e9b8bd7abb6a7703e3077d9415cf532ba Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Fri, 18 Nov 2022 23:22:32 +0000 Subject: [PATCH 3/3] simplify code Co-authored-by: Black-Hole <158blackhole@gmail.com> Co-authored-by: hyrious --- npm/install.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/npm/install.js b/npm/install.js index 7f1fa23d7d723..8fb438ecace25 100755 --- a/npm/install.js +++ b/npm/install.js @@ -80,11 +80,7 @@ function extractFile (zipPath) { const hasTypeDefinitions = fs.existsSync(srcTypeDefPath); if (hasTypeDefinitions) { - try { - fs.renameSync(srcTypeDefPath, targetTypeDefPath); - } catch (err) { - throw err; - } + fs.renameSync(srcTypeDefPath, targetTypeDefPath); } // Write a "path.txt" file.