Unverified Commit fa08a177 authored by Balázs Orbán's avatar Balázs Orbán Committed by GitHub

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)
parent 8698b492
...@@ -5,7 +5,7 @@ import { Stream } from 'stream' ...@@ -5,7 +5,7 @@ import { Stream } from 'stream'
import { promisify } from 'util' import { promisify } from 'util'
import { join } from 'path' import { join } from 'path'
import { tmpdir } from 'os' import { tmpdir } from 'os'
import { createWriteStream } from 'fs' import { createWriteStream, promises as fs } from 'fs'
const pipeline = promisify(Stream.pipeline) const pipeline = promisify(Stream.pipeline)
...@@ -83,7 +83,7 @@ export function existsInRepo(nameOrUrl: string): Promise<boolean> { ...@@ -83,7 +83,7 @@ export function existsInRepo(nameOrUrl: string): Promise<boolean> {
} }
async function downloadTar(url: string) { 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)) await pipeline(got.stream(url), createWriteStream(tempFile))
return tempFile return tempFile
} }
...@@ -105,6 +105,8 @@ export async function downloadAndExtractRepo( ...@@ -105,6 +105,8 @@ export async function downloadAndExtractRepo(
`${name}-${branch.replace(/\//g, '-')}${filePath ? `/${filePath}` : ''}` `${name}-${branch.replace(/\//g, '-')}${filePath ? `/${filePath}` : ''}`
), ),
}) })
await fs.unlink(tempFile)
} }
export async function downloadAndExtractExample(root: string, name: string) { export async function downloadAndExtractExample(root: string, name: string) {
...@@ -122,4 +124,6 @@ export async function downloadAndExtractExample(root: string, name: string) { ...@@ -122,4 +124,6 @@ export async function downloadAndExtractExample(root: string, name: string) {
strip: 3, strip: 3,
filter: (p) => p.includes(`next.js-canary/examples/${name}`), filter: (p) => p.includes(`next.js-canary/examples/${name}`),
}) })
await fs.unlink(tempFile)
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment