PeaBox Lab › PeaLang › Learn › Chapter 11 › Lesson 1

Part II — Intermediate Development · Chapter 11 · Lesson 1 of 6 · 9 min read

Lesson 1: pea.toml Manifests and Semantic-Version Constraints

Lesson level: Intermediate

Purpose: Describe a PeaLang project as a package: give it an identity, declare what it depends on, and state which versions of those dependencies it will accept.

Release note: manifest field names, section names, and commands in this lesson are illustrative. Verify them against the installed v0.63 release before relying on them.

Learning objectives

By the end of this lesson, you should be able to:

1.1 From project to package

In Chapter 9 you organized the order-discount rules into modules with a defined layout. That project already worked on one machine. A package goes one step further: it is a project that describes itself well enough for another person, another machine, or an automated build to use it without guessing.

The description lives in a manifest file named pea.toml at the project root. It answers three questions: what is this package, what does it need, and what does it offer.

1.2 What a manifest is for

A manifest is declarative. It states intent and does not run code. That makes it easy to read, diff, review, and validate before anything executes.

1.3 TOML in five minutes

The manifest uses TOML, a plain-text configuration format. You need only a few rules:

1.4 A minimal manifest

This manifest describes the order-discount project:

[package]
name = "order_rules"
version = "0.1.0"
description = "Order discount rules"
license = "MIT"

[dependencies]

The [package] table gives the package its identity. The empty [dependencies] table says that the package currently needs nothing else. An empty table is a deliberate statement, not an omission.

1.5 Naming and versioning the package

1.6 Anatomy of a semantic version

A semantic version has three numbers separated by dots: MAJOR.MINOR.PATCH. For example, in 2.4.1 the major version is 2, the minor version is 4, and the patch version is 1.

PartIncrease whenConsumer expectation
MAJORYou make an incompatible change to the public interfaceExisting callers may need to change
MINORYou add behavior in a backward-compatible wayExisting callers keep working; new features are available
PATCHYou fix a defect without changing the interfaceExisting callers keep working; behavior is more correct

Semantic versioning is a promise made by the package author. The number communicates intent; it does not prove it. A mislabeled release can still break callers, which is why later lessons add locks, checksums, and tests.

1.7 Versions below 1.0.0

A major version of 0 conventionally means the interface is still settling. Many tools treat a change in the minor number as potentially breaking when the major number is 0. Read your installed release documentation on how it treats 0.x versions before choosing a constraint.

1.8 Pre-release versions

A version may carry a pre-release label after a hyphen, as in 1.0.0-rc.1. A pre-release sorts before the final version it precedes. Constraints normally do not select pre-releases unless the constraint itself names one. This keeps a production build from accidentally picking up a candidate.

1.9 Declaring dependencies

Suppose the order-discount package needs a small validation helper published as input_checks. The manifest names it and states which versions are acceptable:

[dependencies]
input_checks = "^1.2.0"

The key is the dependency name and the value is a version constraint. The tool, not the author, chooses the concrete version later. That choice is the subject of the next lesson on locks.

1.10 Constraint forms

FormExampleTypical meaning
Exact"=1.2.3"Only version 1.2.3
Caret"^1.2.3"At least 1.2.3 and below 2.0.0
Tilde"~1.2.3"At least 1.2.3 and below 1.3.0
Range">=1.2.0, <1.5.0"At least 1.2.0 and below 1.5.0
Wildcard"1.*"Any 1.x version

Verify which forms your installed release accepts and how it reads a bare version such as "1.2.3". Some tools treat a bare version as a caret constraint.

1.11 Reading a constraint as a set

A constraint describes a set of acceptable versions. To read one, list the lowest and highest versions it allows. The caret constraint ^1.2.0 allows 1.2.0, 1.2.9, 1.3.0, and 1.9.4, but not 1.1.9 or 2.0.0. The tilde constraint ~1.2.0 allows 1.2.0 and 1.2.9 but not 1.3.0.

Candidate^1.2.0~1.2.0=1.2.0
1.1.9NoNoNo
1.2.0YesYesYes
1.2.5YesYesNo
1.3.0YesNoNo
2.0.0NoNoNo

1.12 Choosing a constraint

1.13 Runtime and development dependencies

Some packages are needed only to build or test your code. Keeping them separate prevents consumers of your package from installing tools they will never run.

[dependencies]
input_checks = "^1.2.0"

[dev-dependencies]
test_helpers = "^0.4.0"

The table name dev-dependencies is illustrative. Confirm the supported name in your installed release.

1.14 Constraints are intentions, not guarantees

A constraint states what you are willing to accept. It does not prove that every accepted version works. A dependency author may mislabel a release, and a minor release may break a rarely used behavior. Treat the constraint as the first control and rely on tests, locks, checksums, and review for the rest.

1.15 Dependency conflicts

Two dependencies may each require the same third package with different ranges. If the ranges overlap, the tool can pick a version inside the overlap. If they do not overlap, resolution fails.

Package A needsPackage B needsOverlapOutcome
^1.2.0^1.4.01.4.0 up to below 2.0.0Resolvable
^1.2.0^2.0.0NoneConflict

A conflict is information, not a nuisance. It tells you that two parts of the system disagree about a boundary, and a human decision is required.

1.16 Reviewing a manifest change

A manifest diff is a small file with large consequences. Review it with these questions:

1.17 Common mistakes

MistakeWhy it hurtsBetter practice
Leaving the version at 0.1.0 foreverConsumers cannot tell what changedChange the version with every observable change
Using a wildcard across major versionsAdmits incompatible releasesUse a caret constraint
Pinning every dependency exactlyBlocks security and bug fixesUse ranges, and rely on locks for reproducibility
Adding a dependency for one small functionIncreases risk and review burdenWrite the function or justify the dependency
Putting test tools in runtime dependenciesForces consumers to install themUse the development section
Treating the constraint as proof of safetyA mislabeled release still breaks callersCombine constraints with tests and locks
Editing the manifest without recording whyThe reason is lostExplain constraint changes in the change description

1.18 Guided practice

1.19 Hands-on lab: Write and review a manifest

Goal: Describe the Chapter 9 order-discount project as a package and review a proposed change.

Deliverable: The manifest, the five-candidate tables, the review note, and a conflict-resolution note. Use only synthetic package names; do not include credentials or private registry addresses.

1.20 Review questions

1.21 Applied challenge

Choose a project you know and write its manifest. For every dependency, justify the constraint form, name the lowest and highest accepted versions, and describe the risk you accept by admitting the upper end of the range. Finish with a one-paragraph policy that a team could use to decide when a manifest change needs a second reviewer.

Lesson summary

A pea.toml manifest turns a project into a package by declaring its identity, its dependencies, and the version ranges it accepts. Semantic versions communicate the author’s intent about compatibility, and constraints translate your tolerance for change into a set of acceptable versions. Because constraints state intention rather than proof, they are combined with tests, locks, checksums, and careful review of every manifest change.

Transition to Lesson 2

A constraint describes many acceptable versions, but a build must use exactly one. The next lesson covers deterministic locks and reproducible builds, showing how a lock records the concrete versions chosen so that every machine builds the same thing.

Lesson status: Ready for review.

← Previous Next →