From f222ea2e4a5b3e5bb4da6571373c3fdc392a0f4d Mon Sep 17 00:00:00 2001 From: madushajg Date: Tue, 2 Dec 2025 13:45:27 +0530 Subject: [PATCH] Update dependencies to use @iarna/toml and remove legacy toml package --- common/config/rush/pnpm-lock.yaml | 17 ++++++++++------- .../ballerina/ballerina-extension/package.json | 4 ++-- .../src/features/config-generator/utils.ts | 4 ++-- .../src/features/tracing/utils.ts | 4 ++-- .../src/rpc-managers/ai-panel/rpc-manager.ts | 7 ++++--- .../src/rpc-managers/common/rpc-manager.ts | 2 +- .../ballerina-extension/src/utils/bi.ts | 10 +++++----- .../ballerina-extension/src/utils/config.ts | 10 +++++----- .../src/rpc-clients/common/rpc-client.ts | 2 +- workspaces/bi/bi-extension/package.json | 2 +- workspaces/bi/bi-extension/src/utils.ts | 10 +++++----- 11 files changed, 38 insertions(+), 34 deletions(-) diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index da29ba0eb0d..a30112da2af 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,6 +2507,9 @@ 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 @@ -37943,8 +37946,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 +37961,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: diff --git a/workspaces/ballerina/ballerina-extension/package.json b/workspaces/ballerina/ballerina-extension/package.json index cb5933ad706..def74823d75 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 c5dd385cd0c..a91436e6909 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 64915867015..cb97e79655d 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 6ae0af553fa..7a4186e246e 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 b27780af2c9..610a7f2536c 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,7 +265,7 @@ export class CommonRpcManager implements CommonRPCAPI { return extension.ballerinaExtInstance.isNPSupported; } - async getCurrentProjectTomlValues(): Promise { + async getCurrentProjectTomlValues(): Promise> { return getProjectTomlValues(StateMachine.context().projectPath); } diff --git a/workspaces/ballerina/ballerina-extension/src/utils/bi.ts b/workspaces/ballerina/ballerina-extension/src/utils/bi.ts index 424b6cfc4da..80c0c7859b5 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 f3b6c780b59..f9ea67888bc 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 ccd51c57718..a7731461765 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 b553ab1fb24..09e6a9fec63 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 016a83c4e56..30fafddf9db 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;