Skip to content

Commit

Permalink
Use resolved CLI paths again
Browse files Browse the repository at this point in the history
To protect Windows from itself, use explicit 'node <execFile>' call style.

Refs lerna#759
Fixes lerna#708
  • Loading branch information
evocateur committed Apr 18, 2017
1 parent 83a5e9f commit d53bd6a
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 11 deletions.
24 changes: 20 additions & 4 deletions src/ConventionalCommitUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,22 @@ const CHANGELOG_HEADER = dedent(`# Change Log
All notable changes to this project will be documented in this file.
See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.`);

// We call these resolved CLI files in the "path/to/node path/to/cli <..args>"
// pattern to avoid Windows hangups with shebangs (e.g., WSH can't handle it)
const RECOMMEND_CLI = require.resolve("conventional-recommended-bump/cli");
const CHANGELOG_CLI = require.resolve("conventional-changelog-cli/cli");

export default class ConventionalCommitUtilities {
@logger.logifySync()
static recommendVersion(pkg, opts) {
const recommendedBump = ChildProcessUtilities.execSync(
"conventional-recommended-bump",
["-l", pkg.name, "--commit-path", pkg.location, "-p", "angular"],
process.execPath,
[
RECOMMEND_CLI,
"-l", pkg.name,
"--commit-path", pkg.location,
"-p", "angular",
],
opts
);

Expand All @@ -36,8 +46,14 @@ export default class ConventionalCommitUtilities {
// run conventional-changelog-cli to generate the markdown
// for the upcoming release.
const newEntry = ChildProcessUtilities.execSync(
"conventional-changelog",
["-l", pkg.name, "--commit-path", pkg.location, "--pkg", pkgJsonLocation, "-p", "angular"],
process.execPath,
[
CHANGELOG_CLI,
"-l", pkg.name,
"--commit-path", pkg.location,
"--pkg", pkgJsonLocation,
"-p", "angular",
],
opts
);

Expand Down
8 changes: 7 additions & 1 deletion src/FileSystemUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ function ensureEndsWithNewLine(string) {
return ENDS_WITH_NEW_LINE.test(string) ? string : string + "\n";
}

// NOTE: if rimraf moves the location of its executable, this will need to be updated
const RIMRAF_CLI = require.resolve("rimraf/bin");

// globs only return directories with a trailing slash
function trailingSlash(filePath) {
return path.normalize(`${filePath}/`);
Expand Down Expand Up @@ -79,8 +82,11 @@ export default class FileSystemUtilities {

const args = candidates.map(trailingSlash);
args.unshift("--no-glob");
args.unshift(RIMRAF_CLI);

return ChildProcessUtilities.spawn("rimraf", args, {}, callback);
// We call this resolved CLI path in the "path/to/node path/to/cli <..args>"
// pattern to avoid Windows hangups with shebangs (e.g., WSH can't handle it)
return ChildProcessUtilities.spawn(process.execPath, args, {}, callback);
});
}

Expand Down
19 changes: 15 additions & 4 deletions test/ConventionalCommitUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@ describe("ConventionalCommitUtilities", () => {

expect(recommendVersion).toBe("2.0.0");
expect(ChildProcessUtilities.execSync).lastCalledWith(
"conventional-recommended-bump",
["-l", "bar", "--commit-path", "/foo/bar", "-p", "angular"],
process.execPath,
[
require.resolve("conventional-recommended-bump/cli"),
"-l", "bar",
"--commit-path", "/foo/bar",
"-p", "angular",
],
opts,
);
});
Expand All @@ -54,8 +59,14 @@ describe("ConventionalCommitUtilities", () => {
path.normalize("/foo/bar/CHANGELOG.md")
);
expect(ChildProcessUtilities.execSync).lastCalledWith(
"conventional-changelog",
["-l", "bar", "--commit-path", "/foo/bar", "--pkg", path.normalize("/foo/bar/package.json"), "-p", "angular"],
process.execPath,
[
require.resolve("conventional-changelog-cli/cli"),
"-l", "bar",
"--commit-path", "/foo/bar",
"--pkg", path.normalize("/foo/bar/package.json"),
"-p", "angular",
],
opts,
);
expect(FileSystemUtilities.writeFileSync).lastCalledWith(
Expand Down
8 changes: 6 additions & 2 deletions test/FileSystemUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ describe("FileSystemUtilities", () => {
FileSystemUtilities.rimraf(["rimraf/test"], () => {
try {
expect(ChildProcessUtilities.spawn).lastCalledWith(
"rimraf",
["--no-glob", path.normalize("rimraf/test/")],
process.execPath,
[
require.resolve("rimraf/bin"),
"--no-glob",
path.normalize("rimraf/test/"),
],
{},
expect.any(Function)
);
Expand Down

0 comments on commit d53bd6a

Please sign in to comment.