vite-node 0.1.5 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.mjs +2 -2
- package/index.mjs +32 -30
- package/package.json +1 -1
- package/vite-node.mjs +1 -1
package/cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
import minimist from 'minimist'
|
|
3
3
|
import { red, dim } from 'kolorist'
|
|
4
|
-
import {
|
|
4
|
+
import { run } from './index.mjs'
|
|
5
5
|
|
|
6
6
|
const argv = minimist(process.argv.slice(2), {
|
|
7
7
|
'alias': {
|
|
@@ -37,7 +37,7 @@ if (!argv._.length) {
|
|
|
37
37
|
// forward argv
|
|
38
38
|
process.argv = [process.argv.slice(0, 2), ...argv['--']]
|
|
39
39
|
|
|
40
|
-
|
|
40
|
+
run(argv)
|
|
41
41
|
|
|
42
42
|
function help() {
|
|
43
43
|
console.log(`
|
package/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { builtinModules, createRequire } from 'module'
|
|
|
3
3
|
import { pathToFileURL } from 'url'
|
|
4
4
|
import { dirname, resolve, relative } from 'path'
|
|
5
5
|
import vm from 'vm'
|
|
6
|
-
import { createServer } from 'vite'
|
|
6
|
+
import { createServer, mergeConfig } from 'vite'
|
|
7
7
|
import createDebug from 'debug'
|
|
8
8
|
import { red, dim, yellow, green, inverse, cyan } from 'kolorist'
|
|
9
9
|
|
|
@@ -12,7 +12,11 @@ const debugTransform = createDebug('vite-node:transform')
|
|
|
12
12
|
|
|
13
13
|
let executing = false
|
|
14
14
|
|
|
15
|
-
export async function
|
|
15
|
+
export async function run(argv) {
|
|
16
|
+
process.exitCode = 0
|
|
17
|
+
executing = true
|
|
18
|
+
let err
|
|
19
|
+
|
|
16
20
|
function log(...args) {
|
|
17
21
|
if (argv.silent)
|
|
18
22
|
return
|
|
@@ -24,7 +28,9 @@ export async function startAndRun(argv) {
|
|
|
24
28
|
|
|
25
29
|
const files = argv.files || argv._
|
|
26
30
|
|
|
27
|
-
const
|
|
31
|
+
const shouldExternalize = argv.shouldExternalize || (id => id.includes('/node_modules/'))
|
|
32
|
+
|
|
33
|
+
const server = await createServer(mergeConfig(argv.defaultConfig || {}, {
|
|
28
34
|
logLevel: 'error',
|
|
29
35
|
clearScreen: false,
|
|
30
36
|
configFile: argv.config,
|
|
@@ -42,10 +48,27 @@ export async function startAndRun(argv) {
|
|
|
42
48
|
},
|
|
43
49
|
}
|
|
44
50
|
: {},
|
|
45
|
-
})
|
|
51
|
+
}))
|
|
46
52
|
await server.pluginContainer.buildStart({})
|
|
47
53
|
|
|
48
|
-
|
|
54
|
+
process.__vite_node__ = {
|
|
55
|
+
server,
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function run() {
|
|
59
|
+
try {
|
|
60
|
+
await execute(files, server, shouldExternalize)
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
console.error(e)
|
|
64
|
+
err = e
|
|
65
|
+
if (!argv.watch)
|
|
66
|
+
process.exit(1)
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
executing = false
|
|
70
|
+
}
|
|
71
|
+
}
|
|
49
72
|
|
|
50
73
|
if (argv.watch) {
|
|
51
74
|
log(inverse(cyan(' vite node ')), cyan('watch mode enabled\n'))
|
|
@@ -57,29 +80,8 @@ export async function startAndRun(argv) {
|
|
|
57
80
|
}
|
|
58
81
|
})
|
|
59
82
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
async function run(files, server, argv) {
|
|
63
|
-
process.exitCode = 0
|
|
64
|
-
executing = true
|
|
65
|
-
let err
|
|
66
|
-
try {
|
|
67
|
-
await execute(files, server, argv)
|
|
68
|
-
}
|
|
69
|
-
catch (e) {
|
|
70
|
-
console.error(e)
|
|
71
|
-
err = e
|
|
72
|
-
if (!argv.watch)
|
|
73
|
-
process.exit(1)
|
|
74
|
-
}
|
|
75
|
-
finally {
|
|
76
|
-
executing = false
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function log(...args) {
|
|
80
|
-
if (argv.silent)
|
|
81
|
-
return
|
|
82
|
-
console.log(...args)
|
|
83
|
+
else {
|
|
84
|
+
await run()
|
|
83
85
|
}
|
|
84
86
|
|
|
85
87
|
if (argv.watch) {
|
|
@@ -112,7 +114,7 @@ function toFilePath(id, server) {
|
|
|
112
114
|
return absolute
|
|
113
115
|
}
|
|
114
116
|
|
|
115
|
-
async function execute(files, server) {
|
|
117
|
+
async function execute(files, server, shouldExternalize) {
|
|
116
118
|
const __pendingModules__ = new Map()
|
|
117
119
|
|
|
118
120
|
const result = []
|
|
@@ -145,7 +147,7 @@ async function execute(files, server) {
|
|
|
145
147
|
? `/${absolute}`
|
|
146
148
|
: absolute
|
|
147
149
|
|
|
148
|
-
if (absolute
|
|
150
|
+
if (shouldExternalize(absolute))
|
|
149
151
|
return import(unifiedPath)
|
|
150
152
|
|
|
151
153
|
const result = await server.transformRequest(id, { ssr: true })
|
package/package.json
CHANGED
package/vite-node.mjs
CHANGED