Skip to content

Commit

Permalink
fix(angular): fix misc standalone generation issues in application an…
Browse files Browse the repository at this point in the history
…d setup-mf generators (#19846)
  • Loading branch information
leosvelperez authored Oct 25, 2023
1 parent 342546c commit 0475f6f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ApplicationConfig } from '@angular/core';<% if (routing) { %>
import { ApplicationConfig } from <% if (installedAngularInfo.major >= 16) { %>'@angular/core';<% } else { %>'@angular/platform-browser';<% } %><% if (routing) { %>
import { provideRouter, withEnabledBlockingInitialNavigation } from '@angular/router';
import { appRoutes } from './app.routes';<% } %>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { AppComponent } from './app/app.component';
import { AppComponent } from './app/app.component';<% if(installedAngularInfo.major === 14) { %>
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';

if(environment.production) {
enableProdMode();
}<% } %>

bootstrapApplication(AppComponent, appConfig).catch((err) => console.error(err));
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ describe('AppComponent', () => {
imports: [
RouterTestingModule.withRoutes([
{ path: '', component: NxWelcomeComponent },
]),
],
declarations: [AppComponent, NxWelcomeComponent],
]),<% if (standalone) { %>
AppComponent,
NxWelcomeComponent,<% } %>
],<% if (!standalone) { %>
declarations: [AppComponent, NxWelcomeComponent],<% } %>
}).compileComponents();
});

Expand All @@ -37,4 +39,4 @@ describe('AppComponent', () => {
const compiled = fixture.nativeElement as HTMLElement;
expect(compiled.querySelector('h1')?.textContent).toContain('Welcome <%= appName %>');
}));
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function fixBootstrap(tree: Tree, appRoot: string, options: Schema) {
const mainFilePath = joinPathFragments(appRoot, 'src/main.ts');
const bootstrapCode = tree.read(mainFilePath, 'utf-8');
const installedAngularMajor = getInstalledAngularMajorVersion(tree);
if (options.standalone) {
if (options.standalone && options.mfType === 'remote') {
tree.write(
`${appRoot}/src/bootstrap.ts`,
standaloneBootstrapCode(installedAngularMajor === 14)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export function updateHostAppRoutes(tree: Tree, options: Schema) {
joinPathFragments(sourceRoot, 'app'),
{
appName: options.appName,
standalone: options.standalone,
tmpl: '',
}
);
Expand Down
5 changes: 3 additions & 2 deletions packages/angular/src/generators/setup-mf/setup-mf.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -503,14 +503,15 @@ describe('Init MF', () => {
expect(tree.read('ng14/src/bootstrap.ts', 'utf-8')).toMatchInlineSnapshot(`
"import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { RemoteEntryComponent } from './app/remote-entry/entry.component';
import { AppComponent } from './app/app.component';
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
bootstrapApplication(RemoteEntryComponent, appConfig).catch((err) =>
bootstrapApplication(AppComponent, appConfig).catch((err) =>
console.error(err)
);
"
Expand Down

0 comments on commit 0475f6f

Please sign in to comment.