Skip to content

Commit c180354

Browse files
committed
Convert gallery flags to the expected format
It does not seem to affect much other than making VS Code properly display a "preview" tag for extensions that are in preview mode, although maybe there are other consequences.
1 parent 355a9e1 commit c180354

File tree

2 files changed

+95
-2
lines changed

2 files changed

+95
-2
lines changed

Diff for: storage/storage.go

+15-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,21 @@ func parseVSIXManifest(reader io.Reader) (*VSIXManifest, error) {
271271
if err != nil {
272272
return nil, err
273273
}
274-
return vm, validateManifest(vm)
274+
err = validateManifest(vm)
275+
if err != nil {
276+
return vm, err
277+
}
278+
// The manifest stores these as capitalized space-delimited strings but we
279+
// want to present them as lowercased comma-separated strings to VS Code.
280+
// For example, "Public Preview" becomes "public, preview". Make sure to
281+
// handle the case where they are already comma-separated, just in case.
282+
flags := strings.Fields(vm.Metadata.GalleryFlags)
283+
converted := make([]string, len(flags))
284+
for i, flag := range flags {
285+
converted[i] = strings.ToLower(strings.TrimRight(flag, ","))
286+
}
287+
vm.Metadata.GalleryFlags = strings.Join(converted, ", ")
288+
return vm, nil
275289
}
276290

277291
// validateManifest checks a manifest for issues.

Diff for: storage/storage_test.go

+80-1
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,9 @@ func TestReadVSIXManifest(t *testing.T) {
585585
tests := []struct {
586586
// error is the expected error, if any.
587587
error string
588+
// expected is the expected manifest. If not provided, check against
589+
// `manifest` instead.
590+
expected *storage.VSIXManifest
588591
// manifest is the manifest from which to create the VSIX. Use `vsix` to
589592
// specify raw bytes instead.
590593
manifest *storage.VSIXManifest
@@ -607,6 +610,78 @@ func TestReadVSIXManifest(t *testing.T) {
607610
},
608611
},
609612
},
613+
{
614+
name: "SpaceSeparatedFlags",
615+
manifest: &storage.VSIXManifest{
616+
Metadata: storage.VSIXMetadata{
617+
Identity: storage.VSIXIdentity{
618+
Publisher: "foo",
619+
ID: "bar",
620+
Version: "baz",
621+
},
622+
GalleryFlags: "Public Preview",
623+
},
624+
},
625+
expected: &storage.VSIXManifest{
626+
Metadata: storage.VSIXMetadata{
627+
Identity: storage.VSIXIdentity{
628+
Publisher: "foo",
629+
ID: "bar",
630+
Version: "baz",
631+
},
632+
GalleryFlags: "public, preview",
633+
},
634+
},
635+
},
636+
{
637+
name: "CommaSpaceSeparatedFlags",
638+
manifest: &storage.VSIXManifest{
639+
Metadata: storage.VSIXMetadata{
640+
Identity: storage.VSIXIdentity{
641+
Publisher: "foo",
642+
ID: "bar",
643+
Version: "baz",
644+
},
645+
GalleryFlags: "public, preview",
646+
},
647+
},
648+
},
649+
{
650+
name: "CommaSpaceSpaceSeparatedFlags",
651+
manifest: &storage.VSIXManifest{
652+
Metadata: storage.VSIXMetadata{
653+
Identity: storage.VSIXIdentity{
654+
Publisher: "foo",
655+
ID: "bar",
656+
Version: "baz",
657+
},
658+
GalleryFlags: "public, preview",
659+
},
660+
},
661+
expected: &storage.VSIXManifest{
662+
Metadata: storage.VSIXMetadata{
663+
Identity: storage.VSIXIdentity{
664+
Publisher: "foo",
665+
ID: "bar",
666+
Version: "baz",
667+
},
668+
GalleryFlags: "public, preview",
669+
},
670+
},
671+
},
672+
{
673+
name: "CommaSeparatedFlags",
674+
manifest: &storage.VSIXManifest{
675+
Metadata: storage.VSIXMetadata{
676+
Identity: storage.VSIXIdentity{
677+
Publisher: "foo",
678+
ID: "bar",
679+
Version: "baz",
680+
},
681+
GalleryFlags: "public,preview",
682+
},
683+
},
684+
},
610685
{
611686
name: "MissingManifest",
612687
error: "not found",
@@ -670,8 +745,12 @@ func TestReadVSIXManifest(t *testing.T) {
670745
require.Error(t, err)
671746
require.Regexp(t, test.error, err.Error())
672747
} else {
748+
expected := test.expected
749+
if expected == nil {
750+
expected = test.manifest
751+
}
673752
require.NoError(t, err)
674-
require.Equal(t, test.manifest, manifest)
753+
require.Equal(t, expected, manifest)
675754
}
676755
})
677756
}

0 commit comments

Comments
 (0)