Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 10 additions & 15 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions workspaces/ballerina/ballerina-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/**
Expand Down Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
LoginMethod,
MetadataWithAttachments,
OperationType,
PackageTomlValues,
PostProcessRequest,
PostProcessResponse,
ProcessContextTypeCreationRequest,
Expand All @@ -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";
Expand Down Expand Up @@ -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<PackageTomlValues>;
packageName = tomlObj?.package?.name;
} catch (error) {
packageName = '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ export class CommonRpcManager implements CommonRPCAPI {
return extension.ballerinaExtInstance.isNPSupported;
}

async getCurrentProjectTomlValues(): Promise<PackageTomlValues> {
return getProjectTomlValues(StateMachine.context().projectPath);
async getCurrentProjectTomlValues(): Promise<Partial<PackageTomlValues>> {
const tomlValues = await getProjectTomlValues(StateMachine.context().projectPath);
return tomlValues ?? {};
}

async getWorkspaceType(): Promise<WorkspaceTypeResponse> {
Expand Down
10 changes: 5 additions & 5 deletions workspaces/ballerina/ballerina-extension/src/utils/bi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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<WorkspaceTomlValues>;
const existingPackages: string[] = tomlData?.workspace?.packages ?? [];

if (existingPackages.includes(packageName)) {
return; // Package already exists
Expand All @@ -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<WorkspaceTomlValues>;
const existingPackages: string[] = tomlData?.workspace?.packages ?? [];

if (!existingPackages.includes(relativeProjectPath)) {
return; // Package not found
Expand Down
10 changes: 5 additions & 5 deletions workspaces/ballerina/ballerina-extension/src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -303,25 +303,25 @@ export function getOrgPackageName(projectPath: string): { orgName: string, packa
}
}

export async function getProjectTomlValues(projectPath: string): Promise<PackageTomlValues | undefined> {
export async function getProjectTomlValues(projectPath: string): Promise<Partial<PackageTomlValues> | 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<PackageTomlValues>;
} catch (error) {
console.error("Failed to load Ballerina.toml content for project at path: ", projectPath, error);
return;
}
}
}

export async function getWorkspaceTomlValues(workspacePath: string): Promise<WorkspaceTomlValues | undefined> {
export async function getWorkspaceTomlValues(workspacePath: string): Promise<Partial<WorkspaceTomlValues> | 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<WorkspaceTomlValues>;
} catch (error) {
console.error("Failed to load Ballerina.toml content for workspace at path: ", workspacePath, error);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class CommonRpcClient implements CommonRPCAPI {
return this._messenger.sendNotification(showErrorMessage, HOST_EXTENSION, params);
}

getCurrentProjectTomlValues(): Promise<PackageTomlValues> {
getCurrentProjectTomlValues(): Promise<Partial<PackageTomlValues>> {
return this._messenger.sendRequest(getCurrentProjectTomlValues, HOST_EXTENSION);
}

Expand Down
2 changes: 1 addition & 1 deletion workspaces/bi/bi-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions workspaces/bi/bi-extension/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -156,12 +156,12 @@ export async function checkIsBallerinaWorkspace(uri: Uri): Promise<boolean> {
* @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<PackageTomlValues | undefined> {
async function getProjectTomlValues(projectPath: string): Promise<Partial<PackageTomlValues> | 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<PackageTomlValues>;
} catch (error) {
console.error("Failed to load Ballerina.toml content for project at path: ", projectPath, error);
return;
Expand All @@ -176,12 +176,12 @@ async function getProjectTomlValues(projectPath: string): Promise<PackageTomlVal
* @returns A Promise that resolves to the parsed TOML values if successful,
* or undefined if the file doesn't exist or parsing fails
*/
export async function getWorkspaceTomlValues(workspacePath: string): Promise<WorkspaceTomlValues | undefined> {
export async function getWorkspaceTomlValues(workspacePath: string): Promise<Partial<WorkspaceTomlValues> | 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<WorkspaceTomlValues>;
} catch (error) {
console.error("Failed to load Ballerina.toml content for workspace at path: ", workspacePath, error);
return;
Expand Down
Loading