From 72b19e5cc236c83473c93cf6a96603a3f1b5f679 Mon Sep 17 00:00:00 2001 From: cgeek <cem.moreau@gmail.com> Date: Mon, 29 May 2017 15:30:25 +0200 Subject: [PATCH] [enh] #918 Better modules installation support --- app/modules/plugin.js | 10 ++++++++-- index.js | 5 ++++- yarn.lock | 4 ++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/modules/plugin.js b/app/modules/plugin.js index a43c114c0..4f974dc8d 100644 --- a/app/modules/plugin.js +++ b/app/modules/plugin.js @@ -54,9 +54,10 @@ module.exports = { function npmInstall(what, npm, cwd) { return new Promise((res, rej) => { + const node = getNode() npm = npm || getNPM() cwd = cwd || getCWD() - const install = spawn(npm, ['i', '--save', what], { cwd }) + const install = spawn(node, [npm, 'i', '--save', what], { cwd }) install.stdout.pipe(process.stdout) install.stderr.pipe(process.stderr) @@ -81,9 +82,10 @@ function npmInstall(what, npm, cwd) { function npmRemove(what, npm, cwd) { return new Promise((res, rej) => { + const node = getNode() npm = npm || getNPM() cwd = cwd || getCWD() - const uninstall = spawn(npm, ['remove', '--save', what], { cwd }) + const uninstall = spawn(node, [npm, 'remove', '--save', what], { cwd }) uninstall.stdout.pipe(process.stdout) uninstall.stderr.pipe(process.stderr) @@ -105,6 +107,10 @@ function npmRemove(what, npm, cwd) { }) } +function getNode() { + return process.argv[0] +} + function getNPM() { return process.argv[0].replace(/node$/, 'npm') } diff --git a/index.js b/index.js index 607a16929..4b761d0c1 100644 --- a/index.js +++ b/index.js @@ -138,12 +138,15 @@ function Stack(dependencies) { neutral: [] }; + // Part of modules API + this.getModule = (name) => loaded[name] + this.registerDependency = (requiredObject, name) => { if (name && loaded[name]) { // Do not try to load it twice return; } - loaded[name] = true; + loaded[name] = requiredObject; const def = requiredObject.duniter; definitions.push(def); for (const opt of (def.cliOptions || [])) { diff --git a/yarn.lock b/yarn.lock index e4367624b..b8c23c566 100644 --- a/yarn.lock +++ b/yarn.lock @@ -796,8 +796,8 @@ duniter-prover@1.3.x: underscore "1.8.3" duniter-ui@1.3.x: - version "1.3.1" - resolved "https://registry.yarnpkg.com/duniter-ui/-/duniter-ui-1.3.1.tgz#cddebe90588e142c7958b986bb0e1c9f957dbe93" + version "1.3.4" + resolved "https://registry.yarnpkg.com/duniter-ui/-/duniter-ui-1.3.4.tgz#f0e969b30f5bb6076f122fdb119ffda120cf8a7c" dependencies: adm-zip "0.4.7" body-parser "1.17.1" -- GitLab