Skip to content

Commit 9114664

Browse files
committed
fix(@schematics/angular): fix broken API usage from app-shell schematic
Using getDir() on a file is an error, and we are fixing it.
1 parent ef81698 commit 9114664

File tree

1 file changed

+10
-18
lines changed
  • packages/schematics/angular/app-shell

1 file changed

+10
-18
lines changed

packages/schematics/angular/app-shell/index.ts

+10-18
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Use of this source code is governed by an MIT-style license that can be
66
* found in the LICENSE file at https://angular.io/license
77
*/
8-
import { JsonObject, normalize } from '@angular-devkit/core';
8+
import { JsonObject, dirname, join, normalize } from '@angular-devkit/core';
99
import {
1010
Rule,
1111
SchematicContext,
@@ -92,9 +92,8 @@ function getComponentTemplate(host: Tree, compPath: string, tmplInfo: TemplateIn
9292
template = tmplInfo.templateProp.getFullText();
9393
} else if (tmplInfo.templateUrlProp) {
9494
const templateUrl = (tmplInfo.templateUrlProp.initializer as ts.StringLiteral).text;
95-
const dirEntry = host.getDir(compPath);
96-
const dir = dirEntry.parent ? dirEntry.parent.path : '/';
97-
const templatePath = normalize(`/${dir}/${templateUrl}`);
95+
const dir = dirname(normalize(compPath));
96+
const templatePath = join(dir, templateUrl);
9897
const buffer = host.read(templatePath);
9998
if (buffer) {
10099
template = buffer.toString();
@@ -131,11 +130,7 @@ function getBootstrapComponentPath(host: Tree, project: WorkspaceProject): strin
131130
return pathStringLiteral.text;
132131
})[0];
133132

134-
const dirEntry = host.getDir(modulePath);
135-
const dir = dirEntry.parent ? dirEntry.parent.path : '/';
136-
const compPath = normalize(`/${dir}/${relativePath}.ts`);
137-
138-
return compPath;
133+
return join(dirname(normalize(modulePath)), relativePath + '.ts');
139134
}
140135
// end helper functions.
141136

@@ -310,16 +305,13 @@ function addServerRoutes(options: AppShellOptions): Rule {
310305
}
311306

312307
function addShellComponent(options: AppShellOptions): Rule {
313-
return (host: Tree, context: SchematicContext) => {
314-
315-
const componentOptions: ComponentOptions = {
316-
name: 'app-shell',
317-
module: options.rootModuleFileName,
318-
project: options.clientProject,
319-
};
320-
321-
return schematic('component', componentOptions)(host, context);
308+
const componentOptions: ComponentOptions = {
309+
name: 'app-shell',
310+
module: options.rootModuleFileName,
311+
project: options.clientProject,
322312
};
313+
314+
return schematic('component', componentOptions);
323315
}
324316

325317
function getClientProject(host: Tree, options: AppShellOptions): WorkspaceProject {

0 commit comments

Comments
 (0)