-
-
Notifications
You must be signed in to change notification settings - Fork 432
Expand file tree
/
Copy pathrouter.ts
More file actions
68 lines (61 loc) · 1.68 KB
/
router.ts
File metadata and controls
68 lines (61 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import type { RouteLocationRaw } from 'vue-router'
import { valid as isValidSingleVersion } from 'semver'
import { splitPackageName } from '~/utils/package-name'
export function packageRoute(
packageName: string,
version?: string | null,
hash?: string,
): RouteLocationRaw {
const { org, name } = splitPackageName(packageName)
if (version) {
if (isValidSingleVersion(version)) {
return {
name: 'package-version',
params: {
org,
name,
version,
},
}
}
// If we have a version param but it isn't a *specific, single version* (e.g. 1.2.3), treat it
// as a semver specifier (e.g. ^1.2.3 or * or 3||4 or >3<=5) and route to the package page with
// the semver query param, which will pre-populate the version selector and show matching versions.
return {
name: 'package',
params: {
org,
name,
},
query: { semver: version },
hash: hash ?? '#versions',
}
}
return {
name: 'package',
params: {
org,
name,
},
}
}
/** Full version history page (`/package/.../versions`) */
export function packageVersionsRoute(packageName: string): RouteLocationRaw {
const [org, name = ''] = packageName.startsWith('@') ? packageName.split('/') : ['', packageName]
return { name: 'package-versions', params: { org, name } }
}
export function diffRoute(
packageName: string,
fromVersion: string,
toVersion: string,
): RouteLocationRaw {
const { org, name } = splitPackageName(packageName)
return {
name: 'diff',
params: {
org: org || undefined,
packageName: name,
versionRange: `${fromVersion}...${toVersion}`,
},
}
}