Skip to content

Commit

Permalink
Restore @apollo/client/apollo-client.cjs.js bundle for older bundlers.
Browse files Browse the repository at this point in the history
Should resolve issue #8592.
  • Loading branch information
benjamn committed Aug 6, 2021
1 parent 195d279 commit c547113
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
14 changes: 11 additions & 3 deletions config/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,19 @@ export default [
...entryPoints.map(prepareBundle),
// Convert the ESM entry point to a single CJS bundle.
prepareCJS(
'./dist/core/index.js',
'./dist/index.js',
'./dist/apollo-client.cjs.js',
),
// Minify that single CJS bundle.
// The bundlesize check configured in package.json reflects the total size of
// @apollo/client/core (note the /core), rather than @apollo/client, which
// currently includes React-related exports that may not be used by all
// consumers. We are planning to confine those React exports to
// @apollo/client/react in AC4 (see issue #8190).
prepareCJS(
'./dist/core/index.js',
'./dist/apollo-core.cjs.js',
),
prepareCJSMinified(
'./dist/apollo-client.cjs.js',
'./dist/apollo-core.cjs.js',
),
];
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"bundlesize": [
{
"name": "apollo-client",
"path": "./dist/apollo-client.cjs.min.js",
"path": "./dist/apollo-core.cjs.min.js",
"maxSize": "24.6 kB"
}
],
Expand Down
24 changes: 24 additions & 0 deletions scripts/memory/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,30 @@ function makeRegistry(callback, reject) {
return registry;
}

// This is not technically a memory-related test, but it depends on the build
// artifacts generated in the ../../dist directory by `npm run build`, which is
// an assumption shared by the other tests in this file.
describe("@apollo/client/apollo-client.cjs.js", () => {
it("can be imported as a single CommonJS bundle (issue #8592)", () => {
const bundle = require("@apollo/client/apollo-client.cjs.js");

// Very basic test that requiring the bundle worked.
assert.strictEqual(typeof bundle.ApolloClient, "function");
assert.strictEqual(typeof bundle.InMemoryCache, "function");

// TODO This will change in AC4 when we move all React exports to the
// @apollo/client/react entry point (see issue #8190).
assert.strictEqual(typeof bundle.ApolloProvider, "function");

// The CommonJS bundles referred to by the "main" fields in the various
// package.json files that we generate during `npm run build` are all
// independent, non-overlapping bundles, but apollo-client.cjs.js is its own
// bundle, so importing it duplicates everything.
assert.notStrictEqual(bundle.ApolloClient, ApolloClient);
assert.notStrictEqual(bundle.InMemoryCache, InMemoryCache);
});
});

describe("garbage collection", () => {
itAsync("should collect client.cache after client.stop()", (resolve, reject) => {
const expectedKeys = new Set([
Expand Down

0 comments on commit c547113

Please sign in to comment.