From fa08a17768cd6934d7d1ef944849c54a162ee799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Tue, 6 Sep 2022 13:29:25 +0200 Subject: [PATCH] fix(cli): delete temp file after extraction (#40259) Follow-up on the review comment https://github.com/vercel/next.js/pull/40182#discussion_r963036314 since the PR was merged. ## Bug - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` ## Feature - [ ] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR. - [ ] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Documentation added - [ ] Telemetry added. In case of a feature if it's used or not. - [ ] Errors have helpful link attached, see `contributing.md` ## Documentation / Examples - [ ] Make sure the linting passes by running `pnpm lint` - [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples) --- 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) }