Skip to content

Commit ef5abdf

Browse files
committed
chore(build): add version dependencies at build time
1 parent e2be850 commit ef5abdf

File tree

5 files changed

+62
-17
lines changed

5 files changed

+62
-17
lines changed

src/auth/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angularfire2/auth",
3-
"version": "ANGULARFIRE2_VERSION",
3+
"version": "4.0.0-rc.1",
44
"description": "The auth module",
55
"main": "../bundles/auth.umd.js",
66
"module": "index.js",

src/core/angularfire2.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import * as firebase from 'firebase/app';
22
import { FirebaseAppConfigToken, FirebaseApp, _firebaseAppFactory } from './firebase.app.module';
33
import { Injectable, InjectionToken, OpaqueToken, NgModule } from '@angular/core';
4+
import { Subscription } from 'rxjs/Subscription';
5+
import { Scheduler } from 'rxjs/Scheduler';
6+
import { queue } from 'rxjs/scheduler/queue';
47

58
export interface FirebaseAppConfig {
69
apiKey?: string;
@@ -34,16 +37,12 @@ export class AngularFireModule {
3437
}
3538
}
3639

37-
import { Subscription } from 'rxjs/Subscription';
38-
import { Scheduler } from 'rxjs/Scheduler';
39-
import { queue } from 'rxjs/scheduler/queue';
40-
4140
/**
4241
* TODO: remove this scheduler once Rx has a more robust story for working
4342
* with zones.
4443
*/
4544
export class ZoneScheduler {
46-
constructor(public zone: Zone) {}
45+
constructor(public zone: any) {}
4746

4847
schedule(...args): Subscription {
4948
return <Subscription>this.zone.run(() => queue.schedule.apply(queue, args));

src/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angularfire2",
3-
"version": "ANGULARFIRE2_VERSION",
3+
"version": "4.0.0-rc.2",
44
"description": "The core module",
55
"main": "./bundles/core.umd.js",
66
"module": "index.js",

src/database/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angularfire2/database",
3-
"version": "ANGULARFIRE2_VERSION",
3+
"version": "4.0.0-rc.1",
44
"description": "The database module",
55
"main": "../bundles/database.umd.js",
66
"module": "index.js",

tools/build.js

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const { rollup } = require('rollup');
22
const { spawn } = require('child_process');
33
const { Observable } = require('rxjs');
4-
const { copy, readFileSync } = require('fs-extra');
4+
const { copy, readFileSync, writeFile } = require('fs-extra');
55
const { prettySize } = require('pretty-size');
66
const gzipSize = require('gzip-size');
77

@@ -32,7 +32,16 @@ const GLOBALS = {
3232
'angularfire2': 'angularfire2'
3333
};
3434

35-
// constants for running typescript commands
35+
// Map of dependency versions across all packages
36+
const VERSIONS = {
37+
ANGULAR_VERSION: '^4.0.0',
38+
FIREBASE_VERSION: '^4.0.0',
39+
RXJS_VERSION: '^5.0.1',
40+
ZONEJS_VERSION: '^0.8.0',
41+
ANGULARFIRE2_VERSION: '4.0.0-rc.2'
42+
};
43+
44+
// Constants for running typescript commands
3645
const TSC = 'node_modules/.bin/tsc';
3746
const NGC = 'node_modules/.bin/ngc';
3847
const TSC_ARGS = (name, config = 'build') => [`-p`, `${process.cwd()}/src/${name}/tsconfig-${config}.json`];
@@ -52,6 +61,11 @@ function spawnObservable(command, args) {
5261
});
5362
}
5463

64+
/**
65+
* Create a UMD bundle given a module name
66+
* @param {string} name
67+
* @param {Object} globals
68+
*/
5569
function createUmd(name, globals) {
5670
// core module is angularfire2 the rest are angularfire2.feature
5771
const moduleName = name === 'core' ? 'angularfire2' : `angularfire2.${name}`;
@@ -76,6 +90,10 @@ function createUmd(name, globals) {
7690
});
7791
}
7892

93+
/**
94+
* Get the file path of the src package.json for a module
95+
* @param {string} moduleName
96+
*/
7997
function getSrcPackageFile(moduleName) {
8098
const PATHS = {
8199
core: `${process.cwd()}/src/core/package.json`,
@@ -85,6 +103,10 @@ function getSrcPackageFile(moduleName) {
85103
return PATHS[moduleName];
86104
}
87105

106+
/**
107+
* Get the file path of the dist package.json for a module
108+
* @param {string} moduleName
109+
*/
88110
function getDestPackageFile(moduleName) {
89111
const PATHS = {
90112
core: `${process.cwd()}/dist/packages-dist/package.json`,
@@ -94,6 +116,33 @@ function getDestPackageFile(moduleName) {
94116
return PATHS[moduleName];
95117
}
96118

119+
/**
120+
* Create an observable of package.json dependency version replacements.
121+
* This keeps the dependency versions across each package in sync.
122+
* @param {string} name
123+
* @param {Object} versions
124+
*/
125+
function replaceVersionsObservable(name, versions) {
126+
return Observable.create((observer) => {
127+
const package = getSrcPackageFile(name);
128+
let pkg = readFileSync(package, 'utf8');
129+
const regexs = Object.keys(versions).map(key =>
130+
({ expr: new RegExp(key, 'g'), key, val: versions[key] }));
131+
regexs.forEach(reg => {
132+
pkg = pkg.replace(reg.expr, reg.val);
133+
});
134+
const outPath = getDestPackageFile(name);
135+
writeFile(outPath, pkg, err => {
136+
if(err) {
137+
observer.error(err);
138+
} else {
139+
observer.next(pkg);
140+
observer.complete();
141+
}
142+
});
143+
});
144+
}
145+
97146
function copyPackage(moduleName) {
98147
return copy(getSrcPackageFile(moduleName), getDestPackageFile(moduleName));
99148
}
@@ -111,7 +160,7 @@ function buildModule(name, globals) {
111160
return Observable
112161
.forkJoin(es2015$, esm$)
113162
.switchMap(() => Observable.from(createUmd(name, globals)))
114-
.switchMap(() => Observable.from(copyPackage(name)));
163+
.switchMap(() => replaceVersionsObservable(name, VERSIONS));
115164
}
116165

117166
function buildLibrary(globals) {
@@ -123,13 +172,10 @@ function buildLibrary(globals) {
123172
.switchMapTo(auth$)
124173
.switchMapTo(db$)
125174
.do(() => {
126-
const core = measure('core');
127-
const auth = measure('auth');
128-
const db = measure('database');
129175
console.log(`
130-
core.umd.js - ${core}
131-
auth.umd.js - ${auth}
132-
database.umd.js - ${db}
176+
core.umd.js - ${measure('core')}
177+
auth.umd.js - ${measure('auth')}
178+
database.umd.js - ${measure('database')}
133179
`);
134180
});
135181
}

0 commit comments

Comments
 (0)