Skip to content

Commit

Permalink
fix!: use type module (revert #1411) (#1465)
Browse files Browse the repository at this point in the history
Co-authored-by: Vladimir Sheremet <sleuths.slews0s@icloud.com>
  • Loading branch information
bluwy and sheremet-va committed Oct 7, 2022
1 parent 3dbbfe1 commit 652f160
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 19 deletions.
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'
23 changes: 15 additions & 8 deletions packages/vitest/package.json
@@ -1,5 +1,6 @@
{
"name": "vitest",
"type": "module",
"version": "0.23.4",
"description": "A blazing fast unit test framework powered by Vite",
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
Expand All @@ -22,8 +23,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"
}
},
"./*": "./*",
"./globals": {
Expand All @@ -34,24 +41,24 @@
},
"./node": {
"types": "./dist/node.d.ts",
"import": "./dist/node.mjs"
"import": "./dist/node.js"
},
"./environments": {
"types": "./dist/environments.d.ts",
"import": "./dist/environments.mjs"
"import": "./dist/environments.js"
},
"./browser": {
"types": "./dist/browser.d.ts",
"import": "./dist/browser.mjs"
"import": "./dist/browser.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
7 changes: 3 additions & 4 deletions packages/vitest/rollup.config.js
Expand Up @@ -69,7 +69,6 @@ export default ({ watch }) => defineConfig([
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 @@ -79,9 +78,9 @@ export default ({ watch }) => defineConfig([
.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 @@ -99,7 +98,7 @@ export default ({ watch }) => defineConfig([
format: 'cjs',
},
{
file: 'dist/config.mjs',
file: 'dist/config.js',
format: 'esm',
},
],
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/node/cli-wrapper.ts
Expand Up @@ -7,7 +7,7 @@ import c from 'picocolors'
import { execa } from 'execa'
import { EXIT_CODE_RESTART } from '../constants'

const ENTRY = new URL('./cli.mjs', import.meta.url)
const ENTRY = new URL('./cli.js', import.meta.url)

/** Arguments passed to Node before the script */
const NODE_ARGS = [
Expand Down
4 changes: 2 additions & 2 deletions packages/vitest/src/node/pool.ts
Expand Up @@ -18,8 +18,8 @@ export interface WorkerPool {
close: () => Promise<void>
}

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

const suppressLoaderWarningsPath = resolve(rootDir, './suppress-warnings.cjs')

Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/src/runtime/mocker.ts
Expand Up @@ -341,7 +341,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 @@ -39,7 +39,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-wrapper.mjs'
import './dist/cli-wrapper.js'
2 changes: 1 addition & 1 deletion test/fails/test/runner.test.ts
Expand Up @@ -34,6 +34,6 @@ describe('should fails', async () => {
?.trim()
.replace(root, '<rootDir>')
expect(msg).toMatchSnapshot(file)
}, 10000)
}, 30_000)
}
})

0 comments on commit 652f160

Please sign in to comment.