From 59ebffb063722d409d7b078268000bf17ef6a74a Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 9 Mar 2024 14:44:41 +0530 Subject: [PATCH] fix: __dirname workaround --- lib/cli.js | 3 +++ lib/findpath.js | 2 ++ lib/install.js | 6 ++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index b758746..fd70dd0 100755 --- a/lib/cli.js +++ b/lib/cli.js @@ -4,10 +4,13 @@ import child_process from 'node:child_process'; import fs from 'node:fs'; import path from 'node:path'; import process from 'node:process'; +import url from 'node:url'; + import { copyAssets } from './app_assets.js'; import { findpath } from './findpath.js'; async function run() { + const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); /* Rename nw.js's own package.json as workaround for https://github.com/nwjs/nw.js/issues/1503 */ const packagejson = path.resolve(__dirname, '..', 'package.json'); const packagejsonBackup = path.resolve(__dirname, '..', 'package_backup.json'); diff --git a/lib/findpath.js b/lib/findpath.js index 2e03fa3..78c9fe4 100644 --- a/lib/findpath.js +++ b/lib/findpath.js @@ -1,5 +1,6 @@ import process from 'node:process'; import path from 'node:path'; +import url from 'node:url'; /** * Get the platform dependant path of the NW.js or ChromeDriver binary. @@ -8,6 +9,7 @@ import path from 'node:path'; * @return {string} */ export function findpath(executable = 'nwjs') { + const __dirname = path.dirname(url.fileURLToPath(import.meta.url)); const nwDir = path.resolve(__dirname, '..', 'nwjs'); /** * File path to executable. diff --git a/lib/install.js b/lib/install.js index 8e93074..023e22f 100755 --- a/lib/install.js +++ b/lib/install.js @@ -2,8 +2,8 @@ import { createWriteStream, existsSync } from 'node:fs'; import { rename, rm, symlink } from 'node:fs/promises'; import { get } from 'node:https'; import { resolve } from 'node:path'; -import { arch, env, platform, exit } from 'node:process'; -import { URL } from 'node:url'; +import { arch, dirname, env, platform, exit } from 'node:process'; +import { URL, fileURLToPath } from 'node:url'; import compressing from 'compressing'; import { SingleBar, Presets } from 'cli-progress'; @@ -11,6 +11,8 @@ import { parse } from 'semver'; import manifest from '../package.json' assert { type: 'json' }; +const __dirname = dirname(fileURLToPath(import.meta.url)); + install() .catch((error) => { if (error.code === 'EPERM') {