From 29791d1972a960666b894a82978798ae613615be Mon Sep 17 00:00:00 2001 From: Micooz Date: Sat, 14 Oct 2017 22:53:02 +0800 Subject: [PATCH] bin: load libsodium library before run main() --- bin/cli.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 8426665..ac48e4e 100644 --- a/bin/cli.js +++ b/bin/cli.js @@ -53,7 +53,7 @@ function getOptionValue(opt) { return undefined; } -(function main() { +function main() { if (argv.length < 3) { return console.log(usage); } @@ -107,4 +107,13 @@ function getOptionValue(opt) { // other cases console.log(usage); -})(); +} + +// libsodium-wrappers need to be loaded asynchronously +// so we must wait for it ready before run main(). +// https://github.com/jedisct1/libsodium.js#usage-as-a-module +const _sodium = require('libsodium-wrappers'); +_sodium.ready + // a handy way to access libsodium without fighting with Promise + .then(() => global.libsodium = _sodium) + .then(main);