diff --git a/lib/info.js b/lib/info.js index 970fa331f..3e5c63cdf 100644 --- a/lib/info.js +++ b/lib/info.js @@ -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'); diff --git a/lib/install.js b/lib/install.js index 827a2bbd7..a271f515a 100644 --- a/lib/install.js +++ b/lib/install.js @@ -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'); @@ -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 || @@ -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 }) @@ -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)) @@ -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 diff --git a/lib/main.js b/lib/main.js index bae32acb7..f46ea3299 100644 --- a/lib/main.js +++ b/lib/main.js @@ -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. @@ -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} `); /** @@ -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}"`); } } } diff --git a/lib/node-pre-gyp.js b/lib/node-pre-gyp.js index dc18e749e..0c30087b9 100644 --- a/lib/node-pre-gyp.js +++ b/lib/node-pre-gyp.js @@ -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; @@ -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}`); } diff --git a/lib/package.js b/lib/package.js index f8f072c0f..5a8a759af 100644 --- a/lib/package.js +++ b/lib/package.js @@ -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; diff --git a/lib/publish.js b/lib/publish.js index 8cb6c84e0..3b2e08cd3 100644 --- a/lib/publish.js +++ b/lib/publish.js @@ -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'); diff --git a/lib/testbinary.js b/lib/testbinary.js index 429cb1301..bc4883d71 100644 --- a/lib/testbinary.js +++ b/lib/testbinary.js @@ -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'); diff --git a/lib/testpackage.js b/lib/testpackage.js index 29a08a2ba..e6be5bbb3 100644 --- a/lib/testpackage.js +++ b/lib/testpackage.js @@ -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'); diff --git a/lib/unpublish.js b/lib/unpublish.js index ad9b7d4e4..b8e1b550d 100644 --- a/lib/unpublish.js +++ b/lib/unpublish.js @@ -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'); diff --git a/lib/util/log.js b/lib/util/log.js new file mode 100644 index 000000000..edc7b5e49 --- /dev/null +++ b/lib/util/log.js @@ -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; diff --git a/lib/util/napi.js b/lib/util/napi.js index 447155f5b..bfb384385 100644 --- a/lib/util/napi.js +++ b/lib/util/napi.js @@ -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 diff --git a/package-lock.json b/package-lock.json index f2528b8bd..1cb884ab5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,11 +9,11 @@ "version": "1.0.11", "license": "BSD-3-Clause", "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" }, @@ -1331,12 +1331,6 @@ "node": ">=8" } }, - "node_modules/aproba": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/aproba/-/aproba-2.0.0.tgz", - "integrity": "sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ==", - "license": "ISC" - }, "node_modules/archy": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/archy/-/archy-1.0.0.tgz", @@ -1344,16 +1338,6 @@ "dev": true, "license": "MIT" }, - "node_modules/are-we-there-yet": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-4.0.2.tgz", - "integrity": "sha512-ncSWAawFhKMJDTdoAeOV+jyW1VCMj5QIAwULIBV0SSR7B/RLPPEQiknKcg/RIIZlUQrxELpsxMiTUoAQ4sIUyg==", - "deprecated": "This package is no longer supported.", - "license": "ISC", - "engines": { - "node": "^14.17.0 || ^16.13.0 || >=18.0.0" - } - }, "node_modules/argparse": { "version": "1.0.10", "resolved": "https://registry.npmjs.org/argparse/-/argparse-1.0.10.tgz", @@ -1807,15 +1791,6 @@ "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==", "license": "MIT" }, - "node_modules/color-support": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz", - "integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==", - "license": "ISC", - "bin": { - "color-support": "bin.js" - } - }, "node_modules/commondir": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/commondir/-/commondir-1.0.1.tgz", @@ -1830,11 +1805,13 @@ "dev": true, "license": "MIT" }, - "node_modules/console-control-strings": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", - "integrity": "sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==", - "license": "ISC" + "node_modules/consola": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/consola/-/consola-3.2.3.tgz", + "integrity": "sha512-I5qxpzLv+sJhTVEoLYNcTW+bThDCPsit0vLNKShZx6rLtpilNpmmeTPaeqJb9ZE9dV3DGaeby6Vuhrw38WjeyQ==", + "engines": { + "node": "^14.18.0 || >=16.10.0" + } }, "node_modules/convert-source-map": { "version": "1.9.0", @@ -2981,26 +2958,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/gauge": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/gauge/-/gauge-5.0.2.tgz", - "integrity": "sha512-pMaFftXPtiGIHCJHdcUUx9Rby/rFT/Kkt3fIIGCs+9PMDIljSyRiqraTlxNtBReJRDfUefpa263RQ3vnp5G/LQ==", - "deprecated": "This package is no longer supported.", - "license": "ISC", - "dependencies": { - "aproba": "^1.0.3 || ^2.0.0", - "color-support": "^1.1.3", - "console-control-strings": "^1.1.0", - "has-unicode": "^2.0.1", - "signal-exit": "^4.0.1", - "string-width": "^4.2.3", - "strip-ansi": "^6.0.1", - "wide-align": "^1.1.5" - }, - "engines": { - "node": "^14.17.0 || ^16.13.0 || >=18.0.0" - } - }, "node_modules/gensync": { "version": "1.0.0-beta.2", "resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz", @@ -3315,12 +3272,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/has-unicode": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", - "integrity": "sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==", - "license": "ISC" - }, "node_modules/hasha": { "version": "5.2.2", "resolved": "https://registry.npmjs.org/hasha/-/hasha-5.2.2.tgz", @@ -4505,22 +4456,6 @@ "node": "^18.17.0 || >=20.5.0" } }, - "node_modules/npmlog": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-7.0.1.tgz", - "integrity": "sha512-uJ0YFk/mCQpLBt+bxN88AKd+gyqZvZDbtiNxk6Waqcj2aPRyfVx8ITawkyQynxUagInjdYT1+qj4NfA5KJJUxg==", - "deprecated": "This package is no longer supported.", - "license": "ISC", - "dependencies": { - "are-we-there-yet": "^4.0.0", - "console-control-strings": "^1.1.0", - "gauge": "^5.0.0", - "set-blocking": "^2.0.0" - }, - "engines": { - "node": "^14.17.0 || ^16.13.0 || >=18.0.0" - } - }, "node_modules/nyc": { "version": "17.0.0", "resolved": "https://registry.npmjs.org/nyc/-/nyc-17.0.0.tgz", @@ -5364,6 +5299,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==", + "dev": true, "license": "ISC" }, "node_modules/set-function-length": { @@ -6297,15 +6233,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/wide-align": { - "version": "1.1.5", - "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz", - "integrity": "sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==", - "license": "ISC", - "dependencies": { - "string-width": "^1.0.2 || 2 || 3 || 4" - } - }, "node_modules/word-wrap": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/word-wrap/-/word-wrap-1.2.5.tgz", diff --git a/package.json b/package.json index 222aee4f5..4bcbe8b8b 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/test/build.test.js b/test/build.test.js index d90b7208f..3daf9b189 100644 --- a/test/build.test.js +++ b/test/build.test.js @@ -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(); });