Skip to content

@blazetrails/zeitwerk ​

Build-time autoloader for Trails, mirroring Zeitwerk

MeasureValue
Rails counterpartzeitwerk v2.7.3
API methods matched100% (210 of 210)
Rails tests matched100% (24 of 24) (1 permanent)
Ruby files ported19
Ruby files unported0
Measured atfe89b44726

Gaps by file ​

No gaps recorded for this package.

Missing methods ​

None recorded for this package.

Unported Ruby files ​

Every compared Ruby file has a TypeScript file.

Deviation receipts ​

JSDoc receipt tags in the package's source, by the receipt each carries.

TagPERMANENTCONVERGEABLEnone
@noRailsEquivalent2400
@missingRailsCall200
@missingRailsArgs300
@inventedArm1900
@inlinedFrom001
@internal0069

Permanently skipped tests ​

Module#autoload is a build step (Zeitwerk::Loader#define_autoload) (25)
No section cited (2)
Method visibility is compile-time only (Module#private, basic_obj_respond_to's pub) (3)

Ratified deviations ​

Each rule below is ratified in the repository's CLAUDE.md files. The first paragraph is quoted; the link opens the full section at this build's commit.

Method visibility is compile-time only (Module#private, basic_obj_respond_to's pub) ​

Ruby's basic_obj_respond_to (vendor/ruby/v3.3.11/vm_method.c:2864-2879) takes a pub flag and hands it to method_boundp (:1788-1818), so respond_to?(:m) and respond_to?(:m, true) can answer differently for the same receiver, and Kernel#public_send (vm_eval.c:1350) raises NoMethodError "private method '…' called for …" where send dispatches. Visibility is a property of the method entry, readable at run time.

CLAUDE.md →

Module#autoload is a build step (Zeitwerk::Loader#define_autoload) ​

define_autoload calls Module#autoload (vendor/zeitwerk/v2.7.3/lib/zeitwerk/loader.rb:542), which binds a name and runs require synchronously at first reference. JS has no hook on an unresolved identifier and no synchronous import(). The asynchrony goes at the load, and the walk's result can be built ahead of time. In development and test the walk runs in process at setup. trails build (trails-tsc-views build-autoload) boots the application through setup_main_autoloader, with each loader's setup and eager_load stubbed so no application file is imported, runs the same walk, and writes manifest.json, imports.generated.js and constants.generated.d.ts to .trails/autoload/<tag>/ for each loader, with paths relative to Loader#manifestRoot, the application root. For an application it also writes .trails/autoload/install.generated.js, which imports config/application and assigns each of Trails.autoloaders' imports from its tag's map, and .trails/entry.generated.js, which imports that and re-exports config/environment. An ahead-of-time compiler starts from the entry: every require then reaches its file through a literal import() it can see, where importer's import(url) is opaque to it. The install module imports config/application itself rather than relying on the entry's import order, because config/application awaits at top level and a sibling import that does not depend on it runs before it finishes. Every path names the file the walk found: Node runs a .ts file as it stands, and a bundler resolves it. The digest leaves the tag out, so an untagged loader's manifest still matches when it is named by path. A namespace's load is what reveals the constants below it in Ruby, so the step seats an empty module for each namespace and descends. Loader#manifest, a parsed manifest or a path to one, makes setup fill autoloads, namespace_dirs and shadowed_files from its rows, and a digest that differs from the running configuration raises. With a manifest set up, ls, dir? and File.exist? answer from its rows, so the eager load variants, load_file, cpath_expected_at and all_expected_cpaths read no directory; a path the walk left out (hidden, not code) is unknown there, so load_file and cpath_expected_at raise "does not exist" for it and eager_load_dir raises "is not a directory". An ignored path the walk expanded is recorded, so those answer as Ruby does for it. A reload walks the file system, as setup does, so it sees what changed since the build. New names the step needs carry @noRailsEquivalent PERMANENT against this section. This is a genuine language shortcoming, ratified repo-wide by RFC 0213.

packages/zeitwerk/CLAUDE.md →

A namespace's body reaches its own children by ES import (class Zoo; include ReptileHouse; end) ​

Ruby seats Zoo when class Zoo opens, so on_namespace_loaded defines Zoo::ReptileHouse's autoload before the body runs, and include ReptileHouse loads it synchronously (vendor/rails/v8.0.5.2/railties/test/application/initializers/load_path_test.rb:57-72). A JS class body runs while its module evaluates, before require sees the export, and cannot await a load. Such a body is a module-eval read, so by § "Call-time constant resolution" it is a plain ES import of the child file: import { ReptileHouse } from "./zoo/reptile-house.js". The loader adds nothing for it: the eager load's later require of the child gets the same module instance from the module cache and seats it at Zoo::ReptileHouse. That holds past generation 1 and under a host importer: zoo.ts was itself loaded through importer, so its static import resolves in the same graph, and after a reload the resolve hook in core-ext/kernel.ts stamps ?zeitwerk=N on every file under a root, the static import's target included, so both reach one URL.

packages/zeitwerk/CLAUDE.md →

Source ​

packages/zeitwerk on GitHub →