-
-
Notifications
You must be signed in to change notification settings - Fork 425
feat: add PWA web manifest (without service worker) #1181
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
Draft
userquin
wants to merge
14
commits into
npmx-dev:main
Choose a base branch
from
userquin:feat-enable-pwa-manifest
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
37dcddb
feat: add PWA web manifest (without service worker)
userquin abe9cea
chore: add service worker
userquin 2b9ac50
chore: store also api calls to cache readme
userquin 03daa2d
chore: add build local pwa with sw source and logs
userquin f9cee47
chore: add service-worker to knip entry
userquin b73b57d
chore: add workbox-build to knip ignore deps
userquin ba1f96c
Merge branch 'main' into feat-enable-pwa-manifest
userquin d7e9e78
chore: update denylist and runtime caching
userquin 4d02840
chore: disable install prompt
userquin 54ad77b
chore: don't intercept search?
userquin b6f5ade
chore: escape ?
userquin 68f2597
resolve conflicts with main
alexdln 0d1ae52
Merge branch 'main' into feat-enable-pwa-manifest
alexdln d86780d
chore: restore service worker entry in knip
alexdln File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| import { | ||
| cleanupOutdatedCaches, | ||
| createHandlerBoundToURL, | ||
| precacheAndRoute, | ||
| } from 'workbox-precaching' | ||
| import { clientsClaim } from 'workbox-core' | ||
| import { NetworkFirst, StaleWhileRevalidate } from 'workbox-strategies' | ||
| import { NavigationRoute, registerRoute } from 'workbox-routing' | ||
| import { CacheableResponsePlugin } from 'workbox-cacheable-response' | ||
| import { ExpirationPlugin } from 'workbox-expiration' | ||
|
|
||
| declare let self: ServiceWorkerGlobalScope | ||
|
|
||
| const cacheNames = ['npmx-packages', 'npmx-packages-code-and-docs', 'npmx-vercel-proxies'] as const | ||
|
|
||
| async function createRuntimeCaches() { | ||
| await Promise.all(cacheNames.map(c => caches.open(c))) | ||
| } | ||
| self.addEventListener('install', event => { | ||
| event.waitUntil(createRuntimeCaches()) | ||
| }) | ||
|
|
||
| self.skipWaiting() | ||
| clientsClaim() | ||
|
|
||
| cleanupOutdatedCaches() | ||
| precacheAndRoute(self.__WB_MANIFEST, { | ||
| urlManipulation: ({ url }) => { | ||
| const urls: URL[] = [] | ||
| // search use query params, we need to include here any page using query params | ||
| if (url.pathname.endsWith('_payload.json') || url.pathname.endsWith('/search')) { | ||
| const newUrl = new URL(url.href) | ||
| newUrl.search = '' | ||
| urls.push(newUrl) | ||
| } | ||
| return urls | ||
| }, | ||
| }) | ||
|
|
||
| // allow only fallback in dev: we don't want to cache anything | ||
| let allowlist: undefined | RegExp[] | ||
| if (import.meta.env.DEV) allowlist = [/^\/$/] | ||
|
|
||
| // deny api and server page calls | ||
| let denylist: undefined | RegExp[] | ||
| if (import.meta.env.PROD) { | ||
| denylist = [ | ||
| // search page | ||
| /^\/search$/, | ||
| /^\/search\?/, | ||
| /^\/~/, | ||
| /^\/org\//, | ||
| // api calls | ||
| /^\/api\//, | ||
| /^\/oauth\//, | ||
| /^\/package\//, | ||
| /^\/package-code\//, | ||
| /^\/package-docs\//, | ||
| /^\/_v\//, | ||
| /^\/opensearch\.xml$/, | ||
| // exclude sw: if the user navigates to it, fallback to index.html | ||
| /^\/service-worker\.js$/, | ||
| ] | ||
|
|
||
| registerRoute( | ||
| ({ sameOrigin, url }) => | ||
| sameOrigin && | ||
| (url.pathname.startsWith('/package/') || | ||
| url.pathname.startsWith('/org/') || | ||
| url.pathname.startsWith('/~') || | ||
| url.pathname.startsWith('/api/')), | ||
| new NetworkFirst({ | ||
| cacheName: cacheNames[0], | ||
| plugins: [ | ||
| new CacheableResponsePlugin({ statuses: [200] }), | ||
| new ExpirationPlugin({ maxEntries: 1000, maxAgeSeconds: 60 }), | ||
| ], | ||
| }), | ||
| ) | ||
| registerRoute( | ||
| ({ sameOrigin, url }) => | ||
| sameOrigin && | ||
| (url.pathname.startsWith('/package-docs/') || url.pathname.startsWith('/package-code/')), | ||
| new StaleWhileRevalidate({ | ||
| cacheName: cacheNames[1], | ||
| plugins: [ | ||
| new CacheableResponsePlugin({ statuses: [200] }), | ||
| new ExpirationPlugin({ maxEntries: 1000, maxAgeSeconds: 365 * 24 * 60 * 60 }), | ||
| ], | ||
| }), | ||
| ) | ||
| registerRoute( | ||
| ({ sameOrigin, url }) => sameOrigin && url.pathname.startsWith('/_v/'), | ||
| new NetworkFirst({ | ||
| cacheName: cacheNames[1], | ||
| plugins: [ | ||
| new CacheableResponsePlugin({ statuses: [200] }), | ||
| new ExpirationPlugin({ maxEntries: 100, maxAgeSeconds: 60 }), | ||
| ], | ||
| }), | ||
| ) | ||
| } | ||
|
|
||
| // to allow work offline | ||
| registerRoute(new NavigationRoute(createHandlerBoundToURL('/'), { allowlist, denylist })) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ const pages = [ | |
| '/privacy', | ||
| '/search', | ||
| '/settings', | ||
| '/manifest.webmanifest', | ||
| '/recharging', | ||
| ] | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a problem with the icon, it is square, but on other shapes of icons (for example, round ones), the edges are white, this needs to be fixed.
It would also be great to add a monochrome version of the icon to have this icon themed as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to change the svg icons again, will be fixed once the service worker fixed (search page)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you need some specific designs - let me know
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we only need to add some padding at pwa assets generator configuration...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right now we cannot check PWA icons at devtools, we'll need to use external tools: https://issues.chromium.org/issues/492211941
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/npmx-dev/npmx.dev/blob/77b9103a6b1ec172706a6438c92e7328dabfafce/public/pwa-64x64.png
How to add them and where? The icon itself looks fine. I can make it circle or just "./" with a transparent background, but I don't understand what the problem is...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The screenshot is the PWA icons when installed at android device, android "desktop" icon, we can use https://maskable.app/ to check the paddings.
The icon comes from the preset (will be generated when running the pwa icons script here https://github.com/npmx-dev/npmx.dev/blob/main/package.json#L31)
For example, the paddings can be added via custom preset (here the logic https://github.com/elk-zone/elk/blob/main/scripts/generate-pwa-icons.ts#L55-L80 , I added the manual preset al elk.zone then extracted to pwa assets generarator package) => we can add some padding to the svg or we can add the padding when generating the png files.