The digest can load its chart only for runs that request --chart. In Python, an
ordinary import can sit inside the condition. A JavaScript import declaration
inside that block causes a syntax error before the file starts, even when the
condition would be false.
Keep declarations at the module’s top level. Use the import() expression where
optional code is needed. It returns a promise for the module’s namespace object;
await supplies that object, and destructuring selects its named chart function.
Without await, reading the function from the promise gives undefined.
Keep all earlier imports, the setting’s setter call, the plant loop, the collected
peaks, the fault report, and the entry-file guard. Inside the existing async
main(args), replace only the optional chart block:
if (args.includes("--chart")) {
const { peakChart } = await import("#boiler/chart.js");
console.log(peakChart(peaks));
}
Run node digest.js logs/week-12 --chart for the ordinary three-plant report and
the complete weekly chart. Without --chart, the report stays the same and the
chart module isn’t loaded. The existing --verbose option still reports the
science log’s skipped line on standard error and can be combined with --chart.