forked from vitejs/vite
-
-
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.
refactor: tsconfck for esbuild compilerOptions tsconfig files (vitejs…
- Loading branch information
Showing
14 changed files
with
226 additions
and
251 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
50 changes: 50 additions & 0 deletions
50
packages/playground/tsconfig-json-load-error/__tests__/tsconfig-json-load-error.spec.ts
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,50 @@ | ||
import { editFile, isBuild, readFile, untilUpdated } from '../../testUtils' | ||
|
||
if (isBuild) { | ||
test('should throw an error on build', () => { | ||
const buildError = beforeAllError | ||
expect(buildError).toBeTruthy() | ||
expect(buildError.message).toMatch( | ||
/^parsing .* failed: SyntaxError: Unexpected token } in JSON at position \d+$/ | ||
) | ||
beforeAllError = null // got expected error, null it here so testsuite does not fail from rethrow in afterAll | ||
}) | ||
|
||
test('should not output files to dist', () => { | ||
let err | ||
try { | ||
readFile('dist/index.html') | ||
} catch (e) { | ||
err = e | ||
} | ||
expect(err).toBeTruthy() | ||
expect(err.code).toBe('ENOENT') | ||
}) | ||
} else { | ||
test('should log 500 error in browser for malformed tsconfig', () => { | ||
// don't test for actual complete message as this might be locale dependant. chrome does log 500 consistently though | ||
expect(browserLogs.find((x) => x.includes('500'))).toBeTruthy() | ||
expect(browserLogs).not.toContain('tsconfig error fixed, file loaded') | ||
}) | ||
|
||
test('should show error overlay for tsconfig error', async () => { | ||
const errorOverlay = await page.waitForSelector('vite-error-overlay') | ||
expect(errorOverlay).toBeTruthy() | ||
const message = await errorOverlay.$$eval('.message-body', (m) => { | ||
return m[0].innerHTML | ||
}) | ||
// use regex with variable filename and position values because they are different on win | ||
expect(message).toMatch( | ||
/^parsing .* failed: SyntaxError: Unexpected token } in JSON at position \d+$/ | ||
) | ||
}) | ||
|
||
test('should reload when tsconfig is changed', async () => { | ||
await editFile('has-error/tsconfig.json', (content) => { | ||
return content.replace('"compilerOptions":', '"compilerOptions":{}') | ||
}) | ||
await untilUpdated(() => { | ||
return browserLogs.find((x) => x === 'tsconfig error fixed, file loaded') | ||
}, 'tsconfig error fixed, file loaded') | ||
}) | ||
} |
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 @@ | ||
console.log('tsconfig error fixed, file loaded') |
4 changes: 4 additions & 0 deletions
4
packages/playground/tsconfig-json-load-error/has-error/tsconfig.json
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,4 @@ | ||
{ | ||
// this config is deliberately malformed to test how vite handles broken tsconfig | ||
"compilerOptions": | ||
} |
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,12 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Vite App</title> | ||
</head> | ||
<body> | ||
<div id="app"><!--app-html--></div> | ||
<script type="module" src="/src/main.ts"></script> | ||
</body> | ||
</html> |
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,11 @@ | ||
{ | ||
"name": "tsconfig-json-load-error", | ||
"private": true, | ||
"version": "0.0.0", | ||
"scripts": { | ||
"dev": "vite", | ||
"build": "vite build", | ||
"debug": "node --inspect-brk ../../vite/bin/vite", | ||
"serve": "vite preview" | ||
} | ||
} |
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,2 @@ | ||
// @ts-nocheck | ||
import '../has-error/main' |
20 changes: 20 additions & 0 deletions
20
packages/playground/tsconfig-json-load-error/tsconfig.json
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,20 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ESNext", | ||
"module": "ESNext", | ||
"lib": ["ESNext", "DOM"], | ||
"moduleResolution": "Node", | ||
"strict": true, | ||
"sourceMap": true, | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"noEmit": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noImplicitReturns": true, | ||
|
||
"useDefineForClassFields": true, | ||
"importsNotUsedAsValues": "preserve" | ||
}, | ||
"include": ["./src"] | ||
} |
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
Oops, something went wrong.