query-registry
Advanced tools
Comparing version 2.5.0 to 2.6.0
@@ -12,2 +12,17 @@ # Changelog | ||
## [2.5.0] - 2022-05-28 | ||
### Added | ||
- N/A | ||
### Changed | ||
- Fixed ESM export declarations in `package.json` (Thanks @mt-empty) | ||
- Updated dependencies and dev dependencies | ||
### Removed | ||
- N/A | ||
## [2.4.0] - 2022-05-11 | ||
@@ -88,3 +103,3 @@ | ||
[unreleased]: https://github.com/velut/node-query-registry/compare/v2.4.0...HEAD | ||
[unreleased]: https://github.com/velut/node-query-registry/compare/v2.5.0...HEAD | ||
[2.0.0]: https://github.com/velut/node-query-registry/compare/v1.2.0...v2.0.0 | ||
@@ -94,1 +109,2 @@ [2.2.0]: https://github.com/velut/node-query-registry/compare/v2.0.0...v2.2.0 | ||
[2.4.0]: https://github.com/velut/node-query-registry/compare/v2.3.0...v2.4.0 | ||
[2.5.0]: https://github.com/velut/node-query-registry/compare/v2.4.0...v2.5.0 |
@@ -10,3 +10,2 @@ 'use strict'; | ||
var urlJoin = require('url-join'); | ||
var gitUrlParse = require('git-url-parse'); | ||
@@ -38,3 +37,2 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var urlJoin__default = /*#__PURE__*/_interopDefaultLegacy(urlJoin); | ||
var gitUrlParse__default = /*#__PURE__*/_interopDefaultLegacy(gitUrlParse); | ||
@@ -827,24 +825,16 @@ /** | ||
url, | ||
directory: repositoryDir | ||
directory | ||
} = rawRepository; | ||
const info = parseGitURL({ | ||
const parsedUrl = parseGitURL({ | ||
url | ||
}); | ||
if (!info) { | ||
if (!parsedUrl) { | ||
return undefined; | ||
} | ||
const { | ||
resource, | ||
full_name: repositoryID, | ||
filepath | ||
} = info; // Add domain to sources derived from npm-style shortcuts | ||
const host = resource.replace(/^$/, 'github.com').replace(/^github$/, 'github.com').replace(/^gitlab$/, 'gitlab.com').replace(/^bitbucket$/, 'bitbucket.org'); | ||
const parsedDir = filepath !== '' ? filepath : undefined; | ||
return { | ||
type: 'git', | ||
url: `https://${host}/${repositoryID}`, | ||
directory: repositoryDir != null ? repositoryDir : parsedDir | ||
url: parsedUrl, | ||
directory | ||
}; | ||
@@ -856,9 +846,35 @@ } | ||
}) { | ||
let info; | ||
const urlWithProtocol = url.includes(':') ? // A normal URL or a shortcut like `github:user/repository` | ||
url : // The short form github shortcut `user/repository` | ||
url.includes('/') ? `github:${url}` : // Not a URL | ||
''; | ||
try { | ||
info = gitUrlParse__default["default"](url); | ||
} catch {} | ||
const { | ||
protocol, | ||
hostname, | ||
pathname | ||
} = new URL(urlWithProtocol); | ||
const cleanPathname = pathname.replace(/\.git$/, ''); | ||
return info; | ||
if (protocol === 'github:' || hostname === 'github.com') { | ||
return urlJoin__default["default"]('https://github.com', cleanPathname); | ||
} | ||
if (protocol === 'gist:' || hostname === 'gist.github.com') { | ||
return urlJoin__default["default"]('https://gist.github.com', cleanPathname); | ||
} | ||
if (protocol === 'bitbucket:' || hostname === 'bitbucket.org') { | ||
return urlJoin__default["default"]('https://bitbucket.org', cleanPathname); | ||
} | ||
if (protocol === 'gitlab:' || hostname === 'gitlab.com') { | ||
return urlJoin__default["default"]('https://gitlab.com', cleanPathname); | ||
} | ||
return urlWithProtocol; | ||
} catch { | ||
return undefined; | ||
} | ||
} | ||
@@ -865,0 +881,0 @@ |
@@ -1,2 +0,2 @@ | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("validate-npm-package-name"),e=require("make-error"),t=require("isomorphic-unfetch"),n=require("tiny-lru"),a=require("url-join"),i=require("git-url-parse");function s(r){return r&&"object"==typeof r&&"default"in r?r:{default:r}}var o=s(r),c=s(e),d=s(t),u=s(n),p=s(a),y=s(i);const g=["https://registry.npmjs.cf","https://registry.yarnpkg.com"];class l extends e.BaseError{constructor(r,e){super(`fetch: request to ${r} failed with status ${e.statusText}`),this.url=void 0,this.response=void 0,this.url=r,this.response=e}}const m=c.default("InvalidPackageNameError"),f=c.default("InvalidPackageVersionError");async function h(r,...e){}function w({name:r}){const{validForOldPackages:e,validForNewPackages:t}=o.default(r);if(!e&&!t)throw h(),new m(`invalid package name: '${r}'`)}const P=u.default(250,3e5);async function k({url:r,headers:e,cached:t=!0}){const n=`headers=${JSON.stringify(e)};url=${r}`,a=P.get(n);if(t&&a)return h(),a;const i=await d.default(r,{headers:e});if(!i.ok)throw h(),new l(r,i);const s=await i.json();return t&&P.set(n,s),h(),s}async function v({endpoint:r,headers:e,query:t,registry:n="https://registry.npmjs.org",mirrors:a=g,cached:i}){const s=[n,...a].map((e=>p.default(e,r,t?`?${t}`:"")));let o;for(const r of s)try{return await k({url:r,headers:e,cached:i})}catch(r){o=r}throw h(),o}async function $({name:r,registry:e,mirrors:t,cached:n}){return w({name:r}),v({endpoint:`/${r}`,headers:{Accept:"application/vnd.npm.install-v1+json"},registry:e,mirrors:t,cached:n})}async function b({endpoint:r,registryDownloadsAPI:e="https://api.npmjs.org",cached:t}){return v({endpoint:r,registry:e,mirrors:[],cached:t})}function x({rawDownloadPeriod:r="last-week"}){if("string"==typeof r)return r;if(r instanceof Date)return D(r);const{start:e,end:t}=r;return`${D(e)}:${D(t)}`}function D(r){return r.toISOString().split("T")[0]}function R({rawPackument:r,version:e="latest"}){var t;const{name:n,"dist-tags":a,versions:i}=r,s=i[null!=(t=a[e])?t:e];if(!s)throw h(),new f(`invalid package version: '${n}@${e}'`);return s}async function A({name:r,registry:e,mirrors:t,cached:n}){return w({name:r}),v({endpoint:`/${r}`,registry:e,mirrors:t,cached:n})}async function j({name:r,version:e,registry:t,mirrors:n,cached:a}){return R({rawPackument:await A({name:r,registry:t,mirrors:n,cached:a}),version:e})}function I({rawLicense:r}){if(r&&"string"==typeof r)return r}function q({rawRepository:r}){return function(r){return r&&"object"==typeof r&&"string"==typeof r.url&&["string","undefined"].includes(typeof r.type)&&["string","undefined"].includes(typeof r.directory)}(r)?_({rawRepository:r}):"string"==typeof r?_({rawRepository:{url:r}}):void 0}function _({rawRepository:r}){const{url:e,directory:t}=r,n=function({url:r}){let e;try{e=y.default(r)}catch{}return e}({url:e});if(!n)return;const{resource:a,full_name:i,filepath:s}=n;return{type:"git",url:`https://${a.replace(/^$/,"github.com").replace(/^github$/,"github.com").replace(/^gitlab$/,"gitlab.com").replace(/^bitbucket$/,"bitbucket.org")}/${i}`,directory:null!=t?t:""!==s?s:void 0}}exports.FetchError=l,exports.InvalidPackageNameError=m,exports.InvalidPackageVersionError=f,exports.cloudflareRegistry="https://registry.npmjs.cf",exports.getAbbreviatedPackument=async function({name:r,registry:e,mirrors:t,cached:n}){return function({rawAbbreviatedPackument:r}){const{"dist-tags":e,name:t,modified:n}=r;return{...r,id:t,distTags:e,modifiedAt:n}}({rawAbbreviatedPackument:await $({name:r,registry:e,mirrors:t,cached:n})})},exports.getDailyPackageDownloads=async function({name:r,period:e,registryDownloadsAPI:t,cached:n}){return w({name:r}),b({endpoint:`/downloads/range/${x({rawDownloadPeriod:e})}/${r}`,registryDownloadsAPI:t,cached:n})},exports.getDailyRegistryDownloads=async function({period:r,registryDownloadsAPI:e,cached:t}={}){return b({endpoint:`/downloads/range/${x({rawDownloadPeriod:r})}`,registryDownloadsAPI:e,cached:t})},exports.getPackageDownloads=async function({name:r,period:e,registryDownloadsAPI:t,cached:n}){return w({name:r}),b({endpoint:`/downloads/point/${x({rawDownloadPeriod:e})}/${r}`,registryDownloadsAPI:t,cached:n})},exports.getPackageManifest=async function({name:r,version:e,registry:t,mirrors:n,cached:a}){const i=await A({name:r,registry:t,mirrors:n,cached:a}),s=R({rawPackument:i,version:e});return await async function({rawPackageManifest:r,rawPackument:e,registry:t,mirrors:n,cached:a}){const{_id:i,name:s,version:o,license:c,repository:d,_npmUser:u}=r,p=e.time[o],y=I({rawLicense:c}),g=q({rawRepository:d}),l=await async function({rawPackageManifest:r,registry:e,mirrors:t,cached:n}){const{name:a,types:i,typings:s}=r,o=function({name:r}){return r.startsWith("@types/")?r:`@types/${r.replace("@","").replace("/","__")}`}({name:a});if(a===o||i||s)return;let c=!1;try{const{deprecated:r}=await j({name:o,registry:e,mirrors:t,cached:n});c=void 0===r}catch{}return c?o:void 0}({rawPackageManifest:r,registry:t,mirrors:n,cached:a}),m=function({name:r}){if(!r.startsWith("@types/"))return;const[e,t]=r.replace("@types/","").split("__");return t?`@${e}/${t}`:e}({name:s});return{...r,id:i,createdAt:p,publisher:u,license:y,gitRepository:g,definitelyTypedName:l,untypedName:m}}({rawPackageManifest:s,rawPackument:i,registry:t,mirrors:n,cached:a})},exports.getPackument=async function({name:r,registry:e,mirrors:t,cached:n}){return function({rawPackument:r}){const{_id:e,"dist-tags":t,time:n,license:a,repository:i}=r,s=I({rawLicense:a}),o=q({rawRepository:i}),c=Object.fromEntries(Object.entries(n).filter((([r])=>!["created","modified"].includes(r))));return{...r,id:e,distTags:t,versionsToTimestamps:c,license:s,gitRepository:o}}({rawPackument:await A({name:r,registry:e,mirrors:t,cached:n})})},exports.getRawAbbreviatedPackument=$,exports.getRawPackageManifest=j,exports.getRawPackument=A,exports.getRegistryDownloads=async function({period:r,registryDownloadsAPI:e,cached:t}={}){return b({endpoint:`/downloads/point/${x({rawDownloadPeriod:r})}`,registryDownloadsAPI:e,cached:t})},exports.getRegistryMetadata=async function({registry:r,cached:e}={}){return v({registry:r,mirrors:[],endpoint:"/",cached:e})},exports.npmRegistry="https://registry.npmjs.org",exports.npmRegistryDownloadsAPI="https://api.npmjs.org",exports.npmRegistryMirrors=g,exports.searchPackages=async function({query:r,registry:e,mirrors:t,cached:n}){const a=function({rawSearchCriteria:r}){return Object.entries(r).filter((([,r])=>["string","number"].includes(typeof r))).map((([r,e])=>`${r}=${e}`)).join("&")}({rawSearchCriteria:r});return v({endpoint:"/-/v1/search",query:a,registry:e,mirrors:t,cached:n})},exports.yarnRegistry="https://registry.yarnpkg.com"; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("validate-npm-package-name"),r=require("make-error"),t=require("isomorphic-unfetch"),n=require("tiny-lru"),a=require("url-join");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=i(e),o=i(r),c=i(t),d=i(n),u=i(a);const p=["https://registry.npmjs.cf","https://registry.yarnpkg.com"];class g extends r.BaseError{constructor(e,r){super(`fetch: request to ${e} failed with status ${r.statusText}`),this.url=void 0,this.response=void 0,this.url=e,this.response=r}}const y=o.default("InvalidPackageNameError"),m=o.default("InvalidPackageVersionError");async function l(e,...r){}function f({name:e}){const{validForOldPackages:r,validForNewPackages:t}=s.default(e);if(!r&&!t)throw l(),new y(`invalid package name: '${e}'`)}const h=d.default(250,3e5);async function w({url:e,headers:r,cached:t=!0}){const n=`headers=${JSON.stringify(r)};url=${e}`,a=h.get(n);if(t&&a)return l(),a;const i=await c.default(e,{headers:r});if(!i.ok)throw l(),new g(e,i);const s=await i.json();return t&&h.set(n,s),l(),s}async function P({endpoint:e,headers:r,query:t,registry:n="https://registry.npmjs.org",mirrors:a=p,cached:i}){const s=[n,...a].map((r=>u.default(r,e,t?`?${t}`:"")));let o;for(const e of s)try{return await w({url:e,headers:r,cached:i})}catch(e){o=e}throw l(),o}async function k({name:e,registry:r,mirrors:t,cached:n}){return f({name:e}),P({endpoint:`/${e}`,headers:{Accept:"application/vnd.npm.install-v1+json"},registry:r,mirrors:t,cached:n})}async function v({endpoint:e,registryDownloadsAPI:r="https://api.npmjs.org",cached:t}){return P({endpoint:e,registry:r,mirrors:[],cached:t})}function b({rawDownloadPeriod:e="last-week"}){if("string"==typeof e)return e;if(e instanceof Date)return $(e);const{start:r,end:t}=e;return`${$(r)}:${$(t)}`}function $(e){return e.toISOString().split("T")[0]}function x({rawPackument:e,version:r="latest"}){var t;const{name:n,"dist-tags":a,versions:i}=e,s=i[null!=(t=a[r])?t:r];if(!s)throw l(),new m(`invalid package version: '${n}@${r}'`);return s}async function D({name:e,registry:r,mirrors:t,cached:n}){return f({name:e}),P({endpoint:`/${e}`,registry:r,mirrors:t,cached:n})}async function R({name:e,version:r,registry:t,mirrors:n,cached:a}){return x({rawPackument:await D({name:e,registry:t,mirrors:n,cached:a}),version:r})}function A({rawLicense:e}){if(e&&"string"==typeof e)return e}function j({rawRepository:e}){return function(e){return e&&"object"==typeof e&&"string"==typeof e.url&&["string","undefined"].includes(typeof e.type)&&["string","undefined"].includes(typeof e.directory)}(e)?I({rawRepository:e}):"string"==typeof e?I({rawRepository:{url:e}}):void 0}function I({rawRepository:e}){const{url:r,directory:t}=e,n=function({url:e}){const r=e.includes(":")?e:e.includes("/")?`github:${e}`:"";try{const{protocol:e,hostname:t,pathname:n}=new URL(r),a=n.replace(/\.git$/,"");return"github:"===e||"github.com"===t?u.default("https://github.com",a):"gist:"===e||"gist.github.com"===t?u.default("https://gist.github.com",a):"bitbucket:"===e||"bitbucket.org"===t?u.default("https://bitbucket.org",a):"gitlab:"===e||"gitlab.com"===t?u.default("https://gitlab.com",a):r}catch{return}}({url:r});if(n)return{type:"git",url:n,directory:t}}exports.FetchError=g,exports.InvalidPackageNameError=y,exports.InvalidPackageVersionError=m,exports.cloudflareRegistry="https://registry.npmjs.cf",exports.getAbbreviatedPackument=async function({name:e,registry:r,mirrors:t,cached:n}){return function({rawAbbreviatedPackument:e}){const{"dist-tags":r,name:t,modified:n}=e;return{...e,id:t,distTags:r,modifiedAt:n}}({rawAbbreviatedPackument:await k({name:e,registry:r,mirrors:t,cached:n})})},exports.getDailyPackageDownloads=async function({name:e,period:r,registryDownloadsAPI:t,cached:n}){return f({name:e}),v({endpoint:`/downloads/range/${b({rawDownloadPeriod:r})}/${e}`,registryDownloadsAPI:t,cached:n})},exports.getDailyRegistryDownloads=async function({period:e,registryDownloadsAPI:r,cached:t}={}){return v({endpoint:`/downloads/range/${b({rawDownloadPeriod:e})}`,registryDownloadsAPI:r,cached:t})},exports.getPackageDownloads=async function({name:e,period:r,registryDownloadsAPI:t,cached:n}){return f({name:e}),v({endpoint:`/downloads/point/${b({rawDownloadPeriod:r})}/${e}`,registryDownloadsAPI:t,cached:n})},exports.getPackageManifest=async function({name:e,version:r,registry:t,mirrors:n,cached:a}){const i=await D({name:e,registry:t,mirrors:n,cached:a}),s=x({rawPackument:i,version:r});return await async function({rawPackageManifest:e,rawPackument:r,registry:t,mirrors:n,cached:a}){const{_id:i,name:s,version:o,license:c,repository:d,_npmUser:u}=e,p=r.time[o],g=A({rawLicense:c}),y=j({rawRepository:d}),m=await async function({rawPackageManifest:e,registry:r,mirrors:t,cached:n}){const{name:a,types:i,typings:s}=e,o=function({name:e}){return e.startsWith("@types/")?e:`@types/${e.replace("@","").replace("/","__")}`}({name:a});if(a===o||i||s)return;let c=!1;try{const{deprecated:e}=await R({name:o,registry:r,mirrors:t,cached:n});c=void 0===e}catch{}return c?o:void 0}({rawPackageManifest:e,registry:t,mirrors:n,cached:a}),l=function({name:e}){if(!e.startsWith("@types/"))return;const[r,t]=e.replace("@types/","").split("__");return t?`@${r}/${t}`:r}({name:s});return{...e,id:i,createdAt:p,publisher:u,license:g,gitRepository:y,definitelyTypedName:m,untypedName:l}}({rawPackageManifest:s,rawPackument:i,registry:t,mirrors:n,cached:a})},exports.getPackument=async function({name:e,registry:r,mirrors:t,cached:n}){return function({rawPackument:e}){const{_id:r,"dist-tags":t,time:n,license:a,repository:i}=e,s=A({rawLicense:a}),o=j({rawRepository:i}),c=Object.fromEntries(Object.entries(n).filter((([e])=>!["created","modified"].includes(e))));return{...e,id:r,distTags:t,versionsToTimestamps:c,license:s,gitRepository:o}}({rawPackument:await D({name:e,registry:r,mirrors:t,cached:n})})},exports.getRawAbbreviatedPackument=k,exports.getRawPackageManifest=R,exports.getRawPackument=D,exports.getRegistryDownloads=async function({period:e,registryDownloadsAPI:r,cached:t}={}){return v({endpoint:`/downloads/point/${b({rawDownloadPeriod:e})}`,registryDownloadsAPI:r,cached:t})},exports.getRegistryMetadata=async function({registry:e,cached:r}={}){return P({registry:e,mirrors:[],endpoint:"/",cached:r})},exports.npmRegistry="https://registry.npmjs.org",exports.npmRegistryDownloadsAPI="https://api.npmjs.org",exports.npmRegistryMirrors=p,exports.searchPackages=async function({query:e,registry:r,mirrors:t,cached:n}){const a=function({rawSearchCriteria:e}){return Object.entries(e).filter((([,e])=>["string","number"].includes(typeof e))).map((([e,r])=>`${e}=${r}`)).join("&")}({rawSearchCriteria:e});return P({endpoint:"/-/v1/search",query:a,registry:r,mirrors:t,cached:n})},exports.yarnRegistry="https://registry.yarnpkg.com"; | ||
//# sourceMappingURL=query-registry.cjs.production.min.js.map |
@@ -1,2 +0,2 @@ | ||
import gitUrlParse from 'git-url-parse'; | ||
import urlJoin from 'url-join'; | ||
@@ -32,24 +32,16 @@ function normalizeRawRepository({ | ||
url, | ||
directory: repositoryDir | ||
directory | ||
} = rawRepository; | ||
const info = parseGitURL({ | ||
const parsedUrl = parseGitURL({ | ||
url | ||
}); | ||
if (!info) { | ||
if (!parsedUrl) { | ||
return undefined; | ||
} | ||
const { | ||
resource, | ||
full_name: repositoryID, | ||
filepath | ||
} = info; // Add domain to sources derived from npm-style shortcuts | ||
const host = resource.replace(/^$/, 'github.com').replace(/^github$/, 'github.com').replace(/^gitlab$/, 'gitlab.com').replace(/^bitbucket$/, 'bitbucket.org'); | ||
const parsedDir = filepath !== '' ? filepath : undefined; | ||
return { | ||
type: 'git', | ||
url: `https://${host}/${repositoryID}`, | ||
directory: repositoryDir != null ? repositoryDir : parsedDir | ||
url: parsedUrl, | ||
directory | ||
}; | ||
@@ -61,9 +53,35 @@ } | ||
}) { | ||
let info; | ||
const urlWithProtocol = url.includes(':') ? // A normal URL or a shortcut like `github:user/repository` | ||
url : // The short form github shortcut `user/repository` | ||
url.includes('/') ? `github:${url}` : // Not a URL | ||
''; | ||
try { | ||
info = gitUrlParse(url); | ||
} catch {} | ||
const { | ||
protocol, | ||
hostname, | ||
pathname | ||
} = new URL(urlWithProtocol); | ||
const cleanPathname = pathname.replace(/\.git$/, ''); | ||
return info; | ||
if (protocol === 'github:' || hostname === 'github.com') { | ||
return urlJoin('https://github.com', cleanPathname); | ||
} | ||
if (protocol === 'gist:' || hostname === 'gist.github.com') { | ||
return urlJoin('https://gist.github.com', cleanPathname); | ||
} | ||
if (protocol === 'bitbucket:' || hostname === 'bitbucket.org') { | ||
return urlJoin('https://bitbucket.org', cleanPathname); | ||
} | ||
if (protocol === 'gitlab:' || hostname === 'gitlab.com') { | ||
return urlJoin('https://gitlab.com', cleanPathname); | ||
} | ||
return urlWithProtocol; | ||
} catch { | ||
return undefined; | ||
} | ||
} | ||
@@ -70,0 +88,0 @@ |
{ | ||
"name": "query-registry", | ||
"description": "Query the npm registry for packuments, manifests, packages and download counts", | ||
"version": "2.5.0", | ||
"version": "2.6.0", | ||
"author": "Edoardo Scibona (velut)", | ||
@@ -62,3 +62,2 @@ "license": "MIT", | ||
"dependencies": { | ||
"git-url-parse": "^11.6.0", | ||
"isomorphic-unfetch": "^3.1.0", | ||
@@ -71,4 +70,4 @@ "make-error": "^1.3.6", | ||
"devDependencies": { | ||
"@commitlint/cli": "17.0.1", | ||
"@commitlint/config-conventional": "17.0.0", | ||
"@commitlint/cli": "17.0.3", | ||
"@commitlint/config-conventional": "17.0.3", | ||
"@pollyjs/adapter-node-http": "6.0.5", | ||
@@ -84,15 +83,15 @@ "@pollyjs/core": "6.0.5", | ||
"@types/url-join": "4.0.1", | ||
"@types/validate-npm-package-name": "3.0.3", | ||
"@types/validate-npm-package-name": "4.0.0", | ||
"debug": "4.3.4", | ||
"dts-cli": "1.5.1", | ||
"eslint-plugin-prettier": "4.0.0", | ||
"dts-cli": "1.5.2", | ||
"eslint-plugin-prettier": "4.2.1", | ||
"husky": "8.0.1", | ||
"nock": "13.2.4", | ||
"np": "7.6.1", | ||
"prettier": "2.6.2", | ||
"setup-polly-jest": "0.10.0", | ||
"ts-jest": "28.0.3", | ||
"nock": "13.2.9", | ||
"np": "7.6.2", | ||
"prettier": "2.7.1", | ||
"setup-polly-jest": "0.11.0", | ||
"ts-jest": "28.0.7", | ||
"tslib": "2.4.0", | ||
"typescript": "4.7.2" | ||
"typescript": "4.7.4" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
import gitUrlParse from 'git-url-parse'; | ||
import urlJoin from 'url-join'; | ||
import { GitRepository } from '../types/git-repository'; | ||
@@ -38,33 +38,44 @@ import { Repository } from '../types/repository'; | ||
}): GitRepository | undefined { | ||
const { url, directory: repositoryDir } = rawRepository; | ||
const { url, directory } = rawRepository; | ||
const info = parseGitURL({ url }); | ||
if (!info) { | ||
const parsedUrl = parseGitURL({ url }); | ||
if (!parsedUrl) { | ||
return undefined; | ||
} | ||
const { resource, full_name: repositoryID, filepath } = info; | ||
// Add domain to sources derived from npm-style shortcuts | ||
const host = resource | ||
.replace(/^$/, 'github.com') | ||
.replace(/^github$/, 'github.com') | ||
.replace(/^gitlab$/, 'gitlab.com') | ||
.replace(/^bitbucket$/, 'bitbucket.org'); | ||
const parsedDir = filepath !== '' ? filepath : undefined; | ||
return { | ||
type: 'git', | ||
url: `https://${host}/${repositoryID}`, | ||
directory: repositoryDir ?? parsedDir, | ||
url: parsedUrl, | ||
directory, | ||
}; | ||
} | ||
function parseGitURL({ url }: { url: string }): gitUrlParse.GitUrl | undefined { | ||
let info; | ||
function parseGitURL({ url }: { url: string }): string | undefined { | ||
const urlWithProtocol = url.includes(':') | ||
? // A normal URL or a shortcut like `github:user/repository` | ||
url | ||
: // The short form github shortcut `user/repository` | ||
url.includes('/') | ||
? `github:${url}` | ||
: // Not a URL | ||
''; | ||
try { | ||
info = gitUrlParse(url); | ||
} catch {} | ||
return info; | ||
const { protocol, hostname, pathname } = new URL(urlWithProtocol); | ||
const cleanPathname = pathname.replace(/\.git$/, ''); | ||
if (protocol === 'github:' || hostname === 'github.com') { | ||
return urlJoin('https://github.com', cleanPathname); | ||
} | ||
if (protocol === 'gist:' || hostname === 'gist.github.com') { | ||
return urlJoin('https://gist.github.com', cleanPathname); | ||
} | ||
if (protocol === 'bitbucket:' || hostname === 'bitbucket.org') { | ||
return urlJoin('https://bitbucket.org', cleanPathname); | ||
} | ||
if (protocol === 'gitlab:' || hostname === 'gitlab.com') { | ||
return urlJoin('https://gitlab.com', cleanPathname); | ||
} | ||
return urlWithProtocol; | ||
} catch { | ||
return undefined; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
403605
5
6136
2
- Removedgit-url-parse@^11.6.0
- Removedcall-bind@1.0.7(transitive)
- Removeddecode-uri-component@0.2.2(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedfilter-obj@1.1.0(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgit-up@4.0.5(transitive)
- Removedgit-url-parse@11.6.0(transitive)
- Removedgopd@1.0.1(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhasown@2.0.2(transitive)
- Removedis-ssh@1.4.0(transitive)
- Removednormalize-url@6.1.0(transitive)
- Removedobject-inspect@1.13.1(transitive)
- Removedparse-path@4.0.4(transitive)
- Removedparse-url@6.0.5(transitive)
- Removedprotocols@1.4.82.0.1(transitive)
- Removedqs@6.12.1(transitive)
- Removedquery-string@6.14.1(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedside-channel@1.0.6(transitive)
- Removedsplit-on-first@1.1.0(transitive)
- Removedstrict-uri-encode@2.0.0(transitive)