Skip to content

fix(typescript): use correct ts version and fix promise types #510

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

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ before_script:
script:
- npm run build
- ./node_modules/.bin/karma start --single-run --browsers Firefox --reporters mocha
# Make sure the build that ships to npm builds without errors
- npm run build_npm
# Can't run until https://github.com/angular/protractor/issues/2784 is resolved
#- ./node_modules/.bin/protractor protractor.conf.js --browser firefox

Expand Down
22 changes: 21 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,27 @@
* **utils:** Add $exists method to AFUnwrappedSnapshot ([#471](https://github.com/angular/angularfire2/issues/471)) ([f67aab1](https://github.com/angular/angularfire2/commit/f67aab1))
* upgrade to RC7 ([#505](https://github.com/angular/angularfire2/issues/505)) ([2410b2d](https://github.com/angular/angularfire2/commit/2410b2d))

### BREAKING CHANGES

The way this project is packaged has changed to be consistent with other Angular packages.
Previously:

* The project just consisted of CommonJS modules, with `angularfire2.js` as the main entry point.
* The project provided an `es6` directory which contained es2015 modules and es2015 JS
* Package.json included `main` and `jsnext:main` fields, pointing to `angularfire2.js` and `es6/angularfire2.js`, respectively.

Now:

* The project ships ES2015 modules with ES5 JS at the root, as well as an ES5 UMD bundle at `bundles/angulafire2.umd.js`
* The `main` field of `package.json` points to `bundles/angularfire2.umd.js`.
* Instead of `jsnext:main`, we're using the `module` field of package.json to point to `index.js`.
* Instead of `angularfire2.js` being the main entry point, an `index.js` has been added (though angulafire2.js hasn't changed significantly).

If you're using Rollup or Webpack, they should _just work_ with this new setup (please open issues if not). If using SystemJS, you should be able to
add `format: 'esm'` inside of the packages configuration, and it should load and parse the es2015 modules correctly.

The addition of the umd bundle will also make it possible to use AngularFire2 in a `<script>` tag, such as in a plunker or JSBin. The library is
exported on a global called `angularFire2`.

<a name="2.0.0-beta.4"></a>
# [2.0.0-beta.4](https://github.com/angular/angularfire2/compare/2.0.0-beta.2...v2.0.0-beta.3) (2016-08-22)
Expand Down Expand Up @@ -77,7 +97,7 @@ apps are configured, and how third-party oauth tokens are handled.
## Breaking Changes:
* [Upgrade to the Firebase 3.0+ SDK](https://firebase.google.com/docs/web/setup), versions less than 3.0 are not supported. [abe11a2](https://github.com/angular/angularfire2/pull/200/commits/abe11a2fd8f5a3f554056625b751e9308e56b906)
* `defaultFirebase` takes in a configuration object rather than a database url string. [See docs for more info.](https://github.com/angular/angularfire2/blob/master/docs/1-install-and-setup.md)
* Access tokens for third party auth (github, google, facebook, twitter) are not persisted after refresh.
* Access tokens for third party auth (github, google, facebook, twitter) are not persisted after refresh.

# AngularFire2 2.0.0-beta.0

Expand Down
8 changes: 4 additions & 4 deletions docs/1-install-and-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
You need the Angular CLI, typings, and TypeScript 2.0. TypeScript 2.0 is required for AngularFire2.

```bash
npm install -g angular-cli@webpack
npm install -g angular-cli
# or install locally
npm install angular-cli@webpack --save-dev
npm install angular-cli --save-dev
# make sure you have typings installed
npm install -g typings
npm install -g typings
npm install -g [email protected]
```

Expand All @@ -24,7 +24,7 @@ Verify you have the correct version installed by running `ng -v` and ensuring th
npm uninstall -g angular-cli

# reinstall clean version
npm install -g angular-cli@webpack
npm install -g angular-cli
```


Expand Down
86 changes: 4 additions & 82 deletions karma-test-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,85 +2,7 @@
Error.stackTraceLimit = Infinity;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;

__karma__.loaded = function () {
};


function isJsFile(path) {
return path.slice(-3) == '.js';
}

function isSpecFile(path) {
return path.slice(-7) == 'spec.js';
}

function isBuiltFile(path) {
var builtPath = '/base/dist/';
return isJsFile(path) && (path.substr(0, builtPath.length) == builtPath);
}

var allSpecFiles = Object.keys(window.__karma__.files)
.filter(isSpecFile)
.filter(isBuiltFile);

// Load our SystemJS configuration.
System.config({
baseURL: '/base'
});

System.config(
{
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
map: {
'app': 'dist',
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',

// angular testing umd bundles
'@angular/core/testing': 'npm:@angular/core/bundles/core-testing.umd.js',
'@angular/common/testing': 'npm:@angular/common/bundles/common-testing.umd.js',
'@angular/compiler/testing': 'npm:@angular/compiler/bundles/compiler-testing.umd.js',
'@angular/platform-browser/testing': 'npm:@angular/platform-browser/bundles/platform-browser-testing.umd.js',
'@angular/platform-browser-dynamic/testing': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic-testing.umd.js',

// other libraries
'rxjs': 'npm:rxjs',
'firebase': 'npm:firebase/firebase.js'
},
packages: {
'app': {
defaultExtension: 'js'
},
'rxjs': {
main: 'Rx.js',
defaultExtension: 'js'
}
}
});

Promise.all([
System.import('@angular/core/testing'),
System.import('@angular/platform-browser-dynamic/testing')
]).then(function (providers) {
var testing = providers[0];
var testingBrowser = providers[1];

testing.TestBed.initTestEnvironment(
testingBrowser.BrowserDynamicTestingModule,
testingBrowser.platformBrowserDynamicTesting()
);

}).then(function() {
// Finally, load all spec files.
// This will run the tests directly.
return Promise.all(
allSpecFiles.map(function (moduleName) {
return System.import(moduleName);
}));
}).then(__karma__.start, __karma__.error);
ng.core.testing.TestBed.initTestEnvironment(
ng.platformBrowserDynamic.testing.BrowserDynamicTestingModule,
ng.platformBrowserDynamic.testing.platformBrowserDynamicTesting()
);
32 changes: 14 additions & 18 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ module.exports = function(config) {

'node_modules/reflect-metadata/Reflect.js',

// System.js for module loading
'node_modules/systemjs/dist/system-polyfills.js',
'node_modules/systemjs/dist/system.src.js',

// Zone.js dependencies
'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/proxy.js',
Expand All @@ -24,21 +20,13 @@ module.exports = function(config) {
'node_modules/zone.js/dist/async-test.js',
'node_modules/zone.js/dist/fake-async-test.js',

// RxJs.
{ pattern: 'node_modules/rxjs/**/*.js', included: false, watched: false },
{ pattern: 'node_modules/rxjs/**/*.js.map', included: false, watched: false },


{ pattern: 'karma-test-shim.js', included: true, watched: true },
'node_modules/rxjs/bundles/Rx.{js,map}',

// paths loaded via module imports
// Angular itself
{ pattern: 'node_modules/@angular/**/*.js', included: false, watched: true },
{ pattern: 'node_modules/@angular/**/*.js.map', included: false, watched: true },
...getAngularFiles(['core','common','compiler','platform-browser','platform-browser-dynamic']),

{ pattern: 'node_modules/firebase/firebase.js', included: false, watched: false },
{ pattern: 'dist/**/*.js', included: false, watched: true },
{ pattern: 'dist/**/*.js.map', included: false, watched: false }
'karma-test-shim.js',
'node_modules/firebase/firebase.js',
'dist/bundles/test-root.umd.{js,map}',
],

port: 9876,
Expand All @@ -48,4 +36,12 @@ module.exports = function(config) {
browsers: ['Chrome'],
singleRun: false
})
};
};

function getAngularFiles(packages) {
return packages.reduce((files, pkg) => {
files.push(`node_modules/@angular/${pkg}/bundles/${pkg}.umd.js`);
files.push(`node_modules/@angular/${pkg}/bundles/${pkg}-testing.umd.js`);
return files;
}, []);
}
23 changes: 14 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
"name": "angularfire2",
"version": "2.0.0-beta.5",
"description": "",
"main": "./dist/angularfire2.js",
"jsnext:main": "./dist/esm/angularfire2.js",
"main": "bundles/angularfire2.umd.js",
"module": "index.js",
"scripts": {
"test": "npm run build; karma start --single-run",
"test:watch": "karma start",
"build": "rm -rf dist; tsc",
"build:watch": "rm -rf dist && tsc -w",
"build_npm": "rm -rf dist && ngc -p tsconfig.publish.es5.json && ngc -p tsconfig.publish.es6.json && npm run postbuild_npm",
"test:watch": "concurrently 'npm run build:watch' 'npm run delayed_karma'",
"delayed_karma": "sleep 10 && karma start",
"delayed_rollup": "sleep 5 && rollup --watch -c rollup.test.config.js",
"build:watch": "rm -rf dist && concurrently 'tsc -w' 'npm run delayed_rollup'",
"build": "rm -rf dist && tsc && rollup -c rollup.test.config.js",
"build_npm": "rm -rf dist && ngc -p tsconfig.publish.es6.json && rollup -c rollup.publish.config.js && npm run postbuild_npm",
"build_e2e": "rm -rf dist-test && npm run build && tsc -p test/ && cp test/e2e/firebase_object/index.html dist-test/e2e/firebase_object/ && cp test/e2e/firebase_list/index.html dist-test/e2e/firebase_list/ && cp test/e2e/auth/index.html dist-test/e2e/auth/",
"postbuild_npm": "cp package.json README.md .npmignore dist/ && npm run rewrite_npm_package",
"rewrite_npm_package": "node --harmony_destructuring tools/rewrite-published-package.js",
"e2e_test": "webdriver-manager update && npm run build_e2e && protractor",
"build_e2e": "rm -rf dist-test && npm run build && tsc -p test/ && cp test/e2e/firebase_object/index.html dist-test/e2e/firebase_object/ && cp test/e2e/firebase_list/index.html dist-test/e2e/firebase_list/ && cp test/e2e/auth/index.html dist-test/e2e/auth/",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1"
},
"keywords": [
Expand Down Expand Up @@ -44,6 +46,7 @@
"devDependencies": {
"@angular/compiler-cli": "^0.5.0",
"@angular/platform-server": "^2.0.0-rc.5",
"concurrently": "^2.2.0",
"conventional-changelog-cli": "^1.2.0",
"es6-module-loader": "^0.17.10",
"es6-shim": "^0.35.0",
Expand All @@ -64,14 +67,16 @@
"parse5": "^1.3.2",
"protractor": "3.0.0",
"reflect-metadata": "0.1.2",
"rollup": "^0.35.11",
"rollup-watch": "^2.5.0",
"systemjs": "^0.19.16",
"systemjs-builder": "^0.15.7",
"traceur": "0.0.96",
"tsd": "^0.6.5",
"typedoc": "github:jeffbcross/typedoc",
"typescript": "next",
"typescript": "^2.0.2",
"typings": "^1.3.2",
"zone.js": "^0.6.21"
},
"typings": "dist/angularfire2.d.ts"
"typings": "index.d.ts"
}
11 changes: 11 additions & 0 deletions rollup-globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default (mod) => {
if (mod === 'rxjs') return 'Rx';
if (mod.indexOf('rxjs/operator') === 0) return `Rx.Observable.prototype`;
if (mod.indexOf('rxjs/observable') === 0) return `Rx.Observable`;
if (mod === 'rxjs/scheduler/queue') return 'Rx.Scheduler';
if (mod.indexOf('rxjs/') === 0) return 'Rx';

if (mod === 'firebase') return 'firebase';
if (mod === '@angular/core') return 'ng.core';
if (mod === '@angular/core/testing') return 'ng.core.testing';
}
9 changes: 9 additions & 0 deletions rollup.publish.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import globals from './rollup-globals';

export default {
entry: 'dist/index.js',
dest: 'dist/bundles/angularFire2.umd.js',
format: 'umd',
moduleName: 'angularFire2',
globals
}
9 changes: 9 additions & 0 deletions rollup.test.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import globals from './rollup-globals';

export default {
entry: 'dist/test-root.js',
dest: 'dist/bundles/test-root.umd.js',
format: 'umd',
moduleName: 'angularFire2.test',
globals
}
4 changes: 0 additions & 4 deletions src/angularfire2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ import {
} from './angularfire2';
import { Subscription } from 'rxjs/Subscription';
import { COMMON_CONFIG, ANON_AUTH_CONFIG } from './test-config';
import 'rxjs/add/operator/toPromise';
import 'rxjs/add/operator/take';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/delay';

describe('angularfire', () => {
var subscription:Subscription;
Expand Down
8 changes: 4 additions & 4 deletions src/auth/auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
TestBed,
inject
} from '@angular/core/testing';
import 'rxjs/add/operator/do';
import { _do } from 'rxjs/operator/do';

import {
defaultFirebase,
Expand Down Expand Up @@ -97,9 +97,9 @@ describe('Zones', () => {
});
ngZone.run(() => {
var afAuth = new AngularFireAuth(new FirebaseSdkAuthBackend(app), window.location);
afAuth
.take(1)
.do(_ => {
var authObs = afAuth.take(1);

_do.call(authObs, _ => {
expect(Zone.current.name).toBe('ngZone');
})
.subscribe(() => {
Expand Down
46 changes: 22 additions & 24 deletions src/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@ import {
FirebaseAuthState,
stripProviderId
} from './auth_backend';
import 'rxjs/add/operator/mergeMap';
import 'rxjs/add/operator/take';
import 'rxjs/add/operator/concat';
import 'rxjs/add/operator/skip';
import 'rxjs/add/observable/of';
import { mergeMap } from 'rxjs/operator/mergeMap';
import { of as observableOf } from 'rxjs/observable/of';
import { map } from 'rxjs/operator/map';

const kBufferSize = 1;

Expand All @@ -35,26 +33,26 @@ export class AngularFireAuth extends ReplaySubject<FirebaseAuthState> {
super(kBufferSize);

let firstPass = true;
this._authBackend.onAuth()
.mergeMap((authState: FirebaseAuthState) => {
if (firstPass) {
firstPass = false;
if(['http:', 'https:'].indexOf(loc.protocol) > -1) {
// Only call getRedirectResult() in a browser
return this._authBackend.getRedirectResult()
.map((userCredential: firebase.auth.UserCredential) => {
if (userCredential && userCredential.credential) {
authState = attachCredentialToAuthState(authState, userCredential.credential, userCredential.credential.provider);
this._credentialCache[userCredential.credential.provider] = userCredential.credential;
}
return authState;
});
}

let onAuth = this._authBackend.onAuth();

mergeMap.call(onAuth, (authState: FirebaseAuthState) => {
if (firstPass) {
firstPass = false;
if(['http:', 'https:'].indexOf(loc.protocol) > -1) {
// Only call getRedirectResult() in a browser
return map.call(this._authBackend.getRedirectResult(), (userCredential: firebase.auth.UserCredential) => {
if (userCredential && userCredential.credential) {
authState = attachCredentialToAuthState(authState, userCredential.credential, userCredential.credential.provider);
this._credentialCache[userCredential.credential.provider] = userCredential.credential;
}
return authState;
});
}
return Observable.of(authState);
})
.subscribe((authData: FirebaseAuthState) => this._emitAuthData(authData));

}
return observableOf(authState);
})
.subscribe((authData: FirebaseAuthState) => this._emitAuthData(authData));
}

public login(config?: AuthConfiguration): firebase.Promise<FirebaseAuthState>;
Expand Down
Loading