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> {
}
}

// TODO: remove after https://github.com/npm/node-tar/issues/321 is resolved
function swallowPrematureStreamClose(e: Error & { code?: string }) {
if (
process.version.startsWith('v18.') &&
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)
}