Skip to content

Commit 45964c7

Browse files
committed
refactor(@schematics/angular): update internal schematics utilities to use built-in POSIX path utilities
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 db7f465 commit 45964c7

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

packages/schematics/angular/utility/ng-ast-utils.ts

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

9-
import { normalize } from '@angular-devkit/core';
109
import { SchematicsException, Tree } from '@angular-devkit/schematics';
11-
import { dirname } from 'path';
10+
import { dirname, join } from 'node:path/posix';
1211
import * as ts from '../third_party/github.com/Microsoft/TypeScript/lib/typescript';
1312
import { findNode, getSourceNodes } from '../utility/ast-utils';
1413
import { findBootstrapApplicationCall } from './standalone/util';
@@ -75,7 +74,7 @@ function findBootstrapModulePath(host: Tree, mainPath: string): string {
7574
export function getAppModulePath(host: Tree, mainPath: string): string {
7675
const moduleRelativePath = findBootstrapModulePath(host, mainPath);
7776
const mainDir = dirname(mainPath);
78-
const modulePath = normalize(`/${mainDir}/${moduleRelativePath}.ts`);
77+
const modulePath = join(mainDir, `${moduleRelativePath}.ts`);
7978

8079
return modulePath;
8180
}

packages/schematics/angular/utility/paths.ts

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

9-
import { normalize, split } from '@angular-devkit/core';
9+
import { join, relative } from 'node:path/posix';
1010

1111
export function relativePathToWorkspaceRoot(projectRoot: string | undefined): string {
12-
const normalizedPath = split(normalize(projectRoot || ''));
13-
14-
if (normalizedPath.length === 0 || !normalizedPath[0]) {
12+
if (!projectRoot) {
1513
return '.';
16-
} else {
17-
return normalizedPath.map(() => '..').join('/');
1814
}
15+
16+
return relative(join('/', projectRoot), '/') || '.';
1917
}

0 commit comments

Comments
 (0)