← Fundamentals
Fundamentals

From source to a running program

Your build failed. Why does the preview still run?

Follow the connection between saved source, build commands and the program that starts.

Outcome

Predict which source revision a command runs, then change the source marker and workflow so a failed build cannot launch an old artifact.

Terminology (3)Terms used in this lesson

Term on the front, definition on the back. Paste with tabs between fields and a new line between cards, or import the download in Anki as Basic.

Build artifact
In this emitted-file workflow, the JavaScript written to out/main.js by tsc. Node can execute this file independently of main.ts.
Provenance
The relationship between an observed result and the inputs and operations that produced it.
Type stripping
Removing erasable TypeScript annotations so JavaScript behavior can execute, without checking whether those annotations are satisfied.

Source, artifacts and execution

Source is the text you edit. A toolchain reads that text to check or translate it, and a runtime executes the program. Some workflows combine those steps in one command; others create an artifact, such as an executable or emitted JavaScript, that a later command starts.

A launch command therefore has an input of its own: it may name source, a project target or an already produced file. To connect an observation to an edit, follow that input through the commands that prepare and start it. Keep checking, producing an artifact and executing it as distinct operations, even when one command requests all three.

01The old banner

Your edit is saved. Your teammate still sees the old banner.

You change the banner on a release-notes preview before a team demo. Your build fails, but a teammate can still start the preview and sees the old banner. Which source did they just run?

The start command came from the last successful demo. Before handing it over again, you need to find out whether it rebuilds the preview or opens a file left by that earlier build.

Before changing more code, isolate the build and launch steps. The small program below keeps only a printed marker from the preview. That gives you a way to distinguish revisions without loading the release notes or the rest of the application.

Set up your local workspace

The browser lab runs its own sandboxed compilers and needs no local installation. To reproduce the build and run yourself, install the toolchain for the language you are trying.

The commands use a POSIX shell. On Windows, use a Linux environment such as WSL for the same commands and paths.

TypeScript · terminal.sh
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
node --version
npm --version
mkdir primerian-source-ts
cd primerian-source-ts
npm init -y
npm install --save-dev typescript@latest
npx tsc --version

Use current Node LTS and stable TypeScript. The release numbers above were checked on 30 October 2026; later stable patches are fine. npm records the compiler you install in this workspace’s lockfile. Create main.ts here using the valid example below.

First recreate the last successful build. Save revision A below, then use the build and run commands beneath it. Its banner marker is preview: ready.

The examples assume the stated toolchain and no concurrent file changes.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
const message: string = "preview: ready";
console.log(message);
TypeScript · terminal.sh
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
npx tsc main.ts --noEmitOnError --outDir out
node out/main.js

Now reproduce the failed edit: replace the initializer with the version below, save it and rebuild. The marker has a string type, but the edited initializer supplies the number 42.

This attempt fails before replacing out/main.js. The artifact from A is still present. Your teammate’s start command is node out/main.js. Try that same direct invocation next.

main.ts
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
const message: string = 42;
console.log(message);
The saved edit fails to build, yet your teammate can start the preview and see its earlier banner. Which explanation connects that run to the source revision it used?

02Two ways to start it

You and your teammate start the preview differently.

Your teammate started the built file directly. While developing the preview, you usually use the command below. You want to know whether handing over that command would keep a failed edit from being mistaken for a working preview. Keep the invalid initialization saved and predict what happens before trying it.

TypeScript · terminal.sh
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
node main.ts
With the invalid initialization still saved, what happens when you use the edit/run workflow shown above?

03A command to hand over

Check the source you execute

You need a command your teammate can use for the demo: it should show the current saved message when that source passes checking, and stop if checking fails. Use what you learned about the development command to decide whether it already meets that requirement.

node main.ts executes the saved source without a type check. Put tsc --noEmit before that same command. The check writes no JavaScript; Node still reads main.ts. The shell reaches Node only if checking succeeds.

TypeScript · terminal.sh
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
npx tsc main.ts --noEmit && node main.ts

Set the valid string initializer to preview: checked and run this chain. It prints the new message. Restore the invalid initializer: checking fails and Node does not start. Keep the source unchanged between the check and execution.

Those two attempts answer the handoff question: the valid marker reaches the preview; the invalid edit produces a diagnostic without starting it. Keep both checks when you change the launch workflow. A successful run alone would test only the first half.

04The demo shortcut

Will the demo shortcut show your new marker?

The development command is ready to hand over. Your teammate also keeps a shortcut to the built preview for the demo. Check that shortcut in a separate reproduction: save revision A from section 01 and build its preview: ready artifact with the same build command. The shortcut starts that file directly.

Now save the valid preview: checked marker and run the command specified in the case below. It succeeds. The shortcut still uses its original path.

Will that shortcut demonstrate your new marker? Follow the command’s output and the file the shortcut starts.

Your teammate’s demo shortcut runs node out/main.js. Its input, out/main.js, was built from A and prints preview: ready. You save valid source B that prints preview: checked. npx tsc main.ts --noEmit succeeds: this is a no-emit check. Your teammate starts the shortcut again. What is printed?

05Prepare the handoff

Make the preview safe to hand over.

Your teammate needs a repeatable way to open the release-notes preview for review. In the lab, keep the marker program you used to investigate the old banner. The review copy already prints the requested message; first establish that its build task produces the file from your saved revision. Then make the shared development task stop on an invalid edit. Finally, prepare a separate candidate launch for the demo while keeping the everyday workflow available.

The candidate output lets your teammate keep the usual preview alongside the demo version. It is another output of this same small program. The lab supplies both older outputs so you can observe a stale launch, then check that a later saved edit reaches the intended file.

How the lab’s task and launch files work

The editor buffer and saved files are separate. In tasks.json, each entry pairs a task label with its native command; save that file before running the edited task. The final level adds this lab’s small launch.json: preLaunchTask names one of those tasks, and program names the output to start after that task succeeds. A successful check alone cannot produce that output, and building a different path cannot refresh it. Artifact details and compiler diagnostics let you follow the whole chain.

Prepare the preview for your teammate

Verify the review build, make failed edits stop the shared task, then connect the demo launcher to its candidate output. Each level supplies the earlier working behavior.

  1. easy · F-SRC-BUILD-1 Verify the review build
  2. medium · F-SRC-BUILD-2 Guard the preview workflow
  3. hard · F-SRC-BUILD-3 Repair the demo launcher
Check this idea later
A colleague reports a successful run after editing source. You have its output but no command line or build log. Which evidence would establish that the edited source passed checking?
A successful build of the latest source writes artifact B. Artifact A is unchanged from last week. A later command executes A directly, without checking or rebuilding source. Which source revision does it run?
Sources

Report a problem in this lesson

For typos, mistakes and things that don’t work. We read every report and fix what’s wrong, but we don’t reply here, so a question won’t get an answer.