diff --git a/.github/actions/get_dfx_version/action.yml b/.github/actions/get_dfx_version/action.yml index 1acb4e5fad..92f68b5baa 100644 --- a/.github/actions/get_dfx_version/action.yml +++ b/.github/actions/get_dfx_version/action.yml @@ -2,7 +2,7 @@ name: Get dfx version description: Determines Azle's dfx version outputs: dfx-version: - description: Returns the version of dfx that Azle will test against and use to generate its Wasm binary template + description: Returns the version of dfx that Azle will test against and use to generate its Wasm binary templates value: ${{ steps.get-dfx-version.outputs.dfx-version }} runs: using: composite diff --git a/.github/actions/get_node_version/action.yml b/.github/actions/get_node_version/action.yml index 262c7adc50..eadb0684f6 100644 --- a/.github/actions/get_node_version/action.yml +++ b/.github/actions/get_node_version/action.yml @@ -2,7 +2,7 @@ name: Get node version description: Determines Azle's node version outputs: node-version: - description: Returns the version of node that Azle will test against and use to generate its Wasm binary template + description: Returns the version of node that Azle will test against and use to generate its Wasm binary templates value: ${{ steps.get-node-version.outputs.node-version }} runs: using: composite diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ca53608ff3..586f8cf843 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -159,7 +159,7 @@ jobs: - name: Run pre-test Azle setup run: | - # Install dfx (Note: DFX must be installed before `npm install` because the azle instalation process requires dfx) + # Install dfx (Note: DFX must be installed before `npm install` because the azle installation process requires dfx) src/build/stable/commands/install_global_dependencies/install_dfx.sh ${{ steps.get-dfx-version.outputs.dfx-version }} echo "$HOME/.local/share/dfx/bin" >> $GITHUB_PATH diff --git a/src/build/stable/commands/install_global_dependencies/index.ts b/src/build/stable/commands/install_global_dependencies/index.ts index fe3b328251..9a0d7040cf 100644 --- a/src/build/stable/commands/install_global_dependencies/index.ts +++ b/src/build/stable/commands/install_global_dependencies/index.ts @@ -1,22 +1,17 @@ import { IOType } from 'child_process'; -import { readFile } from 'fs/promises'; -import { join } from 'path'; +import { azle } from '../../../../../package.json'; import { execSyncPretty } from '../../utils/exec_sync_pretty'; import { AZLE_PACKAGE_PATH } from '../../utils/global_paths'; type DependencyName = 'node' | 'dfx' | 'rust' | 'wasi2ic'; -type Versions = { - [key in DependencyName]: string; -}; - -type Dependencies = { +type DependencyInstallInfo = { [key in DependencyName]: boolean; }; export async function runCommand( - dependenciesToInstall: Dependencies, + dependenciesToInstall: DependencyInstallInfo, ioType: IOType ): Promise { for (const key in dependenciesToInstall) { @@ -27,29 +22,12 @@ export async function runCommand( } } -async function installDependency( - dependency: DependencyName, - ioType: IOType -): Promise { +function installDependency(dependency: DependencyName, ioType: IOType): void { console.info(`Installing ${dependency}...`); - const version = (await getGlobalDependencies())[dependency]; + const version = azle.globalDependencies[dependency]; const script = `install_${dependency}.sh`; execSyncPretty( `${AZLE_PACKAGE_PATH}/src/build/stable/commands/install_global_dependencies/${script} ${version}`, ioType ); } - -async function getGlobalDependencies(): Promise { - const packageJsonPath = join(AZLE_PACKAGE_PATH, 'package.json'); - - const packageJson = JSON.parse(await readFile(packageJsonPath, 'utf-8')); - - const globalDependencies = packageJson.azle.globalDependencies; - - if (globalDependencies === undefined) { - throw new Error('No globalDependencies found in package.json.'); - } - - return globalDependencies; -} diff --git a/src/build/stable/commands/install_global_dependencies/install_dfx.sh b/src/build/stable/commands/install_global_dependencies/install_dfx.sh index 29e8b7c5bd..e957673178 100755 --- a/src/build/stable/commands/install_global_dependencies/install_dfx.sh +++ b/src/build/stable/commands/install_global_dependencies/install_dfx.sh @@ -8,22 +8,6 @@ fi DFX_VERSION=$1 -if command -v dfx &> /dev/null; then - INSTALLED_VERSION=$(npx tsx src/build/stable/utils/versions/dfx.ts 2>&1 | tr -d '[:space:]') - - echo "Installed dfx version: $INSTALLED_VERSION" - echo "Requested dfx version: $DFX_VERSION" - - if [ "$INSTALLED_VERSION" = "$DFX_VERSION" ]; then - echo "dfx $DFX_VERSION is already installed. No installation needed." - exit 0 - else - echo "Updating dfx from version $INSTALLED_VERSION to $DFX_VERSION" - fi -else - echo "dfx is not installed. Proceeding with installation of dfx $DFX_VERSION." -fi - # Install or update dfx using the official installation script echo "Installing dfx version $DFX_VERSION..." DFXVM_INIT_YES=true DFX_VERSION=$DFX_VERSION sh -ci "$(curl -fsSL https://sdk.dfinity.org/install.sh)" diff --git a/src/build/stable/commands/install_global_dependencies/install_node.sh b/src/build/stable/commands/install_global_dependencies/install_node.sh index 4bc72bbd7a..93b55f7625 100755 --- a/src/build/stable/commands/install_global_dependencies/install_node.sh +++ b/src/build/stable/commands/install_global_dependencies/install_node.sh @@ -17,6 +17,7 @@ else echo "Installing Node.js version $NODE_VERSION..." nvm install "$NODE_VERSION" nvm use "$NODE_VERSION" + nvm alias default "$NODE_VERSION" echo "Node.js $NODE_VERSION installation completed." fi diff --git a/src/build/stable/commands/install_global_dependencies/install_rust.sh b/src/build/stable/commands/install_global_dependencies/install_rust.sh index 4e20123c7b..45091a8c7e 100755 --- a/src/build/stable/commands/install_global_dependencies/install_rust.sh +++ b/src/build/stable/commands/install_global_dependencies/install_rust.sh @@ -8,22 +8,6 @@ fi RUST_VERSION=$1 -if command -v rustc &> /dev/null; then - INSTALLED_VERSION=$(npx tsx src/build/stable/utils/versions/rust.ts 2>&1 | tr -d '[:space:]') - - echo "Installed Rust version: $INSTALLED_VERSION" - echo "Requested Rust version: $RUST_VERSION" - - if [ "$INSTALLED_VERSION" = "$RUST_VERSION" ]; then - echo "Rust $RUST_VERSION is already installed. No installation needed." - exit 0 - else - echo "Updating Rust from version $INSTALLED_VERSION to $RUST_VERSION" - fi -else - echo "Rust is not installed. Proceeding with installation of Rust $RUST_VERSION." -fi - # Install Rust echo "Installing Rust version $RUST_VERSION..." curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain "$RUST_VERSION" diff --git a/src/build/stable/commands/install_global_dependencies/install_wasi2ic.sh b/src/build/stable/commands/install_global_dependencies/install_wasi2ic.sh index 7a4b78a27d..3124a4e330 100755 --- a/src/build/stable/commands/install_global_dependencies/install_wasi2ic.sh +++ b/src/build/stable/commands/install_global_dependencies/install_wasi2ic.sh @@ -15,22 +15,6 @@ else WASI2IC_URL="" fi -if command -v wasi2ic &> /dev/null; then - INSTALLED_VERSION=$(npx tsx src/build/stable/utils/versions/wasi2ic.ts 2>&1 | tr -d '[:space:]') - - echo "Installed wasi2ic version: $INSTALLED_VERSION" - echo "Requested wasi2ic version: $WASI2IC_VERSION" - - if [ "$INSTALLED_VERSION" = "$WASI2IC_VERSION" ]; then - echo "wasi2ic $WASI2IC_VERSION is already installed. No installation needed." - exit 0 - else - echo "Updating wasi2ic from version $INSTALLED_VERSION to $WASI2IC_VERSION" - fi -else - echo "wasi2ic is not installed. Proceeding with installation." -fi - # Install or update wasi2ic if [[ -n "$WASI2IC_URL" ]]; then echo "Installing wasi2ic from repository $WASI2IC_URL" diff --git a/src/build/stable/utils/log_global_dependencies.ts b/src/build/stable/utils/log_global_dependencies.ts index 5f02c41227..ac67caf065 100644 --- a/src/build/stable/utils/log_global_dependencies.ts +++ b/src/build/stable/utils/log_global_dependencies.ts @@ -2,16 +2,16 @@ import { readFile, writeFile } from 'fs/promises'; import { join } from 'path'; import { AZLE_PACKAGE_PATH } from './global_paths'; -import { getDfxVersionLocal } from './versions/dfx'; -import { getNodeVersionLocal } from './versions/node'; -import { getRustVersionLocal } from './versions/rust'; -import { getWasi2icVersionLocal } from './versions/wasi2ic'; +import { getLocalDfxVersion } from './versions/dfx'; +import { getLocalNodeVersion } from './versions/node'; +import { getLocalRustVersion } from './versions/rust'; +import { getLocalWasi2icVersion } from './versions/wasi2ic'; export async function logGlobalDependencies(): Promise { - const wasiVersion = getWasi2icVersionLocal(); - const nodeVersion = getNodeVersionLocal(); - const rustVersion = getRustVersionLocal(); - const dfxVersion = getDfxVersionLocal(); + const wasiVersion = getLocalWasi2icVersion(); + const nodeVersion = getLocalNodeVersion(); + const rustVersion = getLocalRustVersion(); + const dfxVersion = getLocalDfxVersion(); const globalDependencies = { wasi2ic: wasiVersion, diff --git a/src/build/stable/utils/versions/dfx.ts b/src/build/stable/utils/versions/dfx.ts index 9d72033d2a..d5a8f7e763 100644 --- a/src/build/stable/utils/versions/dfx.ts +++ b/src/build/stable/utils/versions/dfx.ts @@ -1,9 +1,6 @@ -import { pathToFileURL } from 'url'; - import { execSyncPretty } from '../exec_sync_pretty'; -import { getVersionFromPackageJson } from './get_version_from_package_json'; -export function getDfxVersionLocal(): string { +export function getLocalDfxVersion(): string { const dfxOutput = execSyncPretty('dfx --version').toString().trim(); const match = dfxOutput.match(/dfx (\d+\.\d+\.\d+)/); @@ -14,21 +11,3 @@ export function getDfxVersionLocal(): string { throw new Error('Could not parse the dfx version'); } } - -export async function getDfxVersionPackageJson(): Promise { - return await getVersionFromPackageJson('dfx'); -} - -async function main(): Promise { - const args = process.argv.slice(2); - - if (args.includes('--local')) { - process.stdout.write(getDfxVersionLocal()); - } else { - process.stdout.write(await getDfxVersionPackageJson()); - } -} - -if (import.meta.url === pathToFileURL(process.argv[1]).href) { - main(); -} diff --git a/src/build/stable/utils/versions/get_version_from_package_json.ts b/src/build/stable/utils/versions/get_version_from_package_json.ts deleted file mode 100644 index dddb63fdab..0000000000 --- a/src/build/stable/utils/versions/get_version_from_package_json.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { readFile } from 'fs/promises'; -import { join } from 'path'; - -import { AZLE_PACKAGE_PATH } from '../global_paths'; - -export async function getVersionFromPackageJson(name: string): Promise { - const packageJson = JSON.parse( - await readFile(join(AZLE_PACKAGE_PATH, 'package.json'), 'utf-8') - ); - - const version = packageJson?.azle?.globalDependencies[name]; - - if (version !== undefined) { - return version; - } else { - throw new Error(`${name} version not found in azle.globalDependencies`); - } -} diff --git a/src/build/stable/utils/versions/node.ts b/src/build/stable/utils/versions/node.ts index a1593edabf..0f045f0aa9 100644 --- a/src/build/stable/utils/versions/node.ts +++ b/src/build/stable/utils/versions/node.ts @@ -1,8 +1,6 @@ -import { pathToFileURL } from 'url'; - import { execSyncPretty } from '../exec_sync_pretty'; -export function getNodeVersionLocal(): string { +export function getLocalNodeVersion(): string { const nodeOutput = execSyncPretty('node --version').toString().trim(); const match = nodeOutput.match(/^v(\d+\.\d+\.\d+)/); @@ -12,11 +10,3 @@ export function getNodeVersionLocal(): string { throw new Error('Could not parse node version'); } } - -function main(): void { - process.stdout.write(getNodeVersionLocal()); -} - -if (import.meta.url === pathToFileURL(process.argv[1]).href) { - main(); -} diff --git a/src/build/stable/utils/versions/rust.ts b/src/build/stable/utils/versions/rust.ts index c18b37ca17..faa5b58650 100644 --- a/src/build/stable/utils/versions/rust.ts +++ b/src/build/stable/utils/versions/rust.ts @@ -1,8 +1,6 @@ -import { pathToFileURL } from 'url'; - import { execSyncPretty } from '../exec_sync_pretty'; -export function getRustVersionLocal(): string { +export function getLocalRustVersion(): string { const rustcOutput = execSyncPretty('rustc --version').toString().trim(); const match = rustcOutput.match(/^rustc\s+(\d+\.\d+\.\d+)/); @@ -12,11 +10,3 @@ export function getRustVersionLocal(): string { throw new Error('Could not parse rustc version'); } } - -function main(): void { - process.stdout.write(getRustVersionLocal()); -} - -if (import.meta.url === pathToFileURL(process.argv[1]).href) { - main(); -} diff --git a/src/build/stable/utils/versions/wasi2ic.ts b/src/build/stable/utils/versions/wasi2ic.ts index 15f4698d28..23d5a6db20 100644 --- a/src/build/stable/utils/versions/wasi2ic.ts +++ b/src/build/stable/utils/versions/wasi2ic.ts @@ -1,8 +1,6 @@ -import { pathToFileURL } from 'url'; - import { execSyncPretty } from '../exec_sync_pretty'; -export function getWasi2icVersionLocal(): string { +export function getLocalWasi2icVersion(): string { return getCargoVersion('wasi2ic'); } @@ -25,11 +23,3 @@ function getCargoVersion(packageName: string): string { throw new Error(`Could not parse ${packageName} version`); } } - -function main(): void { - process.stdout.write(getWasi2icVersionLocal()); -} - -if (import.meta.url === pathToFileURL(process.argv[1]).href) { - main(); -}