Skip to content

Commit 4c35b57

Browse files
committed
fix(@schematics/angular): prevent accidental deletion of main.ts during application builder migration
In certain cases, misconfiguration of the server builder could cause the migration process to incorrectly delete `main.ts`. Closes: #29661 (cherry picked from commit 9107dea)
1 parent 96e5dcb commit 4c35b57

File tree

1 file changed

+4
-1
lines changed
  • packages/schematics/angular/migrations/use-application-builder

1 file changed

+4
-1
lines changed

packages/schematics/angular/migrations/use-application-builder/migration.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,10 @@ function* updateBuildTarget(
151151
// Update server file
152152
const ssrMainFile = serverTarget?.options?.['main'];
153153
if (typeof ssrMainFile === 'string') {
154-
yield deleteFile(ssrMainFile);
154+
// Do not delete the server main file if it's the same as the browser file.
155+
if (buildTarget.options?.browser !== ssrMainFile) {
156+
yield deleteFile(ssrMainFile);
157+
}
155158

156159
yield externalSchematic('@schematics/angular', 'ssr', {
157160
project: projectName,

0 commit comments

Comments
 (0)