node-version-use 2.1.6 → 2.1.7
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/assets/installBinaries.cjs +284 -0
- package/assets/postinstall.cjs +11 -404
- package/dist/cjs/assets/installBinaries.cjs +284 -0
- package/dist/cjs/assets/installBinaries.cjs.map +1 -0
- package/dist/cjs/assets/installBinaries.d.cts +1 -0
- package/dist/cjs/assets/postinstall.cjs +11 -404
- package/dist/cjs/assets/postinstall.cjs.map +1 -1
- package/dist/cjs/commands/index.js +2 -3
- package/dist/cjs/commands/index.js.map +1 -1
- package/dist/cjs/commands/setup.js +23 -41
- package/dist/cjs/commands/setup.js.map +1 -1
- package/dist/cjs/commands/teardown.js +2 -1
- package/dist/cjs/commands/teardown.js.map +1 -1
- package/dist/cjs/compat.d.cts +1 -0
- package/dist/cjs/compat.d.ts +1 -0
- package/dist/cjs/compat.js +11 -4
- package/dist/cjs/compat.js.map +1 -1
- package/dist/esm/assets/installBinaries.cjs +282 -0
- package/dist/esm/assets/installBinaries.cjs.map +1 -0
- package/dist/esm/assets/installBinaries.d.cts +1 -0
- package/dist/esm/assets/postinstall.cjs +11 -404
- package/dist/esm/assets/postinstall.cjs.map +1 -1
- package/dist/esm/commands/index.js +2 -3
- package/dist/esm/commands/index.js.map +1 -1
- package/dist/esm/commands/setup.js +24 -42
- package/dist/esm/commands/setup.js.map +1 -1
- package/dist/esm/commands/teardown.js +2 -1
- package/dist/esm/commands/teardown.js.map +1 -1
- package/dist/esm/compat.d.ts +1 -0
- package/dist/esm/compat.js +8 -4
- package/dist/esm/compat.js.map +1 -1
- package/package.json +13 -8
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/setup.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/setup.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport getopts from 'getopts-compat';\nimport Module from 'module';\nimport path from 'path';\nimport { readdirWithTypes } from '../compat.ts';\nimport { storagePath } from '../constants.ts';\nimport { findInstalledVersions } from '../lib/findInstalledVersions.ts';\n\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\nconst { installBinaries, printInstructions } = _require('../assets/installBinaries.cjs');\n\n/**\n * nvu setup [--shims]\n *\n * Install/reinstall nvu binaries to ~/.nvu/bin\n * With --shims: create shims for existing global packages\n */\nexport default function setupCmd(args: string[]): void {\n const options = getopts(args, { boolean: ['force'] });\n\n installBinaries(options, (err, installed) => {\n if (err) {\n console.error(`Setup failed: ${err.message || err}`);\n exit(1);\n return;\n }\n\n printInstructions();\n if (!installed) console.log('Use --force to reinstall.');\n\n if (options.force) {\n const binDir = path.join(storagePath, 'bin');\n createShimsForGlobalPackages(binDir);\n return;\n }\n });\n}\n\n/**\n * Create shims for all global packages in the default Node version\n */\nfunction createShimsForGlobalPackages(binDir: string): void {\n // Read default version\n const defaultPath = path.join(storagePath, 'default');\n if (!fs.existsSync(defaultPath)) {\n console.log('No default Node version set.');\n console.log('Set one with: nvu default <version>');\n exit(1);\n return;\n }\n\n const defaultVersion = fs.readFileSync(defaultPath, 'utf8').trim();\n const versionsDir = path.join(storagePath, 'installed');\n\n // Resolve to exact version\n const matches = findInstalledVersions(versionsDir, defaultVersion);\n if (matches.length === 0) {\n console.log(`Default version ${defaultVersion} is not installed.`);\n exit(1);\n return;\n }\n\n const resolvedVersion = matches[matches.length - 1];\n const nodeBinDir = path.join(versionsDir, resolvedVersion, 'bin');\n\n if (!fs.existsSync(nodeBinDir)) {\n console.log(`No bin directory found for ${resolvedVersion}`);\n exit(1);\n return;\n }\n\n // Get the node shim to copy from\n const nodeShim = path.join(binDir, 'node');\n if (!fs.existsSync(nodeShim)) {\n console.log('Node shim not found. Run: nvu setup');\n exit(1);\n return;\n }\n\n // Scan binaries in Node's bin directory\n const entries = readdirWithTypes(nodeBinDir);\n let created = 0;\n let skipped = 0;\n\n for (let i = 0; i < entries.length; i++) {\n const entry = entries[i];\n const name = entry.name;\n\n // Skip our routing shims (node/npm/npx) - don't overwrite them\n if (name === 'node' || name === 'npm' || name === 'npx') continue;\n const shimPath = path.join(binDir, name);\n\n // Skip if shim already exists\n if (fs.existsSync(shimPath)) {\n skipped++;\n continue;\n }\n\n // Copy the node shim\n try {\n const shimContent = fs.readFileSync(nodeShim);\n fs.writeFileSync(shimPath, shimContent);\n fs.chmodSync(shimPath, 493); // 0755\n console.log(`Created shim: ${name}`);\n created++;\n } catch (err) {\n console.error(`Failed to create shim for ${name}: ${(err as Error).message}`);\n }\n }\n\n console.log('');\n console.log(`Done. Created ${created} shims, skipped ${skipped} (already exists).`);\n exit(0);\n}\n"],"names":["setupCmd","_require","require","Module","createRequire","installBinaries","printInstructions","args","options","getopts","boolean","err","installed","console","error","message","exit","log","force","binDir","path","join","storagePath","createShimsForGlobalPackages","defaultPath","fs","existsSync","defaultVersion","readFileSync","trim","versionsDir","matches","findInstalledVersions","length","resolvedVersion","nodeBinDir","nodeShim","entries","readdirWithTypes","created","skipped","i","entry","name","shimPath","shimContent","writeFileSync","chmodSync"],"mappings":";;;;+BAYA;;;;;CAKC,GACD;;;eAAwBA;;;iEAlBP;yDACF;oEACK;6DACD;2DACF;wBACgB;2BACL;uCACU;;;;;;AAEtC,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAM,CAACC,aAAa,CAAC,uDAAmBF;AAC1F,IAA+CD,YAAAA,SAAS,kCAAhDI,kBAAuCJ,UAAvCI,iBAAiBC,oBAAsBL,UAAtBK;AAQV,SAASN,SAASO,IAAc;IAC7C,IAAMC,UAAUC,IAAAA,sBAAO,EAACF,MAAM;QAAEG,SAAS;YAAC;SAAQ;IAAC;IAEnDL,gBAAgBG,SAAS,SAACG,KAAKC;QAC7B,IAAID,KAAK;YACPE,QAAQC,KAAK,CAAC,AAAC,iBAAmC,OAAnBH,IAAII,OAAO,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,EAAC;QACL;IACF;IAEA,wCAAwC;IACxC,IAAMqB,UAAUC,IAAAA,0BAAgB,EAACH;IACjC,IAAII,UAAU;IACd,IAAIC,UAAU;IAEd,IAAK,IAAIC,IAAI,GAAGA,IAAIJ,QAAQJ,MAAM,EAAEQ,IAAK;QACvC,IAAMC,QAAQL,OAAO,CAACI,EAAE;QACxB,IAAME,OAAOD,MAAMC,IAAI;QAEvB,+DAA+D;QAC/D,IAAIA,SAAS,UAAUA,SAAS,SAASA,SAAS,OAAO;QACzD,IAAMC,WAAWxB,aAAI,CAACC,IAAI,CAACF,QAAQwB;QAEnC,8BAA8B;QAC9B,IAAIlB,WAAE,CAACC,UAAU,CAACkB,WAAW;YAC3BJ;YACA;QACF;QAEA,qBAAqB;QACrB,IAAI;YACF,IAAMK,cAAcpB,WAAE,CAACG,YAAY,CAACQ;YACpCX,WAAE,CAACqB,aAAa,CAACF,UAAUC;YAC3BpB,WAAE,CAACsB,SAAS,CAACH,UAAU,MAAM,OAAO;YACpC/B,QAAQI,GAAG,CAAC,AAAC,iBAAqB,OAAL0B;YAC7BJ;QACF,EAAE,OAAO5B,KAAK;YACZE,QAAQC,KAAK,CAAC,AAAC,6BAAqC,OAAT6B,MAAK,MAA2B,OAAvB,AAAChC,IAAcI,OAAO;QAC5E;IACF;IAEAF,QAAQI,GAAG,CAAC;IACZJ,QAAQI,GAAG,CAAC,AAAC,iBAA0CuB,OAA1BD,SAAQ,oBAA0B,OAARC,SAAQ;IAC/DxB,IAAAA,mBAAI,EAAC;AACP"}
|
|
@@ -22,6 +22,7 @@ function _interop_require_default(obj) {
|
|
|
22
22
|
default: obj
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
|
+
var isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);
|
|
25
26
|
function teardownCmd(_args) {
|
|
26
27
|
var binDir = _path.default.join(_constantsts.storagePath, 'bin');
|
|
27
28
|
var binaries = [
|
|
@@ -29,7 +30,7 @@ function teardownCmd(_args) {
|
|
|
29
30
|
'npm',
|
|
30
31
|
'npx'
|
|
31
32
|
];
|
|
32
|
-
var ext =
|
|
33
|
+
var ext = isWindows ? '.exe' : '';
|
|
33
34
|
var removed = 0;
|
|
34
35
|
for(var i = 0; i < binaries.length; i++){
|
|
35
36
|
var binaryPath = _path.default.join(binDir, binaries[i] + ext);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/teardown.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport { rmSync } from 'fs-remove-compat';\nimport path from 'path';\nimport { storagePath } from '../constants.ts';\n\n/**\n * nvu teardown\n *\n * Remove nvu binaries from ~/.nvu/bin\n */\nexport default function teardownCmd(_args: string[]): void {\n const binDir = path.join(storagePath, 'bin');\n\n const binaries = ['node', 'npm', 'npx'];\n const ext =
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/commands/teardown.ts"],"sourcesContent":["import exit from 'exit-compat';\nimport fs from 'fs';\nimport { rmSync } from 'fs-remove-compat';\nimport path from 'path';\nimport { storagePath } from '../constants.ts';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\n/**\n * nvu teardown\n *\n * Remove nvu binaries from ~/.nvu/bin\n */\nexport default function teardownCmd(_args: string[]): void {\n const binDir = path.join(storagePath, 'bin');\n\n const binaries = ['node', 'npm', 'npx'];\n const ext = isWindows ? '.exe' : '';\n\n let removed = 0;\n for (let i = 0; i < binaries.length; i++) {\n const binaryPath = path.join(binDir, binaries[i] + ext);\n if (fs.existsSync(binaryPath)) {\n rmSync(binaryPath, { force: true });\n removed++;\n }\n }\n\n if (removed > 0) {\n console.log(`Removed ${removed} binary(s) from ${binDir}`);\n console.log('');\n console.log('You may also want to remove ~/.nvu/bin from your PATH.');\n } else {\n console.log('No binaries found to remove.');\n }\n\n exit(0);\n}\n"],"names":["teardownCmd","isWindows","process","platform","test","env","OSTYPE","_args","binDir","path","join","storagePath","binaries","ext","removed","i","length","binaryPath","fs","existsSync","rmSync","force","console","log","exit"],"mappings":";;;;+BAQA;;;;CAIC,GACD;;;eAAwBA;;;iEAbP;yDACF;8BACQ;2DACN;2BACW;;;;;;AAE5B,IAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAO5E,SAASN,YAAYO,KAAe;IACjD,IAAMC,SAASC,aAAI,CAACC,IAAI,CAACC,wBAAW,EAAE;IAEtC,IAAMC,WAAW;QAAC;QAAQ;QAAO;KAAM;IACvC,IAAMC,MAAMZ,YAAY,SAAS;IAEjC,IAAIa,UAAU;IACd,IAAK,IAAIC,IAAI,GAAGA,IAAIH,SAASI,MAAM,EAAED,IAAK;QACxC,IAAME,aAAaR,aAAI,CAACC,IAAI,CAACF,QAAQI,QAAQ,CAACG,EAAE,GAAGF;QACnD,IAAIK,WAAE,CAACC,UAAU,CAACF,aAAa;YAC7BG,IAAAA,sBAAM,EAACH,YAAY;gBAAEI,OAAO;YAAK;YACjCP;QACF;IACF;IAEA,IAAIA,UAAU,GAAG;QACfQ,QAAQC,GAAG,CAAC,AAAC,WAAoCf,OAA1BM,SAAQ,oBAAyB,OAAPN;QACjDc,QAAQC,GAAG,CAAC;QACZD,QAAQC,GAAG,CAAC;IACd,OAAO;QACLD,QAAQC,GAAG,CAAC;IACd;IAEAC,IAAAA,mBAAI,EAAC;AACP"}
|
package/dist/cjs/compat.d.cts
CHANGED
package/dist/cjs/compat.d.ts
CHANGED
package/dist/cjs/compat.js
CHANGED
|
@@ -26,6 +26,9 @@ _export(exports, {
|
|
|
26
26
|
},
|
|
27
27
|
get stringEndsWith () {
|
|
28
28
|
return stringEndsWith;
|
|
29
|
+
},
|
|
30
|
+
get tmpdir () {
|
|
31
|
+
return tmpdir;
|
|
29
32
|
}
|
|
30
33
|
});
|
|
31
34
|
var _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
@@ -41,12 +44,16 @@ function _interop_require_default(obj) {
|
|
|
41
44
|
var _require = typeof require === 'undefined' ? _module.default.createRequire(require("url").pathToFileURL(__filename).toString()) : require;
|
|
42
45
|
var hasHomedir = typeof _os.default.homedir === 'function';
|
|
43
46
|
function homedir() {
|
|
44
|
-
if (hasHomedir)
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
var home = _require('homedir-polyfill');
|
|
47
|
+
if (hasHomedir) return _os.default.homedir();
|
|
48
|
+
var home = require('homedir-polyfill');
|
|
48
49
|
return home();
|
|
49
50
|
}
|
|
51
|
+
var hasTmpdir = typeof _os.default.tmpdir === 'function';
|
|
52
|
+
function tmpdir() {
|
|
53
|
+
if (hasTmpdir) return _os.default.tmpdir();
|
|
54
|
+
var osShim = require('os-shim');
|
|
55
|
+
return osShim.tmpdir();
|
|
56
|
+
}
|
|
50
57
|
/**
|
|
51
58
|
* String.prototype.endsWith wrapper for Node.js 0.8+
|
|
52
59
|
* - Uses native endsWith on Node 4.0+ / ES2015+
|
package/dist/cjs/compat.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/compat.ts"],"sourcesContent":["/**\n * Compatibility Layer for Node.js 0.8+\n * Local to this package - contains only needed functions.\n */\nimport fs from 'fs';\nimport _Module from 'module';\nimport os from 'os';\nimport path from 'path';\n\n// Use existing require in CJS, or createRequire in ESM (Node 12.2+)\nconst _require = typeof require === 'undefined' ? _Module.createRequire(import.meta.url) : require;\n\nconst hasHomedir = typeof os.homedir === 'function';\
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/compat.ts"],"sourcesContent":["/**\n * Compatibility Layer for Node.js 0.8+\n * Local to this package - contains only needed functions.\n */\nimport fs from 'fs';\nimport _Module from 'module';\nimport os from 'os';\nimport path from 'path';\n\n// Use existing require in CJS, or createRequire in ESM (Node 12.2+)\nconst _require = typeof require === 'undefined' ? _Module.createRequire(import.meta.url) : require;\n\nconst hasHomedir = typeof os.homedir === 'function';\nexport function homedir(): string {\n if (hasHomedir) return os.homedir();\n const home = require('homedir-polyfill');\n return home();\n}\n\nconst hasTmpdir = typeof os.tmpdir === 'function';\nexport function tmpdir(): string {\n if (hasTmpdir) return os.tmpdir();\n const osShim = require('os-shim');\n return osShim.tmpdir();\n}\n\n/**\n * String.prototype.endsWith wrapper for Node.js 0.8+\n * - Uses native endsWith on Node 4.0+ / ES2015+\n * - Falls back to lastIndexOf on Node 0.8-3.x\n */\nconst hasEndsWith = typeof String.prototype.endsWith === 'function';\n\nexport function stringEndsWith(str: string, search: string, position?: number): boolean {\n if (hasEndsWith) {\n return str.endsWith(search, position);\n }\n const len = position === undefined ? str.length : position;\n return str.lastIndexOf(search) === len - search.length;\n}\n\n/**\n * Recursive mkdir for Node.js 0.8+\n */\nexport function mkdirpSync(dir: string): void {\n const mkdirp = _require('mkdirp-classic');\n mkdirp.sync(dir);\n}\n\n/**\n * Recursive rm for Node.js 0.8+\n */\nexport function rmSync(dir: string): void {\n const safeRmSync = _require('fs-remove-compat').safeRmSync;\n safeRmSync(dir);\n}\n\n/**\n * Read directory entries with types for Node.js 0.8+\n * Returns array of {name, isDirectory()}\n */\nexport interface DirEntry {\n name: string;\n isDirectory(): boolean;\n}\n\nexport function readdirWithTypes(dir: string): DirEntry[] {\n const names = fs.readdirSync(dir);\n return names.map((name) => {\n const fullPath = path.join(dir, name);\n let stat: fs.Stats;\n try {\n stat = fs.statSync(fullPath);\n } catch (_e) {\n // If stat fails, treat as non-directory\n return { name: name, isDirectory: () => false };\n }\n return {\n name: name,\n isDirectory: () => stat.isDirectory(),\n };\n });\n}\n"],"names":["homedir","mkdirpSync","readdirWithTypes","rmSync","stringEndsWith","tmpdir","_require","require","_Module","createRequire","hasHomedir","os","home","hasTmpdir","osShim","hasEndsWith","String","prototype","endsWith","str","search","position","len","undefined","length","lastIndexOf","dir","mkdirp","sync","safeRmSync","names","fs","readdirSync","map","name","fullPath","path","join","stat","statSync","_e","isDirectory"],"mappings":"AAAA;;;CAGC;;;;;;;;;;;QAUeA;eAAAA;;QA+BAC;eAAAA;;QAsBAC;eAAAA;;QAdAC;eAAAA;;QAnBAC;eAAAA;;QAbAC;eAAAA;;;yDAhBD;6DACK;yDACL;2DACE;;;;;;AAEjB,oEAAoE;AACpE,IAAMC,WAAW,OAAOC,YAAY,cAAcC,eAAO,CAACC,aAAa,CAAC,uDAAmBF;AAE3F,IAAMG,aAAa,OAAOC,WAAE,CAACX,OAAO,KAAK;AAClC,SAASA;IACd,IAAIU,YAAY,OAAOC,WAAE,CAACX,OAAO;IACjC,IAAMY,OAAOL,QAAQ;IACrB,OAAOK;AACT;AAEA,IAAMC,YAAY,OAAOF,WAAE,CAACN,MAAM,KAAK;AAChC,SAASA;IACd,IAAIQ,WAAW,OAAOF,WAAE,CAACN,MAAM;IAC/B,IAAMS,SAASP,QAAQ;IACvB,OAAOO,OAAOT,MAAM;AACtB;AAEA;;;;CAIC,GACD,IAAMU,cAAc,OAAOC,OAAOC,SAAS,CAACC,QAAQ,KAAK;AAElD,SAASd,eAAee,GAAW,EAAEC,MAAc,EAAEC,QAAiB;IAC3E,IAAIN,aAAa;QACf,OAAOI,IAAID,QAAQ,CAACE,QAAQC;IAC9B;IACA,IAAMC,MAAMD,aAAaE,YAAYJ,IAAIK,MAAM,GAAGH;IAClD,OAAOF,IAAIM,WAAW,CAACL,YAAYE,MAAMF,OAAOI,MAAM;AACxD;AAKO,SAASvB,WAAWyB,GAAW;IACpC,IAAMC,SAASrB,SAAS;IACxBqB,OAAOC,IAAI,CAACF;AACd;AAKO,SAASvB,OAAOuB,GAAW;IAChC,IAAMG,aAAavB,SAAS,oBAAoBuB,UAAU;IAC1DA,WAAWH;AACb;AAWO,SAASxB,iBAAiBwB,GAAW;IAC1C,IAAMI,QAAQC,WAAE,CAACC,WAAW,CAACN;IAC7B,OAAOI,MAAMG,GAAG,CAAC,SAACC;QAChB,IAAMC,WAAWC,aAAI,CAACC,IAAI,CAACX,KAAKQ;QAChC,IAAII;QACJ,IAAI;YACFA,OAAOP,WAAE,CAACQ,QAAQ,CAACJ;QACrB,EAAE,OAAOK,IAAI;YACX,wCAAwC;YACxC,OAAO;gBAAEN,MAAMA;gBAAMO,aAAa;2BAAM;;YAAM;QAChD;QACA,OAAO;YACLP,MAAMA;YACNO,aAAa;uBAAMH,KAAKG,WAAW;;QACrC;IACF;AACF"}
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
const envPathKey = require('env-path-key');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const { safeRmSync } = require('fs-remove-compat');
|
|
4
|
+
const getFile = require('get-file-compat');
|
|
5
|
+
const mkdirp = require('mkdirp-classic');
|
|
6
|
+
const os = require('os');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const Queue = require('queue-cb');
|
|
9
|
+
const moduleRoot = require('module-root-sync');
|
|
10
|
+
const root = moduleRoot(__dirname);
|
|
11
|
+
// Configuration
|
|
12
|
+
const GITHUB_REPO = 'kmalakoff/node-version-use';
|
|
13
|
+
const BINARY_VERSION = require(path.join(root, 'package.json')).binaryVersion;
|
|
14
|
+
const isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);
|
|
15
|
+
const hasHomedir = typeof os.homedir === 'function';
|
|
16
|
+
function homedir() {
|
|
17
|
+
if (hasHomedir) return os.homedir();
|
|
18
|
+
const home = require('homedir-polyfill');
|
|
19
|
+
return home();
|
|
20
|
+
}
|
|
21
|
+
// Allow NVU_HOME override for testing
|
|
22
|
+
const storagePath = process.env.NVU_HOME || path.join(homedir(), '.nvu');
|
|
23
|
+
const hasTmpdir = typeof os.tmpdir === 'function';
|
|
24
|
+
function tmpdir() {
|
|
25
|
+
if (hasTmpdir) return os.tmpdir();
|
|
26
|
+
const osShim = require('os-shim');
|
|
27
|
+
return osShim.tmpdir();
|
|
28
|
+
}
|
|
29
|
+
function removeIfExistsSync(filePath) {
|
|
30
|
+
if (fs.existsSync(filePath)) {
|
|
31
|
+
try {
|
|
32
|
+
fs.unlinkSync(filePath);
|
|
33
|
+
} catch (_e) {
|
|
34
|
+
// ignore cleanup errors
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get the platform-specific archive base name (without extension)
|
|
40
|
+
*/ function getArchiveBaseName() {
|
|
41
|
+
const { platform, arch } = process;
|
|
42
|
+
const platformMap = {
|
|
43
|
+
darwin: 'darwin',
|
|
44
|
+
linux: 'linux',
|
|
45
|
+
win32: 'win32'
|
|
46
|
+
};
|
|
47
|
+
const archMap = {
|
|
48
|
+
x64: 'x64',
|
|
49
|
+
arm64: 'arm64',
|
|
50
|
+
amd64: 'x64'
|
|
51
|
+
};
|
|
52
|
+
const platformName = platformMap[platform];
|
|
53
|
+
const archName = archMap[arch];
|
|
54
|
+
if (!platformName || !archName) return null;
|
|
55
|
+
return `nvu-binary-${platformName}-${archName}`;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Copy file
|
|
59
|
+
*/ function copyFileSync(src, dest) {
|
|
60
|
+
const content = fs.readFileSync(src);
|
|
61
|
+
fs.writeFileSync(dest, content);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Atomic rename with fallback to copy+delete for cross-device moves
|
|
65
|
+
*/ function atomicRename(src, dest, callback) {
|
|
66
|
+
fs.rename(src, dest, (err)=>{
|
|
67
|
+
if (!err) {
|
|
68
|
+
callback(null);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
// Cross-device link error - fall back to copy + delete
|
|
72
|
+
if (err.code === 'EXDEV') {
|
|
73
|
+
try {
|
|
74
|
+
copyFileSync(src, dest);
|
|
75
|
+
fs.unlinkSync(src);
|
|
76
|
+
callback(null);
|
|
77
|
+
} catch (copyErr) {
|
|
78
|
+
callback(copyErr);
|
|
79
|
+
}
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
callback(err);
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Extract archive to a directory (callback-based)
|
|
87
|
+
*/ function extractArchive(archivePath, dest, callback) {
|
|
88
|
+
const Iterator = isWindows ? require('zip-iterator') : require('tar-iterator');
|
|
89
|
+
const stream = isWindows ? fs.createReadStream(archivePath) : fs.createReadStream(archivePath).pipe(require('zlib').createGunzip());
|
|
90
|
+
let iterator = new Iterator(stream);
|
|
91
|
+
// one by one
|
|
92
|
+
const links = [];
|
|
93
|
+
iterator.forEach((entry, callback)=>{
|
|
94
|
+
if (entry.type === 'link') {
|
|
95
|
+
links.unshift(entry);
|
|
96
|
+
callback();
|
|
97
|
+
} else if (entry.type === 'symlink') {
|
|
98
|
+
links.push(entry);
|
|
99
|
+
callback();
|
|
100
|
+
} else entry.create(dest, callback);
|
|
101
|
+
}, {
|
|
102
|
+
callbacks: true,
|
|
103
|
+
concurrency: 1
|
|
104
|
+
}, (_err)=>{
|
|
105
|
+
// create links after directories and files
|
|
106
|
+
const queue = new Queue();
|
|
107
|
+
for(let index = 0; index < links.length; index++){
|
|
108
|
+
const entry = links[index];
|
|
109
|
+
queue.defer(entry.create.bind(entry, dest));
|
|
110
|
+
}
|
|
111
|
+
queue.await((err)=>{
|
|
112
|
+
iterator.destroy();
|
|
113
|
+
iterator = null;
|
|
114
|
+
callback(err);
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Install binaries using atomic rename pattern
|
|
120
|
+
* 1. Extract to temp directory
|
|
121
|
+
* 2. Copy binary to temp files in destination directory
|
|
122
|
+
* 3. Atomic rename temp files to final names
|
|
123
|
+
*/ function extractAndInstall(archivePath, destDir, binaryName, callback) {
|
|
124
|
+
const ext = isWindows ? '.exe' : '';
|
|
125
|
+
// Create temp extraction directory
|
|
126
|
+
const tempExtractDir = path.join(tmpdir(), `nvu-extract-${Date.now()}`);
|
|
127
|
+
mkdirp.sync(tempExtractDir);
|
|
128
|
+
extractArchive(archivePath, tempExtractDir, (err)=>{
|
|
129
|
+
if (err) {
|
|
130
|
+
safeRmSync(tempExtractDir);
|
|
131
|
+
callback(err);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const extractedPath = path.join(tempExtractDir, binaryName);
|
|
135
|
+
if (!fs.existsSync(extractedPath)) {
|
|
136
|
+
safeRmSync(tempExtractDir);
|
|
137
|
+
callback(new Error(`Extracted binary not found: ${binaryName}. ${archivePath} ${tempExtractDir}`));
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
// Binary names to install
|
|
141
|
+
const binaries = [
|
|
142
|
+
'node',
|
|
143
|
+
'npm',
|
|
144
|
+
'npx',
|
|
145
|
+
'corepack'
|
|
146
|
+
];
|
|
147
|
+
const timestamp = Date.now();
|
|
148
|
+
let installError = null;
|
|
149
|
+
// Step 1: Copy extracted binary to temp files in destination directory
|
|
150
|
+
// This ensures the temp files are on the same filesystem for atomic rename
|
|
151
|
+
for(let i = 0; i < binaries.length; i++){
|
|
152
|
+
const name = binaries[i];
|
|
153
|
+
const tempDest = path.join(destDir, `${name}.tmp-${timestamp}${ext}`);
|
|
154
|
+
try {
|
|
155
|
+
// Copy to temp file in destination directory
|
|
156
|
+
copyFileSync(extractedPath, tempDest);
|
|
157
|
+
// Set permissions on Unix
|
|
158
|
+
if (!isWindows) fs.chmodSync(tempDest, 0o755);
|
|
159
|
+
} catch (err) {
|
|
160
|
+
installError = err;
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
if (installError) {
|
|
165
|
+
// Clean up any temp files we created
|
|
166
|
+
for(let j = 0; j < binaries.length; j++){
|
|
167
|
+
const tempPath = path.join(destDir, `${binaries[j]}.tmp-${timestamp}${ext}`);
|
|
168
|
+
removeIfExistsSync(tempPath);
|
|
169
|
+
}
|
|
170
|
+
safeRmSync(tempExtractDir);
|
|
171
|
+
callback(installError);
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
// Step 2: Atomic rename temp files to final names
|
|
175
|
+
let renameError = null;
|
|
176
|
+
function doRename(index) {
|
|
177
|
+
if (index >= binaries.length) {
|
|
178
|
+
// All renames complete
|
|
179
|
+
safeRmSync(tempExtractDir);
|
|
180
|
+
callback(renameError);
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const name = binaries[index];
|
|
184
|
+
const tempDest = path.join(destDir, `${name}.tmp-${timestamp}${ext}`);
|
|
185
|
+
const finalDest = path.join(destDir, `${name}${ext}`);
|
|
186
|
+
// Remove existing file if present (for atomic replacement)
|
|
187
|
+
removeIfExistsSync(finalDest);
|
|
188
|
+
atomicRename(tempDest, finalDest, (err)=>{
|
|
189
|
+
if (err && !renameError) {
|
|
190
|
+
renameError = err;
|
|
191
|
+
}
|
|
192
|
+
doRename(index + 1);
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
doRename(0);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Print setup instructions
|
|
200
|
+
*/ module.exports.printInstructions = function printInstructions() {
|
|
201
|
+
const nvuBinPath = path.join(storagePath, 'bin');
|
|
202
|
+
console.log('nvu binaries installed in ~/.nvu/bin/');
|
|
203
|
+
const pathKey = envPathKey();
|
|
204
|
+
const envPath = process.env[pathKey] || '';
|
|
205
|
+
if (envPath.indexOf('.nvu/bin') >= 0) return; // path exists
|
|
206
|
+
// provide instructions for path setup
|
|
207
|
+
console.log('');
|
|
208
|
+
console.log('============================================================');
|
|
209
|
+
console.log(' Global node setup');
|
|
210
|
+
console.log('============================================================');
|
|
211
|
+
console.log('');
|
|
212
|
+
if (isWindows) {
|
|
213
|
+
console.log(' PowerShell (add to $PROFILE):');
|
|
214
|
+
console.log(` $env:PATH = "${nvuBinPath};$env:PATH"`);
|
|
215
|
+
console.log('');
|
|
216
|
+
console.log(' CMD (run as administrator):');
|
|
217
|
+
console.log(` setx PATH "${nvuBinPath};%PATH%"`);
|
|
218
|
+
} else {
|
|
219
|
+
console.log(' # For bash (~/.bashrc):');
|
|
220
|
+
console.log(' echo \'export PATH="$HOME/.nvu/bin:$PATH"\' >> ~/.bashrc');
|
|
221
|
+
console.log('');
|
|
222
|
+
console.log(' # For zsh (~/.zshrc):');
|
|
223
|
+
console.log(' echo \'export PATH="$HOME/.nvu/bin:$PATH"\' >> ~/.zshrc');
|
|
224
|
+
console.log('');
|
|
225
|
+
console.log(' # For fish (~/.config/fish/config.fish):');
|
|
226
|
+
console.log(" echo 'set -gx PATH $HOME/.nvu/bin $PATH' >> ~/.config/fish/config.fish");
|
|
227
|
+
}
|
|
228
|
+
console.log('');
|
|
229
|
+
console.log('Then restart your terminal or source your shell profile.');
|
|
230
|
+
console.log('');
|
|
231
|
+
console.log("Without this, 'nvu 18 npm test' still works - you just won't have");
|
|
232
|
+
console.log("transparent 'node' command override.");
|
|
233
|
+
console.log('============================================================');
|
|
234
|
+
};
|
|
235
|
+
/**
|
|
236
|
+
* Main installation function
|
|
237
|
+
*/ module.exports.installBinaries = function installBinaries(options, callback) {
|
|
238
|
+
const archiveBaseName = getArchiveBaseName();
|
|
239
|
+
if (!archiveBaseName) {
|
|
240
|
+
callback(new Error('Unsupported platform/architecture for binary.'));
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
const extractedBinaryName = `${archiveBaseName}${isWindows ? '.exe' : ''}`;
|
|
244
|
+
const binDir = path.join(storagePath, 'bin');
|
|
245
|
+
// check if we need to upgrade
|
|
246
|
+
if (!options.force) {
|
|
247
|
+
try {
|
|
248
|
+
// already installed
|
|
249
|
+
if (fs.statSync(binDir)) {
|
|
250
|
+
if (fs.readFileSync(path.join(binDir, 'version.txt'), 'utf8') === BINARY_VERSION) {
|
|
251
|
+
callback(null, false);
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
} catch (_err) {}
|
|
256
|
+
}
|
|
257
|
+
// Create directories
|
|
258
|
+
mkdirp.sync(storagePath);
|
|
259
|
+
mkdirp.sync(binDir);
|
|
260
|
+
const downloadUrl = `https://github.com/${GITHUB_REPO}/releases/download/binary-v${BINARY_VERSION}/${archiveBaseName}${isWindows ? '.zip' : '.tar.gz'}`;
|
|
261
|
+
const tempPath = path.join(tmpdir(), `nvu-binary-${Date.now()}${isWindows ? '.zip' : '.tar.gz'}`);
|
|
262
|
+
console.log(`Downloading binary for ${process.platform}-${process.arch}...`);
|
|
263
|
+
getFile(downloadUrl, tempPath, (err)=>{
|
|
264
|
+
if (err) {
|
|
265
|
+
removeIfExistsSync(tempPath);
|
|
266
|
+
callback(new Error(`No prebuilt binary available for ${process.platform}-${process.arch}. Download: ${downloadUrl}. Error: ${err.message}`));
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
console.log('Extracting binary...');
|
|
270
|
+
extractAndInstall(tempPath, binDir, extractedBinaryName, (err)=>{
|
|
271
|
+
removeIfExistsSync(tempPath);
|
|
272
|
+
if (err) {
|
|
273
|
+
callback(err);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
// save binary version for upgrade checks
|
|
277
|
+
fs.writeFileSync(path.join(binDir, 'version.txt'), BINARY_VERSION, 'utf8');
|
|
278
|
+
console.log('Binary installed successfully!');
|
|
279
|
+
callback(null, true);
|
|
280
|
+
});
|
|
281
|
+
});
|
|
282
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-version-use/src/assets/installBinaries.cts"],"sourcesContent":["const envPathKey = require('env-path-key');\nconst fs = require('fs');\nconst { safeRmSync } = require('fs-remove-compat');\nconst getFile = require('get-file-compat');\nconst mkdirp = require('mkdirp-classic');\nconst os = require('os');\nconst path = require('path');\nconst Queue = require('queue-cb');\nconst moduleRoot = require('module-root-sync');\n\nconst root = moduleRoot(__dirname);\n\n// Configuration\nconst GITHUB_REPO = 'kmalakoff/node-version-use';\nconst BINARY_VERSION = require(path.join(root, 'package.json')).binaryVersion;\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\ntype Callback = (err?: Error | null) => void;\n\ninterface PlatformMap {\n [key: string]: string;\n}\n\nconst hasHomedir = typeof os.homedir === 'function';\nfunction homedir(): string {\n if (hasHomedir) return os.homedir();\n const home = require('homedir-polyfill');\n return home();\n}\n\n// Allow NVU_HOME override for testing\nconst storagePath = (process.env.NVU_HOME || path.join(homedir(), '.nvu')) as string;\n\nconst hasTmpdir = typeof os.tmpdir === 'function';\nfunction tmpdir(): string {\n if (hasTmpdir) return os.tmpdir();\n const osShim = require('os-shim');\n return osShim.tmpdir();\n}\n\nfunction removeIfExistsSync(filePath: string): void {\n if (fs.existsSync(filePath)) {\n try {\n fs.unlinkSync(filePath);\n } catch (_e) {\n // ignore cleanup errors\n }\n }\n}\n\n/**\n * Get the platform-specific archive base name (without extension)\n */\nfunction getArchiveBaseName(): string | null {\n const { platform, arch } = process;\n\n const platformMap: PlatformMap = {\n darwin: 'darwin',\n linux: 'linux',\n win32: 'win32',\n };\n\n const archMap: PlatformMap = {\n x64: 'x64',\n arm64: 'arm64',\n amd64: 'x64',\n };\n\n const platformName = platformMap[platform];\n const archName = archMap[arch];\n\n if (!platformName || !archName) return null;\n return `nvu-binary-${platformName}-${archName}`;\n}\n\n/**\n * Copy file\n */\nfunction copyFileSync(src: string, dest: string): void {\n const content = fs.readFileSync(src);\n fs.writeFileSync(dest, content);\n}\n\n/**\n * Atomic rename with fallback to copy+delete for cross-device moves\n */\nfunction atomicRename(src: string, dest: string, callback: Callback): void {\n fs.rename(src, dest, (err) => {\n if (!err) {\n callback(null);\n return;\n }\n\n // Cross-device link error - fall back to copy + delete\n if ((err as NodeJS.ErrnoException).code === 'EXDEV') {\n try {\n copyFileSync(src, dest);\n fs.unlinkSync(src);\n callback(null);\n } catch (copyErr) {\n callback(copyErr as Error);\n }\n return;\n }\n\n callback(err);\n });\n}\n\n/**\n * Extract archive to a directory (callback-based)\n */\nfunction extractArchive(archivePath: string, dest: string, callback: Callback): void {\n const Iterator = isWindows ? require('zip-iterator') : require('tar-iterator');\n const stream = isWindows ? fs.createReadStream(archivePath) : fs.createReadStream(archivePath).pipe(require('zlib').createGunzip());\n let iterator = new Iterator(stream);\n\n // one by one\n const links = [];\n iterator.forEach(\n (entry, callback) => {\n if (entry.type === 'link') {\n links.unshift(entry);\n callback();\n } else if (entry.type === 'symlink') {\n links.push(entry);\n callback();\n } else entry.create(dest, callback);\n },\n { callbacks: true, concurrency: 1 },\n (_err) => {\n // create links after directories and files\n const queue = new Queue();\n for (let index = 0; index < links.length; index++) {\n const entry = links[index];\n queue.defer(entry.create.bind(entry, dest));\n }\n queue.await((err) => {\n iterator.destroy();\n iterator = null;\n callback(err);\n });\n }\n );\n}\n\n/**\n * Install binaries using atomic rename pattern\n * 1. Extract to temp directory\n * 2. Copy binary to temp files in destination directory\n * 3. Atomic rename temp files to final names\n */\nfunction extractAndInstall(archivePath: string, destDir: string, binaryName: string, callback: Callback): void {\n const ext = isWindows ? '.exe' : '';\n\n // Create temp extraction directory\n const tempExtractDir = path.join(tmpdir(), `nvu-extract-${Date.now()}`);\n mkdirp.sync(tempExtractDir);\n\n extractArchive(archivePath, tempExtractDir, (err) => {\n if (err) {\n safeRmSync(tempExtractDir);\n callback(err);\n return;\n }\n\n const extractedPath = path.join(tempExtractDir, binaryName);\n if (!fs.existsSync(extractedPath)) {\n safeRmSync(tempExtractDir);\n callback(new Error(`Extracted binary not found: ${binaryName}. ${archivePath} ${tempExtractDir}`));\n return;\n }\n\n // Binary names to install\n const binaries = ['node', 'npm', 'npx', 'corepack'];\n const timestamp = Date.now();\n let installError: Error | null = null;\n\n // Step 1: Copy extracted binary to temp files in destination directory\n // This ensures the temp files are on the same filesystem for atomic rename\n for (let i = 0; i < binaries.length; i++) {\n const name = binaries[i];\n const tempDest = path.join(destDir, `${name}.tmp-${timestamp}${ext}`);\n\n try {\n // Copy to temp file in destination directory\n copyFileSync(extractedPath, tempDest);\n\n // Set permissions on Unix\n if (!isWindows) fs.chmodSync(tempDest, 0o755);\n } catch (err) {\n installError = err as Error;\n break;\n }\n }\n\n if (installError) {\n // Clean up any temp files we created\n for (let j = 0; j < binaries.length; j++) {\n const tempPath = path.join(destDir, `${binaries[j]}.tmp-${timestamp}${ext}`);\n removeIfExistsSync(tempPath);\n }\n safeRmSync(tempExtractDir);\n callback(installError);\n return;\n }\n\n // Step 2: Atomic rename temp files to final names\n let renameError: Error | null = null;\n\n function doRename(index: number): void {\n if (index >= binaries.length) {\n // All renames complete\n safeRmSync(tempExtractDir);\n callback(renameError);\n return;\n }\n\n const name = binaries[index];\n const tempDest = path.join(destDir, `${name}.tmp-${timestamp}${ext}`);\n const finalDest = path.join(destDir, `${name}${ext}`);\n\n // Remove existing file if present (for atomic replacement)\n removeIfExistsSync(finalDest);\n\n atomicRename(tempDest, finalDest, (err) => {\n if (err && !renameError) {\n renameError = err;\n }\n doRename(index + 1);\n });\n }\n\n doRename(0);\n });\n}\n\n/**\n * Print setup instructions\n */\nmodule.exports.printInstructions = function printInstructions(): void {\n const nvuBinPath = path.join(storagePath, 'bin');\n\n console.log('nvu binaries installed in ~/.nvu/bin/');\n\n const pathKey = envPathKey();\n const envPath = process.env[pathKey] || '';\n if (envPath.indexOf('.nvu/bin') >= 0) return; // path exists\n\n // provide instructions for path setup\n console.log('');\n console.log('============================================================');\n console.log(' Global node setup');\n console.log('============================================================');\n console.log('');\n if (isWindows) {\n console.log(' PowerShell (add to $PROFILE):');\n console.log(` $env:PATH = \"${nvuBinPath};$env:PATH\"`);\n console.log('');\n console.log(' CMD (run as administrator):');\n console.log(` setx PATH \"${nvuBinPath};%PATH%\"`);\n } else {\n console.log(' # For bash (~/.bashrc):');\n console.log(' echo \\'export PATH=\"$HOME/.nvu/bin:$PATH\"\\' >> ~/.bashrc');\n console.log('');\n console.log(' # For zsh (~/.zshrc):');\n console.log(' echo \\'export PATH=\"$HOME/.nvu/bin:$PATH\"\\' >> ~/.zshrc');\n console.log('');\n console.log(' # For fish (~/.config/fish/config.fish):');\n console.log(\" echo 'set -gx PATH $HOME/.nvu/bin $PATH' >> ~/.config/fish/config.fish\");\n }\n\n console.log('');\n console.log('Then restart your terminal or source your shell profile.');\n console.log('');\n console.log(\"Without this, 'nvu 18 npm test' still works - you just won't have\");\n console.log(\"transparent 'node' command override.\");\n console.log('============================================================');\n};\n\n/**\n * Main installation function\n */\nmodule.exports.installBinaries = function installBinaries(options, callback): void {\n const archiveBaseName = getArchiveBaseName();\n\n if (!archiveBaseName) {\n callback(new Error('Unsupported platform/architecture for binary.'));\n return;\n }\n\n const extractedBinaryName = `${archiveBaseName}${isWindows ? '.exe' : ''}`;\n const binDir = path.join(storagePath, 'bin');\n\n // check if we need to upgrade\n if (!options.force) {\n try {\n // already installed\n if (fs.statSync(binDir)) {\n if (fs.readFileSync(path.join(binDir, 'version.txt'), 'utf8') === BINARY_VERSION) {\n callback(null, false);\n return;\n }\n }\n } catch (_err) {}\n }\n\n // Create directories\n mkdirp.sync(storagePath);\n mkdirp.sync(binDir);\n\n const downloadUrl = `https://github.com/${GITHUB_REPO}/releases/download/binary-v${BINARY_VERSION}/${archiveBaseName}${isWindows ? '.zip' : '.tar.gz'}`;\n const tempPath = path.join(tmpdir(), `nvu-binary-${Date.now()}${isWindows ? '.zip' : '.tar.gz'}`);\n\n console.log(`Downloading binary for ${process.platform}-${process.arch}...`);\n\n getFile(downloadUrl, tempPath, (err) => {\n if (err) {\n removeIfExistsSync(tempPath);\n callback(new Error(`No prebuilt binary available for ${process.platform}-${process.arch}. Download: ${downloadUrl}. Error: ${err.message}`));\n return;\n }\n\n console.log('Extracting binary...');\n\n extractAndInstall(tempPath, binDir, extractedBinaryName, (err) => {\n removeIfExistsSync(tempPath);\n if (err) {\n callback(err);\n return;\n }\n\n // save binary version for upgrade checks\n fs.writeFileSync(path.join(binDir, 'version.txt'), BINARY_VERSION, 'utf8');\n console.log('Binary installed successfully!');\n callback(null, true);\n });\n });\n};\n"],"names":["envPathKey","require","fs","safeRmSync","getFile","mkdirp","os","path","Queue","moduleRoot","root","__dirname","GITHUB_REPO","BINARY_VERSION","join","binaryVersion","isWindows","process","platform","test","env","OSTYPE","hasHomedir","homedir","home","storagePath","NVU_HOME","hasTmpdir","tmpdir","osShim","removeIfExistsSync","filePath","existsSync","unlinkSync","_e","getArchiveBaseName","arch","platformMap","darwin","linux","win32","archMap","x64","arm64","amd64","platformName","archName","copyFileSync","src","dest","content","readFileSync","writeFileSync","atomicRename","callback","rename","err","code","copyErr","extractArchive","archivePath","Iterator","stream","createReadStream","pipe","createGunzip","iterator","links","forEach","entry","type","unshift","push","create","callbacks","concurrency","_err","queue","index","length","defer","bind","await","destroy","extractAndInstall","destDir","binaryName","ext","tempExtractDir","Date","now","sync","extractedPath","Error","binaries","timestamp","installError","i","name","tempDest","chmodSync","j","tempPath","renameError","doRename","finalDest","module","exports","printInstructions","nvuBinPath","console","log","pathKey","envPath","indexOf","installBinaries","options","archiveBaseName","extractedBinaryName","binDir","force","statSync","downloadUrl","message"],"mappings":"AAAA,MAAMA,aAAaC,QAAQ;AAC3B,MAAMC,KAAKD,QAAQ;AACnB,MAAM,EAAEE,UAAU,EAAE,GAAGF,QAAQ;AAC/B,MAAMG,UAAUH,QAAQ;AACxB,MAAMI,SAASJ,QAAQ;AACvB,MAAMK,KAAKL,QAAQ;AACnB,MAAMM,OAAON,QAAQ;AACrB,MAAMO,QAAQP,QAAQ;AACtB,MAAMQ,aAAaR,QAAQ;AAE3B,MAAMS,OAAOD,WAAWE;AAExB,gBAAgB;AAChB,MAAMC,cAAc;AACpB,MAAMC,iBAAiBZ,QAAQM,KAAKO,IAAI,CAACJ,MAAM,iBAAiBK,aAAa;AAE7E,MAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAQ3F,MAAMC,aAAa,OAAOhB,GAAGiB,OA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