Skip to content

Commit

Permalink
fix: use new(er) patches/config.json format
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanders11 committed Nov 3, 2024
1 parent 6011993 commit 5fa1389
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 26 deletions.
31 changes: 21 additions & 10 deletions schemas/patches-config.schema.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
{
"title": "JSON schema for Electron patches/config.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"patternProperties": {
"^src\/electron\/": {
"type": "string",
"description": "Maps patch directory to source tree directory",
"minLength": 1,
"pattern": "^(?:src|src\/.+[^\/])$"
}
},
"additionalProperties": false
"description": "Maps patch directory to source tree directory",
"type": "array",
"items": {
"type": "object",
"properties": {
"patch_dir": {
"type": "string",
"description": "Patch directory in the Electron source tree",
"minLength": 1,
"pattern": "^src\/electron\/"
},
"repo": {
"type": "string",
"description": "Repository directory in the Chromium checkout",
"minLength": 1,
"pattern": "^(?:src|src\/.+[^\/])$"
}
},
"required": ["patch_dir", "repo"],
"additionalProperties": false
}
}
6 changes: 3 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */

import type { ElectronPatchesConfig } from "./types";

export const extensionId = "dsanders11.vscode-electron-build-tools";

export const blankConfigEnumValue = "----";
Expand All @@ -17,7 +15,7 @@ export const buildTargets = Object.freeze([

export const buildToolsExecutable = "electron-build-tools";

export const patchDirectoryPrettyNames = Object.freeze<ElectronPatchesConfig>({
export const patchDirectoryPrettyNames = Object.freeze({
"src/electron/patches/boringssl": "BoringSSL",
"src/electron/patches/chromium": "Chromium",
"src/electron/patches/depot_tools": "depot_tools",
Expand All @@ -28,8 +26,10 @@ export const patchDirectoryPrettyNames = Object.freeze<ElectronPatchesConfig>({
"src/electron/patches/nan": "NAN",
"src/electron/patches/perfetto": "Perfetto",
"src/electron/patches/ReactiveObjC": "ReactiveObjC",
"src/electron/patches/reclient-configs": "Reclient Configs",
"src/electron/patches/squirrel.mac": "Squirrel.Mac",
"src/electron/patches/v8": "V8",
"src/electron/patches/webrtc": "WebRTC",
});

export const checkoutDirectoryGitHubRepo = Object.freeze<{
Expand Down
18 changes: 11 additions & 7 deletions src/types/electronPatchesConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
* and run json-schema-to-typescript to regenerate this file.
*/

export interface JSONSchemaForElectronPatchesConfigJson {
/**
* Maps patch directory to source tree directory
*/
export type JSONSchemaForElectronPatchesConfigJson = {
/**
* Patch directory in the Electron source tree
*/
patch_dir: string;
/**
* Maps patch directory to source tree directory
*
* This interface was referenced by `JSONSchemaForElectronPatchesConfigJson`'s JSON-Schema definition
* via the `patternProperty` "^src/electron/".
* Repository directory in the Chromium checkout
*/
[k: string]: string;
}
repo: string;
}[];
8 changes: 3 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,9 @@ export function getCheckoutDirectoryForPatchDirectory(
config: ElectronPatchesConfig,
patchDirectory: vscode.Uri,
) {
for (const [patchDirectoryTail, checkoutDirectory] of Object.entries(
config,
)) {
if (patchDirectory.path.endsWith(patchDirectoryTail)) {
return vscode.Uri.joinPath(rootDirectory, checkoutDirectory);
for (const { patch_dir, repo } of config) {
if (patchDirectory.path.endsWith(patch_dir)) {
return vscode.Uri.joinPath(rootDirectory, repo);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/views/patches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class ElectronPatchesProvider

if (!element) {
// Root element, read the config file for all patch directories
for (const patchDirectory of Object.keys(await this.patchesConfig)) {
for (const { patch_dir: patchDirectory } of await this.patchesConfig) {
const patchDirectoryBasename = path.basename(patchDirectory);
const uri = vscode.Uri.joinPath(this.rootDirectory, patchDirectory);
const label =
Expand Down

0 comments on commit 5fa1389

Please sign in to comment.