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

Revamp CJS and ESM bundling with Rollup (extracted from #4261) #4401

Merged
merged 19 commits into from
Feb 7, 2019

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Feb 1, 2019

To create this PR, I (@benjamn) first squashed all of @rosskevin's commits from PR #4261 into one big commit, then reverted any changes that did not seem essential to the new bundling strategy discussed in that PR. Once that was done, I rebased against origin/release-2.5.0 and fixed the conflicts. With a few more minor tweaks, all tests are now passing (locally, at least).

I will push a few additional changes after this commit, but I wanted to preserve @rosskevin's intentions as much as possible here, since his name is still attached to this commit.

@benjamn benjamn added this to the Release 2.5.0 milestone Feb 1, 2019
@benjamn benjamn self-assigned this Feb 1, 2019
Copy link
Contributor

@rosskevin rosskevin left a comment

Choose a reason for hiding this comment

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

Great, thanks Ben! I can only spot one thing to change based on our conversations elsewhere - removal of browser from all the package.json files

packages/apollo-boost/package.json Outdated Show resolved Hide resolved
@benjamn
Copy link
Member Author

benjamn commented Feb 2, 2019

@hwillson I still need to write some changelog notes about this PR, but I think it's ready for review (whenever you get to it next week).

@rosskevin
Copy link
Contributor

Nice, I am definitely in favor of a cjs bundle for main. Bundles for all will kill interop problems.

@benjamn
Copy link
Member Author

benjamn commented Feb 2, 2019

Yeah, thanks for continuing to push for that. I’m sold now!

@JoviDeCroock
Copy link
Contributor

Great to see the consistency becoming reality in all packages now, only graphql-tag left.

Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

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

Thanks for working on this originally @rosskevin, and revamping it @benjamn!

.gitignore Show resolved Hide resolved
config/jest.config.settings.js Outdated Show resolved Hide resolved
jest.config.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
packages/apollo-client/package.json Outdated Show resolved Hide resolved
tsconfig.json Show resolved Hide resolved
rosskevin and others added 9 commits February 6, 2019 16:19
To create this commit, I (@benjamn) first squashed all of @rosskevin's
commits from PR #4261 into one big commit, then reverted any changes that
did not seem essential to the new bundling strategy discussed in that
PR. Once that was done, I rebased against origin/release-2.5.0 and fixed
the conflicts. With a few more minor tweaks, all tests are passing.

I will push a few additional changes after this commit, but I wanted to
preserve @rosskevin's intentions as much as possible here, since his name
is still attached to this commit.
Type checking should respect the local tsconfig.json file within each package.
@@ -136,7 +139,7 @@ export default class ApolloClient<TCacheShape> implements DataProxy {
}

if (!link || !cache) {
throw new Error(`
throw new InvariantError(`
Copy link
Member Author

Choose a reason for hiding this comment

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

One of the key benefits of ts-invariant over invariant is that the InvariantError class is exposed, so it can be thrown in a way that TypeScript understands (for type-narrowing purposes). The rollup-plugin-invariant transform also knows how to strip this message string in production (because I wrote both packages).

Copy link
Member

Choose a reason for hiding this comment

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

Love ts-invariant!

invariant(
options.query,
'query option is required. You must specify your GraphQL document ' +
'in the query option.',
Copy link
Member Author

@benjamn benjamn Feb 7, 2019

Choose a reason for hiding this comment

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

The preconditions in this function are a good example of over-checking for hypothetical mistakes (if we keep going down this road, where does it end?), but at least we don't have to pay for these error strings in production anymore!

Mixing default and named imports causes Rollup to use both, which leads to
slightly more generated code, on the whole.
@benjamn
Copy link
Member Author

benjamn commented Feb 7, 2019

@hwillson Ready for another look I think!

Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

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

Looks great @benjamn - thanks!

@@ -136,7 +139,7 @@ export default class ApolloClient<TCacheShape> implements DataProxy {
}

if (!link || !cache) {
throw new Error(`
throw new InvariantError(`
Copy link
Member

Choose a reason for hiding this comment

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

Love ts-invariant!

@benjamn benjamn merged commit 39b77e6 into release-2.5.0 Feb 7, 2019
@benjamn benjamn deleted the revamp-cjs-and-esm-bundling branch February 7, 2019 14:10
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 17, 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.

4 participants