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

feat: add deps.registerNodeLoader option #1751

Merged
merged 3 commits into from
Jul 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 9 additions & 0 deletions docs/config/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ When a dependency is a valid ESM package, try to guess the cjs version based on

This might potentially cause some misalignment if a package has different logic in ESM and CJS mode.

#### deps.experimentalLoader

- **Type:** `boolean`
- **Default:** `true`

Use experimental loader to resolve imports inside `node_modules`, using Vite resolve algorithm.

If disabled, your `alias` and `<plugin>.resolveId` won't affect imports inside `node_modules` or `deps.external`.

#### deps.interopDefault

- **Type:** `boolean`
Expand Down
2 changes: 2 additions & 0 deletions packages/vitest/src/node/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ export function resolveConfig(
}
}

resolved.deps.experimentalLoader ??= true

resolved.testNamePattern = resolved.testNamePattern
? resolved.testNamePattern instanceof RegExp
? resolved.testNamePattern
Expand Down
16 changes: 9 additions & 7 deletions packages/vitest/src/node/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,15 @@ export function createPool(ctx: Vitest): WorkerPool {
maxThreads,
minThreads,

execArgv: [
'--require',
suppressLoaderWarningsPath,
'--experimental-loader',
loaderPath,
...conditions || [],
],
execArgv: ctx.config.deps.experimentalLoader
? [
'--require',
suppressLoaderWarningsPath,
'--experimental-loader',
loaderPath,
...conditions || [],
]
: [],
}

if (ctx.config.isolate) {
Expand Down
6 changes: 6 additions & 0 deletions packages/vitest/src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ export interface InlineConfig {
* @default false
*/
fallbackCJS?: boolean

/**
* Use experimental loader to resolve imports inside node_modules using Vite resolve algorithm.
* @default true
*/
experimentalLoader?: boolean
}

/**
Expand Down