@oxy.so/app-preset 6.7.0 → 6.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -2
- package/bin/oxy-web-pwa.js +12 -4
- package/package.json +1 -1
- package/web/oxy-sw-base.js +3 -2
- package/web/pwa.js +44 -7
package/README.md
CHANGED
|
@@ -102,12 +102,17 @@ The app keeps its own `public/manifest.json` and icons. The step:
|
|
|
102
102
|
does, the step warns. A worker that already answers `fetch` (Inbosh, Nilo)
|
|
103
103
|
must not import it. `--no-sw` ships no worker.
|
|
104
104
|
|
|
105
|
+
`theme-color` comes from the manifest's `theme_color`, one tag. An app whose
|
|
106
|
+
startup colour is a light/dark pair (Bloom adopts one and owns it at runtime)
|
|
107
|
+
passes it instead: `oxy-web-pwa dist --theme-color=#f9f2f6,#100d11` (hex or a
|
|
108
|
+
colour name; a page that already has a `theme-color` keeps it).
|
|
109
|
+
|
|
105
110
|
The base worker (`web/oxy-sw-base.js`, from Inbosh's) answers navigations
|
|
106
111
|
network-first with the one `/index.html` shell as the offline fallback, and
|
|
107
112
|
same-origin static files (`/_expo/`, `/assets/`, images, fonts, JS, CSS)
|
|
108
113
|
stale-while-revalidate. It never stores or serves anything else: cross-origin
|
|
109
|
-
requests (every Oxy API), non-GET, `/api/`, requests carrying `Authorization
|
|
110
|
-
|
|
114
|
+
requests (every Oxy API), non-GET, `/api/`, requests carrying `Authorization`
|
|
115
|
+
or `Range`, and `private`/`no-store` responses. Its
|
|
111
116
|
cache name is a hash of the export, so each deploy installs a new worker and
|
|
112
117
|
drops the old cache; the cache holds at most 150 entries.
|
|
113
118
|
|
package/bin/oxy-web-pwa.js
CHANGED
|
@@ -5,14 +5,16 @@
|
|
|
5
5
|
*
|
|
6
6
|
* expo export --platform web --output-dir dist && oxy-web-pwa dist
|
|
7
7
|
*
|
|
8
|
-
* oxy-web-pwa [dist] [--no-sw]
|
|
8
|
+
* oxy-web-pwa [dist] [--no-sw] [--theme-color=<light>,<dark>]
|
|
9
9
|
*
|
|
10
10
|
* `dist` defaults to `dist`. The step checks the exported manifest
|
|
11
11
|
* (public/manifest.json) against what browsers need to offer installation,
|
|
12
12
|
* adds the manifest link, theme colour, Apple tags and the worker registration
|
|
13
13
|
* to every exported page that lacks them, and ships the Oxy base service
|
|
14
14
|
* worker (`/oxy-sw-base.js`, plus `/sw.js` when the app has none).
|
|
15
|
-
* `--no-sw` skips the worker.
|
|
15
|
+
* `--no-sw` skips the worker. `--theme-color=<light>,<dark>` writes the
|
|
16
|
+
* startup `theme-color` as a light/dark pair (the one Bloom adopts at runtime)
|
|
17
|
+
* instead of the manifest's single `theme_color`.
|
|
16
18
|
*
|
|
17
19
|
* Exits 0 when the export is installable, 1 when it is not, 2 on bad usage.
|
|
18
20
|
* See README "Installable web apps".
|
|
@@ -20,15 +22,21 @@
|
|
|
20
22
|
const { resolve } = require('node:path');
|
|
21
23
|
const { PwaError, makeInstallable } = require('../web/pwa');
|
|
22
24
|
|
|
23
|
-
const usage = 'oxy-web-pwa [dist] [--no-sw]';
|
|
25
|
+
const usage = 'oxy-web-pwa [dist] [--no-sw] [--theme-color=<light>,<dark>]';
|
|
24
26
|
const args = process.argv.slice(2);
|
|
25
27
|
let dist = 'dist';
|
|
26
28
|
let serviceWorker = true;
|
|
29
|
+
let themeColors;
|
|
27
30
|
for (const arg of args) {
|
|
28
31
|
if (arg === '--help' || arg === '-h') {
|
|
29
32
|
console.log(usage);
|
|
30
33
|
process.exit(0);
|
|
31
34
|
} else if (arg === '--no-sw') serviceWorker = false;
|
|
35
|
+
else if (arg.startsWith('--theme-color='))
|
|
36
|
+
themeColors = arg
|
|
37
|
+
.slice('--theme-color='.length)
|
|
38
|
+
.split(',')
|
|
39
|
+
.map((color) => color.trim());
|
|
32
40
|
else if (arg.startsWith('-')) {
|
|
33
41
|
console.error(`Unknown option ${arg}\n${usage}`);
|
|
34
42
|
process.exit(2);
|
|
@@ -36,7 +44,7 @@ for (const arg of args) {
|
|
|
36
44
|
}
|
|
37
45
|
|
|
38
46
|
try {
|
|
39
|
-
const result = makeInstallable(resolve(dist), { serviceWorker });
|
|
47
|
+
const result = makeInstallable(resolve(dist), { serviceWorker, themeColors });
|
|
40
48
|
for (const warning of result.warnings) console.warn(`oxy-web-pwa: warning: ${warning}`);
|
|
41
49
|
console.log(
|
|
42
50
|
`oxy-web-pwa: ${result.manifest} is installable; ${result.updated.length} of ${result.pages} pages updated` +
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxy.so/app-preset",
|
|
3
|
-
"version": "6.7.
|
|
3
|
+
"version": "6.7.1",
|
|
4
4
|
"description": "The Oxy distro of Expo — centralized Expo config plugin, Metro/Babel/ESLint factories, Tailwind base CSS and TypeScript bases shared by every Oxy app (Mention, Homiio, Allo, accounts, …). A zero-build package: apps replace copy-pasted config with a single dependency bump.",
|
|
5
5
|
"main": "./app.plugin.js",
|
|
6
6
|
"publishConfig": {
|
package/web/oxy-sw-base.js
CHANGED
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
* page that is still running it.
|
|
19
19
|
* - Everything else is left to the browser, never stored and never served
|
|
20
20
|
* from here: cross-origin requests (every Oxy API), non-GET, `/api/`, any
|
|
21
|
-
* request carrying
|
|
21
|
+
* request carrying `Authorization`, range requests, and `private` or
|
|
22
|
+
* `no-store` responses. (`credentials` is no test: every navigation is
|
|
23
|
+
* `include`, and a same-origin request sends cookies either way.)
|
|
22
24
|
* Private responses must never be cached by URL: Inbosh once served one
|
|
23
25
|
* signed-in user's API response to the next.
|
|
24
26
|
*
|
|
@@ -78,7 +80,6 @@
|
|
|
78
80
|
if (url.origin !== self.location.origin) return null;
|
|
79
81
|
if (url.pathname.startsWith('/api/')) return null;
|
|
80
82
|
if (request.headers.has('authorization') || request.headers.has('range')) return null;
|
|
81
|
-
if (request.credentials === 'include') return null;
|
|
82
83
|
if (request.mode === 'navigate') return 'navigation';
|
|
83
84
|
if (
|
|
84
85
|
url.pathname.startsWith('/_expo/') ||
|
package/web/pwa.js
CHANGED
|
@@ -124,8 +124,10 @@ function missingTags(document, wanted) {
|
|
|
124
124
|
if (tag.kind === 'script' && scripts.has(tag.src)) continue;
|
|
125
125
|
if (tag.kind === 'link')
|
|
126
126
|
out.push(`<link rel="${tag.rel}" href="${escapeAttribute(tag.href)}" />`);
|
|
127
|
-
if (tag.kind === 'meta')
|
|
128
|
-
|
|
127
|
+
if (tag.kind === 'meta') {
|
|
128
|
+
const media = tag.media ? ` media="${escapeAttribute(tag.media)}"` : '';
|
|
129
|
+
out.push(`<meta name="${tag.name}" content="${escapeAttribute(tag.content)}"${media} />`);
|
|
130
|
+
}
|
|
129
131
|
if (tag.kind === 'script')
|
|
130
132
|
out.push(`<script src="${escapeAttribute(tag.src)}" defer></script>`);
|
|
131
133
|
}
|
|
@@ -147,12 +149,36 @@ function injectHead(html, wanted) {
|
|
|
147
149
|
return `${html.slice(0, end)}${block}${html.slice(end)}`;
|
|
148
150
|
}
|
|
149
151
|
|
|
150
|
-
|
|
152
|
+
/**
|
|
153
|
+
* The startup `theme-color` tags: `--theme-color=<light>,<dark>` gives a pair
|
|
154
|
+
* scoped by `prefers-color-scheme` (what Bloom adopts and then owns at
|
|
155
|
+
* runtime); one colour, or none (the manifest's `theme_color`), gives one tag.
|
|
156
|
+
*/
|
|
157
|
+
function themeColorTags(manifest, themeColors) {
|
|
158
|
+
const colors = themeColors?.length ? themeColors : [manifest.theme_color].filter(Boolean);
|
|
159
|
+
if (colors.length === 2)
|
|
160
|
+
return [
|
|
161
|
+
{
|
|
162
|
+
kind: 'meta',
|
|
163
|
+
name: 'theme-color',
|
|
164
|
+
content: colors[0],
|
|
165
|
+
media: '(prefers-color-scheme: light)',
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
kind: 'meta',
|
|
169
|
+
name: 'theme-color',
|
|
170
|
+
content: colors[1],
|
|
171
|
+
media: '(prefers-color-scheme: dark)',
|
|
172
|
+
},
|
|
173
|
+
];
|
|
174
|
+
return colors.map((content) => ({ kind: 'meta', name: 'theme-color', content }));
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function wantedTags(manifestName, manifest, dist, { serviceWorker, themeColors }) {
|
|
151
178
|
const wanted = [{ kind: 'link', rel: 'manifest', href: `/${manifestName}` }];
|
|
152
179
|
if (existsSync(join(dist, 'apple-touch-icon.png')))
|
|
153
180
|
wanted.push({ kind: 'link', rel: 'apple-touch-icon', href: '/apple-touch-icon.png' });
|
|
154
|
-
|
|
155
|
-
wanted.push({ kind: 'meta', name: 'theme-color', content: manifest.theme_color });
|
|
181
|
+
wanted.push(...themeColorTags(manifest, themeColors));
|
|
156
182
|
wanted.push({ kind: 'meta', name: 'mobile-web-app-capable', content: 'yes' });
|
|
157
183
|
wanted.push({ kind: 'meta', name: 'apple-mobile-web-app-capable', content: 'yes' });
|
|
158
184
|
const title = manifest.short_name || manifest.name;
|
|
@@ -177,7 +203,18 @@ importScripts('/${SW_BASE}');
|
|
|
177
203
|
* Runs the whole step on `dist`. Throws PwaError on anything that leaves the
|
|
178
204
|
* app uninstallable; returns what it did and any warnings.
|
|
179
205
|
*/
|
|
180
|
-
function makeInstallable(dist, { serviceWorker = true } = {}) {
|
|
206
|
+
function makeInstallable(dist, { serviceWorker = true, themeColors } = {}) {
|
|
207
|
+
if (themeColors !== undefined) {
|
|
208
|
+
const valid = /^(?:#[0-9a-f]{3,8}|[a-z]+|(?:rgb|hsl)a?\([^"<>]*\))$/i;
|
|
209
|
+
if (
|
|
210
|
+
themeColors.length < 1 ||
|
|
211
|
+
themeColors.length > 2 ||
|
|
212
|
+
!themeColors.every((c) => valid.test(c))
|
|
213
|
+
)
|
|
214
|
+
throw new PwaError(
|
|
215
|
+
`--theme-color takes one colour or <light>,<dark>; got ${JSON.stringify(themeColors.join(','))}`,
|
|
216
|
+
);
|
|
217
|
+
}
|
|
181
218
|
if (!existsSync(dist) || !statSync(dist).isDirectory())
|
|
182
219
|
throw new PwaError(`${dist} is not a directory; run expo export first`);
|
|
183
220
|
const manifestName = findManifest(dist);
|
|
@@ -197,7 +234,7 @@ function makeInstallable(dist, { serviceWorker = true } = {}) {
|
|
|
197
234
|
|
|
198
235
|
const pages = htmlFiles(dist);
|
|
199
236
|
if (pages.length === 0) throw new PwaError(`${dist} has no HTML page`);
|
|
200
|
-
const wanted = wantedTags(manifestName, manifest, dist, { serviceWorker });
|
|
237
|
+
const wanted = wantedTags(manifestName, manifest, dist, { serviceWorker, themeColors });
|
|
201
238
|
const updated = [];
|
|
202
239
|
for (const page of pages) {
|
|
203
240
|
let next;
|