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:
- explain what a package manifest is and what it is not;
- write a minimal pea.toml with package identity metadata;
- declare dependencies with exact, caret, tilde, and range constraints;
- read a semantic version and say what each part promises;
- predict which candidate versions satisfy a constraint;
- separate runtime dependencies from development-only dependencies;
- explain why constraints are intentions and not guarantees; and
- review a manifest change for risk.
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
- Identity: a name and version that other packages can refer to.
- Requirements: the other packages this one needs, with acceptable version ranges.
- Entry points: which module or modules the package exposes.
- Policy: declared permissions and metadata used later by installation and audit tools.
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:
- A line of the form key = value sets a value.
- Strings are quoted: "order_rules".
- Integers, floats, and booleans are written without quotes.
- A header in square brackets, such as [package], starts a section called a table.
- Lists use square brackets: ["a", "b"].
- A line starting with # is a comment.
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
- Choose a name that is lowercase, uses underscores, and describes the package purpose.
- Keep the name stable. Other packages will refer to it, and renaming forces every consumer to change.
- Start at a low version such as 0.1.0 while the interface is still changing.
- Change the version whenever you publish a change that someone else could observe.
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.
| Part | Increase when | Consumer expectation |
|---|---|---|
| MAJOR | You make an incompatible change to the public interface | Existing callers may need to change |
| MINOR | You add behavior in a backward-compatible way | Existing callers keep working; new features are available |
| PATCH | You fix a defect without changing the interface | Existing 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
| Form | Example | Typical 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.9 | No | No | No |
| 1.2.0 | Yes | Yes | Yes |
| 1.2.5 | Yes | Yes | No |
| 1.3.0 | Yes | No | No |
| 2.0.0 | No | No | No |
1.12 Choosing a constraint
- Use a caret constraint for a dependency whose author follows semantic versioning and whose changes you are willing to receive.
- Use a tilde constraint when you want bug fixes only.
- Use an exact constraint rarely, for a dependency you have audited and must not change.
- Use a range when you know a specific version below which a defect exists or above which an incompatibility begins.
- Avoid a wildcard that spans a major version, because it accepts incompatible changes.
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 needs | Package B needs | Overlap | Outcome |
|---|---|---|---|
| ^1.2.0 | ^1.4.0 | 1.4.0 up to below 2.0.0 | Resolvable |
| ^1.2.0 | ^2.0.0 | None | Conflict |
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:
- Does the package name or version change, and does that match the intended release?
- Was a dependency added, and does the package really need it?
- Was a constraint widened, and what new versions does that admit?
- Was a constraint pinned or narrowed, and is the reason recorded?
- Did any dependency move from development-only to runtime, or the reverse?
- Is every new dependency from a source the team trusts?
1.17 Common mistakes
| Mistake | Why it hurts | Better practice |
|---|---|---|
| Leaving the version at 0.1.0 forever | Consumers cannot tell what changed | Change the version with every observable change |
| Using a wildcard across major versions | Admits incompatible releases | Use a caret constraint |
| Pinning every dependency exactly | Blocks security and bug fixes | Use ranges, and rely on locks for reproducibility |
| Adding a dependency for one small function | Increases risk and review burden | Write the function or justify the dependency |
| Putting test tools in runtime dependencies | Forces consumers to install them | Use the development section |
| Treating the constraint as proof of safety | A mislabeled release still breaks callers | Combine constraints with tests and locks |
| Editing the manifest without recording why | The reason is lost | Explain constraint changes in the change description |
1.18 Guided practice
- Write a minimal manifest for a package named pricing_rules at version 0.1.0 with no dependencies.
- State the lowest and highest versions allowed by ^2.3.1.
- State the lowest and highest versions allowed by ~2.3.1.
- Decide whether 1.9.9 satisfies >=1.2.0, <1.5.0.
- Choose a constraint type for a dependency you have audited and must not change.
- Explain which kind of change should increase the MAJOR number.
- Explain why 1.0.0-rc.1 sorts before 1.0.0.
- Describe how two dependencies can produce a conflict.
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.
- Create pea.toml at the project root with the package name order_rules, version 0.1.0, a description, and a license.
- Add a runtime dependency on input_checks with a caret constraint starting at 1.2.0.
- Add a development dependency on test_helpers with a constraint that admits only bug-fix releases.
- For each dependency, list five candidate versions and mark which ones satisfy the constraint.
- Propose a change that widens one constraint, then write a short review note using the questions in section 1.16.
- Propose a second change that introduces a conflict with another dependency range, and describe how you would resolve it.
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
- What question does a package manifest answer?
- Why is a manifest called declarative?
- What do MAJOR, MINOR, and PATCH each promise?
- What does a caret constraint allow that a tilde constraint does not?
- When is an exact constraint appropriate?
- Why separate development dependencies from runtime dependencies?
- How can two constraints on one package conflict?
- Why is a constraint an intention and not a guarantee?
- What should a reviewer check when a constraint is widened?
- Why are pre-release versions normally excluded?
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.