kernelIsStale method

Future<bool> kernelIsStale(
  1. List<ConstructYaml> constructs,
  2. Directory root, {
  3. File? cachedKernel,
})

Returns true when construct package sources are newer than the compiled kernel. Path dependencies (common in monorepos) change without updating construct.yaml, so asset equality alone is not enough.

Also checks path packages the entrypoint imports (notably package:revali) — the kernel AOT-compiles those sources, so edits there must invalidate it.

Implementation

Future<bool> kernelIsStale(
  List<ConstructYaml> constructs,
  Directory root, {
  File? cachedKernel,
}) async {
  final kernel = await root.getInternalRevaliFile(kernelFile);
  final candidates = <File>[
    if (kernel.existsSync()) kernel,
    if (cachedKernel != null && cachedKernel.existsSync()) cachedKernel,
  ];

  if (candidates.isEmpty) {
    return true;
  }

  // Use the newest available kernel as the baseline.
  candidates.sort(
    (a, b) => b.lastModifiedSync().compareTo(a.lastModifiedSync()),
  );
  return _fileNewerThanSources(candidates.first, constructs, root);
}