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

codemod(v6): Convert all process.env usage to dot notation #8611

Merged
merged 4 commits into from
Jun 15, 2023

Conversation

dac09
Copy link
Collaborator

@dac09 dac09 commented Jun 14, 2023

Process Env Dot Notation

Finds all cases where process.env is accessed via array notation (specifically string literals), and converts it to dot notation.

- process.env['BAZINGA']
+ process.env.BAZINGA

NOTE - this does not deal with dynamic access case. This is something users will need to do themselves

Linting rule for this: #8612


  • Webpack support array notation for both dev and prod
    image
    image

  • Only basic strings work in production. You can't have expressions
    image
    image

  • In Webpack, if you try to access process.env you'll get "MISSING_ENV_VAR" back. But if you try to access an env var that doesn't exist you get undefined (same behavior in both dev and prod)
    image
    image

  • Sometimes you might want to use array notation for tests, like we do in the framework here (it's got red squiggles because I've got our new eslint rule for this set to report it as an error)
    image

@dac09 dac09 added the release:chore This PR is a chore (means nothing for users) label Jun 14, 2023
@dac09 dac09 added this to the v6.0.0 milestone Jun 14, 2023
@dac09 dac09 requested a review from Tobbe June 14, 2023 09:28
@dac09 dac09 force-pushed the codemod/process-env-static-access branch from 05f35cc to 0d78ff2 Compare June 14, 2023 09:31
@dac09 dac09 enabled auto-merge (squash) June 15, 2023 10:51
@dac09 dac09 merged commit 2d10c6e into main Jun 15, 2023
28 checks passed
@dac09 dac09 deleted the codemod/process-env-static-access branch June 15, 2023 11:27
@redwoodjs-bot redwoodjs-bot bot modified the milestones: v6.0.0, next-release Jun 15, 2023
@jtoar jtoar modified the milestones: next-release, v6.0.0 Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release:chore This PR is a chore (means nothing for users)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants