Skip to content

Commit 5343c31

Browse files
committed
refactor(@schematics/angular): use built-in POSIX path utilities for app-shell schematic
The use of the custom path functions from `@angular-devkit/core` have been removed in favor of the built-in functions from Node.js. These provide equivalent functionality with an improvement in performance. The amount of custom code executed has also been reduced.
1 parent 456f08a commit 5343c31

File tree

1 file changed

+6
-6
lines changed
  • packages/schematics/angular/app-shell

1 file changed

+6
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
import { dirname, join, normalize } from '@angular-devkit/core';
109
import {
1110
Rule,
1211
SchematicsException,
@@ -15,6 +14,7 @@ import {
1514
noop,
1615
schematic,
1716
} from '@angular-devkit/schematics';
17+
import { dirname, join } from 'node:path/posix';
1818
import ts from '../third_party/github.com/Microsoft/TypeScript/lib/typescript';
1919
import {
2020
addImportToModule,
@@ -43,14 +43,14 @@ function getSourceFile(host: Tree, path: string): ts.SourceFile {
4343
}
4444

4545
function getServerModulePath(host: Tree, sourceRoot: string, mainPath: string): string | null {
46-
const mainSource = getSourceFile(host, join(normalize(sourceRoot), mainPath));
46+
const mainSource = getSourceFile(host, join(sourceRoot, mainPath));
4747
const allNodes = getSourceNodes(mainSource);
4848
const expNode = allNodes.find((node) => ts.isExportDeclaration(node));
4949
if (!expNode) {
5050
return null;
5151
}
5252
const relativePath = (expNode as ts.ExportDeclaration).moduleSpecifier as ts.StringLiteral;
53-
const modulePath = normalize(`/${sourceRoot}/${relativePath.text}.ts`);
53+
const modulePath = join(sourceRoot, `${relativePath.text}.ts`);
5454

5555
return modulePath;
5656
}
@@ -77,7 +77,7 @@ function getComponentTemplate(host: Tree, compPath: string, tmplInfo: TemplateIn
7777
template = tmplInfo.templateProp.getFullText();
7878
} else if (tmplInfo.templateUrlProp) {
7979
const templateUrl = (tmplInfo.templateUrlProp.initializer as ts.StringLiteral).text;
80-
const dir = dirname(normalize(compPath));
80+
const dir = dirname(compPath);
8181
const templatePath = join(dir, templateUrl);
8282
try {
8383
template = host.readText(templatePath);
@@ -121,7 +121,7 @@ function getBootstrapComponentPath(host: Tree, mainPath: string): string {
121121
return pathStringLiteral.text;
122122
})[0];
123123

124-
return join(dirname(normalize(bootstrappingFilePath)), componentRelativeFilePath + '.ts');
124+
return join(dirname(bootstrappingFilePath), componentRelativeFilePath + '.ts');
125125
}
126126
// end helper functions.
127127

@@ -308,7 +308,7 @@ function addStandaloneServerRoute(options: AppShellOptions): Rule {
308308
throw new SchematicsException(`Project name "${options.project}" doesn't not exist.`);
309309
}
310310

311-
const configFilePath = join(normalize(project.sourceRoot ?? 'src'), 'app/app.config.server.ts');
311+
const configFilePath = join(project.sourceRoot ?? 'src', 'app/app.config.server.ts');
312312
if (!host.exists(configFilePath)) {
313313
throw new SchematicsException(`Cannot find "${configFilePath}".`);
314314
}

0 commit comments

Comments
 (0)