vite-node 0.1.4 → 0.1.8
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 +28 -30
- package/package.json +2 -2
- 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,23 @@ export async function startAndRun(argv) {
|
|
|
42
48
|
},
|
|
43
49
|
}
|
|
44
50
|
: {},
|
|
45
|
-
})
|
|
51
|
+
}))
|
|
46
52
|
await server.pluginContainer.buildStart({})
|
|
47
53
|
|
|
48
|
-
|
|
54
|
+
async function run() {
|
|
55
|
+
try {
|
|
56
|
+
await execute(files, server, shouldExternalize)
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
console.error(e)
|
|
60
|
+
err = e
|
|
61
|
+
if (!argv.watch)
|
|
62
|
+
process.exit(1)
|
|
63
|
+
}
|
|
64
|
+
finally {
|
|
65
|
+
executing = false
|
|
66
|
+
}
|
|
67
|
+
}
|
|
49
68
|
|
|
50
69
|
if (argv.watch) {
|
|
51
70
|
log(inverse(cyan(' vite node ')), cyan('watch mode enabled\n'))
|
|
@@ -57,29 +76,8 @@ export async function startAndRun(argv) {
|
|
|
57
76
|
}
|
|
58
77
|
})
|
|
59
78
|
}
|
|
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)
|
|
79
|
+
else {
|
|
80
|
+
await run()
|
|
83
81
|
}
|
|
84
82
|
|
|
85
83
|
if (argv.watch) {
|
|
@@ -112,7 +110,7 @@ function toFilePath(id, server) {
|
|
|
112
110
|
return absolute
|
|
113
111
|
}
|
|
114
112
|
|
|
115
|
-
async function execute(files, server) {
|
|
113
|
+
async function execute(files, server, shouldExternalize) {
|
|
116
114
|
const __pendingModules__ = new Map()
|
|
117
115
|
|
|
118
116
|
const result = []
|
|
@@ -145,7 +143,7 @@ async function execute(files, server) {
|
|
|
145
143
|
? `/${absolute}`
|
|
146
144
|
: absolute
|
|
147
145
|
|
|
148
|
-
if (absolute
|
|
146
|
+
if (shouldExternalize(absolute))
|
|
149
147
|
return import(unifiedPath)
|
|
150
148
|
|
|
151
149
|
const result = await server.transformRequest(id, { ssr: true })
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-node",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "Vite as Node runtime",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"vite"
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"module": "./index.mjs",
|
|
32
32
|
"types": "./index.d.ts",
|
|
33
33
|
"bin": {
|
|
34
|
-
"vite-node": "
|
|
34
|
+
"vite-node": "./vite-node.mjs"
|
|
35
35
|
},
|
|
36
36
|
"files": [
|
|
37
37
|
"*.mjs"
|
package/vite-node.mjs
CHANGED