()
| 62 | }; |
| 63 | |
| 64 | function zoneWrapExports() { |
| 65 | const reexport = async ( |
| 66 | module: string, |
| 67 | name: string, |
| 68 | path: string, |
| 69 | exports: string[], |
| 70 | overrides: Record<string, OverrideOptions | null> = {} |
| 71 | ) => { |
| 72 | const imported = await import(path); |
| 73 | const toBeExported: [string, string, boolean][] = exports.sort(). |
| 74 | filter(it => !it.startsWith('_') && overrides[it] !== null && overrides[it]?.override !== true). |
| 75 | map(importName => { |
| 76 | const zoneWrap = typeof imported[importName] === 'function' && |
| 77 | // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with |
| 78 | (overrides[importName]?.zoneWrap ?? importName[0] !== importName[0].toUpperCase()); |
| 79 | const exportName = overrides[importName]?.exportName ?? importName; |
| 80 | return [importName, exportName, zoneWrap]; |
| 81 | }); |
| 82 | const zoneWrapped = toBeExported.filter(([, , zoneWrap]) => zoneWrap); |
| 83 | const rawExport = toBeExported.filter(([, , zoneWrap]) => !zoneWrap); |
| 84 | const overridden = Object.keys(overrides).filter(key => overrides[key]?.override); |
| 85 | const isFirebaseSDK = path.startsWith('firebase/'); |
| 86 | const hasZoneWrappedFns = zoneWrapped.length > 0; |
| 87 | const hasRawExportedFns = rawExport.length > 0; |
| 88 | const hasOverridedFns = overridden.length > 0; |
| 89 | const zoneWrappedImports = zoneWrapped.map(([importName]) => `${importName} as _${importName}`).join(',\n '); |
| 90 | const rawExportedFns = rawExport.map(([importName, exportName]) => |
| 91 | `${importName}${exportName === importName ? '' : `as ${exportName}`}`).join(',\n '); |
| 92 | const overriddenFns = overridden.join(',\n '); |
| 93 | const exportedZoneWrappedFns = zoneWrapped.map(([importName, exportName]) => |
| 94 | `export const ${exportName} = ɵzoneWrap(_${importName}, ${overrides[importName]?.blockUntilFirst ?? true}${overrides[importName]?.logLevel ? `, ${overrides[importName].logLevel}` : ""});`) |
| 95 | .join('\n'); |
| 96 | const filePath = join(process.cwd(), 'src', `${module}/${name}.ts`); |
| 97 | // TODO(davideast): Create a builder pattern for this file for readability |
| 98 | const fileOutput = `// DO NOT MODIFY, this file is autogenerated by tools/build.ts |
| 99 | ${isFirebaseSDK ? `export * from '${path}';\n` : ''}${hasZoneWrappedFns ? `import { ɵzoneWrap } from '@angular/fire'; |
| 100 | import { |
| 101 | ${zoneWrappedImports} |
| 102 | } from '${path}'; |
| 103 | ` : ''}${!isFirebaseSDK && hasRawExportedFns ? ` |
| 104 | export { |
| 105 | ${rawExportedFns} |
| 106 | } from '${path}'; |
| 107 | ` : ''}${hasOverridedFns ? ` |
| 108 | export { |
| 109 | ${overriddenFns} |
| 110 | } from './overrides'; |
| 111 | ` : ''} |
| 112 | ${exportedZoneWrappedFns} |
| 113 | `; |
| 114 | await writeFile(filePath, fileOutput); |
| 115 | }; |
| 116 | return Promise.all([ |
| 117 | reexport('ai', 'firebase', 'firebase/ai', tsKeys<typeof import('firebase/ai')>()), |
| 118 | reexport('analytics', 'firebase', 'firebase/analytics', tsKeys<typeof import('firebase/analytics')>(), { |
| 119 | isSupported: { blockUntilFirst: false }, |
| 120 | logEvent: { blockUntilFirst: false, logLevel: LogLevel.VERBOSE }, |
| 121 | setAnalyticsCollectionEnabled: { logLevel: LogLevel.VERBOSE }, |
no test coverage detected