Skip to content

Commit

Permalink
fix(vscode): Add validation for extension bundle workflows folder (#4326
Browse files Browse the repository at this point in the history
)

Add validation for extension bundle workflows folder
  • Loading branch information
ccastrotrejo committed Mar 8, 2024
1 parent ab07b14 commit fe7dc9c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions apps/vs-code-designer/src/app/utils/bundleFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { downloadAndExtractDependency } from './binaries';
import { getJsonFeed } from './feed';
import type { IActionContext } from '@microsoft/vscode-azext-utils';
import type { IBundleDependencyFeed, IBundleFeed, IBundleMetadata, IHostJsonV2 } from '@microsoft/vscode-extension';
import * as fs from 'fs';
import * as fse from 'fs-extra';
import * as path from 'path';
import * as semver from 'semver';
import * as vscode from 'vscode';
Expand Down Expand Up @@ -141,13 +141,16 @@ async function getExtensionBundleZip(context: IActionContext, extensionVersion:
* @param {string} directoryPath - extension bundle path directory.
* @returns {string[]} Returns the list of versions.
*/
function getExtensionBundleVersionFolders(directoryPath: string): string[] {
const directoryContents = fs.readdirSync(directoryPath);
async function getExtensionBundleVersionFolders(directoryPath: string): Promise<string[]> {
if (!(await fse.pathExists(directoryPath))) {
return [];
}
const directoryContents = fse.readdirSync(directoryPath);

// Filter only the folders with valid version names.
const folders = directoryContents.filter((item) => {
const itemPath = path.join(directoryPath, item);
return fs.statSync(itemPath).isDirectory() && semver.valid(item);
return fse.statSync(itemPath).isDirectory() && semver.valid(item);
});

return folders;
Expand Down Expand Up @@ -177,7 +180,7 @@ export async function downloadExtensionBundle(context: IActionContext): Promise<

// Check for latest version at directory.
let latestLocalBundleVersion = '1.0.0';
const localVersions = getExtensionBundleVersionFolders(defaultExtensionBundlePathValue);
const localVersions = await getExtensionBundleVersionFolders(defaultExtensionBundlePathValue);
for (const localVersion of localVersions) {
latestLocalBundleVersion = semver.gt(latestLocalBundleVersion, localVersion) ? latestLocalBundleVersion : localVersion;
}
Expand Down

0 comments on commit fe7dc9c

Please sign in to comment.