fix: remove `globalThis` check and align with what bundlers can accept (#4022)
As surfaced in
[Discord](https://discord.com/channels/625400653321076807/862957336082645006/1206980831915282532)
this currently is a breaking change in the 16.x.x release line which is
preventing folks from upgrading towards a security fix. This PR should
result in a patch release on the 16 release line.
This change was originally introduced to support CFW and browser
environments which should still be supported with the `typeof` check CC
@n1ru4l
This also adds a check whether `.env` is present as in the DOM using
`id="process"` defines that as a global which we don't want to access on
accident. as shown in https://github.com/graphql/graphql-js/pull/4017
Bundles also target `process.env.NODE_ENV` specifically which fails when
it replaces `globalThis.process.env.NODE_ENV` as this becomes
`globalThis."production"` which is invalid syntax.
Fixes https://github.com/graphql/graphql-js/issues/3978
Fixes https://github.com/graphql/graphql-js/issues/3918
Fixes https://github.com/graphql/graphql-js/issues/3928
Fixes https://github.com/graphql/graphql-js/issues/3758
Fixes https://github.com/graphql/graphql-js/issues/3934
This purposefully does not account for
https://github.com/graphql/graphql-js/issues/3925 as we can't address
this without breaking CF/plain browsers so the small byte-size increase
will be expected for bundled browser environments. As a middle ground we
did optimise the performance here. We can revisit this for v17.
Most bundlers will be able to tree-shake this with a little help, in
https://github.com/graphql/graphql-js/issues/4075#issuecomment-2094052098
you can find a conclusion with a repo where we discuss a few.
- Next.JS by default replaces
[`process.env.NODE_ENV`](https://github.com/vercel/next.js/blob/b0ab0fe85fe8c93792051b058e060724ff373cc2/packages/next/webpack.config.js#L182)
you can add `typeof process` linearly
- Vite allows you to specify
[`config.define`](https://vitejs.dev/config/shared-options.html#define)
- ESBuild by default will replace `process.env.NODE_ENV` but does not
support replacing `typeof process`
- Rollup has a plugin for this
https://www.npmjs.com/package/@rollup/plugin-replace
Supersedes https://github.com/graphql/graphql-js/pull/4021
Supersedes https://github.com/graphql/graphql-js/pull/4019
Supersedes https://github.com/graphql/graphql-js/pull/3927
> This now also adds a documentation page on how to remove all of these