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

refactor: use require.resolve and remove resolve dependency #6752

Closed
wants to merge 7 commits into from

Conversation

bluwy
Copy link
Contributor

@bluwy bluwy commented Sep 18, 2024

What this PR solves / how to test

Fixes N/A

It looks like we can simplify the resolve using require.resolve, similar to how other parts of the codebase that also does so:

return require.resolve(specifier, { paths: [referrer] });

// resolve with node resolution
path: require.resolve(aliasPath, {
// From the esbuild alias docs: "Note that when an import path is substituted using an alias, the resulting import path is resolved in the working directory instead of in the directory containing the source file with the import path."
// https://esbuild.github.io/api/#alias:~:text=Note%20that%20when%20an%20import%20path%20is%20substituted%20using%20an%20alias%2C%20the%20resulting%20import%20path%20is%20resolved%20in%20the%20working%20directory%20instead%20of%20in%20the%20directory%20containing%20the%20source%20file%20with%20the%20import%20path.
paths: [entry.directory],
}),

This allows the package to drop the resolve dependency, which isn't used anywhere else in the wrangler prod dependency graph.

Author has addressed the following

  • Tests
    • TODO (before merge)
    • Tests included
    • Tests not necessary because: refactors code
  • E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required
    • Not required because: refactors code
  • Changeset (Changeset guidelines)
    • TODO (before merge)
    • Changeset included
    • Changeset not necessary because:
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Documentation not necessary because: internal refactor

@bluwy bluwy requested a review from a team as a code owner September 18, 2024 18:00
Copy link

changeset-bot bot commented Sep 18, 2024

🦋 Changeset detected

Latest commit: 5935b3b

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

Copy link
Contributor

github-actions bot commented Nov 27, 2024

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/12157810991/npm-package-wrangler-6752

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

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

Or you can use npx with this latest build directly:

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

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.20241106.2
workerd 1.20241106.2 1.20241106.2
workerd --version 1.20241106.2 2024-11-06

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

@bluwy
Copy link
Contributor Author

bluwy commented Dec 4, 2024

I had to remove a test to fix the fail. Looks like it's because the test was importing a non-exported entrypoint here:

import otherMultiple from "import-wasm-static/wasm/not-exported.wasm";

It worked with the resolve package because it does not support the package "exports" field when resolving paths, but node (since v12.7.0) had supported that field when resolving, so it prevents accessing non-exported paths.

Technically it could be a breaking change that it now respects the "exports" field when resolving packages, but on the other hand, "exports" field had been supported by most tooling for many years now that it could be seen as a fix, but I'll leave y'all to decide. I don't mind closing this PR if we're not ready to change that yet.

@penalosa
Copy link
Contributor

penalosa commented Dec 4, 2024

@bluwy Thanks for this contribution! Given it requires removing a test I don't think we'd want to merge it as-is—we do want to preserve that test's behaviour, if possible

@bluwy
Copy link
Contributor Author

bluwy commented Dec 4, 2024

Alright I'll close this for now then, but I think it's something worth revisiting again in a breaking version to respect the "exports" field

@bluwy bluwy closed this Dec 4, 2024
@bluwy bluwy deleted the remove-resolve branch December 4, 2024 14:53
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.

3 participants