Skip to content

Commit

Permalink
Fix: avoid overwriting the .npmrc file in a repository (#30)
Browse files Browse the repository at this point in the history
The release process needs to temporarily write an .npmrc file in order to publish. As a result, if the repository already has an .npmrc file, this will leave the file in a modified state. This isn't a big problem (it happens after creating a git commit, so the updated .npmrc file doesn't get published anywhere), but it has the potential to be confusing or cause human errors when generating a release locally. This commit updates the release publishing process to restore the old .npmrc file after the release finishes.
  • Loading branch information
not-an-aardvark committed Oct 17, 2018
1 parent bcdc618 commit 5c5c361
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lib/release-ops.js
Expand Up @@ -320,9 +320,6 @@ function generateRelease(prereleaseId) {
}
});

// Release needs a .npmrc file to work properly - token is read from environment
console.log("Writing .npmrc file");
fs.writeFileSync(".npmrc", "//registry.npmjs.org/:_authToken=${NPM_TOKEN}");
fs.writeFileSync(".eslint-release-info.json", JSON.stringify(releaseInfo, null, 4));
}

Expand Down Expand Up @@ -362,6 +359,17 @@ function publishRelease() {
validateSetup();
var releaseInfo = JSON.parse(fs.readFileSync(".eslint-release-info.json", "utf8"));

var oldNpmrcContents;
if (fs.existsSync(".npmrc")) {
oldNpmrcContents = fs.readFileSync(".npmrc", "utf8");
} else {
oldNpmrcContents = null;
}

// Release needs a .npmrc file to work properly - token is read from environment
console.log("Writing .npmrc file");
fs.writeFileSync(".npmrc", "//registry.npmjs.org/:_authToken=${NPM_TOKEN}");

// if there's a prerelease ID, publish under "next" tag
console.log("Publishing to npm");

Expand All @@ -376,6 +384,12 @@ function publishRelease() {

ShellOps.exec(command);

if (oldNpmrcContents === null) {
fs.unlinkSync(".npmrc");
} else {
fs.writeFileSync(".npmrc", oldNpmrcContents);
}

console.log("Publishing to git");
ShellOps.exec("git push origin master --tags");

Expand Down

0 comments on commit 5c5c361

Please sign in to comment.