vite-node 0.1.6 → 0.1.10
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 +40 -38
- package/package.json +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) {
|
|
@@ -105,14 +107,19 @@ function normalizeId(id) {
|
|
|
105
107
|
}
|
|
106
108
|
|
|
107
109
|
function toFilePath(id, server) {
|
|
108
|
-
|
|
110
|
+
let absolute = id.startsWith('/@fs/')
|
|
109
111
|
? id.slice(4)
|
|
110
112
|
: slash(resolve(server.config.root, id.slice(1)))
|
|
111
113
|
|
|
114
|
+
if (absolute.startsWith('//'))
|
|
115
|
+
absolute = absolute.slice(1)
|
|
116
|
+
if (!absolute.startsWith('/'))
|
|
117
|
+
absolute = `/${absolute}`
|
|
118
|
+
|
|
112
119
|
return absolute
|
|
113
120
|
}
|
|
114
121
|
|
|
115
|
-
async function execute(files, server) {
|
|
122
|
+
async function execute(files, server, shouldExternalize) {
|
|
116
123
|
const __pendingModules__ = new Map()
|
|
117
124
|
|
|
118
125
|
const result = []
|
|
@@ -140,13 +147,8 @@ async function execute(files, server) {
|
|
|
140
147
|
|
|
141
148
|
debugRequest(absolute)
|
|
142
149
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
? `/${absolute}`
|
|
146
|
-
: absolute
|
|
147
|
-
|
|
148
|
-
if (absolute.includes('/node_modules/'))
|
|
149
|
-
return import(unifiedPath)
|
|
150
|
+
if (shouldExternalize(absolute))
|
|
151
|
+
return import(absolute)
|
|
150
152
|
|
|
151
153
|
const result = await server.transformRequest(id, { ssr: true })
|
|
152
154
|
if (!result)
|
|
@@ -154,7 +156,7 @@ async function execute(files, server) {
|
|
|
154
156
|
|
|
155
157
|
debugTransform(id, result.code)
|
|
156
158
|
|
|
157
|
-
const url = pathToFileURL(
|
|
159
|
+
const url = pathToFileURL(absolute)
|
|
158
160
|
const exports = {}
|
|
159
161
|
|
|
160
162
|
const context = {
|