MCPcopy Create free account
hub / github.com/angular/angular / VersionManager

Class VersionManager

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

Source from the content-addressed store, hash-verified

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

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