Skip to content

Commit 73ea97d

Browse files
authored
Merge pull request #461 from clemgbld/refacto/async-dispose-temp-directory-class
refactor(TempDirectory): use Symbol.asyncDispose for async cleanup
2 parents d272495 + c94285f commit 73ea97d

File tree

4 files changed

+11
-4
lines changed

4 files changed

+11
-4
lines changed

.changeset/bright-insects-cough.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nodesecure/scanner": minor
3+
---
4+
5+
refactor(TempDirectory): use Symbol.asyncDispose for automatic async cleanup

workspaces/scanner/src/class/TempDirectory.class.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,8 @@ export class TempDirectory {
3434

3535
return this;
3636
}
37+
38+
async [Symbol.asyncDispose]() {
39+
await this.clear();
40+
}
3741
}

workspaces/scanner/src/depWalker.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export async function depWalker(
9494
registry
9595
} = options;
9696

97-
const tempDir = await TempDirectory.create();
97+
await using tempDir = await TempDirectory.create();
9898

9999
const payload: Partial<Payload> = {
100100
id: tempDir.id,
@@ -284,7 +284,6 @@ export async function depWalker(
284284
}
285285
finally {
286286
await timers.setImmediate();
287-
await tempDir.clear();
288287

289288
logger.emit(ScannerLoggerEvents.done);
290289
}

workspaces/scanner/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export async function verify(
8888
return tarball.scanPackage(process.cwd());
8989
}
9090

91-
const tempDir = await TempDirectory.create();
91+
await using tempDir = await TempDirectory.create();
9292

9393
try {
9494
const mama = await tarball.extractAndResolve(tempDir.location, {
@@ -101,7 +101,6 @@ export async function verify(
101101
}
102102
finally {
103103
await timers.setImmediate();
104-
await tempDir.clear();
105104
}
106105
}
107106

0 commit comments

Comments
 (0)