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.
This commit is contained in:
Charles Lyding 2024-03-08 17:33:27 -05:00 committed by Charles
parent 456f08abb6
commit 5343c31152

View File

@ -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}".`);
}