Skip to content

Commit

Permalink
Replace npmlog with consola (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
br0p0p authored Nov 27, 2024
1 parent 095bd4a commit 1159038
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 106 deletions.
2 changes: 1 addition & 1 deletion lib/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = exports = info;

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

const log = require('npmlog');
const log = require('./util/log.js');
const versioning = require('./util/versioning.js');
const s3_setup = require('./util/s3_setup.js');

Expand Down
10 changes: 5 additions & 5 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports.usage = 'Attempts to install pre-built binary for module';

const fs = require('fs');
const path = require('path');
const log = require('npmlog');
const log = require('./util/log.js');
const existsAsync = fs.exists || path.exists;
const versioning = require('./util/versioning.js');
const napi = require('./util/napi.js');
Expand All @@ -24,7 +24,7 @@ try {
}

function place_binary(uri, targetDir, opts, callback) {
log.http('GET', uri);
log.log('GET', uri);

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

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

dataStream.pipe(extract(targetDir, countExtractions))
Expand Down Expand Up @@ -148,7 +148,7 @@ function print_fallback_error(err, opts, package_json) {
full_message += fallback_message;
log.warn('Tried to download(' + err.statusCode + '): ' + opts.hosted_tarball);
log.warn(full_message);
log.http(err.message);
log.error(err.message);
} else {
// If we do not have a statusCode that means an unexpected error
// happened and prevented an http response, so we output the exact error
Expand Down
8 changes: 4 additions & 4 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
process.title = 'node-pre-gyp';

const node_pre_gyp = require('../');
const log = require('npmlog');
const log = require('./util/log.js');

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

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


/**
Expand All @@ -58,7 +58,7 @@ if (dir) {
if (e.code === 'ENOENT') {
log.warn('chdir', dir + ' is not a directory');
} else {
log.warn('chdir', 'error during chdir() "%s"', e.message);
log.warn('chdir', `error during chdir() "${e.message}"`);
}
}
}
Expand Down
6 changes: 1 addition & 5 deletions lib/node-pre-gyp.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ const mocking = exports.mockS3Http('get');
const fs = require('fs');
const path = require('path');
const nopt = require('nopt');
const log = require('npmlog');
log.disableProgress();
const log = require('./util/log.js');
const napi = require('./util/napi.js');

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

// differentiate node-pre-gyp's logs from npm's
log.heading = 'node-pre-gyp';

if (mocking) {
log.warn(`mocking s3 to ${process.env.node_pre_gyp_mock_s3}`);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports.usage = 'Packs binary (and enclosing directory) into locally staged tarb

const fs = require('fs');
const path = require('path');
const log = require('npmlog');
const log = require('./util/log.js');
const versioning = require('./util/versioning.js');
const napi = require('./util/napi.js');
const existsAsync = fs.exists || path.exists;
Expand Down
2 changes: 1 addition & 1 deletion lib/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports.usage = 'Publishes pre-built binary (requires aws-sdk)';

const fs = require('fs');
const path = require('path');
const log = require('npmlog');
const log = require('./util/log.js');
const versioning = require('./util/versioning.js');
const napi = require('./util/napi.js');
const s3_setup = require('./util/s3_setup.js');
Expand Down
2 changes: 1 addition & 1 deletion lib/testbinary.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = exports = testbinary;
exports.usage = 'Tests that the binary.node can be required';

const path = require('path');
const log = require('npmlog');
const log = require('./util/log.js');
const cp = require('child_process');
const versioning = require('./util/versioning.js');
const napi = require('./util/napi.js');
Expand Down
2 changes: 1 addition & 1 deletion lib/testpackage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports.usage = 'Tests that the staged package is valid';

const fs = require('fs');
const path = require('path');
const log = require('npmlog');
const log = require('./util/log.js');
const existsAsync = fs.exists || path.exists;
const versioning = require('./util/versioning.js');
const napi = require('./util/napi.js');
Expand Down
2 changes: 1 addition & 1 deletion lib/unpublish.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = exports = unpublish;

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

const log = require('npmlog');
const log = require('./util/log.js');
const versioning = require('./util/versioning.js');
const napi = require('./util/napi.js');
const s3_setup = require('./util/s3_setup.js');
Expand Down
9 changes: 9 additions & 0 deletions lib/util/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

const { createConsola } = require('consola/basic');

// match the default behavior of npm and node-gyp where stdout is reserved for output that is expected
// to be used programmatically (usually json)
const log = createConsola({ stdout: process.stderr });

module.exports = exports = log;
2 changes: 1 addition & 1 deletion lib/util/napi.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ module.exports.expand_commands = function(package_json, opts, commands) {
};

module.exports.get_napi_build_versions = function(package_json, opts, warnings) { // opts may be undefined
const log = require('npmlog');
const log = require('./log.js');
let napi_build_versions = [];
const supported_napi_version = module.exports.get_napi_version(opts ? opts.target : undefined);
// remove duplicates, verify each napi version can actually be built
Expand Down
91 changes: 9 additions & 82 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
"node": ">=18"
},
"dependencies": {
"consola": "^3.2.3",
"detect-libc": "^2.0.0",
"https-proxy-agent": "^5.0.0",
"node-fetch": "^2.6.7",
"nopt": "^8.0.0",
"npmlog": "^7.0.1",
"semver": "^7.5.3",
"tar": "^7.4.0"
},
Expand Down
3 changes: 1 addition & 2 deletions test/build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ apps.forEach((app) => {
test(app.name + ' configures with unparsed options ' + app.args, (t) => {
run('node-pre-gyp', 'configure', '--loglevel=info -- -Dfoo=bar', app, {}, (err, stdout, stderr) => {
t.ifError(err);
const clean = stdout.replaceAll('\n', '');
t.equal(clean, '');
t.equal(stderr.trim().slice(-2), 'ok');
t.ok(stderr.search(/(gyp info spawn args).*(-Dfoo=bar)/) > -1);
t.end();
});
Expand Down

0 comments on commit 1159038

Please sign in to comment.