-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Rework interdependencies between @apollo/client/* entry points. #6656
Commits on Jul 20, 2020
-
Snapshot-test the exported properties of each entry point.
Before we get started refactoring how entry points are built, let's take a snapshot of the current exports of all public entry points.
Configuration menu - View commit details
-
Copy full SHA for 442923b - Browse repository at this point
Copy the full SHA 442923bView commit details -
Configuration menu - View commit details
-
Copy full SHA for 38ed28f - Browse repository at this point
Copy the full SHA 38ed28fView commit details -
Configuration menu - View commit details
-
Copy full SHA for d064c75 - Browse repository at this point
Copy the full SHA d064c75View commit details -
Import entry points from separate config/entryPoints.js module.
This new module provides a single source of truth for all the nested entry points that we build. As a nice bonus, thanks to this unification, the @apollo/client/testing entry point no longer needs such special treatment.
Configuration menu - View commit details
-
Copy full SHA for 847a4a6 - Browse repository at this point
Copy the full SHA 847a4a6View commit details -
Rename main CommonJS entry point to dist/main.cjs.js.
This prevents collision between the actual main entry point (used by Node.js) and the dist/apollo-client.cjs.js bundle that we use for estimating the minified bundle size.
Configuration menu - View commit details
-
Copy full SHA for 0121fc6 - Browse repository at this point
Copy the full SHA 0121fc6View commit details -
Configuration menu - View commit details
-
Copy full SHA for 30ccd41 - Browse repository at this point
Copy the full SHA 30ccd41View commit details -
Standalone script for processing invariants.
Adapted from https://github.com/apollographql/invariant-packages/tree/master/packages/rollup-plugin-invariant, this script wraps invariant(...), new InvariantError(...), and invariant.{warn,error} calls with process.env.NODE_ENV logic, so that long error messages can be stripped from production builds. I decided to abandon the Rollup plugin for this task because I'm planning to change how Rollup determines if imported modules are "external," and Rollup (understandably) stops traversing the dependency graph when it hits an external import, which means we can no longer rely on Rollup to traverse all modules that need invariants to be transformed. Also, this transformation step was never especially intertwined with the dependency traversal and rewriting logic that Rollup provides, so I think it makes things simpler to keep them separate. If Rollup provided hooks for performing arbitrary build steps, we might have been able to do this work in some initial step, but I couldn't find anything in the Rollup documentation that fit the bill (and that's fine: I wouldn't expect Rollup to attempt to be a generic build pipeline). Now, the CJS bundles for each nested entry point (e.g. @apollo/client/core or @apollo/client/react/ssr) can be computed from code that has been processed by the invariant transform, but has not yet been tampered with by Rollup, so we can trust that the exact same module identifiers from the source code are still intact.
Configuration menu - View commit details
-
Copy full SHA for c989212 - Browse repository at this point
Copy the full SHA c989212View commit details -
Avoid re-processing invariant expressions.
There's not currently any risk of running the invariant transform over the ./dist directory more than once during our build process, but it doesn't hurt to make sure the transform is idempotent.
Configuration menu - View commit details
-
Copy full SHA for a075a2a - Browse repository at this point
Copy the full SHA a075a2aView commit details -
Configuration menu - View commit details
-
Copy full SHA for 687eaa3 - Browse repository at this point
Copy the full SHA 687eaa3View commit details -
Remove prepareESM Rollup build step entirely.
Since we aren't using Rollup to apply the invariant transform anymore, it turns out we don't need this build step at all. Instead, the CJS bundles will be generated directly from the modules generated by tsc and processed by the invariant transform.
Configuration menu - View commit details
-
Copy full SHA for 627bd1b - Browse repository at this point
Copy the full SHA 627bd1bView commit details -
Configuration menu - View commit details
-
Copy full SHA for 44b5415 - Browse repository at this point
Copy the full SHA 44b5415View commit details -
Configuration menu - View commit details
-
Copy full SHA for 45bf62a - Browse repository at this point
Copy the full SHA 45bf62aView commit details -
Configuration menu - View commit details
-
Copy full SHA for d654457 - Browse repository at this point
Copy the full SHA d654457View commit details -
Configuration menu - View commit details
-
Copy full SHA for a698c54 - Browse repository at this point
Copy the full SHA a698c54View commit details -
Configuration menu - View commit details
-
Copy full SHA for 1934b98 - Browse repository at this point
Copy the full SHA 1934b98View commit details -
Configuration menu - View commit details
-
Copy full SHA for 112e477 - Browse repository at this point
Copy the full SHA 112e477View commit details -
Tell Rollup to treat imports from internal entry points as external.
This is a vital change (the whole point of this PR, really), because it means Rollup will no longer attempt to include code from other entry points in the CJS bundles for unrelated entry points, so there will no longer be any duplication of code between the CJS bundles.
Configuration menu - View commit details
-
Copy full SHA for 8aa5826 - Browse repository at this point
Copy the full SHA 8aa5826View commit details -
Warn when importing modules within other entry points.
It would be nice to make this an error that would fail the build, but there are a couple of benign violations that would be disruptive to fix at this point, like reexporting `../ApolloClient` from `./core/QueryManager`, and `./testing/index.ts` reaching into `../utilities/testing`.
Configuration menu - View commit details
-
Copy full SHA for f634785 - Browse repository at this point
Copy the full SHA f634785View commit details -
Remove require('react') try-catch wrapping logic.
Now that the CommonJS module tree uses nested entry points with their own package.json files, instead of importing everything and then filtering it (as the CJS version of @apollo/client/core used to do), we do not need to be so paranoid about the possibility that React is not installed.
Configuration menu - View commit details
-
Copy full SHA for 0afe234 - Browse repository at this point
Copy the full SHA 0afe234View commit details -
Configuration menu - View commit details
-
Copy full SHA for 4e1c604 - Browse repository at this point
Copy the full SHA 4e1c604View commit details -
Configuration menu - View commit details
-
Copy full SHA for ca230cd - Browse repository at this point
Copy the full SHA ca230cdView commit details -
Configuration menu - View commit details
-
Copy full SHA for 8388284 - Browse repository at this point
Copy the full SHA 8388284View commit details -
Configuration menu - View commit details
-
Copy full SHA for 2e592b4 - Browse repository at this point
Copy the full SHA 2e592b4View commit details -
Configuration menu - View commit details
-
Copy full SHA for dc403e1 - Browse repository at this point
Copy the full SHA dc403e1View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8363f90 - Browse repository at this point
Copy the full SHA 8363f90View commit details -
Configuration menu - View commit details
-
Copy full SHA for 02ef623 - Browse repository at this point
Copy the full SHA 02ef623View commit details -
Configuration menu - View commit details
-
Copy full SHA for 241d596 - Browse repository at this point
Copy the full SHA 241d596View commit details -
Configuration menu - View commit details
-
Copy full SHA for aefbc38 - Browse repository at this point
Copy the full SHA aefbc38View commit details -
Configuration menu - View commit details
-
Copy full SHA for 94becda - Browse repository at this point
Copy the full SHA 94becdaView commit details -
Configuration menu - View commit details
-
Copy full SHA for 2c30f3d - Browse repository at this point
Copy the full SHA 2c30f3dView commit details -
Configuration menu - View commit details
-
Copy full SHA for 6f18a7e - Browse repository at this point
Copy the full SHA 6f18a7eView commit details -
Configuration menu - View commit details
-
Copy full SHA for d55caca - Browse repository at this point
Copy the full SHA d55cacaView commit details -
Configuration menu - View commit details
-
Copy full SHA for a8867fa - Browse repository at this point
Copy the full SHA a8867faView commit details -
Configuration menu - View commit details
-
Copy full SHA for d3445be - Browse repository at this point
Copy the full SHA d3445beView commit details -
Configuration menu - View commit details
-
Copy full SHA for be4e4ce - Browse repository at this point
Copy the full SHA be4e4ceView commit details -
Configuration menu - View commit details
-
Copy full SHA for 19df06d - Browse repository at this point
Copy the full SHA 19df06dView commit details -
Configuration menu - View commit details
-
Copy full SHA for 11bac16 - Browse repository at this point
Copy the full SHA 11bac16View commit details -
Configuration menu - View commit details
-
Copy full SHA for 8e4f3cb - Browse repository at this point
Copy the full SHA 8e4f3cbView commit details -
Configuration menu - View commit details
-
Copy full SHA for 0153db9 - Browse repository at this point
Copy the full SHA 0153db9View commit details -
Configuration menu - View commit details
-
Copy full SHA for 56db2b3 - Browse repository at this point
Copy the full SHA 56db2b3View commit details -
Configuration menu - View commit details
-
Copy full SHA for 9fe73eb - Browse repository at this point
Copy the full SHA 9fe73ebView commit details -
Move src/ApolloClient.ts into src/core/, and update tests.
This allows src/core/index.ts to avoid reaching outside the @apollo/client/core entry point to import the all-important ApolloClient module/class.
Configuration menu - View commit details
-
Copy full SHA for 30e1083 - Browse repository at this point
Copy the full SHA 30e1083View commit details -
Update entry point export snapshots.
Adding new exports is safe/fine, and additions account for most of what's happening here. For example, @apollo/client/utilities needs to export a few more goodies to support other parts of the codebase, which previously reached inside the utilities entry point and imported stuff willy nilly. The only removal is RenderPromises, which can now be imported from @apollo/client/react/ssr.
Configuration menu - View commit details
-
Copy full SHA for 73687e1 - Browse repository at this point
Copy the full SHA 73687e1View commit details -
Configuration menu - View commit details
-
Copy full SHA for 17851bb - Browse repository at this point
Copy the full SHA 17851bbView commit details -
Test that every entry point's exports are snapshot-tested.
This test ensures we will never forget to update these snapshot tests if/when we add a new entry point in the future.
Configuration menu - View commit details
-
Copy full SHA for 7908e6d - Browse repository at this point
Copy the full SHA 7908e6dView commit details -
Configuration menu - View commit details
-
Copy full SHA for 43fc12d - Browse repository at this point
Copy the full SHA 43fc12dView commit details