Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Replace npmlog dependency in order to support Node 10+ #1392

Merged
merged 7 commits into from Nov 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Expand Up @@ -74,7 +74,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [12.x, 14.x, 16.x]
node-version: [10.x, 12.x, 14.x, 16.x]

name: Test Node ${{ matrix.node-version }}
runs-on: ubuntu-latest
Expand Down
14 changes: 14 additions & 0 deletions js/logger.js
@@ -0,0 +1,14 @@
'use strict';

const format = require('util').format;

module.exports = class Logger {
constructor(stream) {
this.stream = stream;
}

log() {
const message = format(...arguments);
this.stream.write(`[sentry-cli] ${message}\n`);
}
};
9 changes: 6 additions & 3 deletions package.json
Expand Up @@ -7,7 +7,7 @@
"author": "Sentry",
"license": "BSD-3-Clause",
"engines": {
"node": ">= 12"
"node": ">= 10"
},
"main": "js/index.js",
"types": "js/index.d.ts",
Expand All @@ -17,14 +17,13 @@
"dependencies": {
"https-proxy-agent": "^5.0.0",
"node-fetch": "^2.6.7",
"npmlog": "^6.0.1",
"progress": "^2.0.3",
"proxy-from-env": "^1.1.0",
"which": "^2.0.2"
},
"devDependencies": {
"@vercel/nft": "^0.22.1",
"eslint": "^8.13.0",
"eslint": "^7.32.0",
"eslint-config-prettier": "^8.5.0",
"jest": "^27.5.1",
"npm-run-all": "^4.1.5",
Expand All @@ -48,5 +47,9 @@
"testPathIgnorePatterns": [
"<rootDir>/src"
]
},
"volta": {
"node": "10.24.1",
mydea marked this conversation as resolved.
Show resolved Hide resolved
"yarn": "1.22.19"
}
}
22 changes: 11 additions & 11 deletions scripts/install.js
Expand Up @@ -15,11 +15,13 @@ const fetch = require('node-fetch');
const HttpsProxyAgent = require('https-proxy-agent');
const ProgressBar = require('progress');
const Proxy = require('proxy-from-env');
const npmLog = require('npmlog');
const which = require('which');

const helper = require('../js/helper');
const pkgInfo = require('../package.json');
const Logger = require('../js/logger');

const logger = new Logger(getLogStream('stderr'));

const CDN_URL =
process.env.SENTRYCLI_LOCAL_CDNURL ||
Expand Down Expand Up @@ -157,14 +159,14 @@ function validateChecksum(tempPath, name) {
}
}
} catch (e) {
npmLog.info(
logger.log(
'Checksums are generated when the package is published to npm. They are not available directly in the source repository. Skipping validation.'
);
return;
}

if (!storedHash) {
npmLog.info(`Checksum for ${name} not found, skipping validation.`);
logger.log(`Checksum for ${name} not found, skipping validation.`);
return;
}

Expand All @@ -176,7 +178,7 @@ function validateChecksum(tempPath, name) {
`Checksum validation for ${name} failed.\nExpected: ${storedHash}\nReceived: ${currentHash}`
);
} else {
npmLog.info('Checksum validation passed.');
logger.log('Checksum validation passed.');
}
}

Expand All @@ -188,7 +190,7 @@ async function downloadBinary() {
if (process.env.SENTRYCLI_USE_LOCAL === '1') {
try {
const binPath = which.sync('sentry-cli');
npmLog.info('sentry-cli', `Using local binary: ${binPath}`);
logger.log(`Using local binary: ${binPath}`);
fs.copyFileSync(binPath, outputPath);
return Promise.resolve();
} catch (e) {
Expand All @@ -206,18 +208,18 @@ async function downloadBinary() {

const cachedPath = getCachedPath(downloadUrl);
if (fs.existsSync(cachedPath)) {
npmLog.info('sentry-cli', `Using cached binary: ${cachedPath}`);
logger.log(`Using cached binary: ${cachedPath}`);
fs.copyFileSync(cachedPath, outputPath);
return;
}

const proxyUrl = Proxy.getProxyForUrl(downloadUrl);
const agent = proxyUrl ? new HttpsProxyAgent(proxyUrl) : null;

npmLog.info('sentry-cli', `Downloading from ${downloadUrl}`);
logger.log(`Downloading from ${downloadUrl}`);

if (proxyUrl) {
npmLog.info('sentry-cli', `Using proxy URL: ${proxyUrl}`);
logger.log(`Using proxy URL: ${proxyUrl}`);
}

let response;
Expand Down Expand Up @@ -316,10 +318,8 @@ if (process.env.SENTRYCLI_LOCAL_CDNURL) {
process.on('exit', () => server.close());
}

npmLog.stream = getLogStream('stderr');

if (process.env.SENTRYCLI_SKIP_DOWNLOAD === '1') {
npmLog.info('sentry-cli', `Skipping download because SENTRYCLI_SKIP_DOWNLOAD=1 detected.`);
logger.log(`Skipping download because SENTRYCLI_SKIP_DOWNLOAD=1 detected.`);
process.exit(0);
}

Expand Down