|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -const {fetchFromCache} = require('./lib/cache'); |
18 |
| - |
19 |
| -const OMAHA_PROXY_JSON = 'https://omahaproxy.appspot.com/all.json'; |
20 |
| -const SCHEDULE_JSON = |
21 |
| - 'https://chromiumdash.appspot.com/fetch_milestone_schedule'; |
22 |
| - |
23 |
| -// these OS' have weird releases, don't include |
24 |
| -const SKIP_OS = ['webview', 'ios']; |
25 |
| - |
26 |
| -/** |
27 |
| - * Finds the major Chrome release version from the passed string that looks like "84.0.1231.11". |
28 |
| - * |
29 |
| - * @param {string} raw |
30 |
| - * @return {number} |
31 |
| - */ |
32 |
| -function extractMajorVersion(raw) { |
33 |
| - // this is [major, minor, branch, patch] |
34 |
| - const [major] = raw.split('.').map(x => parseInt(x) || 0); |
35 |
| - return major; |
36 |
| -} |
37 |
| - |
38 |
| -/** |
39 |
| - * Fetches Chrome release data for a major version from the Chromium Dashboard. Can return null |
40 |
| - * if the version or data returned is invalid. |
41 |
| - * |
42 |
| - * @param {string} channel |
43 |
| - * @param {number} version |
44 |
| - * @return {Promise<ChromeReleaseData?>} |
45 |
| - */ |
46 |
| -async function dataForVersion(channel, version) { |
47 |
| - const url = `${SCHEDULE_JSON}?mstone=${version}`; |
48 |
| - const json = await fetchFromCache(url); |
49 |
| - |
50 |
| - // We expect this to be shaped like {mstones: [{...}]}, with just a single item returned. |
51 |
| - |
52 |
| - if (!('mstones' in json) || !json['mstones'][0]) { |
53 |
| - return null; |
54 |
| - } |
55 |
| - const data = json['mstones'][0]; |
56 |
| - if (!('stable_date' in data) || data['mstone'] !== version) { |
57 |
| - return null; |
58 |
| - } |
59 |
| - |
60 |
| - // The underlying data contains useful keys "stable_date", "earliest_beta" and "final_beta", |
61 |
| - // among others, most of which are currently ignored. |
62 |
| - |
63 |
| - return { |
64 |
| - mstone: version, |
65 |
| - key: channel, |
66 |
| - stableDate: new Date(data['stable_date']), |
67 |
| - }; |
68 |
| -} |
| 17 | +const fs = require('fs'); |
| 18 | +const path = require('path'); |
69 | 19 |
|
70 | 20 | /**
|
71 | 21 | * Generates Chrome version information.
|
72 |
| - * |
73 |
| - * While there are many channels, we just care about 'stable' and 'beta'. This method returns a |
74 |
| - * value for both. |
75 |
| - * |
76 |
| - * Beta is not always stable+1 in the underlying data, it can either be stable+0 or stable+2 |
77 |
| - * depending on the point in the release cycle. |
78 |
| - * |
79 |
| - * @return {!Promise<{channels: !Object<string, !Object>}>} |
80 | 22 | */
|
81 | 23 | module.exports = async function buildVersionInformation() {
|
82 |
| - const json = await fetchFromCache(OMAHA_PROXY_JSON); |
83 |
| - |
84 |
| - /** @type {{[channel: string]: number}} */ |
85 |
| - const raw = {}; |
86 |
| - |
87 |
| - // Find the current version for every channel. The published data returns the versions for each |
88 |
| - // operating system. We take the highest major version found across each OS and use that. |
89 |
| - for (const {os, versions} of json) { |
90 |
| - if (SKIP_OS.includes(os)) { |
91 |
| - continue; |
92 |
| - } |
93 |
| - |
94 |
| - for (const {channel, version} of versions) { |
95 |
| - if (!['stable', 'beta'].includes(channel)) { |
96 |
| - continue; |
97 |
| - } |
98 |
| - const majorVersion = extractMajorVersion(version); |
99 |
| - if (majorVersion === 0) { |
100 |
| - continue; |
101 |
| - } |
102 |
| - raw[channel] = Math.max(raw[channel] ?? 0, majorVersion); |
103 |
| - } |
104 |
| - } |
| 24 | + const chromeReleaseDataFile = path.join( |
| 25 | + __dirname, |
| 26 | + '../../external/data/chrome-release.json' |
| 27 | + ); |
| 28 | + const data = /** @type {{channels: Object<string, ChromeReleaseData>}} */ ( |
| 29 | + JSON.parse(fs.readFileSync(chromeReleaseDataFile, 'utf-8')) |
| 30 | + ); |
105 | 31 |
|
106 |
| - // Sanity-check that we have 'stable', and if we have 'beta', that it's one or two higher. |
107 |
| - // Create the virtual 'pending' if it's two higher. |
108 |
| - if (!('stable' in raw) || raw['beta'] < raw['stable']) { |
109 |
| - console.warn(raw); |
110 |
| - throw new Error('bad Chrome release data, no stable or beta < stable'); |
111 |
| - } |
112 |
| - if (!('beta' in raw) || raw['beta'] === raw['stable']) { |
113 |
| - // pretend beta is stable+1 if it's not here or beta===stable |
114 |
| - raw['beta'] = raw['stable'] + 1; |
| 32 | + for (const channel in data.channels) { |
| 33 | + const o = data.channels[channel]; |
| 34 | + // JSON-encoding flattens this to a string, so reconstruct the Date. |
| 35 | + o.stableDate = new Date(o.stableDate); |
115 | 36 | }
|
116 |
| - const {beta, stable} = raw; |
117 |
| - if (beta === stable + 1) { |
118 |
| - // great |
119 |
| - } else if (beta === stable + 2) { |
120 |
| - // This can occur if Chrome does something weird with releases, basically the previous beta |
121 |
| - // is about to be released but it's not done yet. |
122 |
| - raw['pending'] = stable + 1; |
123 |
| - } else { |
124 |
| - console.warn(raw); |
125 |
| - throw new Error('bad Chrome release data, beta is >+2 from stable'); |
126 |
| - } |
127 |
| - |
128 |
| - // Now that we have all major versions, look up and/or cache the schedule for each version. This |
129 |
| - // might be the same version for multiple channels, but Eleventy is caching the result for us. |
130 |
| - |
131 |
| - /** @type {(arg: [string, number]) => Promise<[string, ChromeReleaseData]>} */ |
132 |
| - const fetchChannelData = async ([channel, mstone]) => { |
133 |
| - const data = await dataForVersion(channel, mstone); |
134 |
| - if (!data) { |
135 |
| - throw new Error(`couldn't fetch data for Chrome ${mstone}`); |
136 |
| - } |
137 |
| - return [channel, data]; |
138 |
| - }; |
139 |
| - |
140 |
| - const channels = Object.fromEntries( |
141 |
| - await Promise.all(Object.entries(raw).map(fetchChannelData)) |
142 |
| - ); |
143 | 37 |
|
144 |
| - return {channels}; |
| 38 | + return data; |
145 | 39 | };
|
0 commit comments