packaton 0.0.10 → 0.0.12
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 +1 -1
- package/src/plugins-dev/watcherDev.js +14 -2
- package/src/router.js +23 -9
package/package.json
CHANGED
|
@@ -24,9 +24,21 @@ async function longPollDevChanges() {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
function hotReloadCSS(file) {
|
|
27
|
-
|
|
27
|
+
let link = document.querySelector(`link[href^="${file}"]`)
|
|
28
|
+
|
|
29
|
+
// Fallback: construct relative path based on current pathname
|
|
30
|
+
if (!link) {
|
|
31
|
+
const parts = window.location.pathname.split('/').filter(Boolean)
|
|
32
|
+
if (parts.length > 1)
|
|
33
|
+
parts.pop()
|
|
34
|
+
const urlDir = parts.join('/') + '/'
|
|
35
|
+
const r = file.split(urlDir).pop()
|
|
36
|
+
link = document.querySelector(`link[href^="${r}"]`)
|
|
37
|
+
}
|
|
38
|
+
|
|
28
39
|
if (link) {
|
|
29
|
-
const [url] = link.href.split('?')
|
|
40
|
+
const [url] = link.getAttribute('href').split('?')
|
|
30
41
|
link.href = url + '?' + Date.now()
|
|
31
42
|
}
|
|
32
43
|
}
|
|
44
|
+
|
package/src/router.js
CHANGED
|
@@ -3,6 +3,7 @@ import { readFile } from 'node:fs/promises'
|
|
|
3
3
|
|
|
4
4
|
import { docs } from './app.js'
|
|
5
5
|
import { mimeFor } from './utils/mimes.js'
|
|
6
|
+
import { isDirectory } from './utils/fs-utils.js'
|
|
6
7
|
import { devClientWatcher } from './plugins-dev/WatcherDevClient.js'
|
|
7
8
|
import { sendError, sendJSON, servePartialContent, serveAsset } from './utils/http-response.js'
|
|
8
9
|
|
|
@@ -14,7 +15,6 @@ const API = {
|
|
|
14
15
|
}
|
|
15
16
|
|
|
16
17
|
|
|
17
|
-
|
|
18
18
|
/** @param {Config} config */
|
|
19
19
|
export function router({ srcPath, ignore, mode }) {
|
|
20
20
|
docs.init(srcPath, ignore)
|
|
@@ -24,21 +24,21 @@ export function router({ srcPath, ignore, mode }) {
|
|
|
24
24
|
try {
|
|
25
25
|
if (url === API.watchDev)
|
|
26
26
|
longPollDevHotReload(req, response)
|
|
27
|
-
|
|
27
|
+
|
|
28
28
|
else if (url === WATCHER_DEV)
|
|
29
29
|
serveAsset(response, join(import.meta.dirname, url))
|
|
30
|
-
|
|
30
|
+
|
|
31
31
|
else if (docs.hasRoute(url))
|
|
32
32
|
await serveDocument(response, docs.fileFor(url), isDev)
|
|
33
|
-
|
|
34
|
-
else if (docs.hasRoute(join(url, 'index')))
|
|
33
|
+
|
|
34
|
+
else if (docs.hasRoute(join(url, 'index')))
|
|
35
35
|
await serveDocument(response, docs.fileFor(join(url, 'index')), isDev)
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
else if (req.headers.range)
|
|
38
|
-
await servePartialContent(response, req.headers,
|
|
39
|
-
|
|
38
|
+
await servePartialContent(response, req.headers, resolveUrl(req, srcPath, url))
|
|
39
|
+
|
|
40
40
|
else
|
|
41
|
-
serveAsset(response,
|
|
41
|
+
serveAsset(response, resolveUrl(req, srcPath, url))
|
|
42
42
|
}
|
|
43
43
|
catch (error) {
|
|
44
44
|
sendError(response, error)
|
|
@@ -57,6 +57,20 @@ async function serveDocument(response, file, isDev) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
|
|
60
|
+
function resolveUrl(req, srcPath, url) {
|
|
61
|
+
return join(srcPath, dirFor(req.headers.referer, srcPath), url)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function dirFor(referer = '/', srcPath) {
|
|
65
|
+
if (referer.endsWith('/'))
|
|
66
|
+
return ''
|
|
67
|
+
const p = new URL(referer).pathname
|
|
68
|
+
return isDirectory(join(srcPath, p))
|
|
69
|
+
? p
|
|
70
|
+
: ''
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
60
74
|
const LONG_POLL_SERVER_TIMEOUT = 8000
|
|
61
75
|
|
|
62
76
|
function longPollDevHotReload(req, response) {
|