@ywal123456/jskim 0.3.0 → 0.4.0
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 +11 -4
- package/docs/configuration.md +6 -1
- package/docs/create-jskim.md +3 -3
- package/package.json +1 -1
- package/scripts/commands/path-display.js +1 -15
- package/scripts/lib/classify-reload.js +131 -0
- package/scripts/lib/create-live-reload.js +422 -32
- package/scripts/lib/create-nunjucks-env.js +2 -1
- package/scripts/lib/create-project-watcher.js +10 -3
- package/scripts/lib/create-watch-runtime.js +39 -7
- package/scripts/lib/format-diagnostic.js +234 -0
- package/scripts/lib/load-config.js +6 -4
- package/scripts/lib/process-files.js +73 -29
- package/scripts/lib/render-pages.js +23 -13
- package/scripts/lib/resolve-project.js +57 -32
- package/scripts/lib/stylesheet-reload.js +58 -0
- package/scripts/lib/to-display-path.js +28 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const CSS_CACHE_PARAM = '_jskim';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* same-origin の stylesheet URL かどうかを判定します。
|
|
7
|
+
* browser runtime へ Function#toString で埋め込むため、外部クロージャに依存しません。
|
|
8
|
+
*
|
|
9
|
+
* @param {string} href
|
|
10
|
+
* @param {string} pageOrigin location.origin または location.href
|
|
11
|
+
* @returns {boolean}
|
|
12
|
+
*/
|
|
13
|
+
function isSameOriginStylesheetHref(href, pageOrigin) {
|
|
14
|
+
if (!href || typeof href !== 'string') {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
const trimmed = href.trim();
|
|
18
|
+
if (!trimmed || trimmed.startsWith('data:')) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
try {
|
|
23
|
+
const resolved = new URL(trimmed, pageOrigin);
|
|
24
|
+
const origin = new URL(pageOrigin);
|
|
25
|
+
return resolved.origin === origin.origin;
|
|
26
|
+
} catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* cache-busting query を付与または更新します。hash と他 query は維持します。
|
|
33
|
+
* browser runtime へ Function#toString で埋め込むため、パラメータ名はリテラルです。
|
|
34
|
+
*
|
|
35
|
+
* @param {string} href
|
|
36
|
+
* @param {string} pageOrigin
|
|
37
|
+
* @param {string|number} token
|
|
38
|
+
* @returns {string|null}
|
|
39
|
+
*/
|
|
40
|
+
function appendCacheBustParam(href, pageOrigin, token) {
|
|
41
|
+
if (!isSameOriginStylesheetHref(href, pageOrigin)) {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
const url = new URL(href, pageOrigin);
|
|
47
|
+
url.searchParams.set('_jskim', String(token));
|
|
48
|
+
return `${url.pathname}${url.search}${url.hash}`;
|
|
49
|
+
} catch {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = {
|
|
55
|
+
CSS_CACHE_PARAM,
|
|
56
|
+
isSameOriginStylesheetHref,
|
|
57
|
+
appendCacheBustParam,
|
|
58
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const path = require('node:path');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ワークスペース相対の表示用パスへ変換します。
|
|
7
|
+
* @param {string} abs
|
|
8
|
+
* @param {string} workspaceRoot
|
|
9
|
+
* @returns {string}
|
|
10
|
+
*/
|
|
11
|
+
function toDisplayPath(abs, workspaceRoot) {
|
|
12
|
+
if (!abs) {
|
|
13
|
+
return '';
|
|
14
|
+
}
|
|
15
|
+
const resolved = path.resolve(abs);
|
|
16
|
+
if (!workspaceRoot) {
|
|
17
|
+
return resolved.split(path.sep).join('/');
|
|
18
|
+
}
|
|
19
|
+
const rel = path.relative(workspaceRoot, resolved);
|
|
20
|
+
if (!rel || rel.startsWith('..') || path.isAbsolute(rel)) {
|
|
21
|
+
return resolved.split(path.sep).join('/');
|
|
22
|
+
}
|
|
23
|
+
return rel.split(path.sep).join('/');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = {
|
|
27
|
+
toDisplayPath,
|
|
28
|
+
};
|