From 1062278829281a695439e8368d28d84d3b6ca15a Mon Sep 17 00:00:00 2001 From: James Daniels Date: Mon, 16 Aug 2021 15:40:31 -0400 Subject: [PATCH] Find and replace on upgrade --- sample/package.json | 2 +- sample/yarn.lock | 8 ++++---- src/schematics/update/v7/index.ts | 16 +++++++++++----- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/sample/package.json b/sample/package.json index 244454a53..a3b840c77 100644 --- a/sample/package.json +++ b/sample/package.json @@ -17,7 +17,7 @@ "@angular/common": "^12.0.0", "@angular/compiler": "^12.0.0", "@angular/core": "^12.0.0", - "@angular/fire": "7.0.0-canary.32f57c2", + "@angular/fire": "7.0.0-canary.d3a9af2", "@angular/forms": "^12.0.0", "@angular/platform-browser": "^12.0.0", "@angular/platform-browser-dynamic": "^12.0.0", diff --git a/sample/yarn.lock b/sample/yarn.lock index 8f89d7aa1..d159461a5 100644 --- a/sample/yarn.lock +++ b/sample/yarn.lock @@ -216,10 +216,10 @@ dependencies: tslib "^2.2.0" -"@angular/fire@7.0.0-canary.32f57c2": - version "7.0.0-canary.32f57c2" - resolved "https://registry.yarnpkg.com/@angular/fire/-/fire-7.0.0-canary.32f57c2.tgz#f22a08f8ab74968cf1d7ad3899c8172b58be6225" - integrity sha512-LniVulI209Z8GLa0rgrr43kJYW6dDIcaxhlRpq8/sv4x2eOKbwDGqnrnDPZkGwLbp7F19B61hLyMSO5aA7+IpA== +"@angular/fire@7.0.0-canary.d3a9af2": + version "7.0.0-canary.d3a9af2" + resolved "https://registry.yarnpkg.com/@angular/fire/-/fire-7.0.0-canary.d3a9af2.tgz#28050f12da5e9310d209ca0a4e2bc3e0a20ab0d4" + integrity sha512-Jrnen55L0xuhGLEGlbtB7kbzN1ZKE/LQN0aASAxlZ/FnD1CRDmlZlYr4Clz1/ZJH6yMu7sMw72NlI7vk/dJoBA== dependencies: tslib "^2.0.0" diff --git a/src/schematics/update/v7/index.ts b/src/schematics/update/v7/index.ts index 328537799..7450bf08a 100644 --- a/src/schematics/update/v7/index.ts +++ b/src/schematics/update/v7/index.ts @@ -34,16 +34,22 @@ export const ngUpdate = (): Rule => ( overwriteIfExists(host, 'package.json', stringifyFormatted(packageJson)); host.visit(filePath => { - if (!filePath.endsWith('.ts')) { + if ( + !filePath.endsWith('.ts') || + filePath.endsWith('.d.ts') || + filePath.startsWith('/node_modules') + ) { return; } - const content = host.read(filePath); + const content = host.read(filePath)?.toString(); if (!content) { return; } - // rewrite imports from `@angular/fire/*` to `@angular/fire/compat/*` - // rewrite imports from `firebase/*` to `firebase/compat/*` - // rewrite imports from `@firebase/*` to `@firebase/compat/*` + // TODO clean this up + content.replace(/(?import|export)\s+(?:(?[\w,{}\s\*]+)\s+from)?\s*(?:(["'])?firebase\/(?[@\w\s\\\/.-]+)\3?)\s*;/, "$1 $2 from $3firebase/compat/$4$3;"); + content.replace(/(?import|export)\s+(?:(?[\w,{}\s\*]+)\s+from)?\s*(?:(["'])?@firebase\/(?[@\w\s\\\/.-]+)\3?)\s*;/, "$1 $2 from $3@firebase/compat/$4$3;"); + content.replace(/(?import|export)\s+(?:(?[\w,{}\s\*]+)\s+from)?\s*(?:(["'])?@angular\/fire\/(?[@\w\s\\\/.-]+)\3?)\s*;/, "$1 $2 from $3@angular/fire/compat/$4$3;"); + host.overwrite(filePath, content); console.log(filePath); });