Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: resolve raw file bindings correctly in wrangler dev local mode #756

Merged
merged 1 commit into from
Apr 4, 2022

Conversation

threepointone
Copy link
Contributor

For wasm_modules/text_blobs/data_blobs in local mode, we need to rewrite the paths as absolute so that they're resolved correctly by miniflare. This also expands some coverage for local mode wrangler dev.

Fixes #740
Fixes #416

@changeset-bot
Copy link

changeset-bot bot commented Apr 4, 2022

🦋 Changeset detected

Latest commit: 46ff829

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
wrangler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Apr 4, 2022

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/runs/2089426666/npm-package-wrangler-756

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/756/npm-package-wrangler-756

Or you can use npx with this latest build directly:

npx https://prerelease-registry.developers.workers.dev/runs/2089426666/npm-package-wrangler-756 dev path/to/script.js

return new Response(
JSON.stringify(
{
// @ts-expect-error binding
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yurgh I should declare an env.d.ts later/soon

@threepointone threepointone force-pushed the fix-local-mode-binding-resolution branch from 5ceb295 to 3869d2c Compare April 4, 2022 08:16
packages/wrangler/src/dev/local.tsx Show resolved Hide resolved
Comment on lines 92 to 97
const wasmBindings = { ...bindings.wasm_modules };
for (const [name, filePath] of Object.entries(wasmBindings)) {
wasmBindings[name] = path.join(process.cwd(), filePath);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this results in copying over the properties twice. Once for the ...bindings.wasm_modules spread operation, and then again for the path mapping.
Could we just do it in one go?

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

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or am I missing something here?

If you are happy with this approach, then the same is true of the ones below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this is fine.

Copy link
Contributor Author

@threepointone threepointone left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lemme quickly make changes here

packages/wrangler/src/dev/local.tsx Show resolved Hide resolved
packages/wrangler/src/dev/local.tsx Show resolved Hide resolved
Comment on lines 92 to 97
const wasmBindings = { ...bindings.wasm_modules };
for (const [name, filePath] of Object.entries(wasmBindings)) {
wasmBindings[name] = path.join(process.cwd(), filePath);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this is fine.

@threepointone threepointone force-pushed the fix-local-mode-binding-resolution branch 2 times, most recently from 8853ba4 to 8a00710 Compare April 4, 2022 11:04
For `wasm_modules`/`text_blobs`/`data_blobs` in local mode, we need to rewrite the paths as absolute so that they're resolved correctly by miniflare. This also expands some coverage for local mode `wrangler dev`.

Fixes #740
Fixes #416
@threepointone threepointone force-pushed the fix-local-mode-binding-resolution branch from 8a00710 to 46ff829 Compare April 4, 2022 11:05
@threepointone threepointone merged commit 8e38442 into main Apr 4, 2022
@threepointone threepointone deleted the fix-local-mode-binding-resolution branch April 4, 2022 12:54
@github-actions github-actions bot mentioned this pull request Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants