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

fix(rollup): replace globalThis.process. with process. #1360

Merged
merged 2 commits into from
Jun 30, 2023

Conversation

Hebilicious
Copy link
Member

@Hebilicious Hebilicious commented Jun 29, 2023

πŸ”— Linked issue

fix: #1346
fix: nuxt/nuxt#21768

see vite PR logic: vitejs/vite#12194

❓ Type of change

  • πŸ“– Documentation (updates to the documentation or readme)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

Some packages uses globalThis.process.env.NODE_ENV instead of process.env.NODE_ENV, which isn't supported by default by rollup. Vite supports this and so does Nuxt, so this changes brings the exact same feature to the rollup config for Nitro.

See issue in graphql-js

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@codecov
Copy link

codecov bot commented Jun 29, 2023

Codecov Report

Merging #1360 (682f85f) into main (414f5f5) will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main    #1360   +/-   ##
=======================================
  Coverage   76.58%   76.59%           
=======================================
  Files          71       71           
  Lines        7223     7224    +1     
  Branches      718      718           
=======================================
+ Hits         5532     5533    +1     
  Misses       1690     1690           
  Partials        1        1           
Impacted Files Coverage Ξ”
src/rollup/config.ts 90.74% <100.00%> (+0.01%) ⬆️

@Hebilicious
Copy link
Member Author

Hebilicious commented Jun 29, 2023

@pi0
There's a more elegant fix suggested by @phryneas, which would be to use the delimiters options from rollup replace plugin with this regex :

delimiters: ['(?<!\\.)\\b', '\\b(?!\\.)']

However, I'm not sure if that would introduce any breaking change. So maybe this could be done in another PR as a feat, and we could also extend the nitro config to allow custom options for maximum flexibility.

https://github.com/rollup/plugins/tree/master/packages/replace#delimiters

Note that I also opened an upstream issue with rollup directly rollup/plugins#1524

@phryneas
Copy link

This one might still be useful - my suggestion would only prevent foo.process.env.NODE_ENV to be replaced with foo."production" in general, but it won't replace the full term with "production".
It only prevents the bug (and future ones), it doesn't improve the behaviour.

@Hebilicious
Copy link
Member Author

This one might still be useful - my suggestion would only prevent foo.process.env.NODE_ENV to be replaced with foo."production" in general, but it won't replace the full term with "production". It only prevents the bug (and future ones), it doesn't improve the behaviour.

I tried the delimiters option alone, and it does fix this specific issue (ie globalThis.process.env.NODE_ENV gets transformed into "production").
I still think this fix is appropriate as we're sure that we don't break anything now, as technically changing the delimiters could break someone code who relies on this weird transform behaviour.

src/rollup/config.ts Outdated Show resolved Hide resolved
Co-authored-by: pooya parsa <pyapar@gmail.com>
@pi0 pi0 changed the title fix: replace globalThis.process.env.NODE_ENV fix(rollup): replace globalThis.process. with process. Jun 30, 2023
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

Thanks!

@pi0 pi0 merged commit 35e5ba2 into unjs:main Jun 30, 2023
6 of 7 checks passed
@pi0 pi0 mentioned this pull request Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nuxt cloudflare-pages deployment fails Nuxt cloudflare-pages deployment fails
3 participants