Revamping to matrix style

This commit is contained in:
2026-02-16 16:37:35 -05:00
parent 71852ec99a
commit 9d0e3938e4
14958 changed files with 2089572 additions and 114 deletions

42
node_modules/@vscode/l10n/README.md generated vendored Normal file
View File

@@ -0,0 +1,42 @@
# @vscode/l10n
Library used for loading the translations into subprocesses of your extension. These usages also get picked up by [l10n-dev](https://github.com/microsoft/vscode-l10n/tree/main/l10n-dev) string extraction tooling.
> **Note**
>
> You should _NOT_ use this library in your extension's main process. The translations are loaded into the main process by VS Code itself.
## Usage
```typescript
import * as l10n from '@vscode/l10n';
// Load the translations for the current locale
l10n.config({
contents: JSON.parse(process.env.BUNDLE_FROM_EXTENSION)
});
// or
l10n.config({
fsPath: process.env.FSPATH_TO_BUNDLE_FROM_EXTENSION
});
// or (warning, this is async)
await l10n.config({
uri: JSON.parse(process.env.BUNDLE_URI_FROM_EXTENSION)
});
// returns the translated string or the original string if no translation is available
l10n.t('Hello World');
// supports arguments just like the vscode API
l10n.t('Hello {0}', 'John');
// supports comments for translators
l10n.t({
message: 'Hello {0}',
args: ['John'],
comment: ['This is a comment']
});
```
The input for `l10n.config` pairs nicely with the `bundle` and `uri` properties on the `l10n` namespace that are provided by the [VS Code API](https://code.visualstudio.com/api/references/vscode-api#l10n).
You should send the value of one of these properties from your extension to your subprocess that is consuming `@vscode/l10n`.

103
node_modules/@vscode/l10n/dist/browser.js generated vendored Normal file
View File

@@ -0,0 +1,103 @@
// src/browser/reader.ts
async function readFileFromUri(uri) {
if (uri.protocol === "http:" || uri.protocol === "https:") {
const res = await fetch(uri);
return await res.text();
}
throw new Error("Unsupported protocol");
}
function readFileFromFsPath(_) {
throw new Error("Unsupported in browser");
}
// src/main.ts
var bundle;
function config(config2) {
if ("contents" in config2) {
if (typeof config2.contents === "string") {
bundle = JSON.parse(config2.contents);
} else {
bundle = config2.contents;
}
return;
}
if ("fsPath" in config2) {
const fileContent = readFileFromFsPath(config2.fsPath);
const content = JSON.parse(fileContent);
bundle = isBuiltinExtension(content) ? content.contents.bundle : content;
return;
}
if (config2.uri) {
let uri = config2.uri;
if (typeof config2.uri === "string") {
uri = new URL(config2.uri);
}
return new Promise((resolve, reject) => {
readFileFromUri(uri).then((uriContent) => {
try {
const content = JSON.parse(uriContent);
bundle = isBuiltinExtension(content) ? content.contents.bundle : content;
resolve();
} catch (err) {
reject(err);
}
}).catch((err) => {
reject(err);
});
});
}
}
function t(...args) {
const firstArg = args[0];
let key;
let message;
let formatArgs;
if (typeof firstArg === "string") {
key = firstArg;
message = firstArg;
args.splice(0, 1);
formatArgs = !args || typeof args[0] !== "object" ? args : args[0];
} else if (firstArg instanceof Array) {
const replacements = args.slice(1);
if (firstArg.length !== replacements.length + 1) {
throw new Error("expected a string as the first argument to l10n.t");
}
let str = firstArg[0];
for (let i = 1; i < firstArg.length; i++) {
str += `{${i - 1}}` + firstArg[i];
}
return t(str, ...replacements);
} else {
message = firstArg.message;
key = message;
if (firstArg.comment && firstArg.comment.length > 0) {
key += `/${Array.isArray(firstArg.comment) ? firstArg.comment.join("") : firstArg.comment}`;
}
formatArgs = firstArg.args ?? {};
}
const messageFromBundle = bundle?.[key];
if (!messageFromBundle) {
return format(message, formatArgs);
}
if (typeof messageFromBundle === "string") {
return format(messageFromBundle, formatArgs);
}
if (messageFromBundle.comment) {
return format(messageFromBundle.message, formatArgs);
}
return format(message, formatArgs);
}
var _format2Regexp = /{([^}]+)}/g;
function format(template, values) {
if (Object.keys(values).length === 0) {
return template;
}
return template.replace(_format2Regexp, (match, group) => values[group] ?? match);
}
function isBuiltinExtension(json) {
return !!(typeof json?.contents?.bundle === "object" && typeof json?.version === "string");
}
export {
config,
t
};

130
node_modules/@vscode/l10n/dist/main.d.ts generated vendored Normal file
View File

@@ -0,0 +1,130 @@
/**
* @public
* Loads the bundle from the given contents. Must be run before the first call to any `l10n.t()` variant.
* **Note** The best way to set this is to pass the value of the VS Code API `vscode.l10n.contents`
* to the process that uses `@vscode/l10n`.
* @param config - An object that contains one property, contents, which should contain the contents of the bundle.
*/
export declare function config(config: {
contents: string | l10nJsonFormat;
}): void;
/**
* @public
* Loads the bundle from the given fsPath. Must be run before the first call to any `l10n.t()` variant.
* **Warning** This is not implemented in the browser and will throw an Error.
* **Note** The best way to set this is to pass the value of the VS Code API `vscode.l10n.uri.fsPath`
* to the process that uses `@vscode/l10n`.
* @param config - An object that contains one property, fsPath, which should be a path to a file that contains the bundle.
*/
export declare function config(config: {
fsPath: string;
}): void;
/**
* @public
* Loads the bundle from the given URI using an asynchronous fetch request.
* **Warning** Since this is an asynchronous API, you need to ensure that it resolves before
* the first call to any `l10n.t()` variant.
* **Note** The best way to set this is to pass the value of the VS Code API `vscode.l10n.uri.toString()`
* to the process that uses `@vscode/l10n`.
* @param config - An object that contains one property, uri, which should be a URL to the bundle.
*/
export declare function config(config: {
uri: string | URL;
}): Promise<void>;
/**
* @public
* The format of package.nls.json and l10n bundle files.
*/
export declare interface l10nJsonFormat {
[key: string]: l10nJsonMessageFormat;
}
/**
* @public
* The format of a message in a bundle.
*/
export declare type l10nJsonMessageFormat = string | {
message: string;
comment: string[];
};
/**
* @public
* Type that can be used as replacements in `l10n.t()` calls.
*/
export declare type L10nReplacement = string | number | boolean;
/**
* @public
* Marks a string for localization. If the bundle has a localized value for this message, then that localized
* value will be returned (with injected `args` values for any templated values).
* @param message - The message to localize. Supports index templating where strings like `{0}` and `{1}` are
* replaced by the item at that index in the `args` array.
* @param args - The arguments to be used in the localized string. The index of the argument is used to
* match the template placeholder in the localized string.
* @returns localized string with injected arguments.
* @example `l10n.localize('hello', 'Hello {0}!', 'World');`
*/
export declare function t(message: string, ...args: Array<L10nReplacement>): string;
/**
* @public
* Marks a string for localization. If the bundle has a localized value for this message, then that localized
* value will be returned (with injected `args` values for any templated values).
* @param message - The message to localize. Supports named templating where strings like `{foo}` and `{bar}` are
* replaced by the value in the Record for that key (foo, bar, etc).
* @param args - The arguments to be used in the localized string. The name of the key in the record is used to
* match the template placeholder in the localized string.
* @returns localized string with injected arguments.
* @example `l10n.t('Hello {name}', { name: 'Erich' });`
*/
export declare function t(message: string, args: Record<string, L10nReplacement>): string;
/**
* @public
* Marks a string for localization. This function signature is made for usage
* with tagged template literals.
*
* The more verbose overload should still be used if comments are required.
* @example
* ```
* l10n.t`Hello ${name}!`
* ```
* @param message - String message components
* @param args - Replacement components in the string
* @returns localized string with injected arguments.
*/
export declare function t(strs: TemplateStringsArray, ...replacements: L10nReplacement[]): string;
/**
* @public
* Marks a string for localization. If the bundle has a localized value for this message, then that localized
* value will be returned (with injected args values for any templated values).
* @param options - The options to use when localizing the message.
* @returns localized string with injected arguments.
* @example `l10n.t({ message: 'Hello {0}', args: ['Erich'], comment: 'This is a comment' } );`
*/
export declare function t(options: {
/**
* The message to localize. If `args` is an array, this message supports index templating where strings like
* `{0}` and `{1}` are replaced by the item at that index in the `args` array. If `args` is a `Record<string, any>`,
* this supports named templating where strings like `{foo}` and `{bar}` are replaced by the value in
* the Record for that key (foo, bar, etc).
*/
message: string;
/**
* The arguments to be used in the localized string. As an array, the index of the argument is used to
* match the template placeholder in the localized string. As a Record, the key is used to match the template
* placeholder in the localized string.
*/
args?: Array<string | number | boolean> | Record<string, any>;
/**
* A comment to help translators understand the context of the message.
*/
comment: string | string[];
}): string;
export { }

151
node_modules/@vscode/l10n/dist/main.js generated vendored Normal file
View File

@@ -0,0 +1,151 @@
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/main.ts
var main_exports = {};
__export(main_exports, {
config: () => config,
t: () => t
});
module.exports = __toCommonJS(main_exports);
// src/node/reader.ts
var import_fs = require("fs");
var import_promises = require("fs/promises");
async function readFileFromUri(uri) {
if (uri.protocol === "file:") {
return await (0, import_promises.readFile)(uri, "utf8");
}
if (uri.protocol === "http:" || uri.protocol === "https:") {
const res = await fetch(uri.toString(), {
headers: {
"Accept-Encoding": "gzip, deflate",
"Accept": "application/json"
},
redirect: "follow"
});
if (!res.ok) {
let error = `Unexpected ${res.status} response while trying to read ${uri}`;
try {
error += `: ${await res.text()}`;
} catch {
}
throw new Error(error);
}
const decoded = await res.text();
return decoded;
}
throw new Error("Unsupported protocol");
}
function readFileFromFsPath(fsPath) {
return (0, import_fs.readFileSync)(fsPath, "utf8");
}
// src/main.ts
var bundle;
function config(config2) {
if ("contents" in config2) {
if (typeof config2.contents === "string") {
bundle = JSON.parse(config2.contents);
} else {
bundle = config2.contents;
}
return;
}
if ("fsPath" in config2) {
const fileContent = readFileFromFsPath(config2.fsPath);
const content = JSON.parse(fileContent);
bundle = isBuiltinExtension(content) ? content.contents.bundle : content;
return;
}
if (config2.uri) {
let uri = config2.uri;
if (typeof config2.uri === "string") {
uri = new URL(config2.uri);
}
return new Promise((resolve, reject) => {
readFileFromUri(uri).then((uriContent) => {
try {
const content = JSON.parse(uriContent);
bundle = isBuiltinExtension(content) ? content.contents.bundle : content;
resolve();
} catch (err) {
reject(err);
}
}).catch((err) => {
reject(err);
});
});
}
}
function t(...args) {
const firstArg = args[0];
let key;
let message;
let formatArgs;
if (typeof firstArg === "string") {
key = firstArg;
message = firstArg;
args.splice(0, 1);
formatArgs = !args || typeof args[0] !== "object" ? args : args[0];
} else if (firstArg instanceof Array) {
const replacements = args.slice(1);
if (firstArg.length !== replacements.length + 1) {
throw new Error("expected a string as the first argument to l10n.t");
}
let str = firstArg[0];
for (let i = 1; i < firstArg.length; i++) {
str += `{${i - 1}}` + firstArg[i];
}
return t(str, ...replacements);
} else {
message = firstArg.message;
key = message;
if (firstArg.comment && firstArg.comment.length > 0) {
key += `/${Array.isArray(firstArg.comment) ? firstArg.comment.join("") : firstArg.comment}`;
}
formatArgs = firstArg.args ?? {};
}
const messageFromBundle = bundle?.[key];
if (!messageFromBundle) {
return format(message, formatArgs);
}
if (typeof messageFromBundle === "string") {
return format(messageFromBundle, formatArgs);
}
if (messageFromBundle.comment) {
return format(messageFromBundle.message, formatArgs);
}
return format(message, formatArgs);
}
var _format2Regexp = /{([^}]+)}/g;
function format(template, values) {
if (Object.keys(values).length === 0) {
return template;
}
return template.replace(_format2Regexp, (match, group) => values[group] ?? match);
}
function isBuiltinExtension(json) {
return !!(typeof json?.contents?.bundle === "object" && typeof json?.version === "string");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
config,
t
});

11
node_modules/@vscode/l10n/dist/tsdoc-metadata.json generated vendored Normal file
View File

@@ -0,0 +1,11 @@
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
// It should be published with your NPM package. It should not be tracked by Git.
{
"tsdocVersion": "0.12",
"toolPackages": [
{
"packageName": "@microsoft/api-extractor",
"packageVersion": "7.36.3"
}
]
}

50
node_modules/@vscode/l10n/package.json generated vendored Normal file
View File

@@ -0,0 +1,50 @@
{
"name": "@vscode/l10n",
"version": "0.0.18",
"description": "A helper library to assist in localizing subprocesses spun up by VS Code extensions",
"author": "Microsoft Corporation",
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/Microsoft/vscode-l10n.git"
},
"bugs": {
"url": "https://github.com/Microsoft/vscode-l10n/issues"
},
"main": "./dist/main.js",
"sideEffects": false,
"browser": {
"./dist/main.js": "./dist/browser.js",
"./src/node/reader": "./src/browser/reader"
},
"types": "dist/main.d.ts",
"files": [
"dist/*"
],
"devDependencies": {
"@jest/globals": "^29.7.0",
"@microsoft/api-extractor": "^7.32.1",
"@types/mock-fs": "^4.13.1",
"@types/node": "^18",
"@typescript-eslint/eslint-plugin": "^6.13.2",
"@typescript-eslint/parser": "^6.13.2",
"esbuild": "^0.15.5",
"eslint": "^7.29.0",
"http-proxy-agent": "^5.0.0",
"https-proxy-agent": "^5.0.1",
"jest": "^29.7.0",
"jest-fetch-mock": "^3.0.3",
"mock-fs": "^5.1.4",
"rimraf": "^3.0.2",
"ts-jest": "^29.1.1",
"typescript": "^4.7.4"
},
"scripts": {
"clean": "rimraf dist && rimraf lib",
"compile": "npm run clean && tsc --emitDeclarationOnly --outDir lib && node .esbuild.config.js",
"lint": "eslint src --ext ts",
"watch": "node .esbuild.config.js --watch",
"test": "jest --preset ts-jest",
"prepublishOnly": "npm run lint && npm run compile && npm run test"
}
}