Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

fix(netlify): replace global.crypto with crypto #163

Merged
merged 3 commits into from
Feb 26, 2024

Conversation

OiYouYeahYou
Copy link
Contributor

Changes

This is a drive by change because randomUUID is not on the global version of crypto on my node version (v18.18.2). I'm uncertain if this breaks any compatibility for others and do not have pnpm to run and commands.

Testing

Not testing done because this is a trivial change and don't have pnpm

Docs

Trivial change, probably should be noted in changelog

Copy link

changeset-bot bot commented Feb 9, 2024

🦋 Changeset detected

Latest commit: 14e01c2

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

This PR includes changesets to release 2 packages
Name Type
@astrojs/netlify Patch
@test/netlify-hosted-astro-project 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

@alexanderniebuhr
Copy link
Member

cc @Skn0tt, wdyt about this change?

@bluwy
Copy link
Member

bluwy commented Feb 12, 2024

In Astro, it does polyfill the global crypto object here. Does it fail for you? Or are you loading the netlify integration manually outside of Astro?

@Skn0tt
Copy link
Contributor

Skn0tt commented Feb 12, 2024

Looks fine to me!

I don't think the global crypto polyfill will work, because this is about usage within the build, not within the runtime. And we only put that polyfill in place for the runtime.

@bluwy
Copy link
Member

bluwy commented Feb 12, 2024

@Skn0tt
Copy link
Contributor

Skn0tt commented Feb 12, 2024

Interesting, didn't know that! So why is globalThis.crypto undefined for @OiYouYeahYou? 🤔

@OiYouYeahYou
Copy link
Contributor Author

So I've just tested in a docker (node:18-alpine) and node does not have it on globalThis. It is global in REPL, I assume as an enhancement like 'fs' et al is. So, I assume that the polyfill just doesn't have 100% coverage.

As Node 18 is still maintenance for another year, I still thing this is a valid change. But perhaps this is the wrong change to fix this problem.

I will highlight though, the other packages in this repo import crypto instead of using the global version

@lilnasy
Copy link
Contributor

lilnasy commented Feb 14, 2024

@OiYouYeahYou does it only happen with the astro add command?

withastro/astro#10105

@OiYouYeahYou
Copy link
Contributor Author

@lilnasy If I remember rightly, this was a blocker on npm run dev for me

@lilnasy
Copy link
Contributor

lilnasy commented Feb 14, 2024

I can only reproduce it with astro add and a few other commands (fixed by withastro/astro#10105), but the dev command seems to be correctly polyfilled. Do you think something else about your project could be involved?

image

Copy link
Contributor

@lilnasy lilnasy left a comment

Choose a reason for hiding this comment

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

Looks great to me!

The PR to astro will enable the use of crypto and File in the config file for new versions. This PR can help with compatibility with older versions.

Could you add a patch changeset with pnpm -w exec changeset? It will show up in CHANGELOG.md.

@alexanderniebuhr alexanderniebuhr changed the title Use crypto package instead of global.crypto fix(netlify): global.crypto undefined Feb 16, 2024
@alexanderniebuhr alexanderniebuhr changed the title fix(netlify): global.crypto undefined fix(netlify): replace global.crypto with crypto Feb 16, 2024
Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

Looks good to docs, but as mentioned in the comment, would love to be specific about version numbers if it's easy, but not a deal breaker!

(Especially if by chance it now works for some older versions, but not all of them, would be nice for people to know whether or not it should work for their version after this fix.)

"@astrojs/netlify": patch
---

Fixes an issue where using `global.crypto` failed for older Astro versions
Copy link
Member

Choose a reason for hiding this comment

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

Can we give a version number here to be more specific? Something like:

failed for Astro vx.x and earlier

(Assuming this fix works for all earlier Astro versions. Otherwise, specifying the range would be a nice addition.)

Copy link
Member

@alexanderniebuhr alexanderniebuhr Feb 17, 2024

Choose a reason for hiding this comment

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

@lilnasy do you know which versions this applies to? I guess: <4.4.1?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it was fixed in 4.4.1.

@lilnasy lilnasy merged commit bc9ee99 into withastro:main Feb 26, 2024
3 checks passed
@github-actions github-actions bot mentioned this pull request Feb 26, 2024
@OiYouYeahYou OiYouYeahYou deleted the fix-netlify-crypto branch April 19, 2024 15:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants