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
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# VS Code Extension builds
*.vsix
release/*.vsix

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

Expand Down
111 changes: 105 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
"version": "1.1.0",
"publisher": "avidev9",
"scripts": {
"package": "npx vsce package"
"lint": "eslint src/**/*.js",
"clean": "rm -rf release/*.vsix",
"prebuild": "yarn clean",
"build": "npx @vscode/vsce package --out release/",
"package": "yarn build",
"release": "yarn build && echo '✅ Package ready in release/ folder'"
},
"engines": {
"vscode": "^1.61.0"
Expand All @@ -20,6 +25,7 @@
"pack"
],
"activationEvents": [
"workspaceContains:sfdx-project.json",
"onStartupFinished"
],
"main": "./src/extension.js",
Expand Down Expand Up @@ -58,30 +64,123 @@
"type": "boolean",
"default": false,
"description": "Automatically update prettier settings for new sfdx projects"
},
"devPackSalesforce.showStatusBar": {
"type": "boolean",
"default": true,
"description": "Show Salesforce environment status in the status bar"
},
"devPackSalesforce.runHealthCheckOnStartup": {
"type": "boolean",
"default": true,
"description": "Run environment health check when VS Code starts"
},
"devPackSalesforce.autoDeleteApexLogs": {
"type": "boolean",
"default": false,
"description": "Automatically prompt to delete apex logs when there are too many"
},
"devPackSalesforce.preferredDefaultOrg": {
"type": "string",
"default": "",
"description": "Preferred default org alias for operations"
}
}
},
"commands": [
{
"command": "dev-pack-salesforce.forceCheckPackages",
"title": "Dev Pack for Salesforce: Install required node modules",
"shortTitle": "Install required node modules"
"shortTitle": "Install required node modules",
"icon": "$(package)"
},
{
"command": "dev-pack-salesforce.updateSettings",
"title": "Dev Pack for Salesforce: Update prettier formatting settings",
"shortTitle": "Update prettier settings"
"shortTitle": "Update prettier settings",
"icon": "$(gear)"
},
{
"command": "dev-pack-salesforce.updateBetterCommentsSettings",
"title": "Dev Pack for Salesforce: Update better comments settings",
"shortTitle": "Update better comments settings"
"shortTitle": "Update better comments settings",
"icon": "$(comment)"
},
{
"command": "dev-pack-salesforce.deleteApexLogs",
"title": "Dev Pack for Salesforce: Delete all apex logs",
"shortTitle": "Delete all apex logs"
"shortTitle": "Delete all apex logs",
"icon": "$(trash)"
},
{
"command": "dev-pack-salesforce.checkEnvironment",
"title": "Dev Pack for Salesforce: Check Environment Health",
"shortTitle": "Check Environment",
"icon": "$(heart)"
},
{
"command": "dev-pack-salesforce.checkJava",
"title": "Dev Pack for Salesforce: Check Java Installation",
"shortTitle": "Check Java",
"icon": "$(symbol-method)"
},
{
"command": "dev-pack-salesforce.checkSalesforceCLI",
"title": "Dev Pack for Salesforce: Check Salesforce CLI",
"shortTitle": "Check SF CLI",
"icon": "$(cloud)"
},
{
"command": "dev-pack-salesforce.checkNodeJS",
"title": "Dev Pack for Salesforce: Check Node.js Installation",
"shortTitle": "Check Node.js",
"icon": "$(symbol-event)"
},
{
"command": "dev-pack-salesforce.showProjectInfo",
"title": "Dev Pack for Salesforce: Show Project Info",
"shortTitle": "Project Info",
"icon": "$(info)"
},
{
"command": "dev-pack-salesforce.openSfdxProject",
"title": "Dev Pack for Salesforce: Open sfdx-project.json",
"shortTitle": "Open sfdx-project.json",
"icon": "$(json)"
},
{
"command": "dev-pack-salesforce.refreshOrg",
"title": "Dev Pack for Salesforce: Refresh Org Metadata",
"shortTitle": "Refresh Org",
"icon": "$(refresh)"
}
]
],
"menus": {
"commandPalette": [
{
"command": "dev-pack-salesforce.deleteApexLogs",
"when": "sfdx:project_opened"
},
{
"command": "dev-pack-salesforce.showProjectInfo",
"when": "sfdx:project_opened"
},
{
"command": "dev-pack-salesforce.openSfdxProject",
"when": "sfdx:project_opened"
},
{
"command": "dev-pack-salesforce.refreshOrg",
"when": "sfdx:project_opened"
}
],
"explorer/context": [
{
"command": "dev-pack-salesforce.refreshOrg",
"when": "resourceFilename == 'sfdx-project.json'",
"group": "salesforce@1"
}
]
}
}
}
2 changes: 2 additions & 0 deletions release/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This file ensures the release folder is tracked by git
# The actual .vsix build artifacts are ignored
109 changes: 109 additions & 0 deletions src/commands/EnvironmentHealth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
const vscode = require("vscode");
const EnvironmentCheck = require("../utils/EnvironmentCheck");
const CommonUtils = require("../utils/CommonUtils");

class EnvironmentHealth {
/**
* Run full environment health check
*/
static async checkEnvironment() {
await EnvironmentCheck.runHealthCheck(false);
}

/**
* Check and fix Java configuration
*/
static async checkJava() {
const javaCheck = await EnvironmentCheck.checkJava();

if (!javaCheck.installed) {
await EnvironmentCheck.promptJavaPathUpdate();
} else if (!javaCheck.valid) {
const upgrade = await vscode.window.showWarningMessage(
`Java ${javaCheck.version} is installed. Salesforce requires Java 11+.`,
"Find Java Installations",
"Download Java",
"Dismiss"
);

if (upgrade === "Find Java Installations") {
await EnvironmentCheck.promptJavaPathUpdate();
} else if (upgrade === "Download Java") {
vscode.env.openExternal(
vscode.Uri.parse(
"https://developer.salesforce.com/docs/platform/sfvscode-extensions/guide/java-setup.html"
)
);
}
} else {
CommonUtils.showInformationMessage(
`Java ${javaCheck.version} is properly configured ✅\nPath: ${javaCheck.path || "N/A"}`
);
}
}

/**
* Check and update Salesforce CLI
*/
static async checkSalesforceCLI() {
const cliCheck = await EnvironmentCheck.checkSalesforceCLI();
await EnvironmentCheck.promptSalesforceCLIUpdate(cliCheck);
}

/**
* Check Node.js installation
*/
static async checkNodeJS() {
const nodeCheck = await EnvironmentCheck.checkNodeJS();

if (!nodeCheck.installed) {
await EnvironmentCheck.promptNodeJSUpdate(nodeCheck);
} else if (!nodeCheck.valid) {
await EnvironmentCheck.promptNodeJSUpdate(nodeCheck);
} else {
CommonUtils.showInformationMessage(
`Node.js v${nodeCheck.version} is properly configured ✅`
);
}
}

/**
* Show Salesforce project information
*/
static async showProjectInfo() {
const isSFDXProject = await EnvironmentCheck.isSalesforceDXProject();

if (!isSFDXProject) {
vscode.window.showInformationMessage(
"This is not a Salesforce DX project. No sfdx-project.json found."
);
return;
}

const projectInfo = await EnvironmentCheck.getSalesforceProjectInfo();

if (!projectInfo) {
vscode.window.showErrorMessage("Unable to read sfdx-project.json file.");
return;
}

const packageDirs = projectInfo.packageDirectories
.map((dir) => ` • ${dir.path} ${dir.default ? "(default)" : ""}`)
.join("\n");

const message = `📦 Salesforce DX Project\n\nName: ${projectInfo.name}\nAPI Version: ${projectInfo.sourceApiVersion}\nNamespace: ${projectInfo.namespace || "(none)"}\n\nPackage Directories:\n${packageDirs}`;

const action = await vscode.window.showInformationMessage(
message,
"Open sfdx-project.json",
"OK"
);

if (action === "Open sfdx-project.json") {
const doc = await vscode.workspace.openTextDocument(projectInfo.path);
await vscode.window.showTextDocument(doc);
}
}
}

module.exports = EnvironmentHealth;
30 changes: 19 additions & 11 deletions src/commands/NodePackageManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const vscode = require("vscode");
const { EXTENSION_NAME, REQUIRED_PACKAGES } = require("../utils/constants");
const SfdxScannerInstaller = require("./SfdxScannerInstaller");
const CommonUtils = require("../utils/CommonUtils");
const EnvironmentCheck = require("../utils/EnvironmentCheck");

class NodePackageManager {
static async managePackages(context) {
Expand All @@ -28,9 +29,8 @@ class NodePackageManager {
}

static async checkNodeInstallation() {
try {
await CommonUtils.execCommand("node -v");
} catch (error) {
const nodeCheck = await EnvironmentCheck.checkNodeJS();
if (!nodeCheck.installed) {
throw new Error(
`${EXTENSION_NAME}: Node.js is not installed. Please install Node.js to use this extension.`
);
Expand All @@ -54,10 +54,9 @@ class NodePackageManager {
);
}

const missingPackages = this.getMissingPackages(stdout, packagesToCheck);
return missingPackages;
return this.getMissingPackages(stdout, packagesToCheck);
} catch (error) {
const stdout = error.message;
const stdout = error.message || "";
const missingPackages = this.getMissingPackages(
stdout,
REQUIRED_PACKAGES
Expand All @@ -78,15 +77,24 @@ class NodePackageManager {
}

static getMissingPackages(stdout, packagesToInstall) {
// Filter out packages that are already installed
const missingPackages = packagesToInstall.filter(
(pkg) => !stdout.includes(pkg)
);
const hasPrettierPluginApex = stdout.includes("prettier-plugin-apex");
const hasIlyamatsuevPrettierPluginApex = stdout.includes(
"@ilyamatsuev/prettier-plugin-apex"
);

if (!hasPrettierPluginApex && !hasIlyamatsuevPrettierPluginApex) {
// Special handling for prettier-plugin-apex (check for alternative package)
const prettierApexIndex = missingPackages.indexOf("prettier-plugin-apex");
if (prettierApexIndex !== -1) {
// Check if the alternative ilyamatsuev package is installed
if (stdout.includes("@ilyamatsuev/prettier-plugin-apex")) {
missingPackages.splice(prettierApexIndex, 1);
}
} else if (
!stdout.includes("prettier-plugin-apex") &&
!stdout.includes("@ilyamatsuev/prettier-plugin-apex") &&
!missingPackages.includes("prettier-plugin-apex")
) {
// Neither version is installed, add to missing
missingPackages.push("prettier-plugin-apex");
}

Expand Down
Loading