diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index da29ba0eb0..6e56182b73 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -452,6 +452,9 @@ importers: '@ai-sdk/anthropic': specifier: ^2.0.20 version: 2.0.49(zod@4.1.11) + '@iarna/toml': + specifier: ^2.2.5 + version: 2.2.5 '@types/lodash': specifier: ^4.14.200 version: 4.17.17 @@ -524,9 +527,6 @@ importers: source-map-support: specifier: ^0.5.21 version: 0.5.21 - toml: - specifier: ^3.0.0 - version: 3.0.0 unzipper: specifier: ~0.12.3 version: 0.12.3 @@ -2507,15 +2507,15 @@ importers: ../../workspaces/bi/bi-extension: dependencies: + '@iarna/toml': + specifier: ^2.2.5 + version: 2.2.5 '@wso2/ballerina-core': specifier: workspace:* version: link:../../ballerina/ballerina-core '@wso2/font-wso2-vscode': specifier: workspace:* version: link:../../common-libs/font-wso2-vscode - toml: - specifier: ^3.0.0 - version: 3.0.0 xstate: specifier: ^4.38.3 version: 4.38.3 @@ -21708,9 +21708,6 @@ packages: resolution: {integrity: sha512-Y2fmSnZjQdDb9W4w4r1tswlMHylzWIeOKpx0aZH9BgGtACHhrk3OkT52AzwcuqTRBZtvvnTjDBh8eynMulu8Vg==} engines: {node: '>=14.16'} - toml@3.0.0: - resolution: {integrity: sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==} - toposort@1.0.7: resolution: {integrity: sha512-FclLrw8b9bMWf4QlCJuHBEVhSRsqDj6u3nIjAzPeJvgl//1hBlffdlk0MALceL14+koWEdU4ofRAXofbODxQzg==} @@ -37943,8 +37940,8 @@ snapshots: '@webpack-cli/configtest@3.0.1(webpack-cli@6.0.1)(webpack@5.103.0)': dependencies: - webpack: 5.103.0(@swc/core@1.15.3(@swc/helpers@0.5.17))(webpack-cli@6.0.1) - webpack-cli: 6.0.1(webpack-dev-server@5.2.2)(webpack@5.103.0) + webpack: 5.103.0(webpack-cli@6.0.1) + webpack-cli: 6.0.1(webpack@5.103.0) '@webpack-cli/info@1.5.0(webpack-cli@4.10.0)': dependencies: @@ -37958,8 +37955,8 @@ snapshots: '@webpack-cli/info@3.0.1(webpack-cli@6.0.1)(webpack@5.103.0)': dependencies: - webpack: 5.103.0(@swc/core@1.15.3(@swc/helpers@0.5.17))(webpack-cli@6.0.1) - webpack-cli: 6.0.1(webpack-dev-server@5.2.2)(webpack@5.103.0) + webpack: 5.103.0(webpack-cli@6.0.1) + webpack-cli: 6.0.1(webpack@5.103.0) '@webpack-cli/serve@1.7.0(webpack-cli@4.10.0)': dependencies: @@ -52773,8 +52770,6 @@ snapshots: '@tokenizer/token': 0.3.0 ieee754: 1.2.1 - toml@3.0.0: {} - toposort@1.0.7: {} toposort@2.0.2: {} diff --git a/workspaces/ballerina/ballerina-extension/package.json b/workspaces/ballerina/ballerina-extension/package.json index a51f86a5e5..806585ae18 100644 --- a/workspaces/ballerina/ballerina-extension/package.json +++ b/workspaces/ballerina/ballerina-extension/package.json @@ -1213,7 +1213,6 @@ "node-schedule": "^2.1.1", "portfinder": "^1.0.32", "source-map-support": "^0.5.21", - "toml": "^3.0.0", "unzipper": "~0.12.3", "uuid": "^11.1.0", "vscode-debugadapter": "^1.51.0", @@ -1229,7 +1228,8 @@ "xml-js": "^1.6.11", "xstate": "^4.38.3", "zod": "^4.1.8", - "protobufjs": "^7.2.5" + "protobufjs": "^7.2.5", + "@iarna/toml": "^2.2.5" }, "devDependencies": { "@sentry/webpack-plugin": "^1.20.1", diff --git a/workspaces/ballerina/ballerina-extension/src/features/config-generator/utils.ts b/workspaces/ballerina/ballerina-extension/src/features/config-generator/utils.ts index c5dd385cd0..a91436e690 100644 --- a/workspaces/ballerina/ballerina-extension/src/features/config-generator/utils.ts +++ b/workspaces/ballerina/ballerina-extension/src/features/config-generator/utils.ts @@ -17,7 +17,7 @@ */ import { debug } from "../../utils/logger"; -import toml from "toml"; +import { parse } from "@iarna/toml"; import { CompletionItem, CompletionItemKind, Position, TextDocument, Uri } from "vscode"; import { BallerinaExtension } from "../../core"; import { findPropertyValues, getConfigValue, getCurrentBallerinaProjectFromContext } from "./configGenerator"; @@ -33,7 +33,7 @@ export const typeOfComment = 'Type of'; */ export function parseTomlToConfig(tomlContent: string): object { try { - return toml.parse(tomlContent); + return parse(tomlContent); } catch (error) { debug("Error while parsing the Config.toml file content: " + error); } diff --git a/workspaces/ballerina/ballerina-extension/src/features/tracing/utils.ts b/workspaces/ballerina/ballerina-extension/src/features/tracing/utils.ts index 6491586701..cb97e79655 100644 --- a/workspaces/ballerina/ballerina-extension/src/features/tracing/utils.ts +++ b/workspaces/ballerina/ballerina-extension/src/features/tracing/utils.ts @@ -17,7 +17,7 @@ import * as fs from 'fs'; import * as path from 'path'; -import { parse } from 'toml'; +import { parse, stringify } from '@iarna/toml'; import { OTLP_PORT } from './constants'; /** @@ -145,7 +145,7 @@ function updateOrAddSection(content: string, sectionName: string, values: Record // Build the new section content let sectionLines: string[] = [sectionHeader]; for (const [key, value] of Object.entries(values)) { - const formattedValue = typeof value === 'string' ? `"${value}"` : String(value); + const formattedValue = stringify.value(value); sectionLines.push(`${key} = ${formattedValue}`); } const sectionContent = sectionLines.join('\n'); diff --git a/workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-manager.ts b/workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-manager.ts index 6ae0af553f..7a4186e246 100644 --- a/workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-manager.ts +++ b/workspaces/ballerina/ballerina-extension/src/rpc-managers/ai-panel/rpc-manager.ts @@ -41,6 +41,7 @@ import { LoginMethod, MetadataWithAttachments, OperationType, + PackageTomlValues, PostProcessRequest, PostProcessResponse, ProcessContextTypeCreationRequest, @@ -64,7 +65,7 @@ import * as crypto from 'crypto'; import * as fs from 'fs'; import * as os from 'os'; import path from "path"; -import { parse } from 'toml'; +import { parse } from "@iarna/toml"; import { workspace } from 'vscode'; import { isNumber } from "lodash"; @@ -812,8 +813,8 @@ async function getCurrentProjectSource(requestType: OperationType, projectPath?: const tomlContent = await fs.promises.readFile(ballerinaTomlPath, 'utf-8'); // Simple parsing to extract the package.name field try { - const tomlObj = parse(tomlContent); - packageName = tomlObj.package.name; + const tomlObj = parse(tomlContent) as Partial; + packageName = tomlObj?.package?.name; } catch (error) { packageName = ''; } diff --git a/workspaces/ballerina/ballerina-extension/src/rpc-managers/common/rpc-manager.ts b/workspaces/ballerina/ballerina-extension/src/rpc-managers/common/rpc-manager.ts index b27780af2c..d0c0b6b8a0 100644 --- a/workspaces/ballerina/ballerina-extension/src/rpc-managers/common/rpc-manager.ts +++ b/workspaces/ballerina/ballerina-extension/src/rpc-managers/common/rpc-manager.ts @@ -265,8 +265,9 @@ export class CommonRpcManager implements CommonRPCAPI { return extension.ballerinaExtInstance.isNPSupported; } - async getCurrentProjectTomlValues(): Promise { - return getProjectTomlValues(StateMachine.context().projectPath); + async getCurrentProjectTomlValues(): Promise> { + const tomlValues = await getProjectTomlValues(StateMachine.context().projectPath); + return tomlValues ?? {}; } async getWorkspaceType(): Promise { diff --git a/workspaces/ballerina/ballerina-extension/src/utils/bi.ts b/workspaces/ballerina/ballerina-extension/src/utils/bi.ts index 424b6cfc4d..80c0c7859b 100644 --- a/workspaces/ballerina/ballerina-extension/src/utils/bi.ts +++ b/workspaces/ballerina/ballerina-extension/src/utils/bi.ts @@ -38,7 +38,7 @@ import { applyModifications, modifyFileContent, writeBallerinaFileDidOpen } from import { ModulePart, STKindChecker } from "@wso2/syntax-tree"; import { URI } from "vscode-uri"; import { debug } from "./logger"; -import { parse } from "toml"; +import { parse } from "@iarna/toml"; import { getProjectTomlValues } from "./config"; export const README_FILE = "readme.md"; @@ -363,8 +363,8 @@ function addToWorkspaceToml(workspacePath: string, packageName: string) { try { const ballerinaTomlContent = fs.readFileSync(ballerinaTomlPath, 'utf8'); - const tomlData: WorkspaceTomlValues = parse(ballerinaTomlContent); - const existingPackages: string[] = tomlData.workspace?.packages || []; + const tomlData = parse(ballerinaTomlContent) as Partial; + const existingPackages: string[] = tomlData?.workspace?.packages ?? []; if (existingPackages.includes(packageName)) { return; // Package already exists @@ -388,8 +388,8 @@ export function deleteProjectFromWorkspace(workspacePath: string, packagePath: s try { const ballerinaTomlContent = fs.readFileSync(ballerinaTomlPath, 'utf8'); - const tomlData: WorkspaceTomlValues = parse(ballerinaTomlContent); - const existingPackages: string[] = tomlData.workspace?.packages || []; + const tomlData = parse(ballerinaTomlContent) as Partial; + const existingPackages: string[] = tomlData?.workspace?.packages ?? []; if (!existingPackages.includes(relativeProjectPath)) { return; // Package not found diff --git a/workspaces/ballerina/ballerina-extension/src/utils/config.ts b/workspaces/ballerina/ballerina-extension/src/utils/config.ts index f3b6c780b5..f9ea67888b 100644 --- a/workspaces/ballerina/ballerina-extension/src/utils/config.ts +++ b/workspaces/ballerina/ballerina-extension/src/utils/config.ts @@ -21,7 +21,7 @@ import { BallerinaExtension } from '../core'; import { WorkspaceConfiguration, workspace, Uri, RelativePattern } from 'vscode'; import * as fs from 'fs'; import * as path from 'path'; -import { parse } from 'toml'; +import { parse } from '@iarna/toml'; export enum VERSION { BETA = 'beta', @@ -303,12 +303,12 @@ export function getOrgPackageName(projectPath: string): { orgName: string, packa } } -export async function getProjectTomlValues(projectPath: string): Promise { +export async function getProjectTomlValues(projectPath: string): Promise | undefined> { const ballerinaTomlPath = path.join(projectPath, 'Ballerina.toml'); if (fs.existsSync(ballerinaTomlPath)) { const tomlContent = await fs.promises.readFile(ballerinaTomlPath, 'utf-8'); try { - return parse(tomlContent); + return parse(tomlContent) as Partial; } catch (error) { console.error("Failed to load Ballerina.toml content for project at path: ", projectPath, error); return; @@ -316,12 +316,12 @@ export async function getProjectTomlValues(projectPath: string): Promise { +export async function getWorkspaceTomlValues(workspacePath: string): Promise | undefined> { const ballerinaTomlPath = path.join(workspacePath, 'Ballerina.toml'); if (fs.existsSync(ballerinaTomlPath)) { const tomlContent = await fs.promises.readFile(ballerinaTomlPath, 'utf-8'); try { - return parse(tomlContent); + return parse(tomlContent) as Partial; } catch (error) { console.error("Failed to load Ballerina.toml content for workspace at path: ", workspacePath, error); return; diff --git a/workspaces/ballerina/ballerina-rpc-client/src/rpc-clients/common/rpc-client.ts b/workspaces/ballerina/ballerina-rpc-client/src/rpc-clients/common/rpc-client.ts index ccd51c5771..a773146176 100644 --- a/workspaces/ballerina/ballerina-rpc-client/src/rpc-clients/common/rpc-client.ts +++ b/workspaces/ballerina/ballerina-rpc-client/src/rpc-clients/common/rpc-client.ts @@ -116,7 +116,7 @@ export class CommonRpcClient implements CommonRPCAPI { return this._messenger.sendNotification(showErrorMessage, HOST_EXTENSION, params); } - getCurrentProjectTomlValues(): Promise { + getCurrentProjectTomlValues(): Promise> { return this._messenger.sendRequest(getCurrentProjectTomlValues, HOST_EXTENSION); } diff --git a/workspaces/bi/bi-extension/package.json b/workspaces/bi/bi-extension/package.json index 7391ab5e19..5772496da7 100644 --- a/workspaces/bi/bi-extension/package.json +++ b/workspaces/bi/bi-extension/package.json @@ -177,7 +177,7 @@ "@wso2/ballerina-core": "workspace:*", "@wso2/font-wso2-vscode": "workspace:*", "xstate": "^4.38.3", - "toml": "^3.0.0" + "@iarna/toml": "^2.2.5" }, "devDependencies": { "@vscode/vsce": "^3.7.0", diff --git a/workspaces/bi/bi-extension/src/utils.ts b/workspaces/bi/bi-extension/src/utils.ts index 016a83c4e5..30fafddf9d 100644 --- a/workspaces/bi/bi-extension/src/utils.ts +++ b/workspaces/bi/bi-extension/src/utils.ts @@ -21,7 +21,7 @@ import * as fs from 'fs'; import * as path from 'path'; import { extension } from "./biExtentionContext"; import { PackageTomlValues, WorkspaceTomlValues } from "@wso2/ballerina-core"; -import { parse } from "toml"; +import { parse } from "@iarna/toml"; export interface ProjectInfo { isBI: boolean; @@ -156,12 +156,12 @@ export async function checkIsBallerinaWorkspace(uri: Uri): Promise { * @returns A Promise that resolves to the parsed TOML values if successful, * or undefined if the file doesn't exist or parsing fails */ -async function getProjectTomlValues(projectPath: string): Promise { +async function getProjectTomlValues(projectPath: string): Promise | undefined> { const ballerinaTomlPath = path.join(projectPath, 'Ballerina.toml'); if (fs.existsSync(ballerinaTomlPath)) { const tomlContent = await fs.promises.readFile(ballerinaTomlPath, 'utf-8'); try { - return parse(tomlContent); + return parse(tomlContent) as Partial; } catch (error) { console.error("Failed to load Ballerina.toml content for project at path: ", projectPath, error); return; @@ -176,12 +176,12 @@ async function getProjectTomlValues(projectPath: string): Promise { +export async function getWorkspaceTomlValues(workspacePath: string): Promise | undefined> { const ballerinaTomlPath = path.join(workspacePath, 'Ballerina.toml'); if (fs.existsSync(ballerinaTomlPath)) { const tomlContent = await fs.promises.readFile(ballerinaTomlPath, 'utf-8'); try { - return parse(tomlContent); + return parse(tomlContent) as Partial; } catch (error) { console.error("Failed to load Ballerina.toml content for workspace at path: ", workspacePath, error); return;