Skip to content

Commit 25e9da3

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 cfa0382 commit 25e9da3

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

Lines changed: 10 additions & 18 deletions
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,
@@ -91,9 +91,8 @@ function getComponentTemplate(host: Tree, compPath: string, tmplInfo: TemplateIn
9191
template = tmplInfo.templateProp.getFullText();
9292
} else if (tmplInfo.templateUrlProp) {
9393
const templateUrl = (tmplInfo.templateUrlProp.initializer as ts.StringLiteral).text;
94-
const dirEntry = host.getDir(compPath);
95-
const dir = dirEntry.parent ? dirEntry.parent.path : '/';
96-
const templatePath = normalize(`/${dir}/${templateUrl}`);
94+
const dir = dirname(normalize(compPath));
95+
const templatePath = join(dir, templateUrl);
9796
const buffer = host.read(templatePath);
9897
if (buffer) {
9998
template = buffer.toString();
@@ -130,11 +129,7 @@ function getBootstrapComponentPath(host: Tree, project: WorkspaceProject): strin
130129
return pathStringLiteral.text;
131130
})[0];
132131

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

@@ -313,16 +308,13 @@ function addServerRoutes(options: AppShellOptions): Rule {
313308
}
314309

315310
function addShellComponent(options: AppShellOptions): Rule {
316-
return (host: Tree, context: SchematicContext) => {
317-
318-
const componentOptions: ComponentOptions = {
319-
name: 'app-shell',
320-
module: options.rootModuleFileName,
321-
project: options.clientProject,
322-
};
323-
324-
return schematic('component', componentOptions)(host, context);
311+
const componentOptions: ComponentOptions = {
312+
name: 'app-shell',
313+
module: options.rootModuleFileName,
314+
project: options.clientProject,
325315
};
316+
317+
return schematic('component', componentOptions);
326318
}
327319

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

0 commit comments

Comments
 (0)