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

Merge React Apollo hooks into Apollo Client #5357

Merged
merged 29 commits into from
Sep 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
2c03a0f
Remove specific test matching
hwillson Sep 16, 2019
eca59fe
Dependency updates (peer/dep/devDep) in preparation of RA merge
hwillson Sep 16, 2019
d0eca93
Modernize `OperationVariables` using `Record`
hwillson Sep 16, 2019
c5d872b
TS config changes in preparation of React Apollo being merged in
hwillson Sep 16, 2019
191065c
Bring in React Apollo source
hwillson Sep 16, 2019
d6ef803
Re-export React functionality
hwillson Sep 16, 2019
0f962e0
Typing changes to clear implicit any type errors
hwillson Sep 16, 2019
2e2cb07
Add new global dep exemptions for rollup bundling
hwillson Sep 16, 2019
2418a46
Bundlesize increase to accommodate React code
hwillson Sep 16, 2019
5a102b2
Update all React tests to use async instead of done callbacks
hwillson Sep 17, 2019
6ebacef
Create a new testing bundle
hwillson Sep 19, 2019
a241e09
Remove duplicated `MutationFetchResult`
hwillson Sep 19, 2019
dcf1602
Revert "Create a new testing bundle"
hwillson Sep 21, 2019
0f96dff
Stop building UMD bundles
hwillson Sep 21, 2019
ceedde9
Rollup bundling changes
hwillson Sep 21, 2019
4ecd8e1
Be explicit about root named React exports
hwillson Sep 21, 2019
87c410b
Doc updates to reflect new Apollo Client React API
hwillson Sep 23, 2019
08a2b1e
Merge branch 'release-3.0' into hello-react-apollo
hwillson Sep 23, 2019
68195a9
Pin optimism to 0.11.1
hwillson Sep 23, 2019
c3283dc
Fix TS source links; Exclude API from link checker
hwillson Sep 23, 2019
378bef0
Update all docs deps
hwillson Sep 23, 2019
a36780d
Update fetchOptions to point to new location
hwillson Sep 23, 2019
e6e268c
Revert "Pin optimism to 0.11.1"
benjamn Sep 23, 2019
7ee82b5
`react-dom` no longer needs to be a peer dep
hwillson Sep 23, 2019
b6ab68d
Remove unnecessary `await`s in tests
hwillson Sep 23, 2019
f973610
.npmignore is no longer necessary
hwillson Sep 24, 2019
ef6db11
Change compiled source location from "lib" to "dist"
hwillson Sep 24, 2019
4c7af4e
Adjust publish process to use "dist" as the project root
hwillson Sep 24, 2019
d7db78e
Copy LICENSE into dist during predeploy
hwillson Sep 24, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .npmignore

This file was deleted.

4 changes: 2 additions & 2 deletions config/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ module.exports = {
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
testURL: 'http://localhost',
testMatch: ['<rootDir>/src/**/__tests__/**/*.ts'],
testPathIgnorePatterns: [
'/node_modules/',
'/lib/'
'/dist/'
],
modulePathIgnorePatterns: ['/dist/'],
setupFiles: ['<rootDir>/src/config/jest/setup.ts'],
};
43 changes: 43 additions & 0 deletions config/prepareDist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// The Apollo Client source that is published to npm is located in the
// "dist" directory. This utility script is called just before deploying
// Apollo Client, to make sure the "dist" directory is prepared for publishing.
//
// This script will:
//
// - Copy the current root package.json into "dist" after adjusting it for
// publishing.
// - Copy the supporting files from the root into "dist" (e.g. `README.MD`,
// `LICENSE`, etc.)

const packageJson = require('../package.json');
const fs = require('fs');

// The root package.json is marked as private to prevent publishing
// from happening in the root of the project. This sets the package back to
// public so it can be published from the "dist" directory.
packageJson.private = false;

// Remove package.json items that we don't need to publish
delete packageJson.scripts;
delete packageJson.bundlesize;

// The root package.json points to the CJS/ESM source in "dist", to support
// on-going package development (e.g. running tests, supporting npm link, etc.).
// When publishing from "dist" however, we need to update the package.json
// to point to the files within the same directory.
const distPackageJson = JSON.stringify(
packageJson,
(_key, value) => (
typeof value === 'string' ? value.replace(/\.\/dist\//, '') : value
),
2
);

// Save the modified package.json to "dist"
fs.writeFileSync(`${__dirname}/../dist/package.json`, distPackageJson);

// Copy supporting files into "dist"
const srcDir = `${__dirname}/..`;
const destDir = `${srcDir}/dist`;
fs.copyFileSync(`${srcDir}/README.md`, `${destDir}/README.md`);
fs.copyFileSync(`${srcDir}/LICENSE`, `${destDir}/LICENSE`);
190 changes: 66 additions & 124 deletions config/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,10 @@
import nodeResolve from 'rollup-plugin-node-resolve';
import typescriptPlugin from 'rollup-plugin-typescript2';
import typescript from 'typescript';
import path from 'path';
import fs from 'fs';
import { transformSync } from '@babel/core';
import cjsModulesTransform from '@babel/plugin-transform-modules-commonjs';
import umdModulesTransform from '@babel/plugin-transform-modules-umd';
import invariantPlugin from 'rollup-plugin-invariant';
import { terser as minify } from 'rollup-plugin-terser';

function onwarn(message) {
const suppressed = ['UNRESOLVED_IMPORT', 'THIS_IS_UNDEFINED'];
import packageJson from '../package.json';

if (!suppressed.find(code => message.code === code)) {
return console.warn(message.message);
}
}

const defaultGlobals = {
const globals = {
'apollo-link': 'apolloLink.core',
'tslib': 'tslib',
'ts-invariant': 'invariant',
Expand All @@ -27,124 +14,79 @@ const defaultGlobals = {
'graphql/language/visitor': 'visitor',
'fast-json-stable-stringify': 'stringify',
'@wry/equality': 'wryEquality',
graphql: 'graphql',
react: 'React'
hwillson marked this conversation as resolved.
Show resolved Hide resolved
};

function rollup({
input = './src/index.ts',
outputPrefix = 'apollo-client',
extraGlobals = {},
} = {}) {
const projectDir = path.join(__dirname, '..');
console.info(`Building project esm ${projectDir}`);
const tsconfig = `${projectDir}/tsconfig.json`;
function external(id) {
return Object.prototype.hasOwnProperty.call(globals, id);
}

const globals = {
...defaultGlobals,
...extraGlobals,
function prepareESM() {
return {
input: packageJson.module,
external,
preserveModules: true,
output: {
dir: './dist',
format: 'esm',
sourcemap: true,
},
plugins: [
nodeResolve(),
invariantPlugin({
// Instead of completely stripping InvariantError messages in
// production, this option assigns a numeric code to the
// production version of each error (unique to the call/throw
// location), which makes it much easier to trace production
// errors back to the unminified code where they were thrown,
// where the full error string can be found. See #4519.
errorCodes: true,
}),
]
};
}

function external(id) {
return Object.prototype.hasOwnProperty.call(globals, id);
}

function outputFile(format) {
return `./lib/${outputPrefix}.${format}.js`;
}

function fromSource(format) {
return {
input,
external,
output: {
file: outputFile(format),
format,
sourcemap: true,
},
plugins: [
nodeResolve({
extensions: ['.ts', '.tsx'],
}),
typescriptPlugin({ typescript, tsconfig }),
invariantPlugin({
// Instead of completely stripping InvariantError messages in
// production, this option assigns a numeric code to the
// production version of each error (unique to the call/throw
// location), which makes it much easier to trace production
// errors back to the unminified code where they were thrown,
// where the full error string can be found. See #4519.
errorCodes: true,
}),
],
onwarn,
};
}

function fromESM(toFormat) {
return {
input: outputFile('esm'),
output: {
file: outputFile(toFormat),
format: 'esm',
sourcemap: false,
},
// The UMD bundle expects `this` to refer to the global object. By default
// Rollup replaces `this` with `undefined`, but this default behavior can
// be overridden with the `context` option.
context: 'this',
plugins: [{
transform(source, id) {
const output = transformSync(source, {
inputSourceMap: JSON.parse(fs.readFileSync(id + '.map')),
sourceMaps: true,
plugins: [
[toFormat === 'umd' ? umdModulesTransform : cjsModulesTransform, {
loose: true,
allowTopLevelThis: true,
}],
],
});

// There doesn't seem to be any way to get Rollup to emit a source map
// that goes all the way back to the source file (rather than just to
// the bundle.esm.js intermediate file), so we pass sourcemap:false in
// the output options above, and manually write the CJS and UMD source
// maps here.
fs.writeFileSync(
outputFile(toFormat) + '.map',
JSON.stringify(output.map),
);

return {
code: output.code,
};
}
}],
function prepareCJS() {
return {
input: packageJson.module,
external,
output: {
file: packageJson.main,
format: 'cjs',
sourcemap: true,
exports: 'named'
}
}
}

return [
fromSource('esm'),
fromESM('cjs'),
fromESM('umd'),
{
input: outputFile('cjs'),
output: {
file: outputFile('cjs.min'),
format: 'esm',
},
plugins: [
minify({
mangle: {
toplevel: true,
},
compress: {
global_defs: {
'@process.env.NODE_ENV': JSON.stringify('production'),
},
},
}),
],
function prepareCJSMinified() {
return {
input: packageJson.main,
output: {
file: packageJson.main.replace('.js', '.min.js'),
format: 'cjs',
},
plugins: [
minify({
mangle: {
toplevel: true,
},
compress: {
global_defs: {
'@process.env.NODE_ENV': JSON.stringify('production'),
},
},
}),
],
};
}

function rollup() {
return [
prepareESM(),
prepareCJS(),
prepareCJSMinified()
];
}

Expand Down
19 changes: 12 additions & 7 deletions docs/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ module.exports = {
},
*/
checkLinksOptions: {
exceptions: ['/api/apollo-client/', '/v2.4/api/apollo-client/'],
exceptions: [
'/api/core/',
'/v2.4/api/core/',
'/v2.5/api/core/',
'/v2.6/api/core/',
'/v3.0/api/core/'
],
},
typescriptApiBox: {
data: require('./docs.json'),
filepathPrefix: 'packages/apollo-client/src/',
filepathPrefix: 'src/',
},
sidebarCategories: {
null: ['index', 'why-apollo', 'integrations', 'hooks-migration'],
Expand Down Expand Up @@ -59,14 +65,13 @@ module.exports = {
'recipes/meteor',
'recipes/recompose',
],
'API Reference': [
'api/apollo-client',
'Apollo Client API': [
'api/core',
'api/react-hooks',
'api/react-ssr',
'api/react-testing',
'api/react-ssr',
'api/react-components',
'api/react-hoc',
'api/react-common',
'api/react-hoc'
],
},
},
Expand Down
Loading