Skip to content
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

fix(@schematics/angular): support adding app-shell after after nguniv… #15606

Merged
merged 1 commit into from
Sep 18, 2019
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
10 changes: 5 additions & 5 deletions packages/schematics/angular/app-shell/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ function getSourceFile(host: Tree, path: string): ts.SourceFile {

function getServerModulePath(
host: Tree,
projectRoot: string,
sourceRoot: string,
mainPath: string,
): string | null {
const mainSource = getSourceFile(host, mainPath);
const mainSource = getSourceFile(host, join(normalize(sourceRoot), mainPath));
const allNodes = getSourceNodes(mainSource);
const expNode = allNodes.filter(node => node.kind === ts.SyntaxKind.ExportDeclaration)[0];
const expNode = allNodes.find(node => ts.isExportDeclaration(node));
if (!expNode) {
return null;
}
const relativePath = (expNode as ts.ExportDeclaration).moduleSpecifier as ts.StringLiteral;
const modulePath = normalize(`/${projectRoot}/src/${relativePath.text}.ts`);
const modulePath = normalize(`/${sourceRoot}/${relativePath.text}.ts`);

return modulePath;
}
Expand Down Expand Up @@ -243,7 +243,7 @@ function addServerRoutes(options: AppShellOptions): Rule {
if (!clientServerOptions) {
throw new SchematicsException('Server target does not contain options.');
}
const modulePath = getServerModulePath(host, clientProject.root, clientServerOptions.main);
const modulePath = getServerModulePath(host, clientProject.sourceRoot || 'src', options.main as string);
if (modulePath === null) {
throw new SchematicsException('Universal/server module not found.');
}
Expand Down
16 changes: 16 additions & 0 deletions packages/schematics/angular/app-shell/index_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@ describe('App Shell Schematic', () => {
expect(content).toMatch(/import { Routes, RouterModule } from \'@angular\/router\';/);
});

it('should work after adding nguniversal', async () => {
let tree = await schematicRunner.runSchematicAsync('universal', defaultOptions, appTree)
.toPromise();

// change main tsconfig to mimic ng add for nguniveral
const workspace = JSON.parse(appTree.readContent('/angular.json'));
workspace.projects.bar.architect.server.options.main = 'server.ts';
appTree.overwrite('angular.json', JSON.stringify(workspace, undefined, 2));

tree = await schematicRunner.runSchematicAsync('appShell', defaultOptions, tree)
.toPromise();
const filePath = '/projects/bar/src/app/app.server.module.ts';
const content = tree.readContent(filePath);
expect(content).toMatch(/import { Routes, RouterModule } from \'@angular\/router\';/);
});

it('should define a server route', async () => {
const tree = await schematicRunner.runSchematicAsync('appShell', defaultOptions, appTree)
.toPromise();
Expand Down