diff --git a/packages/pyright-scip/src/MainCommand.ts b/packages/pyright-scip/src/MainCommand.ts index d3965640e..5bde7727d 100644 --- a/packages/pyright-scip/src/MainCommand.ts +++ b/packages/pyright-scip/src/MainCommand.ts @@ -64,7 +64,11 @@ export function mainCommand( .option('--project-namespace ', 'A prefix to prepend to all module definitions in the current index') .option('--cwd ', 'working directory for executing scip-python', process.cwd()) .option('--target-only ', 'limit analysis to the following path') - .option('--output ', 'path to the output file', DEFAULT_OUTPUT_FILE) + .option( + '--output ', + 'Path to the output file. If this path is relative, it is interpreted relative to the value for --cwd.', + DEFAULT_OUTPUT_FILE + ) .option('--quiet', 'run without logging and status information', false) .option( '--show-progress-rate-limit ', @@ -85,7 +89,11 @@ export function mainCommand( .option('--only ', 'only generate snapshots for ') .requiredOption('--project-name ', 'the name of the current project, pypi name if applicable') .requiredOption('--project-version ', 'the name of the current project, pypi name if applicable') - .option('--output ', 'path to the output file', DEFAULT_OUTPUT_FILE) + .option( + '--output ', + 'Path to the output file. If this path is relative, it is interpreted relative to the value for --cwd.', + DEFAULT_OUTPUT_FILE + ) .option('--environment ', 'the environment json file (experimental)') .option('--no-index', 'skip indexing (use existing index.scip)') .option('--quiet', 'run without logging and status information', false) diff --git a/packages/pyright-scip/src/main-impl.ts b/packages/pyright-scip/src/main-impl.ts index 443dda638..5b96d2686 100644 --- a/packages/pyright-scip/src/main-impl.ts +++ b/packages/pyright-scip/src/main-impl.ts @@ -22,7 +22,13 @@ function indexAction(options: IndexOptions): void { const originalWorkdir = process.cwd(); process.chdir(projectRoot); - const outputFile = path.isAbsolute(options.output) ? options.output : path.join(originalWorkdir, options.output); + // In the relative path case, we use projectRoot rather than + // originalWorkdir because: + // 1. To preserve back-compat in case anyone is relying on projectRoot + // 2. The actual CLI flag for specifying the project root is --cwd, + // which may lead to the expectation that output is considered + // relative to the project root. + const outputFile = path.isAbsolute(options.output) ? options.output : path.join(projectRoot, options.output); const output = fs.openSync(outputFile, 'w'); try {