forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preserve
next-env.d.ts
line ending (vercel#28100)
* Preserve `next-env.d.ts` line ending Prevent next from changing already existing line ending on `next-env.d.ts` for no good reason * Update comparison Co-authored-by: Steven <[email protected]> * Update checks and add tests * update test Co-authored-by: Steven <[email protected]> Co-authored-by: [email protected] <[email protected]>
- Loading branch information
1 parent
05a732e
commit 23ce41e
Showing
2 changed files
with
107 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* eslint-env jest */ | ||
import os from 'os' | ||
import fs from 'fs-extra' | ||
import { join } from 'path' | ||
import { writeAppTypeDeclarations } from 'next/dist/lib/typescript/writeAppTypeDeclarations' | ||
|
||
const fixtureDir = join(__dirname, 'fixtures/app-declarations') | ||
const declarationFile = join(fixtureDir, 'next-env.d.ts') | ||
const imageImportsEnabled = false | ||
|
||
describe('find config', () => { | ||
afterEach(() => fs.remove(declarationFile)) | ||
|
||
it('should preserve CRLF EOL', async () => { | ||
const eol = '\r\n' | ||
const content = | ||
'/// <reference types="next" />' + | ||
eol + | ||
'/// <reference types="next/types/global" />' + | ||
eol + | ||
(imageImportsEnabled | ||
? '/// <reference types="next/image-types/global" />' + eol | ||
: '') + | ||
eol + | ||
'// NOTE: This file should not be edited' + | ||
eol + | ||
'// see https://nextjs.org/docs/basic-features/typescript for more information.' + | ||
eol | ||
|
||
await fs.ensureDir(fixtureDir) | ||
await fs.writeFile(declarationFile, content) | ||
|
||
await writeAppTypeDeclarations(fixtureDir, imageImportsEnabled) | ||
expect(await fs.readFile(declarationFile, 'utf8')).toBe(content) | ||
}) | ||
|
||
it('should preserve LF EOL', async () => { | ||
const eol = '\n' | ||
const content = | ||
'/// <reference types="next" />' + | ||
eol + | ||
'/// <reference types="next/types/global" />' + | ||
eol + | ||
(imageImportsEnabled | ||
? '/// <reference types="next/image-types/global" />' + eol | ||
: '') + | ||
eol + | ||
'// NOTE: This file should not be edited' + | ||
eol + | ||
'// see https://nextjs.org/docs/basic-features/typescript for more information.' + | ||
eol | ||
|
||
await fs.ensureDir(fixtureDir) | ||
await fs.writeFile(declarationFile, content) | ||
|
||
await writeAppTypeDeclarations(fixtureDir, imageImportsEnabled) | ||
expect(await fs.readFile(declarationFile, 'utf8')).toBe(content) | ||
}) | ||
|
||
it('should use OS EOL by default', async () => { | ||
const eol = os.EOL | ||
const content = | ||
'/// <reference types="next" />' + | ||
eol + | ||
'/// <reference types="next/types/global" />' + | ||
eol + | ||
(imageImportsEnabled | ||
? '/// <reference types="next/image-types/global" />' + eol | ||
: '') + | ||
eol + | ||
'// NOTE: This file should not be edited' + | ||
eol + | ||
'// see https://nextjs.org/docs/basic-features/typescript for more information.' + | ||
eol | ||
|
||
await fs.ensureDir(fixtureDir) | ||
await writeAppTypeDeclarations(fixtureDir, imageImportsEnabled) | ||
expect(await fs.readFile(declarationFile, 'utf8')).toBe(content) | ||
}) | ||
}) |