Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 8b7b00f

Browse files
committed
Add back sourceMap option
1 parent 3716316 commit 8b7b00f

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

packages/miniflare/src/api.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
import { Log, NoOpLog, Options } from "@miniflare/shared";
2626
import { SitesPlugin } from "@miniflare/sites";
2727
import { WebSocketPlugin } from "@miniflare/web-sockets";
28+
import sourceMap from "source-map-support";
2829
import { VariedStorageFactory } from "./storage";
2930

3031
// MiniflareCore will ensure CorePlugin is first and BindingsPlugin is last,
@@ -53,12 +54,20 @@ export type Plugins = typeof PLUGINS;
5354

5455
export type MiniflareOptions = Omit<Options<Plugins>, "debug" | "verbose"> & {
5556
log?: Log;
57+
sourceMap?: boolean;
5658
};
5759

5860
export class Miniflare extends MiniflareCore<Plugins> {
5961
#storageFactory: VariedStorageFactory;
6062

6163
constructor(options?: MiniflareOptions) {
64+
if (options?.sourceMap) {
65+
// Node has the --enable-source-maps flag, but this doesn't work for VM scripts.
66+
// It also doesn't expose a way of flushing the source map cache, which we need
67+
// so previous versions of worker code don't end up in stack traces.
68+
sourceMap.install({ emptyCacheBetweenOperations: true });
69+
}
70+
6271
const storageFactory = new VariedStorageFactory();
6372
super(
6473
PLUGINS,

packages/miniflare/src/cli.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,12 @@ import path from "path";
44
import { fileURLToPath } from "url";
55
import type { Options } from "@miniflare/shared";
66
import { red } from "kleur/colors";
7-
import sourceMap from "source-map-support";
8-
import { MiniflareOptions } from "./api";
7+
import type { MiniflareOptions } from "miniflare";
98
import { updateCheck } from "./updater";
109

1110
const __filename = fileURLToPath(import.meta.url);
1211
const __dirname = path.dirname(__filename);
1312

14-
// Node has the --enable-source-maps flag, but this doesn't work for VM scripts.
15-
// It also doesn't expose a way of flushing the source map cache, which we need
16-
// so previous versions of worker code don't end up in stack traces.
17-
sourceMap.install({ emptyCacheBetweenOperations: true });
18-
1913
function suppressWarnings() {
2014
// Suppress experimental warnings
2115
const originalEmitWarning = process.emitWarning;
@@ -84,6 +78,7 @@ async function main() {
8478
: LogLevel.INFO;
8579
const mfOptions: MiniflareOptions = options;
8680
mfOptions.log = new Log(logLevel);
81+
mfOptions.sourceMap = true;
8782
const mf = new Miniflare(mfOptions);
8883
try {
8984
// Start Miniflare development server

0 commit comments

Comments
 (0)