vite-node 0.1.7 → 0.1.11
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/index.mjs +20 -12
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -28,6 +28,8 @@ export async function run(argv) {
|
|
|
28
28
|
|
|
29
29
|
const files = argv.files || argv._
|
|
30
30
|
|
|
31
|
+
const shouldExternalize = argv.shouldExternalize || (id => id.includes('/node_modules/'))
|
|
32
|
+
|
|
31
33
|
const server = await createServer(mergeConfig(argv.defaultConfig || {}, {
|
|
32
34
|
logLevel: 'error',
|
|
33
35
|
clearScreen: false,
|
|
@@ -49,9 +51,13 @@ export async function run(argv) {
|
|
|
49
51
|
}))
|
|
50
52
|
await server.pluginContainer.buildStart({})
|
|
51
53
|
|
|
54
|
+
process.__vite_node__ = {
|
|
55
|
+
server,
|
|
56
|
+
}
|
|
57
|
+
|
|
52
58
|
async function run() {
|
|
53
59
|
try {
|
|
54
|
-
await execute(files, server,
|
|
60
|
+
await execute(files, server, shouldExternalize)
|
|
55
61
|
}
|
|
56
62
|
catch (e) {
|
|
57
63
|
console.error(e)
|
|
@@ -101,14 +107,21 @@ function normalizeId(id) {
|
|
|
101
107
|
}
|
|
102
108
|
|
|
103
109
|
function toFilePath(id, server) {
|
|
104
|
-
|
|
110
|
+
let absolute = id.startsWith('/@fs/')
|
|
105
111
|
? id.slice(4)
|
|
106
|
-
:
|
|
112
|
+
: id.startsWith(dirname(server.config.root))
|
|
113
|
+
? id
|
|
114
|
+
: slash(resolve(server.config.root, id.slice(1)))
|
|
115
|
+
|
|
116
|
+
if (absolute.startsWith('//'))
|
|
117
|
+
absolute = absolute.slice(1)
|
|
118
|
+
if (!absolute.startsWith('/'))
|
|
119
|
+
absolute = `/${absolute}`
|
|
107
120
|
|
|
108
121
|
return absolute
|
|
109
122
|
}
|
|
110
123
|
|
|
111
|
-
async function execute(files, server) {
|
|
124
|
+
async function execute(files, server, shouldExternalize) {
|
|
112
125
|
const __pendingModules__ = new Map()
|
|
113
126
|
|
|
114
127
|
const result = []
|
|
@@ -136,13 +149,8 @@ async function execute(files, server) {
|
|
|
136
149
|
|
|
137
150
|
debugRequest(absolute)
|
|
138
151
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
? `/${absolute}`
|
|
142
|
-
: absolute
|
|
143
|
-
|
|
144
|
-
if (absolute.includes('/node_modules/'))
|
|
145
|
-
return import(unifiedPath)
|
|
152
|
+
if (shouldExternalize(absolute))
|
|
153
|
+
return import(absolute)
|
|
146
154
|
|
|
147
155
|
const result = await server.transformRequest(id, { ssr: true })
|
|
148
156
|
if (!result)
|
|
@@ -150,7 +158,7 @@ async function execute(files, server) {
|
|
|
150
158
|
|
|
151
159
|
debugTransform(id, result.code)
|
|
152
160
|
|
|
153
|
-
const url = pathToFileURL(
|
|
161
|
+
const url = pathToFileURL(absolute)
|
|
154
162
|
const exports = {}
|
|
155
163
|
|
|
156
164
|
const context = {
|