From 8b76598bd3ed3ab036d903efe0f9286519a4850a Mon Sep 17 00:00:00 2001 From: Thomas Johansen Date: Thu, 18 Jun 2015 09:32:36 +0200 Subject: [PATCH 1/2] Construct args inside Builder::run() instead of passing them --- lib/builder.js | 2 +- lib/builders/latexmk.js | 3 ++- lib/composer.js | 3 +-- spec/builders/latexmk-spec.js | 18 +++++++++--------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/builder.js b/lib/builder.js index ab83291a..59ed5260 100644 --- a/lib/builder.js +++ b/lib/builder.js @@ -8,7 +8,7 @@ export default class Builder { this.envPathKey = this.getEnvironmentPathKey(process.platform); } - run(/* args, callback */) {} + run(/* filePath */) {} constructArgs(/* filePath */) {} parseLogFile(/* texFilePath */) {} diff --git a/lib/builders/latexmk.js b/lib/builders/latexmk.js index 5df071af..e0dd1934 100644 --- a/lib/builders/latexmk.js +++ b/lib/builders/latexmk.js @@ -7,7 +7,8 @@ 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(); diff --git a/lib/composer.js b/lib/composer.js index 34bc1bdd..b5da0397 100644 --- a/lib/composer.js +++ b/lib/composer.js @@ -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(); @@ -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); diff --git a/spec/builders/latexmk-spec.js b/spec/builders/latexmk-spec.js index 81b9d385..74694be1 100644 --- a/spec/builders/latexmk-spec.js +++ b/spec/builders/latexmk-spec.js @@ -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() { @@ -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() { @@ -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() { @@ -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() { From 337fd260af91e73959f860c3e789a33bdf7a591c Mon Sep 17 00:00:00 2001 From: Thomas Johansen Date: Fri, 19 Jun 2015 08:14:32 +0200 Subject: [PATCH 2/2] :bug: Explicitly set the current working directory Fixes #87 --- lib/builders/latexmk.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/builders/latexmk.js b/lib/builders/latexmk.js index e0dd1934..0fafbf4b 100644 --- a/lib/builders/latexmk.js +++ b/lib/builders/latexmk.js @@ -12,6 +12,7 @@ export default class LatexmkBuilder extends Builder { 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.