Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
93 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
const semver = require('semver'); | ||
const _ = require('lodash'); | ||
const { run } = require('./shell'); | ||
const { warn } = require('./log'); | ||
const { config } = require('./config'); | ||
|
||
const getTag = () => { | ||
const tag = config.getOption('npm.tag'); | ||
if (tag) return tag; | ||
const preReleaseComponents = semver.prerelease(config.getOption('version')); | ||
return _.get(preReleaseComponents, 0, config.defaultOptions.npm.tag); | ||
}; | ||
|
||
const publish = (options, pkgName, otpPrompt) => { | ||
const { publishPath, tag, access, otp } = options; | ||
const isScopedPkg = pkgName.startsWith('@'); | ||
const accessArg = isScopedPkg && access ? `--access ${access}` : ''; | ||
const otpArg = otp ? `--otp ${otp}` : ''; | ||
const dryRunArg = config.isDryRun ? '--dry-run' : ''; | ||
return run(`npm publish ${publishPath} --tag ${tag} ${accessArg} ${otpArg} ${dryRunArg}`, { | ||
isReadOnly: true, | ||
verbose: config.isVerbose || config.isDryRun | ||
}).catch(err => { | ||
if (/one-time pass/.test(err)) { | ||
if (otp != null) { | ||
warn('The provided OTP is incorrect or has expired.'); | ||
} | ||
if (otpPrompt) { | ||
return otpPrompt(otp => publish(Object.assign(options, { otp }), pkgName, otpPrompt)); | ||
} | ||
} | ||
throw err; | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
getTag, | ||
publish | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const test = require('tape'); | ||
const proxyquire = require('proxyquire'); | ||
const { Config } = require('../lib/config'); | ||
const { getTag } = require('../lib/npm'); | ||
|
||
const getMock = config => | ||
proxyquire('../lib/npm', { | ||
'./config': { config } | ||
}); | ||
|
||
test('getTag', t => { | ||
t.equal(getTag(), 'latest'); | ||
t.end(); | ||
}); | ||
|
||
test('getTag (pre-release)', t => { | ||
const npm = getMock(new Config({}, '--preRelease=beta')); | ||
t.equal(npm.getTag(), 'beta'); | ||
t.end(); | ||
}); | ||
|
||
test('getTag (pre-release continuation)', t => { | ||
const npm = getMock(new Config({ version: '1.0.2-alpha.3' }, '--preRelease')); | ||
t.equal(npm.getTag(), 'alpha'); | ||
t.end(); | ||
}); |