diff --git a/src/cli.ts b/src/cli.ts index dff2728..a12f9b9 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,6 +1,6 @@ #!/usr/bin/env node -import process from 'node:process' +import process, { emitWarning } from 'node:process' import path from 'node:path' import { fileURLToPath } from 'node:url' import fs from 'node:fs' @@ -10,6 +10,17 @@ import { type Tag, deployContract } from './lib/deploy' const PKG_ROOT = path.join(path.dirname(fileURLToPath(import.meta.url)), '../') +process.emitWarning = (warning, ...args) => { + if (args[0] === 'ExperimentalWarning') + return + + if (args[0] && typeof args[0] === 'object' && args[0].type === 'ExperimentalWarning') + return + + // @ts-expect-error "experimental warning" + return emitWarning(warning, ...args) +} + function getVersion() { const packageJsonPath = path.join(PKG_ROOT, 'package.json') const packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString()) diff --git a/src/lib/load.ts b/src/lib/load.ts index 88f8640..be16e09 100644 --- a/src/lib/load.ts +++ b/src/lib/load.ts @@ -23,19 +23,16 @@ interface Module { name: string, path: string, content?: string } async function fileExists(path: string): Promise { try { - await fs.access(path, constants.R_OK) - return true // The file exists and is readable + await fs.access(path, constants.F_OK | constants.R_OK) + return true } catch { - return false // The file doesn't exist, isn't readable, or another error occurred + return false } } async function getModulePath(module: string, cwd: string) { try { - if (['json', '.base64', '.pretty', '.utils', '.crypto'].includes(module)) - return - const modPath = path.join(cwd, `${module.replace(/\./g, '/')}.lua`) if (await fileExists(modPath)) return modPath @@ -44,10 +41,15 @@ async function getModulePath(module: string, cwd: string) { const command = `lua -e "${luaCode}"` const { stdout, stderr } = await execAsync(command) + if (stderr) return - return stdout.trim() + if (stdout) { + const potentialPath = stdout.trim() + if (await fileExists(potentialPath)) + return potentialPath + } } catch (error) {} } @@ -76,7 +78,7 @@ export async function createProjectStructure(mainFile: string, cwd: string) { let orderedModNames = modules.map(m => m.name) for (let i = 0; i < modules.length; i++) { - if (modules[i].content || !(await fs.stat(modules[i].path)).isFile()) + if (modules[i].content) continue modules[i].content = (await fs.readFile(modules[i].path, 'utf-8')) @@ -123,7 +125,7 @@ async function findRequires(data: string, cwd: string): Promise { : null }) - return (await Promise.all(requiredModules)).filter(m => !!m) + return (await Promise.all(requiredModules)).filter(m => !!m) as Module[] } export async function loadContract(contractPath: string) { @@ -133,9 +135,9 @@ export async function loadContract(contractPath: string) { filePath = path.resolve(path.join(process.cwd(), contractPath)) if (!(await fileExists(filePath))) - throw new Error(chalk.red('ERROR: file not found.')) + throw new Error(chalk.red(`ERROR: ${filePath} file not found.`)) - console.log(chalk.green('Loading... ', contractPath)) + console.log(chalk.green('Deploying: ', contractPath)) let line = await fs.readFile(filePath, 'utf-8') const spinner = ora({