Commit ab0384de authored by Joe Haddad's avatar Joe Haddad Committed by Tim Neutkens

Fix TypeScript setup with empty file (#8332)

New versions of TypeScript now throw an error when no matching TypeScript files are found. We still want to setup in this case.

-----

Closes #8324
parent 06876f1b
......@@ -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)
......
/* 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'
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment