Skip to content

Commit 69994cd

Browse files
committed
refactor: move Effect.scoped in extractPackageApi
1 parent 5af312b commit 69994cd

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

src/extract-package-api-effect.ts

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,27 @@ export const extractPackageApiEffect = ({
1818
maxDepth = 5,
1919
bunPath = "bun",
2020
}: ExtractPackageApiOptions) =>
21-
Effect.scoped(
22-
Effect.gen(function* (_) {
23-
const startTime = performance.now();
24-
const pkgName = yield* _(packageName(pkg));
25-
const { path: cwd } = yield* _(workDir);
26-
const packages = yield* _(installPackage({ pkg, cwd, bunPath }));
27-
const pkgDir = join(cwd, "node_modules", pkgName);
28-
const pkgJson = yield* _(packageJson(pkgDir));
29-
const types = yield* _(packageTypes(pkgJson, subpath));
30-
const indexFilePath = join(pkgDir, types);
31-
const { project, indexFile } = yield* _(createProject({ indexFilePath, cwd }));
32-
const overview = packageOverview(indexFile);
33-
const declarations = yield* _(packageDeclarations({ pkgName, project, indexFile, maxDepth }));
34-
return {
35-
name: pkgJson.name,
36-
version: pkgJson.version,
37-
subpath,
38-
types,
39-
overview,
40-
declarations,
41-
packages,
42-
analyzedAt: new Date().toISOString(),
43-
analyzedIn: Math.round(performance.now() - startTime),
44-
} satisfies PackageApi;
45-
}),
46-
);
21+
Effect.gen(function* (_) {
22+
const startTime = performance.now();
23+
const pkgName = yield* _(packageName(pkg));
24+
const { path: cwd } = yield* _(workDir);
25+
const packages = yield* _(installPackage({ pkg, cwd, bunPath }));
26+
const pkgDir = join(cwd, "node_modules", pkgName);
27+
const pkgJson = yield* _(packageJson(pkgDir));
28+
const types = yield* _(packageTypes(pkgJson, subpath));
29+
const indexFilePath = join(pkgDir, types);
30+
const { project, indexFile } = yield* _(createProject({ indexFilePath, cwd }));
31+
const overview = packageOverview(indexFile);
32+
const declarations = yield* _(packageDeclarations({ pkgName, project, indexFile, maxDepth }));
33+
return {
34+
name: pkgJson.name,
35+
version: pkgJson.version,
36+
subpath,
37+
types,
38+
overview,
39+
declarations,
40+
packages,
41+
analyzedAt: new Date().toISOString(),
42+
analyzedIn: Math.round(performance.now() - startTime),
43+
} satisfies PackageApi;
44+
});

src/extract-package-api.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,4 +129,4 @@ export const extractPackageApi = ({
129129
maxDepth = 5,
130130
bunPath = "bun",
131131
}: ExtractPackageApiOptions): Promise<PackageApi> =>
132-
Effect.runPromise(extractPackageApiEffect({ pkg, subpath, maxDepth, bunPath }));
132+
Effect.runPromise(Effect.scoped(extractPackageApiEffect({ pkg, subpath, maxDepth, bunPath })));

0 commit comments

Comments
 (0)