Skip to content

refactor(TempDirectory): use Symbol.asyncDispose for async cleanup #461

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/bright-insects-cough.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nodesecure/scanner": minor
---

refactor(TempDirectory): use Symbol.asyncDispose for automatic async cleanup
4 changes: 4 additions & 0 deletions workspaces/scanner/src/class/TempDirectory.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ export class TempDirectory {

return this;
}

async [Symbol.asyncDispose]() {
await this.clear();
}
}
3 changes: 1 addition & 2 deletions workspaces/scanner/src/depWalker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export async function depWalker(
registry
} = options;

const tempDir = await TempDirectory.create();
await using tempDir = await TempDirectory.create();

const payload: Partial<Payload> = {
id: tempDir.id,
Expand Down Expand Up @@ -284,7 +284,6 @@ export async function depWalker(
}
finally {
await timers.setImmediate();
await tempDir.clear();

logger.emit(ScannerLoggerEvents.done);
}
Expand Down
3 changes: 1 addition & 2 deletions workspaces/scanner/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export async function verify(
return tarball.scanPackage(process.cwd());
}

const tempDir = await TempDirectory.create();
await using tempDir = await TempDirectory.create();

try {
const mama = await tarball.extractAndResolve(tempDir.location, {
Expand All @@ -101,7 +101,6 @@ export async function verify(
}
finally {
await timers.setImmediate();
await tempDir.clear();
}
}

Expand Down