-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Verify a compatable version of puya is available on the PATH, …
…and fail or warn gracefully if it is not
- Loading branch information
1 parent
979a6b9
commit 8455edb
Showing
9 changed files
with
158 additions
and
17 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Constants } from '../constants' | ||
import { logger } from '../logger' | ||
import { runPuya } from './run-puya' | ||
|
||
export function checkPuyaVersion() { | ||
const versionParser = new VersionParser() | ||
runPuya({ | ||
command: 'puya', | ||
args: ['--version'], | ||
onOutput: (line) => versionParser.receiveLine(line), | ||
}) | ||
|
||
if (versionParser.version) { | ||
const ver = versionParser.version | ||
// Compare | ||
const [major, minor, rev] = Constants.targetedPuyaVersion.split('.').map((x) => Number(x)) | ||
if (major !== ver.major || minor !== ver.minor) { | ||
logger.warn( | ||
undefined, | ||
`Installed version of puya (${ver.major}.${ver.minor}.${ver.rev}) does not match targeted version for puya-ts (${Constants.targetedPuyaVersion}). There may be compatability issues.`, | ||
) | ||
} else if (rev !== ver.rev) { | ||
logger.debug( | ||
undefined, | ||
`Installed revision of puya (${ver.major}.${ver.minor}.${ver.rev}) does not match targeted revision for puya-ts (${Constants.targetedPuyaVersion})`, | ||
) | ||
} | ||
} else { | ||
logger.warn(undefined, `Unable to verify installed puya version. Please ensure version ${Constants.targetedPuyaVersion} is available`) | ||
} | ||
} | ||
|
||
type SemVer = { | ||
major: number | ||
minor: number | ||
rev: number | ||
} | ||
|
||
class VersionParser { | ||
#ver: SemVer | undefined | ||
|
||
receiveLine(line: string): void { | ||
const matched = /^puya (\d+)\.(\d+)\.(\d+)$/.exec(line) | ||
if (!matched) { | ||
logger.debug(undefined, `'puya --version' command returned unexpected output: "${line}"`) | ||
} else { | ||
this.#ver = { | ||
major: Number(matched[1]), | ||
minor: Number(matched[2]), | ||
rev: Number(matched[3]), | ||
} | ||
} | ||
} | ||
|
||
get version(): undefined | SemVer { | ||
return this.#ver | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { sync as whichSync } from 'which' | ||
import { EnvironmentError } from '../errors' | ||
|
||
export function ensurePuyaExists() { | ||
if ( | ||
whichSync('puya', { | ||
nothrow: true, | ||
}) | ||
) | ||
return | ||
throw new EnvironmentError( | ||
`Failed to resolve command path, 'puya' wasn't found. Please ensure puya compiler has been installed and is available on your PATH.`, | ||
) | ||
} |
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