Skip to content

Commit 1062278

Browse files
committed
Find and replace on upgrade
1 parent d3a9af2 commit 1062278

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

sample/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"@angular/common": "^12.0.0",
1818
"@angular/compiler": "^12.0.0",
1919
"@angular/core": "^12.0.0",
20-
"@angular/fire": "7.0.0-canary.32f57c2",
20+
"@angular/fire": "7.0.0-canary.d3a9af2",
2121
"@angular/forms": "^12.0.0",
2222
"@angular/platform-browser": "^12.0.0",
2323
"@angular/platform-browser-dynamic": "^12.0.0",

sample/yarn.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@
216216
dependencies:
217217
tslib "^2.2.0"
218218

219-
"@angular/[email protected].32f57c2":
220-
version "7.0.0-canary.32f57c2"
221-
resolved "https://registry.yarnpkg.com/@angular/fire/-/fire-7.0.0-canary.32f57c2.tgz#f22a08f8ab74968cf1d7ad3899c8172b58be6225"
222-
integrity sha512-LniVulI209Z8GLa0rgrr43kJYW6dDIcaxhlRpq8/sv4x2eOKbwDGqnrnDPZkGwLbp7F19B61hLyMSO5aA7+IpA==
219+
"@angular/[email protected].d3a9af2":
220+
version "7.0.0-canary.d3a9af2"
221+
resolved "https://registry.yarnpkg.com/@angular/fire/-/fire-7.0.0-canary.d3a9af2.tgz#28050f12da5e9310d209ca0a4e2bc3e0a20ab0d4"
222+
integrity sha512-Jrnen55L0xuhGLEGlbtB7kbzN1ZKE/LQN0aASAxlZ/FnD1CRDmlZlYr4Clz1/ZJH6yMu7sMw72NlI7vk/dJoBA==
223223
dependencies:
224224
tslib "^2.0.0"
225225

src/schematics/update/v7/index.ts

+11-5
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,22 @@ export const ngUpdate = (): Rule => (
3434
overwriteIfExists(host, 'package.json', stringifyFormatted(packageJson));
3535

3636
host.visit(filePath => {
37-
if (!filePath.endsWith('.ts')) {
37+
if (
38+
!filePath.endsWith('.ts') ||
39+
filePath.endsWith('.d.ts') ||
40+
filePath.startsWith('/node_modules')
41+
) {
3842
return;
3943
}
40-
const content = host.read(filePath);
44+
const content = host.read(filePath)?.toString();
4145
if (!content) {
4246
return;
4347
}
44-
// rewrite imports from `@angular/fire/*` to `@angular/fire/compat/*`
45-
// rewrite imports from `firebase/*` to `firebase/compat/*`
46-
// rewrite imports from `@firebase/*` to `@firebase/compat/*`
48+
// TODO clean this up
49+
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;");
50+
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;");
51+
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;");
52+
host.overwrite(filePath, content);
4753
console.log(filePath);
4854
});
4955

0 commit comments

Comments
 (0)