Skip to content
This repository has been archived by the owner on Aug 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #95 from thomasjo/tj-fix-cwd-issue-redux
Browse files Browse the repository at this point in the history
Fix working directory issue
  • Loading branch information
thomasjo committed Jun 19, 2015
2 parents 80c2d21 + 337fd26 commit a17fa9b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class Builder {
this.envPathKey = this.getEnvironmentPathKey(process.platform);
}

run(/* args, callback */) {}
run(/* filePath */) {}
constructArgs(/* filePath */) {}
parseLogFile(/* texFilePath */) {}

Expand Down
4 changes: 3 additions & 1 deletion lib/builders/latexmk.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import Builder from "../builder";
import LogParser from "../parsers/log-parser";

export default class LatexmkBuilder extends Builder {
run(args) {
run(filePath) {
const args = this.constructArgs(filePath);
const command = `latexmk ${args.join(" ")}`;
const options = this.constructChildProcessOptions();

options.cwd = path.dirname(filePath); // Run process with sensible CWD.
options.maxBuffer = 52428800; // Set process' max buffer size to 50 MB.
options.env.max_print_line = 1000; // Max log file line length.

Expand Down
3 changes: 1 addition & 2 deletions lib/composer.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export default class Composer {

const builder = latex.getBuilder();
const rootFilePath = this.resolveRootFilePath(filePath);
const args = builder.constructArgs(rootFilePath);

this.destroyErrorIndicator();
this.showProgressIndicator();
Expand All @@ -45,7 +44,7 @@ export default class Composer {
};

try {
statusCode = await builder.run(args);
statusCode = await builder.run(rootFilePath);
result = builder.parseLogFile(rootFilePath);
if (statusCode > 0 || !result || !result.outputFilePath) {
showBuildError(statusCode, result, builder);
Expand Down
18 changes: 9 additions & 9 deletions spec/builders/latexmk-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ describe("LatexmkBuilder", function() {
let exitCode;

it("successfully executes latexmk when given a valid TeX file", function() {
const args = builder.constructArgs(filePath);

waitsForPromise(function() {
return builder.run(args).then(code => exitCode = code);
return builder.run(filePath).then(code => exitCode = code);
});

runs(function() {
Expand All @@ -102,10 +100,9 @@ describe("LatexmkBuilder", function() {

it("successfully executes latexmk when given a file path containing spaces", function() {
filePath = path.join(fixturesPath, "filename with spaces.tex");
const args = builder.constructArgs(filePath);

waitsForPromise(function() {
return builder.run(args).then(code => exitCode = code);
return builder.run(filePath).then(code => exitCode = code);
});

runs(function() {
Expand All @@ -114,10 +111,10 @@ describe("LatexmkBuilder", function() {
});

it("fails to execute latexmk when given invalid arguments", function() {
const args = ["-invalid-argument"];
spyOn(builder, "constructArgs").andReturn(["-invalid-argument"]);

waitsForPromise(function() {
return builder.run(args).then(code => exitCode = code);
return builder.run(filePath).then(code => exitCode = code);
});

runs(function() {
Expand All @@ -128,12 +125,15 @@ describe("LatexmkBuilder", function() {
it("fails to execute latexmk when given invalid file path", function() {
filePath = path.join(fixturesPath, "foo.tex");
const args = builder.constructArgs(filePath);
const removed = args.splice(1, 1);

// Need to remove the "force" flag to trigger the desired failure.
const removed = args.splice(1, 1);
expect(removed).toEqual(["-f"]);

spyOn(builder, "constructArgs").andReturn(args);

waitsForPromise(function() {
return builder.run(args).then(code => exitCode = code);
return builder.run(filePath).then(code => exitCode = code);
});

runs(function() {
Expand Down

0 comments on commit a17fa9b

Please sign in to comment.