Skip to content
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

ng-add providers #3523

Merged
merged 1 commit into from
May 14, 2024
Merged
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
4 changes: 2 additions & 2 deletions src/schematics/setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { writeFileSync } from 'fs';
import { join } from 'path';
import { asWindowsPath, normalize } from '@angular-devkit/core';
import { SchematicContext, SchematicsException, Tree, chain } from '@angular-devkit/schematics';
import { addRootImport } from '@schematics/angular/utility';
import { addRootProvider } from '@schematics/angular/utility';
import {
generateFirebaseRc,
overwriteIfExists,
Expand Down Expand Up @@ -64,7 +64,7 @@ export const setupProject =
const featuresToImport = features.filter(it => it !== FEATURES.Hosting);
if (featuresToImport.length > 0) {
return chain([
addRootImport(projectName, ({code, external}) => {
addRootProvider(projectName, ({code, external}) => {
external('initializeApp', '@angular/fire/app');
return code`${external('provideFirebaseApp', '@angular/fire/app')}(() => initializeApp(${JSON.stringify(config.sdkConfig)}))`;
}),
Expand Down
22 changes: 11 additions & 11 deletions src/schematics/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { readFileSync } from 'fs';
import { join } from 'path';
import { Rule, SchematicsException, Tree, chain } from '@angular-devkit/schematics';
import ts from '@schematics/angular/third_party/github.com/Microsoft/TypeScript/lib/typescript';
import { addRootImport, addRootProvider } from '@schematics/angular/utility';
import { addRootProvider } from '@schematics/angular/utility';
import { findNode } from '@schematics/angular/utility/ast-utils';
import { InsertChange, ReplaceChange, applyToUpdateRecorder } from '@schematics/angular/utility/change';
import { overwriteIfExists } from './common';
Expand Down Expand Up @@ -186,7 +186,7 @@ export function featureToRules(features: FEATURES[], projectName: string) {
switch (feature) {
case FEATURES.AppCheck:
// TODO make this smarter in Angular Universal
return addRootImport(projectName, ({code, external}) => {
return addRootProvider(projectName, ({code, external}) => {
external('initializeAppCheck', '@angular/fire/app-check');
external('ReCaptchaEnterpriseProvider', '@angular/fire/app-check');
return code`${external('provideAppCheck', '@angular/fire/app-check')}(() => {
Expand All @@ -197,7 +197,7 @@ export function featureToRules(features: FEATURES[], projectName: string) {
});
case FEATURES.Analytics:
return chain([
addRootImport(projectName, ({code, external}) => {
addRootProvider(projectName, ({code, external}) => {
external('getAnalytics', '@angular/fire/analytics');
return code`${external('provideAnalytics', '@angular/fire/analytics')}(() => getAnalytics())`;
}),
Expand All @@ -212,44 +212,44 @@ export function featureToRules(features: FEATURES[], projectName: string) {
] : []),
])
case FEATURES.Authentication:
return addRootImport(projectName, ({code, external}) => {
return addRootProvider(projectName, ({code, external}) => {
external('getAuth', '@angular/fire/auth');
return code`${external('provideAuth', '@angular/fire/auth')}(() => getAuth())`;
});
case FEATURES.Database:
return addRootImport(projectName, ({code, external}) => {
return addRootProvider(projectName, ({code, external}) => {
external('getDatabase', '@angular/fire/database');
return code`${external('provideDatabase', '@angular/fire/database')}(() => getDatabase())`;
});
case FEATURES.Firestore:
return addRootImport(projectName, ({code, external}) => {
return addRootProvider(projectName, ({code, external}) => {
external('getFirestore', '@angular/fire/firestore');
return code`${external('provideFirestore', '@angular/fire/firestore')}(() => getFirestore())`;
});
case FEATURES.Functions:
return addRootImport(projectName, ({code, external}) => {
return addRootProvider(projectName, ({code, external}) => {
external('getFunctions', '@angular/fire/functions');
return code`${external('provideFunctions', '@angular/fire/functions')}(() => getFunctions())`;
});
case FEATURES.Messaging:
// TODO add the service worker
return addRootImport(projectName, ({code, external}) => {
return addRootProvider(projectName, ({code, external}) => {
external('getMessaging', '@angular/fire/messaging');
return code`${external('provideMessaging', '@angular/fire/messaging')}(() => getMessaging())`;
});
case FEATURES.Performance:
return addRootImport(projectName, ({code, external}) => {
return addRootProvider(projectName, ({code, external}) => {
external('getPerformance', '@angular/fire/performance');
return code`${external('providePerformance', '@angular/fire/performance')}(() => getPerformance())`;
});
case FEATURES.Storage:
return addRootImport(projectName, ({code, external}) => {
return addRootProvider(projectName, ({code, external}) => {
external('getStorage', '@angular/fire/storage');
return code`${external('provideStorage', '@angular/fire/storage')}(() => getStorage())`;
});
case FEATURES.RemoteConfig:
// TODO consider downloading the defaults
return addRootImport(projectName, ({code, external}) => {
return addRootProvider(projectName, ({code, external}) => {
external('getRemoteConfig', '@angular/fire/remote-config');
return code`${external('provideRemoteConfig', '@angular/fire/remote-config')}(() => getRemoteConfig())`;
});
Expand Down
Loading