From 655470b5dcd7ecb27383e347833278eaa3c0214c Mon Sep 17 00:00:00 2001 From: Kamil Kisiela Date: Sat, 12 Aug 2017 13:17:15 +0200 Subject: [PATCH] Release v0.6.0-rc.1 (#46) * Release v0.6.0-rc.1 * Fix an issue with lift method in TypeScript 2.4 (#47) * Fix an issue with lift method in TypeScript 2.4 * Add it to changelog * Deploy script (#48) * Add it to changelog * Deploy script * Fix changelog * Remove auto-releasing in Travis --- .gitignore | 3 ++ .npmignore | 2 + .travis.yml | 9 ----- .vscode/settings.json | 5 ++- CHANGELOG.md | 6 ++- package.json | 45 +++++++++++----------- rollup.config.js | 44 +++++++++++++++------- scripts/deploy.sh | 46 +++++++++++++++++++++++ src/RxObservableQuery.ts | 6 +-- src/utils/variables.ts | 2 +- tests/RxApolloClient/watchQuery.ts | 8 ++-- tests/RxObservableQuery.ts | 39 +++++++++++++++---- tests/rxify.ts | 11 ++++-- tests/utils/variables/observeVariables.ts | 20 +++++----- tsconfig.json | 2 +- tslint.json | 2 +- 16 files changed, 171 insertions(+), 79 deletions(-) create mode 100755 scripts/deploy.sh diff --git a/.gitignore b/.gitignore index 8f09ef4..989eef4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ build/ coverage/ node_modules/ +npm/ npm-debug.log +package-lock.json +yarn.lock diff --git a/.npmignore b/.npmignore index c3429c9..c4bd052 100644 --- a/.npmignore +++ b/.npmignore @@ -2,8 +2,10 @@ build/tests/ src/ tests/ docs/ +scripts/ .travis.yml CHANGELOG.md +rollup.config.js tsconfig.json tsconfig.test.json tslint.json diff --git a/.travis.yml b/.travis.yml index fcab5a2..dfcd34d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,12 +23,3 @@ script: after_script: - npm run coverage - coveralls < ./coverage/lcov.info || true - -deploy: - provider: npm - email: kamil.kisiela@gmail.com - api_key: - secure: x3/5lQkR2VyN1CXsIxvf2a8intwP00ak984MFu0UIT1y37OI6bmdV3ea5AL5j85NIM0J2qHa4wx1Yu2cXdNmmHnaeI/rScVoKh/QCYsweaAh7Mz9D3kdQZcGdLh0WCRqpQLAUIfZilnmRty9hqpTkoKUQHiJXSAISFA4fOj/a5LC8fuGqhKHp45ezohJTDAKnVFxqSvzKYY+4oX4or4vzeguyE/OJqwFjJn28o+hkh9lK4+QxUkM7qCp8uow0DCzNvNQBFdPH3yANQMGlmrK/P/K1ZxXczn45fS7Y4JsgcpUrTtoRL0DZU13L0AClcYa3HtTEeco1UIqWhtGBHEfCtZMw0mdLCfrHOs538bzlvMW9SgTHFZT1sCrPS/9Ka/n7bY+nUv8edoLVlEzzrKHHjz/TuLvHfuWwcIfWl6+xpKsuqiNWE9rwBbaiz+g3xL+oZ98qPC6UFsr9udnHvzEh4OoKWMDbh0UZkFyYZ7Lmr1yJ8ahKyfSi505O5byPuVG75yN4RqB416gzDq/Q122Rp7HZtq+wR15AwOLsKfLVzTFIYLcN5BtqXRkFBqC1cSiNtLsZZvRrq/Aq3euLw7F8ANib5W5EllkMWlwyTEIxypAZp2KtX9ZThkPBI6Y9YedK6PaosqviICAXQ6cupwGvwcE54bE0D5a4vrb3MvvUHU= - on: - tags: true - repo: kamilkisiela/apollo-client-rxjs diff --git a/.vscode/settings.json b/.vscode/settings.json index e676897..9c7b24f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,9 +7,10 @@ "files.exclude": { "**/.git": true, "**/.DS_Store": true, - "node_modules/**": true, + "node_modules": true, "build": true, - "coverage": true + "coverage": true, + "npm": true }, "typescript.tsdk": "node_modules/typescript/lib" } diff --git a/CHANGELOG.md b/CHANGELOG.md index 0532b2b..daaeaf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # Change log -### vNEXT +### v0.6.0-rc.1 + +- Fix the lift method (an issue since TypeScript 2.4) [PR #47](https://github.com/kamilkisiela/apollo-client-rxjs/pull/47) +- Update dependencies to latest [PR #47](https://github.com/kamilkisiela/apollo-client-rxjs/pull/47) +- Add a deploy script to keep compiled filed in the root directory [PR #48](https://github.com/kamilkisiela/apollo-client-rxjs/pull/48) ### v0.5.2 diff --git a/package.json b/package.json index 5cf71d2..b47f530 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "apollo-client-rxjs", - "version": "0.5.2", + "version": "0.6.0-rc.1", "description": "Adds RxJS to ApolloClient", "author": "Kamil Kisiela ", "license": "MIT", @@ -29,7 +29,7 @@ "test-watch": "mocha --reporter spec --full-trace build/tests/index.js --watch", "coverage": "istanbul cover ./node_modules/mocha/bin/_mocha -- --reporter dot --full-trace build/tests/index.js", "postcoverage": "remap-istanbul --input coverage/coverage.json --type lcovonly --output coverage/lcov.info", - "lint": "tslint src/**/*.ts && tslint tests/*.ts", + "lint": "tslint src/**/*.ts && tslint tests/**/*.ts", "prebuild": "npm run clean:build", "build": "tsc", "build-test": "tsc -p tsconfig.test.json", @@ -39,32 +39,33 @@ "clean": "npm run clean:build && npm run clean:coverage", "clean:build": "rimraf build/*", "clean:coverage": "rimraf coverage/*", - "prepublish": "npm run clean && npm run build" + "prepare": "npm run clean && npm run build", + "deploy": "./scripts/deploy.sh" }, "peerDependencies": { - "apollo-client": ">=0.7.2 <=0.10.1 || >=1.0.0-beta <2.0.0", - "rxjs": "^5.0.0-beta.12 || ^5.0.0-rc.1 || ^5.0.0" + "apollo-client": ">=1.0.0-beta <2.0.0", + "rxjs": "^5.0.0-beta.12 || >=5.0.0-rc.1 <6.0.0" }, "devDependencies": { - "@types/chai": "^3.4.35", - "@types/mocha": "^2.2.40", - "@types/node": "^6.0.38", - "@types/sinon": "^1.16.35", - "apollo-client": "^1.0.0-rc.2", - "apollo-test-utils": "^0.2.0", - "chai": "^3.5.0", - "graphql": "^0.9.1", - "graphql-tag": "^1.3.1", + "@types/chai": "^4.0.2", + "@types/mocha": "^2.2.41", + "@types/node": "^8.0.20", + "@types/sinon": "^2.3.3", + "apollo-client": "^1.9.1", + "apollo-test-utils": "^0.3.2", + "chai": "^4.1.1", + "graphql": "^0.10.5", + "graphql-tag": "^2.4.2", "isomorphic-fetch": "^2.2.1", "istanbul": "^0.4.5", - "mocha": "^3.2.0", - "remap-istanbul": "^0.9.1", + "mocha": "^3.5.0", + "remap-istanbul": "^0.9.5", "rimraf": "^2.6.1", - "rollup": "^0.41.5", - "rxjs": "^5.2.0", - "sinon": "^2.0.0", - "source-map-support": "^0.4.12", - "tslint": "^4.5.1", - "typescript": "^2.2.1" + "rollup": "^0.45.2", + "rxjs": "^5.4.2", + "sinon": "^3.2.0", + "source-map-support": "^0.4.15", + "tslint": "^5.6.0", + "typescript": "^2.4.2" } } diff --git a/rollup.config.js b/rollup.config.js index 080f2fa..3e91a5f 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,23 +1,39 @@ +const globals = { + 'apollo-client': 'apollo', + 'rxjs/Observable': 'Rx', + 'rxjs/Observer': 'Rx', + 'rxjs/Subscription': 'Rx', + 'rxjs/Subscriber': 'Rx', + 'rxjs/Operator': 'Rx', + + 'rxjs/symbol/observable': 'Rx.Symbol', + + 'rxjs/scheduler/AsyncScheduler': 'Rx.Scheduler.async', + + 'rxjs/observable/combineLatest': 'Rx.Observable', + + 'rxjs/operator/observeOn': 'Rx.Observable.prototype', + 'rxjs/operator/switchMap': 'Rx.Observable.prototype' +} + export default { entry: 'build/src/index.js', dest: 'build/bundles/apollo-rxjs.umd.js', format: 'umd', + sourceMap: true, + exports: 'named', moduleName: 'apollo.rxjs', - globals: { - 'apollo-client': 'apollo', - 'rxjs/Observable': 'Rx', - 'rxjs/Observer': 'Rx', - 'rxjs/Subscription': 'Rx', - 'rxjs/Subscriber': 'Rx', - 'rxjs/Operator': 'Rx', - - 'rxjs/symbol/observable': 'Rx.Symbol', - - 'rxjs/scheduler/AsyncScheduler': 'Rx.Scheduler.async', + globals, + onwarn +} - 'rxjs/observable/combineLatest': 'Rx.Observable', +function onwarn(message) { + const suppressed = [ + 'UNRESOLVED_IMPORT', + 'THIS_IS_UNDEFINED' + ]; - 'rxjs/operator/observeOn': 'Rx.Observable.prototype', - 'rxjs/operator/switchMap': 'Rx.Observable.prototype' + if (!suppressed.find(code => message.code === code)) { + return console.warn(message.message); } } diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100755 index 0000000..795931e --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,46 @@ +#!/bin/sh -e + + +# When we publish to npm, the published files are available in the root +# directory, which allows for a clean include or require of sub-modules. +# +# var language = require('apollo-client-rxjs/rxify'); +# + +# Clear the built output +rm -rf ./build + +# Compile new files +npm run build + +# Make sure the ./npm directory is empty +rm -rf ./npm +mkdir ./npm + +# Copy all files from ./lib/src to /npm +cd ./build/src && cp -r ./ ../../npm/ +# Copy also the umd bundle with the source map file +cd ../bundles +cp apollo-rxjs.umd.js ../../npm/ && cp apollo-rxjs.umd.js.map ../../npm/ + +# Back to the root directory +cd ../../ + +# Ensure a vanilla package.json before deploying so other tools do not interpret +# The built output as requiring any further transformation. +node -e "var package = require('./package.json'); \ + delete package.scripts; \ + delete package.devDependencies; \ + package.main = 'apollo-rxjs.umd.js'; \ + package.module = 'index.js'; \ + package.typings = 'index.d.ts'; \ + var fs = require('fs'); \ + fs.writeFileSync('./npm/package.json', JSON.stringify(package, null, 2)); \ + " + + +# Copy few more files to ./npm +cp README.md npm/ + +echo 'deploying to npm...' +cd npm && npm publish && git push --tags diff --git a/src/RxObservableQuery.ts b/src/RxObservableQuery.ts index 0e93b16..ebbfeb6 100644 --- a/src/RxObservableQuery.ts +++ b/src/RxObservableQuery.ts @@ -19,13 +19,13 @@ export class RxObservableQuery extends Observable> { } } - public lift(operator: Operator, ApolloQueryResult>): Observable> { + public lift(operator: Operator, R>): Observable { const observable = new RxObservableQuery(this.apollo); observable.source = this; - observable.operator = operator; + observable.operator = operator as any; - return observable; + return observable as any; } // apollo-specific methods diff --git a/src/utils/variables.ts b/src/utils/variables.ts index fc440b0..d9ee209 100644 --- a/src/utils/variables.ts +++ b/src/utils/variables.ts @@ -46,7 +46,7 @@ export function observeVariables(variables?: Object): Observable { observer.next(resultVariables); }); }); -}; +} function mapVariablesToObservables(variables?: Object): Observable[] { return Object.keys(variables) diff --git a/tests/RxApolloClient/watchQuery.ts b/tests/RxApolloClient/watchQuery.ts index 27ecf15..bc2b0be 100644 --- a/tests/RxApolloClient/watchQuery.ts +++ b/tests/RxApolloClient/watchQuery.ts @@ -12,7 +12,7 @@ describe('RxApolloClient.watchQuery', () => { it('should get the result', (done) => { const obs = client.watchQuery({ - query: heroes.query + query: heroes.query, }); obs.subscribe({ @@ -22,13 +22,13 @@ describe('RxApolloClient.watchQuery', () => { }, error() { done(new Error('should not be called')); - } + }, }); }); it('should be able to refetch', (done) => { const obs = client.watchQuery({ - query: heroes.query + query: heroes.query, }); obs.subscribe({ @@ -37,7 +37,7 @@ describe('RxApolloClient.watchQuery', () => { }, error() { done(new Error('should not be called')); - } + }, }); obs.refetch(heroes.variables).then(({data}) => { diff --git a/tests/RxObservableQuery.ts b/tests/RxObservableQuery.ts index 5639fe3..82f27f2 100644 --- a/tests/RxObservableQuery.ts +++ b/tests/RxObservableQuery.ts @@ -1,6 +1,6 @@ import { assert } from 'chai'; import { spy, stub } from 'sinon'; -import { ApolloClient, ObservableQuery } from 'apollo-client'; +import { ApolloClient, ObservableQuery, ApolloQueryResult } from 'apollo-client'; import * as heroes from './fixtures/heroes'; import { RxObservableQuery } from '../src/RxObservableQuery'; @@ -8,6 +8,7 @@ import { ObservableQueryRef } from '../src/utils/ObservableQueryRef'; import 'rxjs/add/operator/map'; import 'rxjs/add/operator/do'; +import 'rxjs/add/operator/filter'; describe('RxObservableQuery', () => { let obsQuery: ObservableQuery; @@ -56,7 +57,9 @@ describe('RxObservableQuery', () => { }); it('should be able to use a operator', (done: MochaDone) => { - rxObsQuery.map(result => result.data).subscribe({ + rxObsQuery + .map(result => result.data) + .subscribe({ next(result) { assert.deepEqual(result, heroes.data); done(); @@ -67,6 +70,26 @@ describe('RxObservableQuery', () => { }); }); + it('should be able to use multiple operators', (done: MochaDone) => { + function onlyFoo(hero: heroes.Hero): boolean { + return !!hero.name.match(/foo/i); + } + + rxObsQuery + .map, heroes.Hero[]> + (result => result.data.allHeroes.heroes) + .map(heroes => heroes.filter(onlyFoo)) + .subscribe({ + next(result) { + assert.deepEqual(result, heroes.data.allHeroes.heroes.filter(onlyFoo)); + done(); + }, + error() { + done(new Error('should not be called')); + }, + }); + }); + it('should be chainable', (done: MochaDone) => { const counter = { calls: 0 }; @@ -97,7 +120,7 @@ describe('RxObservableQuery', () => { const promise = rxObsQuery.refetch(heroes.variables); assert.deepEqual(stubbed.args[0], [heroes.variables]); - assert.equal(promise, 'promise'); + assert.equal(promise, 'promise' as any); }); it('should be able to startPolling', () => { @@ -121,7 +144,7 @@ describe('RxObservableQuery', () => { const promise = rxObsQuery.fetchMore(options); assert.deepEqual(stubbed.args[0], [options]); - assert.equal(promise, 'promise'); + assert.equal(promise, 'promise' as any); }); it('should be able to subscribeToMore', () => { @@ -130,7 +153,7 @@ describe('RxObservableQuery', () => { const fn = rxObsQuery.subscribeToMore(options); assert.deepEqual(stubbed.args[0], [options]); - assert.equal(fn, 'fn'); + assert.equal(fn, 'fn' as any); }); it('should be able to updateQuery', () => { @@ -148,7 +171,7 @@ describe('RxObservableQuery', () => { stub(obsQuery, 'result').returns('promise'); const promise = rxObsQuery.result(); - assert.equal(promise, 'promise'); + assert.equal(promise, 'promise' as any); }); it('should be able to use currentResult', () => { @@ -168,7 +191,7 @@ describe('RxObservableQuery', () => { const promise = rxObsQuery.setOptions(options); assert.deepEqual(stubbed.args[0], [options]); - assert.equal(promise, 'promise'); + assert.equal(promise, 'promise' as any); }); it('should be able to setVariables', () => { @@ -177,7 +200,7 @@ describe('RxObservableQuery', () => { const promise = rxObsQuery.setVariables(variables); assert.deepEqual(stubbed.args[0], [variables, false]); - assert.equal(promise, 'promise'); + assert.equal(promise, 'promise' as any); }); }); }); diff --git a/tests/rxify.ts b/tests/rxify.ts index 787ba33..2b098e6 100644 --- a/tests/rxify.ts +++ b/tests/rxify.ts @@ -3,6 +3,7 @@ import { Subject } from 'rxjs/Subject'; import { ApolloClient } from 'apollo-client'; import { rxify } from '../src/rxify'; +import { RxObservableQuery } from '../src/RxObservableQuery'; import * as heroes from './fixtures/heroes'; @@ -37,8 +38,12 @@ describe('rxify', () => { }); describe('watchQuery', () => { + const watchQuery = (options: Object): RxObservableQuery => { + return new RxObservableQuery(rxify(client.watchQuery)(options)); + }; + it('should be able to subscribe', (done) => { - rxify(client.watchQuery)({ query: heroes.query }) + watchQuery({ query: heroes.query }) .map(result => result.data) .subscribe({ next(data) { @@ -54,7 +59,7 @@ describe('rxify', () => { it('should be able to use observable variables', (done) => { const hero = new Subject(); - const obs = rxify(client.watchQuery)({ + const obs = watchQuery({ query: heroes.queryWithVariables, variables: { hero }, }); @@ -75,7 +80,7 @@ describe('rxify', () => { it('should be able to use operator and observable variables', (done) => { const hero = new Subject(); - const obs = rxify(client.watchQuery)({ + const obs = watchQuery({ query: heroes.queryWithVariables, variables: { hero }, }).map(result => result.data); diff --git a/tests/utils/variables/observeVariables.ts b/tests/utils/variables/observeVariables.ts index 446f09c..8bd32a9 100644 --- a/tests/utils/variables/observeVariables.ts +++ b/tests/utils/variables/observeVariables.ts @@ -6,10 +6,10 @@ import { observeVariables } from '../../../src/utils/variables'; describe('observeVariables', () => { it('should handle primitive values', (done) => { const variables = { - foo: 'first' + foo: 'first', }; const result = { - foo: 'first' + foo: 'first', }; observeVariables(variables).subscribe((newVariables: any) => { @@ -25,9 +25,9 @@ describe('observeVariables', () => { }; const results = [{ - foo: 'first' + foo: 'first', }, { - foo: 'second' + foo: 'second', }]; observeVariables(variables).subscribe((newVariables: any) => { @@ -46,15 +46,15 @@ describe('observeVariables', () => { const counter = { calls: 0 }; const variables = { foo: new Subject(), - bar: new Subject() + bar: new Subject(), }; const results = [{ foo: 'foo 1', - bar: 'bar 1' + bar: 'bar 1', }, { foo: 'foo 1', - bar: 'bar 2' + bar: 'bar 2', }]; observeVariables(variables).subscribe((newVariables: any) => { @@ -86,7 +86,7 @@ describe('observeVariables', () => { }, { foo: 'foo 1', bar: 'bar 2', - baz: 'baz 1' + baz: 'baz 1', }]; observeVariables(variables).subscribe((newVariables: any) => { @@ -105,10 +105,10 @@ describe('observeVariables', () => { it('should transform undefined variables to be null', (done) => { const variables = { - foo: undefined + foo: undefined, }; const result = { - foo: null + foo: null, }; observeVariables(variables).subscribe((newVariables: any) => { diff --git a/tsconfig.json b/tsconfig.json index 9946f80..1120d27 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,7 @@ { "compilerOptions": { "target": "es5", - "lib": ["es6", "dom"], + "lib": ["es2015", "dom", "esnext.asynciterable"], "module": "es2015", "moduleResolution": "node", "removeComments": true, diff --git a/tslint.json b/tslint.json index 530e38d..a0eda3e 100644 --- a/tslint.json +++ b/tslint.json @@ -57,7 +57,7 @@ "no-switch-case-fall-through": true, "no-trailing-whitespace": true, "no-unused-expression": true, - "no-use-before-declare": true, + "no-use-before-declare": false, "no-var-keyword": true, "no-var-requires": true, "object-literal-sort-keys": false,