From 9b797c9adf63e5bdf5abd55ac8e32792398235e5 Mon Sep 17 00:00:00 2001 From: Benjamin DeMann Date: Tue, 17 Sep 2024 09:38:04 -0600 Subject: [PATCH] fixup into more consistent version checking --- .../stable/commands/install_global_dependencies/index.ts | 2 +- src/build/stable/utils/versions/dfx.ts | 4 +++- src/build/stable/utils/versions/node.ts | 4 +++- src/build/stable/utils/versions/rust.ts | 4 +++- src/build/stable/utils/versions/wasi2ic.ts | 4 +++- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/build/stable/commands/install_global_dependencies/index.ts b/src/build/stable/commands/install_global_dependencies/index.ts index b45be5ba83..1016f0ef24 100644 --- a/src/build/stable/commands/install_global_dependencies/index.ts +++ b/src/build/stable/commands/install_global_dependencies/index.ts @@ -102,7 +102,7 @@ If no options are provided, all dependencies will be installed. async function getGlobalDependencies(): Promise { // Path to package.json - const packageJsonPath = join(process.cwd(), 'package.json'); + const packageJsonPath = join(AZLE_PACKAGE_PATH, 'package.json'); // Read the existing package.json file const packageJsonContent = await readFile(packageJsonPath, 'utf-8'); diff --git a/src/build/stable/utils/versions/dfx.ts b/src/build/stable/utils/versions/dfx.ts index 3f86ad5c34..dddd528355 100644 --- a/src/build/stable/utils/versions/dfx.ts +++ b/src/build/stable/utils/versions/dfx.ts @@ -1,3 +1,5 @@ +import { pathToFileURL } from 'url'; + import { execSyncPretty } from '../exec_sync_pretty'; export function getDfxVersion(): string { @@ -22,6 +24,6 @@ function main(): void { } } -if (require.main === module) { +if (import.meta.url === pathToFileURL(process.argv[1]).href) { main(); } diff --git a/src/build/stable/utils/versions/node.ts b/src/build/stable/utils/versions/node.ts index 4aa213a9f9..907c87d304 100644 --- a/src/build/stable/utils/versions/node.ts +++ b/src/build/stable/utils/versions/node.ts @@ -1,3 +1,5 @@ +import { pathToFileURL } from 'url'; + import { execSyncPretty } from '../exec_sync_pretty'; export function getNodeVersion(): string { @@ -21,6 +23,6 @@ function main(): void { } } -if (require.main === module) { +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 4cf87a0918..e3ec773bd7 100644 --- a/src/build/stable/utils/versions/rust.ts +++ b/src/build/stable/utils/versions/rust.ts @@ -1,3 +1,5 @@ +import { pathToFileURL } from 'url'; + import { execSyncPretty } from '../exec_sync_pretty'; export function getRustVersion(): string { @@ -21,6 +23,6 @@ function main(): void { } } -if (require.main === module) { +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 0ecc54e461..50bf801966 100644 --- a/src/build/stable/utils/versions/wasi2ic.ts +++ b/src/build/stable/utils/versions/wasi2ic.ts @@ -1,3 +1,5 @@ +import { pathToFileURL } from 'url'; + import { execSyncPretty } from '../exec_sync_pretty'; export function getWasiVersion(): string { @@ -34,6 +36,6 @@ function main(): void { } } -if (require.main === module) { +if (import.meta.url === pathToFileURL(process.argv[1]).href) { main(); }