Skip to content

Commit 65c74ed

Browse files
alan-agius4thePunderWoman
authored andcommitted
fix(migrations): normalize paths to posix (#48850)
Both TypeScript and Angular Schematic rely on posix system paths which can cause issues on Windows if paths are not normalized correctly. Such as `sourceFile.fileName.startsWith(pathToMigrate)` on Windows will always return falsey. PR Close #48850
1 parent 2796230 commit 65c74ed

File tree

1 file changed

+7
-1
lines changed
  • packages/core/schematics/ng-generate/standalone-migration

1 file changed

+7
-1
lines changed

packages/core/schematics/ng-generate/standalone-migration/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ interface Options {
2929
mode: MigrationMode;
3030
}
3131

32+
const normalizePath = (path: string): string => path.replace(/\\/g, '/');
33+
3234
export default function(options: Options): Rule {
3335
return async (tree) => {
3436
const {buildPaths, testPaths} = await getProjectTsConfigPaths(tree);
@@ -59,7 +61,11 @@ function standaloneMigration(tree: Tree, tsconfigPath: string, basePath: string,
5961
options: {_enableTemplateTypeChecker: true, compileNonExportedClasses: true}
6062
}) as NgtscProgram;
6163
const printer = ts.createPrinter();
62-
const pathToMigrate = join(basePath, options.path);
64+
65+
// TS and Schematic use paths in POSIX format even on Windows.
66+
// This is needed as otherwise string matching such as
67+
// `sourceFile.fileName.startsWith(pathToMigrate)` will not work correctly.
68+
const pathToMigrate = normalizePath(join(basePath, options.path));
6369

6470
if (existsSync(pathToMigrate) && !statSync(pathToMigrate).isDirectory()) {
6571
throw new SchematicsException(`Migration path ${

0 commit comments

Comments
 (0)