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
11 changes: 10 additions & 1 deletion .node-scripts/validate-changed-package-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,16 @@ function identifyIncorrectlyVersionedPackages(changedPackages) {
const incorrectlyVersionedPackages = [];

for (const changedPackage of changedPackages) {
if (isPackageThatHasNotPublished(changedPackage)) {
continue; // We can't check previous versions of this package because it hasn't published yet, so the version must be correct
}

const packageJsonPath = path.join(changedPackage, 'package.json');
if (!fs.existsSync(packageJsonPath)) {
continue; // This means the package was deleted, so we ignore this package
}

const packageVersion = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')).version;

if (!packageVersion.endsWith('-SNAPSHOT')) {
incorrectlyVersionedPackages.push(`${changedPackage} (currently versioned as ${packageVersion}) lacks a trailing "-SNAPSHOT"`);
continue;
Expand All @@ -109,4 +112,10 @@ function getLatestReleasedVersion(changedPackage) {
}
}

function isPackageThatHasNotPublished(changedPackage) {
return [
"packages/ENGINE-TEMPLATE"
].includes(changedPackage.replace("\\","/"));
}

main();
29 changes: 14 additions & 15 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions packages/ENGINE-TEMPLATE/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"types": "dist/index.d.ts",
"dependencies": {
"@types/node": "^20.0.0",
"@salesforce/code-analyzer-engine-api": "0.28.0"
"@salesforce/code-analyzer-engine-api": "0.29.0-SNAPSHOT"
},
"devDependencies": {
"@eslint/js": "^9.32.0",
Expand All @@ -36,7 +36,7 @@
],
"scripts": {
"build": "tsc --build tsconfig.build.json --verbose",
"test": "jest --coverage",
"test": "tsc --build tsconfig.json && jest --coverage",
"lint": "eslint src/**/*.ts",
"package": "npm pack",
"all": "npm run build && npm run lint && npm run test && npm run package",
Expand Down
18 changes: 5 additions & 13 deletions packages/ENGINE-TEMPLATE/test/engine.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { EngineRunResults, RuleDescription, RunOptions, Workspace } from "@salesforce/code-analyzer-engine-api";
import fs from "node:fs";
import * as os from "node:os";
import path from "path";
import * as fs from "node:fs";
import * as path from "path";
import { TemplateEngine } from "../src/engine";
import { changeWorkingDirectoryToPackageRoot } from "./test-helpers";
import { changeWorkingDirectoryToPackageRoot, createDescribeOptions, createRunOptions } from "./test-helpers";

changeWorkingDirectoryToPackageRoot();

Expand Down Expand Up @@ -41,7 +40,7 @@ describe('Template Engine Tests', () => {
// add more checks for specific rules, describe options, and logging events
it('When no workspace is provided, then all rules are returned', async () => {
const engine: TemplateEngine = new TemplateEngine();
const rules: RuleDescription[] = await engine.describeRules({logFolder: os.tmpdir()});
const rules: RuleDescription[] = await engine.describeRules(createDescribeOptions());

expect(rules).toEqual(ALL_EXPECTED_RULES);
});
Expand All @@ -64,11 +63,4 @@ describe('Template Engine Tests', () => {
const expectedRulesJsonStr: string = (await fs.promises.readFile(path.join(TEST_DATA_FOLDER, relativeExpectedFile), 'utf-8'));
return JSON.parse(expectedRulesJsonStr) as RuleDescription[];
}

function createRunOptions(workspace: Workspace): RunOptions {
return {
logFolder: os.tmpdir(),
workspace: workspace
}
}
});
});
23 changes: 21 additions & 2 deletions packages/ENGINE-TEMPLATE/test/test-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import process from "node:process";
import path from "node:path";
import { DescribeOptions, RunOptions, Workspace } from "@salesforce/code-analyzer-engine-api";
import * as fs from "node:fs";
import * as os from "node:os";
import * as path from "node:path";
import * as process from "node:process";

export function changeWorkingDirectoryToPackageRoot() {
let original_working_directory: string;
Expand All @@ -16,3 +19,19 @@ export function changeWorkingDirectoryToPackageRoot() {
process.chdir(original_working_directory);
});
}

export function createDescribeOptions(workspace?: Workspace): DescribeOptions {
return {
logFolder: os.tmpdir(),
workspace: workspace,
workingFolder: fs.mkdtempSync(path.join(os.tmpdir(),'tmp-'))
}
}

export function createRunOptions(workspace: Workspace): RunOptions {
return {
logFolder: os.tmpdir(),
workspace: workspace,
workingFolder: fs.mkdtempSync(path.join(os.tmpdir(),'tmp-'))
}
}
4 changes: 1 addition & 3 deletions packages/ENGINE-TEMPLATE/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"composite": true,
"outDir": "./dist",
"rootDir": ".",
"isolatedModules": true
"noEmit": true
},
"include": [
"./src",
Expand Down
10 changes: 6 additions & 4 deletions packages/code-analyzer-core/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@salesforce/code-analyzer-core",
"description": "Core Package for the Salesforce Code Analyzer",
"version": "0.34.0",
"version": "0.35.0-SNAPSHOT",
"author": "The Salesforce Code Analyzer Team",
"license": "BSD-3-Clause",
"homepage": "https://developer.salesforce.com/docs/platform/salesforce-code-analyzer/overview",
Expand All @@ -16,19 +16,21 @@
},
"types": "dist/index.d.ts",
"dependencies": {
"@salesforce/code-analyzer-engine-api": "0.28.0",
"@salesforce/code-analyzer-engine-api": "0.29.0-SNAPSHOT",
"@types/node": "^20.0.0",
"csv-stringify": "^6.6.0",
"js-yaml": "^4.1.0",
"semver": "^7.7.2",
"xmlbuilder": "^15.1.1"
"xmlbuilder": "^15.1.1",
"tmp": "^0.2.3"
},
"devDependencies": {
"@eslint/js": "^9.32.0",
"@types/js-yaml": "^4.0.9",
"@types/jest": "^30.0.0",
"@types/sarif": "^2.1.7",
"@types/semver": "^7.7.0",
"@types/tmp": "^0.2.6",
"cross-env": "^10.0.0",
"eslint": "^9.32.0",
"jest": "^30.0.5",
Expand All @@ -48,7 +50,7 @@
],
"scripts": {
"build": "tsc --build tsconfig.build.json --verbose",
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage",
"test": "tsc --build tsconfig.json && cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage",
"lint": "eslint src/**/*.ts",
"package": "npm pack",
"all": "npm run build && npm run lint && npm run test && npm run package",
Expand Down
15 changes: 10 additions & 5 deletions packages/code-analyzer-core/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import path from "node:path";
import * as tmp from 'tmp';
import * as path from "node:path";
import crypto from "node:crypto";
import fs from "node:fs";
import {createTempDir} from "@salesforce/code-analyzer-engine-api/utils";
import * as fs from "node:fs";
import {promisify} from "node:util";

// THIS FILE CONTAINS UTILITIES WHICH ARE USED INTERNALLY ONLY.
// None of the following exported interfaces and functions should be exported from the index file.

tmp.setGracefulCleanup();
const tmpDirAsync = promisify((options: tmp.DirOptions, cb: tmp.DirCallback) => tmp.dir(options, cb));


export function toAbsolutePath(fileOrFolder: string): string {
// Convert slashes to platform specific slashes and then convert to absolute path
return path.resolve(fileOrFolder.replace(/[\\/]/g, path.sep));
Expand Down Expand Up @@ -39,7 +44,7 @@ export class RuntimeTempFolder implements TempFolder {

async getPath(): Promise<string> {
if (!this.rootFolder) {
this.rootFolder = await createTempDir();
this.rootFolder = await tmpDirAsync({keep: false, unsafeCleanup: true});
}
return this.rootFolder;
}
Expand Down Expand Up @@ -125,4 +130,4 @@ export function deepEquals(value1: unknown, value2: unknown): boolean {

// For all other types (number, string, boolean, etc.), use strict equality
return false;
}
}
4 changes: 1 addition & 3 deletions packages/code-analyzer-core/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"composite": true,
"outDir": "./dist",
"rootDir": ".",
"isolatedModules": true
"noEmit": true
},
"include": [
"./src",
Expand Down
8 changes: 3 additions & 5 deletions packages/code-analyzer-engine-api/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@salesforce/code-analyzer-engine-api",
"description": "Engine API Package for the Salesforce Code Analyzer",
"version": "0.28.0",
"version": "0.29.0-SNAPSHOT",
"author": "The Salesforce Code Analyzer Team",
"license": "BSD-3-Clause",
"homepage": "https://developer.salesforce.com/docs/platform/salesforce-code-analyzer/overview",
Expand All @@ -16,13 +16,11 @@
},
"types": "dist/index.d.ts",
"dependencies": {
"@types/node": "^20.0.0",
"tmp": "^0.2.3"
"@types/node": "^20.0.0"
},
"devDependencies": {
"@eslint/js": "^9.32.0",
"@types/jest": "^30.0.0",
"@types/tmp": "^0.2.6",
"eslint": "^9.32.0",
"jest": "^30.0.5",
"rimraf": "^6.0.1",
Expand All @@ -40,7 +38,7 @@
],
"scripts": {
"build": "tsc --build tsconfig.build.json --verbose",
"test": "jest --coverage",
"test": "tsc --build tsconfig.json && jest --coverage",
"lint": "eslint src/**/*.ts",
"package": "npm pack",
"all": "npm run build && npm run lint && npm run test && npm run package",
Expand Down
14 changes: 0 additions & 14 deletions packages/code-analyzer-engine-api/src/utils/fs-utils.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,6 @@
import * as tmp from 'tmp';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can tmp be removed as a dependency in this package now? I see we also have the types in the eslint engine and I'm not sure we need those either:
Screenshot 2025-09-10 at 11 46 54 AM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch. Fixed!

import {promisify} from "node:util";
import path from "node:path";
import fs from "node:fs";

tmp.setGracefulCleanup();
const tmpDirAsync = promisify((options: tmp.DirOptions, cb: tmp.DirCallback) => tmp.dir(options, cb));

/**
* Creates a temporary directory that eventually cleans up after itself
* @param parentTempDir - if supplied, then a temporary folder is placed directly underneath this parent folder.
*/
export async function createTempDir(parentTempDir?: string) : Promise<string> {
return tmpDirAsync({dir: parentTempDir, keep: false, unsafeCleanup: true});
}


/**
* Returns the longest common parent folder of the provided paths.
* If empty or if no common parent folder exists, like in the case on Windows machines of using two different drives
Expand Down
Loading
Loading