Skip to content

fix: simplify debug package resolution#10374

Merged
edmundhung merged 2 commits intomainfrom
edmundhung/simplify-debug-shim-setup
Aug 15, 2025
Merged

fix: simplify debug package resolution#10374
edmundhung merged 2 commits intomainfrom
edmundhung/simplify-debug-shim-setup

Conversation

@edmundhung
Copy link
Copy Markdown
Member

@edmundhung edmundhung commented Aug 14, 2025

Fixes n/a.


  • Tests
    • Tests included
    • Tests not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: no feature change
  • Wrangler V3 Backport
    • Wrangler PR:
    • Not necessary because: v4 only setup

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Aug 14, 2025

🦋 Changeset detected

Latest commit: 364995d

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

This PR includes changesets to release 4 packages
Name Type
@cloudflare/unenv-preset Patch
wrangler Patch
@cloudflare/vite-plugin 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

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Aug 14, 2025

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@10374

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@10374

miniflare

npm i https://pkg.pr.new/miniflare@10374

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@10374

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@10374

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@10374

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@10374

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@10374

wrangler

npm i https://pkg.pr.new/wrangler@10374

commit: 364995d

@edmundhung edmundhung force-pushed the edmundhung/simplify-debug-shim-setup branch from a33b6ef to 84848e2 Compare August 15, 2025 11:57
@edmundhung edmundhung changed the title fix: debug shim fix: simplify debug package resolution Aug 15, 2025
Comment on lines 206 to 244
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have moved these tests to the nodejs hybird app as it requires a different combination of compat date + nodejs_compat flag which doesn't quite fit the setup here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is the difference? I couldn't tell from looking at the Wrangler config files

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The wrangler.json next to the worker is actually irrelevant. The actual test setup is in packages/wrangler/e2e/unenv-preset/preset.test.ts that runs the worker script through a few different combinations of date / flags. But the debug package requires process.env to work properly which needs a compatibility_date after 2025-04-01 and I couldn't figure out a good way to fit this test in 😅

Comment on lines 7 to 23
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We don't use the custom build for the debug patch anymore so the build script is now simplified.

@edmundhung edmundhung marked this pull request as ready for review August 15, 2025 12:01
@edmundhung edmundhung requested a review from a team as a code owner August 15, 2025 12:01
@edmundhung edmundhung requested a review from a team August 15, 2025 12:01
@edmundhung edmundhung force-pushed the edmundhung/simplify-debug-shim-setup branch from 84848e2 to f6d7626 Compare August 15, 2025 12:05
@github-actions

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

@petebacondarwin petebacondarwin left a comment

Choose a reason for hiding this comment

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

I think this is OK except possibly for the Vite integration but perhaps that can be in a followup if there are things to do there?

Comment on lines +36 to +40
alias: {
// Force esbuild to use the node implementation of debug instead of unenv's no-op stub.
// The alias is processed by handleUnenvAliasedPackages which uses require.resolve().
debug: "debug",
},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What about Vite?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Turns out the vite plugin resolve the node implementation of debug correctly likely because it defines the module condition before browser. I have confirmed it manually as well.

Vite conditions: ["workerd", "worker", "module", "browser"]
Wrangler conditions: ["workerd", "worker", "browser"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we add a test?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added a test in 364995d

};

// Test different namespaces based on DEBUG env var: "example:*,test"
const testNamespace = debug("test"); // Should log (matches "test")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I was thrown by these being called "namespaces", when in my mind they are just debugLog functions...

Comment on lines 206 to 244
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What is the difference? I couldn't tell from looking at the Wrangler config files

@github-project-automation github-project-automation bot moved this from Untriaged to Approved in workers-sdk Aug 15, 2025
@edmundhung edmundhung merged commit 20520fa into main Aug 15, 2025
44 of 53 checks passed
@edmundhung edmundhung deleted the edmundhung/simplify-debug-shim-setup branch August 15, 2025 18:13
@github-project-automation github-project-automation bot moved this from Approved to Done in workers-sdk Aug 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants