Skip to content

Commit

Permalink
fix: resolve raw file bindings correctly in local mode
Browse files Browse the repository at this point in the history
For `wasm_modules`/`text_blobs`/`data_blobs` in local mode, we need to rewrite the paths so that they're ersolveds correctly by miniflare.

Fixes #740
Fixes #416
  • Loading branch information
threepointone committed Apr 4, 2022
1 parent b933641 commit d046b92
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion packages/wrangler/src/dev/local.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,29 @@ function useLocalWorker({

const scriptPath = realpathSync(bundle.path);

// the wasm_modules/text_blobs/data_blobs bindings are
// relative to process.cwd(), but the actual worker bundle
// is in the temp output directory; so we rewrite the paths to be absolute,
// letting miniflare resolve them correctly

// wasm
const wasmBindings = { ...bindings.wasm_modules };
for (const [name, filePath] of Object.entries(wasmBindings)) {
wasmBindings[name] = path.join(process.cwd(), filePath);
}

// text
const textBlobBindings = { ...bindings.text_blobs };
for (const [name, filePath] of Object.entries(textBlobBindings)) {
textBlobBindings[name] = path.join(process.cwd(), filePath);
}

// data
const dataBlobBindings = { ...bindings.data_blobs };
for (const [name, filePath] of Object.entries(dataBlobBindings)) {
dataBlobBindings[name] = path.join(process.cwd(), filePath);
}

if (format === "service-worker") {
for (const { type, name } of bundle.modules) {
if (type === "compiled-wasm") {
Expand Down Expand Up @@ -187,7 +207,7 @@ function useLocalWorker({
});

local.current.stdout?.on("data", (data: Buffer) => {
console.log(`${data.toString()}`);
process.stdout.write(data);
});

local.current.stderr?.on("data", (data: Buffer) => {
Expand Down

0 comments on commit d046b92

Please sign in to comment.