Skip to content

Commit

Permalink
fix(cli): delete temp file after extraction (#40259)
Browse files Browse the repository at this point in the history
Follow-up on the review comment #40182 (comment) 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)
  • Loading branch information
balazsorban44 committed Sep 6, 2022
1 parent 8698b49 commit fa08a17
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/create-next-app/helpers/examples.ts
Expand Up @@ -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)

Expand Down Expand Up @@ -83,7 +83,7 @@ export function existsInRepo(nameOrUrl: string): Promise<boolean> {
}

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
}
Expand All @@ -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) {
Expand All @@ -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)
}

0 comments on commit fa08a17

Please sign in to comment.