miniflare
Advanced tools
Comparing version 1.3.2 to 1.3.3
@@ -118,2 +118,6 @@ "use strict"; | ||
}, | ||
"disable-cache": { | ||
type: "boolean", | ||
description: "Disable caching with default/named caches", | ||
}, | ||
site: { | ||
@@ -203,2 +207,3 @@ type: "string", | ||
cachePersist: argv["cache-persist"], | ||
disableCache: argv["disable-cache"], | ||
sitePath: argv.site, | ||
@@ -267,3 +272,3 @@ siteInclude: asStringArray(argv["site-include"]), | ||
mf.getOptions() | ||
.then(async ({ host, port = defaultPort, processedHttps }) => { | ||
.then(async ({ host, port = defaultPort, processedHttps, disableUpdater }) => { | ||
const secure = processedHttps !== undefined; | ||
@@ -281,6 +286,6 @@ (await mf.createServer(secure)).listen(port, host, async () => { | ||
} | ||
if (options.disableUpdater) | ||
if (disableUpdater) | ||
return; | ||
try { | ||
const pkgFile = path_1.default.join(__dirname, "..", "..", "package.json"); | ||
const pkgFile = path_1.default.join(__dirname, "..", "package.json"); | ||
const pkg = JSON.parse(await fs_1.promises.readFile(pkgFile, "utf8")); | ||
@@ -290,3 +295,3 @@ const cachePath = env_paths_1.default(pkg.name).cache; | ||
} | ||
catch (_a) { } | ||
catch (e) { } | ||
}); | ||
@@ -293,0 +298,0 @@ }) |
@@ -12,3 +12,8 @@ import { Request, Response } from "@mrbbot/node-fetch"; | ||
} | ||
export declare class Cache { | ||
export interface CacheInterface { | ||
put(req: string | Request, res: Response): Promise<undefined>; | ||
match(req: string | Request, options?: CacheMatchOptions): Promise<Response | undefined>; | ||
delete(req: string | Request, options?: CacheMatchOptions): Promise<boolean>; | ||
} | ||
export declare class Cache implements CacheInterface { | ||
#private; | ||
@@ -20,1 +25,6 @@ constructor(storage: KVStorage, clock?: KVClock); | ||
} | ||
export declare class NoOpCache implements CacheInterface { | ||
put(_req: string | Request, _res: Response): Promise<undefined>; | ||
match(_req: string | Request, _options?: CacheMatchOptions): Promise<Response | undefined>; | ||
delete(_req: string | Request, _options?: CacheMatchOptions): Promise<boolean>; | ||
} |
"use strict"; | ||
var _Cache_storage, _Cache_clock, _Cache_namespace; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Cache = void 0; | ||
exports.NoOpCache = exports.Cache = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -97,2 +97,14 @@ const node_fetch_1 = require("@mrbbot/node-fetch"); | ||
_Cache_storage = new WeakMap(), _Cache_clock = new WeakMap(), _Cache_namespace = new WeakMap(); | ||
class NoOpCache { | ||
async put(_req, _res) { | ||
return; | ||
} | ||
async match(_req, _options) { | ||
return; | ||
} | ||
async delete(_req, _options) { | ||
return false; | ||
} | ||
} | ||
exports.NoOpCache = NoOpCache; | ||
//# sourceMappingURL=cache.js.map |
@@ -1,2 +0,2 @@ | ||
import { Cache } from "../kv"; | ||
import { Cache, NoOpCache } from "../kv"; | ||
import { KVStorageFactory } from "../kv/helpers"; | ||
@@ -13,1 +13,2 @@ import { Log } from "../log"; | ||
} | ||
export { Cache, NoOpCache }; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CacheModule = void 0; | ||
exports.NoOpCache = exports.Cache = exports.CacheModule = void 0; | ||
const tslib_1 = require("tslib"); | ||
@@ -8,2 +8,4 @@ const path_1 = tslib_1.__importDefault(require("path")); | ||
const kv_1 = require("../kv"); | ||
Object.defineProperty(exports, "Cache", { enumerable: true, get: function () { return kv_1.Cache; } }); | ||
Object.defineProperty(exports, "NoOpCache", { enumerable: true, get: function () { return kv_1.NoOpCache; } }); | ||
const helpers_1 = require("../kv/helpers"); | ||
@@ -13,2 +15,3 @@ const module_1 = require("./module"); | ||
const defaultCacheName = "default"; | ||
const noopCache = new kv_1.NoOpCache(); | ||
class CacheModule extends module_1.Module { | ||
@@ -23,3 +26,5 @@ constructor(log, storageFactory = new helpers_1.KVStorageFactory(defaultPersistRoot)) { | ||
buildSandbox(options) { | ||
const defaultCache = this.getCache(undefined, options.cachePersist); | ||
const defaultCache = options.disableCache | ||
? noopCache | ||
: this.getCache(undefined, options.cachePersist); | ||
return { | ||
@@ -32,3 +37,5 @@ caches: { | ||
} | ||
return this.getCache(name, options.cachePersist); | ||
return options.disableCache | ||
? noopCache | ||
: this.getCache(name, options.cachePersist); | ||
}, | ||
@@ -35,0 +42,0 @@ }, |
@@ -0,1 +1,2 @@ | ||
export { Cache, NoOpCache } from "./cache"; | ||
export { DurableObject } from "./do"; | ||
@@ -2,0 +3,0 @@ export { FetchEvent, ScheduledEvent, ResponseWaitUntil } from "./events"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.WebSocketPair = exports.WebSocket = exports.crypto = exports.btoa = exports.atob = exports.WritableStreamDefaultWriter = exports.WritableStreamDefaultController = exports.WritableStream = exports.TransformStreamDefaultController = exports.TransformStream = exports.ReadableStreamDefaultReader = exports.ReadableStreamDefaultController = exports.ReadableStreamBYOBRequest = exports.ReadableStreamBYOBReader = exports.ReadableStream = exports.ReadableByteStreamController = exports.CountQueuingStrategy = exports.ByteLengthQueuingStrategy = exports.Response = exports.Request = exports.FormData = exports.Headers = exports.TextEncoder = exports.TextDecoder = exports.URLSearchParams = exports.URL = exports.DocumentEnd = exports.Doctype = exports.TextChunk = exports.Comment = exports.Element = exports.HTMLRewriter = exports.ScheduledEvent = exports.FetchEvent = void 0; | ||
exports.WebSocketPair = exports.WebSocket = exports.crypto = exports.btoa = exports.atob = exports.WritableStreamDefaultWriter = exports.WritableStreamDefaultController = exports.WritableStream = exports.TransformStreamDefaultController = exports.TransformStream = exports.ReadableStreamDefaultReader = exports.ReadableStreamDefaultController = exports.ReadableStreamBYOBRequest = exports.ReadableStreamBYOBReader = exports.ReadableStream = exports.ReadableByteStreamController = exports.CountQueuingStrategy = exports.ByteLengthQueuingStrategy = exports.Response = exports.Request = exports.FormData = exports.Headers = exports.TextEncoder = exports.TextDecoder = exports.URLSearchParams = exports.URL = exports.DocumentEnd = exports.Doctype = exports.TextChunk = exports.Comment = exports.Element = exports.HTMLRewriter = exports.ScheduledEvent = exports.FetchEvent = exports.NoOpCache = exports.Cache = void 0; | ||
var cache_1 = require("./cache"); | ||
Object.defineProperty(exports, "Cache", { enumerable: true, get: function () { return cache_1.Cache; } }); | ||
Object.defineProperty(exports, "NoOpCache", { enumerable: true, get: function () { return cache_1.NoOpCache; } }); | ||
var events_1 = require("./events"); | ||
@@ -5,0 +8,0 @@ Object.defineProperty(exports, "FetchEvent", { enumerable: true, get: function () { return events_1.FetchEvent; } }); |
@@ -64,2 +64,3 @@ /// <reference types="node" /> | ||
cachePersist?: boolean | string; | ||
disableCache?: boolean; | ||
sitePath?: string; | ||
@@ -66,0 +67,0 @@ siteInclude?: string[]; |
@@ -40,2 +40,3 @@ "use strict"; | ||
"Cache Persistence": options.cachePersist, | ||
"Cache Disabled": options.disableCache, | ||
"Workers Site Path": options.sitePath, | ||
@@ -42,0 +43,0 @@ "Workers Site Include": options.siteIncludeRegexps, |
@@ -9,3 +9,3 @@ "use strict"; | ||
function getWranglerOptions(input, inputDir, env) { | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9; | ||
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11; | ||
const config = toml_1.default.parse(input); | ||
@@ -67,7 +67,8 @@ if (env && config.env && env in config.env) { | ||
cachePersist: (_1 = config.miniflare) === null || _1 === void 0 ? void 0 : _1.cache_persist, | ||
durableObjectsPersist: (_2 = config.miniflare) === null || _2 === void 0 ? void 0 : _2.durable_objects_persist, | ||
envPath: (_3 = config.miniflare) === null || _3 === void 0 ? void 0 : _3.env_path, | ||
host: (_4 = config.miniflare) === null || _4 === void 0 ? void 0 : _4.host, | ||
port: (_5 = config.miniflare) === null || _5 === void 0 ? void 0 : _5.port, | ||
https: typeof ((_6 = config.miniflare) === null || _6 === void 0 ? void 0 : _6.https) === "object" | ||
disableCache: (_2 = config.miniflare) === null || _2 === void 0 ? void 0 : _2.disable_cache, | ||
durableObjectsPersist: (_3 = config.miniflare) === null || _3 === void 0 ? void 0 : _3.durable_objects_persist, | ||
envPath: (_4 = config.miniflare) === null || _4 === void 0 ? void 0 : _4.env_path, | ||
host: (_5 = config.miniflare) === null || _5 === void 0 ? void 0 : _5.host, | ||
port: (_6 = config.miniflare) === null || _6 === void 0 ? void 0 : _6.port, | ||
https: typeof ((_7 = config.miniflare) === null || _7 === void 0 ? void 0 : _7.https) === "object" | ||
? { | ||
@@ -80,7 +81,8 @@ keyPath: config.miniflare.https.key, | ||
} | ||
: (_7 = config.miniflare) === null || _7 === void 0 ? void 0 : _7.https, | ||
wasmBindings: (_9 = (_8 = config.miniflare) === null || _8 === void 0 ? void 0 : _8.wasm_bindings) === null || _9 === void 0 ? void 0 : _9.reduce((bindings, { name, path }) => { | ||
: (_8 = config.miniflare) === null || _8 === void 0 ? void 0 : _8.https, | ||
wasmBindings: (_10 = (_9 = config.miniflare) === null || _9 === void 0 ? void 0 : _9.wasm_bindings) === null || _10 === void 0 ? void 0 : _10.reduce((bindings, { name, path }) => { | ||
bindings[name] = path; | ||
return bindings; | ||
}, {}), | ||
disableUpdater: (_11 = config.miniflare) === null || _11 === void 0 ? void 0 : _11.disable_updater, | ||
}; | ||
@@ -87,0 +89,0 @@ } |
{ | ||
"name": "miniflare", | ||
"version": "1.3.2", | ||
"version": "1.3.3", | ||
"description": "Fun, full-featured, fully-local simulator for Cloudflare Workers", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -102,2 +102,3 @@ # 🔥 Miniflare | ||
--cache-persist Path to persist cached data to (omit path for default) | ||
--disable-cache Disable caching with default/named caches [boolean] | ||
-s, --site Path to serve Workers Site files from [string] | ||
@@ -104,0 +105,0 @@ --site-include Glob pattern of site files to serve [array] |
@@ -125,2 +125,6 @@ import { promises as fs } from "fs"; | ||
}, | ||
"disable-cache": { | ||
type: "boolean", | ||
description: "Disable caching with default/named caches", | ||
}, | ||
site: { | ||
@@ -216,2 +220,3 @@ type: "string", | ||
cachePersist: argv["cache-persist"] as boolean | string | undefined, | ||
disableCache: argv["disable-cache"], | ||
sitePath: argv.site, | ||
@@ -304,27 +309,29 @@ siteInclude: asStringArray(argv["site-include"]), | ||
mf.getOptions() | ||
.then(async ({ host, port = defaultPort, processedHttps }) => { | ||
const secure = processedHttps !== undefined; | ||
(await mf.createServer(secure as any)).listen(port, host, async () => { | ||
const protocol = secure ? "https" : "http"; | ||
mf.log.info(`Listening on ${host ?? ""}:${port}`); | ||
if (host) { | ||
mf.log.info(`- ${protocol}://${host}:${port}`); | ||
} else { | ||
for (const accessibleHost of getAccessibleHosts(true)) { | ||
mf.log.info(`- ${protocol}://${accessibleHost}:${port}`); | ||
.then( | ||
async ({ host, port = defaultPort, processedHttps, disableUpdater }) => { | ||
const secure = processedHttps !== undefined; | ||
(await mf.createServer(secure as any)).listen(port, host, async () => { | ||
const protocol = secure ? "https" : "http"; | ||
mf.log.info(`Listening on ${host ?? ""}:${port}`); | ||
if (host) { | ||
mf.log.info(`- ${protocol}://${host}:${port}`); | ||
} else { | ||
for (const accessibleHost of getAccessibleHosts(true)) { | ||
mf.log.info(`- ${protocol}://${accessibleHost}:${port}`); | ||
} | ||
} | ||
} | ||
// Check for updates, ignoring errors (it's not that important) | ||
if (options.disableUpdater) return; | ||
try { | ||
// Get currently installed package metadata | ||
const pkgFile = path.join(__dirname, "..", "..", "package.json"); | ||
const pkg = JSON.parse(await fs.readFile(pkgFile, "utf8")); | ||
const cachePath = envPaths(pkg.name).cache; | ||
await updateCheck({ pkg, cachePath, log: mf.log }); | ||
} catch {} | ||
}); | ||
}) | ||
// Check for updates, ignoring errors (it's not that important) | ||
if (disableUpdater) return; | ||
try { | ||
// Get currently installed package metadata | ||
const pkgFile = path.join(__dirname, "..", "package.json"); | ||
const pkg = JSON.parse(await fs.readFile(pkgFile, "utf8")); | ||
const cachePath = envPaths(pkg.name).cache; | ||
await updateCheck({ pkg, cachePath, log: mf.log }); | ||
} catch (e) {} | ||
}); | ||
} | ||
) | ||
.catch((err) => mf.log.error(err)); | ||
} |
@@ -38,3 +38,12 @@ import { Headers, Request, Response } from "@mrbbot/node-fetch"; | ||
export class Cache { | ||
export interface CacheInterface { | ||
put(req: string | Request, res: Response): Promise<undefined>; | ||
match( | ||
req: string | Request, | ||
options?: CacheMatchOptions | ||
): Promise<Response | undefined>; | ||
delete(req: string | Request, options?: CacheMatchOptions): Promise<boolean>; | ||
} | ||
export class Cache implements CacheInterface { | ||
readonly #storage: KVStorage; | ||
@@ -153,1 +162,21 @@ readonly #clock: KVClock; | ||
} | ||
export class NoOpCache implements CacheInterface { | ||
async put(_req: string | Request, _res: Response): Promise<undefined> { | ||
return; | ||
} | ||
async match( | ||
_req: string | Request, | ||
_options?: CacheMatchOptions | ||
): Promise<Response | undefined> { | ||
return; | ||
} | ||
async delete( | ||
_req: string | Request, | ||
_options?: CacheMatchOptions | ||
): Promise<boolean> { | ||
return false; | ||
} | ||
} |
import path from "path"; | ||
import { MiniflareError } from "../error"; | ||
import { Cache } from "../kv"; | ||
import { Cache, NoOpCache } from "../kv"; | ||
import { KVStorageFactory } from "../kv/helpers"; | ||
@@ -12,2 +12,4 @@ import { Log } from "../log"; | ||
const noopCache = new NoOpCache(); | ||
export class CacheModule extends Module { | ||
@@ -26,3 +28,5 @@ constructor( | ||
buildSandbox(options: ProcessedOptions): Context { | ||
const defaultCache = this.getCache(undefined, options.cachePersist); | ||
const defaultCache = options.disableCache | ||
? noopCache | ||
: this.getCache(undefined, options.cachePersist); | ||
return { | ||
@@ -37,3 +41,5 @@ caches: { | ||
} | ||
return this.getCache(name, options.cachePersist); | ||
return options.disableCache | ||
? noopCache | ||
: this.getCache(name, options.cachePersist); | ||
}, | ||
@@ -48,1 +54,3 @@ }, | ||
} | ||
export { Cache, NoOpCache }; |
@@ -0,1 +1,2 @@ | ||
export { Cache, NoOpCache } from "./cache"; | ||
export { DurableObject } from "./do"; | ||
@@ -2,0 +3,0 @@ export { FetchEvent, ScheduledEvent, ResponseWaitUntil } from "./events"; |
@@ -86,2 +86,3 @@ import { networkInterfaces } from "os"; | ||
cachePersist?: boolean | string; | ||
disableCache?: boolean; | ||
@@ -144,2 +145,3 @@ sitePath?: string; | ||
"Cache Persistence": options.cachePersist, | ||
"Cache Disabled": options.disableCache, | ||
"Workers Site Path": options.sitePath, | ||
@@ -146,0 +148,0 @@ "Workers Site Include": options.siteIncludeRegexps, |
@@ -55,2 +55,3 @@ import assert from "assert"; | ||
cache_persist?: boolean | string; | ||
disable_cache?: boolean; | ||
durable_objects_persist?: boolean | string; | ||
@@ -71,2 +72,3 @@ env_path?: string; | ||
wasm_bindings?: { name: string; path: string }[]; | ||
disable_updater?: boolean; | ||
}; | ||
@@ -164,2 +166,3 @@ } | ||
cachePersist: config.miniflare?.cache_persist, | ||
disableCache: config.miniflare?.disable_cache, | ||
durableObjectsPersist: config.miniflare?.durable_objects_persist, | ||
@@ -186,3 +189,4 @@ envPath: config.miniflare?.env_path, | ||
), | ||
disableUpdater: config.miniflare?.disable_updater, | ||
}; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
462040
8560
134