diff --git a/lib/extensions.js b/lib/extensions.js index 854efbd5e..7d5fd9e88 100644 --- a/lib/extensions.js +++ b/lib/extensions.js @@ -23,6 +23,7 @@ function getHumanPlatform(platform) { case 'darwin': return 'OS X'; case 'freebsd': return 'FreeBSD'; case 'linux': return 'Linux'; + case 'linux_musl': return 'Linux/musl'; case 'win32': return 'Windows'; default: return false; } @@ -171,7 +172,9 @@ function getArgument(name, args) { */ function getBinaryName() { - var binaryName; + var binaryName, + variant, + platform = process.platform; if (getArgument('--sass-binary-name')) { binaryName = getArgument('--sass-binary-name'); @@ -182,8 +185,13 @@ function getBinaryName() { } else if (pkg.nodeSassConfig && pkg.nodeSassConfig.binaryName) { binaryName = pkg.nodeSassConfig.binaryName; } else { + variant = getPlatformVariant(); + if (variant) { + platform += '_' + variant; + } + binaryName = [ - process.platform, '-', + platform, '-', process.arch, '-', process.versions.modules ].join(''); @@ -256,7 +264,7 @@ function getBinaryPath() { } else if (pkg.nodeSassConfig && pkg.nodeSassConfig.binaryPath) { binaryPath = pkg.nodeSassConfig.binaryPath; } else { - binaryPath = path.join(defaultBinaryPath, getBinaryName().replace(/_/, '/')); + binaryPath = path.join(defaultBinaryPath, getBinaryName().replace(/_(?=binding\.node)/, '/')); } return binaryPath; @@ -359,6 +367,36 @@ function getVersionInfo(binding) { ].join(eol); } +/** + * Gets the platform variant, currently either an empty string or 'musl' for Linux/musl platforms. + * + * @api public + */ + +function getPlatformVariant() { + var contents = ''; + + if (process.platform !== 'linux') { + return ''; + } + + try { + contents = fs.readFileSync(process.execPath); + + // Buffer.indexOf was added in v1.5.0 so cast to string for old node + // Delay contents.toStrings because it's expensive + if (!contents.indexOf) { + contents = contents.toString(); + } + + if (contents.indexOf('libc.musl-x86_64.so.1') !== -1) { + return 'musl'; + } + } catch (err) { } // eslint-disable-line no-empty + + return ''; +} + module.exports.hasBinary = hasBinary; module.exports.getBinaryUrl = getBinaryUrl; module.exports.getBinaryName = getBinaryName;