Skip to content

Commit

Permalink
fix(index): do not assume win32 usage for binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed Nov 30, 2021
1 parent fc420c9 commit bbd50d8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,18 @@ class UnRTF {
constructor(binPath) {
if (binPath) {
this.unrtfPath = path.normalizeTrim(binPath);
} else {
// If not set, expect user to be using Win32
} else if (process.platform === "win32") {
this.unrtfPath = path.joinSafe(
__dirname,
"lib",
"win32",
"unrtf-0.19.3",
"bin"
);
} else {
throw new Error(
`${process.platform} UnRTF binaries are not provided, please pass the installation directory as a parameter to the UnRTF instance.`
);
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/* eslint-disable security/detect-child-process */
/* eslint-disable security/detect-non-literal-fs-filename */
const isHtml = require("is-html");
const os = require("os");
const path = require("upath");
const semver = require("semver");
const { execFile } = require("child_process");
Expand All @@ -15,8 +14,7 @@ const testDirectory = `${__dirname}/../test_files/`;
const file = `${testDirectory}test-rtf-complex.rtf`;

let testBinaryPath;
const platform = os.platform();
switch (platform) {
switch (process.platform) {
// macOS
case "darwin":
testBinaryPath = "/usr/local/bin";
Expand All @@ -39,7 +37,7 @@ switch (platform) {
break;
}

if (platform === "win32") {
if (process.platform === "win32") {
describe("Constructor", () => {
test("Should convert RTF file to HTML without binary set, and use included Windows binary", async () => {
const unRtf = new UnRTF();
Expand Down

0 comments on commit bbd50d8

Please sign in to comment.