vite-node 0.1.0 → 0.1.1

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.
Files changed (2) hide show
  1. package/index.mjs +10 -11
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -2,6 +2,7 @@
2
2
  import { builtinModules, createRequire } from 'module'
3
3
  import { pathToFileURL } from 'url'
4
4
  import { dirname, resolve, relative } from 'path'
5
+ import vm from 'vm'
5
6
  import { createServer } from 'vite'
6
7
  import createDebug from 'debug'
7
8
  import minimist from 'minimist'
@@ -40,7 +41,6 @@ if (!argv._.length) {
40
41
 
41
42
  const debugRequest = createDebug('vite-node:request')
42
43
  const debugTransform = createDebug('vite-node:transform')
43
- const AsyncFunction = Object.getPrototypeOf(async() => {}).constructor
44
44
 
45
45
  const root = argv.root || process.cwd()
46
46
  process.chdir(root)
@@ -185,21 +185,20 @@ async function execute(files, server) {
185
185
  __vite_ssr_import_meta__: { url },
186
186
  }
187
187
 
188
- const fn = new AsyncFunction(
189
- ...Object.keys(context),
190
- result.code,
191
- )
192
-
193
- // prefetch deps
188
+ const fn = vm.runInThisContext(`async (${Object.keys(context).join(',')}) => { ${result.code} }`, {
189
+ filename: absolute,
190
+ lineOffset: 0,
191
+ })
194
192
  await fn(...Object.values(context))
195
193
 
196
194
  return exports
197
195
  }
198
196
 
199
- function cachedRequest(id, callstack) {
200
- if (!__pendingModules__[id])
201
- __pendingModules__[id] = directRequest(id, callstack)
202
- return __pendingModules__[id]
197
+ async function cachedRequest(id, callstack) {
198
+ if (__pendingModules__[id])
199
+ return __pendingModules__[id]
200
+ __pendingModules__[id] = directRequest(id, callstack)
201
+ return await __pendingModules__[id]
203
202
  }
204
203
 
205
204
  function exportAll(exports, sourceModule) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-node",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Vite as Node runtime",
5
5
  "keywords": [
6
6
  "vite"