From 581ede7a178bf4d57ba03bd3ae51304cbc4aef35 Mon Sep 17 00:00:00 2001 From: Siddhant <115331356+grimsteel@users.noreply.github.com> Date: Sat, 26 Nov 2022 00:37:29 -0600 Subject: [PATCH 1/4] Parse shortcut icons in web app manifests --- .../webmanifest/src/WebManifestTransformer.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/transformers/webmanifest/src/WebManifestTransformer.js b/packages/transformers/webmanifest/src/WebManifestTransformer.js index 138c90f3a76..c0639ad9566 100644 --- a/packages/transformers/webmanifest/src/WebManifestTransformer.js +++ b/packages/transformers/webmanifest/src/WebManifestTransformer.js @@ -61,6 +61,28 @@ export default (new Transformer({ } } + if (data.shortcuts) { + invariant(Array.isArray(data.shortcuts)); + for (let i = 0; i < data.shortcuts.length; i++) { + const list = data.shortcuts[i].icons; + if (list) { + invariant(Array.isArray(list)); + for (let j = 0; j < list.length; j++) { + const res = list[j]; + res.src = asset.addURLDependency(res.src, { + loc: { + filePath: asset.filePath, + ...getJSONSourceLocation( + pointers[`/shortcuts/${i}/icons/${j}/src`], + 'value', + ), + }, + }); + } + } + } + } + asset.type = 'webmanifest'; asset.setCode(JSON.stringify(data)); return [asset]; From ebcd689bd2089ba07000e2970c7ea193e37a2a0b Mon Sep 17 00:00:00 2001 From: Siddhant <115331356+grimsteel@users.noreply.github.com> Date: Sat, 26 Nov 2022 01:08:57 -0600 Subject: [PATCH 2/4] Update webmanifest integration tests --- .../integration/webmanifest-json/manifest.json | 12 ++++++++++++ .../webmanifest-json/shortcut-icon.png | Bin 0 -> 255 bytes .../integration/webmanifest/manifest.webmanifest | 12 ++++++++++++ .../integration/webmanifest/shortcut-icon.png | Bin 0 -> 255 bytes .../core/integration-tests/test/webmanifest.js | 10 ++++++++++ 5 files changed, 34 insertions(+) create mode 100644 packages/core/integration-tests/test/integration/webmanifest-json/shortcut-icon.png create mode 100644 packages/core/integration-tests/test/integration/webmanifest/shortcut-icon.png diff --git a/packages/core/integration-tests/test/integration/webmanifest-json/manifest.json b/packages/core/integration-tests/test/integration/webmanifest-json/manifest.json index df3bafd8591..bf9b21d989b 100644 --- a/packages/core/integration-tests/test/integration/webmanifest-json/manifest.json +++ b/packages/core/integration-tests/test/integration/webmanifest-json/manifest.json @@ -13,5 +13,17 @@ "sizes": "100x100", "type": "image/png" } + ], + "shortcuts": [ + { + "name": "example-shortcut", + "icons": [ + { + "src": "shortcut-icon.png", + "sizes": "100x100", + "type": "image/png" + } + ] + } ] } diff --git a/packages/core/integration-tests/test/integration/webmanifest-json/shortcut-icon.png b/packages/core/integration-tests/test/integration/webmanifest-json/shortcut-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..8a1daa0121d524256c1d1b45ff5e7ed771784c52 GIT binary patch literal 255 zcmeAS@N?(olHy`uVBq!ia0vp^DImVS)*E46%Oq(`s&YU^>_U&7| zc=6GrN4Ia^zG~H~jT<-Ko_$0QsEo6~BeIx*f$sR&2=kJHM z&5N9@w|=XzipNCbb|s-xrJeH)f2E%im~OIrio1Qy&Sj1+>x<+1)+oPni}kGd6Ohy! z>6x1RttNZTv!7LG>?+Ii&zjEnadB}e3778<6P>u`Anzuis~9|8{an^LB{Ts5qZeh6 literal 0 HcmV?d00001 diff --git a/packages/core/integration-tests/test/integration/webmanifest/manifest.webmanifest b/packages/core/integration-tests/test/integration/webmanifest/manifest.webmanifest index df3bafd8591..bf9b21d989b 100644 --- a/packages/core/integration-tests/test/integration/webmanifest/manifest.webmanifest +++ b/packages/core/integration-tests/test/integration/webmanifest/manifest.webmanifest @@ -13,5 +13,17 @@ "sizes": "100x100", "type": "image/png" } + ], + "shortcuts": [ + { + "name": "example-shortcut", + "icons": [ + { + "src": "shortcut-icon.png", + "sizes": "100x100", + "type": "image/png" + } + ] + } ] } diff --git a/packages/core/integration-tests/test/integration/webmanifest/shortcut-icon.png b/packages/core/integration-tests/test/integration/webmanifest/shortcut-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..8a1daa0121d524256c1d1b45ff5e7ed771784c52 GIT binary patch literal 255 zcmeAS@N?(olHy`uVBq!ia0vp^DImVS)*E46%Oq(`s&YU^>_U&7| zc=6GrN4Ia^zG~H~jT<-Ko_$0QsEo6~BeIx*f$sR&2=kJHM z&5N9@w|=XzipNCbb|s-xrJeH)f2E%im~OIrio1Qy&Sj1+>x<+1)+oPni}kGd6Ohy! z>6x1RttNZTv!7LG>?+Ii&zjEnadB}e3778<6P>u`Anzuis~9|8{an^LB{Ts5qZeh6 literal 0 HcmV?d00001 diff --git a/packages/core/integration-tests/test/webmanifest.js b/packages/core/integration-tests/test/webmanifest.js index e63cf3918dd..795f71acae2 100644 --- a/packages/core/integration-tests/test/webmanifest.js +++ b/packages/core/integration-tests/test/webmanifest.js @@ -26,6 +26,10 @@ describe('webmanifest', function () { type: 'png', assets: ['screenshot.png'], }, + { + type: 'png', + assets: ['shortcut-icon.png'], + }, ]); const manifest = await outputFS.readFile( @@ -34,6 +38,7 @@ describe('webmanifest', function () { ); assert(/screenshot\.[0-9a-f]+\.png/.test(manifest)); assert(/icon\.[0-9a-f]+\.png/.test(manifest)); + assert(/shortcut-icon\.[0-9a-f]+\.png/.test(manifest)); }); it('should support .json', async function () { @@ -58,6 +63,10 @@ describe('webmanifest', function () { type: 'png', assets: ['screenshot.png'], }, + { + type: 'png', + assets: ['shortcut-icon.png'], + }, ]); const manifest = await outputFS.readFile( @@ -66,6 +75,7 @@ describe('webmanifest', function () { ); assert(/screenshot\.[0-9a-f]+\.png/.test(manifest)); assert(/icon\.[0-9a-f]+\.png/.test(manifest)); + assert(/shortcut-icon\.[0-9a-f]+\.png/.test(manifest)); }); it('should throw on malformed icons and screenshots', async function () { From 4d0292272573f8f064d2f5469e4db5f82c996d6a Mon Sep 17 00:00:00 2001 From: Siddhant <115331356+grimsteel@users.noreply.github.com> Date: Sun, 27 Nov 2022 11:47:39 -0600 Subject: [PATCH 3/4] Add shortcuts to web manifest transformer schema --- .../webmanifest/src/WebManifestTransformer.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/transformers/webmanifest/src/WebManifestTransformer.js b/packages/transformers/webmanifest/src/WebManifestTransformer.js index c0639ad9566..3288a9c330a 100644 --- a/packages/transformers/webmanifest/src/WebManifestTransformer.js +++ b/packages/transformers/webmanifest/src/WebManifestTransformer.js @@ -30,6 +30,15 @@ const MANIFEST_SCHEMA: SchemaEntity = { properties: { icons: RESOURCES_SCHEMA, screenshots: RESOURCES_SCHEMA, + shortcuts: { + type: 'array', + items: { + type: 'object', + properties: { + icons: RESOURCES_SCHEMA, + }, + }, + }, }, }; From 3fc2b5707a111619fede271d95c4913184c39997 Mon Sep 17 00:00:00 2001 From: Siddhant <115331356+grimsteel@users.noreply.github.com> Date: Sun, 27 Nov 2022 12:10:26 -0600 Subject: [PATCH 4/4] Update webmanifest schema integration test --- .../webmanifest-schema/manifest.webmanifest | 21 +++++++++++- .../integration-tests/test/webmanifest.js | 33 +++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/packages/core/integration-tests/test/integration/webmanifest-schema/manifest.webmanifest b/packages/core/integration-tests/test/integration/webmanifest-schema/manifest.webmanifest index f28b0aedc75..7b9bf17e5db 100644 --- a/packages/core/integration-tests/test/integration/webmanifest-schema/manifest.webmanifest +++ b/packages/core/integration-tests/test/integration/webmanifest-schema/manifest.webmanifest @@ -12,5 +12,24 @@ }, {} ], - "screenshots": {} + "screenshots": {}, + "shortcuts": [ + { + "icons": {} + }, + { + "icons": [ + { + "src": "icon.png", + "sizes": "100x100", + "type": "image/png" + }, + { + "sizes": "100x100", + "type": "image/png" + }, + {} + ] + } + ] } diff --git a/packages/core/integration-tests/test/webmanifest.js b/packages/core/integration-tests/test/webmanifest.js index 795f71acae2..cfee46756f2 100644 --- a/packages/core/integration-tests/test/webmanifest.js +++ b/packages/core/integration-tests/test/webmanifest.js @@ -134,6 +134,39 @@ describe('webmanifest', function () { line: 15, }, }, + { + end: { + column: 17, + line: 18, + }, + message: 'Expected type array', + start: { + column: 16, + line: 18, + }, + }, + { + end: { + column: 9, + line: 30, + }, + message: 'Missing property src', + start: { + column: 9, + line: 27, + }, + }, + { + end: { + column: 10, + line: 31, + }, + message: 'Missing property src', + start: { + column: 9, + line: 31, + }, + }, ], }, ],