Skip to content

Commit

Permalink
fix(npm-verify): unset npm_* environment variables when running whoam…
Browse files Browse the repository at this point in the history
…i command
  • Loading branch information
Pavel910 committed Mar 9, 2018
1 parent 88523c7 commit 11506d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion src/plugins/npm/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export default () => {
logger.log("Verifying access to NPM...");
try {
await fs.appendFile("./.npmrc", `\n//registry.npmjs.org/:_authToken=${NPM_TOKEN}`);
await execa("npm", ["whoami"]);
// We need to unset the `npm_` env variables to make sure local `.npmrc` is being read.
// This is required when running scripts with yarn: https://github.com/yarnpkg/yarn/issues/4475
execa.shellSync("unset $(env | awk -F= '$1 ~ /^npm_/ {print $1}') && npm whoami");
next();
} catch (err) {
throw new Error("EINVALIDNPMTOKEN: " + err.message);
Expand Down
12 changes: 7 additions & 5 deletions tests/npmVerify.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ describe("npmVerify plugin test", function() {
process.env["NPM_TOKEN"] = "npm-token";

proxyquire(modulePath, {
execa: async () => {
const npmrc = await fs.readFile("./.npmrc");
if (npmrc.includes("//registry.npmjs.org/:_authToken=npm-token")) {
return true;
execa: {
shellSync: async () => {
const npmrc = await fs.readFile("./.npmrc");
if (npmrc.includes("//registry.npmjs.org/:_authToken=npm-token")) {
return true;
}
throw new Error("Command failed: npm whoami");
}
throw new Error("Command failed: npm whoami");
}
});

Expand Down

0 comments on commit 11506d1

Please sign in to comment.