diff --git a/eslint.config.mjs b/eslint.config.mjs index 83a82ff1..04c71b0c 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -9,10 +9,10 @@ import { defineConfig } from 'eslint/config'; export default defineConfig([ azExtEslintRecommended, lazyImportRuleConfig([ - '@modelcontextprotocol/*', '@azure/*', 'handlebars', '@microsoft/vscode-azext-azure*', + 'tar', 'vscode-languageclient*', '!@microsoft/vscode-azext-azureauth', ]), diff --git a/package-lock.json b/package-lock.json index 8ed63073..674b8c68 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,6 @@ "version": "2.4.6-alpha", "license": "SEE LICENSE IN LICENSE.md", "dependencies": { - "@azure/arm-authorization": "^9.0.0", "@azure/arm-containerregistry": "^10.1.0", "@azure/storage-blob": "^12.14.0", "@microsoft/compose-language-service": "^0.5.0", @@ -17,29 +16,29 @@ "@microsoft/vscode-azext-azureauth": "6.0.0-alpha.1", "@microsoft/vscode-azext-azureutils": "^4.0.0", "@microsoft/vscode-azext-utils": "^4.0.4", - "@microsoft/vscode-container-client": "^0.5.2", + "@microsoft/vscode-container-client": "^0.5.3", "@microsoft/vscode-docker-registries": "^0.4.1", "@microsoft/vscode-processutils": "^0.2.1", "dayjs": "^1.11.7", "dockerfile-language-server-nodejs": "^0.15.0", + "fast-xml-parser": "^5.3.4", "fs-extra": "^11.1.1", "gradle-to-js": "^2.0.1", - "handlebars": "^4.7.7", + "handlebars": "^4.7.8", "semver": "^7.5.2", "tar": "^7.5.7", "vscode-languageclient": "^10.0.0-next.19", "vscode-tas-client": "^0.1.75", - "xml2js": "^0.6.0", "zod": "~4" }, "devDependencies": { - "@azure/arm-appservice": "^15.0.0", + "@azure/arm-appservice": "*", + "@azure/arm-authorization": "*", "@microsoft/vscode-azext-eng": "1.0.0-alpha.12", "@types/fs-extra": "^11.0.1", "@types/node": "22.x", "@types/semver": "^7.3.13", "@types/vscode": "1.105.0", - "@types/xml2js": "^0.4.11", "@vscode/test-cli": "*", "@vscode/test-electron": "*", "@vscode/vsce": "*", @@ -125,6 +124,7 @@ "version": "9.0.0", "resolved": "https://registry.npmjs.org/@azure/arm-authorization/-/arm-authorization-9.0.0.tgz", "integrity": "sha512-GdiCA8IA1gO+qcCbFEPj+iLC4+3ByjfKzmeAnkP7MdlL84Yo30Huo/EwbZzwRjYybXYUBuFxGPBB+yeTT4Ebxg==", + "license": "MIT", "dependencies": { "@azure/core-auth": "^1.3.0", "@azure/core-client": "^1.7.0", @@ -156,6 +156,7 @@ "version": "10.1.0", "resolved": "https://registry.npmjs.org/@azure/arm-containerregistry/-/arm-containerregistry-10.1.0.tgz", "integrity": "sha512-1ZEmpepqaiM95LH9IHRIBMaELRjh/hSNdLeYniXK7/0EegLHixB3lSA+gx/bR0hj0ZuNF+RrdzOAtjmSAT4/Rw==", + "license": "MIT", "dependencies": { "@azure/abort-controller": "^1.0.0", "@azure/core-auth": "^1.3.0", @@ -173,6 +174,7 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/@azure/abort-controller/-/abort-controller-1.1.0.tgz", "integrity": "sha512-TrRLIoSQVzfAJX9H1JeFjzAoDGcoK1IYX1UImfceTZpsyYfWr09Ss1aHW1y5TrrR3iq6RZLBwJ3E24uwPhwahw==", + "license": "MIT", "dependencies": { "tslib": "^2.2.0" }, @@ -1684,9 +1686,9 @@ } }, "node_modules/@microsoft/vscode-container-client": { - "version": "0.5.2", - "resolved": "https://registry.npmjs.org/@microsoft/vscode-container-client/-/vscode-container-client-0.5.2.tgz", - "integrity": "sha512-nVbNbZ/PshthGRLSXYEMrenVv+Vw5Jl82TYjIyfEzfczkxwAkvQxM8s7uf/q99MigL5AYuxSG4BBaUcwx1cmvw==", + "version": "0.5.3", + "resolved": "https://registry.npmjs.org/@microsoft/vscode-container-client/-/vscode-container-client-0.5.3.tgz", + "integrity": "sha512-vqMgd3iSLbhdmqMcIpL3o5Ms/flia6HHrVk8vg4OWCtqkx7/UCKWrrsSMdKEykDirE2IgCrFYdhCaPavn251sg==", "license": "See LICENSE in the project root for license information.", "dependencies": { "@microsoft/vscode-processutils": "^0.2.1", @@ -2417,15 +2419,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/xml2js": { - "version": "0.4.14", - "resolved": "https://registry.npmjs.org/@types/xml2js/-/xml2js-0.4.14.tgz", - "integrity": "sha512-4YnrRemBShWRO2QjvUin8ESA41rH+9nQGLUGZV/1IDhi3SL9OhdpNC/MrulTWuptXKwhx/aDxE7toV0f/ypIXQ==", - "dev": true, - "dependencies": { - "@types/node": "*" - } - }, "node_modules/@typescript-eslint/eslint-plugin": { "version": "8.48.1", "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.48.1.tgz", @@ -7327,7 +7320,8 @@ "node_modules/sax": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/sax/-/sax-1.4.1.tgz", - "integrity": "sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg==" + "integrity": "sha512-+aWOz7yVScEGoKNd4PA10LZ8sk0A/z5+nXQG5giUO5rprX9jgYsTdov9qCchZiPIZezbZH+jRut8nPodFAX4Jg==", + "dev": true }, "node_modules/secretlint": { "version": "10.2.2", @@ -8777,22 +8771,11 @@ } } }, - "node_modules/xml2js": { - "version": "0.6.2", - "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.6.2.tgz", - "integrity": "sha512-T4rieHaC1EXcES0Kxxj4JWgaUQHDk+qwHcYOCFHfiwKz7tOVPLq7Hjq9dM1WCMhylqMEfP7hMcOIChvotiZegA==", - "dependencies": { - "sax": ">=0.6.0", - "xmlbuilder": "~11.0.0" - }, - "engines": { - "node": ">=4.0.0" - } - }, "node_modules/xmlbuilder": { "version": "11.0.1", "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz", "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA==", + "dev": true, "engines": { "node": ">=4.0" } diff --git a/package.json b/package.json index d3e7c355..64eb73e3 100644 --- a/package.json +++ b/package.json @@ -3351,13 +3351,13 @@ "vscode.yaml" ], "devDependencies": { - "@azure/arm-appservice": "^15.0.0", + "@azure/arm-appservice": "*", + "@azure/arm-authorization": "*", "@microsoft/vscode-azext-eng": "1.0.0-alpha.12", "@types/fs-extra": "^11.0.1", "@types/node": "22.x", "@types/semver": "^7.3.13", "@types/vscode": "1.105.0", - "@types/xml2js": "^0.4.11", "@vscode/test-cli": "*", "@vscode/test-electron": "*", "@vscode/vsce": "*", @@ -3365,7 +3365,6 @@ "esbuild-plugin-copy": "*" }, "dependencies": { - "@azure/arm-authorization": "^9.0.0", "@azure/arm-containerregistry": "^10.1.0", "@azure/storage-blob": "^12.14.0", "@microsoft/compose-language-service": "^0.5.0", @@ -3373,19 +3372,19 @@ "@microsoft/vscode-azext-azureauth": "6.0.0-alpha.1", "@microsoft/vscode-azext-azureutils": "^4.0.0", "@microsoft/vscode-azext-utils": "^4.0.4", - "@microsoft/vscode-container-client": "^0.5.2", + "@microsoft/vscode-container-client": "^0.5.3", "@microsoft/vscode-docker-registries": "^0.4.1", "@microsoft/vscode-processutils": "^0.2.1", "dayjs": "^1.11.7", "dockerfile-language-server-nodejs": "^0.15.0", + "fast-xml-parser": "^5.3.4", "fs-extra": "^11.1.1", "gradle-to-js": "^2.0.1", - "handlebars": "^4.7.7", + "handlebars": "^4.7.8", "semver": "^7.5.2", "tar": "^7.5.7", "vscode-languageclient": "^10.0.0-next.19", "vscode-tas-client": "^0.1.75", - "xml2js": "^0.6.0", "zod": "~4" } } diff --git a/src/commands/registries/azure/tasks/scheduleRunRequest.ts b/src/commands/registries/azure/tasks/scheduleRunRequest.ts index 9b836cb3..4db13df2 100644 --- a/src/commands/registries/azure/tasks/scheduleRunRequest.ts +++ b/src/commands/registries/azure/tasks/scheduleRunRequest.ts @@ -9,13 +9,12 @@ import * as fse from 'fs-extra'; import * as os from 'os'; import * as path from 'path'; import * as readline from 'readline'; -import * as tar from 'tar'; import * as vscode from 'vscode'; import { ext } from '../../../../extensionVariables'; import { AzureRegistry, AzureRegistryItem } from "../../../../tree/registries/Azure/AzureRegistryDataProvider"; import { UnifiedRegistryItem } from "../../../../tree/registries/UnifiedRegistryTreeDataProvider"; import { createArmContainerRegistryClient, getResourceGroupFromId } from "../../../../utils/azureUtils"; -import { getStorageBlob } from '../../../../utils/lazyPackages'; +import { getStorageBlob, getTar } from '../../../../utils/lazyPackages'; import { delay } from '../../../../utils/promiseUtils'; import { Item, quickPickDockerFileItem, quickPickYamlFileItem } from '../../../../utils/quickPickFile'; import { quickPickWorkspaceFolder } from '../../../../utils/quickPickWorkspaceFolder'; @@ -139,6 +138,8 @@ async function quickPickImageName(context: IActionContext, rootFolder: vscode.Wo } async function uploadSourceCode(client: ContainerRegistryManagementClient, registryName: string, resourceGroupName: string, rootFolder: vscode.Uri, tarFilePath: string): Promise { + const tar = await getTar(); + ext.outputChannel.info(vscode.l10n.t(' Sending source code to temp file')); const source: string = rootFolder.fsPath; let items = await fse.readdir(source); diff --git a/src/runtimes/files/ContainerFilesProvider.ts b/src/runtimes/files/ContainerFilesProvider.ts index 4917b2e8..edefdd4d 100644 --- a/src/runtimes/files/ContainerFilesProvider.ts +++ b/src/runtimes/files/ContainerFilesProvider.ts @@ -69,7 +69,7 @@ export class ContainerFilesProvider extends vscode.Disposable implements vscode. const containerOS = dockerUri.options?.containerOS || await getDockerOSType(); const accumulator = new AccumulatorStream(); - const targetStream = containerOS === 'windows' ? accumulator : tarUnpackStream(accumulator); + const targetStream = containerOS === 'windows' ? accumulator : await tarUnpackStream(accumulator); const generator = ext.streamWithDefaults( client => client.readFile({ @@ -133,7 +133,7 @@ export class ContainerFilesProvider extends vscode.Disposable implements vscode. operatingSystem: containerOS, }), { - stdInPipe: tarPackStream(Buffer.from(content), path.basename(uri.path), nowDate, nowDate, nowDate, mode, gid, uid), + stdInPipe: await tarPackStream(Buffer.from(content), path.basename(uri.path), nowDate, nowDate, nowDate, mode, gid, uid), }, ); }); diff --git a/src/scaffolding/wizard/java/JavaGatherInformationStep.ts b/src/scaffolding/wizard/java/JavaGatherInformationStep.ts index f7831a97..100bb182 100644 --- a/src/scaffolding/wizard/java/JavaGatherInformationStep.ts +++ b/src/scaffolding/wizard/java/JavaGatherInformationStep.ts @@ -3,9 +3,9 @@ * Licensed under the MIT License. See LICENSE.md in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import { XMLParser } from 'fast-xml-parser'; import * as fse from 'fs-extra'; import * as gradleParser from 'gradle-to-js/lib/parser'; -import * as xml2js from 'xml2js'; import { GatherInformationStep } from '../GatherInformationStep'; import { JavaScaffoldingWizardContext } from './JavaScaffoldingWizardContext'; @@ -33,7 +33,8 @@ export class JavaGatherInformationStep extends GatherInformationStepawait xml2js.parseStringPromise(contents, { trim: true, normalizeTags: true, normalize: true, mergeAttrs: true }); + const parser = new XMLParser({ trimValues: true, transformTagName: (tagName) => tagName.toLowerCase() }); + const pomObject = parser.parse(contents) as PomContents; wizardContext.version = pomObject?.project?.version || '0.0.1'; diff --git a/src/utils/lazyPackages.ts b/src/utils/lazyPackages.ts index ac86ccc8..4dd08746 100644 --- a/src/utils/lazyPackages.ts +++ b/src/utils/lazyPackages.ts @@ -6,11 +6,6 @@ import { ext } from '../extensionVariables'; import { Lazy } from './lazy'; -const armAuthLazy = new Lazy(async () => await import('@azure/arm-authorization')); -export async function getArmAuth() { - return await armAuthLazy.value; -} - const armContainerRegistryLazy = new Lazy(async () => await import('@azure/arm-containerregistry')); export async function getArmContainerRegistry() { return await armContainerRegistryLazy.value; @@ -21,16 +16,17 @@ export async function getStorageBlob() { return await storageBlobLazy.value; } -const handlebarsLazy = new Lazy(async () => await import('handlebars')); +const handlebarsLazy = new Lazy(async () => getDefaultExport(await import('handlebars'))); export async function getHandlebars() { return await handlebarsLazy.value; } -const languageClientLazy = new Lazy(async () => { - const module = await import('vscode-languageclient/node'); - // The module is CJS; when bundled to ESM by esbuild the exports end up on `default`. Fall back to the module itself for unbundled usage. - return (module as unknown as typeof module & { default?: typeof module }).default ?? module; -}); +const tarLazy = new Lazy(async () => await import('tar')); +export async function getTar() { + return await tarLazy.value; +} + +const languageClientLazy = new Lazy(async () => getDefaultExport(await import('vscode-languageclient/node'))); export async function getLanguageClient() { return await languageClientLazy.value; } @@ -53,3 +49,13 @@ const azExtAppServiceLazy = new Lazy(async () => { export async function getAzExtAppService() { return await azExtAppServiceLazy.value; } + +/** + * Gets the default export out of a module, if it exists, otherwise returns the module itself. This is necessary to support CJS modules, as well as bundled and unbundled usage. + * @param module The module to get the default export for + * @returns The module's default, if it exists, otherwise the module + */ +function getDefaultExport(module: T | { default: T }): T { + // The module is CJS; when bundled to ESM by esbuild the exports end up on `default`. Fall back to the module itself for unbundled usage. + return (module as unknown as { default?: T }).default ?? (module as T); +} diff --git a/src/utils/netCoreUtils.ts b/src/utils/netCoreUtils.ts index 07985a07..70a9d8f4 100644 --- a/src/utils/netCoreUtils.ts +++ b/src/utils/netCoreUtils.ts @@ -7,7 +7,7 @@ import { parseError } from '@microsoft/vscode-azext-utils'; import { CommandLineArgs, composeArgs, withArg, withQuotedArg } from '@microsoft/vscode-processutils'; import * as path from 'path'; import * as vscode from 'vscode'; -import { z } from 'zod'; +import * as z from 'zod/mini'; import { execAsync } from './execAsync'; interface NetCoreCommonProjectInfo { @@ -33,16 +33,18 @@ export type NetCoreProjectInfo = NetCoreCommonProjectInfo & (NetCoreContainerPro const RawNetCoreProjectInfoSchema = z.object({ Properties: z .object({ - AssemblyName: z.string().min(1, vscode.l10n.t('AssemblyName must have a value')), - OutputPath: z.string().min(1, vscode.l10n.t('OutputPath must have a value')), - TargetFramework: z.string().optional(), - TargetFrameworks: z.string().optional(), - EnableSdkContainerSupport: z.stringbool().optional(), - ContainerWorkingDirectory: z.string().optional(), - ContainerRepository: z.string().optional(), + AssemblyName: z.string().check(z.minLength(1, vscode.l10n.t('AssemblyName must have a value'))), + OutputPath: z.string().check(z.minLength(1, vscode.l10n.t('OutputPath must have a value'))), + TargetFramework: z.optional(z.string()), + TargetFrameworks: z.optional(z.string()), + EnableSdkContainerSupport: z.optional(z.stringbool()), + ContainerWorkingDirectory: z.optional(z.string()), + ContainerRepository: z.optional(z.string()), }) - .refine(info => info.TargetFramework || info.TargetFrameworks, vscode.l10n.t('Either TargetFramework or TargetFrameworks must have a value')) - .refine(info => !info.EnableSdkContainerSupport || (info.ContainerWorkingDirectory && info.ContainerRepository), vscode.l10n.t('ContainerWorkingDirectory and ContainerRepository must have values when EnableSdkContainerSupport is true')) + .check( + z.refine(info => info.TargetFramework || info.TargetFrameworks, vscode.l10n.t('Either TargetFramework or TargetFrameworks must have a value')), + z.refine(info => !info.EnableSdkContainerSupport || (info.ContainerWorkingDirectory && info.ContainerRepository), vscode.l10n.t('ContainerWorkingDirectory and ContainerRepository must have values when EnableSdkContainerSupport is true')), + ), }); export async function getNetCoreProjectInfo(project: string, additionalProperties?: CommandLineArgs): Promise { @@ -96,10 +98,10 @@ export interface BlazorManifestInfo { const RawBlazorManifestInfoSchema = z.object({ Properties: z.object({ - MSBuildProjectDirectory: z.string().min(1, vscode.l10n.t('MSBuildProjectDirectory must have a value')), - StaticWebAssetDevelopmentManifestPath: z.string().min(1, vscode.l10n.t('StaticWebAssetDevelopmentManifestPath must have a value')), - OutputPath: z.string().min(1, vscode.l10n.t('OutputPath must have a value')), - TargetName: z.string().min(1, vscode.l10n.t('TargetName must have a value')), + MSBuildProjectDirectory: z.string().check(z.minLength(1, vscode.l10n.t('MSBuildProjectDirectory must have a value'))), + StaticWebAssetDevelopmentManifestPath: z.string().check(z.minLength(1, vscode.l10n.t('StaticWebAssetDevelopmentManifestPath must have a value'))), + OutputPath: z.string().check(z.minLength(1, vscode.l10n.t('OutputPath must have a value'))), + TargetName: z.string().check(z.minLength(1, vscode.l10n.t('TargetName must have a value'))), }) }); diff --git a/src/utils/tarUtils.ts b/src/utils/tarUtils.ts index 891637c3..39036f76 100644 --- a/src/utils/tarUtils.ts +++ b/src/utils/tarUtils.ts @@ -4,7 +4,7 @@ *--------------------------------------------------------------------------------------------*/ import * as stream from 'stream'; -import * as tar from 'tar'; +import { getTar } from './lazyPackages'; /** * Write tarball data containing a single file to this stream, and @@ -12,7 +12,9 @@ import * as tar from 'tar'; * @param destination The destination stream to unpack to * @returns A stream to write tarball data into */ -export function tarUnpackStream(destination: NodeJS.WritableStream): NodeJS.WritableStream { +export async function tarUnpackStream(destination: NodeJS.WritableStream): Promise { + const tar = await getTar(); + let entryCounter = 0; return new tar.Unpack({ filter: () => { @@ -39,7 +41,9 @@ export function tarUnpackStream(destination: NodeJS.WritableStream): NodeJS.Writ * @param uid Optional unix user id specifier * @returns A stream to read tarball data from */ -export function tarPackStream(source: Buffer, sourceFileName: string, atime: Date = new Date(), mtime: Date = new Date(), ctime: Date = new Date(), mode?: number, gid?: number, uid?: number): NodeJS.ReadableStream { +export async function tarPackStream(source: Buffer, sourceFileName: string, atime: Date = new Date(), mtime: Date = new Date(), ctime: Date = new Date(), mode?: number, gid?: number, uid?: number): Promise { + const tar = await getTar(); + const tarPack = new tar.Pack({ portable: true }); const readEntry = new tar.ReadEntry(new tar.Header({ path: sourceFileName,