Skip to content

Commit

Permalink
fix: service worker
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackman99 committed Nov 28, 2024
1 parent 06a39b9 commit dd8385a
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 46 deletions.
5 changes: 5 additions & 0 deletions .changeset/twenty-hairs-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltepress/theme-default": patch
---

fix: service worker
8 changes: 6 additions & 2 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export default antfu({
},
},
],
'unused-imports/no-unused-vars': 'off',
'no-unused-vars': 'off',
},
ignores: [
'node_modules',
Expand Down Expand Up @@ -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',
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ exports[`code import > existing and non-existing file 2`] = `
<!-- svelte-ignore a11y_no_noninteractive_tabindex -->
<pre class="shiki shiki-themes vitesse-light night-owl" style="background-color:#ffffff;--shiki-dark-bg:#011627;color:#393a34;--shiki-dark:#d6deeb" tabindex="0"><code><span class="line"><span style="color:#A0ADA0;--shiki-dark:#637777">//</span><span style="color:#A0ADA0;font-style:inherit;--shiki-dark:#637777;--shiki-dark-font-style:italic"> @noErrors</span></span>
<span class="line"><span style="color:#AB5959;--shiki-dark:#C792EA">const</span><span style="color:#B07D48;font-style:inherit;--shiki-dark:#82AAFF;--shiki-dark-font-style:italic"> VIRTUAL_PWA_SVELTE_REGISTER</span><span style="color:#999999;--shiki-dark:#C792EA"> =</span><span style="color:#B5695977;--shiki-dark:#D9F5DD"> '</span><span style="color:#B56959;--shiki-dark:#ECC48D">virtual:pwa-register/svelte</span><span style="color:#B5695977;--shiki-dark:#D9F5DD">'</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;font-style:inherit;--shiki-dark:#C792EA;--shiki-dark-font-style:italic">export</span><span style="color:#AB5959;--shiki-dark:#C792EA"> const</span><span style="color:#B07D48;font-style:inherit;--shiki-dark:#82AAFF;--shiki-dark-font-style:italic"> themeOptionsRef</span><span style="color:#999999;--shiki-dark:#7FDBCA">:</span><span style="color:#999999;--shiki-dark:#C792EA"> &#123;</span></span>
<span class="line"><span style="color:#B07D48;font-style:inherit;--shiki-dark:#D6DEEB;--shiki-dark-font-style:italic"> value</span><span style="color:#AB5959;--shiki-dark:#7FDBCA">?</span><span style="color:#999999;--shiki-dark:#7FDBCA">:</span><span style="color:#2E8F82;font-style:inherit;--shiki-dark:#FFCB8B;--shiki-dark-font-style:italic"> DefaultThemeOptions</span></span>
<span class="line"><span style="color:#999999;--shiki-dark:#C792EA">&#125;</span><span style="color:#999999;--shiki-dark:#C792EA"> =</span><span style="color:#999999;--shiki-dark:#C792EA"> &#123;</span></span>
<span class="line"><span style="color:#998418;font-style:inherit;--shiki-dark:#C792EA;--shiki-dark-font-style:italic"> value</span><span style="color:#999999;--shiki-dark:#C792EA">:</span><span style="color:#AB5959;font-style:inherit;--shiki-dark:#82AAFF;--shiki-dark-font-style:italic"> undefined</span><span style="color:#999999;--shiki-dark:#C792EA">,</span></span>
<span class="line"><span style="color:#999999;--shiki-dark:#C792EA">&#125;</span></span>
<span class="line"><span style="color:#B07D48;--shiki-dark:#D6DEEB">value</span><span style="color:#AB5959;--shiki-dark:#C792EA">?:</span><span style="color:#B07D48;--shiki-dark:#D6DEEB"> DefaultThemeOptions</span></span>
<span class="line"><span style="color:#393A34;--shiki-dark:#D6DEEB">&#125; </span><span style="color:#999999;--shiki-dark:#C792EA">=</span><span style="color:#999999;--shiki-dark:#D6DEEB"> &#123;</span></span>
<span class="line"><span style="color:#998418;--shiki-dark:#D6DEEB">value</span><span style="color:#999999;--shiki-dark:#D6DEEB">: </span><span style="color:#AB5959;--shiki-dark:#82AAFF">undefined</span><span style="color:#999999;--shiki-dark:#D6DEEB">,</span></span>
<span class="line"><span style="color:#999999;--shiki-dark:#D6DEEB">&#125;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#AB5959;--shiki-dark:#C792EA">const</span><span style="color:#59873A;font-style:inherit;--shiki-dark:#82AAFF;--shiki-dark-font-style:italic"> defaultTheme</span><span style="color:#999999;--shiki-dark:#7FDBCA">:</span><span style="color:#2E8F82;font-style:inherit;--shiki-dark:#FFCB8B;--shiki-dark-font-style:italic"> ThemeDefault</span><span style="color:#999999;--shiki-dark:#C792EA"> =</span><span style="color:#999999;--shiki-dark:#D9F5DD"> (</span><span style="color:#B07D48;font-style:inherit;--shiki-dark:#D7DBE0;--shiki-dark-font-style:italic">options</span><span style="color:#999999;--shiki-dark:#D9F5DD">)</span><span style="color:#999999;--shiki-dark:#C792EA"> =></span><span style="color:#999999;--shiki-dark:#C792EA"> &#123;</span></span>
<span class="line"><span style="color:#B07D48;font-style:inherit;--shiki-dark:#D6DEEB;--shiki-dark-font-style:italic"> themeOptionsRef</span><span style="color:#999999;font-style:inherit;--shiki-dark:#C792EA;--shiki-dark-font-style:italic">.</span><span style="color:#B07D48;font-style:inherit;--shiki-dark:#BAEBE2;--shiki-dark-font-style:italic">value</span><span style="color:#999999;--shiki-dark:#C792EA"> =</span><span style="color:#B07D48;font-style:inherit;--shiki-dark:#D6DEEB;--shiki-dark-font-style:italic"> options</span></span>
<span class="line"><span style="color:#B07D48;font-style:inherit;--shiki-dark:#D6DEEB;--shiki-dark-font-style:italic">themeOptionsRef</span><span style="color:#999999;font-style:inherit;--shiki-dark:#C792EA;--shiki-dark-font-style:italic">.</span><span style="color:#B07D48;font-style:inherit;--shiki-dark:#BAEBE2;--shiki-dark-font-style:italic">value</span><span style="color:#999999;--shiki-dark:#C792EA"> =</span><span style="color:#B07D48;font-style:inherit;--shiki-dark:#D6DEEB;--shiki-dark-font-style:italic"> options</span></span>
<span class="line"></span>
<span class="line"><span style="color:#1E754F;font-style:inherit;--shiki-dark:#C792EA;--shiki-dark-font-style:italic"> return</span><span style="color:#999999;--shiki-dark:#C792EA"> &#123;</span></span>
<span class="line"><span style="color:#998418;font-style:inherit;--shiki-dark:#C792EA;--shiki-dark-font-style:italic"> name</span><span style="color:#999999;--shiki-dark:#C792EA">:</span><span style="color:#B5695977;--shiki-dark:#D9F5DD"> '</span><span style="color:#B56959;--shiki-dark:#ECC48D">@sveltepress/theme-default</span><span style="color:#B5695977;--shiki-dark:#D9F5DD">'</span><span style="color:#999999;--shiki-dark:#C792EA">,</span></span>
<span class="line"><span style="color:#998418;font-style:inherit;--shiki-dark:#C792EA;--shiki-dark-font-style:italic"> globalLayout</span><span style="color:#999999;--shiki-dark:#C792EA">:</span><span style="color:#B5695977;--shiki-dark:#D9F5DD"> '</span><span style="color:#B56959;--shiki-dark:#ECC48D">@sveltepress/theme-default/GlobalLayout.svelte</span><span style="color:#B5695977;--shiki-dark:#D9F5DD">'</span><span style="color:#999999;--shiki-dark:#C792EA">,</span></span>
<span class="line"><span style="color:#998418;font-style:inherit;--shiki-dark:#C792EA;--shiki-dark-font-style:italic"> pageLayout</span><span style="color:#999999;--shiki-dark:#C792EA">:</span><span style="color:#B5695977;--shiki-dark:#D9F5DD"> '</span><span style="color:#B56959;--shiki-dark:#ECC48D">@sveltepress/theme-default/PageLayout.svelte</span><span style="color:#B5695977;--shiki-dark:#D9F5DD">'</span><span style="color:#999999;--shiki-dark:#C792EA">,</span></span>
<span class="line"><span style="color:#59873A;font-style:inherit;--shiki-dark:#82AAFF;--shiki-dark-font-style:italic"> vitePlugins</span><span style="color:#999999;--shiki-dark:#C792EA">:</span><span style="color:#999999;--shiki-dark:#D9F5DD"> (</span><span style="color:#B07D48;font-style:inherit;--shiki-dark:#D7DBE0;--shiki-dark-font-style:italic">corePlugin</span><span style="color:#999999;--shiki-dark:#D9F5DD">)</span><span style="color:#999999;--shiki-dark:#C792EA"> =></span><span style="color:#999999;--shiki-dark:#C792EA"> &#123;</span></span>
<span class="line"><span style="color:#AB5959;--shiki-dark:#C792EA"> const</span><span style="color:#B07D48;font-style:inherit;--shiki-dark:#82AAFF;--shiki-dark-font-style:italic"> plugins</span><span style="color:#999999;--shiki-dark:#C792EA"> =</span><span style="color:#999999;--shiki-dark:#D6DEEB"> [</span></span>
<span class="line"><span style="color:#999999;--shiki-dark:#7FDBCA"> ...</span><span style="color:#59873A;font-style:inherit;--shiki-dark:#82AAFF;--shiki-dark-font-style:italic">createPreCorePlugins</span><span style="color:#999999;--shiki-dark:#D6DEEB">(</span><span style="color:#B07D48;font-style:inherit;--shiki-dark:#D6DEEB;--shiki-dark-font-style:italic">options</span><span style="color:#999999;--shiki-dark:#D6DEEB">)</span></span></code></pre>
<span class="line"><span style="color:#1E754F;font-style:inherit;--shiki-dark:#C792EA;--shiki-dark-font-style:italic">return</span><span style="color:#999999;--shiki-dark:#C792EA"> &#123;</span></span>
<span class="line"><span style="color:#998418;font-style:inherit;--shiki-dark:#C792EA;--shiki-dark-font-style:italic"> name</span><span style="color:#999999;--shiki-dark:#C792EA">:</span><span style="color:#B5695977;--shiki-dark:#D9F5DD"> '</span><span style="color:#B56959;--shiki-dark:#ECC48D">@sveltepress/theme-default</span><span style="color:#B5695977;--shiki-dark:#D9F5DD">'</span><span style="color:#999999;--shiki-dark:#C792EA">,</span></span>
<span class="line"><span style="color:#998418;font-style:inherit;--shiki-dark:#C792EA;--shiki-dark-font-style:italic"> globalLayout</span><span style="color:#999999;--shiki-dark:#C792EA">:</span><span style="color:#B5695977;--shiki-dark:#D9F5DD"> '</span><span style="color:#B56959;--shiki-dark:#ECC48D">@sveltepress/theme-default/GlobalLayout.svelte</span><span style="color:#B5695977;--shiki-dark:#D9F5DD">'</span><span style="color:#999999;--shiki-dark:#C792EA">,</span></span>
<span class="line"><span style="color:#998418;font-style:inherit;--shiki-dark:#C792EA;--shiki-dark-font-style:italic"> pageLayout</span><span style="color:#999999;--shiki-dark:#C792EA">:</span><span style="color:#B5695977;--shiki-dark:#D9F5DD"> '</span><span style="color:#B56959;--shiki-dark:#ECC48D">@sveltepress/theme-default/PageLayout.svelte</span><span style="color:#B5695977;--shiki-dark:#D9F5DD">'</span><span style="color:#999999;--shiki-dark:#C792EA">,</span></span>
<span class="line"><span style="color:#59873A;font-style:inherit;--shiki-dark:#82AAFF;--shiki-dark-font-style:italic"> vitePlugins</span><span style="color:#999999;--shiki-dark:#C792EA">:</span><span style="color:#999999;--shiki-dark:#D9F5DD"> (</span><span style="color:#B07D48;font-style:inherit;--shiki-dark:#D7DBE0;--shiki-dark-font-style:italic">corePlugin</span><span style="color:#999999;--shiki-dark:#D9F5DD">)</span><span style="color:#999999;--shiki-dark:#C792EA"> =></span><span style="color:#999999;--shiki-dark:#C792EA"> &#123;</span></span>
<span class="line"><span style="color:#AB5959;--shiki-dark:#C792EA"> const</span><span style="color:#B07D48;font-style:inherit;--shiki-dark:#82AAFF;--shiki-dark-font-style:italic"> plugins</span><span style="color:#999999;--shiki-dark:#C792EA"> =</span><span style="color:#999999;--shiki-dark:#D6DEEB"> [</span></span>
<span class="line"><span style="color:#999999;--shiki-dark:#7FDBCA"> ...</span><span style="color:#59873A;font-style:inherit;--shiki-dark:#82AAFF;--shiki-dark-font-style:italic">createPreCorePlugins</span><span style="color:#999999;--shiki-dark:#D6DEEB">(</span><span style="color:#B07D48;font-style:inherit;--shiki-dark:#D6DEEB;--shiki-dark-font-style:italic">options</span><span style="color:#999999;--shiki-dark:#D6DEEB">),</span></span>
<span class="line"><span style="color:#B07D48;font-style:inherit;--shiki-dark:#D6DEEB;--shiki-dark-font-style:italic"> corePlugin</span><span style="color:#999999;--shiki-dark:#D6DEEB">,</span></span>
<span class="line"><span style="color:#999999;--shiki-dark:#D6DEEB"> ]</span></span>
<span class="line"><span style="color:#1E754F;--shiki-dark:#C792EA"> if</span><span style="color:#999999;--shiki-dark:#D6DEEB"> (</span><span style="color:#B07D48;font-style:inherit;--shiki-dark:#D6DEEB;--shiki-dark-font-style:italic">options</span><span style="color:#999999;font-style:inherit;--shiki-dark:#C792EA;--shiki-dark-font-style:italic">?.</span><span style="color:#B07D48;font-style:inherit;--shiki-dark:#BAEBE2;--shiki-dark-font-style:italic">pwa</span><span style="color:#999999;--shiki-dark:#D6DEEB">)</span><span style="color:#999999;--shiki-dark:#C792EA"> &#123;</span></span></code></pre>
<div class="svp-code-block--lang">
ts
</div>
Expand Down
1 change: 0 additions & 1 deletion packages/theme-default/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
5 changes: 4 additions & 1 deletion packages/theme-default/src/constants.ts
Original file line number Diff line number Diff line change
@@ -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')
7 changes: 2 additions & 5 deletions packages/theme-default/src/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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'

Expand All @@ -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',
Expand Down
Loading

0 comments on commit dd8385a

Please sign in to comment.