Skip to content

Commit

Permalink
fix(misc): guard against failure to decode file in migration
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEnder committed Apr 29, 2024
1 parent 9bf197f commit 299223d
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { logger } from '../../utils/logger';
import { Tree } from '../../generators/tree';
import { getProjects } from '../../generators/utils/project-configuration';

Expand Down Expand Up @@ -59,13 +60,23 @@ function parseEnvFile(tree: Tree, envFilePath: string) {
if (!tree.exists(envFilePath)) {
return;
}

let envFileContent = tree.read(envFilePath, 'utf-8');
if (!envFileContent) {
// envFileContent is null if we fail to read the file for any reason
// e.g. the file is not utf-8 encoded
logger.info(
`Unable to update ${envFilePath}. Nx interpolates environment variables in the form of $VAR_NAME. To escape the dollar sign, use \\$VAR_NAME.`
);
return;
}

envFileContent = envFileContent
.split('\n')
.map((line) => {
line = line.trim();

if (!line.includes('$')) {
if (!line || !line.includes('$')) {
return line;
}

Expand Down

0 comments on commit 299223d

Please sign in to comment.