@@ -113,29 +113,31 @@ async function fetchComponentVersionsFromCache_(config, runtimeParameters) {
113
113
async function fetchComponentVersions_ ( config , runtimeParameters ) {
114
114
// Strip the leading two chars from the version identifier to get the release tag
115
115
const releaseTag = runtimeParameters . ampRuntimeVersion . substring ( 2 ) ;
116
- console . log ( 'releaseTag' , releaseTag ) ;
117
116
const componentConfigUrl = `https://raw.githubusercontent.com/ampproject/amphtml/${ releaseTag } /build-system/compile/bundles.config.extensions.json` ;
118
117
const componentLatestVersionsUrl = `https://raw.githubusercontent.com/ampproject/amphtml/${ releaseTag } /build-system/compile/bundles.legacy-latest-versions.jsonc` ;
118
+ const componentLatestVersionsUrlFallback = `https://raw.githubusercontent.com/ampproject/amphtml/main/build-system/compile/bundles.legacy-latest-versions.jsonc` ;
119
119
120
+ debugger ;
120
121
const configResponse = await config . fetch ( componentConfigUrl ) ;
121
- const latestVersionsConfigResponse = await config . fetch ( componentLatestVersionsUrl ) ;
122
+ let latestVersionsConfigResponse = await config . fetch ( componentLatestVersionsUrl ) ;
122
123
if ( ! configResponse . ok ) {
123
- console . log ( 'a' ) ;
124
- debugger ;
125
124
throw new Error (
126
125
`Failed fetching latest component versions from ${ URL_COMPONENT_VERSIONS } with status: ${ configResponse . status } `
127
126
) ;
128
127
}
129
- if ( ! latestVersionsConfig . ok ) {
130
- console . log ( 'b' ) ;
131
- debugger ;
132
- throw new Error (
133
- `Failed fetching latest component versions from ${ URL_COMPONENT_LATEST_VERSIONS } with status: ${ latestVersionsConfig . status } `
134
- ) ;
128
+ // If the fetch for the latestVersion jsonc file fails, we try again using the
129
+ // main branch since it might not exist yet in the old releaseTag. The latestVersion's
130
+ // are frozen so its unlikely to have changed.
131
+ if ( ! latestVersionsConfigResponse . ok ) {
132
+ latestVersionsConfigResponse = await config . fetch ( componentLatestVersionsUrlFallback ) ;
133
+ if ( ! latestVersionsConfigResponse . ok ) {
134
+ throw new Error (
135
+ `Failed fetching latest component versions from ${ URL_COMPONENT_LATEST_VERSIONS } with status: ${ latestVersionsConfig . status } `
136
+ ) ;
137
+ }
135
138
}
136
- console . log ( 'c' ) ;
137
- debugger ;
138
- return configResponse . json ( ) ;
139
+ const configJson = await configResponse . json ( ) ;
140
+ const latestVersionConfigJson = JSON5 . parse ( await latestVersionsConfigResponse . text ( ) ) ;
139
141
}
140
142
141
143
/**
0 commit comments