Install: skip header files when using prebuilds

This commit is contained in:
Lovell Fuller 2021-02-27 16:33:50 +00:00
parent af66a73225
commit 5eed87ec4d

View File

@ -22,6 +22,15 @@ const minimumGlibcVersionByArch = {
x64: '2.17' x64: '2.17'
}; };
const hasSharpPrebuild = [
'darwin-x64',
'linux-arm64',
'linux-x64',
'linuxmusl-x64',
'win32-ia32',
'win32-x64'
];
const { minimumLibvipsVersion, minimumLibvipsVersionLabelled } = libvips; const { minimumLibvipsVersion, minimumLibvipsVersionLabelled } = libvips;
const distHost = process.env.npm_config_sharp_libvips_binary_host || 'https://github.com/lovell/sharp-libvips/releases/download'; const distHost = process.env.npm_config_sharp_libvips_binary_host || 'https://github.com/lovell/sharp-libvips/releases/download';
const distBaseUrl = process.env.npm_config_sharp_dist_base_url || process.env.SHARP_DIST_BASE_URL || `${distHost}/v${minimumLibvipsVersionLabelled}/`; const distBaseUrl = process.env.npm_config_sharp_dist_base_url || process.env.SHARP_DIST_BASE_URL || `${distHost}/v${minimumLibvipsVersionLabelled}/`;
@ -37,15 +46,21 @@ const fail = function (err) {
process.exit(1); process.exit(1);
}; };
const extractTarball = function (tarPath) { const extractTarball = function (tarPath, platformAndArch) {
const vendorPath = path.join(__dirname, '..', 'vendor'); const vendorPath = path.join(__dirname, '..', 'vendor');
libvips.mkdirSync(vendorPath); libvips.mkdirSync(vendorPath);
const versionedVendorPath = path.join(vendorPath, minimumLibvipsVersion); const versionedVendorPath = path.join(vendorPath, minimumLibvipsVersion);
libvips.mkdirSync(versionedVendorPath); libvips.mkdirSync(versionedVendorPath);
const ignoreVendorInclude = hasSharpPrebuild.includes(platformAndArch) && !process.env.npm_config_build_from_source;
const ignore = function (name) {
return ignoreVendorInclude && name.includes('include/');
};
stream.pipeline( stream.pipeline(
fs.createReadStream(tarPath), fs.createReadStream(tarPath),
supportsBrotli ? new zlib.BrotliDecompress() : new zlib.Gunzip(), supportsBrotli ? new zlib.BrotliDecompress() : new zlib.Gunzip(),
tarFs.extract(versionedVendorPath), tarFs.extract(versionedVendorPath, { ignore }),
function (err) { function (err) {
if (err) { if (err) {
if (/unexpected end of file/.test(err.message)) { if (/unexpected end of file/.test(err.message)) {
@ -103,7 +118,7 @@ try {
const tarPathCache = path.join(libvips.cachePath(), tarFilename); const tarPathCache = path.join(libvips.cachePath(), tarFilename);
if (fs.existsSync(tarPathCache)) { if (fs.existsSync(tarPathCache)) {
npmLog.info('sharp', `Using cached ${tarPathCache}`); npmLog.info('sharp', `Using cached ${tarPathCache}`);
extractTarball(tarPathCache); extractTarball(tarPathCache, platformAndArch);
} else { } else {
const url = distBaseUrl + tarFilename; const url = distBaseUrl + tarFilename;
npmLog.info('sharp', `Downloading ${url}`); npmLog.info('sharp', `Downloading ${url}`);