Skip to content
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

fix(cli): delete temp file after extraction #40259

Merged
merged 1 commit into from Sep 6, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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)
}