Skip to content

Commit

Permalink
Revert "Revert "Use sync-exec for node 0.10" (lerna#242)"
Browse files Browse the repository at this point in the history
This reverts commit 7eb4763.
  • Loading branch information
gigabo committed Jun 24, 2016
1 parent 9d2f715 commit 9f8cb33
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 39 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ cache:
- node_modules

node_js:
- "0.10"
- "0.12"
- "4"
- stable
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"progress": "^1.1.8",
"rimraf": "^2.4.4",
"semver": "^5.1.0",
"signal-exit": "^2.1.2"
"signal-exit": "^2.1.2",
"sync-exec": "^0.6.2"
},
"bin": {
"lerna": "./bin/lerna.js"
Expand Down
13 changes: 10 additions & 3 deletions src/ChildProcessUtilities.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import child from "child_process";
import objectAssign from "object-assign";
import syncExec from "sync-exec";

export default class ChildProcessUtilities {
static exec(command, opts, callback) {
Expand All @@ -21,9 +22,15 @@ export default class ChildProcessUtilities {
}

static execSync(command) {
return child.execSync(command, {
encoding: "utf8"
}).trim();
if (child.execSync) {
return child.execSync(command, {
encoding: "utf8"
}).trim();
} else {
return syncExec(command, {
encoding: "utf8"
}).stdout.trim();
}
}

static spawn(command, args, opts, callback) {
Expand Down
71 changes: 37 additions & 34 deletions test/UpdatedCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@ import assert from "assert";
import child from "child_process";
import path from "path";
import fs from "fs";
import syncExec from "sync-exec";

import UpdatedCommand from "../src/commands/UpdatedCommand";
import exitWithCode from "./_exitWithCode";
import initFixture from "./_initFixture";
import logger from "../src/logger";
import stub from "./_stub";

const execSync = (child.execSync || syncExec);

describe("UpdatedCommand", () => {

/** =========================================================================
Expand All @@ -23,10 +26,10 @@ describe("UpdatedCommand", () => {
});

it("should list changes", done => {
child.execSync("git tag v1.0.0");
child.execSync("touch " + path.join(testDir, "packages/package-2/random-file"));
child.execSync("git add -A");
child.execSync("git commit -m 'Commit'");
execSync("git tag v1.0.0");
execSync("touch " + path.join(testDir, "packages/package-2/random-file"));
execSync("git add -A");
execSync("git commit -m 'Commit'");

const updatedCommand = new UpdatedCommand([], {});

Expand All @@ -46,10 +49,10 @@ describe("UpdatedCommand", () => {
});

it("should list changes with --force-publish *", done => {
child.execSync("git tag v1.0.0");
child.execSync("touch " + path.join(testDir, "packages/package-2/random-file"));
child.execSync("git add -A");
child.execSync("git commit -m 'Commit'");
execSync("git tag v1.0.0");
execSync("touch " + path.join(testDir, "packages/package-2/random-file"));
execSync("git add -A");
execSync("git commit -m 'Commit'");

const updatedCommand = new UpdatedCommand([], {
forcePublish: "*"
Expand All @@ -71,10 +74,10 @@ describe("UpdatedCommand", () => {
});

it("should list changes with --force-publish [package,package]", done => {
child.execSync("git tag v1.0.0");
child.execSync("touch " + path.join(testDir, "packages/package-3/random-file"));
child.execSync("git add -A");
child.execSync("git commit -m 'Commit'");
execSync("git tag v1.0.0");
execSync("touch " + path.join(testDir, "packages/package-3/random-file"));
execSync("git add -A");
execSync("git commit -m 'Commit'");

const updatedCommand = new UpdatedCommand([], {
forcePublish: "package-2,package-4"
Expand Down Expand Up @@ -103,11 +106,11 @@ describe("UpdatedCommand", () => {
};
fs.writeFileSync(lernaJsonLocation, JSON.stringify(lernaJson, null, 2));

child.execSync("git tag v1.0.0");
child.execSync("touch " + path.join(testDir, "packages/package-2/ignored-file"));
child.execSync("touch " + path.join(testDir, "packages/package-3/random-file"));
child.execSync("git add -A");
child.execSync("git commit -m 'Commit'");
execSync("git tag v1.0.0");
execSync("touch " + path.join(testDir, "packages/package-2/ignored-file"));
execSync("touch " + path.join(testDir, "packages/package-3/random-file"));
execSync("git add -A");
execSync("git commit -m 'Commit'");

const updatedCommand = new UpdatedCommand([], {});

Expand Down Expand Up @@ -139,10 +142,10 @@ describe("UpdatedCommand", () => {
});

it("should list changes", done => {
child.execSync("git tag v1.0.0");
child.execSync("touch " + path.join(testDir, "packages/package-3/random-file"));
child.execSync("git add -A");
child.execSync("git commit -m 'Commit'");
execSync("git tag v1.0.0");
execSync("touch " + path.join(testDir, "packages/package-3/random-file"));
execSync("git add -A");
execSync("git commit -m 'Commit'");

const updatedCommand = new UpdatedCommand([], {});

Expand All @@ -162,10 +165,10 @@ describe("UpdatedCommand", () => {
});

it("should list changes with --force-publish *", done => {
child.execSync("git tag v1.0.0");
child.execSync("touch " + path.join(testDir, "packages/package-2/random-file"));
child.execSync("git add -A");
child.execSync("git commit -m 'Commit'");
execSync("git tag v1.0.0");
execSync("touch " + path.join(testDir, "packages/package-2/random-file"));
execSync("git add -A");
execSync("git commit -m 'Commit'");

const updatedCommand = new UpdatedCommand([], {
forcePublish: "*"
Expand All @@ -187,10 +190,10 @@ describe("UpdatedCommand", () => {
});

it("should list changes with --force-publish [package,package]", done => {
child.execSync("git tag v1.0.0");
child.execSync("touch " + path.join(testDir, "packages/package-4/random-file"));
child.execSync("git add -A");
child.execSync("git commit -m 'Commit'");
execSync("git tag v1.0.0");
execSync("touch " + path.join(testDir, "packages/package-4/random-file"));
execSync("git add -A");
execSync("git commit -m 'Commit'");

const updatedCommand = new UpdatedCommand([], {
forcePublish: "package-2"
Expand Down Expand Up @@ -219,11 +222,11 @@ describe("UpdatedCommand", () => {
};
fs.writeFileSync(lernaJsonLocation, JSON.stringify(lernaJson, null, 2));

child.execSync("git tag v1.0.0");
child.execSync("touch " + path.join(testDir, "packages/package-2/ignored-file"));
child.execSync("touch " + path.join(testDir, "packages/package-3/random-file"));
child.execSync("git add -A");
child.execSync("git commit -m 'Commit'");
execSync("git tag v1.0.0");
execSync("touch " + path.join(testDir, "packages/package-2/ignored-file"));
execSync("touch " + path.join(testDir, "packages/package-3/random-file"));
execSync("git add -A");
execSync("git commit -m 'Commit'");

const updatedCommand = new UpdatedCommand([], {});

Expand Down
3 changes: 2 additions & 1 deletion test/_initFixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import rimraf from "rimraf";
import child from "child_process";
import path from "path";
import cpr from "cpr";
import syncExec from "sync-exec";

const tmpDir = path.resolve(__dirname, "../tmp");
const originalCwd = process.cwd();
Expand Down Expand Up @@ -29,7 +30,7 @@ export default function initFixture(fixturePath, callback) {
}, err => {
if (err) return callback(err);
process.chdir(testDir);
child.execSync("git init . && git add -A && git commit -m 'Init commit'");
(child.execSync || syncExec)("git init . && git add -A && git commit -m 'Init commit'");
callback();
});

Expand Down

0 comments on commit 9f8cb33

Please sign in to comment.