Skip to content

Commit

Permalink
Read env.npm_package_from for npm 7
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Oct 23, 2020
1 parent a2f6fb4 commit 8acccac
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,17 @@ if (napi.isNapiRuntime(rc.runtime)) napi.logUnsupportedVersion(rc.target, log)

var pm = whichPmRuns()
var isNpm = !pm || pm.name === 'npm'
var origin = util.packageOrigin(process.env, pkg)

if (!isNpm && /node_modules/.test(process.cwd())) {
// From yarn repository
} else if (opts.force) {
log.warn('install', 'prebuilt binaries enforced with --force!')
log.warn('install', 'prebuilt binaries may be out of date!')
} else if (!(typeof pkg._from === 'string')) {
} else if (typeof origin !== 'string') {
log.info('install', 'installing standalone, skipping download.')
process.exit(1)
} else if (pkg._from.length > 4 && pkg._from.substr(0, 4) === 'git+') {
} else if (origin.length > 4 && origin.substr(0, 4) === 'git+') {
log.info('install', 'installing from git repository, skipping download.')
process.exit(1)
} else if (opts.compile === true || opts.prebuild === false) {
Expand Down
14 changes: 14 additions & 0 deletions util.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ function tempFile (cached) {
return cached + '.' + process.pid + '-' + Math.random().toString(16).slice(2) + '.tmp'
}

function packageOrigin (env, pkg) {
if (env.npm_package_from) {
// npm 7: metadata is exposed to environment by arborist
// TODO: seems undefined atm (npm 7.0.2)
return env.npm_package_from
}

if (pkg._from) {
// npm <= 6: metadata is stored on disk in node_modules
return pkg._from
}
}

exports.getDownloadUrl = getDownloadUrl
exports.getApiUrl = getApiUrl
exports.getAssetUrl = getAssetUrl
Expand All @@ -95,3 +108,4 @@ exports.cachedPrebuild = cachedPrebuild
exports.prebuildCache = prebuildCache
exports.npmCache = npmCache
exports.tempFile = tempFile
exports.packageOrigin = packageOrigin

0 comments on commit 8acccac

Please sign in to comment.