-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to pass Auth header #23
Changes from all commits
87003f6
7dab37a
d361e80
a2e7d7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,10 @@ program | |
"--dry-run", | ||
"Do not install packages, but show the install command that will be run" | ||
) | ||
.option( | ||
"-a, --auth <token>", | ||
"Provide an NPM authToken for private packages." | ||
) | ||
.usage("<package>[@<version>], default version is 'latest'") | ||
.parse(process.argv); | ||
|
||
|
@@ -132,7 +136,8 @@ const options = { | |
onlyPeers: program.onlyPeers, | ||
silent: program.silent, | ||
packageManager, | ||
dryRun: program.dryRun | ||
dryRun: program.dryRun, | ||
auth: program.auth | ||
}; | ||
|
||
// Disabled this rule so we can hoist the callback | ||
|
@@ -179,13 +184,13 @@ function installCb(err) { | |
console.log(`${C.errorText} ${err.message}`); | ||
process.exit(1); | ||
} | ||
let successMessage = `${C.successText} ${ | ||
packageName | ||
} and its peerDeps were installed successfully.`; | ||
let successMessage = `${ | ||
C.successText | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the linter can't make up it's mind regarding where it wants to do those line breaks... |
||
} ${packageName} and its peerDeps were installed successfully.`; | ||
if (program.onlyPeers) { | ||
successMessage = `${C.successText} The peerDeps of ${ | ||
packageName | ||
} were installed successfully.`; | ||
successMessage = `${ | ||
C.successText | ||
} The peerDeps of ${packageName} were installed successfully.`; | ||
} | ||
console.log(successMessage); | ||
process.exit(0); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,14 +28,19 @@ function encodePackageName(packageName) { | |
* @param {string} requestInfo.registry - the URI of the registry on which the package is hosted | ||
* @returns {Promise<Object>} - a Promise which resolves to the JSON response from the registry | ||
*/ | ||
function getPackageData({ encodedPackageName, registry }) { | ||
function getPackageData({ encodedPackageName, registry, auth }) { | ||
const requestHeaders = {}; | ||
if (auth) { | ||
requestHeaders.Authorization = `Bearer ${auth}`; | ||
} | ||
return request({ | ||
uri: `${registry}/${encodedPackageName}`, | ||
resolveWithFullResponse: true, | ||
// When simple is true, all non-200 status codes throw an | ||
// error. However, we want to handle status code errors in | ||
// the .then(), so we make simple false. | ||
simple: false | ||
simple: false, | ||
headers: requestHeaders | ||
}).then(response => { | ||
const { statusCode } = response; | ||
if (statusCode === 404) { | ||
|
@@ -103,12 +108,13 @@ function installPeerDeps( | |
dev, | ||
onlyPeers, | ||
silent, | ||
dryRun | ||
dryRun, | ||
auth | ||
}, | ||
cb | ||
) { | ||
const encodedPackageName = encodePackageName(packageName); | ||
getPackageData({ encodedPackageName, registry }) | ||
getPackageData({ encodedPackageName, registry, auth }) | ||
// Catch before .then because the .then is so long | ||
.catch(err => cb(err)) | ||
.then(data => { | ||
|
@@ -206,9 +212,7 @@ function installPeerDeps( | |
const commandString = `${packageManager} ${args.join(" ")}\n`; | ||
if (dryRun) { | ||
console.log( | ||
`This command would have been run to install ${packageName}@${ | ||
version | ||
}:` | ||
`This command would have been run to install ${packageName}@${version}:` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, this is something that was picked up by the autolinting and changed. |
||
); | ||
console.log(commandString); | ||
} else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous pattern was not matching because all of the test files are at the root of the src folder. Now the tests are not being built into lib 💃