diff --git a/packages/devkit/src/utils/replace-package.ts b/packages/devkit/src/utils/replace-package.ts index 478deea67f..e9f439db0c 100644 --- a/packages/devkit/src/utils/replace-package.ts +++ b/packages/devkit/src/utils/replace-package.ts @@ -4,6 +4,7 @@ import { requireNx } from '../../nx'; import { visitNotIgnoredFiles } from '../generators/visit-not-ignored-files'; import { basename } from 'path'; import { isBinaryPath } from './binary-extensions'; +const { logger } = requireNx(); const { getProjects, @@ -162,15 +163,23 @@ function replaceMentions( return; } - const contents = tree.read(path).toString(); + try { + const contents = tree.read(path).toString(); - if (!contents.includes(oldPackageName)) { - return; + if (!contents.includes(oldPackageName)) { + return; + } + + tree.write( + path, + contents.replace(new RegExp(oldPackageName, 'g'), newPackageName) + ); + } catch { + // Its **probably** ok, contents can be null if the file is too large or + // there was an access exception. + logger.warn( + `An error was thrown when trying to update ${path}. If you believe the migration should have updated it, be sure to review the file and open an issue.` + ); } - - tree.write( - path, - contents.replace(new RegExp(oldPackageName, 'g'), newPackageName) - ); }); } diff --git a/packages/nx/src/command-line/migrate/migrate.ts b/packages/nx/src/command-line/migrate/migrate.ts index b5f0592e8a..5942e928bc 100644 --- a/packages/nx/src/command-line/migrate/migrate.ts +++ b/packages/nx/src/command-line/migrate/migrate.ts @@ -1558,7 +1558,7 @@ async function runNxMigration( name ); const fn = require(implPath)[fnSymbol]; - const host = new FsTree(root, false); + const host = new FsTree(root, process.env.NX_VERBOSE_LOGGING === 'true'); await fn(host, {}); host.lock(); const changes = host.listChanges();