You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ra...@apache.org on 2019/04/14 10:45:54 UTC

[cordova-lib] branch master updated: Proper async code in src/plugman/createpackagejson.js (#768)

This is an automated email from the ASF dual-hosted git repository.

raphinesse pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-lib.git


The following commit(s) were added to refs/heads/master by this push:
     new e0c4a95  Proper async code in src/plugman/createpackagejson.js (#768)
e0c4a95 is described below

commit e0c4a95eebf855c75163ec8033596ca26bea6ccc
Author: Raphael von der GrĂ¼n <ra...@gmail.com>
AuthorDate: Sun Apr 14 12:45:49 2019 +0200

    Proper async code in src/plugman/createpackagejson.js (#768)
    
    The existing code returned an instantly resolved promise despite the fact that it was doing async operations.
---
 package.json                     |  1 +
 src/plugman/createpackagejson.js | 20 ++++++++++----------
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/package.json b/package.json
index b860fd8..6ab84e4 100644
--- a/package.json
+++ b/package.json
@@ -29,6 +29,7 @@
     "indent-string": "^3.2.0",
     "init-package-json": "^1.10.3",
     "md5-file": "^4.0.0",
+    "pify": "^4.0.1",
     "read-chunk": "^3.1.0",
     "semver": "^5.6.0",
     "shebang-command": "^1.2.0",
diff --git a/src/plugman/createpackagejson.js b/src/plugman/createpackagejson.js
index 4fa92f4..f417210 100644
--- a/src/plugman/createpackagejson.js
+++ b/src/plugman/createpackagejson.js
@@ -21,7 +21,8 @@ var fs = require('fs-extra');
 var path = require('path');
 var PluginInfo = require('cordova-common').PluginInfo;
 var events = require('cordova-common').events;
-var init = require('init-package-json');
+const pify = require('pify');
+const initPkgJson = pify(require('init-package-json'));
 
 // returns a promise
 function createPackageJson (plugin_path) {
@@ -39,18 +40,17 @@ function createPackageJson (plugin_path) {
         platforms: pluginInfo.getPlatformsArray()
     };
 
-    fs.writeFile(path.join(__dirname, 'defaults.json'), JSON.stringify(defaults), 'utf8', function (err) {
-        if (err) throw err;
-        events.emit('verbose', 'defaults.json created from plugin.xml');
-        var initFile = require.resolve('./init-defaults');
-        var dir = process.cwd();
+    return fs.writeFile(path.join(__dirname, 'defaults.json'), JSON.stringify(defaults), 'utf8')
+        .then(_ => {
+            events.emit('verbose', 'defaults.json created from plugin.xml');
 
-        init(dir, initFile, {}, function (err, data) {
-            if (err) throw err;
+            var initFile = require.resolve('./init-defaults');
+            var dir = process.cwd();
+            return initPkgJson(dir, initFile, {});
+        })
+        .then(_ => {
             events.emit('verbose', 'Package.json successfully created');
         });
-    });
-    return Promise.resolve();
 }
 
 module.exports = createPackageJson;


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org