-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
47 lines (35 loc) · 1.1 KB
/
index.js
File metadata and controls
47 lines (35 loc) · 1.1 KB
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
41
42
43
44
45
46
47
#! /usr/bin/env node
import { createRequire } from 'module'
import path from 'path'
import cp from 'child_process'
const require = createRequire(import.meta.url)
require('dotenv').config({
path: path.resolve(import.meta.dirname, '.env'),
})
const isDev = process.env.NODE_ENV == 'development'
const args = []
const NODE_OPTIONS = []
const envVars = { ...process.env }
function scriptPath(...args) {
const filename = path.resolve(import.meta.dirname, ...args)
return 'file://' + filename
}
args.push(
isDev
? path.resolve(import.meta.dirname, 'src/index.ts')
: path.resolve(import.meta.dirname, 'dist/index.js')
)
NODE_OPTIONS.push('--experimental-loader', scriptPath('loader.mjs'))
NODE_OPTIONS.push('--disable-warning', 'ExperimentalWarning')
if (isDev) {
NODE_OPTIONS.push('--import', 'file://' + require.resolve('tsx/esm'))
envVars.TSX_TSCONFIG_PATH = path.join(import.meta.dirname, 'tsconfig.json')
}
args.push(...process.argv.slice(2))
cp.spawn('node', args, {
stdio: 'inherit',
env: {
...envVars,
NODE_OPTIONS: NODE_OPTIONS.join(' '),
},
})