@miniflare/runner-vm
Advanced tools
Comparing version 2.0.0-rc.3 to 2.0.0-rc.4
@@ -0,18 +1,44 @@ | ||
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __getProtoOf = Object.getPrototypeOf; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true }); | ||
var __export = (target, all) => { | ||
__markAsModule(target); | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __reExport = (target, module2, desc) => { | ||
if (module2 && typeof module2 === "object" || typeof module2 === "function") { | ||
for (let key of __getOwnPropNames(module2)) | ||
if (!__hasOwnProp.call(target, key) && key !== "default") | ||
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable }); | ||
} | ||
return target; | ||
}; | ||
var __toModule = (module2) => { | ||
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2); | ||
}; | ||
// packages/runner-vm/src/index.ts | ||
import vm2 from "vm"; | ||
__export(exports, { | ||
VMScriptRunner: () => VMScriptRunner, | ||
VMScriptRunnerError: () => VMScriptRunnerError, | ||
makeProxiedGlobals: () => makeProxiedGlobals | ||
}); | ||
var import_vm2 = __toModule(require("vm")); | ||
// packages/runner-vm/src/error.ts | ||
import { MiniflareError } from "@miniflare/shared"; | ||
var VMScriptRunnerError = class extends MiniflareError { | ||
var import_shared = __toModule(require("@miniflare/shared")); | ||
var VMScriptRunnerError = class extends import_shared.MiniflareError { | ||
}; | ||
// packages/runner-vm/src/linker.ts | ||
import { readFileSync } from "fs"; | ||
import fs from "fs/promises"; | ||
import path from "path"; | ||
import vm from "vm"; | ||
import { | ||
STRING_SCRIPT_PATH, | ||
viewToBuffer | ||
} from "@miniflare/shared"; | ||
var import_fs = __toModule(require("fs")); | ||
var import_promises = __toModule(require("fs/promises")); | ||
var import_path = __toModule(require("path")); | ||
var import_vm = __toModule(require("vm")); | ||
var import_shared2 = __toModule(require("@miniflare/shared")); | ||
var SUGGEST_BUNDLE = "If you're trying to import an npm package, you'll need to bundle your Worker first."; | ||
@@ -36,9 +62,9 @@ var ModuleLinker = class { | ||
async linker(spec, referencing) { | ||
const relative = path.relative("", referencing.identifier); | ||
const relative = import_path.default.relative("", referencing.identifier); | ||
const errorBase = `Unable to resolve "${relative}" dependency "${spec}"`; | ||
if (referencing.identifier === STRING_SCRIPT_PATH) { | ||
if (referencing.identifier === import_shared2.STRING_SCRIPT_PATH) { | ||
throw new VMScriptRunnerError("ERR_MODULE_STRING_SCRIPT", `${errorBase}: imports unsupported with string script`); | ||
} | ||
const additionalModule = this.additionalModules[spec]; | ||
const identifier = additionalModule ? spec : path.resolve(path.dirname(referencing.identifier), spec); | ||
const identifier = additionalModule ? spec : import_path.default.resolve(import_path.default.dirname(referencing.identifier), spec); | ||
const cached = this.#moduleCache.get(identifier); | ||
@@ -48,5 +74,5 @@ if (cached) | ||
const moduleOptions = { identifier, context: referencing.context }; | ||
let module; | ||
let module2; | ||
if (additionalModule) { | ||
module = new vm.SyntheticModule(Object.keys(additionalModule), function() { | ||
module2 = new import_vm.default.SyntheticModule(Object.keys(additionalModule), function() { | ||
for (const [key, value] of Object.entries(additionalModule)) { | ||
@@ -56,6 +82,6 @@ this.setExport(key, value); | ||
}, moduleOptions); | ||
this.#moduleCache.set(identifier, module); | ||
return module; | ||
this.#moduleCache.set(identifier, module2); | ||
return module2; | ||
} | ||
const relativeIdentifier = path.relative("", identifier); | ||
const relativeIdentifier = import_path.default.relative("", identifier); | ||
const rule = this.moduleRules.find((rule2) => rule2.include.test(relativeIdentifier)); | ||
@@ -66,11 +92,11 @@ if (rule === void 0) { | ||
} | ||
const data = await fs.readFile(identifier); | ||
const data = await import_promises.default.readFile(identifier); | ||
this.#referencedPathSizes.set(identifier, data.byteLength); | ||
switch (rule.type) { | ||
case "ESModule": | ||
module = new vm.SourceTextModule(data.toString("utf8"), moduleOptions); | ||
module2 = new import_vm.default.SourceTextModule(data.toString("utf8"), moduleOptions); | ||
break; | ||
case "CommonJS": | ||
const exports = this.loadCommonJSModule(errorBase, identifier, spec, referencing.context); | ||
module = new vm.SyntheticModule(["default"], function() { | ||
module2 = new import_vm.default.SyntheticModule(["default"], function() { | ||
this.setExport("default", exports); | ||
@@ -80,3 +106,3 @@ }, moduleOptions); | ||
case "Text": | ||
module = new vm.SyntheticModule(["default"], function() { | ||
module2 = new import_vm.default.SyntheticModule(["default"], function() { | ||
this.setExport("default", data.toString("utf8")); | ||
@@ -86,8 +112,8 @@ }, moduleOptions); | ||
case "Data": | ||
module = new vm.SyntheticModule(["default"], function() { | ||
this.setExport("default", viewToBuffer(data)); | ||
module2 = new import_vm.default.SyntheticModule(["default"], function() { | ||
this.setExport("default", (0, import_shared2.viewToBuffer)(data)); | ||
}, moduleOptions); | ||
break; | ||
case "CompiledWasm": | ||
module = new vm.SyntheticModule(["default"], function() { | ||
module2 = new import_vm.default.SyntheticModule(["default"], function() { | ||
this.setExport("default", new WebAssembly.Module(data)); | ||
@@ -99,4 +125,4 @@ }, moduleOptions); | ||
} | ||
this.#moduleCache.set(identifier, module); | ||
return module; | ||
this.#moduleCache.set(identifier, module2); | ||
return module2; | ||
} | ||
@@ -108,9 +134,9 @@ loadCommonJSModule(errorBase, identifier, spec, context) { | ||
const additionalModule = this.additionalModules[spec]; | ||
const module = { exports: {} }; | ||
const module2 = { exports: {} }; | ||
if (additionalModule) { | ||
module.exports.default = additionalModule.default; | ||
this.#cjsModuleCache.set(identifier, module); | ||
return module.exports; | ||
module2.exports.default = additionalModule.default; | ||
this.#cjsModuleCache.set(identifier, module2); | ||
return module2.exports; | ||
} | ||
const relativeIdentifier = path.relative("", identifier); | ||
const relativeIdentifier = import_path.default.relative("", identifier); | ||
const rule = this.moduleRules.find((rule2) => rule2.include.test(relativeIdentifier)); | ||
@@ -121,4 +147,4 @@ if (rule === void 0) { | ||
} | ||
this.#cjsModuleCache.set(identifier, module); | ||
const data = readFileSync(identifier); | ||
this.#cjsModuleCache.set(identifier, module2); | ||
const data = (0, import_fs.readFileSync)(identifier); | ||
this.#referencedPathSizes.set(identifier, data.byteLength); | ||
@@ -133,3 +159,3 @@ switch (rule.type) { | ||
});`; | ||
const script = new vm.Script(wrapped, { | ||
const script = new import_vm.default.Script(wrapped, { | ||
filename: identifier, | ||
@@ -140,12 +166,12 @@ lineOffset: -1 | ||
const require2 = this.createRequire(identifier, context); | ||
moduleWrapper(module.exports, require2, module); | ||
moduleWrapper(module2.exports, require2, module2); | ||
break; | ||
case "Text": | ||
module.exports.default = data.toString("utf8"); | ||
module2.exports.default = data.toString("utf8"); | ||
break; | ||
case "Data": | ||
module.exports.default = viewToBuffer(data); | ||
module2.exports.default = (0, import_shared2.viewToBuffer)(data); | ||
break; | ||
case "CompiledWasm": | ||
module.exports.default = new WebAssembly.Module(data); | ||
module2.exports.default = new WebAssembly.Module(data); | ||
break; | ||
@@ -155,10 +181,10 @@ default: | ||
} | ||
return module.exports; | ||
return module2.exports; | ||
} | ||
createRequire(referencingIdentifier, context) { | ||
const relative = path.relative("", referencingIdentifier); | ||
const referencingDirname = path.dirname(referencingIdentifier); | ||
const relative = import_path.default.relative("", referencingIdentifier); | ||
const referencingDirname = import_path.default.dirname(referencingIdentifier); | ||
return (spec) => { | ||
const errorBase = `Unable to resolve "${relative}" dependency "${spec}"`; | ||
const identifier = path.resolve(referencingDirname, spec); | ||
const identifier = import_path.default.resolve(referencingDirname, spec); | ||
return this.loadCommonJSModule(errorBase, identifier, spec, context); | ||
@@ -170,3 +196,3 @@ }; | ||
// packages/runner-vm/src/proxied.ts | ||
import { types } from "util"; | ||
var import_util = __toModule(require("util")); | ||
function isObject(value) { | ||
@@ -181,3 +207,3 @@ return value !== null && typeof value === "object"; | ||
return function(value) { | ||
if (!types.isNativeError(value)) | ||
if (!import_util.types.isNativeError(value)) | ||
return false; | ||
@@ -208,4 +234,4 @@ let prototype = value; | ||
Array: proxyHasInstance(Array, Array.isArray), | ||
Promise: proxyHasInstance(Promise, types.isPromise), | ||
RegExp: proxyHasInstance(RegExp, types.isRegExp), | ||
Promise: proxyHasInstance(Promise, import_util.types.isPromise), | ||
RegExp: proxyHasInstance(RegExp, import_util.types.isRegExp), | ||
Error: proxyHasInstance(Error, isError(Error)), | ||
@@ -233,3 +259,3 @@ EvalError: proxyHasInstance(EvalError, isError(EvalError)), | ||
runAsScript(context, blueprint) { | ||
const script = new vm2.Script(blueprint.code, { | ||
const script = new import_vm2.default.Script(blueprint.code, { | ||
filename: blueprint.filePath | ||
@@ -240,12 +266,12 @@ }); | ||
async runAsModule(context, blueprint, linker) { | ||
const module = new vm2.SourceTextModule(blueprint.code, { | ||
const module2 = new import_vm2.default.SourceTextModule(blueprint.code, { | ||
identifier: blueprint.filePath, | ||
context | ||
}); | ||
await module.link(linker); | ||
await module.evaluate(); | ||
return module.namespace; | ||
await module2.link(linker); | ||
await module2.evaluate(); | ||
return module2.namespace; | ||
} | ||
async run(globalScope, blueprint, modulesRules, additionalModules) { | ||
if (modulesRules && !("SourceTextModule" in vm2)) { | ||
if (modulesRules && !("SourceTextModule" in import_vm2.default)) { | ||
throw new VMScriptRunnerError("ERR_MODULE_DISABLED", "Modules support requires the --experimental-vm-modules flag"); | ||
@@ -260,3 +286,3 @@ } | ||
const allow = !this.blockCodeGeneration; | ||
context = vm2.createContext(globalScope, { | ||
context = import_vm2.default.createContext(globalScope, { | ||
codeGeneration: { strings: allow, wasm: allow } | ||
@@ -279,7 +305,8 @@ }); | ||
}; | ||
export { | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
VMScriptRunner, | ||
VMScriptRunnerError, | ||
makeProxiedGlobals | ||
}; | ||
}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@miniflare/runner-vm", | ||
"version": "2.0.0-rc.3", | ||
"version": "2.0.0-rc.4", | ||
"description": "VM script runner module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers", | ||
@@ -14,4 +14,3 @@ "keywords": [ | ||
"license": "MIT", | ||
"type": "module", | ||
"exports": "./dist/src/index.js", | ||
"main": "./dist/src/index.js", | ||
"types": "./dist/src/index.d.ts", | ||
@@ -40,7 +39,7 @@ "files": [ | ||
"dependencies": { | ||
"@miniflare/shared": "2.0.0-rc.3" | ||
"@miniflare/shared": "2.0.0-rc.4" | ||
}, | ||
"devDependencies": { | ||
"@miniflare/shared-test": "2.0.0-rc.3" | ||
"@miniflare/shared-test": "2.0.0-rc.4" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20857
323
No
+ Added@miniflare/shared@2.0.0-rc.4(transitive)
- Removed@miniflare/shared@2.0.0-rc.3(transitive)
Updated@miniflare/shared@2.0.0-rc.4