Skip to content

Commit 1159038

Browse files
authored
Replace npmlog with consola (#829)
1 parent 095bd4a commit 1159038

14 files changed

Lines changed: 37 additions & 106 deletions

lib/info.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = exports = info;
44

55
exports.usage = 'Lists all published binaries (requires aws-sdk)';
66

7-
const log = require('npmlog');
7+
const log = require('./util/log.js');
88
const versioning = require('./util/versioning.js');
99
const s3_setup = require('./util/s3_setup.js');
1010

lib/install.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ exports.usage = 'Attempts to install pre-built binary for module';
66

77
const fs = require('fs');
88
const path = require('path');
9-
const log = require('npmlog');
9+
const log = require('./util/log.js');
1010
const existsAsync = fs.exists || path.exists;
1111
const versioning = require('./util/versioning.js');
1212
const napi = require('./util/napi.js');
@@ -24,7 +24,7 @@ try {
2424
}
2525

2626
function place_binary(uri, targetDir, opts, callback) {
27-
log.http('GET', uri);
27+
log.log('GET', uri);
2828

2929
// Try getting version info from the currently running npm.
3030
const envVersionInfo = process.env.npm_config_user_agent ||
@@ -57,7 +57,7 @@ function place_binary(uri, targetDir, opts, callback) {
5757
if (proxyUrl) {
5858
const ProxyAgent = require('https-proxy-agent');
5959
agent = new ProxyAgent(proxyUrl);
60-
log.http('download', 'proxy agent configured using: "%s"', proxyUrl);
60+
log.log('download', `proxy agent configured using: "${proxyUrl}"`);
6161
}
6262

6363
fetch(sanitized, { agent })
@@ -71,7 +71,7 @@ function place_binary(uri, targetDir, opts, callback) {
7171
let extractions = 0;
7272
const countExtractions = (entry) => {
7373
extractions += 1;
74-
log.info('install', 'unpacking %s', entry.path);
74+
log.info('install', `unpacking ${entry.path}`);
7575
};
7676

7777
dataStream.pipe(extract(targetDir, countExtractions))
@@ -148,7 +148,7 @@ function print_fallback_error(err, opts, package_json) {
148148
full_message += fallback_message;
149149
log.warn('Tried to download(' + err.statusCode + '): ' + opts.hosted_tarball);
150150
log.warn(full_message);
151-
log.http(err.message);
151+
log.error(err.message);
152152
} else {
153153
// If we do not have a statusCode that means an unexpected error
154154
// happened and prevented an http response, so we output the exact error

lib/main.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
process.title = 'node-pre-gyp';
88

99
const node_pre_gyp = require('../');
10-
const log = require('npmlog');
10+
const log = require('./util/log.js');
1111

1212
/**
1313
* Process and execute the selected commands.
@@ -35,8 +35,8 @@ if (prog.opts && Object.hasOwnProperty.call(prog, 'color') && !prog.opts.color)
3535

3636
log.info('it worked if it ends with', 'ok');
3737
log.verbose('cli', process.argv);
38-
log.info('using', process.title + '@%s', prog.version);
39-
log.info('using', 'node@%s | %s | %s', process.versions.node, process.platform, process.arch);
38+
log.info(`using ${process.title}@${prog.version}`);
39+
log.info(`using node@${process.versions.node} | ${process.platform} | ${process.arch} `);
4040

4141

4242
/**
@@ -58,7 +58,7 @@ if (dir) {
5858
if (e.code === 'ENOENT') {
5959
log.warn('chdir', dir + ' is not a directory');
6060
} else {
61-
log.warn('chdir', 'error during chdir() "%s"', e.message);
61+
log.warn('chdir', `error during chdir() "${e.message}"`);
6262
}
6363
}
6464
}

lib/node-pre-gyp.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ const mocking = exports.mockS3Http('get');
2020
const fs = require('fs');
2121
const path = require('path');
2222
const nopt = require('nopt');
23-
const log = require('npmlog');
24-
log.disableProgress();
23+
const log = require('./util/log.js');
2524
const napi = require('./util/napi.js');
2625

2726
const EE = require('events').EventEmitter;
@@ -43,9 +42,6 @@ const cli_commands = [
4342
];
4443
const aliases = {};
4544

46-
// differentiate node-pre-gyp's logs from npm's
47-
log.heading = 'node-pre-gyp';
48-
4945
if (mocking) {
5046
log.warn(`mocking s3 to ${process.env.node_pre_gyp_mock_s3}`);
5147
}

lib/package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ exports.usage = 'Packs binary (and enclosing directory) into locally staged tarb
66

77
const fs = require('fs');
88
const path = require('path');
9-
const log = require('npmlog');
9+
const log = require('./util/log.js');
1010
const versioning = require('./util/versioning.js');
1111
const napi = require('./util/napi.js');
1212
const existsAsync = fs.exists || path.exists;

lib/publish.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ exports.usage = 'Publishes pre-built binary (requires aws-sdk)';
66

77
const fs = require('fs');
88
const path = require('path');
9-
const log = require('npmlog');
9+
const log = require('./util/log.js');
1010
const versioning = require('./util/versioning.js');
1111
const napi = require('./util/napi.js');
1212
const s3_setup = require('./util/s3_setup.js');

lib/testbinary.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = exports = testbinary;
55
exports.usage = 'Tests that the binary.node can be required';
66

77
const path = require('path');
8-
const log = require('npmlog');
8+
const log = require('./util/log.js');
99
const cp = require('child_process');
1010
const versioning = require('./util/versioning.js');
1111
const napi = require('./util/napi.js');

lib/testpackage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ exports.usage = 'Tests that the staged package is valid';
66

77
const fs = require('fs');
88
const path = require('path');
9-
const log = require('npmlog');
9+
const log = require('./util/log.js');
1010
const existsAsync = fs.exists || path.exists;
1111
const versioning = require('./util/versioning.js');
1212
const napi = require('./util/napi.js');

lib/unpublish.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module.exports = exports = unpublish;
44

55
exports.usage = 'Unpublishes pre-built binary (requires aws-sdk)';
66

7-
const log = require('npmlog');
7+
const log = require('./util/log.js');
88
const versioning = require('./util/versioning.js');
99
const napi = require('./util/napi.js');
1010
const s3_setup = require('./util/s3_setup.js');

lib/util/log.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
'use strict';
2+
3+
const { createConsola } = require('consola/basic');
4+
5+
// match the default behavior of npm and node-gyp where stdout is reserved for output that is expected
6+
// to be used programmatically (usually json)
7+
const log = createConsola({ stdout: process.stderr });
8+
9+
module.exports = exports = log;

0 commit comments

Comments
 (0)