diff --git a/packages/pyright-scip/src/MainCommand.ts b/packages/pyright-scip/src/MainCommand.ts index 75b60b816..d3965640e 100644 --- a/packages/pyright-scip/src/MainCommand.ts +++ b/packages/pyright-scip/src/MainCommand.ts @@ -10,6 +10,7 @@ export interface IndexOptions { output: string; cwd: string; targetOnly?: string; + infer?: { projectVersionFromCommit: boolean }; // Progress reporting configuration quiet: boolean; diff --git a/packages/pyright-scip/src/main-impl.ts b/packages/pyright-scip/src/main-impl.ts index b887276c3..99c504064 100644 --- a/packages/pyright-scip/src/main-impl.ts +++ b/packages/pyright-scip/src/main-impl.ts @@ -30,7 +30,7 @@ function indexAction(options: IndexOptions): void { ...options, projectRoot, environment, - infer: { projectVersionFromCommit: true }, + infer: options.infer ?? { projectVersionFromCommit: true }, writeIndex: (partialIndex: scip.Index): void => { fs.writeSync(output, partialIndex.serializeBinary()); }, @@ -54,55 +54,37 @@ function indexAction(options: IndexOptions): void { } function snapshotAction(snapshotRoot: string, options: SnapshotOptions): void { - setQuiet(options.quiet); - if (options.showProgressRateLimit !== undefined) { - setShowProgressRateLimit(options.showProgressRateLimit); - } - - console.log('... Snapshotting ... '); - const environment = options.environment ? path.resolve(options.environment) : undefined; - - const snapshotOnly = options.only; - + const subdir: string = options.only; const inputDirectory = path.resolve(join(snapshotRoot, 'input')); const outputDirectory = path.resolve(join(snapshotRoot, 'output')); - // Either read all the directories or just the one passed in by name let snapshotDirectories = fs.readdirSync(inputDirectory); - if (snapshotOnly) { - snapshotDirectories = [snapshotOnly]; + if (subdir) { + console.assert(snapshotDirectories.find((val) => val === subdir) !== undefined); + snapshotDirectories = [subdir]; } for (const snapshotDir of snapshotDirectories) { let projectRoot = join(inputDirectory, snapshotDir); - if (!fs.lstatSync(projectRoot).isDirectory()) { - continue; - } - - projectRoot = path.resolve(projectRoot); - const originalWorkdir = process.cwd(); - process.chdir(projectRoot); - - const scipBinaryFile = path.join(projectRoot, options.output); - const output = fs.openSync(scipBinaryFile, 'w'); - - if (options.index) { - let indexer = new Indexer({ - ...options, - projectRoot, - environment, - infer: { projectVersionFromCommit: false }, - writeIndex: (partialIndex: any): void => { - fs.writeSync(output, partialIndex.serializeBinary()); - }, - }); - indexer.index(); - fs.close(output); - } - - const contents = fs.readFileSync(scipBinaryFile); - const scipIndex = scip.Index.deserializeBinary(contents); + console.assert(fs.lstatSync(projectRoot).isDirectory()); + console.log(`Output path = ${options.output}`); + + indexAction({ + projectName: options.projectName, + projectVersion: options.projectVersion, + projectNamespace: options.projectNamespace, + environment: options.environment ? path.resolve(options.environment) : undefined, + dev: options.dev, + output: options.output, + cwd: projectRoot, + targetOnly: options.targetOnly, + infer: { projectVersionFromCommit: false }, + quiet: options.quiet, + showProgressRateLimit: undefined, + }); + const scipIndexPath = path.join(projectRoot, options.output); + const scipIndex = scip.Index.deserializeBinary(fs.readFileSync(scipIndexPath)); for (const doc of scipIndex.documents) { if (doc.relative_path.startsWith('..')) { continue; @@ -120,8 +102,6 @@ function snapshotAction(snapshotRoot: string, options: SnapshotOptions): void { writeSnapshot(outputPath, obtained); } } - - process.chdir(originalWorkdir); } } diff --git a/packages/pyright-scip/test/test-main.ts b/packages/pyright-scip/test/test-main.ts index 1b35ecb89..56becd5a7 100644 --- a/packages/pyright-scip/test/test-main.ts +++ b/packages/pyright-scip/test/test-main.ts @@ -32,7 +32,7 @@ function testMain(mode: 'check' | 'update'): void { projectVersion, '--only', subdirName, - ]; + ]; // FIXME: This should pass with a --dev flag if (mode === 'check') { argv.push('--check'); }