File tree Expand file tree Collapse file tree 1 file changed +14
-8
lines changed Expand file tree Collapse file tree 1 file changed +14
-8
lines changed Original file line number Diff line number Diff line change 11import { Result , err , ok } from "neverthrow" ;
2+ import process from "node:process" ;
23import {
34 ModuleKind ,
45 ModuleResolutionKind ,
@@ -22,13 +23,24 @@ export const createProject = ({
2223 indexFilePath,
2324 cwd,
2425} : CreateProjectOptions ) : Result < ProjectContainer , ProjectError > => {
25- let startDir ;
2626 try {
2727 // By default, ts-morph creates the project in the current working directory.
2828 // We must change it to the temporary directory where the packages are installed,
2929 // otherwise TypeScript will pick up type definitions from our local `node_modules`.
30- startDir = process . cwd ( ) ;
30+ const startDir = process . cwd ( ) ;
3131 process . chdir ( cwd ) ;
32+ const res = _createProject ( indexFilePath ) ;
33+ process . chdir ( startDir ) ;
34+ return res ;
35+ } catch ( e ) {
36+ return err ( new ProjectError ( "failed to change directories" , { cause : e } ) ) ;
37+ }
38+ } ;
39+
40+ const _createProject = (
41+ indexFilePath : string ,
42+ ) : Result < ProjectContainer , ProjectError > => {
43+ try {
3244 const project = new Project ( {
3345 compilerOptions : {
3446 // See https://github.com/dsherret/ts-morph/issues/938
@@ -47,11 +59,5 @@ export const createProject = ({
4759 } ) ;
4860 } catch ( e ) {
4961 return err ( new ProjectError ( "failed to create project" , { cause : e } ) ) ;
50- } finally {
51- try {
52- if ( startDir ) {
53- process . chdir ( startDir ) ;
54- }
55- } catch { }
5662 }
5763} ;
You can’t perform that action at this time.
0 commit comments