Skip to content

Commit

Permalink
refactor: tsconfck for esbuild compilerOptions tsconfig files (#4889)
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikg committed Sep 18, 2021
1 parent 5e1b8d4 commit 9560af8
Show file tree
Hide file tree
Showing 14 changed files with 226 additions and 251 deletions.
3 changes: 2 additions & 1 deletion .prettierignore
Expand Up @@ -4,4 +4,5 @@ packages/plugin-vue/dist/
packages/*/CHANGELOG.md
LICENSE.md
.prettierignore
yarn.lock
yarn.lock
packages/playground/tsconfig-json-load-error/has-error/tsconfig.json
1 change: 1 addition & 0 deletions packages/playground/testEnv.d.ts
Expand Up @@ -9,4 +9,5 @@ declare global {
const browserLogs: string[]
const viteTestUrl: string
const watcher: RollupWatcher
let beforeAllError: any | null // error caught in beforeAll, useful if you want to test error scenarios on build
}
@@ -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')
})
}
@@ -0,0 +1 @@
console.log('tsconfig error fixed, file loaded')
@@ -0,0 +1,4 @@
{
// this config is deliberately malformed to test how vite handles broken tsconfig
"compilerOptions":
}
12 changes: 12 additions & 0 deletions packages/playground/tsconfig-json-load-error/index.html
@@ -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>
11 changes: 11 additions & 0 deletions packages/playground/tsconfig-json-load-error/package.json
@@ -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"
}
}
2 changes: 2 additions & 0 deletions packages/playground/tsconfig-json-load-error/src/main.ts
@@ -0,0 +1,2 @@
// @ts-nocheck
import '../has-error/main'
20 changes: 20 additions & 0 deletions packages/playground/tsconfig-json-load-error/tsconfig.json
@@ -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"]
}
88 changes: 54 additions & 34 deletions packages/vite/LICENSE.md
Expand Up @@ -4736,23 +4736,6 @@ Repository: chalk/strip-ansi
---------------------------------------

## strip-bom
License: MIT
By: Sindre Sorhus
Repository: sindresorhus/strip-bom

> MIT License
>
> Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
>
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
---------------------------------------

## strip-final-newline
License: MIT
By: Sindre Sorhus
Expand All @@ -4770,23 +4753,6 @@ Repository: sindresorhus/strip-final-newline
---------------------------------------

## strip-json-comments
License: MIT
By: Sindre Sorhus
Repository: sindresorhus/strip-json-comments

> MIT License
>
> Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
>
> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
---------------------------------------

## supports-color
License: MIT
By: Sindre Sorhus
Expand Down Expand Up @@ -4891,6 +4857,60 @@ Repository: git://github.com/TypeStrong/ts-node.git
---------------------------------------

## tsconfck
License: MIT
By: dominikg
Repository: git+https://github.com/dominikg/tsconfck.git

> MIT License
>
> Copyright (c) 2021-present dominikg and [contributors](https://github.com/dominikg/tsconfck/graphs/contributors)
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all
> copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.
>
> -- Licenses for 3rd-party code included in tsconfck --
>
> # strip-bom and strip-json-comments
> MIT License
>
> Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in all
> copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.
---------------------------------------

## unpipe
License: MIT
By: Douglas Christopher Wilson
Expand Down
4 changes: 1 addition & 3 deletions packages/vite/package.json
Expand Up @@ -116,10 +116,8 @@
"source-map": "^0.6.1",
"source-map-support": "^0.5.19",
"strip-ansi": "^6.0.0",
"strip-bom": "^4.0.0",
"strip-json-comments": "^3.1.1",
"terser": "^5.7.1",
"tsconfig": "^7.0.0",
"tsconfck": "^1.0.0",
"tslib": "^2.3.0",
"types": "link:./types",
"ws": "^7.5.3"
Expand Down

0 comments on commit 9560af8

Please sign in to comment.