From aa68c1824657072ac3951fd7d7e32680d26e69a3 Mon Sep 17 00:00:00 2001 From: Jake Jarvis Date: Tue, 5 Oct 2021 11:27:43 -0400 Subject: [PATCH] use `process.cwd()` instead of `__dirname` for expected relative paths --- index.js | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index cec8d7f..0818cbe 100644 --- a/index.js +++ b/index.js @@ -1,7 +1,6 @@ import path from "path"; import stream from "stream"; import { promisify } from "util"; -import { fileURLToPath } from "url"; import fs from "fs-extra"; import tempy from "tempy"; import got from "got"; @@ -9,16 +8,13 @@ import sumchecker from "sumchecker"; import decompress from "decompress"; import urlParse from "url-parse"; -// https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c#what-do-i-use-instead-of-__dirname-and-__filename -const __dirname = path.dirname(fileURLToPath(import.meta.url)); - export default async function downloader(downloadUrl, checksumUrl, options) { // normalize options and set defaults options = { filename: options.filename ?? urlParse(downloadUrl).pathname.split("/").pop(), extract: !!options.extract, - tempDir: options.tempDir ? path.resolve(__dirname, options.tempDir) : tempy.directory(), - destDir: options.destDir ? path.resolve(__dirname, options.destDir) : path.resolve(__dirname, "download"), + tempDir: options.tempDir ? path.resolve(process.cwd(), options.tempDir) : tempy.directory(), + destDir: options.destDir ? path.resolve(process.cwd(), options.destDir) : path.resolve(process.cwd(), "download"), cleanDestDir: !!options.cleanDestDir, algorithm: options.algorithm ?? "sha256", encoding: options.encoding ?? "binary",