node-install-release 1.18.6 → 1.19.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.
@@ -44,41 +44,42 @@ function installLib(version, dest, options, callback) {
44
44
  var platform = options.platform;
45
45
  var libPath = platform === 'win32' ? dest : _path.default.join(dest, 'lib');
46
46
  var installPath = _path.default.join(libPath, 'node_modules', 'npm');
47
- var dist = (0, _nodefilenametodistpaths.getDist)(version);
48
- var npmMajorPair = dist && dist.npm ? +dist.npm.split('.')[0] : _constantsts.NPM_MIN_VERSION;
49
- var npmMajor = Math.max(npmMajorPair, _constantsts.NPM_MIN_VERSION);
50
- (0, _getfilecompat.getContent)(_constantsts.NPM_DIST_TAGS_URL, 'utf8', function(err, res) {
51
- if (err) return callback(err);
52
- try {
53
- var _ref, _options_cachePath;
54
- var distTags = JSON.parse((_ref = res === null || res === void 0 ? void 0 : res.content) !== null && _ref !== void 0 ? _ref : '{}');
55
- var npmVersion = distTags["latest-".concat(npmMajor)] || distTags["next-".concat(npmMajor)] || distTags.latest;
56
- var downloadPath = "".concat(_constantsts.NPM_DIST_URL, "/-/npm-").concat(npmVersion, ".tgz");
57
- var cachePath = _path.default.join((_options_cachePath = options.cachePath) !== null && _options_cachePath !== void 0 ? _options_cachePath : (0, _compatts.tmpdir)(), _path.default.basename(downloadPath));
58
- var checksum;
59
- var queue = new _queuecb.default(1);
60
- queue.defer(function(cb) {
61
- return (0, _conditionalCachets.default)(downloadPath, cachePath, options, function(err) {
62
- return cb(err);
47
+ (0, _nodefilenametodistpaths.getDistAsync)(version, function(_err, dist) {
48
+ // pin the npm major only when the dist index knows this version; unknown means use latest
49
+ var npmMajor = dist && dist.npm ? Math.max(+dist.npm.split('.')[0], _constantsts.NPM_MIN_VERSION) : null;
50
+ (0, _getfilecompat.getContent)(_constantsts.NPM_DIST_TAGS_URL, 'utf8', function(err, res) {
51
+ if (err) return callback(err);
52
+ try {
53
+ var _ref, _options_cachePath;
54
+ var distTags = JSON.parse((_ref = res === null || res === void 0 ? void 0 : res.content) !== null && _ref !== void 0 ? _ref : '{}');
55
+ var npmVersion = npmMajor === null ? distTags.latest : distTags["latest-".concat(npmMajor)] || distTags["next-".concat(npmMajor)] || distTags.latest;
56
+ var downloadPath = "".concat(_constantsts.NPM_DIST_URL, "/-/npm-").concat(npmVersion, ".tgz");
57
+ var cachePath = _path.default.join((_options_cachePath = options.cachePath) !== null && _options_cachePath !== void 0 ? _options_cachePath : (0, _compatts.tmpdir)(), _path.default.basename(downloadPath));
58
+ var checksum;
59
+ var queue = new _queuecb.default(1);
60
+ queue.defer(function(cb) {
61
+ return (0, _conditionalCachets.default)(downloadPath, cachePath, options, function(err) {
62
+ return cb(err);
63
+ });
64
+ });
65
+ queue.defer(function(cb) {
66
+ calculateChecksum(cachePath, function(err, hash) {
67
+ checksum = hash;
68
+ cb(err);
69
+ });
63
70
  });
64
- });
65
- queue.defer(function(cb) {
66
- calculateChecksum(cachePath, function(err, hash) {
67
- checksum = hash;
68
- cb(err);
71
+ queue.defer(function(cb) {
72
+ return (0, _extractts.default)(cachePath, installPath, function(err) {
73
+ return cb(err);
74
+ });
69
75
  });
70
- });
71
- queue.defer(function(cb) {
72
- return (0, _extractts.default)(cachePath, installPath, function(err) {
73
- return cb(err);
76
+ queue.await(function(err) {
77
+ err ? callback(err) : callback(undefined, npmVersion, checksum);
74
78
  });
75
- });
76
- queue.await(function(err) {
77
- err ? callback(err) : callback(undefined, npmVersion, checksum);
78
- });
79
- } catch (_e) {
80
- return callback(new Error('Failed to parse npm dist-tags'));
81
- }
79
+ } catch (_e) {
80
+ return callback(new Error('Failed to parse npm dist-tags'));
81
+ }
82
+ });
82
83
  });
83
84
  }
84
85
  /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-install-release/src/installNPM/installLib.ts"],"sourcesContent":["import crypto from 'crypto';\nimport fs from 'fs';\nimport { getContent } from 'get-file-compat';\nimport { getDist } from 'node-filename-to-dist-paths';\nimport oo from 'on-one';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport { tmpdir } from '../compat.ts';\nimport { NPM_DIST_TAGS_URL, NPM_DIST_URL, NPM_MIN_VERSION } from '../constants.ts';\nimport conditionalCache from '../lib/conditionalCache.ts';\nimport extract from '../lib/extract.ts';\n\nimport type { InstallOptions } from '../types.ts';\n\nexport type Callback = (error?: Error | null, npmVersion?: string, checksum?: string) => void;\n\nfunction calculateChecksum(filePath: string, callback: (err?: Error | null, checksum?: string) => void): void {\n const hash = crypto.createHash('sha256');\n const stream = fs.createReadStream(filePath);\n stream.on('data', (data) => hash.update(data));\n oo(stream, ['error', 'end', 'close', 'finish'], (err: Error | null) => {\n if (err) return callback(err);\n callback(undefined, hash.digest('hex'));\n });\n}\n\nexport default function installLib(version: string, dest: string, options: InstallOptions, callback: Callback): void {\n const platform = options.platform;\n const libPath = platform === 'win32' ? dest : path.join(dest, 'lib');\n const installPath = path.join(libPath, 'node_modules', 'npm');\n\n const dist = getDist(version);\n const npmMajorPair = dist && dist.npm ? +dist.npm.split('.')[0] : NPM_MIN_VERSION;\n const npmMajor = Math.max(npmMajorPair, NPM_MIN_VERSION);\n\n getContent(NPM_DIST_TAGS_URL, 'utf8', (err, res) => {\n if (err) return callback(err);\n try {\n const distTags = JSON.parse(res?.content ?? '{}') as Record<string, string>;\n const npmVersion = distTags[`latest-${npmMajor}`] || distTags[`next-${npmMajor}`] || distTags.latest;\n const downloadPath = `${NPM_DIST_URL}/-/npm-${npmVersion}.tgz`;\n const cachePath = path.join(options.cachePath ?? tmpdir(), path.basename(downloadPath));\n\n let checksum: string | undefined;\n const queue = new Queue(1);\n queue.defer((cb) => conditionalCache(downloadPath, cachePath, options, (err) => cb(err)));\n queue.defer((cb) => {\n calculateChecksum(cachePath, (err, hash) => {\n checksum = hash;\n cb(err);\n });\n });\n queue.defer((cb) => extract(cachePath, installPath, (err) => cb(err)));\n queue.await((err) => {\n err ? callback(err) : callback(undefined, npmVersion, checksum);\n });\n } catch (_e) {\n return callback(new Error('Failed to parse npm dist-tags'));\n }\n });\n}\n"],"names":["installLib","calculateChecksum","filePath","callback","hash","crypto","createHash","stream","fs","createReadStream","on","data","update","oo","err","undefined","digest","version","dest","options","platform","libPath","path","join","installPath","dist","getDist","npmMajorPair","npm","split","NPM_MIN_VERSION","npmMajor","Math","max","getContent","NPM_DIST_TAGS_URL","res","distTags","JSON","parse","content","npmVersion","latest","downloadPath","NPM_DIST_URL","cachePath","tmpdir","basename","checksum","queue","Queue","defer","cb","conditionalCache","extract","await","_e","Error"],"mappings":";;;;+BA0BA;;;eAAwBA;;;6DA1BL;yDACJ;6BACY;uCACH;4DACT;2DACE;8DACC;wBACK;2BAC0C;yEACpC;gEACT;;;;;;AAMpB,SAASC,kBAAkBC,QAAgB,EAAEC,QAAyD;IACpG,IAAMC,OAAOC,eAAM,CAACC,UAAU,CAAC;IAC/B,IAAMC,SAASC,WAAE,CAACC,gBAAgB,CAACP;IACnCK,OAAOG,EAAE,CAAC,QAAQ,SAACC;eAASP,KAAKQ,MAAM,CAACD;;IACxCE,IAAAA,cAAE,EAACN,QAAQ;QAAC;QAAS;QAAO;QAAS;KAAS,EAAE,SAACO;QAC/C,IAAIA,KAAK,OAAOX,SAASW;QACzBX,SAASY,WAAWX,KAAKY,MAAM,CAAC;IAClC;AACF;AAEe,SAAShB,WAAWiB,OAAe,EAAEC,IAAY,EAAEC,OAAuB,EAAEhB,QAAkB;IAC3G,IAAMiB,WAAWD,QAAQC,QAAQ;IACjC,IAAMC,UAAUD,aAAa,UAAUF,OAAOI,aAAI,CAACC,IAAI,CAACL,MAAM;IAC9D,IAAMM,cAAcF,aAAI,CAACC,IAAI,CAACF,SAAS,gBAAgB;IAEvD,IAAMI,OAAOC,IAAAA,gCAAO,EAAC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OAAOrD,SAAS,IAAIsD,MAAM;QAC5B;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-install-release/src/installNPM/installLib.ts"],"sourcesContent":["import crypto from 'crypto';\nimport fs from 'fs';\nimport { getContent } from 'get-file-compat';\nimport { getDistAsync } from 'node-filename-to-dist-paths';\nimport oo from 'on-one';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport { tmpdir } from '../compat.ts';\nimport { NPM_DIST_TAGS_URL, NPM_DIST_URL, NPM_MIN_VERSION } from '../constants.ts';\nimport conditionalCache from '../lib/conditionalCache.ts';\nimport extract from '../lib/extract.ts';\n\nimport type { InstallOptions } from '../types.ts';\n\nexport type Callback = (error?: Error | null, npmVersion?: string, checksum?: string) => void;\n\nfunction calculateChecksum(filePath: string, callback: (err?: Error | null, checksum?: string) => void): void {\n const hash = crypto.createHash('sha256');\n const stream = fs.createReadStream(filePath);\n stream.on('data', (data) => hash.update(data));\n oo(stream, ['error', 'end', 'close', 'finish'], (err: Error | null) => {\n if (err) return callback(err);\n callback(undefined, hash.digest('hex'));\n });\n}\n\nexport default function installLib(version: string, dest: string, options: InstallOptions, callback: Callback): void {\n const platform = options.platform;\n const libPath = platform === 'win32' ? dest : path.join(dest, 'lib');\n const installPath = path.join(libPath, 'node_modules', 'npm');\n\n getDistAsync(version, (_err, dist) => {\n // pin the npm major only when the dist index knows this version; unknown means use latest\n const npmMajor = dist && dist.npm ? Math.max(+dist.npm.split('.')[0], NPM_MIN_VERSION) : null;\n\n getContent(NPM_DIST_TAGS_URL, 'utf8', (err, res) => {\n if (err) return callback(err);\n try {\n const distTags = JSON.parse(res?.content ?? '{}') as Record<string, string>;\n const npmVersion = npmMajor === null ? distTags.latest : distTags[`latest-${npmMajor}`] || distTags[`next-${npmMajor}`] || distTags.latest;\n const downloadPath = `${NPM_DIST_URL}/-/npm-${npmVersion}.tgz`;\n const cachePath = path.join(options.cachePath ?? tmpdir(), path.basename(downloadPath));\n\n let checksum: string | undefined;\n const queue = new Queue(1);\n queue.defer((cb) => conditionalCache(downloadPath, cachePath, options, (err) => cb(err)));\n queue.defer((cb) => {\n calculateChecksum(cachePath, (err, hash) => {\n checksum = hash;\n cb(err);\n });\n });\n queue.defer((cb) => extract(cachePath, installPath, (err) => cb(err)));\n queue.await((err) => {\n err ? callback(err) : callback(undefined, npmVersion, checksum);\n });\n } catch (_e) {\n return callback(new Error('Failed to parse npm dist-tags'));\n }\n });\n });\n}\n"],"names":["installLib","calculateChecksum","filePath","callback","hash","crypto","createHash","stream","fs","createReadStream","on","data","update","oo","err","undefined","digest","version","dest","options","platform","libPath","path","join","installPath","getDistAsync","_err","dist","npmMajor","npm","Math","max","split","NPM_MIN_VERSION","getContent","NPM_DIST_TAGS_URL","res","distTags","JSON","parse","content","npmVersion","latest","downloadPath","NPM_DIST_URL","cachePath","tmpdir","basename","checksum","queue","Queue","defer","cb","conditionalCache","extract","await","_e","Error"],"mappings":";;;;+BA0BA;;;eAAwBA;;;6DA1BL;yDACJ;6BACY;uCACE;4DACd;2DACE;8DACC;wBACK;2BAC0C;yEACpC;gEACT;;;;;;AAMpB,SAASC,kBAAkBC,QAAgB,EAAEC,QAAyD;IACpG,IAAMC,OAAOC,eAAM,CAACC,UAAU,CAAC;IAC/B,IAAMC,SAASC,WAAE,CAACC,gBAAgB,CAACP;IACnCK,OAAOG,EAAE,CAAC,QAAQ,SAACC;eAASP,KAAKQ,MAAM,CAACD;;IACxCE,IAAAA,cAAE,EAACN,QAAQ;QAAC;QAAS;QAAO;QAAS;KAAS,EAAE,SAACO;QAC/C,IAAIA,KAAK,OAAOX,SAASW;QACzBX,SAASY,WAAWX,KAAKY,MAAM,CAAC;IAClC;AACF;AAEe,SAAShB,WAAWiB,OAAe,EAAEC,IAAY,EAAEC,OAAuB,EAAEhB,QAAkB;IAC3G,IAAMiB,WAAWD,QAAQC,QAAQ;IACjC,IAAMC,UAAUD,aAAa,UAAUF,OAAOI,aAAI,CAACC,IAAI,CAAC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,SAACV;+BAAQsC,GAAGtC;;;gBAChEmC,MAAMM,KAAK,CAAC,SAACzC;oBACXA,MAAMX,SAASW,OAAOX,SAASY,WAAW0B,YAAYO;gBACxD;YACF,EAAE,OAAOQ,IAAI;gBACX,OAAOrD,SAAS,IAAIsD,MAAM;YAC5B;QACF;IACF;AACF"}
@@ -103,14 +103,12 @@ function install(versionExpression, options, callback) {
103
103
  queue.defer(function(cb) {
104
104
  (0, _checkMissingts.default)(tempPath, options, function(err, npmMissing) {
105
105
  if (err) return cb(err);
106
- if (!~(npmMissing || []).indexOf('npm')) {
107
- // npm is present (bundled with node) - check if it's modern enough to keep
108
- var dist = (0, _nodefilenametodistpaths.getDist)(version);
109
- var bundledNpmMajor = dist && dist.npm ? +dist.npm.split('.')[0] : 0;
110
- if (bundledNpmMajor >= 3) {
111
- cb(); // npm >= 3 bundled, skip download
112
- return;
113
- }
106
+ // npm not bundled with node - download it
107
+ if (~(npmMissing || []).indexOf('npm')) return (0, _indexts1.default)(version, tempPath, options, cb);
108
+ // npm is present (bundled with node) - keep it unless the dist index positively says it is ancient (<3)
109
+ (0, _nodefilenametodistpaths.getDistAsync)(version, function(_err, dist) {
110
+ var bundledNpmIsAncient = dist && dist.npm && +dist.npm.split('.')[0] < 3;
111
+ if (!bundledNpmIsAncient) return cb(); // unknown version keeps the bundled npm
114
112
  // old npm (<3) is buggy - delete it so installNPM can override
115
113
  var platform = options.platform;
116
114
  var libPath = platform === 'win32' ? tempPath : _path.default.join(tempPath, 'lib');
@@ -118,9 +116,7 @@ function install(versionExpression, options, callback) {
118
116
  (0, _fsremovecompat.safeRm)(npmPath, function() {
119
117
  return (0, _indexts1.default)(version, tempPath, options, cb);
120
118
  });
121
- return;
122
- }
123
- (0, _indexts1.default)(version, tempPath, options, cb);
119
+ });
124
120
  });
125
121
  });
126
122
  // Atomic rename: move temp folder to final destination
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-install-release/src/workers/install.ts"],"sourcesContent":["import fs from 'fs';\nimport { safeRm } from 'fs-remove-compat';\nimport isVersion from 'is-version';\nimport mkdirp from 'mkdirp-classic';\nimport { getDist } from 'node-filename-to-dist-paths';\nimport resolveVersions from 'node-resolve-versions';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport tempSuffix from 'temp-suffix';\n\nimport { DEFAULT_STORAGE_PATHS } from '../constants.ts';\n\nimport createResult from '../createResult.ts';\nimport createStoragePaths from '../createStoragePaths.ts';\nimport installNode from '../installNode/index.ts';\n\nimport installNPM from '../installNPM/index.ts';\nimport checkMissing from '../lib/checkMissing.ts';\nimport ensureDestinationParent from '../lib/ensureDestinationParent.ts';\nimport getTarget from '../lib/getTarget.ts';\n\nimport type { InstallCallback, InstallOptions } from '../types.ts';\n\ntype GetVersionsCallback = (error?: Error | null, results?: string[]) => void;\nfunction getVersions(versionExpression: string, options: InstallOptions, callback: GetVersionsCallback) {\n // short circuit\n if (isVersion(versionExpression)) callback(undefined, [versionExpression]);\n else resolveVersions(versionExpression, options, (err?: Error | null, result?: string[] | unknown[]) => callback(err, result as string[] | undefined));\n}\n\nexport default function install(versionExpression: string, options: InstallOptions, callback: InstallCallback): void {\n const storagePaths = options.storagePath ? createStoragePaths(options.storagePath) : DEFAULT_STORAGE_PATHS;\n options = { ...storagePaths, ...options, ...getTarget(options) };\n getVersions(versionExpression, options, (err?: Error | null, versions?: string[]): void => {\n if (err) return callback(err);\n if (!versions || !versions.length) {\n callback(new Error(`Could not resolve versions for: ${versionExpression}`));\n return;\n }\n if (versions.length !== 1) {\n callback(new Error(`Version ${versionExpression} resolved to multiple versions: ${versions.map((x) => x)}. Expecting one.`));\n return;\n }\n\n const version = versions[0];\n const result = createResult(options, version);\n\n // Fast path: with atomic installs, folder exists = complete installation\n fs.stat(result.installPath, (err) => {\n if (!err) return callback(undefined, result);\n\n // Folder doesn't exist - do atomic install with temp folder\n const tempPath = tempSuffix(result.installPath);\n\n const queue = new Queue(1);\n queue.defer((cb) => mkdirp(options.cachePath!, (err) => cb(err)));\n queue.defer(ensureDestinationParent.bind(null, tempPath));\n\n // Install node to temp folder\n queue.defer(installNode.bind(null, version, tempPath, options));\n\n // Check and install npm to temp folder\n // Skip npm download only if bundled npm is modern (>= 3)\n queue.defer((cb) => {\n checkMissing(tempPath, options, (err, npmMissing): void => {\n if (err) return cb(err);\n if (!~(npmMissing || []).indexOf('npm')) {\n // npm is present (bundled with node) - check if it's modern enough to keep\n const dist = getDist(version);\n const bundledNpmMajor = dist && dist.npm ? +dist.npm.split('.')[0] : 0;\n if (bundledNpmMajor >= 3) {\n cb(); // npm >= 3 bundled, skip download\n return;\n }\n // old npm (<3) is buggy - delete it so installNPM can override\n const platform = options.platform;\n const libPath = platform === 'win32' ? tempPath : path.join(tempPath, 'lib');\n const npmPath = path.join(libPath, 'node_modules', 'npm');\n safeRm(npmPath, () => installNPM(version, tempPath, options, cb));\n return;\n }\n installNPM(version, tempPath, options, cb);\n });\n });\n\n // Atomic rename: move temp folder to final destination\n queue.defer((cb) => {\n fs.rename(tempPath, result.installPath, (err) => {\n if (!err) return cb();\n // Race condition: another process may have already created dest\n if (err.code === 'EEXIST' || err.code === 'ENOTEMPTY' || err.code === 'EPERM') {\n // Another process won the race - clean up temp and succeed\n safeRm(tempPath, () => cb());\n return;\n }\n cb(err);\n });\n });\n\n queue.await((err) => {\n // Clean up temp folder on error\n if (err) return safeRm(tempPath, () => callback(err));\n\n callback(undefined, result);\n });\n });\n });\n}\n"],"names":["install","getVersions","versionExpression","options","callback","isVersion","undefined","resolveVersions","err","result","storagePaths","storagePath","createStoragePaths","DEFAULT_STORAGE_PATHS","getTarget","versions","length","Error","map","x","version","createResult","fs","stat","installPath","tempPath","tempSuffix","queue","Queue","defer","cb","mkdirp","cachePath","ensureDestinationParent","bind","installNode","checkMissing","npmMissing","indexOf","dist","getDist","bundledNpmMajor","npm","split","platform","libPath","path","join","npmPath","safeRm","installNPM","rename","code","await"],"mappings":";;;;+BA8BA;;;eAAwBA;;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AAW,EAAE,SAAChB;oBACvC,IAAI,CAACA,KAAK,OAAOsB;oBACjB,gEAAgE;oBAChE,IAAItB,IAAI4C,IAAI,KAAK,YAAY5C,IAAI4C,IAAI,KAAK,eAAe5C,IAAI4C,IAAI,KAAK,SAAS;wBAC7E,2DAA2D;wBAC3DH,IAAAA,sBAAM,EAACxB,UAAU;mCAAMK;;wBACvB;oBACF;oBACAA,GAAGtB;gBACL;YACF;YAEAmB,MAAM0B,KAAK,CAAC,SAAC7C;gBACX,gCAAgC;gBAChC,IAAIA,KAAK,OAAOyC,IAAAA,sBAAM,EAACxB,UAAU;2BAAMrB,SAASI;;gBAEhDJ,SAASE,WAAWG;YACtB;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-install-release/src/workers/install.ts"],"sourcesContent":["import fs from 'fs';\nimport { safeRm } from 'fs-remove-compat';\nimport isVersion from 'is-version';\nimport mkdirp from 'mkdirp-classic';\nimport { getDistAsync } from 'node-filename-to-dist-paths';\nimport resolveVersions from 'node-resolve-versions';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport tempSuffix from 'temp-suffix';\n\nimport { DEFAULT_STORAGE_PATHS } from '../constants.ts';\n\nimport createResult from '../createResult.ts';\nimport createStoragePaths from '../createStoragePaths.ts';\nimport installNode from '../installNode/index.ts';\n\nimport installNPM from '../installNPM/index.ts';\nimport checkMissing from '../lib/checkMissing.ts';\nimport ensureDestinationParent from '../lib/ensureDestinationParent.ts';\nimport getTarget from '../lib/getTarget.ts';\n\nimport type { InstallCallback, InstallOptions } from '../types.ts';\n\ntype GetVersionsCallback = (error?: Error | null, results?: string[]) => void;\nfunction getVersions(versionExpression: string, options: InstallOptions, callback: GetVersionsCallback) {\n // short circuit\n if (isVersion(versionExpression)) callback(undefined, [versionExpression]);\n else resolveVersions(versionExpression, options, (err?: Error | null, result?: string[] | unknown[]) => callback(err, result as string[] | undefined));\n}\n\nexport default function install(versionExpression: string, options: InstallOptions, callback: InstallCallback): void {\n const storagePaths = options.storagePath ? createStoragePaths(options.storagePath) : DEFAULT_STORAGE_PATHS;\n options = { ...storagePaths, ...options, ...getTarget(options) };\n getVersions(versionExpression, options, (err?: Error | null, versions?: string[]): void => {\n if (err) return callback(err);\n if (!versions || !versions.length) {\n callback(new Error(`Could not resolve versions for: ${versionExpression}`));\n return;\n }\n if (versions.length !== 1) {\n callback(new Error(`Version ${versionExpression} resolved to multiple versions: ${versions.map((x) => x)}. Expecting one.`));\n return;\n }\n\n const version = versions[0];\n const result = createResult(options, version);\n\n // Fast path: with atomic installs, folder exists = complete installation\n fs.stat(result.installPath, (err) => {\n if (!err) return callback(undefined, result);\n\n // Folder doesn't exist - do atomic install with temp folder\n const tempPath = tempSuffix(result.installPath);\n\n const queue = new Queue(1);\n queue.defer((cb) => mkdirp(options.cachePath!, (err) => cb(err)));\n queue.defer(ensureDestinationParent.bind(null, tempPath));\n\n // Install node to temp folder\n queue.defer(installNode.bind(null, version, tempPath, options));\n\n // Check and install npm to temp folder\n // Skip npm download only if bundled npm is modern (>= 3)\n queue.defer((cb) => {\n checkMissing(tempPath, options, (err, npmMissing): void => {\n if (err) return cb(err);\n // npm not bundled with node - download it\n if (~(npmMissing || []).indexOf('npm')) return installNPM(version, tempPath, options, cb);\n\n // npm is present (bundled with node) - keep it unless the dist index positively says it is ancient (<3)\n getDistAsync(version, (_err, dist) => {\n const bundledNpmIsAncient = dist && dist.npm && +dist.npm.split('.')[0] < 3;\n if (!bundledNpmIsAncient) return cb(); // unknown version keeps the bundled npm\n\n // old npm (<3) is buggy - delete it so installNPM can override\n const platform = options.platform;\n const libPath = platform === 'win32' ? tempPath : path.join(tempPath, 'lib');\n const npmPath = path.join(libPath, 'node_modules', 'npm');\n safeRm(npmPath, () => installNPM(version, tempPath, options, cb));\n });\n });\n });\n\n // Atomic rename: move temp folder to final destination\n queue.defer((cb) => {\n fs.rename(tempPath, result.installPath, (err) => {\n if (!err) return cb();\n // Race condition: another process may have already created dest\n if (err.code === 'EEXIST' || err.code === 'ENOTEMPTY' || err.code === 'EPERM') {\n // Another process won the race - clean up temp and succeed\n safeRm(tempPath, () => cb());\n return;\n }\n cb(err);\n });\n });\n\n queue.await((err) => {\n // Clean up temp folder on error\n if (err) return safeRm(tempPath, () => callback(err));\n\n callback(undefined, result);\n });\n });\n });\n}\n"],"names":["install","getVersions","versionExpression","options","callback","isVersion","undefined","resolveVersions","err","result","storagePaths","storagePath","createStoragePaths","DEFAULT_STORAGE_PATHS","getTarget","versions","length","Error","map","x","version","createResult","fs","stat","installPath","tempPath","tempSuffix","queue","Queue","defer","cb","mkdirp","cachePath","ensureDestinationParent","bind","installNode","checkMissing","npmMissing","indexOf","installNPM","getDistAsync","_err","dist","bundledNpmIsAncient","npm","split","platform","libPath","path","join","npmPath","safeRm","rename","code","await"],"mappings":";;;;+BA8BA;;;eAAwBA;;;yDA9BT;8BACQ;gEACD;oEACH;uCACU;0EACD;2DACX;8DACC;iEACK;2BAEe;qEAEb;2EACM;8DACP;+DAED;qEACE;gFACW;kEACd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKtB,SAASC,YAAYC,iBAAyB,EAAEC,OAAuB,EAAEC,QAA6B;IACpG,gBAAgB;IAChB,IAAIC,IAAAA,kBAAS,EAACH,oBAAoBE,SAASE,WAAW;QAACJ;KAAkB;SACpEK,IAAAA,4BAAe,EAACL,mBAAmBC,SAAS,SAACK,KAAoBC;eAAkCL,SAASI,KAAKC;;AACxH;AAEe,SAAST,QAAQE,iBAAyB,EAAEC,OAAuB,EAAEC,QAAyB;IAC3G,IAAMM,eAAeP,QAAQQ,WAAW,GAAGC,IAAAA,6BAAkB,EAACT,QAAQQ,WAAW,IAAIE,kCAAqB;IAC1GV,UAAU,mBAAKO,cAAiBP,SAAYW,IAAAA,oBAAS,EAACX;IACtDF,YAAYC,mBAAmBC,SAAS,SAACK,KAAoBO;QAC3D,IAAIP,KAAK,OAAOJ,SAASI;QACzB,IAAI,CAACO,YAAY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AAQA,KAAKE,GAAG,IAAI,CAACF,KAAKE,GAAG,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG;wBAC1E,IAAI,CAACF,qBAAqB,OAAOb,MAAM,wCAAwC;wBAE/E,+DAA+D;wBAC/D,IAAMgB,WAAW3C,QAAQ2C,QAAQ;wBACjC,IAAMC,UAAUD,aAAa,UAAUrB,WAAWuB,aAAI,CAACC,IAAI,CAACxB,UAAU;wBACtE,IAAMyB,UAAUF,aAAI,CAACC,IAAI,CAACF,SAAS,gBAAgB;wBACnDI,IAAAA,sBAAM,EAACD,SAAS;mCAAMX,IAAAA,iBAAU,EAACnB,SAASK,UAAUtB,SAAS2B;;oBAC/D;gBACF;YACF;YAEA,uDAAuD;YACvDH,MAAME,KAAK,CAAC,SAACC;gBACXR,WAAE,CAAC8B,MAAM,CAAC3B,UAAUhB,OAAOe,WAAW,EAAE,SAAChB;oBACvC,IAAI,CAACA,KAAK,OAAOsB;oBACjB,gEAAgE;oBAChE,IAAItB,IAAI6C,IAAI,KAAK,YAAY7C,IAAI6C,IAAI,KAAK,eAAe7C,IAAI6C,IAAI,KAAK,SAAS;wBAC7E,2DAA2D;wBAC3DF,IAAAA,sBAAM,EAAC1B,UAAU;mCAAMK;;wBACvB;oBACF;oBACAA,GAAGtB;gBACL;YACF;YAEAmB,MAAM2B,KAAK,CAAC,SAAC9C;gBACX,gCAAgC;gBAChC,IAAIA,KAAK,OAAO2C,IAAAA,sBAAM,EAAC1B,UAAU;2BAAMrB,SAASI;;gBAEhDJ,SAASE,WAAWG;YACtB;QACF;IACF;AACF"}
@@ -1,7 +1,7 @@
1
1
  import crypto from 'crypto';
2
2
  import fs from 'fs';
3
3
  import { getContent } from 'get-file-compat';
4
- import { getDist } from 'node-filename-to-dist-paths';
4
+ import { getDistAsync } from 'node-filename-to-dist-paths';
5
5
  import oo from 'on-one';
6
6
  import path from 'path';
7
7
  import Queue from 'queue-cb';
@@ -27,32 +27,33 @@ export default function installLib(version, dest, options, callback) {
27
27
  const platform = options.platform;
28
28
  const libPath = platform === 'win32' ? dest : path.join(dest, 'lib');
29
29
  const installPath = path.join(libPath, 'node_modules', 'npm');
30
- const dist = getDist(version);
31
- const npmMajorPair = dist && dist.npm ? +dist.npm.split('.')[0] : NPM_MIN_VERSION;
32
- const npmMajor = Math.max(npmMajorPair, NPM_MIN_VERSION);
33
- getContent(NPM_DIST_TAGS_URL, 'utf8', (err, res)=>{
34
- if (err) return callback(err);
35
- try {
36
- var _ref, _options_cachePath;
37
- const distTags = JSON.parse((_ref = res === null || res === void 0 ? void 0 : res.content) !== null && _ref !== void 0 ? _ref : '{}');
38
- const npmVersion = distTags[`latest-${npmMajor}`] || distTags[`next-${npmMajor}`] || distTags.latest;
39
- const downloadPath = `${NPM_DIST_URL}/-/npm-${npmVersion}.tgz`;
40
- const cachePath = path.join((_options_cachePath = options.cachePath) !== null && _options_cachePath !== void 0 ? _options_cachePath : tmpdir(), path.basename(downloadPath));
41
- let checksum;
42
- const queue = new Queue(1);
43
- queue.defer((cb)=>conditionalCache(downloadPath, cachePath, options, (err)=>cb(err)));
44
- queue.defer((cb)=>{
45
- calculateChecksum(cachePath, (err, hash)=>{
46
- checksum = hash;
47
- cb(err);
30
+ getDistAsync(version, (_err, dist)=>{
31
+ // pin the npm major only when the dist index knows this version; unknown means use latest
32
+ const npmMajor = dist && dist.npm ? Math.max(+dist.npm.split('.')[0], NPM_MIN_VERSION) : null;
33
+ getContent(NPM_DIST_TAGS_URL, 'utf8', (err, res)=>{
34
+ if (err) return callback(err);
35
+ try {
36
+ var _ref, _options_cachePath;
37
+ const distTags = JSON.parse((_ref = res === null || res === void 0 ? void 0 : res.content) !== null && _ref !== void 0 ? _ref : '{}');
38
+ const npmVersion = npmMajor === null ? distTags.latest : distTags[`latest-${npmMajor}`] || distTags[`next-${npmMajor}`] || distTags.latest;
39
+ const downloadPath = `${NPM_DIST_URL}/-/npm-${npmVersion}.tgz`;
40
+ const cachePath = path.join((_options_cachePath = options.cachePath) !== null && _options_cachePath !== void 0 ? _options_cachePath : tmpdir(), path.basename(downloadPath));
41
+ let checksum;
42
+ const queue = new Queue(1);
43
+ queue.defer((cb)=>conditionalCache(downloadPath, cachePath, options, (err)=>cb(err)));
44
+ queue.defer((cb)=>{
45
+ calculateChecksum(cachePath, (err, hash)=>{
46
+ checksum = hash;
47
+ cb(err);
48
+ });
49
+ });
50
+ queue.defer((cb)=>extract(cachePath, installPath, (err)=>cb(err)));
51
+ queue.await((err)=>{
52
+ err ? callback(err) : callback(undefined, npmVersion, checksum);
48
53
  });
49
- });
50
- queue.defer((cb)=>extract(cachePath, installPath, (err)=>cb(err)));
51
- queue.await((err)=>{
52
- err ? callback(err) : callback(undefined, npmVersion, checksum);
53
- });
54
- } catch (_e) {
55
- return callback(new Error('Failed to parse npm dist-tags'));
56
- }
54
+ } catch (_e) {
55
+ return callback(new Error('Failed to parse npm dist-tags'));
56
+ }
57
+ });
57
58
  });
58
59
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-install-release/src/installNPM/installLib.ts"],"sourcesContent":["import crypto from 'crypto';\nimport fs from 'fs';\nimport { getContent } from 'get-file-compat';\nimport { getDist } from 'node-filename-to-dist-paths';\nimport oo from 'on-one';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport { tmpdir } from '../compat.ts';\nimport { NPM_DIST_TAGS_URL, NPM_DIST_URL, NPM_MIN_VERSION } from '../constants.ts';\nimport conditionalCache from '../lib/conditionalCache.ts';\nimport extract from '../lib/extract.ts';\n\nimport type { InstallOptions } from '../types.ts';\n\nexport type Callback = (error?: Error | null, npmVersion?: string, checksum?: string) => void;\n\nfunction calculateChecksum(filePath: string, callback: (err?: Error | null, checksum?: string) => void): void {\n const hash = crypto.createHash('sha256');\n const stream = fs.createReadStream(filePath);\n stream.on('data', (data) => hash.update(data));\n oo(stream, ['error', 'end', 'close', 'finish'], (err: Error | null) => {\n if (err) return callback(err);\n callback(undefined, hash.digest('hex'));\n });\n}\n\nexport default function installLib(version: string, dest: string, options: InstallOptions, callback: Callback): void {\n const platform = options.platform;\n const libPath = platform === 'win32' ? dest : path.join(dest, 'lib');\n const installPath = path.join(libPath, 'node_modules', 'npm');\n\n const dist = getDist(version);\n const npmMajorPair = dist && dist.npm ? +dist.npm.split('.')[0] : NPM_MIN_VERSION;\n const npmMajor = Math.max(npmMajorPair, NPM_MIN_VERSION);\n\n getContent(NPM_DIST_TAGS_URL, 'utf8', (err, res) => {\n if (err) return callback(err);\n try {\n const distTags = JSON.parse(res?.content ?? '{}') as Record<string, string>;\n const npmVersion = distTags[`latest-${npmMajor}`] || distTags[`next-${npmMajor}`] || distTags.latest;\n const downloadPath = `${NPM_DIST_URL}/-/npm-${npmVersion}.tgz`;\n const cachePath = path.join(options.cachePath ?? tmpdir(), path.basename(downloadPath));\n\n let checksum: string | undefined;\n const queue = new Queue(1);\n queue.defer((cb) => conditionalCache(downloadPath, cachePath, options, (err) => cb(err)));\n queue.defer((cb) => {\n calculateChecksum(cachePath, (err, hash) => {\n checksum = hash;\n cb(err);\n });\n });\n queue.defer((cb) => extract(cachePath, installPath, (err) => cb(err)));\n queue.await((err) => {\n err ? callback(err) : callback(undefined, npmVersion, checksum);\n });\n } catch (_e) {\n return callback(new Error('Failed to parse npm dist-tags'));\n }\n });\n}\n"],"names":["crypto","fs","getContent","getDist","oo","path","Queue","tmpdir","NPM_DIST_TAGS_URL","NPM_DIST_URL","NPM_MIN_VERSION","conditionalCache","extract","calculateChecksum","filePath","callback","hash","createHash","stream","createReadStream","on","data","update","err","undefined","digest","installLib","version","dest","options","platform","libPath","join","installPath","dist","npmMajorPair","npm","split","npmMajor","Math","max","res","distTags","JSON","parse","content","npmVersion","latest","downloadPath","cachePath","basename","checksum","queue","defer","cb","await","_e","Error"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,OAAOC,QAAQ,KAAK;AACpB,SAASC,UAAU,QAAQ,kBAAkB;AAC7C,SAASC,OAAO,QAA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C,CAAC,OAAO,EAAEJ,UAAU,CAAC,IAAII,QAAQ,CAAC,CAAC,KAAK,EAAEJ,UAAU,CAAC,IAAII,SAASK,MAAM;YACpG,MAAMC,eAAe,GAAGvC,aAAa,OAAO,EAAEqC,WAAW,IAAI,CAAC;YAC9D,MAAMG,YAAY5C,KAAK2B,IAAI,EAACH,qBAAAA,QAAQoB,SAAS,cAAjBpB,gCAAAA,qBAAqBtB,UAAUF,KAAK6C,QAAQ,CAACF;YAEzE,IAAIG;YACJ,MAAMC,QAAQ,IAAI9C,MAAM;YACxB8C,MAAMC,KAAK,CAAC,CAACC,KAAO3C,iBAAiBqC,cAAcC,WAAWpB,SAAS,CAACN,MAAQ+B,GAAG/B;YACnF6B,MAAMC,KAAK,CAAC,CAACC;gBACXzC,kBAAkBoC,WAAW,CAAC1B,KAAKP;oBACjCmC,WAAWnC;oBACXsC,GAAG/B;gBACL;YACF;YACA6B,MAAMC,KAAK,CAAC,CAACC,KAAO1C,QAAQqC,WAAWhB,aAAa,CAACV,MAAQ+B,GAAG/B;YAChE6B,MAAMG,KAAK,CAAC,CAAChC;gBACXA,MAAMR,SAASQ,OAAOR,SAASS,WAAWsB,YAAYK;YACxD;QACF,EAAE,OAAOK,IAAI;YACX,OAAOzC,SAAS,IAAI0C,MAAM;QAC5B;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-install-release/src/installNPM/installLib.ts"],"sourcesContent":["import crypto from 'crypto';\nimport fs from 'fs';\nimport { getContent } from 'get-file-compat';\nimport { getDistAsync } from 'node-filename-to-dist-paths';\nimport oo from 'on-one';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport { tmpdir } from '../compat.ts';\nimport { NPM_DIST_TAGS_URL, NPM_DIST_URL, NPM_MIN_VERSION } from '../constants.ts';\nimport conditionalCache from '../lib/conditionalCache.ts';\nimport extract from '../lib/extract.ts';\n\nimport type { InstallOptions } from '../types.ts';\n\nexport type Callback = (error?: Error | null, npmVersion?: string, checksum?: string) => void;\n\nfunction calculateChecksum(filePath: string, callback: (err?: Error | null, checksum?: string) => void): void {\n const hash = crypto.createHash('sha256');\n const stream = fs.createReadStream(filePath);\n stream.on('data', (data) => hash.update(data));\n oo(stream, ['error', 'end', 'close', 'finish'], (err: Error | null) => {\n if (err) return callback(err);\n callback(undefined, hash.digest('hex'));\n });\n}\n\nexport default function installLib(version: string, dest: string, options: InstallOptions, callback: Callback): void {\n const platform = options.platform;\n const libPath = platform === 'win32' ? dest : path.join(dest, 'lib');\n const installPath = path.join(libPath, 'node_modules', 'npm');\n\n getDistAsync(version, (_err, dist) => {\n // pin the npm major only when the dist index knows this version; unknown means use latest\n const npmMajor = dist && dist.npm ? Math.max(+dist.npm.split('.')[0], NPM_MIN_VERSION) : null;\n\n getContent(NPM_DIST_TAGS_URL, 'utf8', (err, res) => {\n if (err) return callback(err);\n try {\n const distTags = JSON.parse(res?.content ?? '{}') as Record<string, string>;\n const npmVersion = npmMajor === null ? distTags.latest : distTags[`latest-${npmMajor}`] || distTags[`next-${npmMajor}`] || distTags.latest;\n const downloadPath = `${NPM_DIST_URL}/-/npm-${npmVersion}.tgz`;\n const cachePath = path.join(options.cachePath ?? tmpdir(), path.basename(downloadPath));\n\n let checksum: string | undefined;\n const queue = new Queue(1);\n queue.defer((cb) => conditionalCache(downloadPath, cachePath, options, (err) => cb(err)));\n queue.defer((cb) => {\n calculateChecksum(cachePath, (err, hash) => {\n checksum = hash;\n cb(err);\n });\n });\n queue.defer((cb) => extract(cachePath, installPath, (err) => cb(err)));\n queue.await((err) => {\n err ? callback(err) : callback(undefined, npmVersion, checksum);\n });\n } catch (_e) {\n return callback(new Error('Failed to parse npm dist-tags'));\n }\n });\n });\n}\n"],"names":["crypto","fs","getContent","getDistAsync","oo","path","Queue","tmpdir","NPM_DIST_TAGS_URL","NPM_DIST_URL","NPM_MIN_VERSION","conditionalCache","extract","calculateChecksum","filePath","callback","hash","createHash","stream","createReadStream","on","data","update","err","undefined","digest","installLib","version","dest","options","platform","libPath","join","installPath","_err","dist","npmMajor","npm","Math","max","split","res","distTags","JSON","parse","content","npmVersion","latest","downloadPath","cachePath","basename","checksum","queue","defer","cb","await","_e","Error"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,OAAOC,QAAQ,KAAK;AACpB,SAASC,UAAU,QAAQ,kBAAkB;AAC7C,SAASC,YAAY,QAAQ,8BAA8B;AAC3D,OAAOC,QAAQ,SAAS;AACxB,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAC7B,SAASC,MAAM,QAAQ,eAAe;AACtC,SAASC,iBAAiB,EAAEC,YAAY,EAAEC,eAAe,QAAQ,kBAAkB;AACnF,OAAOC,sBAAsB,6BAA6B;AAC1D,OAAOC,aAAa,oBAAoB;AAMxC,SAASC,kBAAkBC,QAAgB,EAAEC,QAAyD;IACpG,MAAMC,OAAOhB,OAAOiB,UAAU,CAAC;IAC/B,MAAMC,SAASjB,GAAGkB,gBAAgB,CAACL;IACnCI,OAAOE,EAAE,CAAC,QAAQ,CAACC,OAASL,KAAKM,MAAM,CAACD;IACxCjB,GAAGc,QAAQ;QAAC;QAAS;QAAO;QAAS;KAAS,EAAE,CAACK;QAC/C,IAAIA,KAAK,OAAOR,SAASQ;QACzBR,SAASS,WAAWR,KAAKS,MAAM,CAAC;IAClC;AACF;AAEA,eAAe,SAASC,WAAWC,OAAe,EAAEC,IAAY,EAAEC,OAAuB,EAAEd,QAAkB;IAC3G,MAAMe,WAAWD,QAAQC,QAAQ;IACjC,MAAMC,UAAUD,aAAa,UAAUF,OAAOvB,KAAK2B,IAAI,CAACJ,MAAM;IAC9D,MAAMK,cAAc5B,KAAK2B,IAAI,CAACD,SAAS,gBAAgB;IAEvD5B,aAAawB,SAAS,CAACO,MAAMC;QAC3B,0FAA0F;QAC1F,MAAMC,WAAWD,QAAQA,KAAKE,GAAG,GAAGC,KAAKC,GAAG,CAAC,CAACJ,KAAKE,GAAG,CAACG,KAAK,CAAC,IAA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
- import { getDist } from 'node-filename-to-dist-paths';
5
+ import { getDistAsync } from 'node-filename-to-dist-paths';
6
6
  import resolveVersions from 'node-resolve-versions';
7
7
  import path from 'path';
8
8
  import Queue from 'queue-cb';
@@ -56,22 +56,18 @@ export default function install(versionExpression, options, callback) {
56
56
  queue.defer((cb)=>{
57
57
  checkMissing(tempPath, options, (err, npmMissing)=>{
58
58
  if (err) return cb(err);
59
- if (!~(npmMissing || []).indexOf('npm')) {
60
- // npm is present (bundled with node) - check if it's modern enough to keep
61
- const dist = getDist(version);
62
- const bundledNpmMajor = dist && dist.npm ? +dist.npm.split('.')[0] : 0;
63
- if (bundledNpmMajor >= 3) {
64
- cb(); // npm >= 3 bundled, skip download
65
- return;
66
- }
59
+ // npm not bundled with node - download it
60
+ if (~(npmMissing || []).indexOf('npm')) return installNPM(version, tempPath, options, cb);
61
+ // npm is present (bundled with node) - keep it unless the dist index positively says it is ancient (<3)
62
+ getDistAsync(version, (_err, dist)=>{
63
+ const bundledNpmIsAncient = dist && dist.npm && +dist.npm.split('.')[0] < 3;
64
+ if (!bundledNpmIsAncient) return cb(); // unknown version keeps the bundled npm
67
65
  // old npm (<3) is buggy - delete it so installNPM can override
68
66
  const platform = options.platform;
69
67
  const libPath = platform === 'win32' ? tempPath : path.join(tempPath, 'lib');
70
68
  const npmPath = path.join(libPath, 'node_modules', 'npm');
71
69
  safeRm(npmPath, ()=>installNPM(version, tempPath, options, cb));
72
- return;
73
- }
74
- installNPM(version, tempPath, options, cb);
70
+ });
75
71
  });
76
72
  });
77
73
  // Atomic rename: move temp folder to final destination
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-install-release/src/workers/install.ts"],"sourcesContent":["import fs from 'fs';\nimport { safeRm } from 'fs-remove-compat';\nimport isVersion from 'is-version';\nimport mkdirp from 'mkdirp-classic';\nimport { getDist } from 'node-filename-to-dist-paths';\nimport resolveVersions from 'node-resolve-versions';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport tempSuffix from 'temp-suffix';\n\nimport { DEFAULT_STORAGE_PATHS } from '../constants.ts';\n\nimport createResult from '../createResult.ts';\nimport createStoragePaths from '../createStoragePaths.ts';\nimport installNode from '../installNode/index.ts';\n\nimport installNPM from '../installNPM/index.ts';\nimport checkMissing from '../lib/checkMissing.ts';\nimport ensureDestinationParent from '../lib/ensureDestinationParent.ts';\nimport getTarget from '../lib/getTarget.ts';\n\nimport type { InstallCallback, InstallOptions } from '../types.ts';\n\ntype GetVersionsCallback = (error?: Error | null, results?: string[]) => void;\nfunction getVersions(versionExpression: string, options: InstallOptions, callback: GetVersionsCallback) {\n // short circuit\n if (isVersion(versionExpression)) callback(undefined, [versionExpression]);\n else resolveVersions(versionExpression, options, (err?: Error | null, result?: string[] | unknown[]) => callback(err, result as string[] | undefined));\n}\n\nexport default function install(versionExpression: string, options: InstallOptions, callback: InstallCallback): void {\n const storagePaths = options.storagePath ? createStoragePaths(options.storagePath) : DEFAULT_STORAGE_PATHS;\n options = { ...storagePaths, ...options, ...getTarget(options) };\n getVersions(versionExpression, options, (err?: Error | null, versions?: string[]): void => {\n if (err) return callback(err);\n if (!versions || !versions.length) {\n callback(new Error(`Could not resolve versions for: ${versionExpression}`));\n return;\n }\n if (versions.length !== 1) {\n callback(new Error(`Version ${versionExpression} resolved to multiple versions: ${versions.map((x) => x)}. Expecting one.`));\n return;\n }\n\n const version = versions[0];\n const result = createResult(options, version);\n\n // Fast path: with atomic installs, folder exists = complete installation\n fs.stat(result.installPath, (err) => {\n if (!err) return callback(undefined, result);\n\n // Folder doesn't exist - do atomic install with temp folder\n const tempPath = tempSuffix(result.installPath);\n\n const queue = new Queue(1);\n queue.defer((cb) => mkdirp(options.cachePath!, (err) => cb(err)));\n queue.defer(ensureDestinationParent.bind(null, tempPath));\n\n // Install node to temp folder\n queue.defer(installNode.bind(null, version, tempPath, options));\n\n // Check and install npm to temp folder\n // Skip npm download only if bundled npm is modern (>= 3)\n queue.defer((cb) => {\n checkMissing(tempPath, options, (err, npmMissing): void => {\n if (err) return cb(err);\n if (!~(npmMissing || []).indexOf('npm')) {\n // npm is present (bundled with node) - check if it's modern enough to keep\n const dist = getDist(version);\n const bundledNpmMajor = dist && dist.npm ? +dist.npm.split('.')[0] : 0;\n if (bundledNpmMajor >= 3) {\n cb(); // npm >= 3 bundled, skip download\n return;\n }\n // old npm (<3) is buggy - delete it so installNPM can override\n const platform = options.platform;\n const libPath = platform === 'win32' ? tempPath : path.join(tempPath, 'lib');\n const npmPath = path.join(libPath, 'node_modules', 'npm');\n safeRm(npmPath, () => installNPM(version, tempPath, options, cb));\n return;\n }\n installNPM(version, tempPath, options, cb);\n });\n });\n\n // Atomic rename: move temp folder to final destination\n queue.defer((cb) => {\n fs.rename(tempPath, result.installPath, (err) => {\n if (!err) return cb();\n // Race condition: another process may have already created dest\n if (err.code === 'EEXIST' || err.code === 'ENOTEMPTY' || err.code === 'EPERM') {\n // Another process won the race - clean up temp and succeed\n safeRm(tempPath, () => cb());\n return;\n }\n cb(err);\n });\n });\n\n queue.await((err) => {\n // Clean up temp folder on error\n if (err) return safeRm(tempPath, () => callback(err));\n\n callback(undefined, result);\n });\n });\n });\n}\n"],"names":["fs","safeRm","isVersion","mkdirp","getDist","resolveVersions","path","Queue","tempSuffix","DEFAULT_STORAGE_PATHS","createResult","createStoragePaths","installNode","installNPM","checkMissing","ensureDestinationParent","getTarget","getVersions","versionExpression","options","callback","undefined","err","result","install","storagePaths","storagePath","versions","length","Error","map","x","version","stat","installPath","tempPath","queue","defer","cb","cachePath","bind","npmMissing","indexOf","dist","bundledNpmMajor","npm","split","platform","libPath","join","npmPath","rename","code","await"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,eAAe,aAAa;AACnC,OAAOC,YAAY,iBAAiB;AACpC,SAASC,OAAO,QAAQ,8BAA8B;AACtD,OAAOC,qBAAqB,wBAAwB;AACpD,OAAOC,UAAU,OA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UAAUZ,OAAOW,WAAW,EAAE,CAACZ;oBACvC,IAAI,CAACA,KAAK,OAAOgB;oBACjB,gEAAgE;oBAChE,IAAIhB,IAAI8B,IAAI,KAAK,YAAY9B,IAAI8B,IAAI,KAAK,eAAe9B,IAAI8B,IAAI,KAAK,SAAS;wBAC7E,2DAA2D;wBAC3DnD,OAAOkC,UAAU,IAAMG;wBACvB;oBACF;oBACAA,GAAGhB;gBACL;YACF;YAEAc,MAAMiB,KAAK,CAAC,CAAC/B;gBACX,gCAAgC;gBAChC,IAAIA,KAAK,OAAOrB,OAAOkC,UAAU,IAAMf,SAASE;gBAEhDF,SAASC,WAAWE;YACtB;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node-version/node-install-release/src/workers/install.ts"],"sourcesContent":["import fs from 'fs';\nimport { safeRm } from 'fs-remove-compat';\nimport isVersion from 'is-version';\nimport mkdirp from 'mkdirp-classic';\nimport { getDistAsync } from 'node-filename-to-dist-paths';\nimport resolveVersions from 'node-resolve-versions';\nimport path from 'path';\nimport Queue from 'queue-cb';\nimport tempSuffix from 'temp-suffix';\n\nimport { DEFAULT_STORAGE_PATHS } from '../constants.ts';\n\nimport createResult from '../createResult.ts';\nimport createStoragePaths from '../createStoragePaths.ts';\nimport installNode from '../installNode/index.ts';\n\nimport installNPM from '../installNPM/index.ts';\nimport checkMissing from '../lib/checkMissing.ts';\nimport ensureDestinationParent from '../lib/ensureDestinationParent.ts';\nimport getTarget from '../lib/getTarget.ts';\n\nimport type { InstallCallback, InstallOptions } from '../types.ts';\n\ntype GetVersionsCallback = (error?: Error | null, results?: string[]) => void;\nfunction getVersions(versionExpression: string, options: InstallOptions, callback: GetVersionsCallback) {\n // short circuit\n if (isVersion(versionExpression)) callback(undefined, [versionExpression]);\n else resolveVersions(versionExpression, options, (err?: Error | null, result?: string[] | unknown[]) => callback(err, result as string[] | undefined));\n}\n\nexport default function install(versionExpression: string, options: InstallOptions, callback: InstallCallback): void {\n const storagePaths = options.storagePath ? createStoragePaths(options.storagePath) : DEFAULT_STORAGE_PATHS;\n options = { ...storagePaths, ...options, ...getTarget(options) };\n getVersions(versionExpression, options, (err?: Error | null, versions?: string[]): void => {\n if (err) return callback(err);\n if (!versions || !versions.length) {\n callback(new Error(`Could not resolve versions for: ${versionExpression}`));\n return;\n }\n if (versions.length !== 1) {\n callback(new Error(`Version ${versionExpression} resolved to multiple versions: ${versions.map((x) => x)}. Expecting one.`));\n return;\n }\n\n const version = versions[0];\n const result = createResult(options, version);\n\n // Fast path: with atomic installs, folder exists = complete installation\n fs.stat(result.installPath, (err) => {\n if (!err) return callback(undefined, result);\n\n // Folder doesn't exist - do atomic install with temp folder\n const tempPath = tempSuffix(result.installPath);\n\n const queue = new Queue(1);\n queue.defer((cb) => mkdirp(options.cachePath!, (err) => cb(err)));\n queue.defer(ensureDestinationParent.bind(null, tempPath));\n\n // Install node to temp folder\n queue.defer(installNode.bind(null, version, tempPath, options));\n\n // Check and install npm to temp folder\n // Skip npm download only if bundled npm is modern (>= 3)\n queue.defer((cb) => {\n checkMissing(tempPath, options, (err, npmMissing): void => {\n if (err) return cb(err);\n // npm not bundled with node - download it\n if (~(npmMissing || []).indexOf('npm')) return installNPM(version, tempPath, options, cb);\n\n // npm is present (bundled with node) - keep it unless the dist index positively says it is ancient (<3)\n getDistAsync(version, (_err, dist) => {\n const bundledNpmIsAncient = dist && dist.npm && +dist.npm.split('.')[0] < 3;\n if (!bundledNpmIsAncient) return cb(); // unknown version keeps the bundled npm\n\n // old npm (<3) is buggy - delete it so installNPM can override\n const platform = options.platform;\n const libPath = platform === 'win32' ? tempPath : path.join(tempPath, 'lib');\n const npmPath = path.join(libPath, 'node_modules', 'npm');\n safeRm(npmPath, () => installNPM(version, tempPath, options, cb));\n });\n });\n });\n\n // Atomic rename: move temp folder to final destination\n queue.defer((cb) => {\n fs.rename(tempPath, result.installPath, (err) => {\n if (!err) return cb();\n // Race condition: another process may have already created dest\n if (err.code === 'EEXIST' || err.code === 'ENOTEMPTY' || err.code === 'EPERM') {\n // Another process won the race - clean up temp and succeed\n safeRm(tempPath, () => cb());\n return;\n }\n cb(err);\n });\n });\n\n queue.await((err) => {\n // Clean up temp folder on error\n if (err) return safeRm(tempPath, () => callback(err));\n\n callback(undefined, result);\n });\n });\n });\n}\n"],"names":["fs","safeRm","isVersion","mkdirp","getDistAsync","resolveVersions","path","Queue","tempSuffix","DEFAULT_STORAGE_PATHS","createResult","createStoragePaths","installNode","installNPM","checkMissing","ensureDestinationParent","getTarget","getVersions","versionExpression","options","callback","undefined","err","result","install","storagePaths","storagePath","versions","length","Error","map","x","version","stat","installPath","tempPath","queue","defer","cb","cachePath","bind","npmMissing","indexOf","_err","dist","bundledNpmIsAncient","npm","split","platform","libPath","join","npmPath","rename","code","await"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,OAAOC,eAAe,aAAa;AACnC,OAAOC,YAAY,iBAAiB;AACpC,SAASC,YAAY,QAAQ,8BAA8B;AAC3D,OAAOC,qBAAqB,wBAAwB;AACpD,OAAOC,UAAU,OAAO;AACxB,OAAOC,WAAW,WAAW;AAC7B,OAAOC,gBAAgB,cAAc;AAErC,SAASC,qBAAqB,QAAQ,kBAAkB;AAExD,OAAOC,kBAAkB,qBAAqB;AAC9C,OAAOC,wBAAwB,2BAA2B;AAC1D,OAAOC,iBAAiB,0BAA0B;AAElD,OAAOC,gBAAgB,yBAAyB;AAChD,OAAOC,kBAAkB,yBAAyB;AAClD,OAAOC,6BAA6B,oCAAoC;AACxE,OAAOC,eAAe,sBAAsB;AAK5C,SAASC,YAAYC,iBAAyB,EAAEC,OAAuB,EAAEC,QAA6B;IACpG,gBAAgB;IAChB,IAAIlB,UAAUgB,oBAAoBE,SAASC,WAAW;QAACH;KAAkB;SACpEb,gBAAgBa,mBAAmBC,SAAS,CAACG,KAAoBC,SAAkCH,SAASE,KAAKC;AACxH;AAEA,eAAe,SAASC,QA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hB;oBACnB,0CAA0C;oBAC1C,IAAI,CAAC,AAACmB,CAAAA,cAAc,EAAE,AAAD,EAAGC,OAAO,CAAC,QAAQ,OAAO7B,WAAWmB,SAASG,UAAUhB,SAASmB;oBAEtF,wGAAwG;oBACxGlC,aAAa4B,SAAS,CAACW,MAAMC;wBAC3B,MAAMC,sBAAsBD,QAAQA,KAAKE,GAAG,IAAI,CAACF,KAAKE,GAAG,CAACC,KAAK,CAAC,IAAI,CAAC,EAAE,GAAG;wBAC1E,IAAI,CAACF,qBAAqB,OAAOP,MAAM,wCAAwC;wBAE/E,+DAA+D;wBAC/D,MAAMU,WAAW7B,QAAQ6B,QAAQ;wBACjC,MAAMC,UAAUD,aAAa,UAAUb,WAAW7B,KAAK4C,IAAI,CAACf,UAAU;wBACtE,MAAMgB,UAAU7C,KAAK4C,IAAI,CAACD,SAAS,gBAAgB;wBACnDhD,OAAOkD,SAAS,IAAMtC,WAAWmB,SAASG,UAAUhB,SAASmB;oBAC/D;gBACF;YACF;YAEA,uDAAuD;YACvDF,MAAMC,KAAK,CAAC,CAACC;gBACXtC,GAAGoD,MAAM,CAACjB,UAAUZ,OAAOW,WAAW,EAAE,CAACZ;oBACvC,IAAI,CAACA,KAAK,OAAOgB;oBACjB,gEAAgE;oBAChE,IAAIhB,IAAI+B,IAAI,KAAK,YAAY/B,IAAI+B,IAAI,KAAK,eAAe/B,IAAI+B,IAAI,KAAK,SAAS;wBAC7E,2DAA2D;wBAC3DpD,OAAOkC,UAAU,IAAMG;wBACvB;oBACF;oBACAA,GAAGhB;gBACL;YACF;YAEAc,MAAMkB,KAAK,CAAC,CAAChC;gBACX,gCAAgC;gBAChC,IAAIA,KAAK,OAAOrB,OAAOkC,UAAU,IAAMf,SAASE;gBAEhDF,SAASC,WAAWE;YACtB;QACF;IACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-install-release",
3
- "version": "1.18.6",
3
+ "version": "1.19.0",
4
4
  "description": "Cross-platform solution for installing releases of Node.js",
5
5
  "keywords": [
6
6
  "node",
@@ -55,7 +55,7 @@
55
55
  "is-version": "^1.0.9",
56
56
  "lodash.keys": "^4.2.0",
57
57
  "mkdirp-classic": "^0.5.2",
58
- "node-filename-to-dist-paths": "^1.3.15",
58
+ "node-filename-to-dist-paths": "^1.5.0",
59
59
  "node-resolve-versions": "^1.3.13",
60
60
  "on-one": "^1.0.0",
61
61
  "os-shim": "^0.1.3",