Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: better bundling of types #1785

Merged
merged 2 commits into from Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -25,6 +25,7 @@
"test:ci": "cross-env CI=true pnpm -r --stream --filter !test-fails --filter !test-browser run test --allowOnly",
"test:ci:single-thread": "cross-env CI=true pnpm -r --stream --filter !test-fails run test --allowOnly --no-threads",
"typecheck": "tsc --noEmit",
"typecheck:why": "tsc --noEmit --explainFiles > explainTypes.txt",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀? Cool magic good to know!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanted to keep it in case someone will mess up the types again 👀

"ui:build": "vite build packages/ui",
"ui:dev": "vite packages/ui",
"ui:test": "npm -C packages/ui run test:run"
Expand Down
34 changes: 14 additions & 20 deletions packages/vitest/rollup.config.js
Expand Up @@ -60,7 +60,7 @@ const plugins = [
}),
]

export default ({ watch }) => [
export default ({ watch }) => defineConfig([
{
input: entries,
output: {
Expand Down Expand Up @@ -107,25 +107,19 @@ export default ({ watch }) => [
external,
plugins,
},
...dtsEntries.map((input) => {
const _external = external
// index is vitest default types export
if (!input.includes('index'))
_external.push('vitest')

return defineConfig({
input,
output: {
file: input.replace('src/', 'dist/').replace('.ts', '.d.ts'),
format: 'esm',
},
external: _external,
plugins: [
dts({ respectExternal: true }),
],
})
}),
]
{
input: dtsEntries,
output: {
dir: 'dist',
entryFileNames: chunk => `${chunk.name.replace('src/', '')}.d.ts`,
format: 'esm',
},
external,
plugins: [
dts({ respectExternal: true }),
],
},
])

function licensePlugin() {
return license({
Expand Down
5 changes: 1 addition & 4 deletions packages/vitest/src/defaults.ts
@@ -1,7 +1,4 @@
// rollup dts building will external vitest
// so output dts entry using vitest to import internal types
// eslint-disable-next-line no-restricted-imports
import type { ResolvedC8Options, UserConfig } from 'vitest'
import type { ResolvedC8Options, UserConfig } from './types'

export const defaultInclude = ['**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}']
export const defaultExclude = ['**/node_modules/**', '**/dist/**', '**/cypress/**', '**/.{idea,git,cache,output,temp}/**']
Expand Down
4 changes: 0 additions & 4 deletions packages/vitest/tsconfig.json

This file was deleted.

1 change: 0 additions & 1 deletion shims.d.ts
@@ -1,3 +1,2 @@
/// <reference path="./packages/vitest/config.d.ts" />
/// <reference path="./packages/vitest/globals.d.ts" />
/// <reference path="./packages/vitest/importMeta.d.ts" />
2 changes: 1 addition & 1 deletion test/core/vitest.config.ts
@@ -1,5 +1,5 @@
import { basename, dirname, join, resolve } from 'pathe'
import { defineConfig } from 'vite'
import { defineConfig } from 'vitest/config'

export default defineConfig({
plugins: [
Expand Down
2 changes: 0 additions & 2 deletions test/global-setup-fail/fixtures/vitest.config.ts
@@ -1,5 +1,3 @@
/// <reference types="vitest" />

import { defineConfig } from 'vite'

export default defineConfig({
Expand Down
2 changes: 0 additions & 2 deletions test/global-setup-fail/vitest.config.ts
@@ -1,5 +1,3 @@
/// <reference types="vitest" />

import { defineConfig } from 'vite'

export default defineConfig({
Expand Down
2 changes: 0 additions & 2 deletions test/global-setup/vitest.config.ts
@@ -1,5 +1,3 @@
/// <reference types="vitest" />

import { defineConfig } from 'vite'

export default defineConfig({
Expand Down
3 changes: 1 addition & 2 deletions test/reporters/src/data.ts
@@ -1,6 +1,5 @@
import { AssertionError } from 'assert'
import type { ErrorWithDiff } from '../../../packages/vitest/dist'
import type { File, Suite, Task } from '../../../packages/vitest/src/types'
import type { ErrorWithDiff, File, Suite, Task } from 'vitest'

const file: File = {
id: '1223128da3',
Expand Down
2 changes: 0 additions & 2 deletions test/vite-config/vite.config.ts
@@ -1,5 +1,3 @@
/// <reference types="vitest" />

import assert from 'assert'
import { join } from 'pathe'
import { defineConfig } from 'vite'
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Expand Up @@ -36,6 +36,7 @@
"exclude": [
"**/dist/**",
"./packages/vitest/dist/**",
"./packages/vitest/*.d.ts",
"./packages/ui/client/**",
"./examples/**/*.*",
"./bench/**"
Expand Down