Skip to content
Permalink
Browse files
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.
  • Loading branch information
raphinesse committed Apr 14, 2019
1 parent 07cddfc commit e0c4a95eebf855c75163ec8033596ca26bea6ccc
Showing 2 changed files with 11 additions and 10 deletions.
@@ -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",
@@ -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;

0 comments on commit e0c4a95

Please sign in to comment.