Skip to main content

Module source_tools

Module source_tools 

Source
Expand description

Tools that judge the project’s source as text.

A linter, a formatter or a spell checker that a test script runs reads the files of the instrumented workspace, and fails on code nobody wrote: Biome on probe calls it would format otherwise, cspell on Supercov’s own names, knip on the runtime the files now import. ESLint and Prettier are Node programs, and the preload hands them the authored text of each file they read. A native program cannot be handed anything.

Such a tool is started through a launcher in the workspace’s own node_modules/.bin, which calls back into this binary. It then runs in a view of the workspace that holds every file as its author wrote it: a directory beside the workspace with a hard link to each file the run did not rewrite, and the authored text of each one it did. What the tool writes there is the workspace’s too, as if it had run in it.

A tool that changes a source file, a formatter with --write or a linter with --fix, changes the authored text. The workspace holds what was instrumented from the text before, and written over that file the change would leave it unmeasured: Prettier did exactly that through the preload, and a file whose tests passed read 0% covered. The new text is kept beside the instrumented copy instead. Tools that run later in the command read it, the tests run the copy that is measured, and when the command ends the change is the project’s, as the command meant it to be.

Structs§

SourceChanges
The source files the command’s tools changed, by what became of each.

Constants§

SOURCE_TOOLS
The tools measured to fail on an instrumented workspace and to pass in its source view. Anything else that reads source as text can be named in SUPERCOV_SOURCE_TOOLS.
SOURCE_TOOLS_VARIABLE
Names added to SOURCE_TOOLS, separated by commas.
SOURCE_TOOL_COMMAND
The hidden command a launcher runs: supercov __source-tool <tool> <args>.

Functions§

apply_source_changes
Give the project the changes the command’s tools made to its source files. Each was made to the text the run started from, so it is applied only where the project still has that text.
clear_source_changes
Forget the changes a command before this one left behind.
launcher
The launcher that stands in for tool where a shell starts it.
launcher_for
What stands in a workspace’s .bin for the file name of the project’s .bin at tools, when that file starts a tool that judges source.
launching_binary
This binary, by a path a shell and cmd.exe can both be given.
path_with_launchers
PATH for the test command with launchers first for the source tools it has: a package manager’s script finds a project’s own tool in the workspace’s .bin, but supercov -- biome check, and a tool installed for the whole machine, are found here. A name that is not on PATH gets no launcher, so a script that asks whether a tool is installed hears what it heard.
place_launchers
Put launchers in a .bin the workspace already has as a directory of its own, which is how a workspace package’s dependencies are laid out: for each source tool the project’s .bin at tools has, in place of the entry the copy at to has for it.
run_source_tool
Run tool with arguments in the source view of the workspace this process was started in, and return its exit status. Outside a workspace of a run, the tool runs where it was started.
source_tools
The names a launcher is written for.
source_view_path
Where the source view of a workspace is kept: beside the directory that holds the workspaces, under the same name.
write_launcher
Write a launcher where path is, replacing what is there. Never through it: in a workspace whose dependencies are hard links, the file there is the project’s own.