mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 09:08:48 +01:00
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.
This commit is contained in:
committed by
GitHub
parent
aa60836c16
commit
964dc545ab
+21
-3
@@ -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`,
|
||||
|
||||
+24
-3
@@ -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`,
|
||||
|
||||
Reference in New Issue
Block a user