Skip to content

Commit 98eaaee

Browse files
CHANGE: @W-19397345@: Use provided workingFolder instead of creating new temp dirs
1 parent fa896a5 commit 98eaaee

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+472
-447
lines changed

.node-scripts/validate-changed-package-versions.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,13 +77,16 @@ function identifyIncorrectlyVersionedPackages(changedPackages) {
7777
const incorrectlyVersionedPackages = [];
7878

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

8184
const packageJsonPath = path.join(changedPackage, 'package.json');
8285
if (!fs.existsSync(packageJsonPath)) {
8386
continue; // This means the package was deleted, so we ignore this package
8487
}
88+
8589
const packageVersion = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')).version;
86-
8790
if (!packageVersion.endsWith('-SNAPSHOT')) {
8891
incorrectlyVersionedPackages.push(`${changedPackage} (currently versioned as ${packageVersion}) lacks a trailing "-SNAPSHOT"`);
8992
continue;
@@ -109,4 +112,10 @@ function getLatestReleasedVersion(changedPackage) {
109112
}
110113
}
111114

115+
function isPackageThatHasNotPublished(changedPackage) {
116+
return [
117+
"packages/ENGINE-TEMPLATE"
118+
].includes(changedPackage.replace("\\","/"));
119+
}
120+
112121
main();

package-lock.json

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ENGINE-TEMPLATE/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"types": "dist/index.d.ts",
1515
"dependencies": {
1616
"@types/node": "^20.0.0",
17-
"@salesforce/code-analyzer-engine-api": "0.28.0"
17+
"@salesforce/code-analyzer-engine-api": "0.29.0-SNAPSHOT"
1818
},
1919
"devDependencies": {
2020
"@eslint/js": "^9.32.0",
@@ -36,7 +36,7 @@
3636
],
3737
"scripts": {
3838
"build": "tsc --build tsconfig.build.json --verbose",
39-
"test": "jest --coverage",
39+
"test": "tsc --build tsconfig.json --noEmit && jest --coverage",
4040
"lint": "eslint src/**/*.ts",
4141
"package": "npm pack",
4242
"all": "npm run build && npm run lint && npm run test && npm run package",

packages/ENGINE-TEMPLATE/test/engine.test.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { EngineRunResults, RuleDescription, RunOptions, Workspace } from "@salesforce/code-analyzer-engine-api";
2-
import fs from "node:fs";
3-
import * as os from "node:os";
4-
import path from "path";
2+
import * as fs from "node:fs";
3+
import * as path from "path";
54
import { TemplateEngine } from "../src/engine";
6-
import { changeWorkingDirectoryToPackageRoot } from "./test-helpers";
5+
import { changeWorkingDirectoryToPackageRoot, createDescribeOptions, createRunOptions } from "./test-helpers";
76

87
changeWorkingDirectoryToPackageRoot();
98

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

4645
expect(rules).toEqual(ALL_EXPECTED_RULES);
4746
});
@@ -64,11 +63,4 @@ describe('Template Engine Tests', () => {
6463
const expectedRulesJsonStr: string = (await fs.promises.readFile(path.join(TEST_DATA_FOLDER, relativeExpectedFile), 'utf-8'));
6564
return JSON.parse(expectedRulesJsonStr) as RuleDescription[];
6665
}
67-
68-
function createRunOptions(workspace: Workspace): RunOptions {
69-
return {
70-
logFolder: os.tmpdir(),
71-
workspace: workspace
72-
}
73-
}
74-
});
66+
});

packages/ENGINE-TEMPLATE/test/test-helpers.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
import process from "node:process";
2-
import path from "node:path";
1+
import { DescribeOptions, RunOptions, Workspace } from "@salesforce/code-analyzer-engine-api";
2+
import * as fs from "node:fs";
3+
import * as os from "node:os";
4+
import * as path from "node:path";
5+
import * as process from "node:process";
36

47
export function changeWorkingDirectoryToPackageRoot() {
58
let original_working_directory: string;
@@ -16,3 +19,19 @@ export function changeWorkingDirectoryToPackageRoot() {
1619
process.chdir(original_working_directory);
1720
});
1821
}
22+
23+
export function createDescribeOptions(workspace?: Workspace): DescribeOptions {
24+
return {
25+
logFolder: os.tmpdir(),
26+
workspace: workspace,
27+
workingFolder: fs.mkdtempSync(path.join(os.tmpdir(),'tmp-'))
28+
}
29+
}
30+
31+
export function createRunOptions(workspace: Workspace): RunOptions {
32+
return {
33+
logFolder: os.tmpdir(),
34+
workspace: workspace,
35+
workingFolder: fs.mkdtempSync(path.join(os.tmpdir(),'tmp-'))
36+
}
37+
}

packages/code-analyzer-core/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@salesforce/code-analyzer-core",
33
"description": "Core Package for the Salesforce Code Analyzer",
4-
"version": "0.34.0",
4+
"version": "0.35.0-SNAPSHOT",
55
"author": "The Salesforce Code Analyzer Team",
66
"license": "BSD-3-Clause",
77
"homepage": "https://developer.salesforce.com/docs/platform/salesforce-code-analyzer/overview",
@@ -16,7 +16,7 @@
1616
},
1717
"types": "dist/index.d.ts",
1818
"dependencies": {
19-
"@salesforce/code-analyzer-engine-api": "0.28.0",
19+
"@salesforce/code-analyzer-engine-api": "0.29.0-SNAPSHOT",
2020
"@types/node": "^20.0.0",
2121
"csv-stringify": "^6.6.0",
2222
"js-yaml": "^4.1.0",
@@ -48,7 +48,7 @@
4848
],
4949
"scripts": {
5050
"build": "tsc --build tsconfig.build.json --verbose",
51-
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage",
51+
"test": "tsc --build tsconfig.json --noEmit && cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage",
5252
"lint": "eslint src/**/*.ts",
5353
"package": "npm pack",
5454
"all": "npm run build && npm run lint && npm run test && npm run package",

packages/code-analyzer-core/src/utils.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1-
import path from "node:path";
1+
import * as tmp from 'tmp';
2+
import * as path from "node:path";
23
import crypto from "node:crypto";
3-
import fs from "node:fs";
4-
import {createTempDir} from "@salesforce/code-analyzer-engine-api/utils";
4+
import * as fs from "node:fs";
5+
import {promisify} from "node:util";
56

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

10+
tmp.setGracefulCleanup();
11+
const tmpDirAsync = promisify((options: tmp.DirOptions, cb: tmp.DirCallback) => tmp.dir(options, cb));
12+
13+
914
export function toAbsolutePath(fileOrFolder: string): string {
1015
// Convert slashes to platform specific slashes and then convert to absolute path
1116
return path.resolve(fileOrFolder.replace(/[\\/]/g, path.sep));
@@ -39,7 +44,7 @@ export class RuntimeTempFolder implements TempFolder {
3944

4045
async getPath(): Promise<string> {
4146
if (!this.rootFolder) {
42-
this.rootFolder = await createTempDir();
47+
this.rootFolder = await tmpDirAsync({keep: false, unsafeCleanup: true});
4348
}
4449
return this.rootFolder;
4550
}
@@ -125,4 +130,4 @@ export function deepEquals(value1: unknown, value2: unknown): boolean {
125130

126131
// For all other types (number, string, boolean, etc.), use strict equality
127132
return false;
128-
}
133+
}

packages/code-analyzer-engine-api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@salesforce/code-analyzer-engine-api",
33
"description": "Engine API Package for the Salesforce Code Analyzer",
4-
"version": "0.28.0",
4+
"version": "0.29.0-SNAPSHOT",
55
"author": "The Salesforce Code Analyzer Team",
66
"license": "BSD-3-Clause",
77
"homepage": "https://developer.salesforce.com/docs/platform/salesforce-code-analyzer/overview",
@@ -40,7 +40,7 @@
4040
],
4141
"scripts": {
4242
"build": "tsc --build tsconfig.build.json --verbose",
43-
"test": "jest --coverage",
43+
"test": "tsc --build tsconfig.json --noEmit && jest --coverage",
4444
"lint": "eslint src/**/*.ts",
4545
"package": "npm pack",
4646
"all": "npm run build && npm run lint && npm run test && npm run package",

packages/code-analyzer-engine-api/src/utils/fs-utils.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
1-
import * as tmp from 'tmp';
2-
import {promisify} from "node:util";
31
import path from "node:path";
42
import fs from "node:fs";
53

6-
tmp.setGracefulCleanup();
7-
const tmpDirAsync = promisify((options: tmp.DirOptions, cb: tmp.DirCallback) => tmp.dir(options, cb));
8-
9-
/**
10-
* Creates a temporary directory that eventually cleans up after itself
11-
* @param parentTempDir - if supplied, then a temporary folder is placed directly underneath this parent folder.
12-
*/
13-
export async function createTempDir(parentTempDir?: string) : Promise<string> {
14-
return tmpDirAsync({dir: parentTempDir, keep: false, unsafeCleanup: true});
15-
}
16-
17-
184
/**
195
* Returns the longest common parent folder of the provided paths.
206
* If empty or if no common parent folder exists, like in the case on Windows machines of using two different drives

packages/code-analyzer-engine-api/src/utils/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ export {
55
} from './datetime-utils';
66

77
export {
8-
createTempDir,
98
calculateLongestCommonParentFolderOf
109
} from './fs-utils';
1110

0 commit comments

Comments
 (0)