@mokup/shared 1.1.3 → 2.0.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 +58 -0
- package/dist/chokidar.d.mts +3 -8
- package/dist/chokidar.d.ts +3 -9
- package/dist/chokidar.mjs +2 -1
- package/dist/chunk-_iGcCiPk.mjs +28 -0
- package/dist/config-core-dqVMz7on.d.mts +5 -0
- package/dist/config-core-dqVMz7on.d.ts +5 -0
- package/dist/config-core.d.mts +2 -4
- package/dist/config-core.d.ts +2 -4
- package/dist/config-core.mjs +3 -2
- package/dist/config-utils-DFu0_9tl.d.mts +59 -0
- package/dist/config-utils-DFu0_9tl.d.ts +59 -0
- package/dist/config-utils.d.mts +3 -62
- package/dist/config-utils.d.ts +3 -62
- package/dist/config-utils.mjs +143 -159
- package/dist/define-config-CzB1-X1m.d.mts +20 -0
- package/dist/define-config-CzB1-X1m.d.ts +20 -0
- package/dist/define-config.d.mts +2 -20
- package/dist/define-config.d.ts +2 -20
- package/dist/define-config.mjs +146 -161
- package/dist/diagnostic-types-DqAzUbgn.d.mts +39 -0
- package/dist/diagnostic-types-DqAzUbgn.d.ts +39 -0
- package/dist/diagnostic-types.d.mts +2 -0
- package/dist/diagnostic-types.d.ts +2 -0
- package/dist/diagnostic-types.mjs +29 -0
- package/dist/diagnostics-C3QaEtqE.d.mts +101 -0
- package/dist/diagnostics-C3QaEtqE.d.ts +101 -0
- package/dist/diagnostics.d.mts +2 -0
- package/dist/diagnostics.d.ts +2 -0
- package/dist/diagnostics.mjs +129 -0
- package/dist/hono.d.mts +4 -3
- package/dist/hono.d.ts +4 -3
- package/dist/hono.mjs +4 -3
- package/dist/index-5prVUGOX.d.mts +113 -0
- package/dist/index-5prVUGOX.d.ts +113 -0
- package/dist/index.d.mts +13 -10
- package/dist/index.d.ts +13 -10
- package/dist/index.mjs +13 -18
- package/dist/jsonc-parser.d.mts +1 -1
- package/dist/jsonc-parser.d.ts +1 -1
- package/dist/jsonc-parser.mjs +8 -1
- package/dist/jsonc-utils-_Hs6a39T.d.mts +7 -0
- package/dist/jsonc-utils-_Hs6a39T.d.ts +7 -0
- package/dist/jsonc-utils.d.mts +2 -7
- package/dist/jsonc-utils.d.ts +2 -7
- package/dist/jsonc-utils.mjs +20 -20
- package/dist/load-rules-D_kCpu9I.d.mts +14 -0
- package/dist/load-rules-D_kCpu9I.d.ts +14 -0
- package/dist/load-rules.d.mts +2 -14
- package/dist/load-rules.d.ts +2 -14
- package/dist/load-rules.mjs +16 -34
- package/dist/logger-types-BbqYCr6j.d.mts +50 -0
- package/dist/logger-types-BbqYCr6j.d.ts +50 -0
- package/dist/logger.browser.d.mts +4 -3
- package/dist/logger.browser.d.ts +4 -3
- package/dist/logger.browser.mjs +49 -48
- package/dist/logger.d.mts +4 -3
- package/dist/logger.d.ts +4 -3
- package/dist/logger.mjs +49 -48
- package/dist/{mock-files.d.cts → mock-files-DfGigWmY.d.mts} +5 -5
- package/dist/mock-files-DfGigWmY.d.ts +10 -0
- package/dist/mock-files.d.mts +2 -10
- package/dist/mock-files.d.ts +2 -10
- package/dist/mock-files.mjs +38 -50
- package/dist/{module-loader.d.cts → module-loader-nAQlwo3D.d.mts} +7 -6
- package/dist/module-loader-nAQlwo3D.d.ts +14 -0
- package/dist/module-loader.d.mts +2 -13
- package/dist/module-loader.d.ts +2 -13
- package/dist/module-loader.mjs +60 -69
- package/dist/path-utils.d.mts +3 -2
- package/dist/path-utils.d.ts +3 -2
- package/dist/path-utils.mjs +25 -35
- package/dist/pathe.d.mts +1 -1
- package/dist/pathe.d.ts +1 -1
- package/dist/pathe.mjs +8 -1
- package/dist/playground-grouping.d.mts +6 -6
- package/dist/playground-grouping.d.ts +6 -6
- package/dist/playground-grouping.mjs +57 -77
- package/dist/rolldown.d.mts +37 -0
- package/dist/rolldown.d.ts +37 -0
- package/dist/rolldown.mjs +81 -0
- package/dist/{route-constants.d.cts → route-constants-BUi36iYR.d.mts} +3 -2
- package/dist/route-constants-BUi36iYR.d.ts +8 -0
- package/dist/route-constants.d.mts +2 -7
- package/dist/route-constants.d.ts +2 -7
- package/dist/route-constants.mjs +25 -21
- package/dist/route-utils-BiWFUqo-.d.mts +42 -0
- package/dist/route-utils-BiWFUqo-.d.ts +42 -0
- package/dist/route-utils.d.mts +2 -42
- package/dist/route-utils.d.ts +2 -42
- package/dist/route-utils.mjs +94 -121
- package/dist/scan-utils.d.mts +2 -114
- package/dist/scan-utils.d.ts +2 -114
- package/dist/scan-utils.mjs +14 -25
- package/dist/timing.d.mts +3 -2
- package/dist/timing.d.ts +3 -2
- package/dist/timing.mjs +11 -12
- package/package.json +88 -128
- package/dist/chokidar.cjs +0 -11
- package/dist/chokidar.d.cts +0 -9
- package/dist/config-core.cjs +0 -9
- package/dist/config-core.d.cts +0 -4
- package/dist/config-utils.cjs +0 -179
- package/dist/config-utils.d.cts +0 -62
- package/dist/define-config.cjs +0 -168
- package/dist/define-config.d.cts +0 -20
- package/dist/esbuild.cjs +0 -16
- package/dist/esbuild.d.cts +0 -1
- package/dist/esbuild.d.mts +0 -1
- package/dist/esbuild.d.ts +0 -1
- package/dist/esbuild.mjs +0 -1
- package/dist/hono.cjs +0 -20
- package/dist/hono.d.cts +0 -3
- package/dist/index.cjs +0 -50
- package/dist/index.d.cts +0 -10
- package/dist/jsonc-parser.cjs +0 -16
- package/dist/jsonc-parser.d.cts +0 -1
- package/dist/jsonc-utils.cjs +0 -25
- package/dist/jsonc-utils.d.cts +0 -7
- package/dist/load-rules.cjs +0 -39
- package/dist/load-rules.d.cts +0 -14
- package/dist/logger.browser.cjs +0 -55
- package/dist/logger.browser.d.cts +0 -21
- package/dist/logger.cjs +0 -55
- package/dist/logger.d.cts +0 -21
- package/dist/mock-files.cjs +0 -65
- package/dist/module-loader.cjs +0 -93
- package/dist/path-utils.cjs +0 -57
- package/dist/path-utils.d.cts +0 -7
- package/dist/pathe.cjs +0 -16
- package/dist/pathe.d.cts +0 -1
- package/dist/playground-grouping.cjs +0 -95
- package/dist/playground-grouping.d.cts +0 -12
- package/dist/route-constants.cjs +0 -30
- package/dist/route-utils.cjs +0 -126
- package/dist/route-utils.d.cts +0 -42
- package/dist/scan-utils.cjs +0 -39
- package/dist/scan-utils.d.cts +0 -114
- package/dist/shared/shared.DazgCdsk.d.cts +0 -49
- package/dist/shared/shared.DazgCdsk.d.mts +0 -49
- package/dist/shared/shared.DazgCdsk.d.ts +0 -49
- package/dist/timing.cjs +0 -20
- package/dist/timing.d.cts +0 -4
package/dist/define-config.mjs
CHANGED
|
@@ -1,166 +1,151 @@
|
|
|
1
|
-
import { isPromise, middlewareSymbol } from
|
|
2
|
-
|
|
1
|
+
import { isPromise, middlewareSymbol } from "./config-core.mjs";
|
|
2
|
+
//#region src/define-config.ts
|
|
3
3
|
function normalizeHookError(policy) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
return "warn";
|
|
4
|
+
if (policy === "throw" || policy === "silent") return policy;
|
|
5
|
+
return "warn";
|
|
8
6
|
}
|
|
9
7
|
function createDefineConfig(options) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (isPromise(result)) {
|
|
152
|
-
return result.then(finalize);
|
|
153
|
-
}
|
|
154
|
-
return finalize(result);
|
|
155
|
-
}
|
|
156
|
-
const config = normalizeConfig(input);
|
|
157
|
-
return attachMetadata(config, { pre: [], normal: [], post: [] });
|
|
158
|
-
}
|
|
159
|
-
return {
|
|
160
|
-
defineConfig,
|
|
161
|
-
onBeforeAll,
|
|
162
|
-
onAfterAll
|
|
163
|
-
};
|
|
8
|
+
const contextStack = [];
|
|
9
|
+
function getActiveContext() {
|
|
10
|
+
const context = contextStack.at(-1);
|
|
11
|
+
if (!context) throw new Error("onBeforeAll/onAfterAll must be called inside defineConfig()");
|
|
12
|
+
return context;
|
|
13
|
+
}
|
|
14
|
+
function runWithContext(context, fn) {
|
|
15
|
+
contextStack.push(context);
|
|
16
|
+
try {
|
|
17
|
+
const result = fn();
|
|
18
|
+
if (isPromise(result)) return result.finally(() => {
|
|
19
|
+
contextStack.pop();
|
|
20
|
+
});
|
|
21
|
+
contextStack.pop();
|
|
22
|
+
return result;
|
|
23
|
+
} catch (error) {
|
|
24
|
+
contextStack.pop();
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function reportHookError(error, policy) {
|
|
29
|
+
if (policy === "silent") return;
|
|
30
|
+
if (policy === "warn") console.warn(`${options.logPrefix} defineConfig hook failed:`, error);
|
|
31
|
+
}
|
|
32
|
+
function runHookSequence(stage, hooks, policy, setStage) {
|
|
33
|
+
if (hooks.length === 0) return;
|
|
34
|
+
setStage(stage);
|
|
35
|
+
let chain = null;
|
|
36
|
+
const runHook = (hook) => {
|
|
37
|
+
try {
|
|
38
|
+
const result = hook();
|
|
39
|
+
if (isPromise(result)) return result.catch((error) => {
|
|
40
|
+
if (policy === "throw") throw error;
|
|
41
|
+
reportHookError(error, policy);
|
|
42
|
+
});
|
|
43
|
+
return;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (policy === "throw") throw error;
|
|
46
|
+
reportHookError(error, policy);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
for (const hook of hooks) {
|
|
51
|
+
if (chain) {
|
|
52
|
+
chain = chain.then(() => runHook(hook));
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
const result = runHook(hook);
|
|
56
|
+
if (isPromise(result)) chain = result;
|
|
57
|
+
}
|
|
58
|
+
if (!chain) {
|
|
59
|
+
setStage("normal");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
return chain.finally(() => {
|
|
63
|
+
setStage("normal");
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
function attachMetadata(config, meta) {
|
|
67
|
+
Object.defineProperty(config, middlewareSymbol, {
|
|
68
|
+
value: meta,
|
|
69
|
+
enumerable: false
|
|
70
|
+
});
|
|
71
|
+
return config;
|
|
72
|
+
}
|
|
73
|
+
function normalizeConfig(value) {
|
|
74
|
+
return value && typeof value === "object" ? value : {};
|
|
75
|
+
}
|
|
76
|
+
function onBeforeAll(handler) {
|
|
77
|
+
if (typeof handler !== "function") throw new TypeError("onBeforeAll expects a function");
|
|
78
|
+
getActiveContext().hooks.pre.push(handler);
|
|
79
|
+
}
|
|
80
|
+
function onAfterAll(handler) {
|
|
81
|
+
if (typeof handler !== "function") throw new TypeError("onAfterAll expects a function");
|
|
82
|
+
getActiveContext().hooks.post.push(handler);
|
|
83
|
+
}
|
|
84
|
+
function defineConfig(input) {
|
|
85
|
+
if (typeof input === "function") {
|
|
86
|
+
const pre = [];
|
|
87
|
+
const normal = [];
|
|
88
|
+
const post = [];
|
|
89
|
+
let stage = "normal";
|
|
90
|
+
const app = { use: (...handlers) => {
|
|
91
|
+
if (stage === "pre") {
|
|
92
|
+
pre.push(...handlers);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (stage === "post") {
|
|
96
|
+
post.push(...handlers);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
normal.push(...handlers);
|
|
100
|
+
} };
|
|
101
|
+
const context = {
|
|
102
|
+
app,
|
|
103
|
+
hooks: {
|
|
104
|
+
pre: [],
|
|
105
|
+
post: []
|
|
106
|
+
},
|
|
107
|
+
setStage: (next) => {
|
|
108
|
+
stage = next;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
const result = runWithContext(context, () => input({ app }));
|
|
112
|
+
const finalize = (value) => {
|
|
113
|
+
const config = normalizeConfig(value);
|
|
114
|
+
const policy = normalizeHookError(config.hookError);
|
|
115
|
+
const preResult = runHookSequence("pre", context.hooks.pre, policy, context.setStage);
|
|
116
|
+
const runPost = () => runHookSequence("post", context.hooks.post, policy, context.setStage);
|
|
117
|
+
if (isPromise(preResult)) return preResult.then(runPost).then(() => attachMetadata(config, {
|
|
118
|
+
pre,
|
|
119
|
+
normal,
|
|
120
|
+
post
|
|
121
|
+
}));
|
|
122
|
+
const postResult = runPost();
|
|
123
|
+
if (isPromise(postResult)) return postResult.then(() => attachMetadata(config, {
|
|
124
|
+
pre,
|
|
125
|
+
normal,
|
|
126
|
+
post
|
|
127
|
+
}));
|
|
128
|
+
return attachMetadata(config, {
|
|
129
|
+
pre,
|
|
130
|
+
normal,
|
|
131
|
+
post
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
const isConfigPromise = (value) => isPromise(value);
|
|
135
|
+
if (isConfigPromise(result)) return result.then(finalize);
|
|
136
|
+
return finalize(result);
|
|
137
|
+
}
|
|
138
|
+
return attachMetadata(normalizeConfig(input), {
|
|
139
|
+
pre: [],
|
|
140
|
+
normal: [],
|
|
141
|
+
post: []
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return {
|
|
145
|
+
defineConfig,
|
|
146
|
+
onBeforeAll,
|
|
147
|
+
onAfterAll
|
|
148
|
+
};
|
|
164
149
|
}
|
|
165
|
-
|
|
150
|
+
//#endregion
|
|
166
151
|
export { createDefineConfig };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/diagnostic-types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Shared diagnostic categories emitted during mokup route scanning.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* import type { DiagnosticCategory } from '@mokup/shared'
|
|
7
|
+
*
|
|
8
|
+
* const category: DiagnosticCategory = 'invalid-route'
|
|
9
|
+
*/
|
|
10
|
+
type DiagnosticCategory = 'invalid-route' | 'unsupported-fields' | 'missing-handler' | 'duplicate-route' | 'sw-conflict';
|
|
11
|
+
/**
|
|
12
|
+
* Ordered list of all supported diagnostic categories.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { diagnosticCategories } from '@mokup/shared'
|
|
16
|
+
*
|
|
17
|
+
* diagnosticCategories.includes('invalid-route')
|
|
18
|
+
*/
|
|
19
|
+
declare const diagnosticCategories: readonly ["invalid-route", "unsupported-fields", "missing-handler", "duplicate-route", "sw-conflict"];
|
|
20
|
+
/**
|
|
21
|
+
* Runtime guard for supported diagnostic categories.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* import { isDiagnosticCategory } from '@mokup/shared'
|
|
25
|
+
*
|
|
26
|
+
* isDiagnosticCategory('invalid-route')
|
|
27
|
+
*/
|
|
28
|
+
declare function isDiagnosticCategory(value: string): value is DiagnosticCategory;
|
|
29
|
+
/**
|
|
30
|
+
* Controls which diagnostics should fail instead of warn.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* import type { DiagnosticErrorMode } from '@mokup/shared'
|
|
34
|
+
*
|
|
35
|
+
* const errorOn: DiagnosticErrorMode = ['invalid-route']
|
|
36
|
+
*/
|
|
37
|
+
type DiagnosticErrorMode = 'all' | DiagnosticCategory[];
|
|
38
|
+
//#endregion
|
|
39
|
+
export { isDiagnosticCategory as i, DiagnosticErrorMode as n, diagnosticCategories as r, DiagnosticCategory as t };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/diagnostic-types.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Shared diagnostic categories emitted during mokup route scanning.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* import type { DiagnosticCategory } from '@mokup/shared'
|
|
7
|
+
*
|
|
8
|
+
* const category: DiagnosticCategory = 'invalid-route'
|
|
9
|
+
*/
|
|
10
|
+
type DiagnosticCategory = 'invalid-route' | 'unsupported-fields' | 'missing-handler' | 'duplicate-route' | 'sw-conflict';
|
|
11
|
+
/**
|
|
12
|
+
* Ordered list of all supported diagnostic categories.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* import { diagnosticCategories } from '@mokup/shared'
|
|
16
|
+
*
|
|
17
|
+
* diagnosticCategories.includes('invalid-route')
|
|
18
|
+
*/
|
|
19
|
+
declare const diagnosticCategories: readonly ["invalid-route", "unsupported-fields", "missing-handler", "duplicate-route", "sw-conflict"];
|
|
20
|
+
/**
|
|
21
|
+
* Runtime guard for supported diagnostic categories.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* import { isDiagnosticCategory } from '@mokup/shared'
|
|
25
|
+
*
|
|
26
|
+
* isDiagnosticCategory('invalid-route')
|
|
27
|
+
*/
|
|
28
|
+
declare function isDiagnosticCategory(value: string): value is DiagnosticCategory;
|
|
29
|
+
/**
|
|
30
|
+
* Controls which diagnostics should fail instead of warn.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* import type { DiagnosticErrorMode } from '@mokup/shared'
|
|
34
|
+
*
|
|
35
|
+
* const errorOn: DiagnosticErrorMode = ['invalid-route']
|
|
36
|
+
*/
|
|
37
|
+
type DiagnosticErrorMode = 'all' | DiagnosticCategory[];
|
|
38
|
+
//#endregion
|
|
39
|
+
export { isDiagnosticCategory as i, DiagnosticErrorMode as n, diagnosticCategories as r, DiagnosticCategory as t };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/diagnostic-types.ts
|
|
2
|
+
/**
|
|
3
|
+
* Ordered list of all supported diagnostic categories.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* import { diagnosticCategories } from '@mokup/shared'
|
|
7
|
+
*
|
|
8
|
+
* diagnosticCategories.includes('invalid-route')
|
|
9
|
+
*/
|
|
10
|
+
const diagnosticCategories = [
|
|
11
|
+
"invalid-route",
|
|
12
|
+
"unsupported-fields",
|
|
13
|
+
"missing-handler",
|
|
14
|
+
"duplicate-route",
|
|
15
|
+
"sw-conflict"
|
|
16
|
+
];
|
|
17
|
+
/**
|
|
18
|
+
* Runtime guard for supported diagnostic categories.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* import { isDiagnosticCategory } from '@mokup/shared'
|
|
22
|
+
*
|
|
23
|
+
* isDiagnosticCategory('invalid-route')
|
|
24
|
+
*/
|
|
25
|
+
function isDiagnosticCategory(value) {
|
|
26
|
+
return diagnosticCategories.includes(value);
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { diagnosticCategories, isDiagnosticCategory };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
//#region src/diagnostics.d.ts
|
|
2
|
+
interface DiagnosticSummarySection<TCategory extends string = string> {
|
|
3
|
+
category?: TCategory;
|
|
4
|
+
label: string;
|
|
5
|
+
items?: string[];
|
|
6
|
+
count?: number;
|
|
7
|
+
advice?: string;
|
|
8
|
+
}
|
|
9
|
+
declare const routeDiagnosticCatalog: {
|
|
10
|
+
readonly invalidRoute: {
|
|
11
|
+
readonly category: "invalid-route";
|
|
12
|
+
readonly label: "invalid route files ignored";
|
|
13
|
+
readonly advice: "Add a method suffix like .get.ts and avoid unsupported route group segments.";
|
|
14
|
+
};
|
|
15
|
+
readonly unsupportedFields: {
|
|
16
|
+
readonly category: "unsupported-fields";
|
|
17
|
+
readonly label: "routes skipped for unsupported rule fields";
|
|
18
|
+
readonly advice: "Use handler, headers, status, and delay in route rules; do not use legacy response, url, or method fields.";
|
|
19
|
+
};
|
|
20
|
+
readonly missingHandler: {
|
|
21
|
+
readonly category: "missing-handler";
|
|
22
|
+
readonly label: "routes skipped without handler";
|
|
23
|
+
readonly advice: "Export a handler value or function for every enabled rule.";
|
|
24
|
+
};
|
|
25
|
+
readonly duplicateRoute: {
|
|
26
|
+
readonly category: "duplicate-route";
|
|
27
|
+
readonly label: "duplicate route definitions";
|
|
28
|
+
readonly advice: "Keep each method + route path unique across scanned files.";
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
declare const swConflictDiagnostic: {
|
|
32
|
+
readonly category: "sw-conflict";
|
|
33
|
+
readonly label: "service worker config conflicts";
|
|
34
|
+
readonly advice: "Align sw.path, sw.scope, sw.register, and sw.unregister across entries that use SW mode.";
|
|
35
|
+
};
|
|
36
|
+
declare function collectSwConflictDiagnosticWarning(params: {
|
|
37
|
+
message: string;
|
|
38
|
+
onConflict?: (value: string) => void;
|
|
39
|
+
}): boolean;
|
|
40
|
+
declare function collectRouteDiagnosticWarning(params: {
|
|
41
|
+
message: string;
|
|
42
|
+
onUnsupportedFields?: (value: string) => void;
|
|
43
|
+
onMissingHandler?: (value: string) => void;
|
|
44
|
+
onDuplicateRoute?: (value: string) => void;
|
|
45
|
+
}): void;
|
|
46
|
+
declare function createRouteDiagnosticSections(params: {
|
|
47
|
+
invalidRoutes?: string[];
|
|
48
|
+
unsupportedFields?: string[];
|
|
49
|
+
missingHandlers?: string[];
|
|
50
|
+
duplicateRoutes?: string[];
|
|
51
|
+
}): ({
|
|
52
|
+
items: string[];
|
|
53
|
+
category: "invalid-route";
|
|
54
|
+
label: "invalid route files ignored";
|
|
55
|
+
advice: "Add a method suffix like .get.ts and avoid unsupported route group segments.";
|
|
56
|
+
} | {
|
|
57
|
+
items: string[];
|
|
58
|
+
category: "unsupported-fields";
|
|
59
|
+
label: "routes skipped for unsupported rule fields";
|
|
60
|
+
advice: "Use handler, headers, status, and delay in route rules; do not use legacy response, url, or method fields.";
|
|
61
|
+
} | {
|
|
62
|
+
items: string[];
|
|
63
|
+
category: "missing-handler";
|
|
64
|
+
label: "routes skipped without handler";
|
|
65
|
+
advice: "Export a handler value or function for every enabled rule.";
|
|
66
|
+
} | {
|
|
67
|
+
items: string[];
|
|
68
|
+
category: "duplicate-route";
|
|
69
|
+
label: "duplicate route definitions";
|
|
70
|
+
advice: "Keep each method + route path unique across scanned files.";
|
|
71
|
+
})[];
|
|
72
|
+
declare function createSwConflictDiagnosticSections(messages?: string[]): {
|
|
73
|
+
items: string[];
|
|
74
|
+
category: "sw-conflict";
|
|
75
|
+
label: "service worker config conflicts";
|
|
76
|
+
advice: "Align sw.path, sw.scope, sw.register, and sw.unregister across entries that use SW mode.";
|
|
77
|
+
}[];
|
|
78
|
+
declare function buildDiagnosticSummaryLines<TCategory extends string>(params: {
|
|
79
|
+
title?: string;
|
|
80
|
+
sections: DiagnosticSummarySection<TCategory>[];
|
|
81
|
+
maxItems?: number;
|
|
82
|
+
}): string[];
|
|
83
|
+
declare function createDiagnosticError<TCategory extends string>(params: {
|
|
84
|
+
errorOn?: 'all' | TCategory[];
|
|
85
|
+
sections: DiagnosticSummarySection<TCategory>[];
|
|
86
|
+
title?: string;
|
|
87
|
+
maxItems?: number;
|
|
88
|
+
}): Error | null;
|
|
89
|
+
declare function reportDiagnostics<TCategory extends string>(params: {
|
|
90
|
+
errorOn?: 'all' | TCategory[];
|
|
91
|
+
sections: DiagnosticSummarySection<TCategory>[];
|
|
92
|
+
title?: string;
|
|
93
|
+
errorTitle?: string;
|
|
94
|
+
maxItems?: number;
|
|
95
|
+
warn?: (message: string) => void;
|
|
96
|
+
}): {
|
|
97
|
+
summaryLines: string[];
|
|
98
|
+
error: Error | null;
|
|
99
|
+
};
|
|
100
|
+
//#endregion
|
|
101
|
+
export { createDiagnosticError as a, reportDiagnostics as c, collectSwConflictDiagnosticWarning as i, routeDiagnosticCatalog as l, buildDiagnosticSummaryLines as n, createRouteDiagnosticSections as o, collectRouteDiagnosticWarning as r, createSwConflictDiagnosticSections as s, DiagnosticSummarySection as t, swConflictDiagnostic as u };
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
//#region src/diagnostics.d.ts
|
|
2
|
+
interface DiagnosticSummarySection<TCategory extends string = string> {
|
|
3
|
+
category?: TCategory;
|
|
4
|
+
label: string;
|
|
5
|
+
items?: string[];
|
|
6
|
+
count?: number;
|
|
7
|
+
advice?: string;
|
|
8
|
+
}
|
|
9
|
+
declare const routeDiagnosticCatalog: {
|
|
10
|
+
readonly invalidRoute: {
|
|
11
|
+
readonly category: "invalid-route";
|
|
12
|
+
readonly label: "invalid route files ignored";
|
|
13
|
+
readonly advice: "Add a method suffix like .get.ts and avoid unsupported route group segments.";
|
|
14
|
+
};
|
|
15
|
+
readonly unsupportedFields: {
|
|
16
|
+
readonly category: "unsupported-fields";
|
|
17
|
+
readonly label: "routes skipped for unsupported rule fields";
|
|
18
|
+
readonly advice: "Use handler, headers, status, and delay in route rules; do not use legacy response, url, or method fields.";
|
|
19
|
+
};
|
|
20
|
+
readonly missingHandler: {
|
|
21
|
+
readonly category: "missing-handler";
|
|
22
|
+
readonly label: "routes skipped without handler";
|
|
23
|
+
readonly advice: "Export a handler value or function for every enabled rule.";
|
|
24
|
+
};
|
|
25
|
+
readonly duplicateRoute: {
|
|
26
|
+
readonly category: "duplicate-route";
|
|
27
|
+
readonly label: "duplicate route definitions";
|
|
28
|
+
readonly advice: "Keep each method + route path unique across scanned files.";
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
declare const swConflictDiagnostic: {
|
|
32
|
+
readonly category: "sw-conflict";
|
|
33
|
+
readonly label: "service worker config conflicts";
|
|
34
|
+
readonly advice: "Align sw.path, sw.scope, sw.register, and sw.unregister across entries that use SW mode.";
|
|
35
|
+
};
|
|
36
|
+
declare function collectSwConflictDiagnosticWarning(params: {
|
|
37
|
+
message: string;
|
|
38
|
+
onConflict?: (value: string) => void;
|
|
39
|
+
}): boolean;
|
|
40
|
+
declare function collectRouteDiagnosticWarning(params: {
|
|
41
|
+
message: string;
|
|
42
|
+
onUnsupportedFields?: (value: string) => void;
|
|
43
|
+
onMissingHandler?: (value: string) => void;
|
|
44
|
+
onDuplicateRoute?: (value: string) => void;
|
|
45
|
+
}): void;
|
|
46
|
+
declare function createRouteDiagnosticSections(params: {
|
|
47
|
+
invalidRoutes?: string[];
|
|
48
|
+
unsupportedFields?: string[];
|
|
49
|
+
missingHandlers?: string[];
|
|
50
|
+
duplicateRoutes?: string[];
|
|
51
|
+
}): ({
|
|
52
|
+
items: string[];
|
|
53
|
+
category: "invalid-route";
|
|
54
|
+
label: "invalid route files ignored";
|
|
55
|
+
advice: "Add a method suffix like .get.ts and avoid unsupported route group segments.";
|
|
56
|
+
} | {
|
|
57
|
+
items: string[];
|
|
58
|
+
category: "unsupported-fields";
|
|
59
|
+
label: "routes skipped for unsupported rule fields";
|
|
60
|
+
advice: "Use handler, headers, status, and delay in route rules; do not use legacy response, url, or method fields.";
|
|
61
|
+
} | {
|
|
62
|
+
items: string[];
|
|
63
|
+
category: "missing-handler";
|
|
64
|
+
label: "routes skipped without handler";
|
|
65
|
+
advice: "Export a handler value or function for every enabled rule.";
|
|
66
|
+
} | {
|
|
67
|
+
items: string[];
|
|
68
|
+
category: "duplicate-route";
|
|
69
|
+
label: "duplicate route definitions";
|
|
70
|
+
advice: "Keep each method + route path unique across scanned files.";
|
|
71
|
+
})[];
|
|
72
|
+
declare function createSwConflictDiagnosticSections(messages?: string[]): {
|
|
73
|
+
items: string[];
|
|
74
|
+
category: "sw-conflict";
|
|
75
|
+
label: "service worker config conflicts";
|
|
76
|
+
advice: "Align sw.path, sw.scope, sw.register, and sw.unregister across entries that use SW mode.";
|
|
77
|
+
}[];
|
|
78
|
+
declare function buildDiagnosticSummaryLines<TCategory extends string>(params: {
|
|
79
|
+
title?: string;
|
|
80
|
+
sections: DiagnosticSummarySection<TCategory>[];
|
|
81
|
+
maxItems?: number;
|
|
82
|
+
}): string[];
|
|
83
|
+
declare function createDiagnosticError<TCategory extends string>(params: {
|
|
84
|
+
errorOn?: 'all' | TCategory[];
|
|
85
|
+
sections: DiagnosticSummarySection<TCategory>[];
|
|
86
|
+
title?: string;
|
|
87
|
+
maxItems?: number;
|
|
88
|
+
}): Error | null;
|
|
89
|
+
declare function reportDiagnostics<TCategory extends string>(params: {
|
|
90
|
+
errorOn?: 'all' | TCategory[];
|
|
91
|
+
sections: DiagnosticSummarySection<TCategory>[];
|
|
92
|
+
title?: string;
|
|
93
|
+
errorTitle?: string;
|
|
94
|
+
maxItems?: number;
|
|
95
|
+
warn?: (message: string) => void;
|
|
96
|
+
}): {
|
|
97
|
+
summaryLines: string[];
|
|
98
|
+
error: Error | null;
|
|
99
|
+
};
|
|
100
|
+
//#endregion
|
|
101
|
+
export { createDiagnosticError as a, reportDiagnostics as c, collectSwConflictDiagnosticWarning as i, routeDiagnosticCatalog as l, buildDiagnosticSummaryLines as n, createRouteDiagnosticSections as o, collectRouteDiagnosticWarning as r, createSwConflictDiagnosticSections as s, DiagnosticSummarySection as t, swConflictDiagnostic as u };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as createDiagnosticError, c as reportDiagnostics, i as collectSwConflictDiagnosticWarning, l as routeDiagnosticCatalog, n as buildDiagnosticSummaryLines, o as createRouteDiagnosticSections, r as collectRouteDiagnosticWarning, s as createSwConflictDiagnosticSections, t as DiagnosticSummarySection, u as swConflictDiagnostic } from "./diagnostics-C3QaEtqE.mjs";
|
|
2
|
+
export { DiagnosticSummarySection, buildDiagnosticSummaryLines, collectRouteDiagnosticWarning, collectSwConflictDiagnosticWarning, createDiagnosticError, createRouteDiagnosticSections, createSwConflictDiagnosticSections, reportDiagnostics, routeDiagnosticCatalog, swConflictDiagnostic };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as createDiagnosticError, c as reportDiagnostics, i as collectSwConflictDiagnosticWarning, l as routeDiagnosticCatalog, n as buildDiagnosticSummaryLines, o as createRouteDiagnosticSections, r as collectRouteDiagnosticWarning, s as createSwConflictDiagnosticSections, t as DiagnosticSummarySection, u as swConflictDiagnostic } from "./diagnostics-C3QaEtqE.mjs";
|
|
2
|
+
export { DiagnosticSummarySection, buildDiagnosticSummaryLines, collectRouteDiagnosticWarning, collectSwConflictDiagnosticWarning, createDiagnosticError, createRouteDiagnosticSections, createSwConflictDiagnosticSections, reportDiagnostics, routeDiagnosticCatalog, swConflictDiagnostic };
|