-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dap-support
- Loading branch information
Showing
11 changed files
with
234 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
".": "0.0.8" | ||
".": "0.0.11" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,66 @@ | ||
import os from 'os'; | ||
import path from 'path'; | ||
import fs from 'fs'; | ||
import which from 'which'; | ||
import { NargoNotFoundError } from './noir'; | ||
import { MarkdownString } from 'vscode'; | ||
|
||
const nargoBinaries = ['nargo']; | ||
// List of possible nargo binaries to find on Path | ||
// We prioritize 'nargo' as the more standard version. | ||
const NARGO_BINARIES = ['nargo', 'aztec-nargo']; | ||
// List of possible default installations in users folder | ||
const NARGO_INSTALL_LOCATION_POSTFIXES = ['.nargo/bin/nargo', '.aztec/bin/aztec-nargo']; | ||
|
||
export default function findNargo() { | ||
for (const bin of nargoBinaries) { | ||
function absoluteInstallLocationPaths(homeDir: string): string[] { | ||
return NARGO_INSTALL_LOCATION_POSTFIXES.map((postfix) => path.join(homeDir, postfix)).filter((filePath) => | ||
fs.existsSync(filePath), | ||
); | ||
} | ||
|
||
export function findNargoBinaries(homeDir: string): string[] { | ||
// Note that JS sets maintain insertion order. | ||
const nargoBinaryPaths: Set<string> = new Set(); | ||
|
||
for (const bin of NARGO_BINARIES) { | ||
try { | ||
const nargo = which.sync(bin); | ||
const path = which.sync(bin); | ||
// If it didn't throw, we found a nargo binary | ||
return nargo; | ||
nargoBinaryPaths.add(path); | ||
} catch (err) { | ||
// Not found | ||
} | ||
} | ||
throw new Error('Unable to locate any nargo binary. Did you install it?'); | ||
|
||
// So far we have not found installations on path | ||
// Let's check default installation locations | ||
for (const filePath of absoluteInstallLocationPaths(homeDir)) { | ||
nargoBinaryPaths.add(filePath); | ||
} | ||
|
||
return [...nargoBinaryPaths]; | ||
} | ||
|
||
export default function findNargo() { | ||
const homeDir = os.homedir(); | ||
const nargoBinaryPaths = findNargoBinaries(homeDir); | ||
|
||
if (nargoBinaryPaths.length > 0) { | ||
return nargoBinaryPaths[0]; | ||
} else { | ||
const message = new MarkdownString(); | ||
message.appendText(`Could not locate any of\n`); | ||
for (const nargoBinary of NARGO_BINARIES) { | ||
message.appendMarkdown(`\`${nargoBinary}\``); | ||
message.appendText(`\n`); | ||
} | ||
|
||
message.appendText(`on \`$PATH\`, or one of default installation locations\n`); | ||
for (const postfix of NARGO_INSTALL_LOCATION_POSTFIXES) { | ||
const filePath = path.join(homeDir, postfix); | ||
message.appendMarkdown(`\`${filePath}\``); | ||
message.appendText(`\n`); | ||
} | ||
|
||
throw new NargoNotFoundError(message); | ||
} | ||
} |
Oops, something went wrong.