Skip to content

Commit

Permalink
feat: add VITE_NODE_DEPS_MODULE_DIRECTORIES env
Browse files Browse the repository at this point in the history
  • Loading branch information
sheremet-va committed May 30, 2023
1 parent 81d61d6 commit 23bfefa
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 13 deletions.
10 changes: 5 additions & 5 deletions package.json
Expand Up @@ -19,11 +19,11 @@
"lint": "eslint --cache .",
"lint:fix": "nr lint --fix",
"release": "bumpp package.json packages/*/package.json --commit --push --tag && pnpm -r publish --access public",
"test": "vitest --api -r test/core",
"test:run": "vitest run -r test/core",
"test:all": "CI=true pnpm -r --stream run test --allowOnly",
"test:ci": "CI=true pnpm -r --stream --filter !test-fails --filter !test-browser --filter !test-esm --filter !test-browser run test --allowOnly",
"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",
"test": "VITE_NODE_DEPS_MODULE_DIRECTORIES=/node_modules/,/packages/ vitest --api -r test/core",
"test:run": "VITE_NODE_DEPS_MODULE_DIRECTORIES=/node_modules/,/packages/ vitest run -r test/core",
"test:all": "VITE_NODE_DEPS_MODULE_DIRECTORIES=/node_modules/,/packages/ CI=true pnpm -r --stream run test --allowOnly",
"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",
"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",
"typecheck": "tsc --noEmit",
"typecheck:why": "tsc --noEmit --explainFiles > explainTypes.txt",
"ui:build": "vite build packages/ui",
Expand Down
1 change: 0 additions & 1 deletion packages/ui/client/auto-imports.d.ts
Expand Up @@ -93,7 +93,6 @@ declare global {
const toReactive: typeof import('@vueuse/core')['toReactive']
const toRef: typeof import('vue')['toRef']
const toRefs: typeof import('vue')['toRefs']
const toValue: typeof import('@vueuse/core')['toValue']
const triggerRef: typeof import('vue')['triggerRef']
const tryOnBeforeMount: typeof import('@vueuse/core')['tryOnBeforeMount']
const tryOnBeforeUnmount: typeof import('@vueuse/core')['tryOnBeforeUnmount']
Expand Down
5 changes: 5 additions & 0 deletions packages/vite-node/src/server.ts
Expand Up @@ -65,6 +65,11 @@ export class ViteNodeServer {
}
if (options.debug)
this.debugger = new Debugger(server.config.root, options.debug!)

options.deps.moduleDirectories ??= []
const customModuleDirectories = process.env.VITE_NODE_DEPS_MODULE_DIRECTORIES?.split(',')
if (customModuleDirectories)
options.deps.moduleDirectories.push(...customModuleDirectories)
}

shouldExternalize(id: string) {
Expand Down
8 changes: 8 additions & 0 deletions packages/vite-node/src/types.ts
Expand Up @@ -9,6 +9,14 @@ export type Awaitable<T> = T | PromiseLike<T>
export interface DepsHandlingOptions {
external?: (string | RegExp)[]
inline?: (string | RegExp)[] | true
/**
* A list of directories that are considered to hold Node.js modules
* Have to include "/" at the start and end of the path
*
* Vite-Node checks the whole absolute path of the import, so make sure you don't include
* unwanted files accidentally
* @default ['/node_modules/']
*/
moduleDirectories?: string[]
cacheDir?: string
/**
Expand Down
12 changes: 6 additions & 6 deletions test/core/test/timeout.spec.ts
@@ -1,17 +1,17 @@
import { describe, expect, test } from 'vitest'

describe('suite timeout', () => {
test('true is true after 5100ms', async () => {
await new Promise(resolve => setTimeout(resolve, 5100))
test('true is true after 100ms', async () => {
await new Promise(resolve => setTimeout(resolve, 10))
expect(true).toBe(true)
})
}, {
timeout: 6000,
timeout: 100,
})

describe('suite timeout simple input', () => {
test('true is true after 5100ms', async () => {
await new Promise(resolve => setTimeout(resolve, 5100))
test('true is true after 100ms', async () => {
await new Promise(resolve => setTimeout(resolve, 10))
expect(true).toBe(true)
})
}, 6000)
}, 100)
2 changes: 1 addition & 1 deletion test/core/vitest.config.ts
Expand Up @@ -63,7 +63,7 @@ export default defineConfig({
},
deps: {
external: ['tinyspy', /src\/external/],
moduleDirectories: ['node_modules', 'projects'],
moduleDirectories: ['node_modules', 'projects', 'packages'],
},
alias: [
{
Expand Down

0 comments on commit 23bfefa

Please sign in to comment.