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

Rework interdependencies between @apollo/client/* entry points. #6656

Merged
merged 46 commits into from
Jul 20, 2020

Commits on Jul 20, 2020

  1. 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.
    benjamn committed Jul 20, 2020
    Configuration menu
    Copy the full SHA
    442923b View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    38ed28f View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    d064c75 View commit details
    Browse the repository at this point in the history
  4. 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.
    benjamn committed Jul 20, 2020
    Configuration menu
    Copy the full SHA
    847a4a6 View commit details
    Browse the repository at this point in the history
  5. 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.
    benjamn committed Jul 20, 2020
    Configuration menu
    Copy the full SHA
    0121fc6 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    30ccd41 View commit details
    Browse the repository at this point in the history
  7. 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.
    benjamn committed Jul 20, 2020
    Configuration menu
    Copy the full SHA
    c989212 View commit details
    Browse the repository at this point in the history
  8. 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.
    benjamn committed Jul 20, 2020
    Configuration menu
    Copy the full SHA
    a075a2a View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    687eaa3 View commit details
    Browse the repository at this point in the history
  10. 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.
    benjamn committed Jul 20, 2020
    Configuration menu
    Copy the full SHA
    627bd1b View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    44b5415 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    45bf62a View commit details
    Browse the repository at this point in the history
  13. Configuration menu
    Copy the full SHA
    d654457 View commit details
    Browse the repository at this point in the history
  14. Configuration menu
    Copy the full SHA
    a698c54 View commit details
    Browse the repository at this point in the history
  15. Configuration menu
    Copy the full SHA
    1934b98 View commit details
    Browse the repository at this point in the history
  16. Configuration menu
    Copy the full SHA
    112e477 View commit details
    Browse the repository at this point in the history
  17. 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.
    benjamn committed Jul 20, 2020
    Configuration menu
    Copy the full SHA
    8aa5826 View commit details
    Browse the repository at this point in the history
  18. 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`.
    benjamn committed Jul 20, 2020
    Configuration menu
    Copy the full SHA
    f634785 View commit details
    Browse the repository at this point in the history
  19. 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.
    benjamn committed Jul 20, 2020
    Configuration menu
    Copy the full SHA
    0afe234 View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    4e1c604 View commit details
    Browse the repository at this point in the history
  21. Configuration menu
    Copy the full SHA
    ca230cd View commit details
    Browse the repository at this point in the history
  22. Configuration menu
    Copy the full SHA
    8388284 View commit details
    Browse the repository at this point in the history
  23. Configuration menu
    Copy the full SHA
    2e592b4 View commit details
    Browse the repository at this point in the history
  24. Configuration menu
    Copy the full SHA
    dc403e1 View commit details
    Browse the repository at this point in the history
  25. Configuration menu
    Copy the full SHA
    8363f90 View commit details
    Browse the repository at this point in the history
  26. Configuration menu
    Copy the full SHA
    02ef623 View commit details
    Browse the repository at this point in the history
  27. Configuration menu
    Copy the full SHA
    241d596 View commit details
    Browse the repository at this point in the history
  28. Configuration menu
    Copy the full SHA
    aefbc38 View commit details
    Browse the repository at this point in the history
  29. Configuration menu
    Copy the full SHA
    94becda View commit details
    Browse the repository at this point in the history
  30. Configuration menu
    Copy the full SHA
    2c30f3d View commit details
    Browse the repository at this point in the history
  31. Configuration menu
    Copy the full SHA
    6f18a7e View commit details
    Browse the repository at this point in the history
  32. Configuration menu
    Copy the full SHA
    d55caca View commit details
    Browse the repository at this point in the history
  33. Configuration menu
    Copy the full SHA
    a8867fa View commit details
    Browse the repository at this point in the history
  34. Configuration menu
    Copy the full SHA
    d3445be View commit details
    Browse the repository at this point in the history
  35. Configuration menu
    Copy the full SHA
    be4e4ce View commit details
    Browse the repository at this point in the history
  36. Configuration menu
    Copy the full SHA
    19df06d View commit details
    Browse the repository at this point in the history
  37. Configuration menu
    Copy the full SHA
    11bac16 View commit details
    Browse the repository at this point in the history
  38. Configuration menu
    Copy the full SHA
    8e4f3cb View commit details
    Browse the repository at this point in the history
  39. Configuration menu
    Copy the full SHA
    0153db9 View commit details
    Browse the repository at this point in the history
  40. Configuration menu
    Copy the full SHA
    56db2b3 View commit details
    Browse the repository at this point in the history
  41. Configuration menu
    Copy the full SHA
    9fe73eb View commit details
    Browse the repository at this point in the history
  42. 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.
    benjamn committed Jul 20, 2020
    Configuration menu
    Copy the full SHA
    30e1083 View commit details
    Browse the repository at this point in the history
  43. 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.
    benjamn committed Jul 20, 2020
    Configuration menu
    Copy the full SHA
    73687e1 View commit details
    Browse the repository at this point in the history
  44. Configuration menu
    Copy the full SHA
    17851bb View commit details
    Browse the repository at this point in the history
  45. 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.
    benjamn committed Jul 20, 2020
    Configuration menu
    Copy the full SHA
    7908e6d View commit details
    Browse the repository at this point in the history
  46. Configuration menu
    Copy the full SHA
    43fc12d View commit details
    Browse the repository at this point in the history