I11b: a TypeScript import set takes each imported npm package by its content

The import form of a TypeScript module takes each mesh npm package its reported
set names by the digest the packages state keeps under its npm name (I11a), so
a change of an imported package's files moves it and a change of another
leaves it; the npm import of another repository enters the entry's packages as
a Go one does. fingerprint.Resolve already resolves an import by its exact
name, so the form needs no code of its own: the test holds it.

Builds: design 47 H2 H-A-523, H-A-546 (3)
This commit is contained in:
2026-11-23 12:04:06 +01:00
parent d5af4213c3
commit fdaeed4d7e
@@ -636,6 +636,36 @@ func anUnreadPackagesStateWritesNoFingerprintAndFingerprintsAreComputedAgain(t *
t.Errorf("the sibling's directory changed: fingerprint %q, was %q; want a new one", g.fp, f.fp)
}
})
t.Run("a TypeScript import set moves the fingerprint by an imported npm package's content alone", func(t *testing.T) { // I11b/AC1
// Design 47 H2 H-A-523, H-A-546: a TypeScript module's reported set names npm packages, each taken by its digest in the
// packages state, kept by its npm name as I11a publishes it.
const sdkTS, other = "@novox/mesh-sdk", "@novox/other"
npm := func(name, digest string) meshcatalog.PackagesByModuleValue {
return meshcatalog.PackagesByModuleValue{Module: name, Repository: "novox/mesh-sdk", Dir: "ts", Commit: strings.Repeat("c", 40), Requires: "r1",
Packages: []meshcatalog.PackagesByModuleValuePackagesItem{{Package: name, Digest: digest}}}
}
fpOf := func(sdkDigest, otherDigest string) form {
t.Helper()
kept := meshcatalog.ModulesByModuleValueInputs2{Tree: "t", Imports: []string{sdkTS}}
published := map[string]meshcatalog.PackagesByModuleValue{sdkTS: npm(sdkTS, sdkDigest), other: npm(other, otherDigest)}
f := formOf("view", "novox/mesh-catalog", &kept, true, map[string]bool{sdkTS: true, other: true}, nil, meshcatalog.ModulesByModuleValue{}, nil, published, nil, nil)
if f.fp == "" || !f.imports {
t.Fatalf("a TypeScript import set: fingerprint %q (none %q), import form %v; want the import form", f.fp, f.none, f.imports)
}
return f
}
base := fpOf("d1", "o1")
if moved := fpOf("d2", "o1"); moved.fp == base.fp {
t.Error("a change of the imported npm package's files left the fingerprint")
}
if stood := fpOf("d1", "o2"); stood.fp != base.fp {
t.Error("a change of an npm package the module does not import moved the fingerprint")
}
// H-A-546 (3): an npm import of another repository enters the entry's packages as a Go one does.
if _, named := base.versions[sdkTS]; !named {
t.Errorf("versions %v, want %s named", base.versions, sdkTS)
}
})
t.Run("formOf clears the import form when it writes the version line", func(t *testing.T) {
for _, c := range []struct {
name string