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: second-cut of using unenv to create a hybrid node.js compatibility setting (via inject) #5878

Merged
merged 29 commits into from
Jun 6, 2024

Conversation

IgorMinar
Copy link
Contributor

@IgorMinar IgorMinar commented May 21, 2024

rebased version of https://github.com/cloudflare/workers-sdk/pull/5220/files which uses unenv's inject to introduce globals

Author has addressed the following

  • Tests
    • TODO (before merge)
    • Included - the update to the fixture tests this
    • Not necessary because:
  • E2E Tests CI Job required? (Use "e2e" label or ask maintainer to run separately)
    • I don't know
    • Required / Maybe required
    • Not required because: no e2e tests are affected by node-compat
  • Changeset (Changeset guidelines)
    • TODO (before merge)
    • Included
    • Not necessary because:
  • Public documentation
    • TODO (before merge)
    • Cloudflare docs PR(s):
    • Not necessary because: still experimental but we should follow up with a docs ticket.

@IgorMinar IgorMinar requested a review from a team as a code owner May 21, 2024 04:04
Copy link

changeset-bot bot commented May 21, 2024

🦋 Changeset detected

Latest commit: 8639e8b

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

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

gitguardian bot commented May 21, 2024

⚠️ GitGuardian has uncovered 2 secrets following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secrets in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
9963966 Triggered PostgreSQL Credentials 61cbf9d fixtures/nodejs-hybrid-app/wrangler.toml View secret
9963966 Triggered PostgreSQL Credentials 61cbf9d fixtures/nodejs-hybrid-app/worker-configuration.d.ts View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

@IgorMinar IgorMinar requested a review from petebacondarwin May 21, 2024 04:05
@IgorMinar
Copy link
Contributor Author

@petebacondarwin I rebased your PR but didn't want to force-push, so I'm creating a new PR. Let's chat tomorrow to discuss how we want to handle these PRs.

Copy link
Contributor

github-actions bot commented May 21, 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/9403675692/npm-package-wrangler-5878

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

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

Or you can use npx with this latest build directly:

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

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


wrangler@3.59.0 includes the following runtime dependencies:

Package Constraint Resolved
miniflare workspace:* 3.20240524.2
workerd 1.20240605.0 1.20240605.0
workerd --version 1.20240605.0 2024-06-05

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

@@ -78,7 +78,8 @@
"ink@3.2.0": "patches/ink@3.2.0.patch",
"toucan-js@3.2.2": "patches/toucan-js@3.2.2.patch",
"@cloudflare/component-listbox@1.10.6": "patches/@cloudflare__component-listbox@1.10.6.patch",
"capnp-ts@0.7.0": "patches/capnp-ts@0.7.0.patch"
"capnp-ts@0.7.0": "patches/capnp-ts@0.7.0.patch",
"pg@8.11.3": "patches/pg@8.11.3.patch"
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO: remove this once it is fixed upstream

@@ -82,6 +82,7 @@
"resolve.exports": "^2.0.2",
"selfsigned": "^2.0.1",
"source-map": "0.6.1",
"unenv": "npm:unenv-nightly@1.10.0-1717522572.87b9352",
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO: update when this is released

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah. but this won't happen until shortly before we drop the experimental: prefix.

packages/wrangler/src/deploy/deploy.ts Outdated Show resolved Hide resolved
packages/wrangler/src/deploy/deploy.ts Outdated Show resolved Hide resolved
packages/wrangler/src/deployment-bundle/bundle.ts Outdated Show resolved Hide resolved
packages/wrangler/src/deploy/deploy.ts Outdated Show resolved Hide resolved
Copy link
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.

Last small thing:

  • a changeset (with a minor bump) - or are we claiming that since this is internal/experimental it should not appear in the changelog? I don't feel we should try to hide it by doing that: users can see the code being added so it is not a secret, and also no changeset means that the package will not be published.

Copy link
Contributor

@RamIdeas RamIdeas left a comment

Choose a reason for hiding this comment

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

LGTM just needs the changeset before merge and Pete's comment above addressed

Copy link
Contributor Author

@IgorMinar IgorMinar left a comment

Choose a reason for hiding this comment

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

LGTM except for one regression that was introduced during the refactor. I didn't have enough time to debug it, but I discovered it in the matrix app and moved a reduction into the fixture as 0c2fc6d

somehow don't tell esbuild that node:assert is a built-in, so it freaks out when it's not resolved to an absolute path. did we somehow forget to configure externals?

fixtures/nodejs-hybrid-app/tests/index.test.ts Outdated Show resolved Hide resolved
petebacondarwin and others added 10 commits June 6, 2024 15:39
The previous test would pass/fail depending upon which timezone you are in when you run it.
currently this fails with:

nodejs-hybrid-app:build: ✘ [ERROR] Plugin "unenv-cloudflare" returned a non-absolute path: node:assert (set a namespace if this is not a file path)
nodejs-hybrid-app:build:
nodejs-hybrid-app:build:     src/index.ts:2:19:
nodejs-hybrid-app:build:       2 │ import assert from "node:assert/strict";
nodejs-hybrid-app:build:         ╵                    ~~~~~~~~~~~~~~~~~~~~
nodejs-hybrid-app:build:
This was problematic because if you import from `node:assert/strict` there is no entry in the `external` map for that path, instead you need to map it to its alias first (e.g. `node:assert`).
@petebacondarwin petebacondarwin force-pushed the unenv-wrangler-inject branch from 03fdb3a to 12b2b8e Compare June 6, 2024 14:39
@petebacondarwin petebacondarwin requested a review from RamIdeas June 6, 2024 14:45
Copy link
Contributor

@RamIdeas RamIdeas left a comment

Choose a reason for hiding this comment

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

You managed to add this extra compat flag and make the codebase cleaner 👏

@petebacondarwin
Copy link
Contributor

I'm going to override the GitGuardian check failure because it is picking up a DB secret that is actually a publicly accessible DB - so a false positive.

@petebacondarwin petebacondarwin added the e2e Run e2e tests on a PR label Jun 6, 2024
fixtures/nodejs-hybrid-app/src/index.ts Show resolved Hide resolved
fixtures/nodejs-hybrid-app/wrangler.toml Show resolved Hide resolved
packages/wrangler/package.json Show resolved Hide resolved
compatibilityFlags.includes("nodejs_compat_v2");

if (nodejsCompatV2) {
// strip the "experimental:" prefix because workerd doesn't understand it yet.
Copy link
Contributor

Choose a reason for hiding this comment

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

Given the flag is no longer experimental in workerd, do we want to keep this prefix stripping?

Copy link
Contributor

Choose a reason for hiding this comment

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

No we still want to require users of Wrangler to add this - it was orthogonal to workerd's experimental constraints - and is left here to avoid people trying to use this for production while we stabilize it.

@petebacondarwin petebacondarwin merged commit 1e68fe5 into main Jun 6, 2024
23 of 24 checks passed
@petebacondarwin petebacondarwin deleted the unenv-wrangler-inject branch June 6, 2024 16:38
@workers-devprod workers-devprod mentioned this pull request Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
e2e Run e2e tests on a PR
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants