Skip to content

Commit

Permalink
Find and replace on upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdaniels committed Aug 16, 2021
1 parent d3a9af2 commit 1062278
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion sample/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions sample/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
16 changes: 11 additions & 5 deletions src/schematics/update/v7/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(/(?<key>import|export)\s+(?:(?<alias>[\w,{}\s\*]+)\s+from)?\s*(?:(["'])?firebase\/(?<ref>[@\w\s\\\/.-]+)\3?)\s*;/, "$1 $2 from $3firebase/compat/$4$3;");
content.replace(/(?<key>import|export)\s+(?:(?<alias>[\w,{}\s\*]+)\s+from)?\s*(?:(["'])?@firebase\/(?<ref>[@\w\s\\\/.-]+)\3?)\s*;/, "$1 $2 from $3@firebase/compat/$4$3;");
content.replace(/(?<key>import|export)\s+(?:(?<alias>[\w,{}\s\*]+)\s+from)?\s*(?:(["'])?@angular\/fire\/(?<ref>[@\w\s\\\/.-]+)\3?)\s*;/, "$1 $2 from $3@angular/fire/compat/$4$3;");
host.overwrite(filePath, content);
console.log(filePath);
});

Expand Down

0 comments on commit 1062278

Please sign in to comment.