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

Add support for Images bindings, with dynamic Sharp import #8008

Merged
merged 6 commits into from
Feb 5, 2025

Conversation

ns476
Copy link
Contributor

@ns476 ns476 commented Feb 3, 2025

Previous attempts:
#7424 - Reverted because of a missing permission in E2E tests
#7945 - Reverted because some platforms we support don't have Sharp available

These are both now fixed.

  • Tests
    • TODO (before merge)
    • Tests included
    • Tests not necessary because:
  • E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required
    • Not required because:
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Documentation not necessary because: In private beta for now, docs are being worked on

Copy link

changeset-bot bot commented Feb 3, 2025

🦋 Changeset detected

Latest commit: 62e8781

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

This PR includes changesets to release 2 packages
Name Type
wrangler Patch
@cloudflare/vitest-pool-workers 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

@workers-devprod workers-devprod added the e2e Run e2e tests on a PR label Feb 3, 2025
@ns476 ns476 marked this pull request as ready for review February 3, 2025 13:26
@ns476 ns476 requested review from a team as code owners February 3, 2025 13:26
@lrapoport-cf lrapoport-cf added the caretaking Priority for caretaking label Feb 3, 2025
Copy link
Contributor

github-actions bot commented Feb 3, 2025

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

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13139549549/npm-package-wrangler-8008

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

npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/prs/8008/npm-package-wrangler-8008

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13139549549/npm-package-wrangler-8008 dev path/to/script.js
Additional artifacts:

cloudflare-workers-bindings-extension:

wget https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13139549549/npm-package-cloudflare-workers-bindings-extension-8008 -O ./cloudflare-workers-bindings-extension.0.0.0-v3843da1d0.vsix && code --install-extension ./cloudflare-workers-bindings-extension.0.0.0-v3843da1d0.vsix

create-cloudflare:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13139549549/npm-package-create-cloudflare-8008 --no-auto-update

@cloudflare/kv-asset-handler:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13139549549/npm-package-cloudflare-kv-asset-handler-8008

miniflare:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13139549549/npm-package-miniflare-8008

@cloudflare/pages-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13139549549/npm-package-cloudflare-pages-shared-8008

@cloudflare/unenv-preset:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13139549549/npm-package-cloudflare-unenv-preset-8008

@cloudflare/vite-plugin:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13139549549/npm-package-cloudflare-vite-plugin-8008

@cloudflare/vitest-pool-workers:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13139549549/npm-package-cloudflare-vitest-pool-workers-8008

@cloudflare/workers-editor-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13139549549/npm-package-cloudflare-workers-editor-shared-8008

@cloudflare/workers-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13139549549/npm-package-cloudflare-workers-shared-8008

@cloudflare/workflows-shared:

npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13139549549/npm-package-cloudflare-workflows-shared-8008

Note that these links will no longer work once the GitHub Actions artifact expires.


[email protected] includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20250129.0
workerd 1.20250129.0 1.20250129.0
workerd --version 1.20250129.0 2025-01-29

Please ensure constraints are pinned, and miniflare/workerd minor versions match.

.changeset/ninety-donuts-warn.md Outdated Show resolved Hide resolved
packages/wrangler/src/dev/miniflare.ts Outdated Show resolved Hide resolved
packages/wrangler/src/images/local.ts Outdated Show resolved Hide resolved
@edmundhung
Copy link
Member

I have tested the prerelease version locally with node 16 and I can confirm the issue with sharp is gone:

With prerelease version:

> npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13112532233/npm-package-wrangler-8008 --help               
Need to install the following packages:
  https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/13112532233/npm-package-wrangler-8008
Ok to proceed? (y) 
npm WARN deprecated [email protected]: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.
npm WARN deprecated [email protected]: Please use @jridgewell/sourcemap-codec instead
wrangler

COMMANDS
  wrangler docs [search..]        📚 Open Wrangler's command documentation in your browser
  ...

With v3.107.1:

> npx [email protected] --help
Need to install the following packages:
  [email protected]
Ok to proceed? (y) 
npm WARN EBADENGINE Unsupported engine {
npm WARN EBADENGINE   package: '[email protected]',
npm WARN EBADENGINE   required: { node: '^18.17.0 || ^20.3.0 || >=21.0.0' },
npm WARN EBADENGINE   current: { node: 'v16.20.2', npm: '8.19.4' }
npm WARN EBADENGINE }
npm WARN deprecated [email protected]: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-inject.
npm WARN deprecated [email protected]: Please use @jridgewell/sourcemap-codec instead
npm WARN deprecated [email protected]: Please downgrade to v3.106.0
/Users/edmund/.npm/_npx/368e997908476be9/node_modules/sharp/lib/sharp.js:113
  throw new Error(help.join('\n'));
  ^

Error: Could not load the "sharp" module using the darwin-arm64 runtime
Possible solutions:
- Please upgrade Node.js:
    Found 16.20.2
    Requires ^18.17.0 || ^20.3.0 || >=21.0.0
- Consult the installation documentation:
    See https://sharp.pixelplumbing.com/install
    at Object.<anonymous> (/Users/edmund/.npm/_npx/368e997908476be9/node_modules/sharp/lib/sharp.js:113:9)
...

@edmundhung edmundhung self-requested a review February 3, 2025 19:46
@edmundhung
Copy link
Member

edmundhung commented Feb 4, 2025

@ns476 You should be able to fix the CI error by modifying packages/wrangler/src/__tests__/tsconfig.json and add "module": "CommonJS" to the compilerOptions.

@edmundhung
Copy link
Member

You might need to rebase main as we have just landed some changes that improves our test setup 👍🏼

ns476 and others added 6 commits February 4, 2025 15:53
* Add Images binding

* Add Images remote preview mode

* Plumb images local mode flag through

* Add Images binding local mode

* Add Images E2E test

* Hoist @img packages

This fixes the fixture tests, perhaps because sharp does something
unusual with imports, see GH comment: nuxt/image#1210 (comment)

* Add local suffix when printing bindings

* Swap describe/it in E2E test

* Mark sharp as unbundled, rather than hoisting

* Remove zod

* Improve error messages
We want everything that doesn't depend on sharp to work if it is
unavailable, so we need to import it dynamically.
Co-authored-by: Edmund Hung <[email protected]>
@ns476 ns476 force-pushed the ns476/dynamic-sharp-import branch from f5d256d to 62e8781 Compare February 4, 2025 15:59
Copy link
Contributor

@emily-shen emily-shen left a comment

Choose a reason for hiding this comment

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

I've also tested it in node 16 and 19, and wrangler dev seems to run fine.

Third time lucky!

@emily-shen emily-shen merged commit 9d08af8 into cloudflare:main Feb 5, 2025
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
caretaking Priority for caretaking e2e Run e2e tests on a PR
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants