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

Avoid fs write next-env.d.ts on read-only filesystems #28206

Merged
merged 4 commits into from Aug 18, 2021
Merged
Changes from 2 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
33 changes: 19 additions & 14 deletions packages/next/lib/typescript/writeAppTypeDeclarations.ts
Expand Up @@ -9,19 +9,24 @@ export async function writeAppTypeDeclarations(
// Reference `next` types
const appTypeDeclarations = path.join(baseDir, 'next-env.d.ts')

await fs.writeFile(
appTypeDeclarations,
const content =
'/// <reference types="next" />' +
os.EOL +
'/// <reference types="next/types/global" />' +
os.EOL +
(imageImportsEnabled
? '/// <reference types="next/image-types/global" />' + os.EOL
: '') +
os.EOL +
'// NOTE: This file should not be edited' +
os.EOL +
'// see https://nextjs.org/docs/basic-features/typescript for more information.' +
os.EOL
)
os.EOL +
'/// <reference types="next/types/global" />' +
os.EOL +
(imageImportsEnabled
? '/// <reference types="next/image-types/global" />' + os.EOL
: '') +
os.EOL +
'// NOTE: This file should not be edited' +
os.EOL +
'// see https://nextjs.org/docs/basic-features/typescript for more information.' +
os.EOL

// Avoids a write for read-only filesystems
if ((await fs.readFile(appTypeDeclarations, 'utf8')) === content) {
styfle marked this conversation as resolved.
Show resolved Hide resolved
return
}

await fs.writeFile(appTypeDeclarations, content)
}