mirror of
https://codeberg.org/yeentown/barkey
synced 2024-12-22 18:50:00 +00:00
fix locales versioning in service worker
This commit is contained in:
parent
b5a1c54d65
commit
45ac7e50bc
4 changed files with 6 additions and 2 deletions
|
@ -9,6 +9,7 @@ import { fileURLToPath } from 'node:url';
|
|||
import * as esbuild from 'esbuild';
|
||||
import locales from '../../locales/index.js';
|
||||
import meta from '../../package.json' with { type: 'json' };
|
||||
import { localesVersion } from '../../locales/version.js';
|
||||
const watch = process.argv[2]?.includes('watch');
|
||||
|
||||
const __dirname = fileURLToPath(new URL('.', import.meta.url));
|
||||
|
@ -23,6 +24,7 @@ const buildOptions = {
|
|||
_DEV_: JSON.stringify(process.env.NODE_ENV !== 'production'),
|
||||
_ENV_: JSON.stringify(process.env.NODE_ENV ?? ''), // `NODE_ENV`が`undefined`なとき`JSON.stringify`が`undefined`を返してエラーになってしまうので`??`を使っている
|
||||
_LANGS_: JSON.stringify(Object.entries(locales).map(([k, v]) => [k, v._lang_])),
|
||||
_LANGS_VERSION_: JSON.stringify(localesVersion),
|
||||
_PERF_PREFIX_: JSON.stringify('Misskey:'),
|
||||
_VERSION_: JSON.stringify(meta.version),
|
||||
},
|
||||
|
|
|
@ -12,6 +12,7 @@ export default [
|
|||
require: false,
|
||||
_DEV_: false,
|
||||
_LANGS_: false,
|
||||
_LANGS_VERSION_: false,
|
||||
_VERSION_: false,
|
||||
_ENV_: false,
|
||||
_PERF_PREFIX_: false,
|
||||
|
|
1
packages/sw/src/@types/global.d.ts
vendored
1
packages/sw/src/@types/global.d.ts
vendored
|
@ -7,6 +7,7 @@
|
|||
type FIXME = any;
|
||||
|
||||
declare const _LANGS_: string[][];
|
||||
declare const _LANGS_VERSION_: string;
|
||||
declare const _VERSION_: string;
|
||||
declare const _ENV_: string;
|
||||
declare const _DEV_: boolean;
|
||||
|
|
|
@ -11,7 +11,7 @@ import { I18n } from '@@/js/i18n.js';
|
|||
import type { Locale } from '../../../../locales/index.js';
|
||||
|
||||
class SwLang {
|
||||
public cacheName = `mk-cache-${_VERSION_}`;
|
||||
public cacheName = `mk-cache-${_LANGS_VERSION_}`;
|
||||
|
||||
public lang: Promise<string> = get('lang').then(async prelang => {
|
||||
if (!prelang) return 'en-US';
|
||||
|
@ -32,7 +32,7 @@ class SwLang {
|
|||
|
||||
private async _fetch(): Promise<I18n<Locale>> {
|
||||
// Service Workerは何度も起動しそのたびにlocaleを読み込むので、CacheStorageを使う
|
||||
const localeUrl = `/assets/locales/${await this.lang}.${_VERSION_}.json`;
|
||||
const localeUrl = `/assets/locales/${await this.lang}.${_LANGS_VERSION_}.json`;
|
||||
let localeRes = await caches.match(localeUrl);
|
||||
|
||||
// _DEV_がtrueの場合は常に最新化
|
||||
|
|
Loading…
Reference in a new issue