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

fix: use needle instead of request #46

Merged
merged 1 commit into from
Nov 21, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions lib/jar.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from 'path';
import * as crypto from 'crypto';
import * as fs from 'fs';
import * as request from 'request-promise-native';
import * as needle from 'needle';
import { createPom } from './pom';

import * as tmp from 'tmp';
Expand Down Expand Up @@ -72,24 +72,29 @@ export function isJar(file: string) {
}

async function getMavenPackageInfo(sha1: string): Promise<MavenPackageInfo> {
const res: MavenCentralResponse = await request({
url: MAVEN_SEARCH_URL,
qs: {
wt: 'json',
q: `1:"${sha1}"`,
},
json: true,
const url = `${MAVEN_SEARCH_URL}?q=1:"${sha1}"&wt=json`;
return new Promise((resolve, reject) => {
needle.request(
'get',
url,
{},
{ json: true },
(err, fullRes, res: MavenCentralResponse) => {
if (err) {
reject(err);
}
if (!res || !res.response || res.response.docs.length === 0) {
reject(new Error('No package found for provided sha1 hash'));
}

if (res.response.docs.length > 1) {
debug('Got multiple results for sha1, only returning first one');
}

resolve(res.response.docs[0]);
},
);
});

if (!res || !res.response || res.response.docs.length === 0) {
throw new Error('No package found for provided sha1 hash');
}

if (res.response.docs.length > 1) {
debug('Got multiple results for sha1, only returning first one');
}

return res.response.docs[0];
}

async function createTempPomFile(
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"@snyk/cli-interface": "2.2.0",
"debug": "^4.1.1",
"lodash": "^4.17.15",
"request-promise-native": "^1.0.8",
"needle": "^2.4.0",
"tmp": "^0.1.0",
"tslib": "1.9.3"
}
Expand Down