Skip to content

Commit

Permalink
fix(schematics): ng-add should pass if sourceRoot is relative to work…
Browse files Browse the repository at this point in the history
…space root
  • Loading branch information
AgentEnder committed Nov 9, 2021
1 parent 5ecf875 commit 6daffdb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/schematics/ng-add.jasmine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,20 @@ describe('ng-add', () => {
expect(result.read('.firebaserc').toString()).toEqual(overwriteFirebaserc);
expect(result.read('angular.json').toString()).toEqual(overwriteAngularJson);
});

it('runs if source root is relative to workspace root', async () => {
const angularJson = generateAngularJson();
const project: {root: string, sourceRoot?: string} = angularJson.projects[PROJECT_NAME];
project.sourceRoot = `${project.root}/src`;
tree.overwrite('angular.json', JSON.stringify(angularJson));
const promise = setupProject(tree, {} as any, [FEATURES.Hosting], {
firebaseProject: { projectId: FIREBASE_PROJECT } as any,
projectType: PROJECT_TYPE.Static,
project: undefined,
prerender: false,
});
await expectAsync(promise).toBeResolved();
});

it('overrides existing files', async () => {
const tempTree = await setupProject(tree, {} as any, [FEATURES.Hosting], {
Expand Down
4 changes: 3 additions & 1 deletion src/schematics/setup/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ export const setupProject =

const { project, projectName } = getProject(config, tree);

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

addIgnoreFiles(tree);

Expand Down

0 comments on commit 6daffdb

Please sign in to comment.