Skip to content

Commit be93032

Browse files
authoredJun 1, 2023
fix(vite-node): deps.inline doesn't work (#3485)
1 parent 29a37cd commit be93032

File tree

5 files changed

+18
-1
lines changed

5 files changed

+18
-1
lines changed
 

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function matchExternalizePattern(id: string, moduleDirectories: string[], patter
139139
return true
140140
for (const ex of patterns) {
141141
if (typeof ex === 'string') {
142-
if (moduleDirectories.some(dir => id.includes(join(dir, id))))
142+
if (moduleDirectories.some(dir => id.includes(join(dir, ex))))
143143
return true
144144
}
145145
else {
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export default function () {
2+
// module doesn't exist in Node.js ESM, but exists in vite-node
3+
return typeof module
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "module",
3+
"main": "index.js"
4+
}

‎test/core/test/inlined.test.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @ts-expect-error not typed lib
2+
import typeOfModule from 'inline-lib'
3+
import { expect, test } from 'vitest'
4+
5+
test('inline lib has exports injected even though it is ESM', () => {
6+
expect(typeOfModule()).toBe('object')
7+
})

‎test/core/vitest.config.ts

+2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export default defineConfig({
3636
{ find: '#', replacement: resolve(__dirname, 'src') },
3737
{ find: '$', replacement: 'src' },
3838
{ find: /^custom-lib$/, replacement: resolve(__dirname, 'projects', 'custom-lib') },
39+
{ find: /^inline-lib$/, replacement: resolve(__dirname, 'projects', 'inline-lib') },
3940
],
4041
},
4142
test: {
@@ -63,6 +64,7 @@ export default defineConfig({
6364
},
6465
deps: {
6566
external: ['tinyspy', /src\/external/],
67+
inline: ['inline-lib'],
6668
moduleDirectories: ['node_modules', 'projects', 'packages'],
6769
},
6870
alias: [

0 commit comments

Comments
 (0)
Please sign in to comment.