Skip to content

Commit

Permalink
Fix: use global-import shelljs (#38)
Browse files Browse the repository at this point in the history
* Fix: use global-import shelljs

* Add comment
  • Loading branch information
kaicataldo authored May 8, 2020
1 parent 3d05dc5 commit d6439b3
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/release-ops.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@
* MIT License
*/

/* global test, cat, rm, mv */

"use strict";

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

// TODO: Update to use non-global module to avoid prototype pollution.
require("shelljs/global");

const fs = require("fs"),
path = require("path"),
shelljs = require("shelljs"),
semver = require("semver"),
GitHub = require("github-api"),
dateformat = require("dateformat"),
Expand Down Expand Up @@ -44,7 +48,7 @@ function getPackageInfo() {
* @private
*/
function validateSetup() {
if (!shelljs.test("-f", "package.json")) {
if (!test("-f", "package.json")) {
console.error("Missing package.json file");
ShellOps.exit(1);
}
Expand Down Expand Up @@ -319,15 +323,16 @@ function writeChangelog(releaseInfo) {
(`\n${releaseInfo.rawChangelog}\n`).toEnd("CHANGELOG.tmp");

// ensure there's a CHANGELOG.md file
if (!shelljs.test("-f", "CHANGELOG.md")) {
if (!test("-f", "CHANGELOG.md")) {
fs.writeFileSync("CHANGELOG.md", "");
}

// switch-o change-o
fs.writeFileSync("CHANGELOG.md.tmp", shelljs.cat("CHANGELOG.tmp", "CHANGELOG.md"));
shelljs.rm("CHANGELOG.tmp");
shelljs.rm("CHANGELOG.md");
shelljs.mv("CHANGELOG.md.tmp", "CHANGELOG.md");
// `cat` returns a ShellString and `fs.writeFileSync` is throwing an error saying that this must be a String.
fs.writeFileSync("CHANGELOG.md.tmp", cat("CHANGELOG.tmp", "CHANGELOG.md").toString());
rm("CHANGELOG.tmp");
rm("CHANGELOG.md");
mv("CHANGELOG.md.tmp", "CHANGELOG.md");
}

/**
Expand Down

0 comments on commit d6439b3

Please sign in to comment.