1- import { ResultAsync , ok , okAsync } from "neverthrow" ;
1+ import { ResultAsync , err , ok , okAsync } from "neverthrow" ;
22import { performance } from "node:perf_hooks" ;
33import { join } from "pathe" ;
44import { changeDir } from "./change-dir" ;
@@ -168,35 +168,53 @@ export const extractPackageApi = ({
168168 )
169169 . andThen ( ( ctx ) => changeDir ( ctx . rootDir ) . map ( ( ) => ctx ) )
170170 . andThen ( ( ctx ) =>
171- installPackage ( ctx . pkg ) . map ( ( installedPackages ) => ( {
172- ...ctx ,
173- nodeModulesDir : join ( ctx . rootDir , "node_modules" ) ,
174- pkgDir : join ( ctx . rootDir , "node_modules" , ctx . pkgName ) ,
175- installedPackages,
176- } ) ) ,
171+ installPackage ( ctx . pkg )
172+ . map ( ( installedPackages ) => ( {
173+ ...ctx ,
174+ nodeModulesDir : join ( ctx . rootDir , "node_modules" ) ,
175+ pkgDir : join ( ctx . rootDir , "node_modules" , ctx . pkgName ) ,
176+ installedPackages,
177+ } ) )
178+ . orElse ( ( e ) => {
179+ changeDir ( ctx . startDir ) ;
180+ return err ( e ) ;
181+ } ) ,
177182 )
178183 . andThen ( ( ctx ) =>
179- packageJson ( ctx . pkgDir ) . map ( ( pkgJson ) => ( {
180- ...ctx ,
181- pkgJson,
182- } ) ) ,
184+ packageJson ( ctx . pkgDir )
185+ . map ( ( pkgJson ) => ( {
186+ ...ctx ,
187+ pkgJson,
188+ } ) )
189+ . orElse ( ( e ) => {
190+ changeDir ( ctx . startDir ) ;
191+ return err ( e ) ;
192+ } ) ,
183193 )
184194 . andThen ( ( ctx ) =>
185- packageTypes ( ctx . pkgJson , ctx . pkgSubpath ) . map ( ( pkgTypes ) => ( {
186- ...ctx ,
187- pkgTypes,
188- typesFilePath : join ( ctx . pkgDir , pkgTypes ) ,
189- } ) ) ,
195+ packageTypes ( ctx . pkgJson , ctx . pkgSubpath )
196+ . map ( ( pkgTypes ) => ( {
197+ ...ctx ,
198+ pkgTypes,
199+ typesFilePath : join ( ctx . pkgDir , pkgTypes ) ,
200+ } ) )
201+ . orElse ( ( e ) => {
202+ changeDir ( ctx . startDir ) ;
203+ return err ( e ) ;
204+ } ) ,
190205 )
191206 . andThen ( ( ctx ) =>
192- createProject ( ctx . typesFilePath ) . map (
193- ( { project, indexFile, sourceFiles } ) => ( {
207+ createProject ( ctx . typesFilePath )
208+ . map ( ( { project, indexFile, sourceFiles } ) => ( {
194209 ...ctx ,
195210 project,
196211 indexFile,
197212 sourceFiles,
213+ } ) )
214+ . orElse ( ( e ) => {
215+ changeDir ( ctx . startDir ) ;
216+ return err ( e ) ;
198217 } ) ,
199- ) ,
200218 )
201219 . andThen ( ( ctx ) =>
202220 ok ( packageOverview ( ctx . indexFile ) ) . map ( ( pkgOverview ) => ( {
@@ -210,10 +228,15 @@ export const extractPackageApi = ({
210228 project : ctx . project ,
211229 indexFile : ctx . indexFile ,
212230 maxDepth : ctx . maxDepth ,
213- } ) . map ( ( pkgDeclarations ) => ( {
214- ...ctx ,
215- pkgDeclarations,
216- } ) ) ,
231+ } )
232+ . map ( ( pkgDeclarations ) => ( {
233+ ...ctx ,
234+ pkgDeclarations,
235+ } ) )
236+ . orElse ( ( e ) => {
237+ changeDir ( ctx . startDir ) ;
238+ return err ( e ) ;
239+ } ) ,
217240 )
218241 . andThen ( ( ctx ) =>
219242 changeDir ( ctx . startDir )
0 commit comments