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

new __DEV__ handling #10915

Merged
merged 16 commits into from
Jul 6, 2023
Merged

new __DEV__ handling #10915

merged 16 commits into from
Jul 6, 2023

Conversation

phryneas
Copy link
Member

@phryneas phryneas commented May 26, 2023

reverts #10521 (Simplify DEV polyfill to use imports instead of global scope)

more changes to come here, I just want to have a CI build already

Checklist:

  • If this PR contains changes to the library itself (not necessary for e.g. docs updates), please include a changeset (see CONTRIBUTING.md)
  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

On handling of process.env.NODE_ENV or __DEV__

I am trying to find a way here that doesn't crash, doesn't need us to globally polyfill process.env.NODE_ENV or __DEV__,
and still can be tree-shaken away in production builds.

Since we cannot assume that one of those values is always defined, we would want the "undefined" case to be handles as if __DEV__ was true.

Problems

process.env.NODE_ENV or __DEV__ are not defined in the browser

This is our baseline problem - a bundle with a naive check for either of those can be handled very gracefully by the bundler,
but will crash in-browser ESM imports.

Bundlers are stupid

Usually, bundlers rely on plain string replacement to replace process.env.NODE_ENV or __DEV__ with a primitive value.

That means that in the case of process.env.NODE_ENV, the bundler will replace process.env.NODE_ENV with "production"
or "development" - but it will not fill in for process or process.env.
So the bundler could not statically analyze "resilient" code like typeof process !== "undefined" && process.env.NODE_ENV === "development".

In the case of __DEV__, things become a bit easier since we don't have to check for process or process.env - simply replacing __DEV__ in
the statement typeof __DEV__ == "undefined" || __DEV__ will for example result in typeof false == "undefined" || false.

Now, it depends on what the bundler does with typeof false == "undefined".
Unfortunately, most bundlers will handle this as non-evaluated runtime statement. In that case, it could not tree-shake.

We could now try to let the bundler replace typeof __DEV__ with "undefined" - but not all bundlers allow for string replacement on that level. (esbuild has no option for this)

Defeating it just with logic

Finding a logical statement that, naively replaced by the bundler, can eliminate the typeof would work if we would only go for __DEV__ === true, but not for __DEV__ === true || __DEV__ === undefined - in the latter case, there will always be some "runtime-type" statement left that the bundler cannot eliminate.

Getting rid of the typeof

This is the strategy I'm settling on now: If we can get rid of the typeof, we get something that can always be replaced by bundlers.

My current approach for that is to use globalThis.__DEV__ - this will not by default be replaced by most bundlers, but at least they can be configured to be replaced.

The logical statement I've ended up is globalThis.__DEV__ !== false.

In the wild

Tool Can replace
esbuild
{
  "define": {
    "globalThis.__DEV__": "false"
  }
}
webpack
config.plugins.push(
  new webpack.DefinePlugin({
    "globalThis.__DEV__": false,
  })
);
rollup
{
  "global_defs": {
    "@globalThis.__DEV__": "false"
  }
}
swc

.swcrc:

{
  "jsc": {
    "transform": {
      "optimizer": {
        "globals": {
          "vars": {
            "globalThis.__DEV__": "false"
          }
        }
      }
    }
  }
}
nextjs

next.config.js:

/** @type {import('next').NextConfig} */
const nextConfig = {
  webpack(config, { webpack }) {
    config.plugins.push(
      new webpack.DefinePlugin({
        "globalThis.__DEV__": false,
      })
    );
    return config;
  },
};

module.exports = nextConfig;
vite

vite.config.ts

// ...
export default defineConfig({
  // ...
  define: {
    "globalThis.__DEV__": JSON.stringify(false),
  },
});
create-react-app

using craco

craco.config.js

const webpack = require("webpack");
module.exports = {
  webpack: {
    plugins: [
      new webpack.DefinePlugin({
        "globalThis.__DEV__": false,
      }),
    ],
  },
};
using a CDN

See this later comment for more detail

@changeset-bot
Copy link

changeset-bot bot commented May 26, 2023

🦋 Changeset detected

Latest commit: 03ff6c4

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

This PR includes changesets to release 1 package
Name Type
@apollo/client Minor

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

@phryneas phryneas changed the base branch from main to release-3.8 May 26, 2023 12:40
@phryneas phryneas changed the base branch from release-3.8 to pr/error-extraction May 26, 2023 12:40
@phryneas
Copy link
Member Author

/release:pr

@github-actions
Copy link
Contributor

Please add a changeset via npx changeset before attempting a snapshot release.

@netlify
Copy link

netlify bot commented May 26, 2023

Deploy Preview for apollo-client-docs ready!

Name Link
🔨 Latest commit 04c59a4
🔍 Latest deploy log https://app.netlify.com/sites/apollo-client-docs/deploys/6470a88ef4b65b0008c53bc7
😎 Deploy Preview https://deploy-preview-10915--apollo-client-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@phryneas
Copy link
Member Author

/release:pr

@github-actions
Copy link
Contributor

A new release has been made for this PR. You can install it with npm i @apollo/[email protected].

@github-actions
Copy link
Contributor

github-actions bot commented May 26, 2023

size-limit report 📦

Path Size
dist/apollo-client.min.cjs 36.99 KB (-0.13% 🔽)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" 43.56 KB (-0.19% 🔽)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" 32.57 KB (-0.18% 🔽)
import { ApolloProvider } from "dist/react/index.js" 1.23 KB (-5.68% 🔽)
import { useQuery } from "dist/react/index.js" 4.27 KB (-1.78% 🔽)
import { useLazyQuery } from "dist/react/index.js" 4.59 KB (-1.56% 🔽)
import { useMutation } from "dist/react/index.js" 2.5 KB (-2.66% 🔽)
import { useSubscription } from "dist/react/index.js" 2.24 KB (-3.33% 🔽)
import { useSuspenseQuery } from "dist/react/index.js" 3.64 KB (-1.61% 🔽)
import { useBackgroundQuery } from "dist/react/index.js" 3.84 KB (-1.7% 🔽)
import { useReadQuery } from "dist/react/index.js" 2.56 KB (-2.93% 🔽)
import { useFragment } from "dist/react/index.js" 2.05 KB (-3.55% 🔽)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/main.cjs" (production) 42.18 KB (+100% 🔺)
import { ApolloClient, InMemoryCache, HttpLink } from "dist/index.js" (production) 31.43 KB (+100% 🔺)
import { ApolloProvider } from "dist/react/index.js" (production) 1.22 KB (+100% 🔺)
import { useQuery } from "dist/react/index.js" (production) 4.09 KB (+100% 🔺)
import { useLazyQuery } from "dist/react/index.js" (production) 4.4 KB (+100% 🔺)
import { useMutation } from "dist/react/index.js" (production) 2.49 KB (+100% 🔺)
import { useSubscription } from "dist/react/index.js" (production) 2.2 KB (+100% 🔺)
import { useSuspenseQuery } from "dist/react/index.js" (production) 3.05 KB (+100% 🔺)
import { useBackgroundQuery } from "dist/react/index.js" (production) 3.28 KB (+100% 🔺)
import { useReadQuery } from "dist/react/index.js" (production) 2.54 KB (+100% 🔺)
import { useFragment } from "dist/react/index.js" (production) 2 KB (+100% 🔺)

Base automatically changed from pr/error-extraction to release-3.8 May 26, 2023 15:57
@phryneas phryneas self-assigned this Jun 13, 2023
@phryneas
Copy link
Member Author

/release:pr

@github-actions
Copy link
Contributor

A new release has been made for this PR. You can install it with npm i @apollo/[email protected].

@phryneas
Copy link
Member Author

/release:pr

@github-actions
Copy link
Contributor

A new release has been made for this PR. You can install it with npm i @apollo/[email protected].

@phryneas
Copy link
Member Author

phryneas commented Jun 16, 2023

So the good news is that even removing that NODE_ENV workaround for graphql just works in ESM environments. I've tried this in three different configurations now.

jsdeliver and jspm mangle the packages in a way that they strip out NODE_ENV completely. And even importing the unmangled packages from unpkg just works - it seems that we just never reference any code that uses that code path? 🤔

Uploaded test files are here:

Unfortunately, the server will run into CORS problems, so for more testing you'll have to download them and run them from localhost, by starting a server like npx http-server.

The question is if it also works in all the other envs...

@phryneas
Copy link
Member Author

For now, I will remove the graphql process workaround with this PR, as it doesn't make any sense with the current state. We will have to monitor the graphql package and can either leave it out or will have to reintroduce #10993

@phryneas
Copy link
Member Author

Here is a diff of all built files:

differences in *.js files

28 files with differences

./core/ObservableQuery.js
2c2
< import { invariant, __DEV__ } from "../utilities/globals/index.js";
---
> import { invariant } from "../utilities/globals/index.js";
120c120
<             if (__DEV__ &&
---
>             if (globalThis.__DEV__ !== false &&
180c180
<         if (__DEV__ && variables && hasOwnProperty.call(variables, "variables")) {
---
>         if (globalThis.__DEV__ !== false && variables && hasOwnProperty.call(variables, "variables")) {
184c184
<                 __DEV__ && invariant.warn(
---
>                 globalThis.__DEV__ !== false && invariant.warn(
276c276
<                 __DEV__ && invariant.error(20, err);
---
>                 globalThis.__DEV__ !== false && invariant.error(20, err);
530c530
<     __DEV__ && invariant.error(22, error.message, error.stack);
---
>     globalThis.__DEV__ !== false && invariant.error(22, error.message, error.stack);
533,534c533,534
<     if (__DEV__ && missing) {
<         __DEV__ && invariant.debug(23, missing);
---
>     if (globalThis.__DEV__ !== false && missing) {
>         globalThis.__DEV__ !== false && invariant.debug(23, missing);
./core/ApolloClient.js
2c2
< import { invariant, newInvariantError, __DEV__ } from "../utilities/globals/index.js";
---
> import { invariant, newInvariantError } from "../utilities/globals/index.js";
21c21
<             __DEV__ : _c, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d, defaultOptions = options.defaultOptions, _e = options.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? cache.assumeImmutableResults : _e, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwarenessName = options.name, clientAwarenessVersion = options.version;
---
>             globalThis.__DEV__ !== false : _c, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d, defaultOptions = options.defaultOptions, _e = options.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? cache.assumeImmutableResults : _e, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwarenessName = options.name, clientAwarenessVersion = options.version;
45c45
<         if (!hasSuggestedDevtools && connectToDevTools && __DEV__) {
---
>         if (!hasSuggestedDevtools && connectToDevTools && globalThis.__DEV__ !== false) {
64c64
<                     __DEV__ && invariant.log(14, url);
---
>                     globalThis.__DEV__ !== false && invariant.log(14, url);
216c216
<             __DEV__ && invariant.debug(16, error);
---
>             globalThis.__DEV__ !== false && invariant.debug(16, error);
./core/index.js
1d0
< import { __DEV__ } from "../utilities/globals/index.js";
15c14
< setVerbosity(__DEV__ ? "log" : "silent");
---
> setVerbosity(globalThis.__DEV__ !== false ? "log" : "silent");
./core/QueryManager.js
2c2
< import { invariant, newInvariantError, __DEV__ } from "../utilities/globals/index.js";
---
> import { invariant, newInvariantError } from "../utilities/globals/index.js";
304c304
<                 __DEV__ && invariant.error(error);
---
>                 globalThis.__DEV__ !== false && invariant.error(error);
487c487
<         if (__DEV__ && queryNamesAndDocs.size) {
---
>         if (globalThis.__DEV__ !== false && queryNamesAndDocs.size) {
490c490
<                     __DEV__ && invariant.warn(typeof nameOrDoc === "string" ? 32 : 33, nameOrDoc);
---
>                     globalThis.__DEV__ !== false && invariant.warn(typeof nameOrDoc === "string" ? 32 : 33, nameOrDoc);
806c806
<             if (__DEV__ &&
---
>             if (globalThis.__DEV__ !== false &&
./core/core.cjs.native.js
5d4
< var globals = require("../utilities/globals");
6a6
> var globals = require("../utilities/globals");
303c303
<             if (globals.__DEV__ &&
---
>             if (globalThis.__DEV__ !== false &&
363c363
<         if (globals.__DEV__ && variables && hasOwnProperty$1.call(variables, "variables")) {
---
>         if (globalThis.__DEV__ !== false && variables && hasOwnProperty$1.call(variables, "variables")) {
367c367
<                 globals.__DEV__ && globals.invariant.warn(
---
>                 globalThis.__DEV__ !== false && globals.invariant.warn(
459c459
<                 globals.__DEV__ && globals.invariant.error(20, err);
---
>                 globalThis.__DEV__ !== false && globals.invariant.error(20, err);
710c710
<     globals.__DEV__ && globals.invariant.error(22, error.message, error.stack);
---
>     globalThis.__DEV__ !== false && globals.invariant.error(22, error.message, error.stack);
713,714c713,714
<     if (globals.__DEV__ && missing) {
<         globals.__DEV__ && globals.invariant.debug(23, missing);
---
>     if (globalThis.__DEV__ !== false && missing) {
>         globalThis.__DEV__ !== false && globals.invariant.debug(23, missing);
1598c1598
<                 globals.__DEV__ && globals.invariant.error(error);
---
>                 globalThis.__DEV__ !== false && globals.invariant.error(error);
1781c1781
<         if (globals.__DEV__ && queryNamesAndDocs.size) {
---
>         if (globalThis.__DEV__ !== false && queryNamesAndDocs.size) {
1784c1784
<                     globals.__DEV__ && globals.invariant.warn(typeof nameOrDoc === "string" ? 32 : 33, nameOrDoc);
---
>                     globalThis.__DEV__ !== false && globals.invariant.warn(typeof nameOrDoc === "string" ? 32 : 33, nameOrDoc);
2100c2100
<             if (globals.__DEV__ &&
---
>             if (globalThis.__DEV__ !== false &&
2203c2203
<             globals.__DEV__ : _c, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d, defaultOptions = options.defaultOptions, _e = options.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? cache.assumeImmutableResults : _e, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwarenessName = options.name, clientAwarenessVersion = options.version;
---
>             globalThis.__DEV__ !== false : _c, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d, defaultOptions = options.defaultOptions, _e = options.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? cache.assumeImmutableResults : _e, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwarenessName = options.name, clientAwarenessVersion = options.version;
2227c2227
<         if (!hasSuggestedDevtools && connectToDevTools && globals.__DEV__) {
---
>         if (!hasSuggestedDevtools && connectToDevTools && globalThis.__DEV__ !== false) {
2246c2246
<                     globals.__DEV__ && globals.invariant.log(14, url);
---
>                     globalThis.__DEV__ !== false && globals.invariant.log(14, url);
2398c2398
<             globals.__DEV__ && globals.invariant.debug(16, error);
---
>             globalThis.__DEV__ !== false && globals.invariant.debug(16, error);
2430c2430
< tsInvariant.setVerbosity(globals.__DEV__ ? "log" : "silent");
---
> tsInvariant.setVerbosity(globalThis.__DEV__ !== false ? "log" : "silent");
./cache/inmemory/object-canon.js
2d1
< import { __DEV__ } from "../../utilities/globals/index.js";
48c47
<                         if (__DEV__) {
---
>                         if (globalThis.__DEV__ !== false) {
73c72
<                         if (__DEV__) {
---
>                         if (globalThis.__DEV__ !== false) {
./cache/inmemory/writeToStore.js
2c2
< import { invariant, newInvariantError, __DEV__ } from "../../utilities/globals/index.js";
---
> import { invariant, newInvariantError } from "../../utilities/globals/index.js";
55c55
<             if (__DEV__ && !context.overwrite) {
---
>             if (globalThis.__DEV__ !== false && !context.overwrite) {
143c143
<             else if (__DEV__ &&
---
>             else if (globalThis.__DEV__ !== false &&
148c148
<                 __DEV__ && invariant.error(10, resultKeyNameFromField(field), result);
---
>                 globalThis.__DEV__ !== false && invariant.error(10, resultKeyNameFromField(field), result);
197c197
<             return __DEV__ ? cloneDeep(value) : value;
---
>             return globalThis.__DEV__ !== false ? cloneDeep(value) : value;
389c389
<     __DEV__ && invariant.warn(12, fieldName, parentType, childTypenames.length
---
>     globalThis.__DEV__ !== false && invariant.warn(12, fieldName, parentType, childTypenames.length
./cache/inmemory/policies.js
2c2
< import { invariant, newInvariantError, __DEV__ } from "../../utilities/globals/index.js";
---
> import { invariant, newInvariantError } from "../../utilities/globals/index.js";
234c234
<                             __DEV__ && invariant.warn(4, typename, supertype);
---
>                             globalThis.__DEV__ !== false && invariant.warn(4, typename, supertype);
388,389c388,389
<     if (__DEV__ && options.from === void 0) {
<         __DEV__ && invariant.warn(5, stringifyForDisplay(Array.from(readFieldArgs)));
---
>     if (globalThis.__DEV__ !== false && options.from === void 0) {
>         globalThis.__DEV__ !== false && invariant.warn(5, stringifyForDisplay(Array.from(readFieldArgs)));
./cache/inmemory/readFromStore.js
2c2
< import { invariant, newInvariantError, __DEV__ } from "../../utilities/globals/index.js";
---
> import { invariant, newInvariantError } from "../../utilities/globals/index.js";
231c231
<             if (__DEV__) {
---
>             if (globalThis.__DEV__ !== false) {
./cache/inmemory/inMemoryCache.js
2c2
< import { invariant, __DEV__ } from "../../utilities/globals/index.js";
---
> import { invariant } from "../../utilities/globals/index.js";
171c171
<             __DEV__ && invariant.warn(e);
---
>             globalThis.__DEV__ !== false && invariant.warn(e);
./cache/cache.cjs.native.js
707c707
<                         if (globals.__DEV__) {
---
>                         if (globalThis.__DEV__ !== false) {
732c732
<                         if (globals.__DEV__) {
---
>                         if (globalThis.__DEV__ !== false) {
999c999
<             if (globals.__DEV__) {
---
>             if (globalThis.__DEV__ !== false) {
1444c1444
<                             globals.__DEV__ && globals.invariant.warn(4, typename, supertype);
---
>                             globalThis.__DEV__ !== false && globals.invariant.warn(4, typename, supertype);
1597,1598c1597,1598
<     if (globals.__DEV__ && options.from === void 0) {
<         globals.__DEV__ && globals.invariant.warn(5, utilities.stringifyForDisplay(Array.from(readFieldArgs)));
---
>     if (globalThis.__DEV__ !== false && options.from === void 0) {
>         globalThis.__DEV__ !== false && globals.invariant.warn(5, utilities.stringifyForDisplay(Array.from(readFieldArgs)));
1681c1681
<             if (globals.__DEV__ && !context.overwrite) {
---
>             if (globalThis.__DEV__ !== false && !context.overwrite) {
1769c1769
<             else if (globals.__DEV__ &&
---
>             else if (globalThis.__DEV__ !== false &&
1774c1774
<                 globals.__DEV__ && globals.invariant.error(10, utilities.resultKeyNameFromField(field), result);
---
>                 globalThis.__DEV__ !== false && globals.invariant.error(10, utilities.resultKeyNameFromField(field), result);
1823c1823
<             return globals.__DEV__ ? utilities.cloneDeep(value) : value;
---
>             return globalThis.__DEV__ !== false ? utilities.cloneDeep(value) : value;
2014c2014
<     globals.__DEV__ && globals.invariant.warn(12, fieldName, parentType, childTypenames.length
---
>     globalThis.__DEV__ !== false && globals.invariant.warn(12, fieldName, parentType, childTypenames.length
2174c2174
<             globals.__DEV__ && globals.invariant.warn(e);
---
>             globalThis.__DEV__ !== false && globals.invariant.warn(e);
./utilities/globals/index.js
2,6d1
< import DEV from "./DEV.js";
< export { DEV };
< export var __DEV__ = DEV;
< import { removeTemporaryGlobals } from "./fix-graphql.js";
< removeTemporaryGlobals();
9a5,6
> export var DEV = globalThis.__DEV__ !== false;
> export { DEV as __DEV__ };
./utilities/globals/globals.cjs.native.js
7,8d6
< var process$1 = require("ts-invariant/process");
< var graphql = require("graphql");
22,23c20
<     maybe(function () { return global; }) ||
<     maybe(function () { return maybe.constructor("return this")(); }));
---
>     maybe(function () { return global; }) || maybe(function () { return maybe.constructor("return this")(); }));
87,96c84
< var DEV = ("__DEV__" in global$1
<     ? Boolean(global$1.__DEV__)
<     : maybe(function () { return process.env.NODE_ENV; }) !== "production");
< 
< function removeTemporaryGlobals() {
<     return typeof graphql.Source === "function" ? process$1.remove() : process$1.remove();
< }
< 
< var __DEV__ = DEV;
< removeTemporaryGlobals();
---
> var DEV = globalThis.__DEV__ !== false;
100c88
< exports.__DEV__ = __DEV__;
---
> exports.__DEV__ = DEV;
./utilities/utilities.cjs.native.js
608c608
<         globals.__DEV__ && globals.invariant.error(82);
---
>         globalThis.__DEV__ !== false && globals.invariant.error(82);
784c784
<                 globals.__DEV__ && globals.invariant.warn(83);
---
>                 globalThis.__DEV__ !== false && globals.invariant.warn(83);
1199c1199
<     if (globals.__DEV__ && !Object.isFrozen(obj)) {
---
>     if (globalThis.__DEV__ !== false && !Object.isFrozen(obj)) {
1212c1212
<     if (globals.__DEV__) {
---
>     if (globalThis.__DEV__ !== false) {
./utilities/common/maybeDeepFreeze.js
1d0
< import { __DEV__ } from "../globals/index.js";
16c15
<     if (__DEV__ && !Object.isFrozen(obj)) {
---
>     if (globalThis.__DEV__ !== false && !Object.isFrozen(obj)) {
29c28
<     if (__DEV__) {
---
>     if (globalThis.__DEV__ !== false) {
./utilities/graphql/transform.js
2c2
< import { invariant, __DEV__ } from "../globals/index.js";
---
> import { invariant } from "../globals/index.js";
78c78
<         __DEV__ && invariant.error(82);
---
>         globalThis.__DEV__ !== false && invariant.error(82);
254c254
<                 __DEV__ && invariant.warn(83);
---
>                 globalThis.__DEV__ !== false && invariant.warn(83);
./link/core/ApolloLink.js
1c1
< import { newInvariantError, invariant, __DEV__ } from "../../utilities/globals/index.js";
---
> import { newInvariantError, invariant } from "../../utilities/globals/index.js";
50c50
<             __DEV__ && invariant.warn(34, firstLink);
---
>             globalThis.__DEV__ !== false && invariant.warn(34, firstLink);
./link/core/core.cjs.native.js
55c55
<             globals.__DEV__ && globals.invariant.warn(34, firstLink);
---
>             globalThis.__DEV__ !== false && globals.invariant.warn(34, firstLink);
./link/utils/utils.cjs.native.js
22c22
<                     globals.__DEV__ && globals.invariant.warn(41);
---
>                     globalThis.__DEV__ !== false && globals.invariant.warn(41);
./link/utils/toPromise.js
1c1
< import { invariant, __DEV__ } from "../../utilities/globals/index.js";
---
> import { invariant } from "../../utilities/globals/index.js";
8c8
<                     __DEV__ && invariant.warn(41);
---
>                     globalThis.__DEV__ !== false && invariant.warn(41);
./link/http/createHttpLink.js
2c2
< import { __DEV__, invariant } from "../../utilities/globals/index.js";
---
> import { invariant } from "../../utilities/globals/index.js";
18c18
<     if (__DEV__) {
---
>     if (globalThis.__DEV__ !== false) {
81c81
<                 __DEV__ && invariant.warn(37);
---
>                 globalThis.__DEV__ !== false && invariant.warn(37);
./link/http/http.cjs.native.js
488c488
<     if (globals.__DEV__) {
---
>     if (globalThis.__DEV__ !== false) {
551c551
<                 globals.__DEV__ && globals.invariant.warn(37);
---
>                 globalThis.__DEV__ !== false && globals.invariant.warn(37);
./dev/dev.cjs.native.js
549,550c549
<     maybe(function () { return global; }) ||
<     maybe(function () { return maybe.constructor("return this")(); }));
---
>     maybe(function () { return global; }) || maybe(function () { return maybe.constructor("return this")(); }));
./react/hooks/useQuery.js
2c2
< import { invariant, __DEV__ } from "../../utilities/globals/index.js";
---
> import { invariant } from "../../utilities/globals/index.js";
57c57
<         __DEV__ && invariant.warn(49);
---
>         globalThis.__DEV__ !== false && invariant.warn(49);
262c262
<                 __DEV__ && invariant.warn(error);
---
>                 globalThis.__DEV__ !== false && invariant.warn(error);
./react/hooks/useSyncExternalStore.js
1c1
< import { invariant, __DEV__ } from "../../utilities/globals/index.js";
---
> import { invariant } from "../../utilities/globals/index.js";
9c9
<     if (__DEV__ &&
---
>     if (globalThis.__DEV__ !== false &&
13c13
<         __DEV__ && invariant.error(58);
---
>         globalThis.__DEV__ !== false && invariant.error(58);
./react/hooks/hooks.cjs.native.js
47c47
<     if (globals.__DEV__ &&
---
>     if (globalThis.__DEV__ !== false &&
51c51
<         globals.__DEV__ && globals.invariant.error(58);
---
>         globalThis.__DEV__ !== false && globals.invariant.error(58);
131c131
<         globals.__DEV__ && globals.invariant.warn(49);
---
>         globalThis.__DEV__ !== false && globals.invariant.warn(49);
336c336
<                 globals.__DEV__ && globals.invariant.warn(error);
---
>                 globalThis.__DEV__ !== false && globals.invariant.warn(error);
542c542
<             globals.__DEV__ && globals.invariant.warn(options.onData ? 51 : 52);
---
>             globalThis.__DEV__ !== false && globals.invariant.warn(options.onData ? 51 : 52);
545c545
<             globals.__DEV__ && globals.invariant.warn(options.onComplete ? 53 : 54);
---
>             globalThis.__DEV__ !== false && globals.invariant.warn(options.onComplete ? 53 : 54);
845c845
<         globals.__DEV__ && globals.invariant.warn(57);
---
>         globalThis.__DEV__ !== false && globals.invariant.warn(57);
868c868
<         if (globals.__DEV__) {
---
>         if (globalThis.__DEV__ !== false) {
./react/hooks/useSubscription.js
1c1
< import { invariant, __DEV__ } from "../../utilities/globals/index.js";
---
> import { invariant } from "../../utilities/globals/index.js";
19c19
<             __DEV__ && invariant.warn(options.onData ? 51 : 52);
---
>             globalThis.__DEV__ !== false && invariant.warn(options.onData ? 51 : 52);
22c22
<             __DEV__ && invariant.warn(options.onComplete ? 53 : 54);
---
>             globalThis.__DEV__ !== false && invariant.warn(options.onComplete ? 53 : 54);
./react/hooks/useSuspenseQuery.js
2c2
< import { invariant, __DEV__ } from "../../utilities/globals/index.js";
---
> import { invariant } from "../../utilities/globals/index.js";
96c96
<         __DEV__ && invariant.warn(57);
---
>         globalThis.__DEV__ !== false && invariant.warn(57);
119c119
<         if (__DEV__) {
---
>         if (globalThis.__DEV__ !== false) {

differences in *.cjs files

11 files with differences

./core/core.cjs
5d4
< var globals = require("../utilities/globals");
6a6
> var globals = require("../utilities/globals");
303c303
<             if (globals.__DEV__ &&
---
>             if (globalThis.__DEV__ !== false &&
363c363
<         if (globals.__DEV__ && variables && hasOwnProperty$1.call(variables, "variables")) {
---
>         if (globalThis.__DEV__ !== false && variables && hasOwnProperty$1.call(variables, "variables")) {
367c367
<                 globals.__DEV__ && globals.invariant.warn(
---
>                 globalThis.__DEV__ !== false && globals.invariant.warn(
459c459
<                 globals.__DEV__ && globals.invariant.error(20, err);
---
>                 globalThis.__DEV__ !== false && globals.invariant.error(20, err);
710c710
<     globals.__DEV__ && globals.invariant.error(22, error.message, error.stack);
---
>     globalThis.__DEV__ !== false && globals.invariant.error(22, error.message, error.stack);
713,714c713,714
<     if (globals.__DEV__ && missing) {
<         globals.__DEV__ && globals.invariant.debug(23, missing);
---
>     if (globalThis.__DEV__ !== false && missing) {
>         globalThis.__DEV__ !== false && globals.invariant.debug(23, missing);
1598c1598
<                 globals.__DEV__ && globals.invariant.error(error);
---
>                 globalThis.__DEV__ !== false && globals.invariant.error(error);
1781c1781
<         if (globals.__DEV__ && queryNamesAndDocs.size) {
---
>         if (globalThis.__DEV__ !== false && queryNamesAndDocs.size) {
1784c1784
<                     globals.__DEV__ && globals.invariant.warn(typeof nameOrDoc === "string" ? 32 : 33, nameOrDoc);
---
>                     globalThis.__DEV__ !== false && globals.invariant.warn(typeof nameOrDoc === "string" ? 32 : 33, nameOrDoc);
2100c2100
<             if (globals.__DEV__ &&
---
>             if (globalThis.__DEV__ !== false &&
2203c2203
<             globals.__DEV__ : _c, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d, defaultOptions = options.defaultOptions, _e = options.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? cache.assumeImmutableResults : _e, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwarenessName = options.name, clientAwarenessVersion = options.version;
---
>             globalThis.__DEV__ !== false : _c, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d, defaultOptions = options.defaultOptions, _e = options.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? cache.assumeImmutableResults : _e, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwarenessName = options.name, clientAwarenessVersion = options.version;
2227c2227
<         if (!hasSuggestedDevtools && connectToDevTools && globals.__DEV__) {
---
>         if (!hasSuggestedDevtools && connectToDevTools && globalThis.__DEV__ !== false) {
2246c2246
<                     globals.__DEV__ && globals.invariant.log(14, url);
---
>                     globalThis.__DEV__ !== false && globals.invariant.log(14, url);
2398c2398
<             globals.__DEV__ && globals.invariant.debug(16, error);
---
>             globalThis.__DEV__ !== false && globals.invariant.debug(16, error);
2430c2430
< tsInvariant.setVerbosity(globals.__DEV__ ? "log" : "silent");
---
> tsInvariant.setVerbosity(globalThis.__DEV__ !== false ? "log" : "silent");
./cache/cache.cjs
707c707
<                         if (globals.__DEV__) {
---
>                         if (globalThis.__DEV__ !== false) {
732c732
<                         if (globals.__DEV__) {
---
>                         if (globalThis.__DEV__ !== false) {
999c999
<             if (globals.__DEV__) {
---
>             if (globalThis.__DEV__ !== false) {
1444c1444
<                             globals.__DEV__ && globals.invariant.warn(4, typename, supertype);
---
>                             globalThis.__DEV__ !== false && globals.invariant.warn(4, typename, supertype);
1597,1598c1597,1598
<     if (globals.__DEV__ && options.from === void 0) {
<         globals.__DEV__ && globals.invariant.warn(5, utilities.stringifyForDisplay(Array.from(readFieldArgs)));
---
>     if (globalThis.__DEV__ !== false && options.from === void 0) {
>         globalThis.__DEV__ !== false && globals.invariant.warn(5, utilities.stringifyForDisplay(Array.from(readFieldArgs)));
1681c1681
<             if (globals.__DEV__ && !context.overwrite) {
---
>             if (globalThis.__DEV__ !== false && !context.overwrite) {
1769c1769
<             else if (globals.__DEV__ &&
---
>             else if (globalThis.__DEV__ !== false &&
1774c1774
<                 globals.__DEV__ && globals.invariant.error(10, utilities.resultKeyNameFromField(field), result);
---
>                 globalThis.__DEV__ !== false && globals.invariant.error(10, utilities.resultKeyNameFromField(field), result);
1823c1823
<             return globals.__DEV__ ? utilities.cloneDeep(value) : value;
---
>             return globalThis.__DEV__ !== false ? utilities.cloneDeep(value) : value;
2014c2014
<     globals.__DEV__ && globals.invariant.warn(12, fieldName, parentType, childTypenames.length
---
>     globalThis.__DEV__ !== false && globals.invariant.warn(12, fieldName, parentType, childTypenames.length
2174c2174
<             globals.__DEV__ && globals.invariant.warn(e);
---
>             globalThis.__DEV__ !== false && globals.invariant.warn(e);
./apollo-client.cjs
6,8d5
< var process$1 = require("ts-invariant/process");
< var graphql = require("graphql");
< var equal = require("@wry/equality");
9a7,8
> var equal = require("@wry/equality");
> var graphql = require("graphql");
32d30
< var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
33a32
> var equal__default = /*#__PURE__*/_interopDefaultLegacy(equal);
49,50c48
<     maybe(function () { return global; }) ||
<     maybe(function () { return maybe.constructor("return this")(); }));
---
>     maybe(function () { return global; }) || maybe(function () { return maybe.constructor("return this")(); }));
114,124d111
< var DEV = ("__DEV__" in global$1
<     ? Boolean(global$1.__DEV__)
<     : maybe(function () { return process.env.NODE_ENV; }) !== "production");
< 
< function removeTemporaryGlobals() {
<     return typeof graphql.Source === "function" ? process$1.remove() : process$1.remove();
< }
< 
< var __DEV__ = DEV;
< removeTemporaryGlobals();
< 
704c691
<         __DEV__ && invariant.error(82);
---
>         globalThis.__DEV__ !== false && invariant.error(82);
1056c1043
<     if (__DEV__ && !Object.isFrozen(obj)) {
---
>     if (globalThis.__DEV__ !== false && !Object.isFrozen(obj)) {
1069c1056
<     if (__DEV__) {
---
>     if (globalThis.__DEV__ !== false) {
1381c1368
<                     __DEV__ && invariant.warn(41);
---
>                     globalThis.__DEV__ !== false && invariant.warn(41);
1531c1518
<             __DEV__ && invariant.warn(34, firstLink);
---
>             globalThis.__DEV__ !== false && invariant.warn(34, firstLink);
2085c2072
<     if (__DEV__) {
---
>     if (globalThis.__DEV__ !== false) {
2148c2135
<                 __DEV__ && invariant.warn(37);
---
>                 globalThis.__DEV__ !== false && invariant.warn(37);
2900c2887
<                         if (__DEV__) {
---
>                         if (globalThis.__DEV__ !== false) {
2925c2912
<                         if (__DEV__) {
---
>                         if (globalThis.__DEV__ !== false) {
3192c3179
<             if (__DEV__) {
---
>             if (globalThis.__DEV__ !== false) {
3637c3624
<                             __DEV__ && invariant.warn(4, typename, supertype);
---
>                             globalThis.__DEV__ !== false && invariant.warn(4, typename, supertype);
3790,3791c3777,3778
<     if (__DEV__ && options.from === void 0) {
<         __DEV__ && invariant.warn(5, stringifyForDisplay(Array.from(readFieldArgs)));
---
>     if (globalThis.__DEV__ !== false && options.from === void 0) {
>         globalThis.__DEV__ !== false && invariant.warn(5, stringifyForDisplay(Array.from(readFieldArgs)));
3874c3861
<             if (__DEV__ && !context.overwrite) {
---
>             if (globalThis.__DEV__ !== false && !context.overwrite) {
3962c3949
<             else if (__DEV__ &&
---
>             else if (globalThis.__DEV__ !== false &&
3967c3954
<                 __DEV__ && invariant.error(10, resultKeyNameFromField(field), result);
---
>                 globalThis.__DEV__ !== false && invariant.error(10, resultKeyNameFromField(field), result);
4016c4003
<             return __DEV__ ? cloneDeep(value) : value;
---
>             return globalThis.__DEV__ !== false ? cloneDeep(value) : value;
4207c4194
<     __DEV__ && invariant.warn(12, fieldName, parentType, childTypenames.length
---
>     globalThis.__DEV__ !== false && invariant.warn(12, fieldName, parentType, childTypenames.length
4367c4354
<             __DEV__ && invariant.warn(e);
---
>             globalThis.__DEV__ !== false && invariant.warn(e);
4703c4690
<             if (__DEV__ &&
---
>             if (globalThis.__DEV__ !== false &&
4763c4750
<         if (__DEV__ && variables && hasOwnProperty$2.call(variables, "variables")) {
---
>         if (globalThis.__DEV__ !== false && variables && hasOwnProperty$2.call(variables, "variables")) {
4767c4754
<                 __DEV__ && invariant.warn(
---
>                 globalThis.__DEV__ !== false && invariant.warn(
4859c4846
<                 __DEV__ && invariant.error(20, err);
---
>                 globalThis.__DEV__ !== false && invariant.error(20, err);
5110c5097
<     __DEV__ && invariant.error(22, error.message, error.stack);
---
>     globalThis.__DEV__ !== false && invariant.error(22, error.message, error.stack);
5113,5114c5100,5101
<     if (__DEV__ && missing) {
<         __DEV__ && invariant.debug(23, missing);
---
>     if (globalThis.__DEV__ !== false && missing) {
>         globalThis.__DEV__ !== false && invariant.debug(23, missing);
5998c5985
<                 __DEV__ && invariant.error(error);
---
>                 globalThis.__DEV__ !== false && invariant.error(error);
6181c6168
<         if (__DEV__ && queryNamesAndDocs.size) {
---
>         if (globalThis.__DEV__ !== false && queryNamesAndDocs.size) {
6184c6171
<                     __DEV__ && invariant.warn(typeof nameOrDoc === "string" ? 32 : 33, nameOrDoc);
---
>                     globalThis.__DEV__ !== false && invariant.warn(typeof nameOrDoc === "string" ? 32 : 33, nameOrDoc);
6500c6487
<             if (__DEV__ &&
---
>             if (globalThis.__DEV__ !== false &&
6603c6590
<             __DEV__ : _c, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d, defaultOptions = options.defaultOptions, _e = options.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? cache.assumeImmutableResults : _e, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwarenessName = options.name, clientAwarenessVersion = options.version;
---
>             globalThis.__DEV__ !== false : _c, _d = options.queryDeduplication, queryDeduplication = _d === void 0 ? true : _d, defaultOptions = options.defaultOptions, _e = options.assumeImmutableResults, assumeImmutableResults = _e === void 0 ? cache.assumeImmutableResults : _e, resolvers = options.resolvers, typeDefs = options.typeDefs, fragmentMatcher = options.fragmentMatcher, clientAwarenessName = options.name, clientAwarenessVersion = options.version;
6627c6614
<         if (!hasSuggestedDevtools && connectToDevTools && __DEV__) {
---
>         if (!hasSuggestedDevtools && connectToDevTools && globalThis.__DEV__ !== false) {
6646c6633
<                     __DEV__ && invariant.log(14, url);
---
>                     globalThis.__DEV__ !== false && invariant.log(14, url);
6798c6785
<             __DEV__ && invariant.debug(16, error);
---
>             globalThis.__DEV__ !== false && invariant.debug(16, error);
6871c6858
<     if (__DEV__ &&
---
>     if (globalThis.__DEV__ !== false &&
6875c6862
<         __DEV__ && invariant.error(58);
---
>         globalThis.__DEV__ !== false && invariant.error(58);
7051c7038
<         __DEV__ && invariant.warn(49);
---
>         globalThis.__DEV__ !== false && invariant.warn(49);
7256c7243
<                 __DEV__ && invariant.warn(error);
---
>                 globalThis.__DEV__ !== false && invariant.warn(error);
7462c7449
<             __DEV__ && invariant.warn(options.onData ? 51 : 52);
---
>             globalThis.__DEV__ !== false && invariant.warn(options.onData ? 51 : 52);
7465c7452
<             __DEV__ && invariant.warn(options.onComplete ? 53 : 54);
---
>             globalThis.__DEV__ !== false && invariant.warn(options.onComplete ? 53 : 54);
7765c7752
<         __DEV__ && invariant.warn(57);
---
>         globalThis.__DEV__ !== false && invariant.warn(57);
7788c7775
<         if (__DEV__) {
---
>         if (globalThis.__DEV__ !== false) {
./apollo-client.min.cjs
> Minified file differs.
./utilities/globals/globals.cjs
7,8d6
< var process$1 = require("ts-invariant/process");
< var graphql = require("graphql");
22,23c20
<     maybe(function () { return global; }) ||
<     maybe(function () { return maybe.constructor("return this")(); }));
---
>     maybe(function () { return global; }) || maybe(function () { return maybe.constructor("return this")(); }));
87,96c84
< var DEV = ("__DEV__" in global$1
<     ? Boolean(global$1.__DEV__)
<     : maybe(function () { return process.env.NODE_ENV; }) !== "production");
< 
< function removeTemporaryGlobals() {
<     return typeof graphql.Source === "function" ? process$1.remove() : process$1.remove();
< }
< 
< var __DEV__ = DEV;
< removeTemporaryGlobals();
---
> var DEV = globalThis.__DEV__ !== false;
100c88
< exports.__DEV__ = __DEV__;
---
> exports.__DEV__ = DEV;
./utilities/utilities.cjs
608c608
<         globals.__DEV__ && globals.invariant.error(82);
---
>         globalThis.__DEV__ !== false && globals.invariant.error(82);
784c784
<                 globals.__DEV__ && globals.invariant.warn(83);
---
>                 globalThis.__DEV__ !== false && globals.invariant.warn(83);
1199c1199
<     if (globals.__DEV__ && !Object.isFrozen(obj)) {
---
>     if (globalThis.__DEV__ !== false && !Object.isFrozen(obj)) {
1212c1212
<     if (globals.__DEV__) {
---
>     if (globalThis.__DEV__ !== false) {
./link/core/core.cjs
55c55
<             globals.__DEV__ && globals.invariant.warn(34, firstLink);
---
>             globalThis.__DEV__ !== false && globals.invariant.warn(34, firstLink);
./link/utils/utils.cjs
22c22
<                     globals.__DEV__ && globals.invariant.warn(41);
---
>                     globalThis.__DEV__ !== false && globals.invariant.warn(41);
./link/http/http.cjs
488c488
<     if (globals.__DEV__) {
---
>     if (globalThis.__DEV__ !== false) {
551c551
<                 globals.__DEV__ && globals.invariant.warn(37);
---
>                 globalThis.__DEV__ !== false && globals.invariant.warn(37);
./dev/dev.cjs
549,550c549
<     maybe(function () { return global; }) ||
<     maybe(function () { return maybe.constructor("return this")(); }));
---
>     maybe(function () { return global; }) || maybe(function () { return maybe.constructor("return this")(); }));
./react/hooks/hooks.cjs
47c47
<     if (globals.__DEV__ &&
---
>     if (globalThis.__DEV__ !== false &&
51c51
<         globals.__DEV__ && globals.invariant.error(58);
---
>         globalThis.__DEV__ !== false && globals.invariant.error(58);
131c131
<         globals.__DEV__ && globals.invariant.warn(49);
---
>         globalThis.__DEV__ !== false && globals.invariant.warn(49);
336c336
<                 globals.__DEV__ && globals.invariant.warn(error);
---
>                 globalThis.__DEV__ !== false && globals.invariant.warn(error);
542c542
<             globals.__DEV__ && globals.invariant.warn(options.onData ? 51 : 52);
---
>             globalThis.__DEV__ !== false && globals.invariant.warn(options.onData ? 51 : 52);
545c545
<             globals.__DEV__ && globals.invariant.warn(options.onComplete ? 53 : 54);
---
>             globalThis.__DEV__ !== false && globals.invariant.warn(options.onComplete ? 53 : 54);
845c845
<         globals.__DEV__ && globals.invariant.warn(57);
---
>         globalThis.__DEV__ !== false && globals.invariant.warn(57);
868c868
<         if (globals.__DEV__) {
---
>         if (globalThis.__DEV__ !== false) {

differences in *.d.ts files

2 files with differences

./utilities/globals/global.d.ts
1a2
>     const __DEV__: boolean;
./utilities/globals/index.d.ts
2,4d1
< import DEV from "./DEV";
< export { DEV };
< export declare const __DEV__: boolean;
7a5,6
> export declare const DEV: boolean;
> export { DEV as __DEV__ };

differences in other files

0 files with differences

@phryneas phryneas marked this pull request as ready for review June 30, 2023 13:01
Copy link
Member

@jerelmiller jerelmiller left a comment

Choose a reason for hiding this comment

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

The changes look good to me. Just had a couple questions in here. Thanks for tackling this difficult problem!

@@ -4,6 +4,7 @@ on:
branches:
- main
- release-*
- pr/*
Copy link
Member

Choose a reason for hiding this comment

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

I'm assuming this was for testing this branch. Do you still need this?

Copy link
Member Author

Choose a reason for hiding this comment

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

It will generally be useful for PRs against other PR branches.

.changeset/three-grapes-marry.md Outdated Show resolved Hide resolved
src/utilities/globals/index.ts Outdated Show resolved Hide resolved
@phryneas phryneas merged commit 3a62d82 into release-3.8 Jul 6, 2023
@phryneas phryneas deleted the pr/__DEV__ branch July 6, 2023 16:01
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants