diff options
author | F. Eugene Aumson <gene@aumson.org> | 2018-08-17 04:59:46 +0800 |
---|---|---|
committer | F. Eugene Aumson <gene@aumson.org> | 2018-08-17 06:01:33 +0800 |
commit | 402ca27fbf91f543addf0d4618e071ae10cfd70e (patch) | |
tree | 889ac48b996dfa2aa037a713fc32f7f1084fa98f /packages | |
parent | 85427a84df9954c5849ea471f549549bc1486aec (diff) | |
download | dexon-sol-tools-402ca27fbf91f543addf0d4618e071ae10cfd70e.tar dexon-sol-tools-402ca27fbf91f543addf0d4618e071ae10cfd70e.tar.gz dexon-sol-tools-402ca27fbf91f543addf0d4618e071ae10cfd70e.tar.bz2 dexon-sol-tools-402ca27fbf91f543addf0d4618e071ae10cfd70e.tar.lz dexon-sol-tools-402ca27fbf91f543addf0d4618e071ae10cfd70e.tar.xz dexon-sol-tools-402ca27fbf91f543addf0d4618e071ae10cfd70e.tar.zst dexon-sol-tools-402ca27fbf91f543addf0d4618e071ae10cfd70e.zip |
change some *Sync to *Async
Diffstat (limited to 'packages')
-rw-r--r-- | packages/sol-compiler/src/compiler.ts | 22 | ||||
-rw-r--r-- | packages/sol-compiler/src/utils/fs_wrapper.ts | 1 |
2 files changed, 19 insertions, 4 deletions
diff --git a/packages/sol-compiler/src/compiler.ts b/packages/sol-compiler/src/compiler.ts index 296411b76..d3c4a3919 100644 --- a/packages/sol-compiler/src/compiler.ts +++ b/packages/sol-compiler/src/compiler.ts @@ -82,6 +82,18 @@ export class Compiler { private readonly _artifactsDir: string; private readonly _solcVersionIfExists: string | undefined; private readonly _specifiedContracts: string[] | TYPE_ALL_FILES_IDENTIFIER; + private static async _doesFileExistAsync(filePath: string): Promise<boolean> { + try { + await fsWrapper.accessAsync( + filePath, + // node says we need to use bitwise, but tslint says no: + fs.constants.F_OK | fs.constants.R_OK, // tslint:disable-line:no-bitwise + ); + } catch (err) { + return false; + } + return true; + } private static async _getSolcAsync( solcVersion: string, ): Promise<{ solcInstance: solc.SolcInstance; fullSolcVersion: string }> { @@ -91,9 +103,8 @@ export class Compiler { } const compilerBinFilename = path.join(SOLC_BIN_DIR, fullSolcVersion); let solcjs: string; - const isCompilerAvailableLocally = fs.existsSync(compilerBinFilename); - if (isCompilerAvailableLocally) { - solcjs = fs.readFileSync(compilerBinFilename).toString(); + if (await Compiler._doesFileExistAsync(compilerBinFilename)) { + solcjs = (await fsWrapper.readFileAsync(compilerBinFilename)).toString(); } else { logUtils.log(`Downloading ${fullSolcVersion}...`); const url = `${constants.BASE_COMPILER_URL}${fullSolcVersion}`; @@ -103,7 +114,10 @@ export class Compiler { throw new Error(`Failed to load ${fullSolcVersion}`); } solcjs = await response.text(); - fs.writeFileSync(compilerBinFilename, solcjs); + await fsWrapper.writeFileAsync(compilerBinFilename, solcjs); + } + if (solcjs.length === 0) { + throw new Error('No compiler available'); } const solcInstance = solc.setupMethods(requireFromString(solcjs, compilerBinFilename)); return { solcInstance, fullSolcVersion }; diff --git a/packages/sol-compiler/src/utils/fs_wrapper.ts b/packages/sol-compiler/src/utils/fs_wrapper.ts index 6e3547a76..44c97bd1e 100644 --- a/packages/sol-compiler/src/utils/fs_wrapper.ts +++ b/packages/sol-compiler/src/utils/fs_wrapper.ts @@ -12,4 +12,5 @@ export const fsWrapper = { removeFileAsync: promisify<undefined>(fs.unlink), statAsync: promisify<fs.Stats>(fs.stat), appendFileAsync: promisify<undefined>(fs.appendFile), + accessAsync: promisify<boolean>(fs.access), }; |