From 40f3267e68ab2ce0dcd3e2f882ee84897d346976 Mon Sep 17 00:00:00 2001 From: Steven McDowall Date: Wed, 9 Sep 2015 09:23:33 -0400 Subject: [PATCH] Make logic even easier across all platforms and modify tests to suit new logic --- lib/update-package.js | 16 +++++----------- test/update-package.js | 4 ++-- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/update-package.js b/lib/update-package.js index 84ee918..80ab65b 100644 --- a/lib/update-package.js +++ b/lib/update-package.js @@ -28,16 +28,10 @@ module.exports = function (options, done) { Hoek.merge(packageContents, options.json || {}); // - // The generated package.json is read-only, but removing it prior to writing - // will allow updates. + // Change the file permissions so we can over-write the package. Then we'll write the package + // and then change the file permissions back to read-only. // - // Node 0.10.xx + Windows Hack .. Windows does not allow an unlink of a Read-Only file .. - // So we chmod it to be rw by owner... - // This was fixed in node 0.12 + but still is an issue in 0.10.XX which Meteor uses.. - if ( FindNodeVersion(options).substring(0,4) === "0.10" && process.platform === "win32") { - Fs.chmodSync( packagePath, "0644") ; - } - - Fs.unlinkSync(packagePath); - Fs.writeFile(packagePath, JSON.stringify(packageContents, null, 2), done); + Fs.chmodSync( packagePath, "0644" ) ; + Fs.writeFile( packagePath, JSON.stringify(packageContents, null, 2), done); + Fs.chmodSync( packagePath, "0444" ) ; }; diff --git a/test/update-package.js b/test/update-package.js index bd1f94e..474cfd0 100644 --- a/test/update-package.js +++ b/test/update-package.js @@ -45,7 +45,7 @@ describe('update-package', function () { before(function (done) { fsStub.existsSync = Sinon.stub().returns(true); fsStub.readFileSync = Sinon.stub().returns('{}'); - fsStub.unlinkSync = Sinon.stub(); + fsStub.chmodSync = Sinon.stub(); fsStub.writeFile = Sinon.stub().yields(null); done(); }); @@ -62,7 +62,7 @@ describe('update-package', function () { before(function (done) { fsStub.existsSync = Sinon.stub().returns(true); fsStub.readFileSync = Sinon.stub().returns('{}'); - fsStub.unlinkSync = Sinon.stub(); + fsStub.chmodSync = Sinon.stub(); fsStub.writeFile = Sinon.stub().yields(null); done(); });