diff --git a/.changeset/twenty-hairs-wink.md b/.changeset/twenty-hairs-wink.md new file mode 100644 index 00000000..5e2fff47 --- /dev/null +++ b/.changeset/twenty-hairs-wink.md @@ -0,0 +1,5 @@ +--- +"@sveltepress/theme-default": patch +--- + +fix: service worker diff --git a/eslint.config.mjs b/eslint.config.mjs index ad6ce866..f4b5549d 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -14,8 +14,6 @@ export default antfu({ }, }, ], - 'unused-imports/no-unused-vars': 'off', - 'no-unused-vars': 'off', }, ignores: [ 'node_modules', @@ -53,4 +51,10 @@ export default antfu({ 'style/no-tabs': 'off', 'style/eol-last': 'off', }, +}, { + files: ['packages/docs-site*/**/*'], + rules: { + 'unused-imports/no-unused-vars': 'off', + 'no-unused-vars': 'off', + }, }) diff --git a/packages/theme-default/__tests__/__snapshots__/import-code.test.ts.snap b/packages/theme-default/__tests__/__snapshots__/import-code.test.ts.snap index 86254713..a15b3bcc 100644 --- a/packages/theme-default/__tests__/__snapshots__/import-code.test.ts.snap +++ b/packages/theme-default/__tests__/__snapshots__/import-code.test.ts.snap @@ -9,24 +9,24 @@ exports[`code import > existing and non-existing file 2`] = `
// @noErrors
-const VIRTUAL_PWA_SVELTE_REGISTER = 'virtual:pwa-register/svelte'
-
-export const themeOptionsRef: {
-  value?: DefaultThemeOptions
-} = {
-  value: undefined,
-}
+value?: DefaultThemeOptions
+} = {
+value: undefined,
+}
 
 const defaultTheme: ThemeDefault = (options) => {
-  themeOptionsRef.value = options
+themeOptionsRef.value = options
 
-  return {
-    name: '@sveltepress/theme-default',
-    globalLayout: '@sveltepress/theme-default/GlobalLayout.svelte',
-    pageLayout: '@sveltepress/theme-default/PageLayout.svelte',
-    vitePlugins: (corePlugin) => {
-      const plugins = [
-        ...createPreCorePlugins(options)
+return { + name: '@sveltepress/theme-default', + globalLayout: '@sveltepress/theme-default/GlobalLayout.svelte', + pageLayout: '@sveltepress/theme-default/PageLayout.svelte', + vitePlugins: (corePlugin) => { + const plugins = [ + ...createPreCorePlugins(options), + corePlugin, + ] + if (options?.pwa) {
ts
diff --git a/packages/theme-default/package.json b/packages/theme-default/package.json index 1a496f3c..749f7c1b 100644 --- a/packages/theme-default/package.json +++ b/packages/theme-default/package.json @@ -80,7 +80,6 @@ "uid": "^2.0.2", "unist-util-visit": "^5.0.0", "unocss": "catalog:", - "vite-plugin-pwa": "^0.19.0", "workbox-precaching": "^7.0.0", "workbox-routing": "^7.0.0" }, diff --git a/packages/theme-default/src/constants.ts b/packages/theme-default/src/constants.ts index 051b1b68..b5a65bc3 100644 --- a/packages/theme-default/src/constants.ts +++ b/packages/theme-default/src/constants.ts @@ -1 +1,4 @@ -export const SERVICE_WORKER_PATH = 'node_modules/@sveltepress/theme-default/dist/components/pwa/sw.js' +import { resolve } from 'node:path' +import { cwd } from 'node:process' + +export const SERVICE_WORKER_PATH = resolve(cwd(), 'node_modules/@sveltepress/theme-default/dist/components/pwa/sw.js') diff --git a/packages/theme-default/src/index.ts b/packages/theme-default/src/index.ts index e402b5ae..9eb6c2ff 100644 --- a/packages/theme-default/src/index.ts +++ b/packages/theme-default/src/index.ts @@ -1,8 +1,7 @@ import type { DefaultThemeOptions, ThemeDefault } from 'virtual:sveltepress/theme-default' -import { resolve } from 'node:path' -import { fileURLToPath } from 'node:url' import { SvelteKitPWA } from '@vite-pwa/sveltekit' +import { SERVICE_WORKER_PATH } from './constants.js' import admonitions from './markdown/admonitions.js' import anchors from './markdown/anchors.js' import codeImport from './markdown/code-import.js' @@ -14,8 +13,6 @@ import createPreCorePlugins from './vite-plugins/create-pre-core-plugins.js' export { SERVICE_WORKER_PATH } from './constants.js' -const __dirname = fileURLToPath(new URL('.', import.meta.url)) - const VIRTUAL_PWA = 'virtual:pwa-info' const VIRTUAL_PWA_SVELTE_REGISTER = 'virtual:pwa-register/svelte' @@ -40,7 +37,7 @@ const defaultTheme: ThemeDefault = (options) => { if (options?.pwa) { plugins.push(SvelteKitPWA({ strategies: 'injectManifest', - srcDir: resolve(__dirname, './components/pwa'), + srcDir: SERVICE_WORKER_PATH.replace(/sw\.js$/, ''), filename: 'sw.js', injectManifest: { globDirectory: '.svelte-kit/output', diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index aa1644a8..597118bb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -55,8 +55,8 @@ catalogs: specifier: ^3.0.1 version: 3.0.1 '@sveltejs/kit': - specifier: ^2.8.1 - version: 2.8.1 + specifier: ^2.8.5 + version: 2.8.5 '@sveltejs/package': specifier: ^2.3.7 version: 2.3.7 @@ -213,10 +213,10 @@ importers: version: 1.1.36 '@sveltejs/adapter-static': specifier: 'catalog:' - version: 3.0.1(@sveltejs/kit@2.8.1(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3))) + version: 3.0.1(@sveltejs/kit@2.8.5(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3))) '@sveltejs/kit': specifier: 'catalog:' - version: 2.8.1(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)) + version: 2.8.5(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)) '@sveltejs/vite-plugin-svelte': specifier: 'catalog:' version: 4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)) @@ -291,10 +291,10 @@ importers: version: 1.1.36 '@sveltejs/adapter-static': specifier: 'catalog:' - version: 3.0.1(@sveltejs/kit@2.8.1(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3))) + version: 3.0.1(@sveltejs/kit@2.8.5(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3))) '@sveltejs/kit': specifier: 'catalog:' - version: 2.8.1(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)) + version: 2.8.5(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)) '@sveltejs/vite-plugin-svelte': specifier: 'catalog:' version: 4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)) @@ -369,10 +369,10 @@ importers: version: 1.1.36 '@sveltejs/adapter-static': specifier: 'catalog:' - version: 3.0.1(@sveltejs/kit@2.8.1(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3))) + version: 3.0.1(@sveltejs/kit@2.8.5(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3))) '@sveltejs/kit': specifier: 'catalog:' - version: 2.8.1(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)) + version: 2.8.5(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)) '@sveltejs/vite-plugin-svelte': specifier: 'catalog:' version: 4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)) @@ -423,7 +423,7 @@ importers: version: 0.61.5 '@vite-pwa/sveltekit': specifier: ^0.4.0 - version: 0.4.0(@sveltejs/kit@2.8.1(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(vite-plugin-pwa@0.19.2(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3))(workbox-build@7.0.0)(workbox-window@7.0.0)) + version: 0.4.0(@sveltejs/kit@2.8.5(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(vite-plugin-pwa@0.19.2(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3))(workbox-build@7.0.0)(workbox-window@7.0.0)) lru-cache: specifier: 'catalog:' version: 10.2.0 @@ -439,9 +439,6 @@ importers: unocss: specifier: 'catalog:' version: 0.61.5(postcss@8.4.49)(rollup@2.79.1)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)) - vite-plugin-pwa: - specifier: ^0.19.0 - version: 0.19.2(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3))(workbox-build@7.0.0)(workbox-window@7.0.0) workbox-precaching: specifier: ^7.0.0 version: 7.0.0 @@ -451,7 +448,7 @@ importers: devDependencies: '@sveltejs/kit': specifier: 'catalog:' - version: 2.8.1(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)) + version: 2.8.5(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)) '@sveltejs/package': specifier: 'catalog:' version: 2.3.7(svelte@5.2.7)(typescript@5.5.4) @@ -594,7 +591,7 @@ importers: devDependencies: '@sveltejs/kit': specifier: 'catalog:' - version: 2.8.1(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)) + version: 2.8.5(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)) '@sveltepress/theme-default': specifier: workspace:* version: link:../theme-default @@ -2360,8 +2357,8 @@ packages: peerDependencies: '@sveltejs/kit': ^2.0.0 - '@sveltejs/kit@2.8.1': - resolution: {integrity: sha512-uuOfFwZ4xvnfPsiTB6a4H1ljjTUksGhWnYq5X/Y9z4x5+3uM2Md8q/YVeHL+7w+mygAwoEFdgKZ8YkUuk+VKww==} + '@sveltejs/kit@2.8.5': + resolution: {integrity: sha512-5ry1jPd4r9knsphDK2eTYUFPhFZMqF0PHFfa8MdMQCqWaKwLSXdFMU/Vevih1I7C1/VNB5MvTuFl1kXu5vx8UA==} engines: {node: '>=18.13'} hasBin: true peerDependencies: @@ -8378,11 +8375,11 @@ snapshots: magic-string: 0.25.9 string.prototype.matchall: 4.0.11 - '@sveltejs/adapter-static@3.0.1(@sveltejs/kit@2.8.1(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))': + '@sveltejs/adapter-static@3.0.1(@sveltejs/kit@2.8.5(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))': dependencies: - '@sveltejs/kit': 2.8.1(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)) + '@sveltejs/kit': 2.8.5(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)) - '@sveltejs/kit@2.8.1(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3))': + '@sveltejs/kit@2.8.5(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3))': dependencies: '@sveltejs/vite-plugin-svelte': 4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)) '@types/cookie': 0.6.0 @@ -8762,9 +8759,9 @@ snapshots: transitivePeerDependencies: - rollup - '@vite-pwa/sveltekit@0.4.0(@sveltejs/kit@2.8.1(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(vite-plugin-pwa@0.19.2(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3))(workbox-build@7.0.0)(workbox-window@7.0.0))': + '@vite-pwa/sveltekit@0.4.0(@sveltejs/kit@2.8.5(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(vite-plugin-pwa@0.19.2(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3))(workbox-build@7.0.0)(workbox-window@7.0.0))': dependencies: - '@sveltejs/kit': 2.8.1(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)) + '@sveltejs/kit': 2.8.5(@sveltejs/vite-plugin-svelte@4.0.1(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)))(svelte@5.2.7)(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3)) kolorist: 1.8.0 vite-plugin-pwa: 0.19.2(vite@5.3.4(@types/node@20.14.13)(terser@5.31.3))(workbox-build@7.0.0)(workbox-window@7.0.0) diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 5b18d245..27346158 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -16,7 +16,7 @@ catalog: '@shikijs/twoslash': ^1.23.1 '@unocss/extractor-svelte': ^0.61.5 '@sveltejs/package': ^2.3.7 - '@sveltejs/kit': ^2.8.1 + '@sveltejs/kit': ^2.8.5 '@sveltejs/vite-plugin-svelte': ^4.0.1 '@sveltejs/adapter-static': ^3.0.1 '@iconify-json/bi': ^1.1.23