From 5343c3115201b13b75d439cc3316e90550cf4af9 Mon Sep 17 00:00:00 2001 From: Charles Lyding <19598772+clydin@users.noreply.github.com> Date: Fri, 8 Mar 2024 17:33:27 -0500 Subject: [PATCH] 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. --- packages/schematics/angular/app-shell/index.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/schematics/angular/app-shell/index.ts b/packages/schematics/angular/app-shell/index.ts index 1db4ffbf4a..e856b1bf69 100644 --- a/packages/schematics/angular/app-shell/index.ts +++ b/packages/schematics/angular/app-shell/index.ts @@ -6,7 +6,6 @@ * found in the LICENSE file at https://angular.io/license */ -import { dirname, join, normalize } from '@angular-devkit/core'; import { Rule, SchematicsException, @@ -15,6 +14,7 @@ import { noop, schematic, } from '@angular-devkit/schematics'; +import { dirname, join } from 'node:path/posix'; import ts from '../third_party/github.com/Microsoft/TypeScript/lib/typescript'; import { addImportToModule, @@ -43,14 +43,14 @@ function getSourceFile(host: Tree, path: string): ts.SourceFile { } function getServerModulePath(host: Tree, sourceRoot: string, mainPath: string): string | null { - const mainSource = getSourceFile(host, join(normalize(sourceRoot), mainPath)); + const mainSource = getSourceFile(host, join(sourceRoot, mainPath)); const allNodes = getSourceNodes(mainSource); 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(`/${sourceRoot}/${relativePath.text}.ts`); + const modulePath = join(sourceRoot, `${relativePath.text}.ts`); return modulePath; } @@ -77,7 +77,7 @@ function getComponentTemplate(host: Tree, compPath: string, tmplInfo: TemplateIn template = tmplInfo.templateProp.getFullText(); } else if (tmplInfo.templateUrlProp) { const templateUrl = (tmplInfo.templateUrlProp.initializer as ts.StringLiteral).text; - const dir = dirname(normalize(compPath)); + const dir = dirname(compPath); const templatePath = join(dir, templateUrl); try { template = host.readText(templatePath); @@ -121,7 +121,7 @@ function getBootstrapComponentPath(host: Tree, mainPath: string): string { return pathStringLiteral.text; })[0]; - return join(dirname(normalize(bootstrappingFilePath)), componentRelativeFilePath + '.ts'); + return join(dirname(bootstrappingFilePath), componentRelativeFilePath + '.ts'); } // end helper functions. @@ -308,7 +308,7 @@ function addStandaloneServerRoute(options: AppShellOptions): Rule { throw new SchematicsException(`Project name "${options.project}" doesn't not exist.`); } - const configFilePath = join(normalize(project.sourceRoot ?? 'src'), 'app/app.config.server.ts'); + const configFilePath = join(project.sourceRoot ?? 'src', 'app/app.config.server.ts'); if (!host.exists(configFilePath)) { throw new SchematicsException(`Cannot find "${configFilePath}".`); }