Skip to content

Commit

Permalink
@W-17397557@ Core now prepends node homedir onto PATH
Browse files Browse the repository at this point in the history
  • Loading branch information
jfeingold35 committed Dec 11, 2024
1 parent a25ff11 commit 165a28e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/code-analyzer-core/src/code-analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
UniqueIdGenerator
} from "./utils";
import fs from "node:fs";
import path from 'node:path';

export interface Workspace {
getWorkspaceId(): string
Expand Down Expand Up @@ -61,6 +62,8 @@ export class CodeAnalyzer {
if (semver.major < MINIMUM_SUPPORTED_NODE) {
throw new Error(getMessage('UnsupportedNodeVersion', MINIMUM_SUPPORTED_NODE, version));
}
const nodeHomeDir: string = path.dirname(process.execPath);
process.env.PATH = `${nodeHomeDir}${path.delimiter}${process.env.PATH}`;
}

// For testing purposes only
Expand Down
12 changes: 12 additions & 0 deletions packages/code-analyzer-core/test/code-analyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ describe("Tests for CodeAnalyzer constructor", () => {
])('When supplied with a Node Version of v20 or later, construction succeeds. Case: $version"', ({version}) => {
expect(new CodeAnalyzer(CodeAnalyzerConfig.withDefaults(), version)).toBeInstanceOf(CodeAnalyzer);
});

it("Constructor prepends the currently-running Node's parent folder to the PATH", () => {
// Figure out what the current value of PATH is.
const initialPath: string = process.env.PATH || '';
const nodeParentDir: string = path.dirname(process.execPath);

// Instantiate a Code Analyzer.
const codeAnalyzer: CodeAnalyzer = new CodeAnalyzer(CodeAnalyzerConfig.withDefaults());

// Verify that the PATH was changed.
expect(process.env.PATH).toEqual(`${nodeParentDir}${path.delimiter}${initialPath}`);
});
});

describe("Tests for the run method of CodeAnalyzer", () => {
Expand Down

0 comments on commit 165a28e

Please sign in to comment.