Skip to content

Commit

Permalink
fix(angular): fix root selector in index.html for standalone remotes (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Coly010 committed Sep 27, 2022
1 parent 2f91d96 commit 66d1aed
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/angular/src/generators/remote/remote.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,23 @@ describe('MF Remote App Generator', () => {
const projects = getProjects(tree);
expect(projects.has('remote1-e2e')).toBeFalsy();
});

it('should update the index.html to use the remote entry component selector for root when standalone', async () => {
// ARRANGE
const tree = createTreeWithEmptyWorkspace();

// ACT
await remote(tree, {
name: 'test',
standalone: true,
});

// ASSERT
expect(tree.read('apps/test/src/index.html', 'utf-8')).not.toContain(
'proj-root'
);
expect(tree.read('apps/test/src/index.html', 'utf-8')).toContain(
'proj-test-entry'
);
});
});
15 changes: 15 additions & 0 deletions packages/angular/src/generators/remote/remote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
getProjects,
joinPathFragments,
readProjectConfiguration,
readWorkspaceConfiguration,
Tree,
} from '@nrwl/devkit';
import type { Schema } from './schema';
Expand Down Expand Up @@ -132,5 +133,19 @@ export class AppModule {}`
);
} else {
tree.delete(pathToAppComponent);

const prefix = options.prefix ?? readWorkspaceConfiguration(tree).npmScope;
const remoteEntrySelector = `${prefix}-${projectName}-entry`;

const pathToIndexHtml = project.targets.build.options.index;
const indexContents = tree.read(pathToIndexHtml, 'utf-8');

const rootSelectorRegex = new RegExp(`${prefix}-root`, 'ig');
const newIndexContents = indexContents.replace(
rootSelectorRegex,
remoteEntrySelector
);

tree.write(pathToIndexHtml, newIndexContents);
}
}

0 comments on commit 66d1aed

Please sign in to comment.