Skip to content

Commit 5d8abe5

Browse files
committed
update getChangesSinceLastFileVersion
1 parent 8b885fb commit 5d8abe5

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

npm-app/src/project-files.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -374,26 +374,28 @@ async function getGitChanges() {
374374
*/
375375
export function getChangesSinceLastFileVersion(
376376
lastFileVersion: Record<string, string>
377-
) {
377+
): Record<string, string> {
378378
const changes = Object.entries(lastFileVersion)
379-
.map(([filePath, file]) => {
379+
.map(([filePath, lastContents]) => {
380380
const fullFilePath = path.join(getProjectRoot(), filePath)
381381
try {
382382
const currentContent = fs.readFileSync(fullFilePath, 'utf8')
383-
if (currentContent === file) {
383+
if (currentContent === lastContents) {
384384
return [filePath, null] as const
385385
}
386-
return [filePath, createPatch(filePath, file, currentContent)] as const
386+
return [
387+
filePath,
388+
createPatch(filePath, lastContents, currentContent),
389+
] as const
387390
} catch (error) {
388-
logger.error(
389-
{
390-
errorMessage:
391-
error instanceof Error ? error.message : String(error),
392-
errorStack: error instanceof Error ? error.stack : undefined,
393-
filePath: fullFilePath,
394-
},
395-
'Error reading file for changes comparison'
396-
)
391+
if (
392+
error instanceof Object &&
393+
'code' in error &&
394+
error.code === 'ENOENT'
395+
) {
396+
return [filePath, createPatch(filePath, lastContents, '')]
397+
}
398+
logger.error({ error }, 'Error reading file while getting file changes')
397399
return [filePath, null] as const
398400
}
399401
})

0 commit comments

Comments
 (0)