Skip to content

Commit

Permalink
Merge pull request #590 from ronilan/Fix-Unpublish-Default-Issue-589
Browse files Browse the repository at this point in the history
Command "publish" and "unpublish" to both default to staging_host
  • Loading branch information
springmeyer committed Oct 20, 2021
2 parents 3ac4191 + 91f73c6 commit 7f363ca
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,14 @@ must be true.

If any of these checks fail then the operation will not perform execution time determination of the s3 target.

If the command being executed is "publish" then the default is set to `binary.staging_host`. In all other cases
If the command being executed is either "publish" or "unpublish" then the default is set to `binary.staging_host`. In all other cases
the default is `binary.production_host`.

The command-line options `--s3_host=staging` or `--s3_host=production` override the default. If `s3_host`
is present and not `staging` or `production` an exception is thrown.

This allows installing from staging by specifying `--s3_host=staging`. And it requires specifying
`--s3_option=production` in order to publish to production making accidental publishing less likely.
`--s3_option=production` in order to publish to, or unpublish from, production, making accidental errors less likely.

## Node-API Considerations

Expand Down
8 changes: 4 additions & 4 deletions lib/node-pre-gyp.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ proto.parseArgv = function parseOpts(argv) {
*
* if '--s3_host' is not present then "binary.host" is set to the default as above.
*
* this strategy was chosen so that any command other than "publish" uses "production"
* as the default without requiring any command-line options but that "publish" requires
* '--s3_host production_host' to be specified in order to *really* publish. publishing
* this strategy was chosen so that any command other than "publish" or "unpublish" uses "production"
* as the default without requiring any command-line options but that "publish" and "unpublish" require
* '--s3_host production_host' to be specified in order to *really* publish (or unpublish). publishing
* to staging can be done freely without worrying about disturbing any production releases.
*/
proto.setBinaryHostProperty = function(command) {
Expand All @@ -257,7 +257,7 @@ proto.setBinaryHostProperty = function(command) {
return '';
}
let target = 'production_host';
if (command === 'publish') {
if (command === 'publish' || command === 'unpublish') {
target = 'staging_host';
}
// the environment variable has priority over the default or the command line. if
Expand Down
2 changes: 1 addition & 1 deletion test/run.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ test('should set staging and production hosts', (t) => {
mpj.binary.host = '';
const opts = { argv: [cmd] };
({ prog } = setupTest(dir, mpj, opts));
mpj.binary.host = cmd === 'publish' ? mpj.binary.staging_host : mpj.binary.production_host;
mpj.binary.host = (cmd === 'publish' || cmd === 'unpublish') ? mpj.binary.staging_host : mpj.binary.production_host;
t.deepEqual(prog.package_json, mpj, 'host should be correct for command: ' + cmd);
t.equal(prog.binaryHostSet, true, 'binary host should be flagged as set');
});
Expand Down

0 comments on commit 7f363ca

Please sign in to comment.