diff --git a/common/package.json b/common/package.json new file mode 100644 index 00000000000..dff04bc8006 --- /dev/null +++ b/common/package.json @@ -0,0 +1,12 @@ +{ + "name": "@apollo/client/common", + "description": "@apollo/client without React", + "author": "opensource@apollographql.com", + "license": "MIT", + "main": "./dist/common/apollo-client.cjs.js", + "module": "./dist/common/index.js", + "types": "./dist/common/index.d.ts", + "sideEffects": [ + "./dist/cache/inmemory/fixPolyfills.js" + ] +} diff --git a/config/prepareDist.js b/config/prepareDist.js index 880b870e722..2fd87a8aced 100644 --- a/config/prepareDist.js +++ b/config/prepareDist.js @@ -10,6 +10,7 @@ // `LICENSE`, etc.) const packageJson = require('../package.json'); +const commonPackageJson = require('../common/package.json'); const fs = require('fs'); // The root package.json is marked as private to prevent publishing @@ -33,8 +34,17 @@ const distPackageJson = JSON.stringify( 2 ); +const distCommonPackageJson = JSON.stringify( + commonPackageJson, + (_key, value) => ( + typeof value === 'string' ? value.replace(/\.\/dist\/common\//, './').replace(/\.\/dist\//, '../') : value + ), + 2 +); + // Save the modified package.json to "dist" fs.writeFileSync(`${__dirname}/../dist/package.json`, distPackageJson); +fs.writeFileSync(`${__dirname}/../dist/common/package.json`, distCommonPackageJson); // Copy supporting files into "dist" const srcDir = `${__dirname}/..`; diff --git a/config/rollup.config.js b/config/rollup.config.js index 3a11b9ed83b..a9635a8b06c 100644 --- a/config/rollup.config.js +++ b/config/rollup.config.js @@ -5,11 +5,13 @@ import cjs from 'rollup-plugin-commonjs'; import fs from 'fs'; import packageJson from '../package.json'; +import commonPackageJson from '../common/package.json'; const distDir = './dist'; +const distCommonDir = `${distDir}/common`; const globals = { - 'tslib': 'tslib', + tslib: 'tslib', 'ts-invariant': 'invariant', 'symbol-observable': '$$observable', 'graphql/language/printer': 'print', @@ -21,7 +23,7 @@ const globals = { '@wry/equality': 'wryEquality', graphql: 'graphql', react: 'React', - 'zen-observable': 'Observable' + 'zen-observable': 'Observable', }; const hasOwn = Object.prototype.hasOwnProperty; @@ -30,12 +32,17 @@ function external(id) { return hasOwn.call(globals, id); } -function prepareESM() { +/** + * + * @param {string} input + * @param {string} outputDir + */ +function prepareESM(input, outputDir) { return { - input: packageJson.module, + input, // packageJson.module, external, output: { - dir: distDir, + dir: outputDir, // distDir, format: 'esm', sourcemap: true, }, @@ -58,39 +65,49 @@ function prepareESM() { }), cjs({ namedExports: { - 'graphql-tag': ['gql'] - } + 'graphql-tag': ['gql'], + }, }), - ] + ], }; } -function prepareCJS() { +/** + * + * @param {string} input + * @param {string} outputDir + */ +function prepareCJS(input, output) { return { - input: packageJson.module, + input, // packageJson.module, external, output: { - file: packageJson.main, + file: output, // packageJson.main, format: 'cjs', sourcemap: true, - exports: 'named' + exports: 'named', }, plugins: [ nodeResolve(), cjs({ namedExports: { - 'graphql-tag': ['gql'] - } + 'graphql-tag': ['gql'], + }, }), - ] - } + ], + }; } -function prepareCJSMinified() { +/** + * + * @param {string} input + * @param {string} outputDir + */ +function prepareCJSMinified(input) { return { - input: packageJson.main, + input, // packageJson.main, output: { - file: packageJson.main.replace('.js', '.min.js'), + file: input.replace('.js', '.min.js'), // packageJson.main.replace('.js', '.min.js'), format: 'cjs', }, plugins: [ @@ -128,7 +145,7 @@ function prepareTesting() { const testingGlobals = { ...globals, - [`../../${apolloProviderPath}`]: 'ApolloProvider' + [`../../${apolloProviderPath}`]: 'ApolloProvider', }; const output = { @@ -140,12 +157,12 @@ function prepareTesting() { // `react/testing` type definitions. fs.writeFileSync( `${distDir}/${bundleName}.d.ts`, - "export * from './react/testing';" + "export * from './react/testing';", ); return { input: `${distDir}/react/testing/index.js`, - external: (id) => hasOwn.call(testingGlobals, id), + external: id => hasOwn.call(testingGlobals, id), output, plugins: [ nodeResolve({ @@ -160,24 +177,30 @@ function prepareTesting() { const bundleJs = `${bundleName}.js`; return { generateBundle(_option, bundle) { - bundle[bundleJs].code = - bundle[bundleJs].code.replace( - `../${apolloProviderPath}`, - packageJson.main.replace(distDir, '.') - ); - } - } - })() + bundle[bundleJs].code = bundle[bundleJs].code.replace( + `../${apolloProviderPath}`, + packageJson.main.replace(distDir, '.'), + ); + }, + }; + })(), ], }; } function rollup() { return [ - prepareESM(), - prepareCJS(), - prepareCJSMinified(), - prepareTesting() + // @apollo/client + prepareESM(packageJson.module, distDir), + prepareCJS(packageJson.module, packageJson.main), + prepareCJSMinified(packageJson.main), + prepareTesting(), + // @apollo/client/common + prepareCJS( + commonPackageJson.module, + commonPackageJson.main, + ), + prepareCJSMinified(commonPackageJson.main), ]; } diff --git a/package.json b/package.json index 7c352e551e6..badaeef5839 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@apollo/client", - "version": "3.0.0-beta.1", + "version": "3.0.0-beta.2", "description": "A fully-featured caching GraphQL client.", "private": true, "keywords": [ @@ -42,7 +42,7 @@ "bundlesize": "npm run build && bundlesize", "prepdist": "node ./config/prepareDist.js", "predeploy": "npm run build && npm run prepdist", - "deploy": "cd dist && npm publish --tag beta" + "deploy": "cd dist && npm publish --tag beta --registry http://localhost:4873" }, "bundlesize": [ { diff --git a/src/common/index.ts b/src/common/index.ts new file mode 100644 index 00000000000..1a04870c3a2 --- /dev/null +++ b/src/common/index.ts @@ -0,0 +1,84 @@ +/* Core */ + +export { + ApolloClient, + ApolloClientOptions, + DefaultOptions +} from '../ApolloClient'; +export { + ObservableQuery, + FetchMoreOptions, + UpdateQueryOptions, + ApolloCurrentQueryResult, +} from '../core/ObservableQuery'; +export { + QueryBaseOptions, + QueryOptions, + WatchQueryOptions, + MutationOptions, + SubscriptionOptions, + FetchPolicy, + WatchQueryFetchPolicy, + ErrorPolicy, + FetchMoreQueryOptions, + SubscribeToMoreOptions, + MutationUpdaterFn, +} from '../core/watchQueryOptions'; +export { NetworkStatus } from '../core/networkStatus'; +export * from '../core/types'; +export { + Resolver, + FragmentMatcher as LocalStateFragmentMatcher, +} from '../core/LocalState'; +export { isApolloError, ApolloError } from '../errors/ApolloError'; + +/* Cache */ + +export { Transaction, ApolloCache } from '../cache/core/cache'; +export { Cache } from '../cache/core/types/Cache'; +export { DataProxy } from '../cache/core/types/DataProxy'; +export { + InMemoryCache, + InMemoryCacheConfig, +} from '../cache/inmemory/inMemoryCache'; +export { defaultDataIdFromObject } from '../cache/inmemory/policies'; +export * from '../cache/inmemory/types'; + +/* Link */ + +export { empty } from '../link/core/empty'; +export { from } from '../link/core/from'; +export { split } from '../link/core/split'; +export { concat } from '../link/core/concat'; +export { execute } from '../link/core/execute'; +export { ApolloLink } from '../link/core/ApolloLink'; +export * from '../link/core/types'; +export { + parseAndCheckHttpResponse, + ServerParseError +} from '../link/http/parseAndCheckHttpResponse'; +export { + serializeFetchParameter, + ClientParseError +} from '../link/http/serializeFetchParameter'; +export { + HttpOptions, + fallbackHttpConfig, + selectHttpOptionsAndBody, + UriFunction +} from '../link/http/selectHttpOptionsAndBody'; +export { checkFetcher } from '../link/http/checkFetcher'; +export { createSignalIfSupported } from '../link/http/createSignalIfSupported'; +export { selectURI } from '../link/http/selectURI'; +export { createHttpLink } from '../link/http/createHttpLink'; +export { HttpLink } from '../link/http/HttpLink'; +export { fromError } from '../link/utils/fromError'; +export { ServerError, throwServerError } from '../link/utils/throwServerError'; + +/* Utilities */ + +export { Observable } from '../utilities/observables/Observable'; + +/* Supporting */ + +export { default as gql } from 'graphql-tag';