methanol 0.0.16 → 0.0.18

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "methanol",
3
- "version": "0.0.16",
3
+ "version": "0.0.18",
4
4
  "description": "Static site generator powered by rEFui and MDX",
5
5
  "main": "./index.js",
6
6
  "type": "module",
package/src/client/sw.js CHANGED
@@ -139,7 +139,6 @@ self.addEventListener('install', (event) => {
139
139
  const assetCache = await openCache(ASSETS_CACHE)
140
140
  const manifestEntries = getManifestEntries()
141
141
  const manifestMap = buildManifestMap(manifestEntries)
142
- const previousMap = await loadStoredManifestMap()
143
142
  const manifestUrls = manifestEntries.map((entry) => entry.url)
144
143
  const [prioritized] = prioritizeManifestUrls(manifestUrls)
145
144
  const { failedIndex } = await runConcurrentQueue(prioritized, {
@@ -150,11 +149,9 @@ self.addEventListener('install', (event) => {
150
149
  const cached = await matchCache(cacheName, url)
151
150
  const key = manifestKey(url)
152
151
  const currentRevision = manifestMap.get(key) ?? null
153
- const previousRevision = previousMap.get(key) ?? null
154
152
  const shouldFetch = shouldFetchWithRevision({
155
153
  cached,
156
- currentRevision,
157
- previousRevision
154
+ currentRevision
158
155
  })
159
156
  if (!shouldFetch) return true
160
157
  const cache = isHtml ? pageCache : assetCache
@@ -272,11 +269,12 @@ async function runConcurrentQueue(list, { concurrency, handler, stopOnError = tr
272
269
  return { ok: failedIndex === null, failedIndex }
273
270
  }
274
271
 
275
- function shouldFetchWithRevision({ cached, currentRevision, previousRevision }) {
272
+ function shouldFetchWithRevision({ cached, currentRevision }) {
276
273
  if (!cached) return true
277
274
  if (currentRevision == null) return false
278
- if (previousRevision == null) return true
279
- return currentRevision !== previousRevision
275
+ const cachedRevision = cached.headers?.get?.(REVISION_HEADER)
276
+ if (cachedRevision == null) return true
277
+ return cachedRevision !== String(currentRevision)
280
278
  }
281
279
 
282
280
  function shouldRevalidateCached(cached, currentRevision) {
@@ -550,7 +548,6 @@ const DB_STORE = 'kv'
550
548
  const KEY_INDEX = 'warmIndex'
551
549
  const KEY_LEASE = 'warmLease'
552
550
  const KEY_FORCE = 'warmForce'
553
- const KEY_MANIFEST = 'warmManifest'
554
551
 
555
552
  function idbOpen() {
556
553
  return new Promise((resolve, reject) => {
@@ -611,12 +608,6 @@ function buildManifestMap(entries) {
611
608
  return map
612
609
  }
613
610
 
614
- async function loadStoredManifestMap() {
615
- const stored = await idbGet(KEY_MANIFEST)
616
- if (!stored) return new Map()
617
- if (Array.isArray(stored)) return buildManifestMap(stored)
618
- return new Map()
619
- }
620
611
 
621
612
  async function tryAcquireLease(leaseMs) {
622
613
  const leaseId = randomId()
@@ -667,7 +658,6 @@ async function warmManifestResumable({ force = false } = {}) {
667
658
  try {
668
659
  const manifestEntries = getManifestEntries()
669
660
  const manifestMap = buildManifestMap(manifestEntries)
670
- const previousMap = await loadStoredManifestMap()
671
661
  const [, urls] = prioritizeManifestUrls(manifestEntries.map((entry) => entry.url))
672
662
  if (!urls.length) return
673
663
  if (index >= urls.length) {
@@ -685,14 +675,12 @@ async function warmManifestResumable({ force = false } = {}) {
685
675
  const isHtml = abs.endsWith('.html')
686
676
  const key = manifestKey(abs)
687
677
  const currentRevision = manifestMap.get(key) ?? null
688
- const previousRevision = previousMap.get(key) ?? null
689
678
 
690
679
  if (isHtml) {
691
680
  const cached = await matchCache(PAGES_CACHE, abs)
692
681
  const shouldFetch = shouldFetchWithRevision({
693
682
  cached,
694
- currentRevision,
695
- previousRevision
683
+ currentRevision
696
684
  })
697
685
  if (!shouldFetch) return true
698
686
 
@@ -709,8 +697,7 @@ async function warmManifestResumable({ force = false } = {}) {
709
697
  const cached = await matchCache(ASSETS_CACHE, abs)
710
698
  const shouldFetch = shouldFetchWithRevision({
711
699
  cached,
712
- currentRevision,
713
- previousRevision
700
+ currentRevision
714
701
  })
715
702
  if (!shouldFetch) return true
716
703
 
@@ -738,7 +725,6 @@ async function warmManifestResumable({ force = false } = {}) {
738
725
  completed = true
739
726
  } finally {
740
727
  if (completed) {
741
- await idbSet(KEY_MANIFEST, getManifestEntries())
742
728
  await idbSet(KEY_FORCE, 0)
743
729
  }
744
730
  await releaseLease(lease)
package/src/components.js CHANGED
@@ -51,6 +51,7 @@ export const reframeEnv = env()
51
51
  export const register = reframeEnv.register
52
52
  export const invalidateRegistryEntry = reframeEnv.invalidate
53
53
  export const genRegistryScript = reframeEnv.genRegistryScript
54
+ export const resetReframeRenderCount = () => reframeEnv.resetRenderCount()
54
55
 
55
56
  const resolveComponentExport = (componentPath, exportName, ext) => {
56
57
  const staticCandidate = `${componentPath}.static${ext}`
@@ -75,7 +76,9 @@ const resolveComponentExport = (componentPath, exportName, ext) => {
75
76
  }
76
77
 
77
78
  if (ret.staticPath) {
78
- ret.staticImportURL = `${pathToFileURL(ret.staticPath).href}?t=${componentImportNonce}`
79
+ const baseUrl = pathToFileURL(ret.staticPath).href
80
+ ret.staticImportURL =
81
+ state.CURRENT_MODE === 'production' ? baseUrl : `${baseUrl}?t=${componentImportNonce}`
79
82
  }
80
83
 
81
84
  return ret
package/src/mdx.js CHANGED
@@ -38,6 +38,7 @@ import { resolveUserMdxConfig, withBase } from './config.js'
38
38
  import { methanolCtx } from './rehype-plugins/methanol-ctx.js'
39
39
  import { linkResolve } from './rehype-plugins/link-resolve.js'
40
40
  import { cached } from './utils.js'
41
+ import { resetReframeRenderCount } from './components.js'
41
42
 
42
43
  // Workaround for Vite: it doesn't support resolving module/virtual modules in script src in dev mode
43
44
  const resolveRewindInject = cached(() =>
@@ -585,6 +586,7 @@ export const compilePageMdx = async (page, pagesContext, options = {}) => {
585
586
  }
586
587
 
587
588
  export const renderHtml = async ({ routePath, path, components, pagesContext, pageMeta }) => {
589
+ resetReframeRenderCount()
588
590
  const ctx = buildPageContext({
589
591
  routePath,
590
592
  path,
package/src/reframe.js CHANGED
@@ -61,10 +61,10 @@ export function env(parentEnv) {
61
61
  } while (keyPathRegistry[key] && keyPathRegistry[key] !== clientPath)
62
62
 
63
63
  const component = async ({ children: childrenProp, ...props }, ...children) => {
64
- const staticComponent = (await import(staticImportURL)).default
65
-
66
64
  const id = renderCount++
67
65
  const idStr = id.toString(16)
66
+
67
+ const staticComponent = (await import(staticImportURL)).default
68
68
  const script = `$$rfrm(${JSON.stringify(key)},${id},${Object.keys(props).length ? JSON5.stringify(props).replace(/<\/script/ig, '<\\/script') : '{}'})`
69
69
 
70
70
  return (R) => {
@@ -101,6 +101,11 @@ export function env(parentEnv) {
101
101
  parent = nextParent || null
102
102
  }
103
103
 
104
+ function resetRenderCount() {
105
+ renderCount = 0
106
+ parent?.resetRenderCount()
107
+ }
108
+
104
109
  function getMergedRegistry() {
105
110
  return Object.assign({}, parent?.registry, registry)
106
111
  }
@@ -117,6 +122,7 @@ export function env(parentEnv) {
117
122
  invalidate,
118
123
  genRegistryScript,
119
124
  setParent,
125
+ resetRenderCount,
120
126
  get registry() {
121
127
  return getMergedRegistry()
122
128
  }
@@ -29,7 +29,7 @@
29
29
  if (savedAccent && savedAccent !== 'default') {
30
30
  document.documentElement.classList.add('accent-' + savedAccent)
31
31
  }
32
- })
32
+ })()
33
33
  ;(function initPrefetch() {
34
34
  const prefetched = new Set()
35
35
  const canPrefetch = (anchor) => {
@@ -58,4 +58,4 @@
58
58
  document.head.appendChild(link)
59
59
  }
60
60
  document.addEventListener('pointerover', onHover, { capture: true, passive: true })
61
- })
61
+ })()