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): do not throw error when extracting examples in Node 18+ #40182

Merged
merged 7 commits into from Sep 5, 2022
15 changes: 13 additions & 2 deletions packages/create-next-app/helpers/examples.ts
Expand Up @@ -79,6 +79,17 @@ export function existsInRepo(nameOrUrl: string): Promise<boolean> {
}
}

// HACK: See: https://github.com/vercel/next.js/issues/39321
balazsorban44 marked this conversation as resolved.
Show resolved Hide resolved
function swallowPrematureStreamClose(e: Error & { code?: string }) {
if (
process.version.startsWith('v18') &&
balazsorban44 marked this conversation as resolved.
Show resolved Hide resolved
e.code === 'ERR_STREAM_PREMATURE_CLOSE'
) {
return
}
throw e
}

export function downloadAndExtractRepo(
root: string,
{ username, name, branch, filePath }: RepoInfo
Expand All @@ -91,7 +102,7 @@ export function downloadAndExtractRepo(
{ cwd: root, strip: filePath ? filePath.split('/').length + 1 : 1 },
[`${name}-${branch.replace(/\//g, '-')}${filePath ? `/${filePath}` : ''}`]
)
)
).catch(swallowPrematureStreamClose)
}

export function downloadAndExtractExample(
Expand All @@ -105,5 +116,5 @@ export function downloadAndExtractExample(
return pipeline(
got.stream('https://codeload.github.com/vercel/next.js/tar.gz/canary'),
tar.extract({ cwd: root, strip: 3 }, [`next.js-canary/examples/${name}`])
)
).catch(swallowPrematureStreamClose)
}