"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/node-gyp/lib/process-release.js" (8 Mar 2017, 6051 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 var semver = require('semver')
    2   , url = require('url')
    3   , path = require('path')
    4   , log = require('npmlog')
    5 
    6     // versions where -headers.tar.gz started shipping
    7   , headersTarballRange = '>= 3.0.0 || ~0.12.10 || ~0.10.42'
    8   , bitsre = /\/win-(x86|x64)\//
    9   , bitsreV3 = /\/win-(x86|ia32|x64)\// // io.js v3.x.x shipped with "ia32" but should
   10                                         // have been "x86"
   11 
   12 // Captures all the logic required to determine download URLs, local directory and 
   13 // file names. Inputs come from command-line switches (--target, --dist-url),
   14 // `process.version` and `process.release` where it exists.
   15 function processRelease (argv, gyp, defaultVersion, defaultRelease) {
   16   var version = (semver.valid(argv[0]) && argv[0]) || gyp.opts.target || defaultVersion
   17     , versionSemver = semver.parse(version)
   18     , overrideDistUrl = gyp.opts['dist-url'] || gyp.opts.disturl
   19     , isDefaultVersion
   20     , isIojs
   21     , name
   22     , distBaseUrl
   23     , baseUrl
   24     , libUrl32
   25     , libUrl64
   26     , tarballUrl
   27     , canGetHeaders
   28 
   29   if (!versionSemver) {
   30     // not a valid semver string, nothing we can do
   31     return { version: version }
   32   }
   33   // flatten version into String
   34   version = versionSemver.version
   35 
   36   // defaultVersion should come from process.version so ought to be valid semver
   37   isDefaultVersion = version === semver.parse(defaultVersion).version
   38 
   39   // can't use process.release if we're using --target=x.y.z
   40   if (!isDefaultVersion)
   41     defaultRelease = null
   42 
   43   if (defaultRelease) {
   44     // v3 onward, has process.release
   45     name = defaultRelease.name.replace(/io\.js/, 'iojs') // remove the '.' for directory naming purposes
   46     isIojs = name === 'iojs'
   47   } else {
   48     // old node or alternative --target=
   49     // semver.satisfies() doesn't like prerelease tags so test major directly
   50     isIojs = versionSemver.major >= 1 && versionSemver.major < 4
   51     name = isIojs ? 'iojs' : 'node'
   52   }
   53 
   54   // check for the nvm.sh standard mirror env variables
   55   if (!overrideDistUrl) {
   56     if (isIojs) {
   57       if (process.env.IOJS_ORG_MIRROR) {
   58         overrideDistUrl = process.env.IOJS_ORG_MIRROR
   59       } else if (process.env.NVM_IOJS_ORG_MIRROR) {// remove on next semver-major
   60         overrideDistUrl = process.env.NVM_IOJS_ORG_MIRROR
   61         log.warn('download',
   62             'NVM_IOJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, ' +
   63             'please use IOJS_ORG_MIRROR')
   64       }
   65     } else {
   66       if (process.env.NODEJS_ORG_MIRROR) {
   67         overrideDistUrl = process.env.NODEJS_ORG_MIRROR
   68       } else if (process.env.NVM_NODEJS_ORG_MIRROR) {// remove on next semver-major
   69         overrideDistUrl = process.env.NVM_NODEJS_ORG_MIRROR
   70         log.warn('download',
   71             'NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, ' +
   72             'please use NODEJS_ORG_MIRROR')
   73       }
   74     }
   75   }
   76 
   77 
   78   if (overrideDistUrl)
   79     distBaseUrl = overrideDistUrl.replace(/\/+$/, '')
   80   else
   81     distBaseUrl = isIojs ? 'https://iojs.org/download/release' : 'https://nodejs.org/dist'
   82   distBaseUrl += '/v' + version + '/'
   83 
   84   // new style, based on process.release so we have a lot of the data we need
   85   if (defaultRelease && defaultRelease.headersUrl && !overrideDistUrl) {
   86     baseUrl = url.resolve(defaultRelease.headersUrl, './')
   87     libUrl32 = resolveLibUrl(name, defaultRelease.libUrl || baseUrl || distBaseUrl, 'x86', versionSemver.major)
   88     libUrl64 = resolveLibUrl(name, defaultRelease.libUrl || baseUrl || distBaseUrl, 'x64', versionSemver.major)
   89 
   90     return {
   91       version: version,
   92       semver: versionSemver,
   93       name: name,
   94       baseUrl: baseUrl,
   95       tarballUrl: defaultRelease.headersUrl,
   96       shasumsUrl: url.resolve(baseUrl, 'SHASUMS256.txt'),
   97       versionDir: (name !== 'node' ? name + '-' : '') + version,
   98       libUrl32: libUrl32,
   99       libUrl64: libUrl64,
  100       libPath32: normalizePath(path.relative(url.parse(baseUrl).path, url.parse(libUrl32).path)),
  101       libPath64: normalizePath(path.relative(url.parse(baseUrl).path, url.parse(libUrl64).path))
  102     }
  103   }
  104 
  105   // older versions without process.release are captured here and we have to make
  106   // a lot of assumptions, additionally if you --target=x.y.z then we can't use the
  107   // current process.release
  108 
  109   baseUrl = distBaseUrl
  110   libUrl32 = resolveLibUrl(name, baseUrl, 'x86', versionSemver.major)
  111   libUrl64 = resolveLibUrl(name, baseUrl, 'x64', versionSemver.major)
  112   // making the bold assumption that anything with a version number >3.0.0 will
  113   // have a *-headers.tar.gz file in its dist location, even some frankenstein
  114   // custom version
  115   canGetHeaders = semver.satisfies(versionSemver, headersTarballRange)
  116   tarballUrl = url.resolve(baseUrl, name + '-v' + version + (canGetHeaders ? '-headers' : '') + '.tar.gz')
  117 
  118   return {
  119     version: version,
  120     semver: versionSemver,
  121     name: name,
  122     baseUrl: baseUrl,
  123     tarballUrl: tarballUrl,
  124     shasumsUrl: url.resolve(baseUrl, 'SHASUMS256.txt'),
  125     versionDir: (name !== 'node' ? name + '-' : '') + version,
  126     libUrl32: libUrl32,
  127     libUrl64: libUrl64,
  128     libPath32: normalizePath(path.relative(url.parse(baseUrl).path, url.parse(libUrl32).path)),
  129     libPath64: normalizePath(path.relative(url.parse(baseUrl).path, url.parse(libUrl64).path))
  130   }
  131 }
  132 
  133 function normalizePath (p) {
  134   return path.normalize(p).replace(/\\/g, '/')
  135 }
  136 
  137 function resolveLibUrl (name, defaultUrl, arch, versionMajor) {
  138   var base = url.resolve(defaultUrl, './')
  139     , hasLibUrl = bitsre.test(defaultUrl) || (versionMajor === 3 && bitsreV3.test(defaultUrl))
  140 
  141   if (!hasLibUrl) {
  142     // let's assume it's a baseUrl then
  143     if (versionMajor >= 1)
  144       return url.resolve(base, 'win-' + arch  +'/' + name + '.lib')
  145     // prior to io.js@1.0.0 32-bit node.lib lives in /, 64-bit lives in /x64/
  146     return url.resolve(base, (arch === 'x64' ? 'x64/' : '') + name + '.lib')
  147   }
  148 
  149   // else we have a proper url to a .lib, just make sure it's the right arch
  150   return defaultUrl.replace(versionMajor === 3 ? bitsreV3 : bitsre, '/win-' + arch + '/')
  151 }
  152 
  153 module.exports = processRelease