Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: check for Binaryen installation #725

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
[#721](https://github.com/hypermodeinc/modus/pull/721)
- feat: support MySQL database connections [#722](https://github.com/hypermodeinc/modus/pull/722)
- chore: refactoring / tests [#723](https://github.com/hypermodeinc/modus/pull/723)
- feat: check for Binaryen installation [#725](https://github.com/hypermodeinc/modus/pull/725)

## 2025-01-09 - CLI 0.16.6

Expand Down
3 changes: 2 additions & 1 deletion cli/src/commands/info/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import os from "node:os";
import * as vi from "../../util/versioninfo.js";
import { SDK } from "../../custom/globals.js";
import { getHeader } from "../../custom/header.js";
import { getGoVersion, getNPMVersion, getTinyGoVersion } from "../../util/systemVersions.js";
import { getGoVersion, getNPMVersion, getTinyGoVersion, getBinaryenVersion } from "../../util/systemVersions.js";
import { BaseCommand } from "../../baseCommand.js";

export default class InfoCommand extends BaseCommand {
Expand Down Expand Up @@ -38,6 +38,7 @@ export default class InfoCommand extends BaseCommand {
"NPM Version": (await getNPMVersion()) || "Not installed",
"Go Version": (await getGoVersion()) || "Not installed",
"TinyGo Version": (await getTinyGoVersion()) || "Not installed",
"Binaryen Version": (await getBinaryenVersion()) || "Not installed",
};
}

Expand Down
27 changes: 24 additions & 3 deletions cli/src/commands/new/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { extract } from "../../util/tar.js";
import SDKInstallCommand from "../sdk/install/index.js";
import { getHeader } from "../../custom/header.js";
import * as inquirer from "@inquirer/prompts";
import { getGoVersion, getTinyGoVersion } from "../../util/systemVersions.js";
import { getGoVersion, getTinyGoVersion, getBinaryenVersion } from "../../util/systemVersions.js";
import { generateAppName } from "../../util/appname.js";
import { BaseCommand } from "../../baseCommand.js";
import { isErrorWithName } from "../../util/errors.js";
Expand Down Expand Up @@ -194,13 +194,15 @@ export default class NewCommand extends BaseCommand {
case SDK.Go: {
const goVersion = await getGoVersion();
const tinyGoVersion = await getTinyGoVersion();
const binaryenVersion = await getBinaryenVersion();

const foundGo = !!goVersion;
const foundTinyGo = !!tinyGoVersion;
const foundBinaryen = !!binaryenVersion;
const okGo = foundGo && semver.gte(goVersion, MinGoVersion);
const okTinyGo = foundTinyGo && semver.gte(tinyGoVersion, MinTinyGoVersion);

if (okGo && okTinyGo) {
if (okGo && okTinyGo && foundBinaryen) {
break;
}

Expand All @@ -222,6 +224,12 @@ export default class NewCommand extends BaseCommand {
this.log(chalk.dim(`• TinyGo v${MinTinyGoVersion} or newer `) + chalk.red("(not found)"));
}

if (foundBinaryen) {
this.log(chalk.dim(`• Binaryen `) + chalk.green(`(found v${binaryenVersion})`));
} else {
this.log(chalk.dim(`• Binaryen `) + chalk.red("(not found)"));
}

this.log();

if (!okGo) {
Expand All @@ -232,11 +240,24 @@ export default class NewCommand extends BaseCommand {
if (!okTinyGo) {
this.log(chalk.yellow(`Please install TinyGo ${MinTinyGoVersion} or newer from https://tinygo.org/getting-started/install`));
if (os.platform() === "win32") {
this.log(`Note that you will need to install the binaryen components for wasi support.`);
this.log(`Note that you will need to install the Binaryen components for WASM support.`);
this.log(`Please install with: scoop install tinygo binaryen`);
} else if (os.platform() === "darwin") {
this.log(`Please install with: brew install tinygo`);
}
this.log();
}

if (!foundBinaryen) {
if (os.platform() === "win32") {
this.log(chalk.yellow(`Please install Binaryen from Scoop: scoop install binaryen`));
} else if (os.platform() === "darwin") {
this.log(chalk.yellow(`Please install Binaryen from Homebrew: brew install binaryen`));
} else {
this.log(chalk.yellow(`Please install Binaryen from your package manager.`));
}
}

this.log(`Make sure to add Go and TinyGo to your PATH. You can check for yourself by running:`);
this.log(`${chalk.dim("$")} go version`);
this.log(`${chalk.dim("$")} tinygo version`);
Expand Down
10 changes: 10 additions & 0 deletions cli/src/util/systemVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ export async function getTinyGoVersion(): Promise<string | undefined> {
}
}

export async function getBinaryenVersion(): Promise<string | undefined> {
try {
const result = await execFile("wasm-opt", ["--version"], EXEC_OPTIONS);
const parts = result.stdout.split(" ");
return parts.length > 2 ? parts[2] : undefined;
} catch {
/* empty */
}
}

export async function getNPMVersion(): Promise<string | undefined> {
try {
const result = await execFile("npm", ["--version"], EXEC_OPTIONS);
Expand Down
Loading