Skip to content

Commit c306188

Browse files
committed
fix(core): ensure default path is set for control flow migration
When running the control flow migration via `ng update`, the path parameter could be undefined. This change ensures a default value of './' is used when no path is explicitly provided, making the migration work consistently between `ng update` and `ng generate` commands. Fixes angular#63294
1 parent e279f30 commit c306188

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

  • packages/core/schematics/migrations/control-flow-migration

packages/core/schematics/migrations/control-flow-migration/index.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,24 @@ interface Options {
2626

2727
export function migrate(options: Options): Rule {
2828
return async (tree: Tree, context: SchematicContext) => {
29+
// Apply default values from schema when not provided by the migration system
30+
const resolvedOptions = {
31+
path: options.path ?? './',
32+
format: options.format ?? true,
33+
};
34+
2935
let allPaths = [];
3036
const basePath = process.cwd();
3137
let pathToMigrate: string | undefined;
32-
if (options.path) {
33-
if (options.path.startsWith('..')) {
38+
39+
if (resolvedOptions.path) {
40+
if (resolvedOptions.path.startsWith('..')) {
3441
throw new SchematicsException(
3542
'Cannot run control flow migration outside of the current project.',
3643
);
3744
}
3845

39-
pathToMigrate = normalizePath(join(basePath, options.path));
46+
pathToMigrate = normalizePath(join(basePath, resolvedOptions.path));
4047
if (pathToMigrate.trim() !== '') {
4148
allPaths.push(pathToMigrate);
4249
}

0 commit comments

Comments
 (0)