Skip to content
This repository was archived by the owner on Feb 19, 2026. It is now read-only.

Commit e9065dd

Browse files
committed
Don't compile on default if installed via Yarn
prebuild/prebuild#150 prebuild/prebuild#151
1 parent 3379919 commit e9065dd

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

bin.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var extend = require('xtend')
77

88
var rc = require('./rc')
99
var download = require('./download')
10+
var util = require('./util')
1011

1112
var prebuildClientVersion = require('./package.json').version
1213
if (rc.version) {
@@ -39,15 +40,17 @@ log.info('begin', 'Prebuild-install version', prebuildClientVersion)
3940

4041
var opts = extend(rc, {pkg: pkg, log: log})
4142

42-
if (!(typeof pkg._from === 'string')) {
43+
var execPath = process.env.npm_execpath || process.env.NPM_CLI_JS
44+
45+
if (util.isYarnPath(execPath) && /node_modules/.test(process.cwd())) {
46+
// From yarn repository
47+
} else if (!(typeof pkg._from === 'string')) {
4348
log.info('install', 'installing inside prebuild-install directory, skipping download.')
4449
process.exit(1)
4550
} else if (pkg._from.length > 4 && pkg._from.substr(0, 4) === 'git+') {
4651
log.info('install', 'installing from git repository, skipping download.')
4752
process.exit(1)
48-
}
49-
50-
if (opts.compile === true || opts.prebuild === false) {
53+
} else if (opts.compile === true || opts.prebuild === false) {
5154
log.info('install', '--build-from-source specified, not attempting download.')
5255
process.exit(1)
5356
}

test/util-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,12 @@ test('getDownloadUrl() expands template to correct values', function (t) {
160160
t.equal(url3, url2, 'scope does not matter for download url')
161161
t.end()
162162
})
163+
164+
test('isYarnPath(): returns correct value', function (t) {
165+
var yarn = util.isYarnPath
166+
t.equal(yarn(null), false)
167+
t.equal(yarn(undefined), false)
168+
t.equal(yarn('/usr/local/lib/node_modules/npm/bin/npm-cli.js'), false)
169+
t.equal(yarn('/usr/local/opt/yarn/libexec/lib/node_modules/yarn/bin/yarn.js'), true)
170+
t.end()
171+
})

util.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,15 @@ function localPrebuild (url) {
6767
return path.join('prebuilds', path.basename(url))
6868
}
6969

70+
function isYarnPath (execPath) {
71+
return execPath ? /^yarn/.test(path.basename(execPath)) : false
72+
}
73+
7074
exports.getDownloadUrl = getDownloadUrl
7175
exports.urlTemplate = urlTemplate
7276
exports.cachedPrebuild = cachedPrebuild
7377
exports.localPrebuild = localPrebuild
7478
exports.prebuildCache = prebuildCache
7579
exports.npmCache = npmCache
7680
exports.tempFile = tempFile
81+
exports.isYarnPath = isYarnPath

0 commit comments

Comments
 (0)