Skip to content

Commit

Permalink
Merge branch 'master' into gh-2884
Browse files Browse the repository at this point in the history
  • Loading branch information
retorquere committed May 20, 2024
2 parents e858da8 + c702025 commit 6588430
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 94 deletions.
39 changes: 21 additions & 18 deletions content/path-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,37 @@ export async function findBinary(bin: string, installationDirectory: { mac?: str

const ENV = Components.classes['@mozilla.org/process/environment;1'].getService(Components.interfaces.nsIEnvironment)
const VarRef = Zotero.isWin ? /%([A-Z][A-Z0-9]*)%/ig : /[$]([A-Z][A-Z0-9]*)/ig
function expandVars(name: string, expanded: Record<string, string>): string {
if (typeof expanded[name] !== 'string') {
expanded[name] = ENV.get(name) || ''
let more = true
while (more) {
more = false
expanded[name] = expanded[name].replace(VarRef, (match, varref) => {
more = true
return expandVars(varref, expanded)
})
}
function resolveVars(path: string, resolved: Record<string, string>): string {
let more = true
while (more) {
more = false
path = path.replace(VarRef, (match, varref) => {
more = true
if (typeof resolved[varref] !== 'string') resolved[varref] = ENV.get(name) || ''
return resolved[varref]
})
}
return expanded[name]
return path
}

async function pathSearch(bin: string, installationDirectory: { mac?: string[], win?: string[] } = {}): Promise<string> {
const env = Components.classes['@mozilla.org/process/environment;1'].getService(Components.interfaces.nsIEnvironment)

let paths: string[] = ENV.get('PATH').split(Zotero.isWin ? ';' : ':')

const expanded = {}
paths = paths.map(p => expandVars(p, expanded))
log.debug('path-search: looking for', bin, 'in', ENV.get('PATH'), paths)
const PATH = ENV.get('PATH')
if (!PATH.length) {
log.error('path-search: PATH not set')
return ''
}
let paths: string[] = PATH.split(Zotero.isWin ? ';' : ':')
log.debug('path-search:', PATH, '=>', paths)
const resolved = {}
paths = paths.map(p => resolveVars(p, resolved))
log.debug('path-search: looking for', bin, 'in', PATH, paths)
if (Zotero.isWin && installationDirectory.win) paths.unshift(...(installationDirectory.win))
if (Zotero.isMac && installationDirectory.mac) paths.unshift(...(installationDirectory.mac))
paths = paths.filter(p => p)
if (!paths.length) {
log.error('path-search: PATH not set')
log.error('path-search:', PATH, 'yielded no directories')
return ''
}

Expand Down
85 changes: 15 additions & 70 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zotero-better-bibtex",
"version": "6.7.197",
"version": "6.7.198",
"description": "Make Zotero useful for us LaTeX holdouts.",
"homepage": "https://retorque.re/zotero-better-bibtex",
"license": "ISC",
Expand Down Expand Up @@ -110,7 +110,7 @@
"uzip": "^0.20201231.0",
"words-to-numbers": "^1.5.1",
"xregexp": "^5.1.1",
"zotero-plugin": "2.0.15"
"zotero-plugin": "2.0.16"
},
"devDependencies": {
"@retorquere/bibtex-parser": "^9.0.10",
Expand Down Expand Up @@ -169,7 +169,7 @@
"process": "^0.11.10",
"properties-reader": "^2.3.0",
"pug": "^3.0.2",
"putout": "^35.24.0",
"putout": "^35.25.0",
"recast": "^0.23.7",
"regenerate": "^1.4.2",
"rimraf": "^5.0.7",
Expand Down
2 changes: 1 addition & 1 deletion submodules/babel
2 changes: 1 addition & 1 deletion submodules/citation-style-language-locales
2 changes: 1 addition & 1 deletion submodules/zotero

0 comments on commit 6588430

Please sign in to comment.