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(vitest-pool-workers): enable dependency pre-bundling #7810

Merged
merged 6 commits into from
Feb 11, 2025

Conversation

edmundhung
Copy link
Member

@edmundhung edmundhung commented Jan 17, 2025

Fixes #5672.

This PR adds Vite dependency pre-bundling support. If you see module resolution issues—such as: Error: Cannot use require() to import an ES Module or Error: No such module—you can now bundle these dependencies using the deps.optimizer option:

import { defineWorkersConfig } from "@cloudflare/vitest-pool-workers/config";

export default defineWorkersConfig({
    test: {
        deps: {
            optimizer: {
                ssr: {
                    enabled: true,
                    include: ["your-package-name"],
                },
            },
        },
        poolOptions: {
            workers: {
                // ...
            },
        },
    },
});

This is tested against #6591, #6581 & #6405.


Copy link
Contributor

github-actions bot commented Jan 17, 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/13267584468/npm-package-wrangler-7810

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

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

Or you can use npx with this latest build directly:

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

cloudflare-workers-bindings-extension:

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

create-cloudflare:

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

@cloudflare/kv-asset-handler:

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

miniflare:

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

@cloudflare/pages-shared:

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

@cloudflare/unenv-preset:

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

@cloudflare/vite-plugin:

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

@cloudflare/vitest-pool-workers:

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

@cloudflare/workers-editor-shared:

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

@cloudflare/workers-shared:

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

@cloudflare/workflows-shared:

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

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.20250204.0
workerd 1.20250204.0 1.20250204.0
workerd --version 1.20250204.0 2025-02-04

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

Copy link

changeset-bot bot commented Jan 17, 2025

🦋 Changeset detected

Latest commit: c88e19b

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

This PR includes changesets to release 1 package
Name Type
@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

@edmundhung edmundhung force-pushed the edmundhung/vitest-pre-bundling branch 2 times, most recently from d386b79 to 87c26db Compare February 6, 2025 17:52
@edmundhung edmundhung marked this pull request as ready for review February 6, 2025 20:51
@edmundhung edmundhung requested a review from a team as a code owner February 6, 2025 20:51
@penalosa
Copy link
Contributor

penalosa commented Feb 6, 2025

I think this should probably have some docs added to the testing section, calling out the problem and solution?

What about doing this automatically for e.g. all packages in package.json?

@edmundhung
Copy link
Member Author

I think this should probably have some docs added to the testing section, calling out the problem and solution?

How about updating the recipes page and add a link to the external-package-resolution example that I updated in this PR? We can add some guideline either as a README in that folder or on the recipes page.

What about doing this automatically for e.g. all packages in package.json?

I am not sure. The vite/vitest team seems to have concern about the performance if all dependencies are pre-bundled. It might increase the start-up time quite a bit 🤔

@penalosa
Copy link
Contributor

penalosa commented Feb 7, 2025

How about updating the recipes page and add a link to the external-package-resolution example that I updated in this PR? We can add some guideline either as a README in that folder or on the recipes page.

Sounds good! Maybe also a callout on the https://developers.cloudflare.com/workers/testing/vitest-integration/known-issues/ page?

I am not sure. The vite/vitest team seems to have concern about the performance if all dependencies are pre-bundled. It might increase the start-up time quite a bit 🤔

Fair enough—and just to double check (I know we've talked about this in the past), there's no way to discover which dependencies to pre-bundle automatically?

@edmundhung
Copy link
Member Author

edmundhung commented Feb 7, 2025

Maybe also a callout on the https://developers.cloudflare.com/workers/testing/vitest-integration/known-issues/ page?

👍🏼

just to double check (I know we've talked about this in the past), there's no way to discover which dependencies to pre-bundle automatically?

Not that I know of. But it might be worth updating the error message in the module fallback service to suggest people enabling pre-bundling. Wdyt?

@penalosa
Copy link
Contributor

penalosa commented Feb 7, 2025

Not that I know of. But it might be worth updating the error message in the module fallback service to suggest people enabling pre-bundling. Wdyt?

That's a great idea!

@edmundhung edmundhung force-pushed the edmundhung/vitest-pre-bundling branch 2 times, most recently from f40257c to b73d6cf Compare February 7, 2025 13:11
@edmundhung edmundhung changed the title fix(vitest-pool-workers): pre-bundling dependencies fix(vitest-pool-workers): enable dependency pre-bundling Feb 7, 2025
@edmundhung edmundhung force-pushed the edmundhung/vitest-pre-bundling branch from 66e4047 to 43ba7a9 Compare February 10, 2025 12:10
@edmundhung edmundhung force-pushed the edmundhung/vitest-pre-bundling branch from c4de8ac to c88e19b Compare February 11, 2025 11:52
@edmundhung edmundhung force-pushed the edmundhung/vitest-pre-bundling branch from c88e19b to 4d4a05c Compare February 11, 2025 16:23
@edmundhung edmundhung merged commit ac4f30b into main Feb 11, 2025
27 checks passed
@edmundhung edmundhung deleted the edmundhung/vitest-pre-bundling branch February 11, 2025 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

🐛 BUG: support Vitest deps.optimizer
2 participants