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

feat: add support for custom unenv preset path #7522

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

vicb
Copy link
Contributor

@vicb vicb commented Dec 11, 2024

We are moving the unenv preset to this repo.

We will need to be able to test the version that is package with wrangler as well as the dev version. We can do that by passing the path to the dev version in the added env var.

/cc @pi0


  • Tests
    • TODO (before merge)
    • Tests included
    • Tests not necessary because: tested locally
  • 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: internal use

Introduce `WRANGLER_UNENV_PRESET_PATH` to 
specify a custom root path for the unenv preset.
@vicb vicb requested a review from a team as a code owner December 11, 2024 15:24
Copy link

changeset-bot bot commented Dec 11, 2024

🦋 Changeset detected

Latest commit: 5a39e9e

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

This PR includes changesets to release 2 packages
Name Type
wrangler Minor
@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

@vicb vicb requested a review from petebacondarwin December 11, 2024 15:25
Copy link
Contributor

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/12279501204/npm-package-wrangler-7522

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

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

Or you can use npx with this latest build directly:

npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12279501204/npm-package-wrangler-7522 dev path/to/script.js
Additional artifacts:
npx https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12279501204/npm-package-create-cloudflare-7522 --no-auto-update
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12279501204/npm-package-cloudflare-kv-asset-handler-7522
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12279501204/npm-package-miniflare-7522
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12279501204/npm-package-cloudflare-pages-shared-7522
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12279501204/npm-package-cloudflare-vitest-pool-workers-7522
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12279501204/npm-package-cloudflare-workers-editor-shared-7522
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12279501204/npm-package-cloudflare-workers-shared-7522
npm install https://prerelease-registry.devprod.cloudflare.dev/workers-sdk/runs/12279501204/npm-package-cloudflare-workflows-shared-7522

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.20241205.0
workerd 1.20241205.0 1.20241205.0
workerd --version 1.20241205.0 2024-12-05

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

) {
// esbuild expects alias paths to be absolute
const aliasAbsolute: Record<string, string> = {};
for (const [module, unresolvedAlias] of Object.entries(alias)) {
try {
const paths = unenvPresetPath ? [unenvPresetPath] : undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just call

const unenvPresetPath = getUnenvPresetPathFromEnv();

here and avoid having to thread it through the code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My thinking was that ultimately we want the plugin to live in the preset package.
WDYT?

Copy link

@pi0 pi0 Dec 11, 2024

Choose a reason for hiding this comment

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

(quick call with Vic, we might eventually move the plugin to unenv core as part of unjs/unenv#263 -- this unifies impl between nitro and wrangler as a bonus) + working on a quick feature in unenv to support alias resolution.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I follow here.
If we move this to the preset (or even to unenv core) then this unenvPresetPath would be moot, right? So we'd need to redo this code then anyway.
In that case just loading the env var where it is needed is simplest and touches the least code.

Copy link

@pi0 pi0 Dec 11, 2024

Choose a reason for hiding this comment

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

So there are two things:

  • To move wrangler PRs forward add a feature to unenv core to allow full path resolves
  • In the future, to move the plugin stuff as an unplugin

Copy link
Contributor

Choose a reason for hiding this comment

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

Does that affect my original comment to move the reading of the environment variable into this code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we move this to the preset (or even to unenv core) then this unenvPresetPath would be moot, right?

It would only be a different path but same code.

In that case just loading the env var where it is needed is simplest and touches the least code.
Does that affect my original comment to move the reading of the environment variable into this code?

In general I find injecting values cleaner.
i.e. in this case if we have an hardcoded WRANGLER_... name, we would have to change that if we move the plugin. Injecting the value is more flexible (i.e. the first point above).

Copy link

@pi0 pi0 Dec 11, 2024

Choose a reason for hiding this comment

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

Oh sorry, if you meant to just move it out yes it makes sense.

(my point was that, we are moving resolution logic out shortly after unjs/unenv#372 lands!)

@vicb vicb marked this pull request as draft December 11, 2024 17:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

3 participants