Skip to content

Commit

Permalink
Make logic even easier across all platforms and modify tests to suit …
Browse files Browse the repository at this point in the history
…new logic
  • Loading branch information
Steven McDowall committed Sep 9, 2015
1 parent ee58847 commit 40f3267
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
16 changes: 5 additions & 11 deletions lib/update-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) ;
};
4 changes: 2 additions & 2 deletions test/update-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand All @@ -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();
});
Expand Down

0 comments on commit 40f3267

Please sign in to comment.