Skip to content

feat(@schematics/angular): augment universal schematics to import platform-server shims #19869

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

Merged
merged 1 commit into from
Feb 18, 2021
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
/***************************************************************************************************
* Initialize the server environment - for example, adding DOM built-in types to the global scope.
*
* NOTE:
* This import must come before any imports (direct or transitive) that rely on DOM built-ins being
* available, such as `@angular/elements`.
*/
import '@angular/platform-server/init';

<% if (hasLocalizePackage) { %>/***************************************************************************************************
* Load `$localize` onto the global scope - used if i18n tags appear in Angular templates.
*/
*/
import '@angular/localize/init';

<% } %>import { enableProdMode } from '@angular/core';
Expand Down
8 changes: 8 additions & 0 deletions packages/schematics/angular/universal/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@ describe('Universal Schematic', () => {
expect(tree.exists(filePath)).toEqual(true);
});

it(`should add import to '@angular/platform-server/init' in main file`, async () => {
const tree = await schematicRunner.runSchematicAsync('universal', defaultOptions, appTree)
.toPromise();
const filePath = '/projects/bar/src/main.server.ts';
const contents = tree.readContent(filePath);
expect(contents).toContain('import \'@angular/platform-server/init\'');
});

it(`should not add import to '@angular/localize' in main file when it's not a depedency`, async () => {
const tree = await schematicRunner.runSchematicAsync('universal', defaultOptions, appTree)
.toPromise();
Expand Down