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

Class VersionManager

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

Source from the content-addressed store, hash-verified

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

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