BG8, BN8, BI2: each artifact carries the version the ask names

A Go program is linked with -X main.meshVersion beside main.builtFor, a Node program's package.json version is set, an
image is labelled org.opencontainers.image.version; a build with no version stamps none.

Builds: design 47 G §458, §573

Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
2026-11-12 05:15:43 +01:00
parent f339ea5936
commit 48ad5ce947
6 changed files with 45 additions and 3 deletions
@@ -137,6 +137,14 @@ func (m *Module) build(ctx context.Context, args map[string]any) (any, error) {
if err := copyPackages(filepath.Join(m.toolchainDir(), "node_modules"), filepath.Join(stage, "node_modules")); err != nil {
return nil, fmt.Errorf("providing the toolchain's packages to the build: %w", err)
}
// A program reads its own version from its package.json `version`, which is the version the ask carries (§458); the
// staged copy is the build's own, so nothing is restored. A build with no version, or a module with no package.json,
// keeps what it carries.
if _, err := os.Stat(filepath.Join(dir, "package.json")); err == nil && version != "" {
if _, err := setPackageVersion(dir, version); err != nil {
return nil, err
}
}
out, final := Out(a.Name), Out(a.Name)+".bundled"
if err := os.MkdirAll(filepath.Join(dir, out), 0o755); err != nil {
return nil, err
@@ -328,3 +328,24 @@ func TestTheBundleBuildGetsTheVersionTheAskCarriesAsMeshVersion(t *testing.T) {
}
}
}
// Design 47 G §458 (BN8): a Node program reads its version from its package.json `version`, which is the version the
// ask carries; a build with no version keeps what the package.json carries.
func TestTheBundleCarriesTheAsksVersionInItsPackageJSON(t *testing.T) {
for _, c := range []struct{ version, want string }{{"1.4.3", "1.4.3"}, {"", "0.0.0"}} {
m, f, work := builtMachine(t, "")
workspaceWith(t, work, map[string]string{"modules/m/package.json": `{"name":"m","version":"0.0.0"}`})
args := buildArgs()
if c.version != "" {
args["version"] = c.version
}
if _, err := m.build(context.Background(), args); err != nil {
t.Fatal(err)
}
_ = f
raw, err := os.ReadFile(filepath.Join(work, "w1", "stage-tools", "modules", "module", "package.json"))
if err != nil || !strings.Contains(string(raw), `"version": "`+c.want+`"`) && !strings.Contains(string(raw), `"version":"`+c.want+`"`) {
t.Errorf("ask version %q: the staged package.json is %q (%v), want version %s", c.version, raw, err, c.want)
}
}
}