New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@pnpm/git-resolver

Package Overview
Dependencies
Maintainers
2
Versions
140
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@pnpm/git-resolver - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

16

lib/index.d.ts
import { HostedPackageSpec } from './parsePref';
export { HostedPackageSpec };
export default function (opts: {
getJson: <T>(url: string, registry: string) => Promise<T>;
}): any;
export default function (opts: {}): (wantedDependency: {
pref: string;
}) => Promise<{
id: string;
normalizedPref: string;
resolution: {
commit: string;
repo: string;
type: "git";
} | {
tarball: string;
};
} | null>;

115

lib/index.js

@@ -12,2 +12,3 @@ "use strict";

const logger_1 = require("@pnpm/logger");
const got = require("got");
const git = require("graceful-git");

@@ -18,61 +19,60 @@ const parsePref_1 = require("./parsePref");

function default_1(opts) {
return resolveGit.bind(null, tryResolveViaGitHubApi.bind(null, opts.getJson));
}
exports.default = default_1;
function resolveGit(tryResolveViaGitHubApiBySpec, wantedDependency) {
return __awaiter(this, void 0, void 0, function* () {
const parsedSpec = parsePref_1.default(wantedDependency.pref);
if (!parsedSpec)
return null;
const isGitHubHosted = parsedSpec.hosted && parsedSpec.hosted.type === 'github';
if (!isGitHubHosted || isSsh(wantedDependency.pref)) {
const commit = yield resolveRef(parsedSpec.fetchSpec, parsedSpec.gitCommittish || 'master');
return {
id: parsedSpec.fetchSpec
.replace(/^.*:\/\/(git@)?/, '')
.replace(/:/g, '+')
.replace(/\.git$/, '') + '/' + commit,
normalizedPref: parsedSpec.normalizedPref,
resolution: {
commit,
repo: parsedSpec.fetchSpec,
type: 'git',
},
return function resolveGit(wantedDependency) {
return __awaiter(this, void 0, void 0, function* () {
const parsedSpec = parsePref_1.default(wantedDependency.pref);
if (!parsedSpec)
return null;
const isGitHubHosted = parsedSpec.hosted && parsedSpec.hosted.type === 'github';
if (!isGitHubHosted || isSsh(wantedDependency.pref)) {
const commit = yield resolveRef(parsedSpec.fetchSpec, parsedSpec.gitCommittish || 'master');
return {
id: parsedSpec.fetchSpec
.replace(/^.*:\/\/(git@)?/, '')
.replace(/:/g, '+')
.replace(/\.git$/, '') + '/' + commit,
normalizedPref: parsedSpec.normalizedPref,
resolution: {
commit,
repo: parsedSpec.fetchSpec,
type: 'git',
},
};
}
const parts = normalizeRepoUrl(parsedSpec).split('#');
const repo = parts[0];
const ghSpec = {
project: parsedSpec.hosted.project,
ref: parsedSpec.hosted.committish || 'HEAD',
user: parsedSpec.hosted.user,
};
}
const parts = normalizeRepoUrl(parsedSpec).split('#');
const repo = parts[0];
const ghSpec = {
project: parsedSpec.hosted.project,
ref: parsedSpec.hosted.committish || 'HEAD',
user: parsedSpec.hosted.user,
};
let commitId;
if (tryGitHubApi) {
try {
commitId = yield tryResolveViaGitHubApiBySpec(ghSpec);
let commitId;
if (tryGitHubApi) {
try {
commitId = yield tryResolveViaGitHubApi(ghSpec);
}
catch (err) {
gitLogger.warn({
err,
message: `Error while trying to resolve ${parsedSpec.fetchSpec} via GitHub API`,
});
// if it fails once, don't bother retrying for other packages
tryGitHubApi = false;
commitId = yield resolveRef(repo, ghSpec.ref);
}
}
catch (err) {
gitLogger.warn({
err,
message: `Error while trying to resolve ${parsedSpec.fetchSpec} via GitHub API`,
});
// if it fails once, don't bother retrying for other packages
tryGitHubApi = false;
else {
commitId = yield resolveRef(repo, ghSpec.ref);
}
}
else {
commitId = yield resolveRef(repo, ghSpec.ref);
}
const tarballResolution = {
tarball: `https://codeload.github.com/${ghSpec.user}/${ghSpec.project}/tar.gz/${commitId}`,
};
return {
id: ['github.com', ghSpec.user, ghSpec.project, commitId].join('/'),
normalizedPref: parsedSpec.normalizedPref,
resolution: tarballResolution,
};
});
const tarballResolution = {
tarball: `https://codeload.github.com/${ghSpec.user}/${ghSpec.project}/tar.gz/${commitId}`,
};
return {
id: ['github.com', ghSpec.user, ghSpec.project, commitId].join('/'),
normalizedPref: parsedSpec.normalizedPref,
resolution: tarballResolution,
};
});
};
}
exports.default = default_1;
function resolveRef(repo, ref) {

@@ -100,3 +100,3 @@ return __awaiter(this, void 0, void 0, function* () {

*/
function tryResolveViaGitHubApi(getJson, spec) {
function tryResolveViaGitHubApi(spec) {
return __awaiter(this, void 0, void 0, function* () {

@@ -110,7 +110,6 @@ const url = [

].join('/');
// TODO: investigate what should be the correct registry path here
const body = yield getJson(url, url);
return body.sha;
const response = yield got(url, { json: true });
return response.body.sha;
});
}
//# sourceMappingURL=index.js.map
{
"name": "@pnpm/git-resolver",
"version": "0.2.0",
"version": "0.3.0",
"description": "Resolver for git-hosted packages",

@@ -41,2 +41,3 @@ "main": "lib/index.js",

"@types/node": "^8.0.53",
"got": "^8.0.1",
"graceful-git": "^1.0.1",

@@ -49,3 +50,2 @@ "hosted-git-info": "^2.5.0",

"@types/tape": "^4.2.31",
"got": "^8.0.0",
"mos": "^2.0.0-alpha.3",

@@ -52,0 +52,0 @@ "mos-plugin-readme": "^1.0.4",

@@ -20,10 +20,9 @@ # @pnpm/git-resolver

'use strict'
const got = require('got')
const createResolveFromNpm = require('@pnpm/git-resolver').default
const resolveFromNpm = createResolveFromNpm({getJson})
const resolveFromNpm = createResolveFromNpm({})
resolveFromNpm({
pref: 'kevva/is-negative#16fd36fe96106175d02d066171c44e2ff83bc055'
}, { getJson })
})
.then(resolveResult => console.log(JSON.stringify(resolveResult, null, 2)))

@@ -37,7 +36,2 @@ //> {

// }
function getJson (url, registry) {
return got(url, {json: true})
.then(response => response.body)
}
```

@@ -44,0 +38,0 @@ <!--/@-->

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc