Skip to content

Commit

Permalink
fix(google-maps): resolve CLI errors in ng update schematic (#29947)
Browse files Browse the repository at this point in the history
* Fixes that the schematic was throwing an error for non-UTF8 files, because we were using `Tree.readText` instead of `Tree.read.toString`.
* Fixes that we appear to be traversing the `node_modules`.

Fixes #29917.

(cherry picked from commit f890455)
  • Loading branch information
crisbeto committed Oct 31, 2024
1 parent 1975f3f commit 74c2a08
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/google-maps/schematics/ng-update/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ const DEPRECATED_CLASS_NAME = 'DeprecatedMapMarkerClusterer';
export function updateToV19(): Rule {
return tree => {
tree.visit(path => {
if (path.includes('node_modules')) {
return;
}

if (path.endsWith('.html')) {
const content = tree.readText(path);
const content = tree.read(path)?.toString();

if (content.includes('<' + TAG_NAME)) {
if (content && content.includes('<' + TAG_NAME)) {
tree.overwrite(path, migrateHtml(content));
}
} else if (path.endsWith('.ts') && !path.endsWith('.d.ts')) {
Expand All @@ -48,13 +52,14 @@ function migrateHtml(content: string): string {

/** Migrates a TypeScript file from the old tag and class names to the new ones. */
function migrateTypeScript(path: Path, tree: Tree) {
const content = tree.readText(path);
const content = tree.read(path)?.toString();

// Exit early if none of the symbols we're looking for are mentioned.
if (
!content.includes('<' + TAG_NAME) &&
!content.includes(MODULE_NAME) &&
!content.includes(CLASS_NAME)
!content ||
(!content.includes('<' + TAG_NAME) &&
!content.includes(MODULE_NAME) &&
!content.includes(CLASS_NAME))
) {
return;
}
Expand Down

0 comments on commit 74c2a08

Please sign in to comment.