Skip to content

Commit

Permalink
fix: better bundling of types (#1785)
Browse files Browse the repository at this point in the history
* fix: better bundling of types

* chore: fix types clash
  • Loading branch information
sheremet-va authored Aug 4, 2022
1 parent de85869 commit 6ed32dd
Show file tree
Hide file tree
Showing 12 changed files with 19 additions and 40 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
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",
"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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"exclude": [
"**/dist/**",
"./packages/vitest/dist/**",
"./packages/vitest/*.d.ts",
"./packages/ui/client/**",
"./examples/**/*.*",
"./bench/**"
Expand Down

0 comments on commit 6ed32dd

Please sign in to comment.