diff --git a/packages/sw/build.js b/packages/sw/build.js index a9c2e428c0..c975408664 100644 --- a/packages/sw/build.js +++ b/packages/sw/build.js @@ -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), }, diff --git a/packages/sw/eslint.config.js b/packages/sw/eslint.config.js index c62a2eadc6..7878eb14b0 100644 --- a/packages/sw/eslint.config.js +++ b/packages/sw/eslint.config.js @@ -12,6 +12,7 @@ export default [ require: false, _DEV_: false, _LANGS_: false, + _LANGS_VERSION_: false, _VERSION_: false, _ENV_: false, _PERF_PREFIX_: false, diff --git a/packages/sw/src/@types/global.d.ts b/packages/sw/src/@types/global.d.ts index bf63810e6d..334fa81511 100644 --- a/packages/sw/src/@types/global.d.ts +++ b/packages/sw/src/@types/global.d.ts @@ -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; diff --git a/packages/sw/src/scripts/lang.ts b/packages/sw/src/scripts/lang.ts index 3000160e41..41b06515f4 100644 --- a/packages/sw/src/scripts/lang.ts +++ b/packages/sw/src/scripts/lang.ts @@ -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 = get('lang').then(async prelang => { if (!prelang) return 'en-US'; @@ -32,7 +32,7 @@ class SwLang { private async _fetch(): Promise> { // 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の場合は常に最新化