MCPcopy Index your code
hub / github.com/angular/angular / VersionManager

Class VersionManager

adev/src/app/core/services/version-manager.service.ts:34–102  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32 */
33@Service()
34export class VersionManager {
35 private document = inject(DOCUMENT);
36
37 readonly currentDocsVersionMode = computed<VersionMode>(() => {
38 const hostname = this.document.location.hostname;
39 if (hostname.startsWith('v')) return 'deprecated';
40 if (hostname.startsWith('rc')) return 'rc';
41 if (hostname.startsWith('next')) return 'next';
42
43 return 'stable';
44 });
45
46 private localVersions = (versionJson as VersionJson[]).map((v) => {
47 return {
48 displayName: v.version,
49 url: v.url,
50 };
51 });
52
53 // This handle the fallback if the resource fails.
54 readonly versions = computed(() => {
55 return this.remoteVersions.hasValue() ? this.remoteVersions.value() : this.localVersions;
56 });
57
58 // Yes this will trigger a cors error on localhost
59 // but this is fine as we'll fallback to the local versions.json
60 // which is the most up-to-date anyway.
61 remoteVersions = httpResource(
62 () => ({
63 url: 'https://angular.dev/assets/others/versions.json',
64 transferCache: false,
65 cache: 'no-cache',
66 }),
67 {
68 parse: (json: unknown) => {
69 if (!Array.isArray(json)) {
70 throw new Error('Invalid version data');
71 }
72 return json.map((v: unknown) => {
73 if (
74 v === undefined ||
75 v === null ||
76 typeof v !== 'object' ||
77 !('version' in v) ||
78 !('url' in v) ||
79 typeof v.version !== 'string' ||
80 typeof v.url !== 'string'
81 ) {
82 throw new Error('Invalid version data');
83 }
84
85 return {
86 displayName: v.version,
87 url: v.url,
88 };
89 });
90 },
91 },

Callers

nothing calls this directly

Calls 7

injectFunction · 0.90
computedFunction · 0.90
mapMethod · 0.80
isArrayMethod · 0.80
hasValueMethod · 0.65
valueMethod · 0.65
findMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…