Skip to content

Commit

Permalink
fix!: remove deprecated node loader (#4371)
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va authored Oct 25, 2023
1 parent 9527e65 commit 29299f3
Show file tree
Hide file tree
Showing 11 changed files with 460 additions and 846 deletions.
11 changes: 1 addition & 10 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ Directory to save cache files.

### deps

- **Type:** `{ optimizer?, registerNodeLoader?, ... }`
- **Type:** `{ optimizer?, ... }`

Handling for dependencies resolution.

Expand Down Expand Up @@ -278,15 +278,6 @@ By default, files inside `node_modules` are externalized and not transformed, un
At the moment, this option only works with [`vmThreads`](#vmthreads) pool.
:::

#### deps.registerNodeLoader<NonProjectOption />

- **Type:** `boolean`
- **Default:** `false`

Use [experimental Node loader](https://nodejs.org/api/esm.html#loaders) to resolve imports inside externalized files, using Vite resolve algorithm.

If disabled, your `alias` and `<plugin>.resolveId` won't affect imports inside externalized packages (by default, `node_modules`).

#### deps.interopDefault

- **Type:** `boolean`
Expand Down
6 changes: 3 additions & 3 deletions examples/solid/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
"coverage": "vitest --coverage"
},
"dependencies": {
"solid-js": "^1.4.3"
"solid-js": "^1.8.3"
},
"devDependencies": {
"@solidjs/testing-library": "^0.8.4",
"@testing-library/jest-dom": "^5.16.4",
"jsdom": "latest",
"solid-testing-library": "^0.5.0",
"vite": "latest",
"vite-plugin-solid": "^2.5.0",
"vite-plugin-solid": "^2.7.2",
"vitest": "latest"
}
}
2 changes: 1 addition & 1 deletion examples/solid/test/Hello.test.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, test } from 'vitest'
import { fireEvent, render } from 'solid-testing-library'
import { fireEvent, render } from '@solidjs/testing-library'
import { Hello } from '../components/Hello'

describe('<Hello />', () => {
Expand Down
7 changes: 7 additions & 0 deletions examples/solid/vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ export default defineConfig({
isolate: false,
},
},
deps: {
optimizer: {
web: {
exclude: ['solid-js'],
},
},
},
},
plugins: [solid()],
resolve: {
Expand Down
1 change: 0 additions & 1 deletion packages/vitest/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const entries = [
'src/runtime/worker.ts',
'src/runtime/vm.ts',
'src/runtime/child.ts',
'src/runtime/loader.ts',
'src/runtime/entry.ts',
'src/runtime/entry-vm.ts',
'src/integrations/spy.ts',
Expand Down
10 changes: 0 additions & 10 deletions packages/vitest/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,6 @@ export function resolveConfig(
?? resolve(resolved.root, resolved.runner)
}

if (resolved.deps.registerNodeLoader) {
const transformMode = resolved.environment === 'happy-dom' || resolved.environment === 'jsdom' ? 'web' : 'ssr'
console.warn(
c.yellow(
`${c.inverse(c.yellow(' Vitest '))} "deps.registerNodeLoader" is deprecated.`
+ `If you rely on aliases inside external packages, use "deps.optimizer.${transformMode}.include" instead.`,
),
)
}

resolved.testNamePattern = resolved.testNamePattern
? resolved.testNamePattern instanceof RegExp
? resolved.testNamePattern
Expand Down
23 changes: 4 additions & 19 deletions packages/vitest/src/node/pool.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { pathToFileURL } from 'node:url'
import mm from 'micromatch'
import { resolve } from 'pathe'
import { distDir, rootDir } from '../paths'
import type { Pool } from '../types'
import type { Vitest } from './core'
import { createChildProcessPool } from './pools/child'
Expand All @@ -27,9 +24,6 @@ export interface PoolProcessOptions {
env: Record<string, string>
}

const loaderPath = pathToFileURL(resolve(distDir, './loader.js')).href
const suppressLoaderWarningsPath = resolve(rootDir, './suppress-warnings.cjs')

export function createPool(ctx: Vitest): ProcessPool {
const pools: Record<Pool, ProcessPool | null> = {
forks: null,
Expand Down Expand Up @@ -74,19 +68,10 @@ export function createPool(ctx: Vitest): ProcessPool {

const options: PoolProcessOptions = {
...ctx.projectFiles,
execArgv: ctx.config.deps.registerNodeLoader
? [
...execArgv,
'--require',
suppressLoaderWarningsPath,
'--experimental-loader',
loaderPath,
...conditions,
]
: [
...execArgv,
...conditions,
],
execArgv: [
...execArgv,
...conditions,
],
env: {
TEST: 'true',
VITEST: 'true',
Expand Down
95 changes: 0 additions & 95 deletions packages/vitest/src/runtime/loader.ts

This file was deleted.

9 changes: 1 addition & 8 deletions packages/vitest/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,6 @@ interface DepsOptions {
*/
fallbackCJS?: boolean

/**
* Use experimental Node loader to resolve imports inside node_modules using Vite resolve algorithm.
* @default false
* @deprecated If you rely on aliases inside external packages, use `deps.optimizer.{web,ssr}.include` instead.
*/
registerNodeLoader?: boolean

/**
* A list of directories relative to the config file that should be treated as module directories.
*
Expand Down Expand Up @@ -805,7 +798,7 @@ export type ProjectConfig = Omit<
| 'coverage'
> & {
sequencer?: Omit<SequenceOptions, 'sequencer' | 'seed'>
deps?: Omit<DepsOptions, 'registerNodeLoader' | 'moduleDirectories'>
deps?: Omit<DepsOptions, 'moduleDirectories'>
}

export type RuntimeConfig = Pick<
Expand Down
Loading

0 comments on commit 29299f3

Please sign in to comment.