-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
vitest.config.ts
40 lines (32 loc) · 1.18 KB
/
vitest.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import { defineConfig,mergeConfig} from 'vitest/config'
import path from 'path'
export const nodejsPolarsDirnamePlugin = () => {
const name = 'nodejs-polars-dirname-plugin'
return {
name,
transform(code: string, id: string) {
// aim for the node_modules/nodejs-polars/bin/native-polars.js file
if (id.endsWith('.node')) {
const file = path.basename(id)
return `
// create a custom require function to load .node files
import { createRequire } from 'module';
const customRequire = createRequire(import.meta.url)
// load the .node file expecting it to be in the same directory as the output bundle
const content = customRequire('./${file}')
// export the content straight back out again
export default content
`
}
// else return the original code (leave code unrelated to nodejs-polars untouched)
return code
},
}
}
export default defineConfig({
test: {
},
plugins: [
nodejsPolarsDirnamePlugin()
]
})