Skip to content

Commit 306b233

Browse files
authoredMay 30, 2023
fix(vite-node): don't externalize "dist" by default (#3446)
1 parent e39adea commit 306b233

File tree

8 files changed

+27
-16
lines changed

8 files changed

+27
-16
lines changed
 

‎docs/config/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ You will not be able to edit your `node_modules` code for debugging, since the c
136136
#### deps.external
137137

138138
- **Type:** `(string | RegExp)[]`
139-
- **Default:** `['**/node_modules/**', '**/dist/**']`
139+
- **Default:** `['**/node_modules/**']`
140140

141141
Externalize means that Vite will bypass the package to native Node. Externalized dependencies will not be applied Vite's transformers and resolvers, so they do not support HMR on reload. Typically, packages under `node_modules` are externalized.
142142

‎package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
"lint": "eslint --cache .",
2020
"lint:fix": "nr lint --fix",
2121
"release": "bumpp package.json packages/*/package.json --commit --push --tag && pnpm -r publish --access public",
22-
"test": "vitest --api -r test/core",
23-
"test:run": "vitest run -r test/core",
24-
"test:all": "CI=true pnpm -r --stream run test --allowOnly",
25-
"test:ci": "CI=true pnpm -r --stream --filter !test-fails --filter !test-browser --filter !test-esm --filter !test-browser run test --allowOnly",
26-
"test:ci:single-thread": "CI=true pnpm -r --stream --filter !test-fails --filter !test-coverage --filter !test-watch --filter !test-bail --filter !test-esm --filter !test-browser run test --allowOnly --no-threads",
22+
"test": "VITE_NODE_DEPS_MODULE_DIRECTORIES=/node_modules/,/packages/ vitest --api -r test/core",
23+
"test:run": "VITE_NODE_DEPS_MODULE_DIRECTORIES=/node_modules/,/packages/ vitest run -r test/core",
24+
"test:all": "VITE_NODE_DEPS_MODULE_DIRECTORIES=/node_modules/,/packages/ CI=true pnpm -r --stream run test --allowOnly",
25+
"test:ci": "VITE_NODE_DEPS_MODULE_DIRECTORIES=/node_modules/,/packages/ CI=true pnpm -r --stream --filter !test-fails --filter !test-browser --filter !test-esm --filter !test-browser run test --allowOnly",
26+
"test:ci:single-thread": "VITE_NODE_DEPS_MODULE_DIRECTORIES=/node_modules/,/packages/ CI=true pnpm -r --stream --filter !test-fails --filter !test-coverage --filter !test-watch --filter !test-bail --filter !test-esm --filter !test-browser run test --allowOnly --no-threads",
2727
"typecheck": "tsc --noEmit",
2828
"typecheck:why": "tsc --noEmit --explainFiles > explainTypes.txt",
2929
"ui:build": "vite build packages/ui",

‎packages/ui/client/auto-imports.d.ts

-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ declare global {
9393
const toReactive: typeof import('@vueuse/core')['toReactive']
9494
const toRef: typeof import('vue')['toRef']
9595
const toRefs: typeof import('vue')['toRefs']
96-
const toValue: typeof import('@vueuse/core')['toValue']
9796
const triggerRef: typeof import('vue')['triggerRef']
9897
const tryOnBeforeMount: typeof import('@vueuse/core')['tryOnBeforeMount']
9998
const tryOnBeforeUnmount: typeof import('@vueuse/core')['tryOnBeforeUnmount']

‎packages/vite-node/src/externalize.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ async function _shouldExternalize(
126126
if (matchExternalizePattern(id, moduleDirectories, depsExternal))
127127
return id
128128

129-
const isDist = id.includes('/dist/')
130-
if ((isLibraryModule || isDist) && await isValidNodeImport(id))
129+
if (isLibraryModule && await isValidNodeImport(id))
131130
return id
132131

133132
return false

‎packages/vite-node/src/server.ts

+5
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ export class ViteNodeServer {
6565
}
6666
if (options.debug)
6767
this.debugger = new Debugger(server.config.root, options.debug!)
68+
69+
options.deps.moduleDirectories ??= []
70+
const customModuleDirectories = process.env.VITE_NODE_DEPS_MODULE_DIRECTORIES?.split(',')
71+
if (customModuleDirectories)
72+
options.deps.moduleDirectories.push(...customModuleDirectories)
6873
}
6974

7075
shouldExternalize(id: string) {

‎packages/vite-node/src/types.ts

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ export type Awaitable<T> = T | PromiseLike<T>
99
export interface DepsHandlingOptions {
1010
external?: (string | RegExp)[]
1111
inline?: (string | RegExp)[] | true
12+
/**
13+
* A list of directories that are considered to hold Node.js modules
14+
* Have to include "/" at the start and end of the path
15+
*
16+
* Vite-Node checks the whole absolute path of the import, so make sure you don't include
17+
* unwanted files accidentally
18+
* @default ['/node_modules/']
19+
*/
1220
moduleDirectories?: string[]
1321
cacheDir?: string
1422
/**

‎test/core/test/timeout.spec.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
import { describe, expect, test } from 'vitest'
22

33
describe('suite timeout', () => {
4-
test('true is true after 5100ms', async () => {
5-
await new Promise(resolve => setTimeout(resolve, 5100))
4+
test('true is true after 100ms', async () => {
5+
await new Promise(resolve => setTimeout(resolve, 10))
66
expect(true).toBe(true)
77
})
88
}, {
9-
timeout: 6000,
9+
timeout: 100,
1010
})
1111

1212
describe('suite timeout simple input', () => {
13-
test('true is true after 5100ms', async () => {
14-
await new Promise(resolve => setTimeout(resolve, 5100))
13+
test('true is true after 100ms', async () => {
14+
await new Promise(resolve => setTimeout(resolve, 10))
1515
expect(true).toBe(true)
1616
})
17-
}, 6000)
17+
}, 100)

‎test/core/vitest.config.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export default defineConfig({
6363
},
6464
deps: {
6565
external: ['tinyspy', /src\/external/],
66-
moduleDirectories: ['node_modules', 'projects'],
66+
moduleDirectories: ['node_modules', 'projects', 'packages'],
6767
},
6868
alias: [
6969
{

0 commit comments

Comments
 (0)
Please sign in to comment.