Skip to content

Commit

Permalink
FLUID-5789: Addressing an issue with clean
Browse files Browse the repository at this point in the history
The package.json file couldn't be cleaned in windows systems due to issues
with how node and git handle absolute paths differently. This has been addressed
by changing the working directly briefly to execute the clean command with a
relative path.

Also removed the documentation of the moduleRoot option which is really only
for rebasing when running tests.
  • Loading branch information
jobara committed Oct 21, 2015
1 parent ca0f7fd commit 2caa567
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 31 deletions.
18 changes: 2 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ npm install fluid-publish --save-dev

### Command Line ###

Run these commands from the root directory of the module to be published.

```bash
# creates a dev release (global install)
fluid-publish
Expand Down Expand Up @@ -280,22 +282,6 @@ publish.standard();
"dev"
</td>
</tr>
<tr>
<td>
`moduleRoot`
</td>
<td>
The root directory of the module executing `fluid-publish`
</td>
<td>
""
<br>
<br>
<p>
<em><strong>NOTE</strong>: This refers to the current working directory and is analogous to `process.cwd`</em>
</p>
</td>
</tr>
</tbody>
</table>

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"publishCmd": "npm publish",
"versionCmd": "npm version --no-git-tag-version ${version}",
"distTagCmd": "npm dist-tag add ${packageName}@${version} ${tag}",
"cleanCmd": "git checkout -- ${package}",
"cleanCmd": "git checkout -- package.json",
"devVersion": "${version}-${preRelease}.${timestamp}.${revision}",
"devTag": "dev",
"moduleRoot": ""
Expand Down
23 changes: 15 additions & 8 deletions publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,22 @@ publish.tag = function (isTest, packageName, version, tag, options) {
* Restore the package.json file to the latest committed version.
*
* Used internally to reset version number changes in package.json
* @param packagePath {String} - the path to the package.json file to clean
* @param options {Object} - e.g. {"cleanCmd": "git checkout -- ${package}"}
* @param moduleRoot {String} - the directory where the package.json file to
clean is located in.
* @param options {Object} - e.g. {"cleanCmd": "git checkout -- package.json"}
*/
publish.clean = function (packagePath, options) {
var cmdTemplate = options.cleanCmd || defaults.cleanCmd;
var cmdStr = es6Template(cmdTemplate, {
"package": packagePath
});
publish.clean = function (moduleRoot, options) {
var cmdStr = options.cleanCmd || defaults.cleanCmd;
var originalDir = process.cwd();

// change to the module root directory
process.chdir(moduleRoot || "./");

// run the clean command
publish.execSync(cmdStr);

// restore the working directory
process.chdir(originalDir);
};

/**
Expand Down Expand Up @@ -250,7 +257,7 @@ publish.dev = function (isTest, options) {
publish.tag(isTest, modulePkg.name, devVersion, opts.devTag, opts);

// cleanup changes
publish.clean(modulePkgPath, opts);
publish.clean(opts.moduleRoot, opts);
};

/**
Expand Down
11 changes: 5 additions & 6 deletions tests/publishTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,20 +258,19 @@ tagFixture.forEach(function (fixture) {
console.log("\n*** publish.clean ***");

var cleanFixture = [{
packagePath: "path/to/package.json",
cleanCmd: "clean ${package}",
expected: "clean path/to/package.json"
moduleRoot: "./",
cleanCmd: "clean"
}];

cleanFixture.forEach(function (fixture) {
console.log("clean test - cleanCmd: " + fixture.cleanCmd);

var exec = sinon.stub(publish, "execSync");

publish.clean(fixture.packagePath, fixture);
publish.clean(fixture.moduleRoot, fixture);

assert(exec.calledOnce, "execSync should have been called");
assert(exec.calledWith(fixture.expected), "execSync should have been called with: " + fixture.expected);
assert(exec.calledWith(fixture.cleanCmd), "execSync should have been called with: " + fixture.expected);

// remove execSync stub
publish.execSync.restore();
Expand Down Expand Up @@ -339,7 +338,7 @@ publishFixture.forEach(function (fixture) {
assert(stub.tag.calledOnce, "tag should have been called");
assert(stub.tag.calledWith(fixture.isTest, modulePackage.name, devVersion, fixture.options.devTag, fixture.options), "tag should have been called with: " + fixture.isTest + ", " + modulePackage.name + ", " + devVersion + ", " + fixture.options.devTag + ", " + optsString);
assert(stub.clean.calledOnce, "clean should have been called");
assert(stub.clean.calledWith(modulePackagePath, fixture.options), "clean should have been called with: " + modulePackagePath + ", " + optsString);
assert(stub.clean.calledWith(fixture.options.moduleRoot, fixture.options), "clean should have been called with: " + fixture.options.moduleRoot + ", " + optsString);

removeStubs(publish, toStub);
});
Expand Down

0 comments on commit 2caa567

Please sign in to comment.