From 49156be0b4be8679797287b2de46521bcba827a3 Mon Sep 17 00:00:00 2001 From: Emiliano Heyns Date: Thu, 29 Aug 2024 16:43:44 +0200 Subject: [PATCH 1/2] relative paths --- content/path-search.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/content/path-search.ts b/content/path-search.ts index 0c48447404..a830d0d326 100644 --- a/content/path-search.ts +++ b/content/path-search.ts @@ -1,7 +1,7 @@ import { log } from './logger' import { Shim } from './os' -import { is7 } from './client' -const $OS = is7 ? Shim : OS +import * as client from './client' +const $OS = client.is7 ? Shim : OS // https://searchfox.org/mozilla-central/source/toolkit/modules/subprocess/subprocess_win.jsm#135 doesn't seem to work on Windows. export async function findBinary(bin: string, installationDirectory: { mac?: string[]; win?: string[] } = {}): Promise { @@ -28,19 +28,24 @@ function resolveVars(path: string, resolved: Record): string { return path } +const dirService = Components.classes['@mozilla.org/file/directory_service;1'].getService(Components.interfaces.nsIProperties) +const cwd = dirService.get('CurWorkD', Components.interfaces.nsIFile)?.path ?? '' + async function pathSearch(bin: string, installationDirectory: { mac?: string[]; win?: string[] } = {}): Promise { const PATH = ENV.get('PATH') if (!PATH.length) { log.error('path-search: PATH not set') return '' } - let paths: string[] = PATH.split(Zotero.isWin ? ';' : ':') - const resolved = {} - paths = paths.map(p => resolveVars(p, resolved)).filter((p: string, i: number, self: string[]) => self.indexOf(p) === i) + log.info(`path-search: looking for ${ bin } in ${ PATH }`) - if (Zotero.isWin && installationDirectory.win) paths.unshift(...(installationDirectory.win)) - if (Zotero.isMac && installationDirectory.mac) paths.unshift(...(installationDirectory.mac)) - paths = paths.filter(p => p) + const sep = Zotero.isWin ? '\\' : '/' + const resolved = {} + const paths: string[] = [ ...PATH.split(Zotero.isWin ? ';' : ':'), installationDirectory[client.platform] || '' ] + .map(p => resolveVars(p, resolved)) + .filter(_ => _) + .filter((p: string, i: number, self: string[]) => self.indexOf(p) === i) // unique + .map(p => cwd && p[0] === '.' && (p[1] || sep) === sep ? `${cwd}${p.substring(1)}` : p) if (!paths.length) { log.error('path-search:', PATH, 'yielded no directories') return '' From 199d652ed7eda5eca6722b23190f40ebfcedc75f Mon Sep 17 00:00:00 2001 From: Emiliano Heyns Date: Thu, 29 Aug 2024 16:55:27 +0200 Subject: [PATCH 2/2] default path last --- content/path-search.ts | 2 +- submodules/babel | 2 +- submodules/zotero | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/content/path-search.ts b/content/path-search.ts index a830d0d326..328165c866 100644 --- a/content/path-search.ts +++ b/content/path-search.ts @@ -41,7 +41,7 @@ async function pathSearch(bin: string, installationDirectory: { mac?: string[]; log.info(`path-search: looking for ${ bin } in ${ PATH }`) const sep = Zotero.isWin ? '\\' : '/' const resolved = {} - const paths: string[] = [ ...PATH.split(Zotero.isWin ? ';' : ':'), installationDirectory[client.platform] || '' ] + const paths: string[] = [ ...PATH.split(Zotero.isWin ? ';' : ':'), ...(installationDirectory[client.platform] || []) ] .map(p => resolveVars(p, resolved)) .filter(_ => _) .filter((p: string, i: number, self: string[]) => self.indexOf(p) === i) // unique diff --git a/submodules/babel b/submodules/babel index 02adf0c5af..1e0a52663c 160000 --- a/submodules/babel +++ b/submodules/babel @@ -1 +1 @@ -Subproject commit 02adf0c5afb076b8f73f41b0c197dc3ee6d6b86e +Subproject commit 1e0a52663c2ec343374cd4fcfb8162412eadbd43 diff --git a/submodules/zotero b/submodules/zotero index aed604ddc0..460d5e0f9b 160000 --- a/submodules/zotero +++ b/submodules/zotero @@ -1 +1 @@ -Subproject commit aed604ddc01b95dc9c52f4da20b1c4261d99defb +Subproject commit 460d5e0f9b3ef63804abf30d8d6dee061a851d9d