Skip to content

Commit d6c4fe6

Browse files
cleanup: Reset original workdir after change (sourcegraph#114)
1 parent 52de5e5 commit d6c4fe6

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

packages/pyright-scip/src/main-impl.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function indexAction(options: IndexOptions): void {
2020
const snapshotDir = options.snapshotDir;
2121
const environment = options.environment;
2222

23+
const originalWorkdir = process.cwd();
2324
process.chdir(projectRoot);
2425

2526
const outputFile = path.join(projectRoot, options.output);
@@ -44,6 +45,7 @@ function indexAction(options: IndexOptions): void {
4445
'\n\nExperienced Fatal Error While Indexing:\nPlease create an issue at github.com/sourcegraph/scip-python:',
4546
e
4647
);
48+
process.chdir(originalWorkdir);
4749
exit(1);
4850
}
4951

@@ -67,6 +69,8 @@ function indexAction(options: IndexOptions): void {
6769
writeSnapshot(outputPath, obtained);
6870
}
6971
}
72+
73+
process.chdir(originalWorkdir);
7074
}
7175

7276
function snapshotAction(snapshotRoot: string, options: SnapshotOptions): void {
@@ -96,6 +100,7 @@ function snapshotAction(snapshotRoot: string, options: SnapshotOptions): void {
96100
}
97101

98102
projectRoot = path.resolve(projectRoot);
103+
const originalWorkdir = process.cwd();
99104
process.chdir(projectRoot);
100105

101106
const scipBinaryFile = path.join(projectRoot, options.output);
@@ -135,6 +140,8 @@ function snapshotAction(snapshotRoot: string, options: SnapshotOptions): void {
135140
writeSnapshot(outputPath, obtained);
136141
}
137142
}
143+
144+
process.chdir(originalWorkdir);
138145
}
139146
}
140147

packages/pyright-scip/test/test-main.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@ function testMain(mode: 'check' | 'update'): void {
3737
argv.push('--check');
3838
}
3939
main(argv);
40-
// main changes the working directory; reset it.
41-
process.chdir(startCwd);
4240
}
4341
}
4442

0 commit comments

Comments
 (0)