miniflare
Advanced tools
Comparing version 2.0.0-rc.3 to 2.0.0-rc.4
#!/usr/bin/env node | ||
// @ts-check | ||
import childProcess from "child_process"; | ||
import path from "path"; | ||
import { fileURLToPath } from "url"; | ||
import semiver from "semiver"; | ||
const childProcess = require("child_process"); | ||
const path = require("path"); | ||
const semiver = require("semiver"); | ||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
// Miniflare makes extensive use of new Web Standards added in recent versions | ||
@@ -17,4 +13,5 @@ // of Node.js (streams, crypto, Blob, EventTarget). The most recent thing | ||
async function main() { | ||
// @ts-expect-error require doesn't give the correct types | ||
if (semiver(process.versions.node, MIN_NODE_VERSION) < 0) { | ||
const { red } = await import("kleur/colors"); | ||
const { red } = require("kleur/colors"); | ||
// Note Volta and nvm are also recommended in the official docs: | ||
@@ -51,5 +48,5 @@ // https://developers.cloudflare.com/workers/get-started/guide#2-install-the-workers-cli | ||
) | ||
.on("exit", (code) => process.exit(code ?? 0)); | ||
.on("exit", (code) => process.exit(code === null ? 1 : code)); | ||
} | ||
void main(); |
#!/usr/bin/env node | ||
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 __commonJS = (cb, mod) => function __require() { | ||
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; | ||
}; | ||
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); | ||
}; | ||
// node_modules/is-docker/index.js | ||
var require_is_docker = __commonJS({ | ||
"node_modules/is-docker/index.js"(exports2, module2) { | ||
"use strict"; | ||
var fs3 = require("fs"); | ||
var isDocker; | ||
function hasDockerEnv() { | ||
try { | ||
fs3.statSync("/.dockerenv"); | ||
return true; | ||
} catch (_) { | ||
return false; | ||
} | ||
} | ||
function hasDockerCGroup() { | ||
try { | ||
return fs3.readFileSync("/proc/self/cgroup", "utf8").includes("docker"); | ||
} catch (_) { | ||
return false; | ||
} | ||
} | ||
module2.exports = () => { | ||
if (isDocker === void 0) { | ||
isDocker = hasDockerEnv() || hasDockerCGroup(); | ||
} | ||
return isDocker; | ||
}; | ||
} | ||
}); | ||
// node_modules/is-wsl/index.js | ||
var require_is_wsl = __commonJS({ | ||
"node_modules/is-wsl/index.js"(exports2, module2) { | ||
"use strict"; | ||
var os = require("os"); | ||
var fs3 = require("fs"); | ||
var isDocker = require_is_docker(); | ||
var isWsl = () => { | ||
if (process.platform !== "linux") { | ||
return false; | ||
} | ||
if (os.release().toLowerCase().includes("microsoft")) { | ||
if (isDocker()) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
try { | ||
return fs3.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft") ? !isDocker() : false; | ||
} catch (_) { | ||
return false; | ||
} | ||
}; | ||
if (process.env.__IS_WSL_TEST__) { | ||
module2.exports = isWsl; | ||
} else { | ||
module2.exports = isWsl(); | ||
} | ||
} | ||
}); | ||
// node_modules/define-lazy-prop/index.js | ||
var require_define_lazy_prop = __commonJS({ | ||
"node_modules/define-lazy-prop/index.js"(exports2, module2) { | ||
"use strict"; | ||
module2.exports = (object, propertyName, fn) => { | ||
const define = (value) => Object.defineProperty(object, propertyName, { value, enumerable: true, writable: true }); | ||
Object.defineProperty(object, propertyName, { | ||
configurable: true, | ||
enumerable: true, | ||
get() { | ||
const result = fn(); | ||
define(result); | ||
return result; | ||
}, | ||
set(value) { | ||
define(value); | ||
} | ||
}); | ||
return object; | ||
}; | ||
} | ||
}); | ||
// node_modules/open/index.js | ||
var require_open = __commonJS({ | ||
"node_modules/open/index.js"(exports2, module2) { | ||
var path2 = require("path"); | ||
var childProcess = require("child_process"); | ||
var { promises: fs3, constants: fsConstants } = require("fs"); | ||
var isWsl = require_is_wsl(); | ||
var isDocker = require_is_docker(); | ||
var defineLazyProperty = require_define_lazy_prop(); | ||
var localXdgOpenPath = path2.join(__dirname, "xdg-open"); | ||
var { platform, arch } = process; | ||
var getWslDrivesMountPoint = (() => { | ||
const defaultMountPoint = "/mnt/"; | ||
let mountPoint; | ||
return async function() { | ||
if (mountPoint) { | ||
return mountPoint; | ||
} | ||
const configFilePath = "/etc/wsl.conf"; | ||
let isConfigFileExists = false; | ||
try { | ||
await fs3.access(configFilePath, fsConstants.F_OK); | ||
isConfigFileExists = true; | ||
} catch { | ||
} | ||
if (!isConfigFileExists) { | ||
return defaultMountPoint; | ||
} | ||
const configContent = await fs3.readFile(configFilePath, { encoding: "utf8" }); | ||
const configMountPoint = /(?<!#.*)root\s*=\s*(?<mountPoint>.*)/g.exec(configContent); | ||
if (!configMountPoint) { | ||
return defaultMountPoint; | ||
} | ||
mountPoint = configMountPoint.groups.mountPoint.trim(); | ||
mountPoint = mountPoint.endsWith("/") ? mountPoint : `${mountPoint}/`; | ||
return mountPoint; | ||
}; | ||
})(); | ||
var pTryEach = async (array, mapper) => { | ||
let latestError; | ||
for (const item of array) { | ||
try { | ||
return await mapper(item); | ||
} catch (error) { | ||
latestError = error; | ||
} | ||
} | ||
throw latestError; | ||
}; | ||
var baseOpen = async (options) => { | ||
options = { | ||
wait: false, | ||
background: false, | ||
newInstance: false, | ||
allowNonzeroExitCode: false, | ||
...options | ||
}; | ||
if (Array.isArray(options.app)) { | ||
return pTryEach(options.app, (singleApp) => baseOpen({ | ||
...options, | ||
app: singleApp | ||
})); | ||
} | ||
let { name: app, arguments: appArguments = [] } = options.app || {}; | ||
appArguments = [...appArguments]; | ||
if (Array.isArray(app)) { | ||
return pTryEach(app, (appName) => baseOpen({ | ||
...options, | ||
app: { | ||
name: appName, | ||
arguments: appArguments | ||
} | ||
})); | ||
} | ||
let command; | ||
const cliArguments = []; | ||
const childProcessOptions = {}; | ||
if (platform === "darwin") { | ||
command = "open"; | ||
if (options.wait) { | ||
cliArguments.push("--wait-apps"); | ||
} | ||
if (options.background) { | ||
cliArguments.push("--background"); | ||
} | ||
if (options.newInstance) { | ||
cliArguments.push("--new"); | ||
} | ||
if (app) { | ||
cliArguments.push("-a", app); | ||
} | ||
} else if (platform === "win32" || isWsl && !isDocker()) { | ||
const mountPoint = await getWslDrivesMountPoint(); | ||
command = isWsl ? `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe` : `${process.env.SYSTEMROOT}\\System32\\WindowsPowerShell\\v1.0\\powershell`; | ||
cliArguments.push("-NoProfile", "-NonInteractive", "\u2013ExecutionPolicy", "Bypass", "-EncodedCommand"); | ||
if (!isWsl) { | ||
childProcessOptions.windowsVerbatimArguments = true; | ||
} | ||
const encodedArguments = ["Start"]; | ||
if (options.wait) { | ||
encodedArguments.push("-Wait"); | ||
} | ||
if (app) { | ||
encodedArguments.push(`"\`"${app}\`""`, "-ArgumentList"); | ||
if (options.target) { | ||
appArguments.unshift(options.target); | ||
} | ||
} else if (options.target) { | ||
encodedArguments.push(`"${options.target}"`); | ||
} | ||
if (appArguments.length > 0) { | ||
appArguments = appArguments.map((arg) => `"\`"${arg}\`""`); | ||
encodedArguments.push(appArguments.join(",")); | ||
} | ||
options.target = Buffer.from(encodedArguments.join(" "), "utf16le").toString("base64"); | ||
} else { | ||
if (app) { | ||
command = app; | ||
} else { | ||
const isBundled = !__dirname || __dirname === "/"; | ||
let exeLocalXdgOpen = false; | ||
try { | ||
await fs3.access(localXdgOpenPath, fsConstants.X_OK); | ||
exeLocalXdgOpen = true; | ||
} catch { | ||
} | ||
const useSystemXdgOpen = process.versions.electron || platform === "android" || isBundled || !exeLocalXdgOpen; | ||
command = useSystemXdgOpen ? "xdg-open" : localXdgOpenPath; | ||
} | ||
if (appArguments.length > 0) { | ||
cliArguments.push(...appArguments); | ||
} | ||
if (!options.wait) { | ||
childProcessOptions.stdio = "ignore"; | ||
childProcessOptions.detached = true; | ||
} | ||
} | ||
if (options.target) { | ||
cliArguments.push(options.target); | ||
} | ||
if (platform === "darwin" && appArguments.length > 0) { | ||
cliArguments.push("--args", ...appArguments); | ||
} | ||
const subprocess = childProcess.spawn(command, cliArguments, childProcessOptions); | ||
if (options.wait) { | ||
return new Promise((resolve, reject) => { | ||
subprocess.once("error", reject); | ||
subprocess.once("close", (exitCode) => { | ||
if (options.allowNonzeroExitCode && exitCode > 0) { | ||
reject(new Error(`Exited with code ${exitCode}`)); | ||
return; | ||
} | ||
resolve(subprocess); | ||
}); | ||
}); | ||
} | ||
subprocess.unref(); | ||
return subprocess; | ||
}; | ||
var open2 = (target, options) => { | ||
if (typeof target !== "string") { | ||
throw new TypeError("Expected a `target`"); | ||
} | ||
return baseOpen({ | ||
...options, | ||
target | ||
}); | ||
}; | ||
var openApp = (name, options) => { | ||
if (typeof name !== "string") { | ||
throw new TypeError("Expected a `name`"); | ||
} | ||
const { arguments: appArguments = [] } = options || {}; | ||
if (appArguments !== void 0 && appArguments !== null && !Array.isArray(appArguments)) { | ||
throw new TypeError("Expected `appArguments` as Array type"); | ||
} | ||
return baseOpen({ | ||
...options, | ||
app: { | ||
name, | ||
arguments: appArguments | ||
} | ||
}); | ||
}; | ||
function detectArchBinary(binary) { | ||
if (typeof binary === "string" || Array.isArray(binary)) { | ||
return binary; | ||
} | ||
const { [arch]: archBinary } = binary; | ||
if (!archBinary) { | ||
throw new Error(`${arch} is not supported`); | ||
} | ||
return archBinary; | ||
} | ||
function detectPlatformBinary({ [platform]: platformBinary }, { wsl }) { | ||
if (wsl && isWsl) { | ||
return detectArchBinary(wsl); | ||
} | ||
if (!platformBinary) { | ||
throw new Error(`${platform} is not supported`); | ||
} | ||
return detectArchBinary(platformBinary); | ||
} | ||
var apps = {}; | ||
defineLazyProperty(apps, "chrome", () => detectPlatformBinary({ | ||
darwin: "google chrome", | ||
win32: "chrome", | ||
linux: ["google-chrome", "google-chrome-stable", "chromium"] | ||
}, { | ||
wsl: { | ||
ia32: "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe", | ||
x64: ["/mnt/c/Program Files/Google/Chrome/Application/chrome.exe", "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"] | ||
} | ||
})); | ||
defineLazyProperty(apps, "firefox", () => detectPlatformBinary({ | ||
darwin: "firefox", | ||
win32: "C:\\Program Files\\Mozilla Firefox\\firefox.exe", | ||
linux: "firefox" | ||
}, { | ||
wsl: "/mnt/c/Program Files/Mozilla Firefox/firefox.exe" | ||
})); | ||
defineLazyProperty(apps, "edge", () => detectPlatformBinary({ | ||
darwin: "microsoft edge", | ||
win32: "msedge", | ||
linux: ["microsoft-edge", "microsoft-edge-dev"] | ||
}, { | ||
wsl: "/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe" | ||
})); | ||
open2.apps = apps; | ||
open2.openApp = openApp; | ||
module2.exports = open2; | ||
} | ||
}); | ||
// packages/miniflare/src/cli.ts | ||
import fs2 from "fs/promises"; | ||
import path from "path"; | ||
import { fileURLToPath } from "url"; | ||
import { red } from "kleur/colors"; | ||
var import_promises2 = __toModule(require("fs/promises")); | ||
var import_path = __toModule(require("path")); | ||
var import_colors = __toModule(require("kleur/colors")); | ||
var import_open = __toModule(require_open()); | ||
// packages/miniflare/src/updater.ts | ||
import fs from "fs/promises"; | ||
import semiver from "semiver"; | ||
import { fetch } from "undici"; | ||
var import_promises = __toModule(require("fs/promises")); | ||
var import_semiver = __toModule(require("semiver")); | ||
var import_undici = __toModule(require("undici")); | ||
var numericCompare = new Intl.Collator(void 0, { numeric: true }).compare; | ||
@@ -23,3 +362,3 @@ async function updateCheck({ | ||
try { | ||
lastCheck = parseInt(await fs.readFile(lastCheckFile, "utf8")); | ||
lastCheck = parseInt(await import_promises.default.readFile(lastCheckFile, "utf8")); | ||
} catch { | ||
@@ -29,3 +368,3 @@ } | ||
return; | ||
const res = await fetch(`${registry}${pkg.name}/latest`, { | ||
const res = await (0, import_undici.fetch)(`${registry}${pkg.name}/latest`, { | ||
headers: { Accept: "application/json" } | ||
@@ -36,4 +375,4 @@ }); | ||
return; | ||
await fs.writeFile(lastCheckFile, now.toString(), "utf8"); | ||
if (semiver(registryVersion, pkg.version) > 0) { | ||
await import_promises.default.writeFile(lastCheckFile, now.toString(), "utf8"); | ||
if ((0, import_semiver.default)(registryVersion, pkg.version) > 0) { | ||
log.warn(`Miniflare ${registryVersion} is available, but you're using ${pkg.version}. Update for improved compatibility with Cloudflare Workers.`); | ||
@@ -49,4 +388,2 @@ const registryMajor = registryVersion.split(".")[0]; | ||
// packages/miniflare/src/cli.ts | ||
var __filename = fileURLToPath(import.meta.url); | ||
var __dirname = path.dirname(__filename); | ||
function suppressWarnings() { | ||
@@ -65,11 +402,15 @@ const originalEmitWarning = process.emitWarning; | ||
async function main() { | ||
const [ | ||
{ ParseError, buildHelp, parseArgv }, | ||
{ Log, LogLevel }, | ||
{ Miniflare, PLUGINS } | ||
] = await Promise.all([ | ||
import("@miniflare/cli-parser"), | ||
import("@miniflare/shared"), | ||
import("miniflare") | ||
]); | ||
const { | ||
ParseError, | ||
buildHelp, | ||
parseArgv | ||
} = require("@miniflare/cli-parser"); | ||
const { | ||
Log, | ||
LogLevel | ||
} = require("@miniflare/shared"); | ||
const { | ||
Miniflare, | ||
PLUGINS | ||
} = require("miniflare"); | ||
let options; | ||
@@ -90,3 +431,3 @@ try { | ||
console.error(` | ||
${red(e.message)}`); | ||
${(0, import_colors.red)(e.message)}`); | ||
process.exitCode = 1; | ||
@@ -108,2 +449,3 @@ return; | ||
mfOptions.sourceMap = true; | ||
mfOptions.logUnhandledRejections = true; | ||
const mf = new Miniflare(mfOptions); | ||
@@ -121,2 +463,9 @@ try { | ||
} | ||
const openURL = await mf.getOpenURL(); | ||
try { | ||
if (openURL) | ||
await (0, import_open.default)(openURL); | ||
} catch (e) { | ||
mf.log.warn("Unable to open browser: " + e.stack); | ||
} | ||
const plugins = await mf.getPlugins(); | ||
@@ -126,7 +475,7 @@ if (plugins.CorePlugin.updateCheck === false) | ||
try { | ||
const pkgFile = path.join(__dirname, "..", "..", "package.json"); | ||
const pkg = JSON.parse(await fs2.readFile(pkgFile, "utf8")); | ||
const cacheDir = path.resolve("node_modules", ".mf"); | ||
await fs2.mkdir(cacheDir, { recursive: true }); | ||
const lastCheckFile = path.join(cacheDir, "update-check"); | ||
const pkgFile = import_path.default.join(__dirname, "..", "..", "package.json"); | ||
const pkg = JSON.parse(await import_promises2.default.readFile(pkgFile, "utf8")); | ||
const cacheDir = import_path.default.resolve("node_modules", ".mf"); | ||
await import_promises2.default.mkdir(cacheDir, { recursive: true }); | ||
const lastCheckFile = import_path.default.join(cacheDir, "update-check"); | ||
await updateCheck({ pkg, lastCheckFile, log: mf.log }); | ||
@@ -133,0 +482,0 @@ } catch (e) { |
@@ -8,2 +8,3 @@ /// <reference types="node" /> | ||
import { CorePlugin } from '@miniflare/core'; | ||
import { CronScheduler } from '@miniflare/scheduler'; | ||
import { DurableObjectId } from '@miniflare/durable-objects'; | ||
@@ -25,3 +26,2 @@ import { DurableObjectNamespace } from '@miniflare/durable-objects'; | ||
import { MiniflareCoreOptions } from '@miniflare/core'; | ||
import { Scheduler } from '@miniflare/scheduler'; | ||
import { SchedulerPlugin } from '@miniflare/scheduler'; | ||
@@ -47,3 +47,4 @@ import { SitesPlugin } from '@miniflare/sites'; | ||
startServer(options?: http.ServerOptions & https.ServerOptions): Promise<http.Server | https.Server>; | ||
startScheduler(): Promise<Scheduler<Plugins>>; | ||
startScheduler(): Promise<CronScheduler<Plugins>>; | ||
getOpenURL(): Promise<string | undefined>; | ||
} | ||
@@ -50,0 +51,0 @@ |
@@ -0,29 +1,53 @@ | ||
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/miniflare/src/index.ts | ||
__export(exports, { | ||
Log: () => import_shared3.Log, | ||
LogLevel: () => import_shared3.LogLevel, | ||
Miniflare: () => Miniflare, | ||
PLUGINS: () => PLUGINS, | ||
VariedStorageFactory: () => VariedStorageFactory, | ||
updateCheck: () => updateCheck | ||
}); | ||
// packages/miniflare/src/api.ts | ||
import { CachePlugin } from "@miniflare/cache"; | ||
import { | ||
BindingsPlugin, | ||
BuildPlugin, | ||
CorePlugin, | ||
MiniflareCore | ||
} from "@miniflare/core"; | ||
import { | ||
DurableObjectsPlugin | ||
} from "@miniflare/durable-objects"; | ||
import { HTMLRewriterPlugin } from "@miniflare/html-rewriter"; | ||
import { HTTPPlugin, createServer, startServer } from "@miniflare/http-server"; | ||
import { KVPlugin } from "@miniflare/kv"; | ||
import { VMScriptRunner } from "@miniflare/runner-vm"; | ||
import { | ||
SchedulerPlugin, | ||
startScheduler | ||
} from "@miniflare/scheduler"; | ||
import { NoOpLog } from "@miniflare/shared"; | ||
import { SitesPlugin } from "@miniflare/sites"; | ||
import { WebSocketPlugin } from "@miniflare/web-sockets"; | ||
import sourceMap from "source-map-support"; | ||
var import_cache = __toModule(require("@miniflare/cache")); | ||
var import_core = __toModule(require("@miniflare/core")); | ||
var import_durable_objects = __toModule(require("@miniflare/durable-objects")); | ||
var import_html_rewriter = __toModule(require("@miniflare/html-rewriter")); | ||
var import_http_server = __toModule(require("@miniflare/http-server")); | ||
var import_kv = __toModule(require("@miniflare/kv")); | ||
var import_runner_vm = __toModule(require("@miniflare/runner-vm")); | ||
var import_scheduler = __toModule(require("@miniflare/scheduler")); | ||
var import_shared2 = __toModule(require("@miniflare/shared")); | ||
var import_sites = __toModule(require("@miniflare/sites")); | ||
var import_web_sockets = __toModule(require("@miniflare/web-sockets")); | ||
var import_source_map_support = __toModule(require("source-map-support")); | ||
// packages/miniflare/src/storage.ts | ||
import assert from "assert"; | ||
import path from "path"; | ||
import { sanitisePath } from "@miniflare/shared"; | ||
var import_assert = __toModule(require("assert")); | ||
var import_path = __toModule(require("path")); | ||
var import_shared = __toModule(require("@miniflare/shared")); | ||
var redisConnectionStringRegexp = /^rediss?:\/\//; | ||
@@ -36,3 +60,3 @@ var VariedStorageFactory = class { | ||
async storage(namespace, persist) { | ||
assert(typeof persist !== "boolean"); | ||
(0, import_assert.default)(typeof persist !== "boolean"); | ||
if (persist === void 0) { | ||
@@ -42,3 +66,5 @@ let storage = this.memoryStorages.get(namespace); | ||
return storage; | ||
const { MemoryStorage } = await import("@miniflare/storage-memory"); | ||
const { | ||
MemoryStorage | ||
} = require("@miniflare/storage-memory"); | ||
this.memoryStorages.set(namespace, storage = new MemoryStorage()); | ||
@@ -48,12 +74,16 @@ return storage; | ||
if (redisConnectionStringRegexp.test(persist)) { | ||
const { RedisStorage } = await import("@miniflare/storage-redis"); | ||
const IORedis = await import("ioredis"); | ||
const { | ||
RedisStorage | ||
} = require("@miniflare/storage-redis"); | ||
const IORedis = require("ioredis"); | ||
let connection = this.redisConnections.get(persist); | ||
if (!connection) { | ||
this.redisConnections.set(persist, connection = new IORedis.default(persist)); | ||
this.redisConnections.set(persist, connection = new IORedis(persist)); | ||
} | ||
return new RedisStorage(connection, namespace); | ||
} | ||
const root = path.join(persist, sanitisePath(namespace)); | ||
const { FileStorage } = await import("@miniflare/storage-file"); | ||
const root = import_path.default.join(persist, (0, import_shared.sanitisePath)(namespace)); | ||
const { | ||
FileStorage | ||
} = require("@miniflare/storage-file"); | ||
return new FileStorage(root); | ||
@@ -70,25 +100,25 @@ } | ||
var PLUGINS = { | ||
CorePlugin, | ||
HTTPPlugin, | ||
SchedulerPlugin, | ||
BuildPlugin, | ||
KVPlugin, | ||
DurableObjectsPlugin, | ||
CachePlugin, | ||
SitesPlugin, | ||
HTMLRewriterPlugin, | ||
WebSocketPlugin, | ||
BindingsPlugin | ||
CorePlugin: import_core.CorePlugin, | ||
HTTPPlugin: import_http_server.HTTPPlugin, | ||
SchedulerPlugin: import_scheduler.SchedulerPlugin, | ||
BuildPlugin: import_core.BuildPlugin, | ||
KVPlugin: import_kv.KVPlugin, | ||
DurableObjectsPlugin: import_durable_objects.DurableObjectsPlugin, | ||
CachePlugin: import_cache.CachePlugin, | ||
SitesPlugin: import_sites.SitesPlugin, | ||
HTMLRewriterPlugin: import_html_rewriter.HTMLRewriterPlugin, | ||
WebSocketPlugin: import_web_sockets.WebSocketPlugin, | ||
BindingsPlugin: import_core.BindingsPlugin | ||
}; | ||
var Miniflare = class extends MiniflareCore { | ||
var Miniflare = class extends import_core.MiniflareCore { | ||
#storageFactory; | ||
constructor(options) { | ||
if (options?.sourceMap) { | ||
sourceMap.install({ emptyCacheBetweenOperations: true }); | ||
import_source_map_support.default.install({ emptyCacheBetweenOperations: true }); | ||
} | ||
const storageFactory = new VariedStorageFactory(); | ||
super(PLUGINS, { | ||
log: options?.log ?? new NoOpLog(), | ||
log: options?.log ?? new import_shared2.NoOpLog(), | ||
storageFactory, | ||
scriptRunner: new VMScriptRunner(), | ||
scriptRunner: new import_runner_vm.VMScriptRunner(), | ||
scriptRequired: true | ||
@@ -123,16 +153,30 @@ }, options); | ||
createServer(options) { | ||
return createServer(this, options); | ||
return (0, import_http_server.createServer)(this, options); | ||
} | ||
startServer(options) { | ||
return startServer(this, options); | ||
return (0, import_http_server.startServer)(this, options); | ||
} | ||
startScheduler() { | ||
return startScheduler(this); | ||
return (0, import_scheduler.startScheduler)(this); | ||
} | ||
async getOpenURL() { | ||
const { | ||
open, | ||
httpsEnabled, | ||
host = "localhost", | ||
port = import_http_server.DEFAULT_PORT | ||
} = (await this.getPlugins()).HTTPPlugin; | ||
if (!open) | ||
return; | ||
if (typeof open === "string") | ||
return open; | ||
const protocol = httpsEnabled ? "https" : "http"; | ||
return `${protocol}://${host}:${port}/`; | ||
} | ||
}; | ||
// packages/miniflare/src/updater.ts | ||
import fs from "fs/promises"; | ||
import semiver from "semiver"; | ||
import { fetch } from "undici"; | ||
var import_promises = __toModule(require("fs/promises")); | ||
var import_semiver = __toModule(require("semiver")); | ||
var import_undici = __toModule(require("undici")); | ||
var numericCompare = new Intl.Collator(void 0, { numeric: true }).compare; | ||
@@ -148,3 +192,3 @@ async function updateCheck({ | ||
try { | ||
lastCheck = parseInt(await fs.readFile(lastCheckFile, "utf8")); | ||
lastCheck = parseInt(await import_promises.default.readFile(lastCheckFile, "utf8")); | ||
} catch { | ||
@@ -154,3 +198,3 @@ } | ||
return; | ||
const res = await fetch(`${registry}${pkg.name}/latest`, { | ||
const res = await (0, import_undici.fetch)(`${registry}${pkg.name}/latest`, { | ||
headers: { Accept: "application/json" } | ||
@@ -161,4 +205,4 @@ }); | ||
return; | ||
await fs.writeFile(lastCheckFile, now.toString(), "utf8"); | ||
if (semiver(registryVersion, pkg.version) > 0) { | ||
await import_promises.default.writeFile(lastCheckFile, now.toString(), "utf8"); | ||
if ((0, import_semiver.default)(registryVersion, pkg.version) > 0) { | ||
log.warn(`Miniflare ${registryVersion} is available, but you're using ${pkg.version}. Update for improved compatibility with Cloudflare Workers.`); | ||
@@ -174,5 +218,6 @@ const registryMajor = registryVersion.split(".")[0]; | ||
// packages/miniflare/src/index.ts | ||
import { Log as Log2, LogLevel } from "@miniflare/shared"; | ||
export { | ||
Log2 as Log, | ||
var import_shared3 = __toModule(require("@miniflare/shared")); | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
Log, | ||
LogLevel, | ||
@@ -183,3 +228,3 @@ Miniflare, | ||
updateCheck | ||
}; | ||
}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "miniflare", | ||
"version": "2.0.0-rc.3", | ||
"version": "2.0.0-rc.4", | ||
"description": "Fun, full-featured, fully-local simulator for Cloudflare Workers", | ||
@@ -14,3 +14,3 @@ "keywords": [ | ||
"license": "MIT", | ||
"type": "module", | ||
"main": "./dist/src/index.js", | ||
"exports": { | ||
@@ -50,17 +50,17 @@ ".": "./dist/src/index.js", | ||
"dependencies": { | ||
"@miniflare/cache": "2.0.0-rc.3", | ||
"@miniflare/cli-parser": "2.0.0-rc.3", | ||
"@miniflare/core": "2.0.0-rc.3", | ||
"@miniflare/durable-objects": "2.0.0-rc.3", | ||
"@miniflare/html-rewriter": "2.0.0-rc.3", | ||
"@miniflare/http-server": "2.0.0-rc.3", | ||
"@miniflare/kv": "2.0.0-rc.3", | ||
"@miniflare/runner-vm": "2.0.0-rc.3", | ||
"@miniflare/scheduler": "2.0.0-rc.3", | ||
"@miniflare/shared": "2.0.0-rc.3", | ||
"@miniflare/sites": "2.0.0-rc.3", | ||
"@miniflare/storage-file": "2.0.0-rc.3", | ||
"@miniflare/storage-memory": "2.0.0-rc.3", | ||
"@miniflare/watcher": "2.0.0-rc.3", | ||
"@miniflare/web-sockets": "2.0.0-rc.3", | ||
"@miniflare/cache": "2.0.0-rc.4", | ||
"@miniflare/cli-parser": "2.0.0-rc.4", | ||
"@miniflare/core": "2.0.0-rc.4", | ||
"@miniflare/durable-objects": "2.0.0-rc.4", | ||
"@miniflare/html-rewriter": "2.0.0-rc.4", | ||
"@miniflare/http-server": "2.0.0-rc.4", | ||
"@miniflare/kv": "2.0.0-rc.4", | ||
"@miniflare/runner-vm": "2.0.0-rc.4", | ||
"@miniflare/scheduler": "2.0.0-rc.4", | ||
"@miniflare/shared": "2.0.0-rc.4", | ||
"@miniflare/sites": "2.0.0-rc.4", | ||
"@miniflare/storage-file": "2.0.0-rc.4", | ||
"@miniflare/storage-memory": "2.0.0-rc.4", | ||
"@miniflare/watcher": "2.0.0-rc.4", | ||
"@miniflare/web-sockets": "2.0.0-rc.4", | ||
"kleur": "^4.1.4", | ||
@@ -72,7 +72,8 @@ "semiver": "^1.1.0", | ||
"devDependencies": { | ||
"@miniflare/shared-test": "2.0.0-rc.3", | ||
"@types/source-map-support": "^0.5.4" | ||
"@miniflare/shared-test": "2.0.0-rc.4", | ||
"@types/source-map-support": "^0.5.4", | ||
"open": "^8.4.0" | ||
}, | ||
"peerDependencies": { | ||
"@miniflare/storage-redis": "2.0.0-rc.3", | ||
"@miniflare/storage-redis": "2.0.0-rc.4", | ||
"cron-schedule": "^3.0.4", | ||
@@ -79,0 +80,0 @@ "ioredis": "^4.27.9" |
@@ -32,5 +32,5 @@ # ๐ฅ Miniflare | ||
[122 third-party packages](http://npm.anvaka.com/#/view/2d/miniflare) with a | ||
total install size of `88.3MB`. Miniflare 2 reduces this to **23 packages and | ||
`6.2MB`** ๐คฏ. | ||
3. โ **Correct:** Miniflare 2 more accurately replicates the quirks and thrown | ||
total install size of `88MB`. Miniflare 2 reduces this to **23 packages and | ||
`6MB`** ๐คฏ. | ||
3. โ **Accurate:** Miniflare 2 more accurately replicates the quirks and thrown | ||
errors of the real Workers runtime, so you'll know before you deploy if | ||
@@ -67,3 +67,3 @@ things are going to break. | ||
```shell | ||
```sh | ||
$ npm install -g miniflare@next # either globally.. | ||
@@ -75,3 +75,3 @@ $ npm install -D miniflare@next # ...or as a dev dependency | ||
```shell | ||
```sh | ||
$ miniflare worker.js --watch --debug | ||
@@ -78,0 +78,0 @@ [mf:dbg] Options: |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
50818
811
3
9
No
+ Added@miniflare/cache@2.0.0-rc.4(transitive)
+ Added@miniflare/cli-parser@2.0.0-rc.4(transitive)
+ Added@miniflare/core@2.0.0-rc.4(transitive)
+ Added@miniflare/durable-objects@2.0.0-rc.4(transitive)
+ Added@miniflare/html-rewriter@2.0.0-rc.4(transitive)
+ Added@miniflare/http-server@2.0.0-rc.4(transitive)
+ Added@miniflare/kv@2.0.0-rc.4(transitive)
+ Added@miniflare/runner-vm@2.0.0-rc.4(transitive)
+ Added@miniflare/scheduler@2.0.0-rc.4(transitive)
+ Added@miniflare/shared@2.0.0-rc.4(transitive)
+ Added@miniflare/sites@2.0.0-rc.4(transitive)
+ Added@miniflare/storage-file@2.0.0-rc.4(transitive)
+ Added@miniflare/storage-memory@2.0.0-rc.4(transitive)
+ Added@miniflare/storage-redis@2.0.0-rc.4(transitive)
+ Added@miniflare/watcher@2.0.0-rc.4(transitive)
+ Added@miniflare/web-sockets@2.0.0-rc.4(transitive)
- Removed@miniflare/cache@2.0.0-rc.3(transitive)
- Removed@miniflare/cli-parser@2.0.0-rc.3(transitive)
- Removed@miniflare/core@2.0.0-rc.3(transitive)
- Removed@miniflare/durable-objects@2.0.0-rc.3(transitive)
- Removed@miniflare/html-rewriter@2.0.0-rc.3(transitive)
- Removed@miniflare/http-server@2.0.0-rc.3(transitive)
- Removed@miniflare/kv@2.0.0-rc.3(transitive)
- Removed@miniflare/runner-vm@2.0.0-rc.3(transitive)
- Removed@miniflare/scheduler@2.0.0-rc.3(transitive)
- Removed@miniflare/shared@2.0.0-rc.3(transitive)
- Removed@miniflare/sites@2.0.0-rc.3(transitive)
- Removed@miniflare/storage-file@2.0.0-rc.3(transitive)
- Removed@miniflare/storage-memory@2.0.0-rc.3(transitive)
- Removed@miniflare/storage-redis@2.0.0-rc.3(transitive)
- Removed@miniflare/watcher@2.0.0-rc.3(transitive)
- Removed@miniflare/web-sockets@2.0.0-rc.3(transitive)
Updated@miniflare/cache@2.0.0-rc.4
Updated@miniflare/core@2.0.0-rc.4
Updated@miniflare/kv@2.0.0-rc.4
Updated@miniflare/shared@2.0.0-rc.4
Updated@miniflare/sites@2.0.0-rc.4