Skip to content

Commit 4e28c06

Browse files
committed
cleanup build.ts
1 parent ab78b59 commit 4e28c06

File tree

1 file changed

+5
-82
lines changed

1 file changed

+5
-82
lines changed

tools/build.ts

Lines changed: 5 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,6 @@
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';
51
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';
184

195
interface OverrideOptions {
206
exportName?: string;
@@ -32,10 +18,11 @@ function zoneWrapExports() {
3218
overrides: Record<string, OverrideOptions | null> = {}
3319
) => {
3420
const imported = await import(path);
35-
const toBeExported: Array<[string, string, boolean]> = exports.
21+
const toBeExported: [string, string, boolean][] = exports.
3622
filter(it => !it.startsWith('_') && overrides[it] !== null && overrides[it]?.override !== true).
3723
map(importName => {
3824
const zoneWrap = typeof imported[importName] === 'function' &&
25+
// eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
3926
(overrides[importName]?.zoneWrap ?? importName[0] !== importName[0].toUpperCase());
4027
const exportName = overrides[importName]?.exportName ?? importName;
4128
return [importName, exportName, zoneWrap];
@@ -134,33 +121,6 @@ ${exportedZoneWrappedFns}
134121
]);
135122
}
136123

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-
164124
const src = (...args: string[]) => join(process.cwd(), 'src', ...args);
165125
const dest = (...args: string[]) => join(process.cwd(), 'dist', '@angular/fire', ...args);
166126
const destPacakges = (...args: string[]) => join(process.cwd(), 'dist/packages-dist', ...args);
@@ -169,6 +129,7 @@ const rootPackage = import(join(process.cwd(), 'package.json'));
169129

170130
async function replacePackageCoreVersion() {
171131
const root = await rootPackage;
132+
// eslint-disable-next-line @typescript-eslint/no-var-requires
172133
const replace = require('replace-in-file');
173134
const files = destPacakges('package.json');
174135
return replace({
@@ -215,39 +176,7 @@ async function compileSchematics() {
215176
]);
216177
}
217178

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-
249179
async function buildLibrary() {
250-
// await proxyPolyfillCompat();
251180
await zoneWrapExports();
252181
await spawnPromise('npx', ['ng', 'build']);
253182
await Promise.all([
@@ -256,15 +185,9 @@ async function buildLibrary() {
256185
copy(join(process.cwd(), 'docs'), dest('docs')),
257186
compileSchematics(),
258187
replacePackageCoreVersion(),
259-
// fixImportForLazyModules(),
260-
// webpackFirestoreProtos(),
261188
]);
262189
}
263190

264-
function measureLibrary() {
265-
return Promise.all(UMD_NAMES.map(measure));
266-
}
267-
268191
buildLibrary().catch(err => {
269192
console.error(err);
270193
process.exit(1);

0 commit comments

Comments
 (0)