fix(misc): make Nx 16 migration safer when treee throws an exception (#16782)
This commit is contained in:
parent
c7ce767298
commit
95594d21f7
@ -4,6 +4,7 @@ import { requireNx } from '../../nx';
|
|||||||
import { visitNotIgnoredFiles } from '../generators/visit-not-ignored-files';
|
import { visitNotIgnoredFiles } from '../generators/visit-not-ignored-files';
|
||||||
import { basename } from 'path';
|
import { basename } from 'path';
|
||||||
import { isBinaryPath } from './binary-extensions';
|
import { isBinaryPath } from './binary-extensions';
|
||||||
|
const { logger } = requireNx();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
getProjects,
|
getProjects,
|
||||||
@ -162,15 +163,23 @@ function replaceMentions(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const contents = tree.read(path).toString();
|
try {
|
||||||
|
const contents = tree.read(path).toString();
|
||||||
|
|
||||||
if (!contents.includes(oldPackageName)) {
|
if (!contents.includes(oldPackageName)) {
|
||||||
return;
|
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)
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1558,7 +1558,7 @@ async function runNxMigration(
|
|||||||
name
|
name
|
||||||
);
|
);
|
||||||
const fn = require(implPath)[fnSymbol];
|
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, {});
|
await fn(host, {});
|
||||||
host.lock();
|
host.lock();
|
||||||
const changes = host.listChanges();
|
const changes = host.listChanges();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user