diff options
Diffstat (limited to 'build/lib/policies.ts')
-rw-r--r-- | build/lib/policies.ts | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/build/lib/policies.ts b/build/lib/policies.ts index 62ea4d561e5..eaa8cb719a2 100644 --- a/build/lib/policies.ts +++ b/build/lib/policies.ts @@ -593,7 +593,7 @@ async function getLatestStableVersion(updateUrl: string) { return version; } -async function getNLS(resourceUrlTemplate: string, languageId: string, version: string) { +async function getSpecificNLS(resourceUrlTemplate: string, languageId: string, version: string) { const resource = { publisher: 'ms-ceintl', name: `vscode-language-pack-${languageId}`, @@ -603,10 +603,33 @@ async function getNLS(resourceUrlTemplate: string, languageId: string, version: const url = resourceUrlTemplate.replace(/\{([^}]+)\}/g, (_, key) => resource[key as keyof typeof resource]); const res = await fetch(url); + + if (res.status !== 200) { + throw new Error(`[${res.status}] Error downloading language pack ${languageId}@${version}`); + } + const { contents: result } = await res.json() as { contents: LanguageTranslations }; return result; } +function previousVersion(version: string): string { + const [, major, minor, patch] = /^(\d+)\.(\d+)\.(\d+)$/.exec(version)!; + return `${major}.${parseInt(minor) - 1}.${patch}`; +} + +async function getNLS(resourceUrlTemplate: string, languageId: string, version: string) { + try { + return await getSpecificNLS(resourceUrlTemplate, languageId, version); + } catch (err) { + if (/\[404\]/.test(err.message)) { + console.warn(`Language pack ${languageId}@${version} is missing. Downloading previous version...`); + return await getSpecificNLS(resourceUrlTemplate, languageId, previousVersion(version)); + } else { + throw err; + } + } +} + async function parsePolicies(): Promise<Policy[]> { const parser = new Parser(); parser.setLanguage(typescript); |