node-version-use 0.4.7 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/cli.js ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ require('../dist/cjs/cli.js')(process.argv.slice(2), 'nvu');
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "default", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return _default;
9
+ }
10
+ });
11
+ var _exit = /*#__PURE__*/ _interop_require_default(require("exit"));
12
+ var _getoptscompat = /*#__PURE__*/ _interop_require_default(require("getopts-compat"));
13
+ var _index = /*#__PURE__*/ _interop_require_default(require("./index.js"));
14
+ function _interop_require_default(obj) {
15
+ return obj && obj.__esModule ? obj : {
16
+ default: obj
17
+ };
18
+ }
19
+ var _default = function(argv, name) {
20
+ var options = (0, _getoptscompat.default)(argv.slice(1), {
21
+ alias: {
22
+ range: "r",
23
+ desc: "d",
24
+ silent: "s"
25
+ },
26
+ default: {
27
+ range: "major,even"
28
+ },
29
+ boolean: [
30
+ "silent",
31
+ "desc"
32
+ ],
33
+ stopEarly: true
34
+ });
35
+ // define.option('-r, --range [range]', 'range type of major, minor, or patch with filters of lts, even, odd for version string expressions', 'major,even');
36
+ // define.option('-s, --silent', 'suppress logging', false);
37
+ options.sort = options.desc ? -1 : 1;
38
+ var args = argv.slice(0, 1).concat(options._);
39
+ if (args.length < 1) {
40
+ console.log("Missing command. Example usage: ".concat(name, " [version expression] [command]"));
41
+ return (0, _exit.default)(-1);
42
+ }
43
+ if (!options.silent) options.header = function(version, command, args) {
44
+ console.log("\n----------------------");
45
+ console.log("".concat([
46
+ command
47
+ ].concat(args).join(" "), " (").concat(version, ")"));
48
+ console.log("----------------------");
49
+ };
50
+ options.stdio = "inherit"; // pass through stdio
51
+ (0, _index.default)(args[0], args[1], args.slice(2), options, function(err, results) {
52
+ if (err) {
53
+ console.log(err.message);
54
+ return (0, _exit.default)(err.code || -1);
55
+ }
56
+ var errors = results.filter(function(result) {
57
+ return !!result.error;
58
+ });
59
+ if (!options.silent) {
60
+ console.log("\n======================");
61
+ if (errors.length) {
62
+ console.log("Errors (".concat(errors.length, ")"));
63
+ for(var index = 0; index < errors.length; index++){
64
+ var result = errors[index];
65
+ console.log("".concat(result.version, " Error: ").concat(result.error.message));
66
+ }
67
+ } else console.log("Success (".concat(results.length, ")"));
68
+ console.log("======================");
69
+ }
70
+ (0, _exit.default)(errors.length ? -1 : 0);
71
+ });
72
+ };
73
+ /* CJS INTEROP */ if (exports.__esModule && exports.default) { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) exports.default[key] = exports[key]; module.exports = exports.default; }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["cli.js"],"sourcesContent":["import exit from 'exit';\nimport getopts from 'getopts-compat';\nimport nvu from './index.mjs';\n\nexport default (argv, name) => {\n const options = getopts(argv.slice(1), {\n alias: { range: 'r', desc: 'd', silent: 's' },\n default: { range: 'major,even' },\n boolean: ['silent', 'desc'],\n stopEarly: true,\n });\n\n // define.option('-r, --range [range]', 'range type of major, minor, or patch with filters of lts, even, odd for version string expressions', 'major,even');\n // define.option('-s, --silent', 'suppress logging', false);\n options.sort = options.desc ? -1 : 1;\n\n const args = argv.slice(0, 1).concat(options._);\n if (args.length < 1) {\n console.log(`Missing command. Example usage: ${name} [version expression] [command]`);\n return exit(-1);\n }\n\n if (!options.silent)\n options.header = (version, command, args) => {\n console.log('\\n----------------------');\n console.log(`${[command].concat(args).join(' ')} (${version})`);\n console.log('----------------------');\n };\n\n options.stdio = 'inherit'; // pass through stdio\n nvu(args[0], args[1], args.slice(2), options, (err, results) => {\n if (err) {\n console.log(err.message);\n return exit(err.code || -1);\n }\n const errors = results.filter((result) => !!result.error);\n\n if (!options.silent) {\n console.log('\\n======================');\n if (errors.length) {\n console.log(`Errors (${errors.length})`);\n for (let index = 0; index < errors.length; index++) {\n const result = errors[index];\n console.log(`${result.version} Error: ${result.error.message}`);\n }\n } else console.log(`Success (${results.length})`);\n console.log('======================');\n }\n\n exit(errors.length ? -1 : 0);\n });\n};\n"],"names":["argv","name","options","getopts","slice","alias","range","desc","silent","default","boolean","stopEarly","sort","args","concat","_","length","console","log","exit","header","version","command","join","stdio","nvu","err","results","message","code","errors","filter","result","error","index"],"mappings":";;;;+BAIA;;;eAAA;;;2DAJiB;oEACG;4DACJ;;;;;;IAEhB,WAAe,SAACA,MAAMC;IACpB,IAAMC,UAAUC,IAAAA,sBAAO,EAACH,KAAKI,KAAK,CAAC,IAAI;QACrCC,OAAO;YAAEC,OAAO;YAAKC,MAAM;YAAKC,QAAQ;QAAI;QAC5CC,SAAS;YAAEH,OAAO;QAAa;QAC/BI,SAAS;YAAC;YAAU;SAAO;QAC3BC,WAAW;IACb;IAEA,4JAA4J;IAC5J,4DAA4D;IAC5DT,QAAQU,IAAI,GAAGV,QAAQK,IAAI,GAAG,CAAC,IAAI;IAEnC,IAAMM,OAAOb,KAAKI,KAAK,CAAC,GAAG,GAAGU,MAAM,CAACZ,QAAQa,CAAC;IAC9C,IAAIF,KAAKG,MAAM,GAAG,GAAG;QACnBC,QAAQC,GAAG,CAAC,AAAC,mCAAuC,OAALjB,MAAK;QACpD,OAAOkB,IAAAA,aAAI,EAAC,CAAC;IACf;IAEA,IAAI,CAACjB,QAAQM,MAAM,EACjBN,QAAQkB,MAAM,GAAG,SAACC,SAASC,SAAST;QAClCI,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC,AAAC,GAAuCG,OAArC;YAACC;SAAQ,CAACR,MAAM,CAACD,MAAMU,IAAI,CAAC,MAAK,MAAY,OAARF,SAAQ;QAC5DJ,QAAQC,GAAG,CAAC;IACd;IAEFhB,QAAQsB,KAAK,GAAG,WAAW,qBAAqB;IAChDC,IAAAA,cAAG,EAACZ,IAAI,CAAC,EAAE,EAAEA,IAAI,CAAC,EAAE,EAAEA,KAAKT,KAAK,CAAC,IAAIF,SAAS,SAACwB,KAAKC;QAClD,IAAID,KAAK;YACPT,QAAQC,GAAG,CAACQ,IAAIE,OAAO;YACvB,OAAOT,IAAAA,aAAI,EAACO,IAAIG,IAAI,IAAI,CAAC;QAC3B;QACA,IAAMC,SAASH,QAAQI,MAAM,CAAC,SAACC;mBAAW,CAAC,CAACA,OAAOC,KAAK;;QAExD,IAAI,CAAC/B,QAAQM,MAAM,EAAE;YACnBS,QAAQC,GAAG,CAAC;YACZ,IAAIY,OAAOd,MAAM,EAAE;gBACjBC,QAAQC,GAAG,CAAC,AAAC,WAAwB,OAAdY,OAAOd,MAAM,EAAC;gBACrC,IAAK,IAAIkB,QAAQ,GAAGA,QAAQJ,OAAOd,MAAM,EAAEkB,QAAS;oBAClD,IAAMF,SAASF,MAAM,CAACI,MAAM;oBAC5BjB,QAAQC,GAAG,CAAC,AAAC,GAA2Bc,OAAzBA,OAAOX,OAAO,EAAC,YAA+B,OAArBW,OAAOC,KAAK,CAACL,OAAO;gBAC9D;YACF,OAAOX,QAAQC,GAAG,CAAC,AAAC,YAA0B,OAAfS,QAAQX,MAAM,EAAC;YAC9CC,QAAQC,GAAG,CAAC;QACd;QAEAC,IAAAA,aAAI,EAACW,OAAOd,MAAM,GAAG,CAAC,IAAI;IAC5B;AACF"}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ var path = require("path");
3
+ var home = require("osenv").home();
4
+ module.exports = {
5
+ cacheDirectory: path.join(home, ".nvu", "cache"),
6
+ installDirectory: path.join(home, ".nvu", "installed")
7
+ };
8
+ /* CJS INTEROP */ if (exports.__esModule && exports.default) { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) exports.default[key] = exports[key]; module.exports = exports.default; }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["constants.js"],"sourcesContent":["const path = require('path');\nconst home = require('osenv').home();\n\nmodule.exports = {\n cacheDirectory: path.join(home, '.nvu', 'cache'),\n installDirectory: path.join(home, '.nvu', 'installed'),\n};\n"],"names":["path","require","home","module","exports","cacheDirectory","join","installDirectory"],"mappings":";AAAA,IAAMA,OAAOC,QAAQ;AACrB,IAAMC,OAAOD,QAAQ,SAASC,IAAI;AAElCC,OAAOC,OAAO,GAAG;IACfC,gBAAgBL,KAAKM,IAAI,CAACJ,MAAM,QAAQ;IACxCK,kBAAkBP,KAAKM,IAAI,CAACJ,MAAM,QAAQ;AAC5C"}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ cacheDirectory: function() {
13
+ return cacheDirectory;
14
+ },
15
+ default: function() {
16
+ return nodeVersionUse;
17
+ },
18
+ installDirectory: function() {
19
+ return installDirectory;
20
+ }
21
+ });
22
+ var _constants = /*#__PURE__*/ _interop_require_default(require("./constants"));
23
+ var _use = /*#__PURE__*/ _interop_require_default(require("./use"));
24
+ function _interop_require_default(obj) {
25
+ return obj && obj.__esModule ? obj : {
26
+ default: obj
27
+ };
28
+ }
29
+ function nodeVersionUse(versionExpression, command, args, options, callback) {
30
+ if (typeof options === "function") {
31
+ callback = options;
32
+ options = {};
33
+ }
34
+ if (typeof callback === "function") return (0, _use.default)(versionExpression, command, args, options || {}, callback);
35
+ return new Promise(function(resolve, reject) {
36
+ nodeVersionUse(versionExpression, command, args, options, function nodeVersionUseCallback(err, res) {
37
+ err ? reject(err) : resolve(res);
38
+ });
39
+ });
40
+ }
41
+ function installDirectory() {
42
+ return _constants.default.installDirectory;
43
+ }
44
+ function cacheDirectory(_options) {
45
+ return _constants.default.cacheDirectory;
46
+ }
47
+ /* CJS INTEROP */ if (exports.__esModule && exports.default) { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) exports.default[key] = exports[key]; module.exports = exports.default; }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["index.mjs"],"sourcesContent":["import constants from './constants';\nimport use from './use';\n\nexport default function nodeVersionUse(versionExpression, command, args, options, callback) {\n if (typeof options === 'function') {\n callback = options;\n options = {};\n }\n if (typeof callback === 'function') return use(versionExpression, command, args, options || {}, callback);\n return new Promise((resolve, reject) => {\n nodeVersionUse(versionExpression, command, args, options, function nodeVersionUseCallback(err, res) {\n err ? reject(err) : resolve(res);\n });\n });\n}\n\nexport function installDirectory() {\n return constants.installDirectory;\n}\n\nexport function cacheDirectory(_options) {\n return constants.cacheDirectory;\n}\n"],"names":["cacheDirectory","nodeVersionUse","installDirectory","versionExpression","command","args","options","callback","use","Promise","resolve","reject","nodeVersionUseCallback","err","res","constants","_options"],"mappings":";;;;;;;;;;;IAoBgBA,cAAc;eAAdA;;IAjBhB,OAWC;eAXuBC;;IAaRC,gBAAgB;eAAhBA;;;gEAhBM;0DACN;;;;;;AAED,SAASD,eAAeE,iBAAiB,EAAEC,OAAO,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IACxF,IAAI,OAAOD,YAAY,YAAY;QACjCC,WAAWD;QACXA,UAAU,CAAC;IACb;IACA,IAAI,OAAOC,aAAa,YAAY,OAAOC,IAAAA,YAAG,EAACL,mBAAmBC,SAASC,MAAMC,WAAW,CAAC,GAAGC;IAChG,OAAO,IAAIE,QAAQ,SAACC,SAASC;QAC3BV,eAAeE,mBAAmBC,SAASC,MAAMC,SAAS,SAASM,uBAAuBC,GAAG,EAAEC,GAAG;YAChGD,MAAMF,OAAOE,OAAOH,QAAQI;QAC9B;IACF;AACF;AAEO,SAASZ;IACd,OAAOa,kBAAS,CAACb,gBAAgB;AACnC;AAEO,SAASF,eAAegB,QAAQ;IACrC,OAAOD,kBAAS,CAACf,cAAc;AACjC"}
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ function _define_property(obj, key, value) {
3
+ if (key in obj) {
4
+ Object.defineProperty(obj, key, {
5
+ value: value,
6
+ enumerable: true,
7
+ configurable: true,
8
+ writable: true
9
+ });
10
+ } else {
11
+ obj[key] = value;
12
+ }
13
+ return obj;
14
+ }
15
+ function _object_spread(target) {
16
+ for(var i = 1; i < arguments.length; i++){
17
+ var source = arguments[i] != null ? arguments[i] : {};
18
+ var ownKeys = Object.keys(source);
19
+ if (typeof Object.getOwnPropertySymbols === "function") {
20
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
21
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
22
+ }));
23
+ }
24
+ ownKeys.forEach(function(key) {
25
+ _define_property(target, key, source[key]);
26
+ });
27
+ }
28
+ return target;
29
+ }
30
+ function ownKeys(object, enumerableOnly) {
31
+ var keys = Object.keys(object);
32
+ if (Object.getOwnPropertySymbols) {
33
+ var symbols = Object.getOwnPropertySymbols(object);
34
+ if (enumerableOnly) {
35
+ symbols = symbols.filter(function(sym) {
36
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
37
+ });
38
+ }
39
+ keys.push.apply(keys, symbols);
40
+ }
41
+ return keys;
42
+ }
43
+ function _object_spread_props(target, source) {
44
+ source = source != null ? source : {};
45
+ if (Object.getOwnPropertyDescriptors) {
46
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
47
+ } else {
48
+ ownKeys(Object(source)).forEach(function(key) {
49
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
50
+ });
51
+ }
52
+ return target;
53
+ }
54
+ var path = require("path");
55
+ var Queue = require("queue-cb");
56
+ var installRelease = require("node-install-release");
57
+ var versionUtils = require("node-version-utils");
58
+ var resolveVersions = require("node-resolve-versions");
59
+ var constants = require("./constants");
60
+ var spawnKeys = [
61
+ "encoding",
62
+ "stdio",
63
+ "stdin",
64
+ "stdout",
65
+ "stderr",
66
+ "cwd",
67
+ "env"
68
+ ];
69
+ module.exports = function use(versionExpression, command, args, options, callback) {
70
+ resolveVersions(versionExpression, _object_spread_props(_object_spread({}, options), {
71
+ path: "raw"
72
+ }), function(err, versions) {
73
+ if (err) return callback(err);
74
+ if (!versions.length) return callback(new Error("No versions found from expression: ".concat(versionExpression)));
75
+ var spawnOptions = {};
76
+ for(var i = 0; i < spawnKeys.length; i++){
77
+ if (options[spawnKeys[i]] !== undefined) spawnOptions[spawnKeys[i]] = options[spawnKeys[i]];
78
+ }
79
+ var results = [];
80
+ var queue = new Queue(1);
81
+ for(var index = 0; index < versions.length; index++){
82
+ (function(version) {
83
+ queue.defer(function(callback) {
84
+ !options.header || options.header(version.version, command, args);
85
+ var installDirectory = options.installDirectory || constants.installDirectory;
86
+ var cacheDirectory = options.cacheDirectory || constants.cacheDirectory;
87
+ var installPath = path.join(installDirectory, version.version);
88
+ installRelease(version, installPath, {
89
+ cacheDirectory: cacheDirectory
90
+ }, function(err) {
91
+ if (err) return callback(err);
92
+ versionUtils.spawn(installPath, command, args, spawnOptions, function(err, res) {
93
+ results.push({
94
+ version: version.version,
95
+ error: err,
96
+ result: res
97
+ });
98
+ callback();
99
+ });
100
+ });
101
+ });
102
+ })(versions[index]);
103
+ }
104
+ queue.await(function(err) {
105
+ err ? callback(err) : callback(null, results);
106
+ });
107
+ });
108
+ };
109
+ /* CJS INTEROP */ if (exports.__esModule && exports.default) { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) exports.default[key] = exports[key]; module.exports = exports.default; }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["use.js"],"sourcesContent":["const path = require('path');\nconst Queue = require('queue-cb');\nconst installRelease = require('node-install-release');\nconst versionUtils = require('node-version-utils');\nconst resolveVersions = require('node-resolve-versions');\n\nconst constants = require('./constants');\nconst spawnKeys = ['encoding', 'stdio', 'stdin', 'stdout', 'stderr', 'cwd', 'env'];\n\nmodule.exports = function use(versionExpression, command, args, options, callback) {\n resolveVersions(versionExpression, { ...options, path: 'raw' }, (err, versions) => {\n if (err) return callback(err);\n if (!versions.length) return callback(new Error(`No versions found from expression: ${versionExpression}`));\n\n const spawnOptions = {};\n for (let i = 0; i < spawnKeys.length; i++) {\n if (options[spawnKeys[i]] !== undefined) spawnOptions[spawnKeys[i]] = options[spawnKeys[i]];\n }\n\n const results = [];\n const queue = new Queue(1);\n for (let index = 0; index < versions.length; index++) {\n ((version) => {\n queue.defer((callback) => {\n !options.header || options.header(version.version, command, args);\n\n const installDirectory = options.installDirectory || constants.installDirectory;\n const cacheDirectory = options.cacheDirectory || constants.cacheDirectory;\n const installPath = path.join(installDirectory, version.version);\n\n installRelease(version, installPath, { cacheDirectory: cacheDirectory }, (err) => {\n if (err) return callback(err);\n\n versionUtils.spawn(installPath, command, args, spawnOptions, (err, res) => {\n results.push({ version: version.version, error: err, result: res });\n callback();\n });\n });\n });\n })(versions[index]);\n }\n queue.await((err) => {\n err ? callback(err) : callback(null, results);\n });\n });\n};\n"],"names":["path","require","Queue","installRelease","versionUtils","resolveVersions","constants","spawnKeys","module","exports","use","versionExpression","command","args","options","callback","err","versions","length","Error","spawnOptions","i","undefined","results","queue","index","version","defer","header","installDirectory","cacheDirectory","installPath","join","spawn","res","push","error","result","await"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAMA,OAAOC,QAAQ;AACrB,IAAMC,QAAQD,QAAQ;AACtB,IAAME,iBAAiBF,QAAQ;AAC/B,IAAMG,eAAeH,QAAQ;AAC7B,IAAMI,kBAAkBJ,QAAQ;AAEhC,IAAMK,YAAYL,QAAQ;AAC1B,IAAMM,YAAY;IAAC;IAAY;IAAS;IAAS;IAAU;IAAU;IAAO;CAAM;AAElFC,OAAOC,OAAO,GAAG,SAASC,IAAIC,iBAAiB,EAAEC,OAAO,EAAEC,IAAI,EAAEC,OAAO,EAAEC,QAAQ;IAC/EV,gBAAgBM,mBAAmB,wCAAKG;QAASd,MAAM;QAAS,SAACgB,KAAKC;QACpE,IAAID,KAAK,OAAOD,SAASC;QACzB,IAAI,CAACC,SAASC,MAAM,EAAE,OAAOH,SAAS,IAAII,MAAM,AAAC,sCAAuD,OAAlBR;QAEtF,IAAMS,eAAe,CAAC;QACtB,IAAK,IAAIC,IAAI,GAAGA,IAAId,UAAUW,MAAM,EAAEG,IAAK;YACzC,IAAIP,OAAO,CAACP,SAAS,CAACc,EAAE,CAAC,KAAKC,WAAWF,YAAY,CAACb,SAAS,CAACc,EAAE,CAAC,GAAGP,OAAO,CAACP,SAAS,CAACc,EAAE,CAAC;QAC7F;QAEA,IAAME,UAAU,EAAE;QAClB,IAAMC,QAAQ,IAAItB,MAAM;QACxB,IAAK,IAAIuB,QAAQ,GAAGA,QAAQR,SAASC,MAAM,EAAEO,QAAS;YACnD,CAAA,SAACC;gBACAF,MAAMG,KAAK,CAAC,SAACZ;oBACX,CAACD,QAAQc,MAAM,IAAId,QAAQc,MAAM,CAACF,QAAQA,OAAO,EAAEd,SAASC;oBAE5D,IAAMgB,mBAAmBf,QAAQe,gBAAgB,IAAIvB,UAAUuB,gBAAgB;oBAC/E,IAAMC,iBAAiBhB,QAAQgB,cAAc,IAAIxB,UAAUwB,cAAc;oBACzE,IAAMC,cAAc/B,KAAKgC,IAAI,CAACH,kBAAkBH,QAAQA,OAAO;oBAE/DvB,eAAeuB,SAASK,aAAa;wBAAED,gBAAgBA;oBAAe,GAAG,SAACd;wBACxE,IAAIA,KAAK,OAAOD,SAASC;wBAEzBZ,aAAa6B,KAAK,CAACF,aAAanB,SAASC,MAAMO,cAAc,SAACJ,KAAKkB;4BACjEX,QAAQY,IAAI,CAAC;gCAAET,SAASA,QAAQA,OAAO;gCAAEU,OAAOpB;gCAAKqB,QAAQH;4BAAI;4BACjEnB;wBACF;oBACF;gBACF;YACF,CAAA,EAAGE,QAAQ,CAACQ,MAAM;QACpB;QACAD,MAAMc,KAAK,CAAC,SAACtB;YACXA,MAAMD,SAASC,OAAOD,SAAS,MAAMQ;QACvC;IACF;AACF"}
@@ -0,0 +1,2 @@
1
+ declare function _default(argv: any, name: any): any;
2
+ export default _default;
@@ -0,0 +1,2 @@
1
+ export let cacheDirectory: string;
2
+ export let installDirectory: string;
@@ -0,0 +1,3 @@
1
+ export default function nodeVersionUse(versionExpression: any, command: any, args: any, options: any, callback: any): void | Promise<any>;
2
+ export function installDirectory(): string;
3
+ export function cacheDirectory(_options: any): string;
@@ -0,0 +1,2 @@
1
+ declare function _exports(versionExpression: any, command: any, args: any, options: any, callback: any): void;
2
+ export = _exports;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-version-use",
3
- "version": "0.4.7",
3
+ "version": "0.5.0",
4
4
  "description": "Cross-platform solution for using multiple versions of node. Useful for compatibility testing",
5
5
  "keywords": [
6
6
  "node",
@@ -17,48 +17,49 @@
17
17
  "url": "git@github.com:kmalakoff/node-version-use.git"
18
18
  },
19
19
  "license": "MIT",
20
- "main": "lib/index.js",
20
+ "main": "dist/cjs/index.js",
21
+ "types": "dist/types/index.d.ts",
21
22
  "bin": {
22
- "nvu": "./bin/node-version-use.js"
23
+ "nvu": "./bin/cli.js"
23
24
  },
24
25
  "files": [
25
- "lib"
26
+ "dist"
26
27
  ],
27
28
  "scripts": {
28
- "build": "",
29
- "compat": "./bin/node-version-use.js engines mocha-compat test/spec/**/*.test.js --no-timeouts",
30
- "format": "prettier --write .",
31
- "lint": "eslint .",
32
- "prepublishOnly": "npm run lint && depcheck",
33
- "test": "mocha-compat test/spec/**/*.test.js --no-timeouts",
34
- "test:engines": "nvu engines npm test"
29
+ "build": "tsds build",
30
+ "deploy": "tsds deploy",
31
+ "format": "biome check --apply-unsafe src/ test/",
32
+ "test": "tsds test:node --no-timeouts",
33
+ "test:engines": "nvu engines npm test",
34
+ "version": "tsds version"
35
35
  },
36
36
  "dependencies": {
37
- "cross-spawn-cb": "^0.6.14",
37
+ "cross-spawn-cb": "^0.6.18",
38
38
  "exit": "^0.1.2",
39
39
  "getopts-compat": "^2.2.5",
40
- "just-extend": "^6.1.1",
41
- "node-install-release": "^0.4.7",
42
- "node-resolve-versions": "^0.3.9",
40
+ "node-install-release": "^1.1.1",
41
+ "node-resolve-versions": "^0.3.10",
43
42
  "node-version-utils": "^0.5.6",
44
43
  "osenv": "^0.1.5",
45
- "queue-cb": "^1.1.7"
44
+ "queue-cb": "^1.2.1"
46
45
  },
47
46
  "devDependencies": {
48
- "@typescript-eslint/parser": "^5.33.0",
47
+ "@biomejs/biome": "^1.5.3",
48
+ "@types/mocha": "^10.0.6",
49
+ "@types/node": "^20.11.19",
49
50
  "cr": "^0.1.0",
50
- "depcheck": "^1.4.3",
51
- "eslint": "^8.21.0",
52
- "eslint-config-prettier": "^8.5.0",
53
- "eslint-config-standard": "^17.0.0",
54
- "eslint-plugin-import": "^2.26.0",
55
- "eslint-plugin-promise": "^6.0.0",
51
+ "depcheck": "^1.4.7",
56
52
  "is-version": "^0.2.1",
57
- "mocha-compat": "^3.5.5",
58
- "prettier": "^2.7.1",
59
- "rimraf": "^2.7.1"
53
+ "rimraf": "^2.7.1",
54
+ "ts-dev-stack": "^0.14.9"
60
55
  },
61
56
  "engines": {
62
57
  "node": ">=0.8"
58
+ },
59
+ "tsds": {
60
+ "source": "src/index.mjs",
61
+ "targets": [
62
+ "cjs"
63
+ ]
63
64
  }
64
65
  }
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- require('../lib/cli')(process.argv.slice(2), 'nvu');
package/lib/cli.js DELETED
@@ -1,54 +0,0 @@
1
- var getopts = require('getopts-compat');
2
- var exit = require('exit');
3
- var nvs = require('..');
4
-
5
- module.exports = function cli(argv, name) {
6
- var options = getopts(argv.slice(1), {
7
- alias: { range: 'r', desc: 'd', silent: 's' },
8
- default: { range: 'major,even' },
9
- boolean: ['silent', 'desc'],
10
- stopEarly: true,
11
- });
12
-
13
- // define.option('-r, --range [range]', 'range type of major, minor, or patch with filters of lts, even, odd for version string expressions', 'major,even');
14
- // define.option('-s, --silent', 'suppress logging', false);
15
- options.sort = options.desc ? -1 : 1;
16
-
17
- var args = argv.slice(0, 1).concat(options._);
18
- if (args.length < 1) {
19
- console.log('Missing command. Example usage: ' + name + ' [version expression] [command]');
20
- return exit(-1);
21
- }
22
-
23
- if (!options.silent)
24
- options.header = function (version, command, args) {
25
- console.log('\n----------------------');
26
- console.log([command].concat(args).join(' ') + ' (' + version + ')');
27
- console.log('----------------------');
28
- };
29
-
30
- options.stdio = 'inherit'; // pass through stdio
31
- nvs(args[0], args[1], args.slice(2), options, function (err, results) {
32
- if (err) {
33
- console.log(err.message);
34
- return exit(err.code || -1);
35
- }
36
- var errors = results.filter(function (result) {
37
- return !!result.error;
38
- });
39
-
40
- if (!options.silent) {
41
- console.log('\n======================');
42
- if (errors.length) {
43
- console.log('Errors (' + errors.length + ')');
44
- for (var index = 0; index < errors.length; index++) {
45
- var result = errors[index];
46
- console.log(result.version + ' Error: ' + result.error.message);
47
- }
48
- } else console.log('Success (' + results.length + ')');
49
- console.log('======================');
50
- }
51
-
52
- exit(errors.length ? -1 : 0);
53
- });
54
- };
package/lib/constants.js DELETED
@@ -1,7 +0,0 @@
1
- var path = require('path');
2
- var home = require('osenv').home();
3
-
4
- module.exports = {
5
- cacheDirectory: path.join(home, '.nvu', 'cache'),
6
- installDirectory: path.join(home, '.nvu', 'installed'),
7
- };
package/lib/index.js DELETED
@@ -1,23 +0,0 @@
1
- var use = require('./use');
2
- var constants = require('./constants');
3
-
4
- module.exports = function nodeVersionUse(versionExpression, command, args, options, callback) {
5
- if (typeof options === 'function') {
6
- callback = options;
7
- options = {};
8
- }
9
- if (typeof callback === 'function') return use(versionExpression, command, args, options || {}, callback);
10
- return new Promise(function (resolve, reject) {
11
- nodeVersionUse(versionExpression, command, args, options, function nodeVersionUseCallback(err, res) {
12
- err ? reject(err) : resolve(res);
13
- });
14
- });
15
- };
16
-
17
- module.exports.installDirectory = function installDirectory() {
18
- return constants.installDirectory;
19
- };
20
-
21
- module.exports.cacheDirectory = function cacheDirectory(options) {
22
- return constants.cacheDirectory;
23
- };
package/lib/use.js DELETED
@@ -1,47 +0,0 @@
1
- var path = require('path');
2
- var assign = require('just-extend');
3
- var Queue = require('queue-cb');
4
- var installRelease = require('node-install-release');
5
- var versionUtils = require('node-version-utils');
6
- var resolveVersions = require('node-resolve-versions');
7
-
8
- var constants = require('./constants');
9
- var spawnKeys = ['encoding', 'stdio', 'stdin', 'stdout', 'stderr', 'cwd', 'env'];
10
-
11
- module.exports = function use(versionExpression, command, args, options, callback) {
12
- resolveVersions(versionExpression, assign({}, options, { path: 'raw' }), function (err, versions) {
13
- if (err) return callback(err);
14
- if (!versions.length) return callback(new Error('No versions found from expression: ' + versionExpression));
15
-
16
- var spawnOptions = {};
17
- for (var i = 0; i < spawnKeys.length; i++) {
18
- if (options[spawnKeys[i]] !== undefined) spawnOptions[spawnKeys[i]] = options[spawnKeys[i]];
19
- }
20
-
21
- var results = [];
22
- var queue = new Queue(1);
23
- for (var index = 0; index < versions.length; index++) {
24
- (function (version) {
25
- queue.defer(function (callback) {
26
- !options.header || options.header(version.version, command, args);
27
-
28
- var installDirectory = options.installDirectory || constants.installDirectory;
29
- var cacheDirectory = options.cacheDirectory || constants.cacheDirectory;
30
- var installPath = path.join(installDirectory, version.version);
31
-
32
- installRelease(version, installPath, { cacheDirectory: cacheDirectory }, function (err) {
33
- if (err) return callback(err);
34
-
35
- versionUtils.spawn(installPath, command, args, spawnOptions, function (err, res) {
36
- results.push({ version: version.version, error: err, result: res });
37
- callback();
38
- });
39
- });
40
- });
41
- })(versions[index]);
42
- }
43
- queue.await(function (err) {
44
- err ? callback(err) : callback(null, results);
45
- });
46
- });
47
- };