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!: use type module (revert #1411) #1465

Merged
merged 8 commits into from Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
Empty file added packages/vitest/index.cjs
Empty file.
1 change: 1 addition & 0 deletions packages/vitest/index.d.cts
@@ -0,0 +1 @@
export * from './dist/index.js'
19 changes: 13 additions & 6 deletions packages/vitest/package.json
@@ -1,5 +1,6 @@
{
"name": "vitest",
"type": "module",
"version": "0.15.0",
"description": "A blazing fast unit test framework powered by Vite",
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
Expand All @@ -21,8 +22,14 @@
],
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs"
"require": {
"types": "./index.d.cts",
"default": "./index.cjs"
},
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
bluwy marked this conversation as resolved.
Show resolved Hide resolved
},
"./*": "./*",
"./globals": {
Expand All @@ -33,16 +40,16 @@
},
"./node": {
"types": "./dist/node.d.ts",
"import": "./dist/node.mjs"
"import": "./dist/node.js"
},
"./config": {
"types": "./config.d.ts",
"require": "./dist/config.cjs",
"import": "./dist/config.mjs"
"import": "./dist/config.js"
}
},
"main": "./dist/index.mjs",
"module": "./dist/index.mjs",
"main": "./dist/index.js",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"bin": {
"vitest": "./vitest.mjs"
Expand Down
15 changes: 7 additions & 8 deletions packages/vitest/rollup.config.js
Expand Up @@ -56,12 +56,11 @@ const plugins = [
]

export default ({ watch }) => [
{
defineConfig({
input: entries,
output: {
dir: 'dist',
format: 'esm',
entryFileNames: '[name].mjs',
chunkFileNames: (chunkInfo) => {
const id = chunkInfo.facadeModuleId || Object.keys(chunkInfo.modules).find(i => !i.includes('node_modules') && i.includes('src/'))
if (id) {
Expand All @@ -71,9 +70,9 @@ export default ({ watch }) => [
.filter(i => !['src', 'index', 'dist', 'node_modules'].some(j => i.includes(j)) && i.match(/^[\w_-]+$/))),
)
if (parts.length)
return `chunk-${parts.slice(-2).join('-')}.[hash].mjs`
return `chunk-${parts.slice(-2).join('-')}.[hash].js`
}
return 'vendor-[name].[hash].mjs'
return 'vendor-[name].[hash].js'
},
},
external,
Expand All @@ -86,22 +85,22 @@ export default ({ watch }) => [
return
console.error(message)
},
},
{
}),
defineConfig({
input: 'src/config.ts',
output: [
{
file: 'dist/config.cjs',
format: 'cjs',
},
{
file: 'dist/config.mjs',
file: 'dist/config.js',
format: 'esm',
},
],
external,
plugins,
},
}),
...dtsEntries.map((input) => {
const _external = external
// index is vitest default types export
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/pool.ts
Expand Up @@ -19,7 +19,7 @@ export interface WorkerPool {
close: () => Promise<void>
}

const workerPath = pathToFileURL(resolve(distDir, './worker.mjs')).href
const workerPath = pathToFileURL(resolve(distDir, './worker.js')).href

export function createPool(ctx: Vitest): WorkerPool {
const threadsCount = ctx.config.watch
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/runtime/mocker.ts
Expand Up @@ -230,7 +230,7 @@ export class VitestMocker {
private async ensureSpy() {
if (VitestMocker.spyModule)
return
VitestMocker.spyModule = await this.request(`/@fs/${slash(resolve(distDir, 'spy.mjs'))}`) as typeof import('../integrations/spy')
VitestMocker.spyModule = await this.request(`/@fs/${slash(resolve(distDir, 'spy.js'))}`) as typeof import('../integrations/spy')
}

public async requestWithMock(dep: string) {
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/runtime/worker.ts
Expand Up @@ -38,7 +38,7 @@ async function startViteNode(ctx: WorkerContext) {

const { run } = (await executeInViteNode({
files: [
resolve(distDir, 'entry.mjs'),
resolve(distDir, 'entry.js'),
],
fetchModule(id) {
return rpc().fetch(id)
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/vitest.mjs
@@ -1,2 +1,2 @@
#!/usr/bin/env node
import './dist/cli.mjs'
import './dist/cli.js'