framework
framework copied to clipboard
Fallback to CDN imports when libraries needed by FileAttachment are not detected through static analysis
The FileAttachment
methods have implicit imports:
-
FileAttachment.dsv
,FileAttachment.csv
, andFileAttachment.tsv
usenpm:d3-dsv
. -
FileAttachment.arrow
usesnpm:apache-arrow
. -
FileAttachment.parquet
usesnpm:apache-arrow
andnpm:parquet-wasm
. -
FileAttachment.arquero
usesnpm:arquero
, and maybenpm:apache-arrow
andnpm:parquet-wasm
. -
FileAttachment.sqlite
usesobservablehq:stdlib/sqlite
. -
FileAttachment.zip
usesobservablehq:stdlib/zip
. -
FileAttachment.xlsx
usesobservablehq:stdlib/xlsx
.
Normally we detect these through static analysis, but we can’t guarantee that we always detect which methods are used through static analysis. For example see https://talk.observablehq.com/t/404-errors-in-module-load/9623. A trivial example where static analysis fails is:
const file = FileAttachment("file.csv");
const data = await file.csv();
When static analysis fails, built sites currently break because they try to load the self-hosted copy of the library (which doesn’t exist because we only host copies of libraries that we know are used). Perhaps we should fallback to jsDelivr instead, so at least the site keeps working?
Alternatively, we could add a copy of these libraries even if we don’t detect that they’re used, but I don’t think people will like hosting copies of unused libraries.
Alternatively, we could make the static analysis heuristic more lax, for example looking for file.csv()
calls and not just FileAttachment("name.csv").csv()
calls, but that could have false positives.
Related #1574.