1
- import { spawn } from 'cross-spawn' ;
2
- import { copy , readFile , writeFile } from 'fs-extra' ;
3
- import { prettySize } from 'pretty-size' ;
4
- import { file as gzipSizeFile } from 'gzip-size' ;
5
1
import { join } from 'path' ;
6
-
7
- // TODO infer these from the package.json
8
- const MODULES = [
9
- 'core' , 'app' , 'app-check' , 'auth-guard' , 'compat' , 'analytics' , 'auth' , 'database' , 'firestore' , 'functions' ,
10
- 'remote-config' , 'storage' , 'messaging' , 'performance' , 'compat/analytics' ,
11
- 'compat/auth-guard' , 'compat/auth' , 'compat/database' , 'compat/firestore' ,
12
- 'compat/functions' , 'compat/remote-config' , 'compat/storage' , 'compat/messaging' ,
13
- 'compat/performance' , 'firestore/lite' ,
14
- ] ;
15
- const LAZY_MODULES = [ 'compat/analytics' , 'compat/auth' , 'compat/functions' , 'compat/messaging' , 'compat/remote-config' ] ;
16
- const UMD_NAMES = MODULES . map ( m => m === 'core' ? 'angular-fire' : `angular-fire-${ m . replace ( '/' , '-' ) } ` ) ;
17
- const ENTRY_NAMES = MODULES . map ( m => m === 'core' ? '@angular/fire' : `@angular/fire/${ m } ` ) ;
2
+ import { spawn } from 'cross-spawn' ;
3
+ import { copy , writeFile } from 'fs-extra' ;
18
4
19
5
interface OverrideOptions {
20
6
exportName ?: string ;
@@ -32,10 +18,11 @@ function zoneWrapExports() {
32
18
overrides : Record < string , OverrideOptions | null > = { }
33
19
) => {
34
20
const imported = await import ( path ) ;
35
- const toBeExported : Array < [ string , string , boolean ] > = exports .
21
+ const toBeExported : [ string , string , boolean ] [ ] = exports .
36
22
filter ( it => ! it . startsWith ( '_' ) && overrides [ it ] !== null && overrides [ it ] ?. override !== true ) .
37
23
map ( importName => {
38
24
const zoneWrap = typeof imported [ importName ] === 'function' &&
25
+ // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
39
26
( overrides [ importName ] ?. zoneWrap ?? importName [ 0 ] !== importName [ 0 ] . toUpperCase ( ) ) ;
40
27
const exportName = overrides [ importName ] ?. exportName ?? importName ;
41
28
return [ importName , exportName , zoneWrap ] ;
@@ -134,33 +121,6 @@ ${exportedZoneWrappedFns}
134
121
] ) ;
135
122
}
136
123
137
- function webpackFirestoreProtos ( ) {
138
- const path = dest ( 'firestore-protos.js' ) ;
139
- console . log ( { path } )
140
- return writeFile ( dest ( 'firestore-protos.js' ) , `/**
141
- * @deprecated No longer needed since Firebase JS SDK 9.6.3
142
- */
143
- export {};` ) ;
144
- }
145
-
146
- function proxyPolyfillCompat ( ) {
147
- const defaultObject = {
148
- 'compat/analytics' : [ "app" , "logEvent" , "setCurrentScreen" , "setUserId" , "setUserProperties" , "setAnalyticsCollectionEnabled" ] ,
149
- 'compat/auth' : [ "name" , "config" , "emulatorConfig" , "app" , "applyActionCode" , "checkActionCode" , "confirmPasswordReset" , "createUserWithEmailAndPassword" , "currentUser" , "fetchSignInMethodsForEmail" , "isSignInWithEmailLink" , "getRedirectResult" , "languageCode" , "settings" , "onAuthStateChanged" , "onIdTokenChanged" , "sendSignInLinkToEmail" , "sendPasswordResetEmail" , "setPersistence" , "signInAndRetrieveDataWithCredential" , "signInAnonymously" , "signInWithCredential" , "signInWithCustomToken" , "signInWithEmailAndPassword" , "signInWithPhoneNumber" , "signInWithEmailLink" , "signInWithPopup" , "signInWithRedirect" , "signOut" , "tenantId" , "updateCurrentUser" , "useDeviceLanguage" , "useEmulator" , "verifyPasswordResetCode" ] ,
150
- 'compat/functions' : [ "useEmulator" , "useFunctionsEmulator" , "httpsCallable" ] ,
151
- 'compat/messaging' : [ "deleteToken" , "getToken" , "onMessage" , "onBackgroundMessage" ] ,
152
- 'compat/performance' : [ "app" , "trace" , "instrumentationEnabled" , "dataCollectionEnabled" ] ,
153
- 'compat/remote-config' : [ "app" , "settings" , "defaultConfig" , "fetchTimeMillis" , "lastFetchStatus" , "activate" , "ensureInitialized" , "fetch" , "fetchAndActivate" , "getAll" , "getBoolean" , "getNumber" , "getString" , "getValue" , "setLogLevel" ] ,
154
- } ;
155
- return Promise . all ( Object . keys ( defaultObject ) . map ( module =>
156
- writeFile ( join ( process . cwd ( ) , 'src' , `${ module } /base.ts` ) , `// DO NOT MODIFY, this file is autogenerated by tools/build.ts
157
- // Export a null object with the same keys as firebase/${ module } , so Proxy can work with proxy-polyfill in Internet Explorer
158
- export const proxyPolyfillCompat = {
159
- ${ defaultObject [ module ] . map ( it => ` ${ it } : null,` ) . join ( '\n' ) }
160
- };\n` )
161
- ) ) ;
162
- }
163
-
164
124
const src = ( ...args : string [ ] ) => join ( process . cwd ( ) , 'src' , ...args ) ;
165
125
const dest = ( ...args : string [ ] ) => join ( process . cwd ( ) , 'dist' , '@angular/fire' , ...args ) ;
166
126
const destPacakges = ( ...args : string [ ] ) => join ( process . cwd ( ) , 'dist/packages-dist' , ...args ) ;
@@ -169,6 +129,7 @@ const rootPackage = import(join(process.cwd(), 'package.json'));
169
129
170
130
async function replacePackageCoreVersion ( ) {
171
131
const root = await rootPackage ;
132
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
172
133
const replace = require ( 'replace-in-file' ) ;
173
134
const files = destPacakges ( 'package.json' ) ;
174
135
return replace ( {
@@ -215,39 +176,7 @@ async function compileSchematics() {
215
176
] ) ;
216
177
}
217
178
218
- async function measure ( module : string ) {
219
- const path = dest ( 'bundles' , `${ module } .umd.js` ) ;
220
- const file = await readFile ( path ) ;
221
- const size = prettySize ( file . byteLength , true ) ;
222
- const gzip = prettySize ( await gzipSizeFile ( path ) , true ) ;
223
- return { size, gzip } ;
224
- }
225
-
226
- async function fixImportForLazyModules ( ) {
227
- await Promise . all ( LAZY_MODULES . map ( async module => {
228
- const packageJson = JSON . parse ( ( await readFile ( dest ( module , 'package.json' ) ) ) . toString ( ) ) ;
229
- const entries = Array . from ( new Set ( Object . values ( packageJson ) . filter ( v => typeof v === 'string' && v . endsWith ( '.js' ) ) ) ) as string [ ] ;
230
- // TODO don't hardcode esm2015 here, perhaps we should scan all the entry directories
231
- // e.g, if ng-packagr starts building other non-flattened entries we'll lose the dynamic import
232
- // TODO fix in Windows
233
- entries . push ( `../${ module . includes ( '/' ) ? '../' : '' } esm2015/${ module } /public_api.js` ) ;
234
- await Promise . all ( entries . map ( async path => {
235
- const source = ( await readFile ( dest ( module , path ) ) ) . toString ( ) ;
236
- let newSource : string ;
237
- if ( path . endsWith ( '.umd.js' ) ) {
238
- // in the UMD for lazy modules replace the dyanamic import
239
- newSource = source . replace ( `import('firebase/${ module } ')` , 'rxjs.of(undefined)' ) ;
240
- } else {
241
- // in everything else get rid of the global side-effect import
242
- newSource = source . replace ( new RegExp ( `^import 'firebase/${ module } '.+$` , 'gm' ) , '' ) ;
243
- }
244
- await writeFile ( dest ( module , path ) , newSource ) ;
245
- } ) ) ;
246
- } ) ) ;
247
- }
248
-
249
179
async function buildLibrary ( ) {
250
- // await proxyPolyfillCompat();
251
180
await zoneWrapExports ( ) ;
252
181
await spawnPromise ( 'npx' , [ 'ng' , 'build' ] ) ;
253
182
await Promise . all ( [
@@ -256,15 +185,9 @@ async function buildLibrary() {
256
185
copy ( join ( process . cwd ( ) , 'docs' ) , dest ( 'docs' ) ) ,
257
186
compileSchematics ( ) ,
258
187
replacePackageCoreVersion ( ) ,
259
- // fixImportForLazyModules(),
260
- // webpackFirestoreProtos(),
261
188
] ) ;
262
189
}
263
190
264
- function measureLibrary ( ) {
265
- return Promise . all ( UMD_NAMES . map ( measure ) ) ;
266
- }
267
-
268
191
buildLibrary ( ) . catch ( err => {
269
192
console . error ( err ) ;
270
193
process . exit ( 1 ) ;
0 commit comments