diff options
author | Tyler James Leonhardt <me@tylerleonhardt.com> | 2022-11-13 01:42:39 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-13 01:42:39 +0300 |
commit | 964dc545abd63c5f6f6c42755f1c11c2c912a0b5 (patch) | |
tree | e994f6eb0b17427c4c559991784261fd51489ade | |
parent | aa60836c16abb03839962354138aed04a9344968 (diff) |
Pickup bundle.l10n.json (#166169)
For npm modules that have bundled `@vscode/l10n`, they can export their strings to a bundle.l10n.json file which will get picked up by this change and included in the overall bundle for the extension.
-rw-r--r-- | build/lib/i18n.js | 24 | ||||
-rw-r--r-- | build/lib/i18n.ts | 27 |
2 files changed, 45 insertions, 6 deletions
diff --git a/build/lib/i18n.js b/build/lib/i18n.js index dcb3b7ddb30..4297b93d730 100644 --- a/build/lib/i18n.js +++ b/build/lib/i18n.js @@ -513,18 +513,36 @@ function createL10nBundleForExtension(extensionFolderName) { // For source code of extensions `extensions/${extensionFolderName}/src/**/*.{ts,tsx}`, // For any dependencies pulled in (think vscode-css-languageservice or @vscode/emmet-helper) - `extensions/${extensionFolderName}/node_modules/**/*.{js,jsx}` + `extensions/${extensionFolderName}/node_modules/**/*.{js,jsx}`, + // For any dependencies pulled in that bundle @vscode/l10n. They needed to export the bundle + `extensions/${extensionFolderName}/node_modules/**/bundle.l10n.json`, ]).pipe((0, event_stream_1.writeArray)((err, files) => { if (err) { result.emit('error', err); return; } - const json = (0, l10n_dev_1.getL10nJson)(files - .filter(file => file.isBuffer()) + const buffers = files.filter(file => file.isBuffer()); + const json = (0, l10n_dev_1.getL10nJson)(buffers + .filter(file => path.extname(file.path) !== '.json') .map(file => ({ contents: file.contents.toString('utf8'), extension: path.extname(file.path) }))); + buffers + .filter(file => path.extname(file.path) === '.json') + .forEach(file => { + const bundleJson = JSON.parse(file.contents.toString('utf8')); + for (const key in bundleJson) { + if ( + // some validation of the bundle.l10n.json format + typeof bundleJson[key] !== 'string' && + (typeof bundleJson[key].message !== 'string' || !Array.isArray(bundleJson[key].comment))) { + console.error(`Invalid bundle.l10n.json file. The value for key ${key} is not in the expected format. Skipping key...`); + continue; + } + json[key] = bundleJson[key]; + } + }); if (Object.keys(json).length > 0) { result.emit('data', new File({ path: `extensions/${extensionFolderName}/bundle.l10n.json`, diff --git a/build/lib/i18n.ts b/build/lib/i18n.ts index 58cce082343..85d1e2eebbf 100644 --- a/build/lib/i18n.ts +++ b/build/lib/i18n.ts @@ -585,20 +585,41 @@ function createL10nBundleForExtension(extensionFolderName: string): ThroughStrea // For source code of extensions `extensions/${extensionFolderName}/src/**/*.{ts,tsx}`, // For any dependencies pulled in (think vscode-css-languageservice or @vscode/emmet-helper) - `extensions/${extensionFolderName}/node_modules/**/*.{js,jsx}` + `extensions/${extensionFolderName}/node_modules/**/*.{js,jsx}`, + // For any dependencies pulled in that bundle @vscode/l10n. They needed to export the bundle + `extensions/${extensionFolderName}/node_modules/**/bundle.l10n.json`, ]).pipe(writeArray((err, files: File[]) => { if (err) { result.emit('error', err); return; } - const json = getL10nJson(files - .filter(file => file.isBuffer()) + const buffers = files.filter(file => file.isBuffer()); + + const json = getL10nJson(buffers + .filter(file => path.extname(file.path) !== '.json') .map(file => ({ contents: file.contents.toString('utf8'), extension: path.extname(file.path) }))); + buffers + .filter(file => path.extname(file.path) === '.json') + .forEach(file => { + const bundleJson = JSON.parse(file.contents.toString('utf8')); + for (const key in bundleJson) { + if ( + // some validation of the bundle.l10n.json format + typeof bundleJson[key] !== 'string' && + (typeof bundleJson[key].message !== 'string' || !Array.isArray(bundleJson[key].comment)) + ) { + console.error(`Invalid bundle.l10n.json file. The value for key ${key} is not in the expected format. Skipping key...`); + continue; + } + json[key] = bundleJson[key]; + } + }); + if (Object.keys(json).length > 0) { result.emit('data', new File({ path: `extensions/${extensionFolderName}/bundle.l10n.json`, |