2024-08-13 04:53:07 +03:00
|
|
|
import { resolve } from 'node:path'
|
|
|
|
|
2024-04-25 04:47:33 +03:00
|
|
|
import { defineConfig } from 'vite'
|
2024-08-13 04:53:07 +03:00
|
|
|
|
2024-04-25 04:47:33 +03:00
|
|
|
import { fixupCjs } from './vite-utils/fixup-cjs'
|
|
|
|
import { testSetup } from './vite-utils/test-setup-plugin'
|
|
|
|
import { collectTestEntrypoints } from './vite-utils/collect-test-entrypoints'
|
|
|
|
|
2024-08-13 04:53:07 +03:00
|
|
|
// eslint-disable-next-line no-restricted-globals
|
2024-04-25 05:25:56 +03:00
|
|
|
const POLYFILLS = resolve(__dirname, 'vite-utils/polyfills-deno.ts')
|
2024-04-25 04:47:33 +03:00
|
|
|
|
|
|
|
export default defineConfig({
|
|
|
|
build: {
|
|
|
|
lib: {
|
2024-08-13 04:53:07 +03:00
|
|
|
entry: process.env.ENTRYPOINT
|
|
|
|
? [process.env.ENTRYPOINT]
|
|
|
|
: collectTestEntrypoints({
|
|
|
|
// these packages rely on node apis and are not meant to be run under deno
|
|
|
|
skipPackages: ['create-bot', 'crypto-node', 'bun', 'node', 'http-proxy', 'socks-proxy', 'mtproxy'],
|
|
|
|
skipTests: [
|
2024-04-25 04:47:33 +03:00
|
|
|
// uses timers
|
2024-08-13 04:53:07 +03:00
|
|
|
'core/src/network/config-manager.test.ts',
|
|
|
|
'core/src/network/persistent-connection.test.ts',
|
|
|
|
// https://github.com/denoland/deno/issues/22470
|
|
|
|
'wasm/tests/gunzip.test.ts',
|
|
|
|
'wasm/tests/zlib.test.ts',
|
|
|
|
],
|
|
|
|
}),
|
2024-04-25 04:47:33 +03:00
|
|
|
formats: ['es'],
|
|
|
|
},
|
|
|
|
rollupOptions: {
|
|
|
|
external: [
|
|
|
|
/^(jsr|npm|node|https?):/,
|
|
|
|
],
|
|
|
|
output: {
|
|
|
|
chunkFileNames: 'chunk-[hash].js',
|
|
|
|
entryFileNames: '[name]-[hash].test.js',
|
|
|
|
minifyInternalExports: false,
|
|
|
|
},
|
|
|
|
treeshake: false,
|
|
|
|
},
|
|
|
|
commonjsOptions: {
|
|
|
|
ignoreDynamicRequires: true,
|
|
|
|
},
|
|
|
|
outDir: process.env.OUT_DIR || 'dist/tests',
|
|
|
|
emptyOutDir: true,
|
|
|
|
target: 'esnext',
|
|
|
|
minify: false,
|
|
|
|
},
|
|
|
|
plugins: [
|
|
|
|
fixupCjs(),
|
|
|
|
{
|
2024-04-25 05:25:56 +03:00
|
|
|
name: 'polyfills',
|
2024-04-25 04:47:33 +03:00
|
|
|
transform(code) {
|
|
|
|
if (!code.includes('vitest')) return code
|
2024-08-13 04:53:07 +03:00
|
|
|
code = code.replace(/^import \{(.+?)\} from ['"]vitest['"]/gms, (_, names) => {
|
|
|
|
const namesParsed = names.split(',').map(name => name.trim())
|
2024-04-25 04:47:33 +03:00
|
|
|
|
2024-04-25 05:25:56 +03:00
|
|
|
return `import {${namesParsed.join(', ')}} from '${POLYFILLS}'`
|
2024-04-25 04:47:33 +03:00
|
|
|
})
|
|
|
|
return code
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'fix-events',
|
|
|
|
transform(code) {
|
|
|
|
if (!code.includes('events')) return code
|
|
|
|
return code.replace(/^import (.+?) from ['"]events['"]/gms, (_, name) => {
|
|
|
|
return `import ${name} from 'node:events'`
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// todo
|
|
|
|
// {
|
|
|
|
// name: 'fix-wasm-load',
|
|
|
|
// async transform(code, id) {
|
|
|
|
// if (code.includes('@mtcute/wasm/mtcute.wasm')) {
|
|
|
|
// return code.replace('@mtcute/wasm/mtcute.wasm', resolve(__dirname, '../packages/wasm/mtcute.wasm'))
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return code
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
testSetup(),
|
|
|
|
],
|
|
|
|
define: {
|
|
|
|
'import.meta.env.TEST_ENV': '"deno"',
|
|
|
|
},
|
|
|
|
})
|