From fdaeed4d7e4446b9b1fc8fe2b8e171a82181f7b3 Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 23 Nov 2026 12:04:06 +0100 Subject: [PATCH] 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) --- .../internal/index/imports_test.go | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/modules/mesh-delivery-indexer/internal/index/imports_test.go b/modules/mesh-delivery-indexer/internal/index/imports_test.go index 02ea1a4fe..116ef8920 100644 --- a/modules/mesh-delivery-indexer/internal/index/imports_test.go +++ b/modules/mesh-delivery-indexer/internal/index/imports_test.go @@ -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