diff --git a/canister_templates/stable.wasm b/canister_templates/stable.wasm index 7bf87656d7..9c9645faef 100644 Binary files a/canister_templates/stable.wasm and b/canister_templates/stable.wasm differ diff --git a/package-lock.json b/package-lock.json index 124331ff04..88df072559 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "azle", - "version": "0.25.0-pre-bifurcation", + "version": "0.25.0-dev", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "azle", - "version": "0.25.0-pre-bifurcation", + "version": "0.25.0-dev", "hasInstallScript": true, "license": "MIT", "dependencies": { @@ -41,7 +41,7 @@ "wasmedge_quickjs": "github:demergent-labs/wasmedge-quickjs#3b3b0ee91248ccf9cd954ffafbac7e024648af92" }, "bin": { - "azle": "src/build/index.js" + "azle": "src/build/index.ts" }, "devDependencies": { "@types/deep-equal": "^1.0.4", diff --git a/package.json b/package.json index a368fdf3ae..238744b726 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "azle", - "version": "0.25.0-pre-bifurcation", + "version": "0.25.0-dev", "description": "TypeScript and JavaScript CDK for the Internet Computer", "scripts": { "typecheck": "tsc --noEmit", @@ -11,7 +11,7 @@ }, "type": "module", "bin": { - "azle": "./src/build/index.js" + "azle": "./src/build/index.ts" }, "main": "./src/lib/stable/index.ts", "repository": { diff --git a/src/build/experimental/utils/experimental_message.ts b/src/build/experimental/utils/experimental_message.ts index 5185ddef35..1c8f62950c 100644 --- a/src/build/experimental/utils/experimental_message.ts +++ b/src/build/experimental/utils/experimental_message.ts @@ -1,5 +1,5 @@ export function experimentalMessageDfxJson(description: string): string { - return `Azle: Experimental mode must be enabled to use ${description}. You can enable experimental mode in your dfx.json file like this: + return `Experimental mode must be enabled to use ${description}. You can enable experimental mode in your dfx.json file like this: { "canisters": { "canisterName": { @@ -15,5 +15,5 @@ export function experimentalMessageDfxJson(description: string): string { } export function experimentalMessageCli(description: string): string { - return `Azle: Experimental mode must be enabled to use ${description}. You can enable experimental mode with the --experimental flag`; + return `Experimental mode must be enabled to use ${description}. You can enable experimental mode with the --experimental flag`; } diff --git a/src/build/index.js b/src/build/index.js deleted file mode 100755 index 5333dd896f..0000000000 --- a/src/build/index.js +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env -S node --abort-on-uncaught-exception - -import 'tsx'; -import('./index.ts'); diff --git a/src/build/index.ts b/src/build/index.ts index 5d4022dc5f..1e4d007c1b 100755 --- a/src/build/index.ts +++ b/src/build/index.ts @@ -1,3 +1,5 @@ +#!/usr/bin/env -S npx tsx + import { IOType } from 'child_process'; import { join } from 'path'; @@ -20,6 +22,32 @@ import { getCanisterConfig } from './stable/utils/get_canister_config'; import { AZLE_PACKAGE_PATH } from './stable/utils/global_paths'; import { CanisterConfig, Command } from './stable/utils/types'; +process.on('uncaughtException', (error: Error) => { + const prefix = 'Azle BuildError'; + + const message = + process.env.AZLE_VERBOSE === 'true' + ? `${prefix}: ${error.stack}` + : `${prefix}: ${error}`; + + console.error(message); + + process.exit(1); +}); + +process.on('unhandledRejection', (reason: any) => { + const prefix = 'Azle BuildError'; + + const message = + process.env.AZLE_VERBOSE === 'true' && reason instanceof Error + ? `${prefix}: ${reason.stack}` + : `${prefix}: ${reason}`; + + console.error(message); + + process.exit(1); +}); + build(); async function build(): Promise { @@ -27,7 +55,7 @@ async function build(): Promise { if (command === undefined) { throw new Error( - `Azle: No command found when running azle. Running azle should start like this: azle [commandName]` + `No command found when running azle. Running azle should start like this: azle [commandName]` ); } @@ -40,7 +68,7 @@ async function build(): Promise { } if (command === 'install-global-dependencies') { - handleInstallGlobalDependenciesCommand(ioType); + handleInstallGlobalDependenciesCommand(); return; } @@ -82,7 +110,7 @@ async function build(): Promise { } throw new Error( - `Azle: Invalid command found when running azle. Running azle ${command} is not valid` + `Invalid command found when running azle. Running azle ${command} is not valid` ); } @@ -136,24 +164,21 @@ async function handleTemplateCommand(ioType: IOType): Promise { } } -async function handleInstallGlobalDependenciesCommand( - ioType: IOType -): Promise { +async function handleInstallGlobalDependenciesCommand(): Promise { const node = process.argv.includes('--node'); const dfx = process.argv.includes('--dfx'); const rust = process.argv.includes('--rust'); const wasi2ic = process.argv.includes('--wasi2ic'); if (!node && !dfx && !rust && !wasi2ic) { - await runInstallGlobalDependenciesCommand( - { dfx: true, node: true, rust: true, wasi2ic: true }, - ioType - ); + await runInstallGlobalDependenciesCommand({ + dfx: true, + node: true, + rust: true, + wasi2ic: true + }); } else { - await runInstallGlobalDependenciesCommand( - { dfx, node, rust, wasi2ic }, - ioType - ); + await runInstallGlobalDependenciesCommand({ dfx, node, rust, wasi2ic }); } } diff --git a/src/build/stable/commands/compile/candid_and_method_meta/execute.ts b/src/build/stable/commands/compile/candid_and_method_meta/execute.ts index 27e74ea804..fff4b87f3f 100644 --- a/src/build/stable/commands/compile/candid_and_method_meta/execute.ts +++ b/src/build/stable/commands/compile/candid_and_method_meta/execute.ts @@ -72,9 +72,7 @@ export async function execute( ); const message = new TextDecoder('utf8').decode(memory); - console.error(message); - - process.exit(1); + throw message; } } // env: { diff --git a/src/build/stable/commands/compile/get_context.ts b/src/build/stable/commands/compile/get_context.ts index 76ee81f431..14b463e41d 100644 --- a/src/build/stable/commands/compile/get_context.ts +++ b/src/build/stable/commands/compile/get_context.ts @@ -19,7 +19,7 @@ export function getContext( const candidPath = process.env.CANISTER_CANDID_PATH; if (candidPath === undefined) { - throw new Error(`Azle: CANISTER_CANDID_PATH is not defined`); + throw new Error(`CANISTER_CANDID_PATH is not defined`); } const wasmBinaryPath = join(canisterPath, `${canisterName}.wasm`); diff --git a/src/build/stable/commands/compile/javascript.ts b/src/build/stable/commands/compile/javascript.ts index 71e5a9d459..632c4e6a5c 100644 --- a/src/build/stable/commands/compile/javascript.ts +++ b/src/build/stable/commands/compile/javascript.ts @@ -51,7 +51,7 @@ export async function bundle(buildOptions: BuildOptions): Promise { if (buildResult.outputFiles === undefined) { throw new Error( - `Azle: Build process failed to produce JavaScript output files` + `Build process failed to produce JavaScript output files` ); } @@ -84,7 +84,7 @@ export function getBuildOptions(ts: string): BuildOptions { filter: /^internal$|^util$|^fs$|^fs\/promises$|^fmt$|^assert$|^buffer$|^path$|^stream$|^process$|^url$|^events$|^string_decoder$|^punycode$|^querystring$|^whatwg_url$|^encoding$|^http$|^os$|^crypto$|^zlib$|^internal\/deps\/acorn\/acorn\/dist\/acorn$|^internal\/deps\/acorn\/acorn-walk\/dist\/walk$|^perf_hooks$|^async_hooks$|^https$|^_node:fs$|^_node:os$|^_node:crypto$|^qjs:os$|^_encoding$|^wasi_net$|^wasi_http$/ }, (args) => { - throw new Error(experimentalMessage(args.path)); + throw experimentalMessage(args.path); } ); } @@ -95,7 +95,7 @@ export function getBuildOptions(ts: string): BuildOptions { } function experimentalMessage(importName: string): string { - return `Azle: experimental mode must be enabled to import from ${importName}. You can enable experimental mode in your dfx.json file like this: + return `Experimental mode must be enabled to import from ${importName}. You can enable experimental mode in your dfx.json file like this: { "canisters": { "canisterName": { diff --git a/src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/candid.rs b/src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/candid.rs index 86bdc48227..868ddd26a9 100644 --- a/src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/candid.rs +++ b/src/build/stable/commands/compile/wasm_binary/rust/stable_canister_template/src/candid.rs @@ -18,7 +18,7 @@ pub fn get_candid_and_method_meta_pointer() -> CCharPtr { match initialize_and_get_candid() { Ok(c_char_ptr) => c_char_ptr, Err(error) => { - trap(&format!("Azle CandidAndMethodMetaError: {error}")); + trap(&format!("Candid and MethodMeta generation failed: {error}")); } } } diff --git a/src/build/stable/commands/install_dfx_extension.ts b/src/build/stable/commands/install_dfx_extension.ts index 29b5454276..aed82655e5 100644 --- a/src/build/stable/commands/install_dfx_extension.ts +++ b/src/build/stable/commands/install_dfx_extension.ts @@ -6,5 +6,9 @@ import { AZLE_PACKAGE_PATH } from '../utils/global_paths'; export function runCommand(ioType: IOType): void { const dfxExtensionDirectoryPath = join(AZLE_PACKAGE_PATH, 'dfx_extension'); - execSyncPretty(`cd ${dfxExtensionDirectoryPath} && ./install.sh`, ioType); + execSyncPretty( + `cd ${dfxExtensionDirectoryPath} && ./install.sh`, + ioType, + 'dfx extension installation script execution failed' + ); } diff --git a/src/build/stable/commands/install_global_dependencies/index.ts b/src/build/stable/commands/install_global_dependencies/index.ts index 9a0d7040cf..0731e27e72 100644 --- a/src/build/stable/commands/install_global_dependencies/index.ts +++ b/src/build/stable/commands/install_global_dependencies/index.ts @@ -1,5 +1,3 @@ -import { IOType } from 'child_process'; - import { azle } from '../../../../../package.json'; import { execSyncPretty } from '../../utils/exec_sync_pretty'; import { AZLE_PACKAGE_PATH } from '../../utils/global_paths'; @@ -11,23 +9,22 @@ type DependencyInstallInfo = { }; export async function runCommand( - dependenciesToInstall: DependencyInstallInfo, - ioType: IOType + dependenciesToInstall: DependencyInstallInfo ): Promise { for (const key in dependenciesToInstall) { const dependency = key as DependencyName; if (dependenciesToInstall[dependency] === true) { - installDependency(dependency, ioType); + installDependency(dependency); } } } -function installDependency(dependency: DependencyName, ioType: IOType): void { +function installDependency(dependency: DependencyName): void { console.info(`Installing ${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 + 'inherit' ); } diff --git a/src/build/stable/commands/new.ts b/src/build/stable/commands/new.ts index 0b6d04f722..246fdcbf8e 100644 --- a/src/build/stable/commands/new.ts +++ b/src/build/stable/commands/new.ts @@ -9,8 +9,7 @@ export async function runCommand( templatePath: string ): Promise { if (process.argv[3] === undefined) { - console.error('You must provide a name for your Azle project'); - return; + throw new Error(`You must provide a name for your Azle project`); } const projectName = process.argv[3]; diff --git a/src/build/stable/utils/exec_sync_pretty.ts b/src/build/stable/utils/exec_sync_pretty.ts index a4cf4bd821..effa6d8a16 100644 --- a/src/build/stable/utils/exec_sync_pretty.ts +++ b/src/build/stable/utils/exec_sync_pretty.ts @@ -1,9 +1,17 @@ import { execSync, IOType } from 'child_process'; -export function execSyncPretty(command: string, stdio?: IOType): Buffer { +export function execSyncPretty( + command: string, + stdio?: IOType, + hint?: string +): Buffer { try { return execSync(command, { stdio }); } catch (error) { - throw new Error(`Azle build error`); + if (hint !== undefined) { + throw new Error(`${hint}: ${error}`); + } else { + throw error; + } } } diff --git a/src/build/stable/utils/versions/dfx.ts b/src/build/stable/utils/versions/dfx.ts index d5a8f7e763..679ee420cf 100644 --- a/src/build/stable/utils/versions/dfx.ts +++ b/src/build/stable/utils/versions/dfx.ts @@ -8,6 +8,6 @@ export function getLocalDfxVersion(): string { if (match !== null && match.length > 1 && typeof match[1] === 'string') { return match[1]; // Return the version number } else { - throw new Error('Could not parse the dfx version'); + throw new Error(`Could not parse the dfx version`); } } diff --git a/src/build/stable/utils/versions/node.ts b/src/build/stable/utils/versions/node.ts index 0f045f0aa9..2221e6d749 100644 --- a/src/build/stable/utils/versions/node.ts +++ b/src/build/stable/utils/versions/node.ts @@ -7,6 +7,6 @@ export function getLocalNodeVersion(): string { if (match !== null && match.length > 1 && typeof match[1] === 'string') { return match[1]; // Returns the version number (e.g., "16.13.0") } else { - throw new Error('Could not parse node version'); + throw new Error(`Could not parse node version`); } } diff --git a/src/build/stable/utils/versions/rust.ts b/src/build/stable/utils/versions/rust.ts index faa5b58650..ad1626861a 100644 --- a/src/build/stable/utils/versions/rust.ts +++ b/src/build/stable/utils/versions/rust.ts @@ -7,6 +7,6 @@ export function getLocalRustVersion(): string { if (match !== null && match.length > 1 && typeof match[1] === 'string') { return match[1]; // Returns the version number } else { - throw new Error('Could not parse rustc version'); + throw new Error(`Could not parse rustc version`); } }