Skip to content

Commit

Permalink
style: destruct upath module import
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed Sep 12, 2023
1 parent c91218b commit 7b5dba2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
4 changes: 2 additions & 2 deletions scripts/license-checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { init } = require("license-checker");
/** @type {string[]} */
// @ts-ignore: module is a JSON file
const copyLeftLicenses = require("spdx-copyleft");
const path = require("upath");
const { joinSafe } = require("upath");

const check = promisify(init);

Expand Down Expand Up @@ -57,7 +57,7 @@ async function checkLicenses() {
const licenses = await check({
direct: true,
production: true,
start: path.joinSafe(__dirname, ".."),
start: joinSafe(__dirname, ".."),
});

const copyLeftLicensesList = Object.keys(licenses).filter((license) =>
Expand Down
14 changes: 7 additions & 7 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { execFile, spawn } = require("node:child_process");
const { promisify } = require("node:util");
const { readFile } = require("node:fs/promises");
const { gt, lt } = require("semver");
const path = require("upath");
const { joinSafe, normalizeTrim } = require("upath");

const execFileAsync = promisify(execFile);

Expand Down Expand Up @@ -76,9 +76,9 @@ class UnRTF {
constructor(binPath) {
/* istanbul ignore else: requires specific OS */
if (binPath) {
this.unrtfPath = path.normalizeTrim(binPath);
this.unrtfPath = normalizeTrim(binPath);
} else if (process.platform === "win32") {
this.unrtfPath = path.joinSafe(
this.unrtfPath = joinSafe(
__dirname,
"lib",
"win32",
Expand Down Expand Up @@ -166,7 +166,7 @@ class UnRTF {
let buff;
try {
// eslint-disable-next-line security/detect-non-literal-fs-filename
buff = await readFile(path.normalizeTrim(file));
buff = await readFile(normalizeTrim(file));
} catch {
throw new Error("File missing");
}
Expand All @@ -178,7 +178,7 @@ class UnRTF {
}

const { stderr } = await execFileAsync(
path.joinSafe(this.unrtfPath, "unrtf"),
joinSafe(this.unrtfPath, "unrtf"),
["--version"]
);

Expand All @@ -190,10 +190,10 @@ class UnRTF {
const versionInfo = /^(\d{1,2}\.\d{1,2}\.\d{1,2})/u.exec(stderr)[1];

const args = parseOptions(acceptedOptions, options, versionInfo);
args.push(path.normalizeTrim(file));
args.push(normalizeTrim(file));

return new Promise((resolve, reject) => {
const child = spawn(path.joinSafe(this.unrtfPath, "unrtf"), args);
const child = spawn(joinSafe(this.unrtfPath, "unrtf"), args);

let stdOut = "";
let stdErr = "";
Expand Down
12 changes: 3 additions & 9 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { execFile } = require("node:child_process");
const { promisify } = require("node:util");
const isHtml = require("is-html");
const { gt, lt } = require("semver");
const path = require("upath");
const { joinSafe } = require("upath");
const generateCombos = require("../test_resources/utils/gen-combos");

const execFileAsync = promisify(execFile);
Expand All @@ -15,13 +15,7 @@ const { UnRTF } = require("./index");
const testDirectory = `${__dirname}/../test_resources/test_files/`;
const file = `${testDirectory}test-rtf-complex.rtf`;

const windowsPath = path.joinSafe(
__dirname,
"lib",
"win32",
"unrtf-0.19.3",
"bin"
);
const windowsPath = joinSafe(__dirname, "lib", "win32", "unrtf-0.19.3", "bin");
let testBinaryPath;
switch (process.platform) {
// macOS
Expand Down Expand Up @@ -86,7 +80,7 @@ describe("Convert function", () => {

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

0 comments on commit 7b5dba2

Please sign in to comment.