From b1522365382e8f4b500fdf50d7ceee84638527f5 Mon Sep 17 00:00:00 2001 From: Mario Majcica Date: Sun, 2 Jun 2024 11:25:19 +0200 Subject: [PATCH 1/4] draft --- BuildTasks/Common/v5/Common.ts | 55 ++++++++++++++++++- .../PublishExtension/v5/PublishExtension.ts | 5 +- BuildTasks/PublishExtension/v5/task.json | 9 +++ BuildTasks/PublishExtension/v5/vsixeditor.ts | 10 +++- 4 files changed, 75 insertions(+), 4 deletions(-) diff --git a/BuildTasks/Common/v5/Common.ts b/BuildTasks/Common/v5/Common.ts index 69588366..7198a0ac 100644 --- a/BuildTasks/Common/v5/Common.ts +++ b/BuildTasks/Common/v5/Common.ts @@ -7,6 +7,7 @@ import { AzureRMEndpoint } from "azure-pipelines-tasks-azure-arm-rest/azure-arm- import fse from "fs-extra"; import uuidv5 from "uuidv5"; import tmp from "tmp"; +import { forEach } from "core-js/core/array"; function writeBuildTempFile(taskName: string, data: any): string { const tempDir = tl.getVariable("Agent.TempDirectory"); @@ -342,6 +343,15 @@ function getTaskPathContributions(manifest: any): string[] { .map((c: any) => c.properties["name"]); } +function getContributions(manifest: any): string[] { + // Check for all contributions + if (!manifest.contributions) { + return []; + } + + return manifest.contributions; +} + function updateTaskId(manifest: any, publisherId: string, extensionId: string): unknown { tl.debug(`Task manifest ${manifest.name} id before: ${manifest.id}`); @@ -379,6 +389,35 @@ function updateExtensionManifestTaskIds(manifest: any, originalTaskId: string, n return manifest; } +function updateExtensionManifestsFeatureConstrains(manifest: any): unknown { + if (!manifest.contributions) { + tl.debug(`No contributions found`); + return manifest; + } + + const extensionTag = tl.getInput("extensionTag", false) || ""; + const extensionId = `${(tl.getInput("extensionId", false) || manifest.id)}${extensionTag}`; + + manifest.contributions + .filter((c: any) => c.constraints && c.constraints.length > 0) + .forEach((c: any) => { + c.constraints.forEach((constraint: any) => { + if (constraint.properties?.featureId) { + tl.debug(`Extension manifest featureId before: ${constraint.properties.featureId}`); + + const parts = constraint.properties.featureId.split("."); + parts[1] = extensionId; + const newFeatureId = parts.join("."); + constraint.properties.featureId = newFeatureId; + + tl.debug(`Extension manifest featureId after: ${newFeatureId}`); + } + }); + }); + + return manifest; +} + function updateTaskVersion(manifest: any, extensionVersionString: string, extensionVersionType: string): unknown { const versionParts = extensionVersionString.split("."); if (versionParts.length > 3) { @@ -415,6 +454,8 @@ function updateTaskVersion(manifest: any, extensionVersionString: string, extens export async function updateManifests(manifestPaths: string[]): Promise { const updateTasksVersion = tl.getBoolInput("updateTasksVersion", false); const updateTasksId = tl.getBoolInput("updateTasksId", false); + const extensionTag = tl.getInput("extensionTag", false); + const updateFeatureConstraints = tl.getBoolInput("updateFeatureConstraints", false); if (updateTasksVersion || updateTasksId) { if (!(manifestPaths && manifestPaths.length)) { @@ -424,7 +465,17 @@ export async function updateManifests(manifestPaths: string[]): Promise { tl.debug(`Found manifests: ${manifestPaths.join(", ")}`); const tasksIds = await updateTaskManifests(manifestPaths, updateTasksId, updateTasksVersion); - await updateExtensionManifests(manifestPaths, tasksIds); + await updateExtensionManifestsTaskIds(manifestPaths, tasksIds); + } + + if (extensionTag && updateFeatureConstraints) { + if (!(manifestPaths && manifestPaths.length)) { + manifestPaths = getExtensionManifestPaths(); + } + + tl.debug(`Found manifests: ${manifestPaths.join(", ")}`); + + await updateExtensionManifestsFeatureConstrains(manifestPaths); } } @@ -476,7 +527,7 @@ async function updateTaskManifests(manifestPaths: string[], updateTasksId: boole return tasksIds; } -async function updateExtensionManifests(manifestPaths: string[], updatedTaskIds: [string, string][]): Promise { +async function updateExtensionManifestsTaskIds(manifestPaths: string[], updatedTaskIds: [string, string][]): Promise { await Promise.all(manifestPaths.map(async (path) => { tl.debug(`Patching: ${path}.`); let originalManifest = await getManifest(path); diff --git a/BuildTasks/PublishExtension/v5/PublishExtension.ts b/BuildTasks/PublishExtension/v5/PublishExtension.ts index 90853ad7..e165336a 100644 --- a/BuildTasks/PublishExtension/v5/PublishExtension.ts +++ b/BuildTasks/PublishExtension/v5/PublishExtension.ts @@ -59,6 +59,7 @@ await common.runTfx(async tfx => { const extensionVersion = common.getExtensionVersion(); const updateTasksId = tl.getBoolInput("updateTasksId", false); const updateTasksVersion = tl.getBoolInput("updateTasksVersion", false); + const updateFeatureConstraints = tl.getBoolInput("updateFeatureConstraints", false); if (publisher || extensionId @@ -67,7 +68,8 @@ await common.runTfx(async tfx => { || (extensionPricing && extensionPricing !== "default") || (extensionVisibility && extensionVisibility !== "default") || extensionVersion - || updateTasksId) { + || updateTasksId + || updateFeatureConstraints) { tl.debug("Start editing of VSIX"); const ve = new VsixEditor(vsixFile, vsixOutput); @@ -77,6 +79,7 @@ await common.runTfx(async tfx => { if (extensionId) { ve.editId(extensionId); } if (extensionTag) { ve.editIdTag(extensionTag); } if (extensionName) { ve.editExtensionName(extensionName); } + if (updateFeatureConstraints) { ve.editUpdateFeatureConstraints(updateFeatureConstraints); } if (extensionVisibility) { ve.editExtensionVisibility(extensionVisibility); } if (extensionPricing) { ve.editExtensionPricing(extensionPricing); } if (extensionVersion) { diff --git a/BuildTasks/PublishExtension/v5/task.json b/BuildTasks/PublishExtension/v5/task.json index 7ca3d8fa..423a16dd 100644 --- a/BuildTasks/PublishExtension/v5/task.json +++ b/BuildTasks/PublishExtension/v5/task.json @@ -176,6 +176,15 @@ "required": false, "groupName": "manifest" }, + { + "name": "updateFeatureConstraints", + "type": "boolean", + "label": "Override feature Id", + "defaultValue": "false", + "required": false, + "helpMarkDown": "Search for feature constraints in extension manifests and updates the featureId to match the actual extension id.", + "groupName": "manifest" + }, { "name": "updateTasksVersion", "type": "boolean", diff --git a/BuildTasks/PublishExtension/v5/vsixeditor.ts b/BuildTasks/PublishExtension/v5/vsixeditor.ts index e7e54ffc..ca7d6791 100644 --- a/BuildTasks/PublishExtension/v5/vsixeditor.ts +++ b/BuildTasks/PublishExtension/v5/vsixeditor.ts @@ -109,6 +109,7 @@ export default class VSIXEditor { private extensionPricing: string = null; private updateTasksVersion = true; private updateTasksId = true; + private updateFeatureConstraints = false; constructor( public inputFile: string, @@ -203,7 +204,9 @@ export default class VSIXEditor { tl.debug("Extracting files to " + dirPath); await this.extractArchive(this.inputFile, dirPath); - if (this.versionNumber && this.updateTasksVersion || this.updateTasksId) { + + if (this.versionNumber && this.updateTasksVersion || this.updateTasksId || + this.editIdTag && this.editUpdateFeatureConstraints) { tl.debug("Look for build tasks manifest"); const extensionManifest = path.join(dirPath, "extension.vsomanifest"); await common.checkUpdateTasksManifests(extensionManifest); @@ -344,6 +347,11 @@ export default class VSIXEditor { this.updateTasksId = updateTasksId; } + public editUpdateFeatureConstraints(updateFeatureConstraints: boolean) { + this.validateEditMode(); + this.updateFeatureConstraints = updateFeatureConstraints; + } + private validateEditMode() { if (!this.edit) { throw new Error("Editing is not started"); } } From d42ab87508937f649684725c5cbf170b6ca55529 Mon Sep 17 00:00:00 2001 From: Mario Majcica Date: Sun, 2 Jun 2024 11:31:31 +0200 Subject: [PATCH 2/4] minor --- BuildTasks/Common/v5/Common.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/BuildTasks/Common/v5/Common.ts b/BuildTasks/Common/v5/Common.ts index 7198a0ac..ca1c5252 100644 --- a/BuildTasks/Common/v5/Common.ts +++ b/BuildTasks/Common/v5/Common.ts @@ -343,15 +343,6 @@ function getTaskPathContributions(manifest: any): string[] { .map((c: any) => c.properties["name"]); } -function getContributions(manifest: any): string[] { - // Check for all contributions - if (!manifest.contributions) { - return []; - } - - return manifest.contributions; -} - function updateTaskId(manifest: any, publisherId: string, extensionId: string): unknown { tl.debug(`Task manifest ${manifest.name} id before: ${manifest.id}`); From 447bb68886f66d728cdf66a606ec2dbc9089ad78 Mon Sep 17 00:00:00 2001 From: Mario Majcica Date: Sun, 2 Jun 2024 11:33:04 +0200 Subject: [PATCH 3/4] minor --- BuildTasks/Common/v5/Common.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BuildTasks/Common/v5/Common.ts b/BuildTasks/Common/v5/Common.ts index ca1c5252..545085ee 100644 --- a/BuildTasks/Common/v5/Common.ts +++ b/BuildTasks/Common/v5/Common.ts @@ -353,7 +353,7 @@ function updateTaskId(manifest: any, publisherId: string, extensionId: string): return manifest; } -function updateExtensionManifestTaskIds(manifest: any, originalTaskId: string, newTaskId: string): unknown { +function updateExtensionManifests(manifest: any, originalTaskId: string, newTaskId: string): unknown { if (!manifest.contributions) { tl.debug(`No contributions found`); return manifest; @@ -525,7 +525,7 @@ async function updateExtensionManifestsTaskIds(manifestPaths: string[], updatedT updatedTaskIds.map(([originalTaskId, newTaskId]) => { tl.debug(`Updating: ${originalTaskId} => ${newTaskId}.`) - originalManifest = updateExtensionManifestTaskIds(originalManifest, originalTaskId, newTaskId); + originalManifest = updateExtensionManifests(originalManifest, originalTaskId, newTaskId); }); await writeManifest(originalManifest, path); From 973aaff8cc8dcb0a2464e98b7c9731aa6339c3b0 Mon Sep 17 00:00:00 2001 From: Mario Majcica Date: Sun, 2 Jun 2024 11:33:41 +0200 Subject: [PATCH 4/4] rollback --- BuildTasks/Common/v5/Common.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BuildTasks/Common/v5/Common.ts b/BuildTasks/Common/v5/Common.ts index 545085ee..ca1c5252 100644 --- a/BuildTasks/Common/v5/Common.ts +++ b/BuildTasks/Common/v5/Common.ts @@ -353,7 +353,7 @@ function updateTaskId(manifest: any, publisherId: string, extensionId: string): return manifest; } -function updateExtensionManifests(manifest: any, originalTaskId: string, newTaskId: string): unknown { +function updateExtensionManifestTaskIds(manifest: any, originalTaskId: string, newTaskId: string): unknown { if (!manifest.contributions) { tl.debug(`No contributions found`); return manifest; @@ -525,7 +525,7 @@ async function updateExtensionManifestsTaskIds(manifestPaths: string[], updatedT updatedTaskIds.map(([originalTaskId, newTaskId]) => { tl.debug(`Updating: ${originalTaskId} => ${newTaskId}.`) - originalManifest = updateExtensionManifests(originalManifest, originalTaskId, newTaskId); + originalManifest = updateExtensionManifestTaskIds(originalManifest, originalTaskId, newTaskId); }); await writeManifest(originalManifest, path);