methanol 0.0.8 → 0.0.10
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/README.md +3 -0
- package/index.js +7 -2
- package/package.json +9 -3
- package/src/build-system.js +50 -8
- package/src/client/sw.js +751 -0
- package/src/{assets.js → client/virtual-module/assets.js} +7 -3
- package/src/{virtual-module → client/virtual-module}/inject.js +1 -0
- package/src/{virtual-module → client/virtual-module}/loader.js +5 -5
- package/src/{virtual-module → client/virtual-module}/pagefind-loader.js +1 -1
- package/src/client/virtual-module/pwa-inject.js +25 -0
- package/src/components.js +5 -5
- package/src/config.js +38 -7
- package/src/dev-server.js +64 -66
- package/src/logger.js +84 -0
- package/src/main.js +11 -0
- package/src/mdx.js +33 -38
- package/src/pagefind.js +16 -5
- package/src/pages.js +61 -51
- package/src/public-assets.js +1 -1
- package/src/{rewind.js → reframe.js} +1 -1
- package/src/rehype-plugins/link-resolve.js +2 -2
- package/src/stage-logger.js +10 -6
- package/src/state.js +31 -4
- package/src/utils.js +23 -1
- package/src/vite-plugins.js +17 -4
- package/themes/default/components/ThemeSearchBox.client.jsx +120 -11
- package/themes/default/index.js +2 -2
- package/themes/default/pages/404.mdx +4 -0
- package/themes/default/pages/index.mdx +7 -9
- package/themes/default/pages/offline.mdx +11 -0
- package/themes/default/sources/style.css +248 -169
- package/themes/default/src/nav-tree.jsx +112 -0
- package/themes/default/{page.jsx → src/page.jsx} +10 -55
- /package/themes/default/{heading.jsx → src/heading.jsx} +0 -0
|
@@ -21,10 +21,14 @@
|
|
|
21
21
|
import { readFileSync } from 'fs'
|
|
22
22
|
import { fileURLToPath } from 'url'
|
|
23
23
|
import { dirname, resolve } from 'path'
|
|
24
|
+
import { cached } from '../../utils.js'
|
|
24
25
|
|
|
25
26
|
const __filename = fileURLToPath(import.meta.url)
|
|
26
27
|
const __dirname = dirname(__filename)
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export const
|
|
29
|
+
const readStatic = (filePath) => cached(() => readFileSync(resolve(__dirname, filePath), 'utf-8'))
|
|
30
|
+
|
|
31
|
+
export const INJECT_SCRIPT = readStatic('./inject.js')
|
|
32
|
+
export const LOADER_SCRIPT = readStatic('./loader.js')
|
|
33
|
+
export const PAGEFIND_LOADER_SCRIPT = readStatic('./pagefind-loader.js')
|
|
34
|
+
export const PWA_INJECT_SCRIPT = readStatic('./pwa-inject.js')
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
export function init(registry, R) {
|
|
22
22
|
if (!registry) return
|
|
23
23
|
|
|
24
|
-
async function $$
|
|
24
|
+
async function $$rfrm(key, id, props, target = document.currentScript) {
|
|
25
25
|
const loader = registry[key]
|
|
26
26
|
|
|
27
27
|
if (!loader) {
|
|
@@ -103,14 +103,14 @@ export function init(registry, R) {
|
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
let loaded = []
|
|
106
|
-
if (window.$$
|
|
107
|
-
loaded = window.$$
|
|
106
|
+
if (window.$$rfrm) {
|
|
107
|
+
loaded = window.$$rfrm.$$loaded
|
|
108
108
|
}
|
|
109
|
-
window.$$
|
|
109
|
+
window.$$rfrm = $$rfrm
|
|
110
110
|
|
|
111
111
|
if (loaded) {
|
|
112
112
|
for (let i = 0; i < loaded.length; i++) {
|
|
113
|
-
$$
|
|
113
|
+
$$rfrm.apply(null, loaded[i])
|
|
114
114
|
}
|
|
115
115
|
}
|
|
116
116
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/* Copyright Yukino Song, SudoMaker Ltd.
|
|
2
|
+
*
|
|
3
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
4
|
+
* or more contributor license agreements. See the NOTICE file
|
|
5
|
+
* distributed with this work for additional information
|
|
6
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
7
|
+
* to you under the Apache License, Version 2.0 (the
|
|
8
|
+
* "License"); you may not use this file except in compliance
|
|
9
|
+
* with the License. You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing,
|
|
14
|
+
* software distributed under the License is distributed on an
|
|
15
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
|
+
* KIND, either express or implied. See the License for the
|
|
17
|
+
* specific language governing permissions and limitations
|
|
18
|
+
* under the License.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
if (typeof navigator !== 'undefined' && 'serviceWorker' in navigator) {
|
|
22
|
+
navigator.serviceWorker.ready.then((reg) => {
|
|
23
|
+
reg.active?.postMessage({ type: 'METHANOL_WARM_MANIFEST' });
|
|
24
|
+
});
|
|
25
|
+
}
|
package/src/components.js
CHANGED
|
@@ -22,7 +22,7 @@ import { readdir, stat } from 'fs/promises'
|
|
|
22
22
|
import { existsSync } from 'fs'
|
|
23
23
|
import { join, extname, basename } from 'path'
|
|
24
24
|
import { pathToFileURL } from 'url'
|
|
25
|
-
import { env } from './
|
|
25
|
+
import { env } from './reframe.js'
|
|
26
26
|
import { state } from './state.js'
|
|
27
27
|
|
|
28
28
|
const normalizeComponentName = (value) => basename(value)
|
|
@@ -47,10 +47,10 @@ export const bumpComponentImportNonce = () => {
|
|
|
47
47
|
return componentImportNonce
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
export const
|
|
51
|
-
export const client =
|
|
52
|
-
export const invalidateRegistryEntry =
|
|
53
|
-
export const genRegistryScript =
|
|
50
|
+
export const reframeEnv = env()
|
|
51
|
+
export const client = reframeEnv.client
|
|
52
|
+
export const invalidateRegistryEntry = reframeEnv.invalidate
|
|
53
|
+
export const genRegistryScript = reframeEnv.genRegistryScript
|
|
54
54
|
|
|
55
55
|
const resolveComponentExport = (componentPath, ext) => {
|
|
56
56
|
const staticCandidate = `${componentPath}.static${ext}`
|
package/src/config.js
CHANGED
|
@@ -24,9 +24,10 @@ import { resolve, isAbsolute, extname, basename } from 'path'
|
|
|
24
24
|
import { pathToFileURL } from 'url'
|
|
25
25
|
import { mergeConfig } from 'vite'
|
|
26
26
|
import { cli, state } from './state.js'
|
|
27
|
+
import { logger } from './logger.js'
|
|
27
28
|
import { HTMLRenderer } from './renderer.js'
|
|
28
|
-
import {
|
|
29
|
-
import { env as createEnv } from './
|
|
29
|
+
import { reframeEnv } from './components.js'
|
|
30
|
+
import { env as createEnv } from './reframe.js'
|
|
30
31
|
import { cached, cachedStr } from './utils.js'
|
|
31
32
|
import defaultTheme from '../themes/default/index.js'
|
|
32
33
|
|
|
@@ -123,7 +124,7 @@ const warnDevBase = (value) => {
|
|
|
123
124
|
if (devBaseWarningShown) return
|
|
124
125
|
devBaseWarningShown = true
|
|
125
126
|
const label = value ? ` (received "${value}")` : ''
|
|
126
|
-
|
|
127
|
+
logger.warn(`Methanol: \`base\`${label} is disabled in dev mode due to module resolution inconsistencies in Vite. Using "/".\n`)
|
|
127
128
|
}
|
|
128
129
|
|
|
129
130
|
const hasOwn = (obj, key) => Object.prototype.hasOwnProperty.call(obj || {}, key)
|
|
@@ -264,7 +265,7 @@ export const applyConfig = async (config, mode) => {
|
|
|
264
265
|
const configSiteName = cli.CLI_SITE_NAME ?? config.site?.name ?? null
|
|
265
266
|
state.SITE_NAME = configSiteName || basename(root) || 'Methanol Site'
|
|
266
267
|
const userSite = config.site && typeof config.site === 'object' ? { ...config.site } : null
|
|
267
|
-
const siteBase = normalizeSiteBase(userSite?.base)
|
|
268
|
+
const siteBase = normalizeSiteBase(cli.CLI_BASE || userSite?.base)
|
|
268
269
|
state.SITE_BASE = siteBase
|
|
269
270
|
if (userSite) {
|
|
270
271
|
if (siteBase == null) {
|
|
@@ -323,7 +324,7 @@ export const applyConfig = async (config, mode) => {
|
|
|
323
324
|
}
|
|
324
325
|
const themeEnv = state.USER_THEME.env || createEnv()
|
|
325
326
|
state.THEME_ENV = themeEnv
|
|
326
|
-
|
|
327
|
+
reframeEnv.setParent(themeEnv)
|
|
327
328
|
const themeRoot = state.USER_THEME.root || root
|
|
328
329
|
const themeComponentDirValue = hasOwn(state.USER_THEME, 'componentsDir')
|
|
329
330
|
? state.USER_THEME.componentsDir
|
|
@@ -382,8 +383,27 @@ export const applyConfig = async (config, mode) => {
|
|
|
382
383
|
state.RESOLVED_MDX_CONFIG = undefined
|
|
383
384
|
state.RESOLVED_VITE_CONFIG = undefined
|
|
384
385
|
state.PAGEFIND_ENABLED = resolvePagefindEnabled(config)
|
|
386
|
+
if (cli.CLI_SEARCH !== undefined) {
|
|
387
|
+
state.PAGEFIND_ENABLED = cli.CLI_SEARCH
|
|
388
|
+
}
|
|
385
389
|
state.PAGEFIND_OPTIONS = resolvePagefindOptions(config)
|
|
386
390
|
state.PAGEFIND_BUILD = resolvePagefindBuild(config)
|
|
391
|
+
|
|
392
|
+
if (hasOwn(config, 'pwa')) {
|
|
393
|
+
if (config.pwa === true) {
|
|
394
|
+
state.PWA_ENABLED = true
|
|
395
|
+
state.PWA_OPTIONS = null
|
|
396
|
+
} else if (typeof config.pwa === 'object' && config.pwa !== null) {
|
|
397
|
+
state.PWA_ENABLED = true
|
|
398
|
+
state.PWA_OPTIONS = config.pwa
|
|
399
|
+
} else {
|
|
400
|
+
state.PWA_ENABLED = false
|
|
401
|
+
state.PWA_OPTIONS = null
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
if (cli.CLI_PWA !== undefined) {
|
|
405
|
+
state.PWA_ENABLED = cli.CLI_PWA
|
|
406
|
+
}
|
|
387
407
|
state.USER_PRE_BUILD_HOOKS = normalizeHooks(config.preBuild)
|
|
388
408
|
state.USER_POST_BUILD_HOOKS = normalizeHooks(config.postBuild)
|
|
389
409
|
state.USER_PRE_BUNDLE_HOOKS = normalizeHooks(config.preBundle)
|
|
@@ -392,6 +412,9 @@ export const applyConfig = async (config, mode) => {
|
|
|
392
412
|
state.THEME_POST_BUILD_HOOKS = normalizeHooks(state.USER_THEME?.postBuild)
|
|
393
413
|
state.THEME_PRE_BUNDLE_HOOKS = normalizeHooks(state.USER_THEME?.preBundle)
|
|
394
414
|
state.THEME_POST_BUNDLE_HOOKS = normalizeHooks(state.USER_THEME?.postBundle)
|
|
415
|
+
if (hasOwn(config, 'gfm')) {
|
|
416
|
+
state.GFM_ENABLED = config.gfm !== false
|
|
417
|
+
}
|
|
395
418
|
const starryNight = resolveStarryNightConfig(config.starryNight)
|
|
396
419
|
const cliCodeHighlighting = cli.CLI_CODE_HIGHLIGHTING
|
|
397
420
|
if (cliCodeHighlighting != null) {
|
|
@@ -448,6 +471,7 @@ export const resolveUserViteConfig = async (command) => {
|
|
|
448
471
|
if (state.RESOLVED_VITE_CONFIG !== undefined) {
|
|
449
472
|
return state.RESOLVED_VITE_CONFIG
|
|
450
473
|
}
|
|
474
|
+
|
|
451
475
|
const resolveConfig = async (config) => {
|
|
452
476
|
if (!config) return null
|
|
453
477
|
if (typeof config === 'function') {
|
|
@@ -463,9 +487,10 @@ export const resolveUserViteConfig = async (command) => {
|
|
|
463
487
|
}
|
|
464
488
|
return config || null
|
|
465
489
|
}
|
|
490
|
+
|
|
466
491
|
const themeConfig = await resolveConfig(state.USER_THEME.vite)
|
|
467
492
|
const userConfig = await resolveConfig(state.USER_VITE_CONFIG)
|
|
468
|
-
|
|
493
|
+
|
|
469
494
|
if (!themeConfig && !userConfig) {
|
|
470
495
|
if (state.SITE_BASE) {
|
|
471
496
|
state.RESOLVED_VITE_CONFIG = { base: state.SITE_BASE }
|
|
@@ -484,15 +509,20 @@ export const resolveUserViteConfig = async (command) => {
|
|
|
484
509
|
}
|
|
485
510
|
return state.RESOLVED_VITE_CONFIG
|
|
486
511
|
}
|
|
512
|
+
|
|
487
513
|
state.RESOLVED_VITE_CONFIG = themeConfig
|
|
488
514
|
? userConfig
|
|
489
515
|
? mergeConfig(themeConfig, userConfig)
|
|
490
516
|
: themeConfig
|
|
491
517
|
: userConfig
|
|
492
|
-
|
|
518
|
+
|
|
519
|
+
const userHasBase = userConfig && hasOwn(userConfig, 'base')
|
|
520
|
+
if (state.SITE_BASE && (cli.CLI_BASE || !userHasBase)) {
|
|
493
521
|
state.RESOLVED_VITE_CONFIG.base = state.SITE_BASE
|
|
494
522
|
}
|
|
523
|
+
|
|
495
524
|
state.VITE_BASE = normalizeViteBase(state.RESOLVED_VITE_CONFIG?.base || state.SITE_BASE || '/')
|
|
525
|
+
|
|
496
526
|
if (command === 'serve') {
|
|
497
527
|
if (state.VITE_BASE !== '/' || (state.SITE_BASE && state.SITE_BASE !== '/')) {
|
|
498
528
|
warnDevBase(state.RESOLVED_VITE_CONFIG?.base || state.SITE_BASE || '')
|
|
@@ -500,6 +530,7 @@ export const resolveUserViteConfig = async (command) => {
|
|
|
500
530
|
state.RESOLVED_VITE_CONFIG.base = '/'
|
|
501
531
|
state.VITE_BASE = '/'
|
|
502
532
|
}
|
|
533
|
+
|
|
503
534
|
return state.RESOLVED_VITE_CONFIG
|
|
504
535
|
}
|
|
505
536
|
|
package/src/dev-server.js
CHANGED
|
@@ -104,12 +104,12 @@ export const runViteDev = async () => {
|
|
|
104
104
|
const assetWatcher = chokidar.watch(state.USER_ASSETS_DIR, {
|
|
105
105
|
ignoreInitial: true
|
|
106
106
|
})
|
|
107
|
-
const handleAssetUpdate = (type,
|
|
108
|
-
const relPath = relative(state.USER_ASSETS_DIR,
|
|
107
|
+
const handleAssetUpdate = (type, path) => {
|
|
108
|
+
const relPath = relative(state.USER_ASSETS_DIR, path)
|
|
109
109
|
enqueue(async () => {
|
|
110
110
|
await updateAsset({
|
|
111
111
|
type,
|
|
112
|
-
|
|
112
|
+
path,
|
|
113
113
|
relPath,
|
|
114
114
|
themeDir: state.THEME_ASSETS_DIR,
|
|
115
115
|
userDir: state.USER_ASSETS_DIR,
|
|
@@ -117,9 +117,9 @@ export const runViteDev = async () => {
|
|
|
117
117
|
})
|
|
118
118
|
})
|
|
119
119
|
}
|
|
120
|
-
assetWatcher.on('add', (
|
|
121
|
-
assetWatcher.on('change', (
|
|
122
|
-
assetWatcher.on('unlink', (
|
|
120
|
+
assetWatcher.on('add', (path) => handleAssetUpdate('add', path))
|
|
121
|
+
assetWatcher.on('change', (path) => handleAssetUpdate('change', path))
|
|
122
|
+
assetWatcher.on('unlink', (path) => handleAssetUpdate('unlink', path))
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
const themeComponentsDir = state.THEME_COMPONENTS_DIR
|
|
@@ -289,8 +289,8 @@ export const runViteDev = async () => {
|
|
|
289
289
|
}
|
|
290
290
|
const notFoundPage = pagesContext.pagesByRoute.get('/404')
|
|
291
291
|
let pageMeta = pagesContext.pagesByRoute.get(requestedPath)
|
|
292
|
-
let
|
|
293
|
-
const hasMdx = Boolean(pageMeta) || existsSync(
|
|
292
|
+
let path = pageMeta?.path || resolvePageFile(requestedPath)
|
|
293
|
+
const hasMdx = Boolean(pageMeta) || existsSync(path)
|
|
294
294
|
let status = 200
|
|
295
295
|
let renderRoutePath = requestedPath
|
|
296
296
|
|
|
@@ -326,41 +326,39 @@ export const runViteDev = async () => {
|
|
|
326
326
|
|
|
327
327
|
if (isExcludedPath()) {
|
|
328
328
|
if (notFoundPage) {
|
|
329
|
-
|
|
329
|
+
path = notFoundPage.path
|
|
330
330
|
renderRoutePath = '/404'
|
|
331
331
|
status = 404
|
|
332
332
|
} else {
|
|
333
333
|
return next()
|
|
334
334
|
}
|
|
335
|
-
} else if (
|
|
336
|
-
filePath = notFoundPage.filePath
|
|
337
|
-
renderRoutePath = '/404'
|
|
338
|
-
status = 404
|
|
339
|
-
} else if (!pageMeta && !existsSync(filePath)) {
|
|
335
|
+
} else if (!pageMeta && !existsSync(path)) {
|
|
340
336
|
if (notFoundPage) {
|
|
341
|
-
|
|
337
|
+
path = notFoundPage.path
|
|
342
338
|
renderRoutePath = '/404'
|
|
343
339
|
status = 404
|
|
344
340
|
} else {
|
|
345
341
|
return next()
|
|
346
342
|
}
|
|
343
|
+
} else if (requestedPath.endsWith('/index')) {
|
|
344
|
+
renderRoutePath = requestedPath.slice(0, -5) // remove last 'index'
|
|
347
345
|
}
|
|
348
346
|
|
|
349
347
|
try {
|
|
350
348
|
const renderEpoch = htmlCacheEpoch
|
|
351
349
|
const cacheEntry = htmlCache.get(renderRoutePath)
|
|
352
|
-
if (cacheEntry && cacheEntry.
|
|
350
|
+
if (cacheEntry && cacheEntry.path === path && cacheEntry.epoch === htmlCacheEpoch) {
|
|
353
351
|
res.statusCode = status
|
|
354
352
|
res.setHeader('Content-Type', 'text/html')
|
|
355
353
|
res.end(cacheEntry.html)
|
|
356
354
|
return
|
|
357
355
|
}
|
|
358
356
|
|
|
359
|
-
pageMeta ??= pagesContext.getPageByRoute(renderRoutePath, {
|
|
357
|
+
pageMeta ??= pagesContext.getPageByRoute(renderRoutePath, { path })
|
|
360
358
|
|
|
361
359
|
const html = await renderHtml({
|
|
362
360
|
routePath: renderRoutePath,
|
|
363
|
-
|
|
361
|
+
path,
|
|
364
362
|
components: {
|
|
365
363
|
...themeComponents,
|
|
366
364
|
...components
|
|
@@ -371,7 +369,7 @@ export const runViteDev = async () => {
|
|
|
371
369
|
if (renderEpoch === htmlCacheEpoch) {
|
|
372
370
|
htmlCache.set(renderRoutePath, {
|
|
373
371
|
html,
|
|
374
|
-
|
|
372
|
+
path,
|
|
375
373
|
epoch: renderEpoch
|
|
376
374
|
})
|
|
377
375
|
}
|
|
@@ -427,7 +425,7 @@ export const runViteDev = async () => {
|
|
|
427
425
|
reload()
|
|
428
426
|
}
|
|
429
427
|
|
|
430
|
-
const getExportName = (
|
|
428
|
+
const getExportName = (path) => basename(path).split('.')[0]
|
|
431
429
|
|
|
432
430
|
const findComponentExt = (dir, exportName) => {
|
|
433
431
|
for (const ext of COMPONENT_EXTENSIONS) {
|
|
@@ -442,11 +440,11 @@ export const runViteDev = async () => {
|
|
|
442
440
|
return null
|
|
443
441
|
}
|
|
444
442
|
|
|
445
|
-
const updateComponentEntry = async (
|
|
443
|
+
const updateComponentEntry = async (path, { fallback = false } = {}) => {
|
|
446
444
|
bumpComponentImportNonce()
|
|
447
|
-
const exportName = getExportName(
|
|
448
|
-
const dir = dirname(
|
|
449
|
-
let ext = extname(
|
|
445
|
+
const exportName = getExportName(path)
|
|
446
|
+
const dir = dirname(path)
|
|
447
|
+
let ext = extname(path)
|
|
450
448
|
let { component, hasClient, staticPath } = await buildComponentEntry({
|
|
451
449
|
dir,
|
|
452
450
|
exportName,
|
|
@@ -486,28 +484,28 @@ export const runViteDev = async () => {
|
|
|
486
484
|
const PAGE_UPDATE_DEBOUNCE_MS = 30
|
|
487
485
|
const pageUpdateTimers = new Map()
|
|
488
486
|
|
|
489
|
-
const schedulePageUpdate = (
|
|
490
|
-
const existing = pageUpdateTimers.get(
|
|
487
|
+
const schedulePageUpdate = (path, kind) => {
|
|
488
|
+
const existing = pageUpdateTimers.get(path)
|
|
491
489
|
if (existing?.timer) {
|
|
492
490
|
clearTimeout(existing.timer)
|
|
493
491
|
}
|
|
494
492
|
const entry = {
|
|
495
493
|
kind,
|
|
496
494
|
timer: setTimeout(() => {
|
|
497
|
-
pageUpdateTimers.delete(
|
|
498
|
-
enqueue(() => handlePageUpdate(
|
|
495
|
+
pageUpdateTimers.delete(path)
|
|
496
|
+
enqueue(() => handlePageUpdate(path, kind))
|
|
499
497
|
}, PAGE_UPDATE_DEBOUNCE_MS)
|
|
500
498
|
}
|
|
501
|
-
pageUpdateTimers.set(
|
|
499
|
+
pageUpdateTimers.set(path, entry)
|
|
502
500
|
}
|
|
503
501
|
|
|
504
|
-
const resolveWatchedSource = (
|
|
505
|
-
const inUserPages = routePathFromFile(
|
|
502
|
+
const resolveWatchedSource = (path) => {
|
|
503
|
+
const inUserPages = routePathFromFile(path, state.PAGES_DIR)
|
|
506
504
|
if (inUserPages) {
|
|
507
505
|
return { pagesDir: state.PAGES_DIR, source: 'user', routePath: inUserPages }
|
|
508
506
|
}
|
|
509
507
|
if (state.THEME_PAGES_DIR) {
|
|
510
|
-
const inThemePages = routePathFromFile(
|
|
508
|
+
const inThemePages = routePathFromFile(path, state.THEME_PAGES_DIR)
|
|
511
509
|
if (inThemePages) {
|
|
512
510
|
return { pagesDir: state.THEME_PAGES_DIR, source: 'theme', routePath: inThemePages }
|
|
513
511
|
}
|
|
@@ -515,16 +513,16 @@ export const runViteDev = async () => {
|
|
|
515
513
|
return null
|
|
516
514
|
}
|
|
517
515
|
|
|
518
|
-
const updatePageEntry = async (
|
|
516
|
+
const updatePageEntry = async (path, resolved) => {
|
|
519
517
|
if (!pagesContext || !resolved) return false
|
|
520
|
-
pagesContext.clearDerivedTitle?.(
|
|
518
|
+
pagesContext.clearDerivedTitle?.(path)
|
|
521
519
|
const nextEntry = await buildPageEntry({
|
|
522
|
-
|
|
520
|
+
path,
|
|
523
521
|
pagesDir: resolved.pagesDir,
|
|
524
522
|
source: resolved.source
|
|
525
523
|
})
|
|
526
524
|
if (!nextEntry) return false
|
|
527
|
-
const prevEntry = pagesContext.pages?.find?.((page) => page.
|
|
525
|
+
const prevEntry = pagesContext.pages?.find?.((page) => page.path === path) || null
|
|
528
526
|
if (!prevEntry) return false
|
|
529
527
|
if (prevEntry.exclude !== nextEntry.exclude) return false
|
|
530
528
|
if (prevEntry.isIndex !== nextEntry.isIndex || prevEntry.dir !== nextEntry.dir) return false
|
|
@@ -544,22 +542,22 @@ export const runViteDev = async () => {
|
|
|
544
542
|
return true
|
|
545
543
|
}
|
|
546
544
|
|
|
547
|
-
const isUserHeadAsset = (
|
|
548
|
-
const name = basename(
|
|
545
|
+
const isUserHeadAsset = (path) => {
|
|
546
|
+
const name = basename(path)
|
|
549
547
|
if (name !== 'style.css' && name !== 'index.js' && name !== 'index.ts') {
|
|
550
548
|
return false
|
|
551
549
|
}
|
|
552
550
|
const root = resolve(state.PAGES_DIR || '')
|
|
553
|
-
return root && resolve(dirname(
|
|
551
|
+
return root && resolve(dirname(path)) === root
|
|
554
552
|
}
|
|
555
553
|
|
|
556
|
-
const handlePageUpdate = async (
|
|
557
|
-
if (isUserHeadAsset(
|
|
554
|
+
const handlePageUpdate = async (path, kind) => {
|
|
555
|
+
if (isUserHeadAsset(path)) {
|
|
558
556
|
invalidateHtmlCache()
|
|
559
557
|
reload()
|
|
560
558
|
return
|
|
561
559
|
}
|
|
562
|
-
const resolved = resolveWatchedSource(
|
|
560
|
+
const resolved = resolveWatchedSource(path)
|
|
563
561
|
if (kind === 'unlink') {
|
|
564
562
|
if (resolved?.routePath) {
|
|
565
563
|
htmlCache.delete(resolved.routePath)
|
|
@@ -569,7 +567,7 @@ export const runViteDev = async () => {
|
|
|
569
567
|
await refreshPages()
|
|
570
568
|
return
|
|
571
569
|
}
|
|
572
|
-
const updated = await updatePageEntry(
|
|
570
|
+
const updated = await updatePageEntry(path, resolved)
|
|
573
571
|
if (updated) {
|
|
574
572
|
invalidateHtmlCache()
|
|
575
573
|
reload()
|
|
@@ -581,15 +579,15 @@ export const runViteDev = async () => {
|
|
|
581
579
|
await refreshPages()
|
|
582
580
|
}
|
|
583
581
|
|
|
584
|
-
pageWatcher.on('change', (
|
|
585
|
-
schedulePageUpdate(
|
|
582
|
+
pageWatcher.on('change', (path) => {
|
|
583
|
+
schedulePageUpdate(path, 'change')
|
|
586
584
|
})
|
|
587
585
|
|
|
588
|
-
pageWatcher.on('add', (
|
|
589
|
-
schedulePageUpdate(
|
|
586
|
+
pageWatcher.on('add', (path) => {
|
|
587
|
+
schedulePageUpdate(path, 'add')
|
|
590
588
|
})
|
|
591
|
-
pageWatcher.on('unlink', (
|
|
592
|
-
schedulePageUpdate(
|
|
589
|
+
pageWatcher.on('unlink', (path) => {
|
|
590
|
+
schedulePageUpdate(path, 'unlink')
|
|
593
591
|
})
|
|
594
592
|
pageWatcher.on('addDir', () => {
|
|
595
593
|
enqueue(refreshPages)
|
|
@@ -603,13 +601,13 @@ export const runViteDev = async () => {
|
|
|
603
601
|
ignoreInitial: true
|
|
604
602
|
})
|
|
605
603
|
|
|
606
|
-
componentWatcher.on('add', (
|
|
607
|
-
if (!isComponentFile(
|
|
604
|
+
componentWatcher.on('add', (path) => {
|
|
605
|
+
if (!isComponentFile(path)) {
|
|
608
606
|
return
|
|
609
607
|
}
|
|
610
|
-
if (isClientComponent(
|
|
608
|
+
if (isClientComponent(path)) {
|
|
611
609
|
enqueue(async () => {
|
|
612
|
-
const { hasClient } = await updateComponentEntry(
|
|
610
|
+
const { hasClient } = await updateComponentEntry(path)
|
|
613
611
|
if (hasClient) {
|
|
614
612
|
invalidateRewindInject()
|
|
615
613
|
}
|
|
@@ -619,7 +617,7 @@ export const runViteDev = async () => {
|
|
|
619
617
|
return
|
|
620
618
|
}
|
|
621
619
|
enqueue(async () => {
|
|
622
|
-
const { hasClient } = await updateComponentEntry(
|
|
620
|
+
const { hasClient } = await updateComponentEntry(path)
|
|
623
621
|
invalidateHtmlCache()
|
|
624
622
|
if (hasClient) {
|
|
625
623
|
invalidateRewindInject()
|
|
@@ -628,19 +626,19 @@ export const runViteDev = async () => {
|
|
|
628
626
|
})
|
|
629
627
|
})
|
|
630
628
|
|
|
631
|
-
componentWatcher.on('change', (
|
|
632
|
-
if (!isComponentFile(
|
|
629
|
+
componentWatcher.on('change', (path) => {
|
|
630
|
+
if (!isComponentFile(path)) {
|
|
633
631
|
return
|
|
634
632
|
}
|
|
635
|
-
if (isClientComponent(
|
|
633
|
+
if (isClientComponent(path)) {
|
|
636
634
|
enqueue(async () => {
|
|
637
|
-
await updateComponentEntry(
|
|
635
|
+
await updateComponentEntry(path)
|
|
638
636
|
invalidateHtmlCache()
|
|
639
637
|
})
|
|
640
638
|
return
|
|
641
639
|
}
|
|
642
640
|
enqueue(async () => {
|
|
643
|
-
const { hasClient } = await updateComponentEntry(
|
|
641
|
+
const { hasClient } = await updateComponentEntry(path)
|
|
644
642
|
invalidateHtmlCache()
|
|
645
643
|
if (hasClient) {
|
|
646
644
|
invalidateRewindInject()
|
|
@@ -649,24 +647,24 @@ export const runViteDev = async () => {
|
|
|
649
647
|
})
|
|
650
648
|
})
|
|
651
649
|
|
|
652
|
-
componentWatcher.on('unlink', (
|
|
653
|
-
if (!isComponentFile(
|
|
654
|
-
if (isClientComponent(
|
|
650
|
+
componentWatcher.on('unlink', (path) => {
|
|
651
|
+
if (!isComponentFile(path)) return
|
|
652
|
+
if (isClientComponent(path)) {
|
|
655
653
|
enqueue(async () => {
|
|
656
|
-
await updateComponentEntry(
|
|
654
|
+
await updateComponentEntry(path, { fallback: true })
|
|
657
655
|
invalidateRewindInject()
|
|
658
656
|
invalidateHtmlCache()
|
|
659
657
|
reload()
|
|
660
658
|
})
|
|
661
659
|
return
|
|
662
660
|
}
|
|
663
|
-
const exportName = getExportName(
|
|
661
|
+
const exportName = getExportName(path)
|
|
664
662
|
const currentSource = componentSources.get(exportName)
|
|
665
|
-
if (currentSource && currentSource !==
|
|
663
|
+
if (currentSource && currentSource !== path && existsSync(currentSource)) {
|
|
666
664
|
return
|
|
667
665
|
}
|
|
668
666
|
enqueue(async () => {
|
|
669
|
-
const { hasClient } = await updateComponentEntry(
|
|
667
|
+
const { hasClient } = await updateComponentEntry(path, {
|
|
670
668
|
fallback: true
|
|
671
669
|
})
|
|
672
670
|
invalidateHtmlCache()
|
package/src/logger.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/* Copyright Yukino Song, SudoMaker Ltd.
|
|
2
|
+
*
|
|
3
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
4
|
+
* or more contributor license agreements. See the NOTICE file
|
|
5
|
+
* distributed with this work for additional information
|
|
6
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
7
|
+
* to you under the Apache License, Version 2.0 (the
|
|
8
|
+
* "License"); you may not use this file except in compliance
|
|
9
|
+
* with the License. You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing,
|
|
14
|
+
* software distributed under the License is distributed on an
|
|
15
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
16
|
+
* KIND, either express or implied. See the License for the
|
|
17
|
+
* specific language governing permissions and limitations
|
|
18
|
+
* under the License.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
const supportColor =
|
|
22
|
+
typeof process !== 'undefined' &&
|
|
23
|
+
process.stdout &&
|
|
24
|
+
(process.stdout.isTTY || process.env.FORCE_COLOR)
|
|
25
|
+
|
|
26
|
+
const formatter = (open, close, replace = open) =>
|
|
27
|
+
supportColor
|
|
28
|
+
? (input) => {
|
|
29
|
+
const string = '' + input
|
|
30
|
+
const index = string.indexOf(close, open.length)
|
|
31
|
+
return ~index
|
|
32
|
+
? open + getReplace(string, index, close, replace) + close
|
|
33
|
+
: open + string + close
|
|
34
|
+
}
|
|
35
|
+
: (input) => '' + input
|
|
36
|
+
|
|
37
|
+
const getReplace = (string, index, close, replace) => {
|
|
38
|
+
const head = string.substring(0, index) + replace
|
|
39
|
+
const tail = string.substring(index + close.length)
|
|
40
|
+
const next = tail.indexOf(close)
|
|
41
|
+
return ~next ? head + getReplace(tail, next, close, replace) : head + tail
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const style = {
|
|
45
|
+
reset: formatter('\x1b[0m', '\x1b[0m'),
|
|
46
|
+
bold: formatter('\x1b[1m', '\x1b[22m', '\x1b[22m\x1b[1m'),
|
|
47
|
+
dim: formatter('\x1b[2m', '\x1b[22m', '\x1b[22m\x1b[2m'),
|
|
48
|
+
italic: formatter('\x1b[3m', '\x1b[23m'),
|
|
49
|
+
underline: formatter('\x1b[4m', '\x1b[24m'),
|
|
50
|
+
inverse: formatter('\x1b[7m', '\x1b[27m'),
|
|
51
|
+
hidden: formatter('\x1b[8m', '\x1b[28m'),
|
|
52
|
+
strikethrough: formatter('\x1b[9m', '\x1b[29m'),
|
|
53
|
+
|
|
54
|
+
black: formatter('\x1b[30m', '\x1b[39m'),
|
|
55
|
+
red: formatter('\x1b[31m', '\x1b[39m'),
|
|
56
|
+
green: formatter('\x1b[32m', '\x1b[39m'),
|
|
57
|
+
yellow: formatter('\x1b[33m', '\x1b[39m'),
|
|
58
|
+
blue: formatter('\x1b[34m', '\x1b[39m'),
|
|
59
|
+
magenta: formatter('\x1b[35m', '\x1b[39m'),
|
|
60
|
+
cyan: formatter('\x1b[36m', '\x1b[39m'),
|
|
61
|
+
white: formatter('\x1b[37m', '\x1b[39m'),
|
|
62
|
+
gray: formatter('\x1b[90m', '\x1b[39m'),
|
|
63
|
+
|
|
64
|
+
bgBlack: formatter('\x1b[40m', '\x1b[49m'),
|
|
65
|
+
bgRed: formatter('\x1b[41m', '\x1b[49m'),
|
|
66
|
+
bgGreen: formatter('\x1b[42m', '\x1b[49m'),
|
|
67
|
+
bgYellow: formatter('\x1b[43m', '\x1b[49m'),
|
|
68
|
+
bgBlue: formatter('\x1b[44m', '\x1b[49m'),
|
|
69
|
+
bgMagenta: formatter('\x1b[45m', '\x1b[49m'),
|
|
70
|
+
bgCyan: formatter('\x1b[46m', '\x1b[49m'),
|
|
71
|
+
bgWhite: formatter('\x1b[47m', '\x1b[49m')
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const log = console.log.bind(console)
|
|
75
|
+
const warn = console.warn.bind(console)
|
|
76
|
+
const error = console.error.bind(console)
|
|
77
|
+
|
|
78
|
+
export const logger = {
|
|
79
|
+
info: (msg) => log(`${style.blue('ℹ')} ${msg}`),
|
|
80
|
+
success: (msg) => log(`${style.green('✔')} ${msg}`),
|
|
81
|
+
warn: (msg) => warn(`${style.yellow('⚠')} ${msg}`),
|
|
82
|
+
error: (msg) => error(`${style.red('✖')} ${msg}`),
|
|
83
|
+
dim: (msg) => log(style.dim(msg))
|
|
84
|
+
}
|