()
| 14 | } |
| 15 | |
| 16 | export const ngUpdate = (): Rule => ( |
| 17 | host: Tree, |
| 18 | context: SchematicContext |
| 19 | ) => { |
| 20 | const packageJson = host.exists('package.json') && safeReadJSON('package.json', host); |
| 21 | |
| 22 | if (packageJson === undefined) { |
| 23 | throw new SchematicsException('Could not locate package.json'); |
| 24 | } |
| 25 | |
| 26 | Object.keys(peerDependencies).forEach(depName => { |
| 27 | const dep = peerDependencies[depName]; |
| 28 | if (dep) { |
| 29 | packageJson[dep.dev ? 'devDependencies' : 'dependencies'][depName] = dep.version; |
| 30 | } |
| 31 | }); |
| 32 | |
| 33 | // TODO test if it's a SSR project in the JSON |
| 34 | Object.keys(firebaseFunctionsDependencies).forEach(depName => { |
| 35 | const dep = firebaseFunctionsDependencies[depName]; |
| 36 | if (dep.dev && packageJson.devDependencies[depName]) { |
| 37 | packageJson.devDependencies[depName] = dep.version; |
| 38 | } else if (packageJson.dependencies[depName]) { |
| 39 | packageJson.dependencies[depName] = dep.version; |
| 40 | } |
| 41 | }); |
| 42 | |
| 43 | overwriteIfExists(host, 'package.json', stringifyFormatted(packageJson)); |
| 44 | context.addTask(new NodePackageInstallTask()); |
| 45 | |
| 46 | const angularJson = host.exists('angular.json') && safeReadJSON('angular.json', host); |
| 47 | if (packageJson === undefined) { |
| 48 | throw new SchematicsException('Could not locate angular.json'); |
| 49 | } |
| 50 | |
| 51 | // TODO investigate if this is correct in Windows |
| 52 | const srcRoots: string[] = Object.values(angularJson.projects).map((it: any) => |
| 53 | join(...['/', it.root, it.sourceRoot].filter(it => !!it)) |
| 54 | ); |
| 55 | |
| 56 | host.visit(filePath => { |
| 57 | if ( |
| 58 | !filePath.endsWith('.ts') || |
| 59 | filePath.endsWith('.d.ts') || |
| 60 | !srcRoots.find(root => filePath.startsWith(root)) |
| 61 | ) { |
| 62 | return; |
| 63 | } |
| 64 | const content = host.read(filePath)?.toString(); |
| 65 | if (!content) { |
| 66 | return; |
| 67 | } |
| 68 | const newContent = content.replace(IMPORT_REGEX, (substring, ...args) => { |
| 69 | const { alias, key, ref, quote, term }: ImportRegexMatch = args.pop(); |
| 70 | if (ref.startsWith('@angular/fire') && !ref.startsWith('@angular/fire/compat')) { |
| 71 | return `${key} ${alias} from ${quote}${ref.replace('@angular/fire', '@angular/fire/compat')}${quote}${term}`; |
| 72 | } |
| 73 | if (ref.startsWith('firebase') && !ref.startsWith('firebase/compat')) { |
nothing calls this directly
no test coverage detected