Skip to content

ng g @angular/fire:ng-add fails in a project where sourceRoot starts with the project's root #3052

Closed
@AgentEnder

Description

@AgentEnder

Version info

Angular: 12.2.0

Firebase: latest

AngularFire: latest

Other (e.g. Ionic/Cordova, Node, browser, operating system):

How to reproduce these conditions

This can be easily reproduced in Nx by following these steps, but would occur in a regular Angular project if the angular.json file had a similar project configuration to below. Reproduction steps for Nx are found in the Issue mention, for angular just ng new and update the configuration.

Debug output

** Screenshots **
image

Expected behavior

ng add @angular/fire passes if sourceRoot and root are both relative to the workspace root

Actual behavior

ng add @angular/fire only passes if sourceRoot is relative to root


In a workspace with a project configured as below, ng add @angular/fire fails due to the sourceRoot path being appended to the root, rather than replacing it.

{
  "root": "apps/admin"
  "sourceRoot": "apps/admin/src"
}

const sourcePath = [project.root, project.sourceRoot].filter(it => !!it).join('/');

Maybe this portion of code could use something like

const sourcePath = project.sourceRoot?.startsWith(project.root) 
		? project.sourceRoot 
		: [project.root, project.sourceRoot].filter(it => !!it).join('/'); 

I'd be happy to put in a PR to make the change if its agreed upon.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions