From 2ed2c2e7f7fdf1a861b4e9dee8b4d89b7dcd1180 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Tue, 6 Sep 2022 12:54:34 +0200 Subject: [PATCH] fix: delete temp file after extraction --- packages/create-next-app/helpers/examples.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/create-next-app/helpers/examples.ts b/packages/create-next-app/helpers/examples.ts index 64a7635cf1d1..961199628d3e 100644 --- a/packages/create-next-app/helpers/examples.ts +++ b/packages/create-next-app/helpers/examples.ts @@ -5,7 +5,7 @@ import { Stream } from 'stream' import { promisify } from 'util' import { join } from 'path' import { tmpdir } from 'os' -import { createWriteStream } from 'fs' +import { createWriteStream, promises as fs } from 'fs' const pipeline = promisify(Stream.pipeline) @@ -83,7 +83,7 @@ export function existsInRepo(nameOrUrl: string): Promise { } async function downloadTar(url: string) { - const tempFile = join(tmpdir(), `next.js-cra-example.temp-${Date.now()}`) + const tempFile = join(tmpdir(), `next.js-cna-example.temp-${Date.now()}`) await pipeline(got.stream(url), createWriteStream(tempFile)) return tempFile } @@ -105,6 +105,8 @@ export async function downloadAndExtractRepo( `${name}-${branch.replace(/\//g, '-')}${filePath ? `/${filePath}` : ''}` ), }) + + await fs.unlink(tempFile) } export async function downloadAndExtractExample(root: string, name: string) { @@ -122,4 +124,6 @@ export async function downloadAndExtractExample(root: string, name: string) { strip: 3, filter: (p) => p.includes(`next.js-canary/examples/${name}`), }) + + await fs.unlink(tempFile) }