Skip to content

Commit

Permalink
Exposed installDirectory
Browse files Browse the repository at this point in the history
  • Loading branch information
kmalakoff committed Jul 10, 2022
1 parent 794f974 commit 0b2c4fb
Show file tree
Hide file tree
Showing 6 changed files with 830 additions and 178 deletions.
7 changes: 7 additions & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var path = require('path');
var home = require('osenv').home();

module.exports = {
cacheDirectory: path.join(home, '.nvu', 'cache'),
installDirectory: path.join(home, '.nvu', 'installed'),
};
9 changes: 9 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var use = require('./use');
var constants = require('./constants')

module.exports = function nodeVersionUse(versionExpression, command, args, options, callback) {
if (typeof options === 'function') {
Expand All @@ -12,3 +13,11 @@ module.exports = function nodeVersionUse(versionExpression, command, args, optio
});
});
};

module.exports.installDirectory = function installDirectory() {
return constants.installDirectory;
}

module.exports.cacheDirectory = function cacheDirectory(options) {
return constants.cacheDirectory;
}
12 changes: 4 additions & 8 deletions lib/use.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@ var installRelease = require('node-install-release');
var versionUtils = require('node-version-utils');
var resolveVersions = require('node-resolve-versions');

var HOME = require('osenv').home();
var DEFAULT_OPTIONS = {
cacheDirectory: path.join(HOME, '.nvu', 'cache'),
installedDirectory: path.join(HOME, '.nvu', 'installed'),
};
var constants = require('./constants')

module.exports = function use(versionExpression, command, args, options, callback) {
resolveVersions(versionExpression, assign({}, options, { path: 'raw' }), function (err, versions) {
Expand All @@ -26,9 +22,9 @@ module.exports = function use(versionExpression, command, args, options, callbac
queue.defer(function (callback) {
!options.header || options.header(version.version, command, args);

var installedDirectory = options.installedDirectory || DEFAULT_OPTIONS.installedDirectory;
var cacheDirectory = options.cacheDirectory || DEFAULT_OPTIONS.cacheDirectory;
var installPath = path.join(installedDirectory, version.version);
var installDirectory = options.installDirectory || constants.installDirectory;
var cacheDirectory = options.cacheDirectory || constants.cacheDirectory;
var installPath = path.join(installDirectory, version.version);

installRelease(version, installPath, { cacheDirectory: cacheDirectory }, function (err) {
if (err) return callback(err);
Expand Down
Loading

0 comments on commit 0b2c4fb

Please sign in to comment.