Skip to main content

Module assets

Module assets 

Source
Expand description

#1883 (static assets): the checker-side rules for asset name = "path" declarations — the path rules, the name rule, the composition of a unit’s visible assets through uses ([DECISION G]) — and (slice 1b) the build side’s shared definitions: the existence check, the served URL path, and the files each Worker ships.

The checker stays disk-free (bynk-wasm compiles it with no filesystem): the project’s assets/ folder reaches it from the caller (bynk_project::assets), as a path set or as an AssetFolder whose reader it calls for the declared files alone (read_declared_files).

Constants§

SERVED_PREFIX
The URL path prefix every asset is served under. A handler route under it is reserved for assets (slice 2’s check), and _headers gives everything under it an immutable cache lifetime.

Functions§

asset_key
The key a declaration’s served path is filed under (declared_served_paths): its normalised source path, plus its fixed URL path when it has one — so one file may be served both content-hashed and at a fixed path.
at_path_error
bynk.asset.invalid_at_path for a, when its at path fails at_path_reason.
at_path_reason
Why at is not a valid fixed URL path for an asset, or None when it is. It must be an absolute URL path naming a file: starting with /, not ending in /, with no empty, . or .. segment, and only [A-Za-z0-9._~-] between the slashes (so it needs no encoding). It may not lie under SERVED_PREFIX (the content-hashed files’ space) or /_bynk/ (Bynk’s own dispatch), nor be one of the root files the platform reads as configuration (/_headers, /_redirects, /.assetsignore).
bundle_not_served_warnings
bynk.asset.not_served (a warning) for each asset among items, for a deployable Bundle build: a Bundle ships no Worker and so no files, yet each module still carries its asset’s .url, which would 404 wherever the output is served. A warning, not an error, because a Bundle build is also how bynkc test compiles; the caller raises it only for a build without tests (review of #1904). A helper here keeps bynk-emit’s project.rs free of syntax-tree types (the ast_importers probe).
compose_unit_assets
Every asset visible in unit name: its own, plus those of each commons it uses (one level, the same mixin rule compose_unit_symbols applies to types and functions). A local asset wins over an imported one of the same name; two used commons declaring the same name is bynk.uses.name_conflict (phase_uses_name_conflicts), so which of them is kept here is never observable in a program that checks.
content_type_for
The Content-Type the platform serves served (a URL path) with, by its extension — the table measured against wrangler dev 4.107.0 (#1883, slice 3), so a suite fetching an asset (svc.GET(style)) sees what production sends. Text types carry ; charset=utf-8. A file with no extension is served with no content type, here ""; an extension the table does not know is application/octet-stream.
declared_served_paths
Every declared asset’s served path, keyed by asset_key — what the emitter writes as each .url: its fixed path (at "/favicon.ico", slice 2) or its content-hashed one (served_path). Only declarations whose file is in files appear (a missing one is bynk.asset.missing_file).
deployed_assets
The files a context’s Worker ships, keyed by served path, each mapped to its normalised source path. Sorted and deduplicated by served path, so the output is reproducible.
name_error
The name rule for asset a, given what its unit already declares under that name: an earlier asset is bynk.asset.duplicate; a free function or a type is bynk.resolve.name_conflict (an asset is a value, in the function namespace, and a type name in value position is an error). None when the name is free. One rule for the project pipeline (symbols::build_unit_table) and the single-file compile, which has no unit table (review of #1903).
needs_project_error
bynk.asset.needs_project for a: a single-file build emits one module and no Worker, and has no project root to find assets/ under, so it cannot ship a file. Checking a single file (bynk check page.bynk) is unaffected; building one that declares an asset is refused. Build the project instead.
outside_assets_dir_error
bynk.asset.outside_assets_dir for a, when its path is safe but does not lie inside the project’s assets folder ([bynk_project::assets::PROJECT_ASSETS_DIR]). Assets are public, so they come only from that folder, and a declaration can never publish .env or a source file by mistake (#1883, slice 1b).
path_errors
The path rules for a, in order: unsafe_path_error, then outside_assets_dir_error (at most one of the two applies).
phase_asset_files
bynk.asset.missing_file for each asset whose (otherwise valid) path names no file in available — the project’s assets/ folder as the caller read it (bynk_project::assets). None skips the check: nothing on disk was consulted (an in-memory check). A build passes Some, an empty set when it had no filesystem, so it never invents a URL for a file nobody read.
phase_asset_routes
#1883, slice 2 ([DECISION C]): fixed asset paths against each Worker’s routes. For every context, over the assets its uses closure declares with an at path:
read_declared_files
The bytes of every declared asset file in folder, keyed by normalised path — read through the folder’s reader once each, and only for a file a declaration names, so a large file nothing declares is never read. A declaration whose path fails path_errors or names no listed file is skipped (phase_asset_files reports the latter); a listed file the reader fails on is bynk.asset.unreadable_file, and is left out.
served_path
The URL path the platform serves the asset file source (a normalised assets/… key) with content bytes at: /_assets/<stem>.<hash>.<ext>, where <hash> is the content’s FNV-1a 64 (crate::contract::fnv1a64_hex) and <stem>/<ext> are the file name’s, split at its last . (no .<ext> when it has none).
served_path_with_hash
served_path with the content hash supplied rather than computed — the one definition of the served name’s shape, shared with the editor, which lists the assets/ folder but never reads its bytes and so shows served_path_with_hash(source, "<hash>") (#1883, editor tooling).
single_file_asset_errors
The single-file compile’s asset diagnostics, in declaration order: each asset’s path check and name rule (name_error, against the file’s own functions, types and earlier assets), and, when build is set, its refusal (needs_project_error). Placement needs no check here: a single file is always a commons (an adapter is a parse error).
unsafe_asset_path_reason
Why path is not a safe asset path, or None when it is.
unsafe_path_error
bynk.asset.unsafe_path for a, when unsafe_asset_path_reason rejects its path. One constructor for the project pipeline (symbols::build_unit_table) and the single-file compile (bynk-emit’s compile), so the two report it identically.