Skip to content

Commit 4dd7069

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 28b0d53 commit 4dd7069

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

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

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,23 @@ interface Options {
2424

2525
export function migrate(options: Options): Rule {
2626
return async (tree: Tree, context: SchematicContext) => {
27+
const resolvedOptions = {
28+
path: options.path ?? './',
29+
format: options.format ?? true,
30+
};
31+
2732
let allPaths = [];
2833
const basePath = process.cwd();
2934
let pathToMigrate: string | undefined;
30-
if (options.path) {
31-
pathToMigrate = normalizePath(join(basePath, options.path));
35+
36+
if (resolvedOptions.path) {
37+
if (resolvedOptions.path.startsWith('..')) {
38+
throw new SchematicsException(
39+
'Cannot run control flow migration outside of the current project.',
40+
);
41+
}
42+
43+
pathToMigrate = normalizePath(join(basePath, resolvedOptions.path));
3244
if (pathToMigrate.trim() !== '') {
3345
allPaths.push(pathToMigrate);
3446
}

0 commit comments

Comments
 (0)