Browse Source

chore: fix dangling promise in npm install (#36398)

* Fix dangling promise introduced in #33979

Co-authored-by: hyrious <[email protected]>

* fix reject in callback

Co-authored-by: hyrious <[email protected]>

* simplify code

Co-authored-by: Black-Hole <[email protected]>

Co-authored-by: hyrious <[email protected]>

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: hyrious <[email protected]>
trop[bot] 2 years ago
parent
commit
02eef17791
1 changed files with 15 additions and 23 deletions
  1. 15 23
      npm/install.js

+ 15 - 23
npm/install.js

@@ -70,29 +70,21 @@ 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) {
+      fs.renameSync(srcTypeDefPath, targetTypeDefPath);
+    }
+
+    // Write a "path.txt" file.
+    return fs.promises.writeFile(path.join(__dirname, 'path.txt'), platformPath);
   });
 }