Skip to content

Commit 182d4a0

Browse files
committed
fix: emit warning if input.json is modified during run and prefilled with defaults (#672)
1 parent bcef7e3 commit 182d4a0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

src/commands/run.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,21 @@ export class RunCommand extends ApifyCommand<typeof RunCommand> {
357357
} finally {
358358
if (storedInputResults) {
359359
if (storedInputResults.existingInput) {
360+
// Check if the input file was modified since we modified it. If it was, we abort the re-overwrite and warn the user
361+
const stats = await stat(storedInputResults.inputFilePath);
362+
363+
const mtime = Math.trunc(stats.mtimeMs);
364+
365+
// If its in a 5ms range, we assume the file was modified (realistically impossible)
366+
if (mtime - storedInputResults.writtenAt >= 5) {
367+
warning({
368+
message: `The "${storedInputResults.inputFilePath}" file was overwritten during the run. The CLI will not undo the setting of missing default fields from your input schema.`,
369+
});
370+
371+
// eslint-disable-next-line no-unsafe-finally -- we do not return anything in the commands anyways
372+
return;
373+
}
374+
360375
// Overwrite with the original input
361376
await writeFile(storedInputResults.inputFilePath, storedInputResults.existingInput.body);
362377
} else {
@@ -398,6 +413,7 @@ export class RunCommand extends ApifyCommand<typeof RunCommand> {
398413
return {
399414
existingInput,
400415
inputFilePath,
416+
writtenAt: Date.now(),
401417
};
402418
}
403419

@@ -457,6 +473,7 @@ export class RunCommand extends ApifyCommand<typeof RunCommand> {
457473
return {
458474
existingInput,
459475
inputFilePath,
476+
writtenAt: Date.now(),
460477
};
461478
}
462479

@@ -468,6 +485,7 @@ export class RunCommand extends ApifyCommand<typeof RunCommand> {
468485
return {
469486
existingInput,
470487
inputFilePath,
488+
writtenAt: Date.now(),
471489
};
472490
}
473491

@@ -501,6 +519,7 @@ export class RunCommand extends ApifyCommand<typeof RunCommand> {
501519
return {
502520
existingInput,
503521
inputFilePath,
522+
writtenAt: Date.now(),
504523
};
505524
}
506525

0 commit comments

Comments
 (0)