Skip to content

Commit

Permalink
Merge pull request #271 from Fdawgs/fix/paths
Browse files Browse the repository at this point in the history
fix(index): normalize binary paths
  • Loading branch information
Fdawgs authored Jun 2, 2021
2 parents 8fc8117 + eff091b commit 2943368
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 31 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
"typescript": "^4.2.4"
},
"dependencies": {
"camelcase": "^6.2.0"
"camelcase": "^6.2.0",
"upath": "^2.0.1"
}
}
50 changes: 25 additions & 25 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const camelCase = require("camelcase");
const os = require("os");
const path = require("path");
const path = require("upath");
const { execFile } = require("child_process");
const util = require("util");

Expand Down Expand Up @@ -94,7 +94,7 @@ class Poppler {
switch (platform) {
// Windows OS
case "win32":
popplerPath = path.join(
popplerPath = path.joinSafe(
__dirname,
"lib",
"win32",
Expand All @@ -106,7 +106,7 @@ class Poppler {

// macOS
case "darwin":
popplerPath = path.join(
popplerPath = path.joinSafe(
__dirname,
"lib",
"darwin",
Expand Down Expand Up @@ -147,7 +147,7 @@ class Poppler {
args.push(outputFile);

const { stdout } = await execFileAsync(
path.join(this.popplerPath, "pdfattach"),
path.joinSafe(this.popplerPath, "pdfattach"),
args
);
return Promise.resolve(stdout);
Expand Down Expand Up @@ -205,7 +205,7 @@ class Poppler {
args.push(file);

const { stdout } = await execFileAsync(
path.join(this.popplerPath, "pdfdetach"),
path.joinSafe(this.popplerPath, "pdfdetach"),
args
);
return Promise.resolve(stdout);
Expand Down Expand Up @@ -241,7 +241,7 @@ class Poppler {

try {
const { stderr } = await execFileAsync(
path.join(this.popplerPath, "pdffonts"),
path.joinSafe(this.popplerPath, "pdffonts"),
["-v"]
);

Expand All @@ -261,7 +261,7 @@ class Poppler {
}

const child = execFile(
path.join(this.popplerPath, "pdffonts"),
path.joinSafe(this.popplerPath, "pdffonts"),
args
);

Expand Down Expand Up @@ -338,7 +338,7 @@ class Poppler {

try {
const { stderr } = await execFileAsync(
path.join(this.popplerPath, "pdfimages"),
path.joinSafe(this.popplerPath, "pdfimages"),
["-v"]
);

Expand All @@ -362,7 +362,7 @@ class Poppler {
}

const child = execFile(
path.join(this.popplerPath, "pdfimages"),
path.joinSafe(this.popplerPath, "pdfimages"),
args
);

Expand Down Expand Up @@ -460,7 +460,7 @@ class Poppler {

try {
const { stderr } = await execFileAsync(
path.join(this.popplerPath, "pdfinfo"),
path.joinSafe(this.popplerPath, "pdfinfo"),
["-v"]
);

Expand All @@ -480,7 +480,7 @@ class Poppler {
}

const child = execFile(
path.join(this.popplerPath, "pdfinfo"),
path.joinSafe(this.popplerPath, "pdfinfo"),
args
);

Expand Down Expand Up @@ -557,7 +557,7 @@ class Poppler {

try {
const { stderr } = await execFileAsync(
path.join(this.popplerPath, "pdfseparate"),
path.joinSafe(this.popplerPath, "pdfseparate"),
["-v"]
);

Expand All @@ -572,7 +572,7 @@ class Poppler {
args.push(outputPattern);

const { stdout } = await execFileAsync(
path.join(this.popplerPath, "pdfseparate"),
path.joinSafe(this.popplerPath, "pdfseparate"),
args
);
return Promise.resolve(stdout);
Expand Down Expand Up @@ -737,7 +737,7 @@ class Poppler {

try {
const { stderr } = await execFileAsync(
path.join(this.popplerPath, "pdftocairo"),
path.joinSafe(this.popplerPath, "pdftocairo"),
["-v"]
);

Expand All @@ -763,7 +763,7 @@ class Poppler {
}

const child = execFile(
path.join(this.popplerPath, "pdftocairo"),
path.joinSafe(this.popplerPath, "pdftocairo"),
args
);

Expand Down Expand Up @@ -881,7 +881,7 @@ class Poppler {

try {
const { stderr } = await execFileAsync(
path.join(this.popplerPath, "pdftohtml"),
path.joinSafe(this.popplerPath, "pdftohtml"),
["-v"]
);

Expand All @@ -905,7 +905,7 @@ class Poppler {
}

const child = execFile(
path.join(this.popplerPath, "pdftohtml"),
path.joinSafe(this.popplerPath, "pdftohtml"),
args
);

Expand Down Expand Up @@ -1096,7 +1096,7 @@ class Poppler {

try {
const { stderr } = await execFileAsync(
path.join(this.popplerPath, "pdftoppm"),
path.joinSafe(this.popplerPath, "pdftoppm"),
["-v"]
);

Expand All @@ -1118,7 +1118,7 @@ class Poppler {
args.push(outputPath);

const child = execFile(
path.join(this.popplerPath, "pdftoppm"),
path.joinSafe(this.popplerPath, "pdftoppm"),
args
);

Expand Down Expand Up @@ -1330,7 +1330,7 @@ class Poppler {

try {
const { stderr } = await execFileAsync(
path.join(this.popplerPath, "pdftops"),
path.joinSafe(this.popplerPath, "pdftops"),
["-v"]
);

Expand All @@ -1356,7 +1356,7 @@ class Poppler {
}

const child = execFile(
path.join(this.popplerPath, "pdftops"),
path.joinSafe(this.popplerPath, "pdftops"),
args
);

Expand Down Expand Up @@ -1486,7 +1486,7 @@ class Poppler {

try {
const { stderr } = await execFileAsync(
path.join(this.popplerPath, "pdftotext"),
path.joinSafe(this.popplerPath, "pdftotext"),
["-v"]
);

Expand All @@ -1512,7 +1512,7 @@ class Poppler {
}

const child = execFile(
path.join(this.popplerPath, "pdftotext"),
path.joinSafe(this.popplerPath, "pdftotext"),
args
);

Expand Down Expand Up @@ -1574,7 +1574,7 @@ class Poppler {

try {
const { stderr } = await execFileAsync(
path.join(this.popplerPath, "pdfunite"),
path.joinSafe(this.popplerPath, "pdfunite"),
["-v"]
);

Expand All @@ -1591,7 +1591,7 @@ class Poppler {
args.push(outputFile);

const { stdout } = await execFileAsync(
path.join(this.popplerPath, "pdfunite"),
path.joinSafe(this.popplerPath, "pdfunite"),
args
);
return Promise.resolve(stdout);
Expand Down
11 changes: 6 additions & 5 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const fs = require("fs");
const glob = require("glob");
const os = require("os");
const path = require("path");
const path = require("upath");
const { execFile } = require("child_process");
const util = require("util");

Expand All @@ -18,7 +18,7 @@ const platform = os.platform();
switch (platform) {
// macOS
case "darwin":
testBinaryPath = path.join(
testBinaryPath = path.joinSafe(
__dirname,
"lib",
"darwin",
Expand All @@ -34,7 +34,7 @@ switch (platform) {
// Windows OS
case "win32":
default:
testBinaryPath = path.join(
testBinaryPath = path.joinSafe(
__dirname,
"lib",
"win32",
Expand Down Expand Up @@ -380,8 +380,9 @@ describe("pdfInfo Function", () => {

test("Should list info of PDF file as Buffer", async () => {
const poppler = new Poppler(testBinaryPath);
const attachmentFile = fs.readFileSync(file);

const res = await poppler.pdfInfo(file);
const res = await poppler.pdfInfo(attachmentFile);

expect(typeof res).toEqual("string");
});
Expand Down Expand Up @@ -716,7 +717,7 @@ describe("pdfToPpm Function", () => {

beforeAll(async () => {
const { stderr } = await execFileAsync(
path.join(testBinaryPath, "pdftoppm"),
path.joinSafe(testBinaryPath, "pdftoppm"),
["-v"]
);
version = /(\d{1,2}\.\d{1,2}\.\d{1,2})/i.exec(stderr)[1];
Expand Down

0 comments on commit 2943368

Please sign in to comment.