MCPcopy
hub / github.com/webpack/webpack / getGitUrlVersion

Function getGitUrlVersion

lib/sharing/utils.js:246–293  ·  view source on GitHub ↗

* get right dep version from git url * @param {string} gitUrl git url * @returns {string} dep version

(gitUrl)

Source from the content-addressed store, hash-verified

244 * @returns {string} dep version
245 */
246function getGitUrlVersion(gitUrl) {
247 const oriGitUrl = gitUrl;
248 // github extreme shorthand
249 gitUrl = RE_URL_GITHUB_EXTREME_SHORT.test(gitUrl)
250 ? `github:${gitUrl}`
251 : correctProtocol(gitUrl);
252
253 gitUrl = correctUrl(gitUrl);
254
255 /** @type {undefined | URL} */
256 let parsed;
257
258 try {
259 parsed = new URL(gitUrl);
260 // eslint-disable-next-line no-empty
261 } catch (_err) {}
262
263 if (!parsed) {
264 return "";
265 }
266
267 const { protocol, hostname, pathname, username, password } = parsed;
268 if (!RE_PROTOCOL.test(protocol)) {
269 return "";
270 }
271
272 // pathname shouldn't be empty or URL malformed
273 if (!pathname || !canBeDecoded(pathname)) {
274 return "";
275 }
276
277 // without protocol, there should have auth info
278 if (RE_NO_PROTOCOL.test(oriGitUrl) && !username && !password) {
279 return "";
280 }
281
282 if (!PROTOCOLS_FOR_SHORT.includes(protocol.toLowerCase())) {
283 if (!RE_HOSTNAME.test(hostname)) {
284 return "";
285 }
286
287 const commithash = getCommithash(parsed);
288 return getVersionFromHash(commithash) || commithash;
289 }
290
291 // for protocol short
292 return getVersionFromHash(gitUrl);
293}
294
295/** @typedef {{ data: JsonObject, path: string }} DescriptionFile */
296

Callers 1

normalizeVersionFunction · 0.85

Calls 6

correctProtocolFunction · 0.85
correctUrlFunction · 0.85
canBeDecodedFunction · 0.85
getCommithashFunction · 0.85
getVersionFromHashFunction · 0.85
testMethod · 0.45

Tested by

no test coverage detected