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
_headersgives 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_pathfora, when itsatpath failsat_path_reason.- at_
path_ reason - Why
atis not a valid fixed URL path for an asset, orNonewhen 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 underSERVED_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 amongitems, 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 howbynkc testcompiles; the caller raises it only for a build without tests (review of #1904). A helper here keepsbynk-emit’sproject.rsfree of syntax-tree types (theast_importersprobe).- compose_
unit_ assets - Every asset visible in unit
name: its own, plus those of each commons ituses(one level, the same mixin rulecompose_unit_symbolsapplies to types and functions). A local asset wins over an imported one of the same name; two used commons declaring the same name isbynk.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-Typethe platform servesserved(a URL path) with, by its extension — the table measured againstwrangler dev4.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 isapplication/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 infilesappear (a missing one isbynk.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 isbynk.asset.duplicate; a free function or a type isbynk.resolve.name_conflict(an asset is a value, in the function namespace, and a type name in value position is an error).Nonewhen 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_projectfora: a single-file build emits one module and no Worker, and has no project root to findassets/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_dirfora, 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.envor a source file by mistake (#1883, slice 1b).- path_
errors - The path rules for
a, in order:unsafe_path_error, thenoutside_assets_dir_error(at most one of the two applies). - phase_
asset_ files bynk.asset.missing_filefor each asset whose (otherwise valid) path names no file inavailable— the project’sassets/folder as the caller read it (bynk_project::assets).Noneskips the check: nothing on disk was consulted (an in-memory check). A build passesSome, 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
usesclosure declares with anatpath: - 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 failspath_errorsor names no listed file is skipped (phase_asset_filesreports the latter); a listed file the reader fails on isbynk.asset.unreadable_file, and is left out. - served_
path - The URL path the platform serves the asset file
source(a normalisedassets/…key) with contentbytesat:/_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_pathwith the content hash supplied rather than computed — the one definition of the served name’s shape, shared with the editor, which lists theassets/folder but never reads its bytes and so showsserved_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, whenbuildis set, its refusal (needs_project_error). Placement needs no check here: a single file is always a commons (anadapteris a parse error). - unsafe_
asset_ path_ reason - Why
pathis not a safe asset path, orNonewhen it is. - unsafe_
path_ error bynk.asset.unsafe_pathfora, whenunsafe_asset_path_reasonrejects its path. One constructor for the project pipeline (symbols::build_unit_table) and the single-file compile (bynk-emit’scompile), so the two report it identically.