Skip to content

Commit

Permalink
Fix TypeScript setup with empty file (vercel#8332)
Browse files Browse the repository at this point in the history
New versions of TypeScript now throw an error when no matching TypeScript files are found. We still want to setup in this case.

-----

Closes vercel#8324
  • Loading branch information
Timer authored and timneutkens committed Aug 12, 2019
1 parent 06876f1 commit ab0384d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
8 changes: 8 additions & 0 deletions packages/next/lib/verifyTypeScriptSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ export async function verifyTypeScriptSetup(dir: string): Promise<void> {
path.dirname(tsConfigPath)
)

if (result.errors) {
result.errors = result.errors.filter(
({ code }) =>
// No inputs were found in config file
code !== 18003
)
}

if (result.errors && result.errors.length) {
throw new Error(
ts.formatDiagnostic(result.errors[0], formatDiagnosticHost)
Expand Down
31 changes: 30 additions & 1 deletion test/integration/tsconfig-verifier/test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
/* eslint-env jest */
/* global jasmine */
import path from 'path'
import { exists, remove, readFile, readJSON, writeJSON } from 'fs-extra'
import {
exists,
remove,
readFile,
readJSON,
writeJSON,
createFile
} from 'fs-extra'

import { launchApp, findPort, killApp, renderViaHTTP } from 'next-test-utils'

Expand Down Expand Up @@ -35,6 +42,28 @@ describe('Fork ts checker plugin', () => {
expect(parsedTsConfig.exclude[0]).toBe('node_modules')
})

it('Works with an empty tsconfig.json (docs)', async () => {
await killApp(app)

await remove(tsConfig)
await new Promise(resolve => setTimeout(resolve, 500))
expect(await exists(tsConfig)).toBe(false)
await createFile(tsConfig)
await new Promise(resolve => setTimeout(resolve, 500))
expect(await readFile(tsConfig, 'utf8')).toBe('')

appPort = await findPort()
app = await launchApp(appDir, appPort)

const tsConfigContent = await readFile(tsConfig)
let parsedTsConfig
expect(() => {
parsedTsConfig = JSON.parse(tsConfigContent)
}).not.toThrow()

expect(parsedTsConfig.exclude[0]).toBe('node_modules')
})

it('Updates an existing tsconfig.json with required value', async () => {
await killApp(app)

Expand Down

0 comments on commit ab0384d

Please sign in to comment.