From 6edab0c62d1dbc2063d29fb1a219a9a6ef954b02 Mon Sep 17 00:00:00 2001 From: Victor Vlasenko Date: Thu, 3 Nov 2016 09:44:22 +0200 Subject: [PATCH] Better packaging Provide compiled sources from 'lib' for node modules. Provide all API exports from index.js. This is breaking change. As a side effect this change fixes file paths in Stack Traces when react-apollo throws exceptions. --- Changelog.md | 11 +++++++++++ examples/create-react-app/src/App.js | 2 +- examples/create-react-app/src/Pokemon.js | 2 +- examples/create-react-app/src/Pokemon.test.js | 2 +- package.json | 16 +++++++++++++--- src/browser.ts | 5 +++++ src/index.ts | 8 ++------ tsconfig.json | 2 +- 8 files changed, 35 insertions(+), 13 deletions(-) create mode 100644 src/browser.ts diff --git a/Changelog.md b/Changelog.md index d76f76caee..100db087d5 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,17 @@ Expect active development and potentially significant breaking changes in the `0 ### vNext +#### Breaking +```js +// old +import { getDataFromTree, renderToStringWithData } from 'react-apollo/server' + +// new +import { getDataFromTree, renderToStringWithData } from 'react-apollo' +``` + +- Feature: Better packaging [PR #306](https://github.com/apollostack/react-apollo/pull/306) + ### v0.5.15 - Feature: Added test utilities and examples to library. diff --git a/examples/create-react-app/src/App.js b/examples/create-react-app/src/App.js index 54ee5397a8..fdeb8362a0 100644 --- a/examples/create-react-app/src/App.js +++ b/examples/create-react-app/src/App.js @@ -1,6 +1,6 @@ import React, { Component } from 'react'; import ApolloClient, { createNetworkInterface } from 'apollo-client'; -import { ApolloProvider } from "../../../lib/src"; +import { ApolloProvider } from "../../../lib"; import Pokemon from "./Pokemon"; diff --git a/examples/create-react-app/src/Pokemon.js b/examples/create-react-app/src/Pokemon.js index 8112141c48..506a43754d 100644 --- a/examples/create-react-app/src/Pokemon.js +++ b/examples/create-react-app/src/Pokemon.js @@ -1,6 +1,6 @@ import React from 'react'; import gql from 'graphql-tag'; -import { graphql } from '../../../lib/src'; +import { graphql } from '../../../lib'; // The data prop, which is provided by the wrapper below contains, // a `loading` key while the query is in flight and posts when it is ready diff --git a/examples/create-react-app/src/Pokemon.test.js b/examples/create-react-app/src/Pokemon.test.js index dc6da70986..6c6fe302ee 100644 --- a/examples/create-react-app/src/Pokemon.test.js +++ b/examples/create-react-app/src/Pokemon.test.js @@ -1,6 +1,6 @@ import React from 'react'; import renderer from 'react-test-renderer'; -import { MockedProvider } from '../../../lib/src/test-utils'; +import { MockedProvider } from '../../../lib/test-utils'; import { print } from 'graphql-tag/printer'; import { addTypenameToDocument } from 'apollo-client/queries/queryTransform'; diff --git a/package.json b/package.json index 5a3b16eb84..914caeda7c 100644 --- a/package.json +++ b/package.json @@ -2,15 +2,16 @@ "name": "react-apollo", "version": "0.5.16", "description": "React data container for Apollo Client", - "main": "index.js", - "typings": "index.d.ts", + "main": "lib/index.js", + "browser": "lib/browser.js", + "typings": "lib/index.d.ts", "scripts": { "test": "jest", "flow": "flow; test $? -eq 0 -o $? -eq 2", "posttest": "npm run lint", "filesize": "npm run compile:browser && ./scripts/filesize.js --file=./dist/index.min.js --maxGzip=15", "compile": "tsc", - "compile:browser": "rm -rf ./dist && mkdir ./dist && browserify ./lib/src/index.js --i react --i apollo-client -o=./dist/index.js && npm run minify:browser", + "compile:browser": "rm -rf ./dist && mkdir ./dist && browserify ./lib/index.js --i react --i apollo-client -o=./dist/index.js && npm run minify:browser", "minify:browser": "uglifyjs --compress --mangle --screw-ie8 -o=./dist/index.min.js -- ./dist/index.js", "watch": "tsc -w", "lint": "tslint 'src/*.ts*' && tslint 'test/*.ts*'" @@ -48,6 +49,15 @@ "collectCoverage": true }, "license": "MIT", + "files": [ + "dist", + "lib", + "src", + "exports.d.ts", + "CHANGELOG.md", + "LICENSE", + "README.md" + ], "peerDependencies": { "apollo-client": "^0.4.21 || ^0.5.0", "react": "0.14.x || 15.* || ^15.0.0", diff --git a/src/browser.ts b/src/browser.ts new file mode 100644 index 0000000000..fedf3d7911 --- /dev/null +++ b/src/browser.ts @@ -0,0 +1,5 @@ +export { default as ApolloProvider } from './ApolloProvider'; +export { default as graphql, withApollo } from './graphql'; + +// expose easy way to join queries from redux +export { compose } from 'redux'; diff --git a/src/index.ts b/src/index.ts index 3c221adee3..5d975c33e4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,7 +1,3 @@ -import ApolloProvider from './ApolloProvider'; -import graphql, { withApollo } from './graphql'; +export * from './browser'; -// expose easy way to join queries from redux -import { compose } from 'redux'; - -export { ApolloProvider, graphql, withApollo, compose }; +export { getDataFromTree, renderToStringWithData } from './server'; diff --git a/tsconfig.json b/tsconfig.json index 1aaad176aa..e785fee9fa 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -7,7 +7,7 @@ "sourceMap": true, "declaration": true, "noImplicitAny": false, - "rootDir": ".", + "rootDir": "src", "outDir": "lib", "allowSyntheticDefaultImports": true, "experimentalDecorators": true,