From 580217f5f179ad8ce08f91993a0382d2f0dfde9a Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Tue, 23 Apr 2019 17:56:22 +0100 Subject: [PATCH] fix(@schematics/angular): workaround bug in recorder/update --- .../migrations/update-8/differential-loading.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/schematics/angular/migrations/update-8/differential-loading.ts b/packages/schematics/angular/migrations/update-8/differential-loading.ts index b753c1c9aa02..2d55c33cd4d9 100644 --- a/packages/schematics/angular/migrations/update-8/differential-loading.ts +++ b/packages/schematics/angular/migrations/update-8/differential-loading.ts @@ -112,9 +112,21 @@ function updateBrowserlist(): Rule { const browserslistPath = join(normalize(project.root), 'browserslist'); if (typeof project.sourceRoot === 'string') { + // Move the CLI 7 style browserlist to root if it's there. const srcBrowsersList = join(normalize(project.sourceRoot), 'browserslist'); - if (tree.exists(srcBrowsersList)) { - tree.rename(srcBrowsersList, browserslistPath); + if (tree.exists(srcBrowsersList) && !tree.exists(browserslistPath)) { + // TODO: use rename instead. + // This is a hacky workaround. We should be able to just rename it. + // On unit tests the rename works fine but on real projects it fails with + // ERROR! browserslist does not exist.. + // This seems to happen because we are both renaming and then commiting an update. + // But it's fine if we read/create/delete. There's a bug somewhere. + // tree.rename(srcBrowsersList, browserslistPath); + const content = tree.read(srcBrowsersList); + if (content) { + tree.create(browserslistPath, content); + tree.delete(srcBrowsersList); + } } }