Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use icon url instead name in manifest icons #37

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/api/generate-manifest-icons-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ export function generateManifestIconsEntry<Format extends ManifestIconsType>(

for (const icon of Object.values(instruction.transparent)) {
icons.icons.push({
src: icon.name,
src: icon.url,
sizes: `${icon.width}x${icon.height}`,
type: icon.mimeType,
})
}
for (const icon of Object.values(instruction.maskable)) {
icons.icons.push({
src: icon.name,
src: icon.url,
sizes: `${icon.width}x${icon.height}`,
type: icon.mimeType,
purpose: 'maskable',
Expand Down
36 changes: 32 additions & 4 deletions test/__snapshots__/manifest-icons.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,51 @@ exports[`should generate manifest icons entry 1`] = `
"icons": [
{
"sizes": "64x64",
"src": "pwa-64x64.png",
"src": "/pwa-64x64.png",
"type": "image/png",
},
{
"sizes": "192x192",
"src": "pwa-192x192.png",
"src": "/pwa-192x192.png",
"type": "image/png",
},
{
"sizes": "512x512",
"src": "pwa-512x512.png",
"src": "/pwa-512x512.png",
"type": "image/png",
},
{
"purpose": "maskable",
"sizes": "512x512",
"src": "maskable-icon-512x512.png",
"src": "/maskable-icon-512x512.png",
"type": "image/png",
},
],
}
`;

exports[`should generate manifest icons entry with custom base 1`] = `
{
"icons": [
{
"sizes": "64x64",
"src": "/test/pwa-64x64.png",
"type": "image/png",
},
{
"sizes": "192x192",
"src": "/test/pwa-192x192.png",
"type": "image/png",
},
{
"sizes": "512x512",
"src": "/test/pwa-512x512.png",
"type": "image/png",
},
{
"purpose": "maskable",
"sizes": "512x512",
"src": "/test/maskable-icon-512x512.png",
"type": "image/png",
},
],
Expand Down
19 changes: 19 additions & 0 deletions test/manifest-icons.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,22 @@ it('should generate manifest icons entry', async () => {
expectTypeOf(icons).toEqualTypeOf<ManifestIcons>()
expect(icons).toMatchSnapshot()
})

it('should generate manifest icons entry with custom base', async () => {
const instructions = await resolveInstructions({
imageResolver: () => readFile('playground/pwa/public/favicon.svg'),
imageName: 'playground/pwa/public/favicon.svg',
preset: 'minimal-2023',
htmlLinks: {
xhtml: false,
includeId: false,
},
basePath: '/test/',
resolveSvgName: name => basename(name),
})
const iconsString = generateManifestIconsEntry('string', instructions)
expectTypeOf(iconsString).toEqualTypeOf<string>()
const icons = generateManifestIconsEntry('object', instructions)
expectTypeOf(icons).toEqualTypeOf<ManifestIcons>()
expect(icons).toMatchSnapshot()
})