mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
Remove npmlog as a direct dependency
It remains a transitive dependency via prebuild-install
This commit is contained in:
parent
b05a4bdadd
commit
8dffa28b4d
@ -4,7 +4,6 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const libvips = require('../lib/libvips');
|
||||
const npmLog = require('npmlog');
|
||||
|
||||
const minimumLibvipsVersion = libvips.minimumLibvipsVersion;
|
||||
|
||||
@ -12,13 +11,13 @@ const platform = process.env.npm_config_platform || process.platform;
|
||||
if (platform === 'win32') {
|
||||
const buildDir = path.join(__dirname, '..', 'build');
|
||||
const buildReleaseDir = path.join(buildDir, 'Release');
|
||||
npmLog.info('sharp', `Creating ${buildReleaseDir}`);
|
||||
libvips.log(`Creating ${buildReleaseDir}`);
|
||||
try {
|
||||
libvips.mkdirSync(buildDir);
|
||||
libvips.mkdirSync(buildReleaseDir);
|
||||
} catch (err) {}
|
||||
const vendorLibDir = path.join(__dirname, '..', 'vendor', minimumLibvipsVersion, 'lib');
|
||||
npmLog.info('sharp', `Copying DLLs from ${vendorLibDir} to ${buildReleaseDir}`);
|
||||
libvips.log(`Copying DLLs from ${vendorLibDir} to ${buildReleaseDir}`);
|
||||
try {
|
||||
fs
|
||||
.readdirSync(vendorLibDir)
|
||||
@ -32,6 +31,7 @@ if (platform === 'win32') {
|
||||
);
|
||||
});
|
||||
} catch (err) {
|
||||
npmLog.error('sharp', err.message);
|
||||
libvips.log(err);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ const stream = require('stream');
|
||||
const zlib = require('zlib');
|
||||
|
||||
const detectLibc = require('detect-libc');
|
||||
const npmLog = require('npmlog');
|
||||
const semver = require('semver');
|
||||
const simpleGet = require('simple-get');
|
||||
const tarFs = require('tar-fs');
|
||||
@ -37,12 +36,12 @@ const distBaseUrl = process.env.npm_config_sharp_dist_base_url || process.env.SH
|
||||
const supportsBrotli = ('BrotliDecompress' in zlib);
|
||||
|
||||
const fail = function (err) {
|
||||
npmLog.error('sharp', err.message);
|
||||
libvips.log(err);
|
||||
if (err.code === 'EACCES') {
|
||||
npmLog.info('sharp', 'Are you trying to install as a root or sudo user? Try again with the --unsafe-perm flag');
|
||||
libvips.log('Are you trying to install as a root or sudo user? Try again with the --unsafe-perm flag');
|
||||
}
|
||||
npmLog.info('sharp', 'Attempting to build from source via node-gyp but this may fail due to the above error');
|
||||
npmLog.info('sharp', 'Please see https://sharp.pixelplumbing.com/install for required dependencies');
|
||||
libvips.log('Attempting to build from source via node-gyp but this may fail due to the above error');
|
||||
libvips.log('Please see https://sharp.pixelplumbing.com/install for required dependencies');
|
||||
process.exit(1);
|
||||
};
|
||||
|
||||
@ -64,7 +63,7 @@ const extractTarball = function (tarPath, platformAndArch) {
|
||||
function (err) {
|
||||
if (err) {
|
||||
if (/unexpected end of file/.test(err.message)) {
|
||||
npmLog.error('sharp', `Please delete ${tarPath} as it is not a valid tarball`);
|
||||
fail(new Error(`Please delete ${tarPath} as it is not a valid tarball`));
|
||||
}
|
||||
fail(err);
|
||||
}
|
||||
@ -77,11 +76,11 @@ try {
|
||||
|
||||
if (useGlobalLibvips) {
|
||||
const globalLibvipsVersion = libvips.globalLibvipsVersion();
|
||||
npmLog.info('sharp', `Detected globally-installed libvips v${globalLibvipsVersion}`);
|
||||
npmLog.info('sharp', 'Building from source via node-gyp');
|
||||
libvips.log(`Detected globally-installed libvips v${globalLibvipsVersion}`);
|
||||
libvips.log('Building from source via node-gyp');
|
||||
process.exit(1);
|
||||
} else if (libvips.hasVendoredLibvips()) {
|
||||
npmLog.info('sharp', `Using existing vendored libvips v${minimumLibvipsVersion}`);
|
||||
libvips.log(`Using existing vendored libvips v${minimumLibvipsVersion}`);
|
||||
} else {
|
||||
// Is this arch/platform supported?
|
||||
const arch = process.env.npm_config_arch || process.arch;
|
||||
@ -117,11 +116,11 @@ try {
|
||||
const tarFilename = ['libvips', minimumLibvipsVersion, platformAndArch].join('-') + '.tar.' + extension;
|
||||
const tarPathCache = path.join(libvips.cachePath(), tarFilename);
|
||||
if (fs.existsSync(tarPathCache)) {
|
||||
npmLog.info('sharp', `Using cached ${tarPathCache}`);
|
||||
libvips.log(`Using cached ${tarPathCache}`);
|
||||
extractTarball(tarPathCache, platformAndArch);
|
||||
} else {
|
||||
const url = distBaseUrl + tarFilename;
|
||||
npmLog.info('sharp', `Downloading ${url}`);
|
||||
libvips.log(`Downloading ${url}`);
|
||||
simpleGet({ url: url, agent: agent() }, function (err, response) {
|
||||
if (err) {
|
||||
fail(err);
|
||||
|
@ -37,6 +37,14 @@ const cachePath = function () {
|
||||
return libvipsCachePath;
|
||||
};
|
||||
|
||||
const log = function (item) {
|
||||
if (item instanceof Error) {
|
||||
console.error(`sharp: ${item.message}`);
|
||||
} else {
|
||||
console.log(`sharp: ${item}`);
|
||||
}
|
||||
};
|
||||
|
||||
const isRosetta = function () {
|
||||
/* istanbul ignore next */
|
||||
if (process.platform === 'darwin' && process.arch === 'x64') {
|
||||
@ -104,6 +112,7 @@ module.exports = {
|
||||
minimumLibvipsVersion,
|
||||
minimumLibvipsVersionLabelled,
|
||||
cachePath,
|
||||
log,
|
||||
globalLibvipsVersion,
|
||||
hasVendoredLibvips,
|
||||
pkgConfigPath,
|
||||
|
@ -120,7 +120,6 @@
|
||||
"color": "^3.1.3",
|
||||
"detect-libc": "^1.0.3",
|
||||
"node-addon-api": "^3.1.0",
|
||||
"npmlog": "^4.1.2",
|
||||
"prebuild-install": "^6.0.1",
|
||||
"semver": "^7.3.4",
|
||||
"simple-get": "^3.1.0",
|
||||
|
@ -105,4 +105,30 @@ describe('libvips binaries', function () {
|
||||
assert.strictEqual(true, fs.existsSync(nestedDirPath));
|
||||
});
|
||||
});
|
||||
|
||||
describe('logger', function () {
|
||||
const consoleLog = console.log;
|
||||
const consoleError = console.error;
|
||||
|
||||
after(function () {
|
||||
console.log = consoleLog;
|
||||
console.error = consoleError;
|
||||
});
|
||||
|
||||
it('logs an info message', function (done) {
|
||||
console.log = function (msg) {
|
||||
assert.strictEqual(msg, 'sharp: progress');
|
||||
done();
|
||||
};
|
||||
libvips.log('progress');
|
||||
});
|
||||
|
||||
it('logs an error message', function (done) {
|
||||
console.error = function (msg) {
|
||||
assert.strictEqual(msg, 'sharp: problem');
|
||||
done();
|
||||
};
|
||||
libvips.log(new Error('problem'));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user