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

fix(vite-node): deps.inline doesn't work #3485

Merged
merged 1 commit into from Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion packages/vite-node/src/externalize.ts
Expand Up @@ -139,7 +139,7 @@ function matchExternalizePattern(id: string, moduleDirectories: string[], patter
return true
for (const ex of patterns) {
if (typeof ex === 'string') {
if (moduleDirectories.some(dir => id.includes(join(dir, id))))
if (moduleDirectories.some(dir => id.includes(join(dir, ex))))
return true
}
else {
Expand Down
4 changes: 4 additions & 0 deletions test/core/projects/inline-lib/index.js
@@ -0,0 +1,4 @@
export default function () {
// module doesn't exist in Node.js ESM, but exists in vite-node
return typeof module
}
4 changes: 4 additions & 0 deletions test/core/projects/inline-lib/package.json
@@ -0,0 +1,4 @@
{
"type": "module",
"main": "index.js"
}
7 changes: 7 additions & 0 deletions test/core/test/inlined.test.ts
@@ -0,0 +1,7 @@
// @ts-expect-error not typed lib
import typeOfModule from 'inline-lib'
import { expect, test } from 'vitest'

test('inline lib has exports injected even though it is ESM', () => {
expect(typeOfModule()).toBe('object')
})
2 changes: 2 additions & 0 deletions test/core/vitest.config.ts
Expand Up @@ -36,6 +36,7 @@ export default defineConfig({
{ find: '#', replacement: resolve(__dirname, 'src') },
{ find: '$', replacement: 'src' },
{ find: /^custom-lib$/, replacement: resolve(__dirname, 'projects', 'custom-lib') },
{ find: /^inline-lib$/, replacement: resolve(__dirname, 'projects', 'inline-lib') },
],
},
test: {
Expand Down Expand Up @@ -63,6 +64,7 @@ export default defineConfig({
},
deps: {
external: ['tinyspy', /src\/external/],
inline: ['inline-lib'],
moduleDirectories: ['node_modules', 'projects', 'packages'],
},
alias: [
Expand Down