MCPcopy
hub / github.com/prisma/prisma / getCurrentPatchForPatchVersions

Function getCurrentPatchForPatchVersions

scripts/ci/publish.ts:249–305  ·  view source on GitHub ↗
(patchMajorMinor: { major: number; minor: number })

Source from the content-addressed store, hash-verified

247// and filters that array down to the major and minor of the patch branch
248// to figure out what the current highest patch number there currently is
249async function getCurrentPatchForPatchVersions(patchMajorMinor: { major: number; minor: number }): Promise<number> {
250 // TODO: could we add the name of the branch, as well as the relevant versions => faster
251 // $ npm view '@prisma/client@3.0.x' version --json
252 // [
253 // "3.0.1",
254 // "3.0.2"
255 // ]
256
257 // We retry a few times if it fails
258 // npm can have some hiccups
259 const remoteVersionsString = await pRetry(
260 async () => {
261 return await runResult('.', 'npm view @prisma/client@* version --json')
262 },
263 {
264 retries: 6,
265 onFailedAttempt: (e) => {
266 console.error(e)
267 },
268 },
269 )
270 let versions = JSON.parse(remoteVersionsString)
271
272 // inconsistent npm api
273 if (!Array.isArray(versions)) {
274 versions = [versions]
275 }
276
277 const relevantVersions: Array<{
278 major: number
279 minor: number
280 patch: number
281 }> = versions
282 .map((v) => {
283 const match = semverRegex.exec(v)
284 if (match?.groups) {
285 return {
286 major: Number(match.groups.major),
287 minor: Number(match.groups.minor),
288 patch: Number(match.groups.patch),
289 }
290 }
291 return null
292 })
293 .filter((group) => group && group.minor === patchMajorMinor.minor && group.major === patchMajorMinor.major)
294
295 if (relevantVersions.length === 0) {
296 return 0
297 }
298
299 // sort descending by patch
300 relevantVersions.sort((a, b) => {
301 return a.patch < b.patch ? 1 : -1
302 })
303
304 return relevantVersions[0].patch
305}
306

Callers 1

getNewPatchDevVersionFunction · 0.85

Calls 3

runResultFunction · 0.85
errorMethod · 0.80
parseMethod · 0.65

Tested by

no test coverage detected