You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2018/09/05 22:25:20 UTC

[GitHub] raphinesse closed pull request #196: GH-195: Ensure synchronous operation

raphinesse closed pull request #196: GH-195: Ensure synchronous operation
URL: https://github.com/apache/cordova-coho/pull/196
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/spec/versionutil.spec.js b/spec/versionutil.spec.js
index 7c1c04d81..c84d342fb 100644
--- a/spec/versionutil.spec.js
+++ b/spec/versionutil.spec.js
@@ -22,6 +22,7 @@ var jasmine_co = require('jasmine-co').install();
 var fs = require('fs');
 var path = require('path');
 var shell = require('shelljs');
+var xml2js = require('xml2js');
 var repoutil = require('../src/repoutil');
 var executil = require('../src/executil');
 var gitutil = require('../src/gitutil');
@@ -58,7 +59,8 @@ describe("Correct version is passed to gradle.build", function () {
 	var shellSpy;
 	beforeEach(function* () {
 		spyOn(fs, 'writeFileSync').and.returnValue(true);
-		spyOn(fs, 'readFile').and.returnValue(true);
+		spyOn(fs, 'readFileSync').and.returnValue("{}");
+		spyOn(xml2js, 'parseString').and.returnValue(true);
 		spyOn(fs,'existsSync').and.returnValue(true);
 		shellSpy = spyOn(shell,'sed').and.returnValue(true);
 		spyOn(apputil, 'print').and.returnValue(true);
@@ -73,7 +75,7 @@ describe("Correct version is passed to gradle.build", function () {
 
 	afterEach(function () {
 		fs.writeFileSync.calls.reset();
-		fs.readFile.calls.reset();
+		fs.readFileSync.calls.reset();
 		fs.existsSync.calls.reset();
 		shell.sed.calls.reset();
 		apputil.print.calls.reset();
@@ -85,9 +87,9 @@ describe("Correct version is passed to gradle.build", function () {
 	it("Test#001 : checks that the correct android version is passed in", function* () {
 		var androidVersion = yield versionutil.updateRepoVersion(androidRepo, "6.4.0-dev");
 		// Check call count
-		expect(fs.writeFileSync.calls.count()).toEqual(1);
+		expect(fs.writeFileSync.calls.count()).toEqual(2);
 		expect(fs.existsSync.calls.count()).toEqual(4);
-		expect(fs.readFile.calls.count()).toEqual(3);
+		expect(fs.readFileSync.calls.count()).toEqual(3);
 		expect(repoutil.isInRepoGroup.calls.count()).toEqual(2);
 		expect(repoutil.isInRepoGroup.calls.count()).toEqual(2);
 		expect(gitutil.pendingChangesExist.calls.count()).toEqual(4);
@@ -105,10 +107,10 @@ describe("Correct version is passed to gradle.build", function () {
 	it("Test#002 : checks that the correct ios version is passed in", function* () {
 		var iosVersion = yield versionutil.updateRepoVersion(iosRepo, "4.2.0-dev");
 		// Check call count
-		expect(fs.writeFileSync.calls.count()).toEqual(1);
+		expect(fs.writeFileSync.calls.count()).toEqual(2);
 		expect(fs.existsSync.calls.count()).toEqual(4);
 		expect(repoutil.isInRepoGroup.calls.count()).toEqual(2);
-		expect(fs.readFile.calls.count()).toEqual(3);
+		expect(fs.readFileSync.calls.count()).toEqual(3);
 		expect(gitutil.pendingChangesExist.calls.count()).toEqual(4);
 		expect(shell.sed.calls.count()).toEqual(1);
 		expect(apputil.print.calls.count()).toEqual(0);
@@ -120,11 +122,11 @@ describe("Correct version is passed to gradle.build", function () {
 	it("Test#003 : checks that the correct windows version is passed in", function* () {
 		var windowsVersion = yield versionutil.updateRepoVersion(windowsRepo, "4.5.0-dev");
 		// Check call count
-		expect(fs.writeFileSync.calls.count()).toEqual(1);
+		expect(fs.writeFileSync.calls.count()).toEqual(2);
 		expect(fs.existsSync.calls.count()).toEqual(5);
 		expect(repoutil.isInRepoGroup.calls.count()).toEqual(2);
 		expect(gitutil.pendingChangesExist.calls.count()).toEqual(4);
-		expect(fs.readFile.calls.count()).toEqual(3);
+		expect(fs.readFileSync.calls.count()).toEqual(3);
 		expect(shell.sed.calls.count()).toEqual(1);
 		expect(apputil.print.calls.count()).toEqual(0);
 		expect(executil.execHelper.calls.count()).toEqual(1);
@@ -135,11 +137,11 @@ describe("Correct version is passed to gradle.build", function () {
 	it("Test#004 : check that the correct browser version is passed in", function* () {
 		var browserVersion = yield versionutil.updateRepoVersion(browserRepo, "4.1.0-dev");
 		//Check call count
-		expect(fs.writeFileSync.calls.count()).toEqual(1);
+		expect(fs.writeFileSync.calls.count()).toEqual(2);
 		expect(fs.existsSync.calls.count()).toEqual(5);
 		expect(repoutil.isInRepoGroup.calls.count()).toEqual(2);
 		expect(gitutil.pendingChangesExist.calls.count()).toEqual(4);
-		expect(fs.readFile.calls.count()).toEqual(3);
+		expect(fs.readFileSync.calls.count()).toEqual(3);
 		expect(shell.sed.calls.count()).toEqual(1);
 		expect(apputil.print.calls.count()).toEqual(0);
 		expect(executil.execHelper.calls.count()).toEqual(1);
diff --git a/src/versionutil.js b/src/versionutil.js
index 7c1909939..9dedbcd89 100644
--- a/src/versionutil.js
+++ b/src/versionutil.js
@@ -131,13 +131,11 @@ exports.updateRepoVersion = function * updateRepoVersion (repo, version, opts) {
     // Update the package.json VERSION.
     var packageFilePaths = repo.packageFilePaths || ['package.json'];
     if (fs.existsSync(packageFilePaths[0])) {
-        fs.readFile(packageFilePaths[0], {encoding: 'utf-8'}, function (err, data) {
-            if (err) throw err;
-            var packageJSON = JSON.parse(data);
-            packageJSON.version = version;
-            // use 2 spaces indent similar to npm
-            fs.writeFileSync(packageFilePaths[0], JSON.stringify(packageJSON, null, 2) + '\n');
-        });
+        var data = fs.readFileSync(packageFilePaths[0], {encoding: 'utf-8'});
+        var packageJSON = JSON.parse(data);
+        packageJSON.version = version;
+        // use 2 spaces indent similar to npm
+        fs.writeFileSync(packageFilePaths[0], JSON.stringify(packageJSON, null, 2) + '\n');
         if (!(yield gitutil.pendingChangesExist())) {
             apputil.print('package.json file was already up-to-date.');
         }
@@ -151,13 +149,11 @@ exports.updateRepoVersion = function * updateRepoVersion (repo, version, opts) {
         var xmlFilePaths = repo.xmlFilePaths || ['plugin.xml', 'tests/plugin.xml'];
         xmlFilePaths.forEach(function (xmlFile) {
             if (fs.existsSync(xmlFile)) {
-                fs.readFile(xmlFile, {encoding: 'utf-8'}, function (err, data) {
+                var data = fs.readFileSync(xmlFile, {encoding: 'utf-8'});
+                xml2js.parseString(data, {async: false}, function (err, xml) {
                     if (err) throw err;
-                    xml2js.parseString(data, function (err, xml) {
-                        if (err) throw err;
-                        var prev_version = xml.plugin['$'].version;
-                        shelljs.sed('-i', new RegExp('version="' + prev_version + '"', 'i'), 'version="' + version + '"', xmlFile);
-                    });
+                    var prev_version = xml.plugin['$'].version;
+                    shelljs.sed('-i', new RegExp('version="' + prev_version + '"', 'i'), 'version="' + version + '"', xmlFile);
                 });
             } else {
                 console.warn('No ' + xmlFile + ' file exists in repo ' + repo.repoName);


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

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