@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
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
//#region src/diagnostics.ts
|
|
2
|
+
const routeDiagnosticCatalog = {
|
|
3
|
+
invalidRoute: {
|
|
4
|
+
category: "invalid-route",
|
|
5
|
+
label: "invalid route files ignored",
|
|
6
|
+
advice: "Add a method suffix like .get.ts and avoid unsupported route group segments."
|
|
7
|
+
},
|
|
8
|
+
unsupportedFields: {
|
|
9
|
+
category: "unsupported-fields",
|
|
10
|
+
label: "routes skipped for unsupported rule fields",
|
|
11
|
+
advice: "Use handler, headers, status, and delay in route rules; do not use legacy response, url, or method fields."
|
|
12
|
+
},
|
|
13
|
+
missingHandler: {
|
|
14
|
+
category: "missing-handler",
|
|
15
|
+
label: "routes skipped without handler",
|
|
16
|
+
advice: "Export a handler value or function for every enabled rule."
|
|
17
|
+
},
|
|
18
|
+
duplicateRoute: {
|
|
19
|
+
category: "duplicate-route",
|
|
20
|
+
label: "duplicate route definitions",
|
|
21
|
+
advice: "Keep each method + route path unique across scanned files."
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const swConflictDiagnostic = {
|
|
25
|
+
category: "sw-conflict",
|
|
26
|
+
label: "service worker config conflicts",
|
|
27
|
+
advice: "Align sw.path, sw.scope, sw.register, and sw.unregister across entries that use SW mode."
|
|
28
|
+
};
|
|
29
|
+
const unsupportedFieldsWarningRE = /^Skip mock with unsupported fields .*: (.+)$/;
|
|
30
|
+
const missingHandlerWarningRE = /^Skip mock without handler: (.+)$/;
|
|
31
|
+
const duplicateRouteWarningRE = /^Duplicate mock route (.+) from .+$/;
|
|
32
|
+
function collectSwConflictDiagnosticWarning(params) {
|
|
33
|
+
if (!params.message.startsWith("SW ")) return false;
|
|
34
|
+
params.onConflict?.(params.message);
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
function collectRouteDiagnosticWarning(params) {
|
|
38
|
+
const unsupportedMatch = params.message.match(unsupportedFieldsWarningRE);
|
|
39
|
+
if (unsupportedMatch?.[1]) params.onUnsupportedFields?.(unsupportedMatch[1]);
|
|
40
|
+
const missingHandlerMatch = params.message.match(missingHandlerWarningRE);
|
|
41
|
+
if (missingHandlerMatch?.[1]) params.onMissingHandler?.(missingHandlerMatch[1]);
|
|
42
|
+
const duplicateRouteMatch = params.message.match(duplicateRouteWarningRE);
|
|
43
|
+
if (duplicateRouteMatch?.[1]) params.onDuplicateRoute?.(duplicateRouteMatch[1]);
|
|
44
|
+
}
|
|
45
|
+
function createRouteDiagnosticSections(params) {
|
|
46
|
+
return [
|
|
47
|
+
{
|
|
48
|
+
...routeDiagnosticCatalog.invalidRoute,
|
|
49
|
+
items: params.invalidRoutes ?? []
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
...routeDiagnosticCatalog.unsupportedFields,
|
|
53
|
+
items: params.unsupportedFields ?? []
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
...routeDiagnosticCatalog.missingHandler,
|
|
57
|
+
items: params.missingHandlers ?? []
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
...routeDiagnosticCatalog.duplicateRoute,
|
|
61
|
+
items: params.duplicateRoutes ?? []
|
|
62
|
+
}
|
|
63
|
+
];
|
|
64
|
+
}
|
|
65
|
+
function createSwConflictDiagnosticSections(messages = []) {
|
|
66
|
+
return [{
|
|
67
|
+
...swConflictDiagnostic,
|
|
68
|
+
items: messages
|
|
69
|
+
}];
|
|
70
|
+
}
|
|
71
|
+
function normalizeSections(sections) {
|
|
72
|
+
return sections.map((section) => {
|
|
73
|
+
const items = Array.from(new Set((section.items ?? []).filter((item) => typeof item === "string" && item.length > 0)));
|
|
74
|
+
const count = section.count ?? items.length;
|
|
75
|
+
return {
|
|
76
|
+
...section,
|
|
77
|
+
items,
|
|
78
|
+
count
|
|
79
|
+
};
|
|
80
|
+
}).filter((section) => section.count > 0);
|
|
81
|
+
}
|
|
82
|
+
function buildDiagnosticSummaryLines(params) {
|
|
83
|
+
const title = params.title ?? "Mokup diagnostics summary";
|
|
84
|
+
const maxItems = params.maxItems ?? 3;
|
|
85
|
+
const sections = normalizeSections(params.sections);
|
|
86
|
+
if (sections.length === 0) return [];
|
|
87
|
+
const lines = [`${title}: ${sections.map((section) => `${section.count} ${section.label}`).join("; ")}`];
|
|
88
|
+
for (const section of sections) {
|
|
89
|
+
if (section.items.length > 0) {
|
|
90
|
+
const preview = section.items.slice(0, maxItems);
|
|
91
|
+
const remaining = section.items.length - preview.length;
|
|
92
|
+
lines.push(`${section.label}: ${preview.join(", ")}${remaining > 0 ? ` (+${remaining} more)` : ""}`);
|
|
93
|
+
}
|
|
94
|
+
if (section.advice) lines.push(`Fix: ${section.advice}`);
|
|
95
|
+
}
|
|
96
|
+
return lines;
|
|
97
|
+
}
|
|
98
|
+
function matchesErrorMode(category, errorOn) {
|
|
99
|
+
if (!category || !errorOn) return false;
|
|
100
|
+
if (errorOn === "all") return true;
|
|
101
|
+
return errorOn.includes(category);
|
|
102
|
+
}
|
|
103
|
+
function createDiagnosticError(params) {
|
|
104
|
+
const failingSections = normalizeSections(params.sections).filter((section) => matchesErrorMode(section.category, params.errorOn));
|
|
105
|
+
if (failingSections.length === 0) return null;
|
|
106
|
+
const buildParams = {
|
|
107
|
+
title: params.title ?? "Mokup diagnostics error",
|
|
108
|
+
sections: failingSections
|
|
109
|
+
};
|
|
110
|
+
if (typeof params.maxItems === "number") buildParams.maxItems = params.maxItems;
|
|
111
|
+
return new Error(buildDiagnosticSummaryLines(buildParams).join("\n"));
|
|
112
|
+
}
|
|
113
|
+
function reportDiagnostics(params) {
|
|
114
|
+
const summaryParams = { sections: params.sections };
|
|
115
|
+
if (typeof params.title === "string") summaryParams.title = params.title;
|
|
116
|
+
if (typeof params.maxItems === "number") summaryParams.maxItems = params.maxItems;
|
|
117
|
+
const summaryLines = buildDiagnosticSummaryLines(summaryParams);
|
|
118
|
+
if (params.warn) for (const line of summaryLines) params.warn(line);
|
|
119
|
+
const errorParams = { sections: params.sections };
|
|
120
|
+
if (params.errorOn) errorParams.errorOn = params.errorOn;
|
|
121
|
+
if (typeof params.errorTitle === "string") errorParams.title = params.errorTitle;
|
|
122
|
+
if (typeof params.maxItems === "number") errorParams.maxItems = params.maxItems;
|
|
123
|
+
return {
|
|
124
|
+
summaryLines,
|
|
125
|
+
error: createDiagnosticError(errorParams)
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
//#endregion
|
|
129
|
+
export { buildDiagnosticSummaryLines, collectRouteDiagnosticWarning, collectSwConflictDiagnosticWarning, createDiagnosticError, createRouteDiagnosticSections, createSwConflictDiagnosticSections, reportDiagnostics, routeDiagnosticCatalog, swConflictDiagnostic };
|
package/dist/hono.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
import { PatternRouter } from "hono/router/pattern-router";
|
|
2
|
+
import { handle } from "hono/service-worker";
|
|
3
|
+
export * from "hono";
|
|
4
|
+
export { PatternRouter, handle };
|
package/dist/hono.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
import { PatternRouter } from "hono/router/pattern-router";
|
|
2
|
+
import { handle } from "hono/service-worker";
|
|
3
|
+
export * from "hono";
|
|
4
|
+
export { PatternRouter, handle };
|
package/dist/hono.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export
|
|
1
|
+
import { PatternRouter } from "hono/router/pattern-router";
|
|
2
|
+
import { handle } from "hono/service-worker";
|
|
3
|
+
export * from "hono";
|
|
4
|
+
export { PatternRouter, handle };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { n as DiagnosticErrorMode } from "./diagnostic-types-DqAzUbgn.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/scan-utils.d.ts
|
|
4
|
+
declare function normalizeMethod(method?: string | null): string | undefined;
|
|
5
|
+
declare function normalizePrefix(prefix: string): string;
|
|
6
|
+
declare function resolveDirs(dir: DirInput, root: string): string[];
|
|
7
|
+
declare function normalizeIgnorePrefix(value: string | string[] | undefined, fallback?: string[]): string[];
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/index.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* Directory input for mock scanning.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import type { DirInput } from '@mokup/shared'
|
|
15
|
+
*
|
|
16
|
+
* const dir: DirInput = ['mock', 'fixtures']
|
|
17
|
+
*/
|
|
18
|
+
type DirInput = string | string[] | ((root: string) => string | string[]) | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Shared entry options for mokup scanners and plugins.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* import type { MockEntryOptions } from '@mokup/shared'
|
|
24
|
+
*
|
|
25
|
+
* const entry: MockEntryOptions = {
|
|
26
|
+
* dir: 'mock',
|
|
27
|
+
* prefix: '/api',
|
|
28
|
+
* watch: true,
|
|
29
|
+
* }
|
|
30
|
+
*/
|
|
31
|
+
interface MockEntryOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Directory (or directories) to scan for mock routes.
|
|
34
|
+
*
|
|
35
|
+
* @default "mock" (resolved by Vite/webpack plugins)
|
|
36
|
+
*/
|
|
37
|
+
dir?: DirInput;
|
|
38
|
+
/**
|
|
39
|
+
* Request path prefix to mount mock routes under.
|
|
40
|
+
*
|
|
41
|
+
* @default ""
|
|
42
|
+
*/
|
|
43
|
+
prefix?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Include filter for files to scan.
|
|
46
|
+
*
|
|
47
|
+
* @default undefined
|
|
48
|
+
*/
|
|
49
|
+
include?: RegExp | RegExp[];
|
|
50
|
+
/**
|
|
51
|
+
* Exclude filter for files to scan.
|
|
52
|
+
*
|
|
53
|
+
* @default undefined
|
|
54
|
+
*/
|
|
55
|
+
exclude?: RegExp | RegExp[];
|
|
56
|
+
/**
|
|
57
|
+
* Ignore file or folder prefixes when scanning.
|
|
58
|
+
*
|
|
59
|
+
* @default ["."]
|
|
60
|
+
*/
|
|
61
|
+
ignorePrefix?: string | string[];
|
|
62
|
+
/**
|
|
63
|
+
* Enable file watching for live route updates.
|
|
64
|
+
*
|
|
65
|
+
* @default true
|
|
66
|
+
*/
|
|
67
|
+
watch?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Enable mokup logging.
|
|
70
|
+
*
|
|
71
|
+
* @default true
|
|
72
|
+
*/
|
|
73
|
+
log?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Promote selected diagnostics from warnings to errors.
|
|
76
|
+
*
|
|
77
|
+
* @default undefined
|
|
78
|
+
*/
|
|
79
|
+
errorOn?: DiagnosticErrorMode;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Playground configuration input.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* import type { PlaygroundOptionsInput } from '@mokup/shared'
|
|
86
|
+
*
|
|
87
|
+
* const playground: PlaygroundOptionsInput = {
|
|
88
|
+
* path: '/__mokup',
|
|
89
|
+
* enabled: true,
|
|
90
|
+
* }
|
|
91
|
+
*/
|
|
92
|
+
type PlaygroundOptionsInput = boolean | {
|
|
93
|
+
/**
|
|
94
|
+
* Base path for the playground UI.
|
|
95
|
+
*
|
|
96
|
+
* @default "/__mokup"
|
|
97
|
+
*/
|
|
98
|
+
path?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Emit playground assets during production builds.
|
|
101
|
+
*
|
|
102
|
+
* @default false
|
|
103
|
+
*/
|
|
104
|
+
build?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Enable or disable the playground routes.
|
|
107
|
+
*
|
|
108
|
+
* @default true
|
|
109
|
+
*/
|
|
110
|
+
enabled?: boolean;
|
|
111
|
+
} | undefined;
|
|
112
|
+
//#endregion
|
|
113
|
+
export { normalizeMethod as a, normalizeIgnorePrefix as i, MockEntryOptions as n, normalizePrefix as o, PlaygroundOptionsInput as r, resolveDirs as s, DirInput as t };
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { n as DiagnosticErrorMode } from "./diagnostic-types-DqAzUbgn.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/scan-utils.d.ts
|
|
4
|
+
declare function normalizeMethod(method?: string | null): string | undefined;
|
|
5
|
+
declare function normalizePrefix(prefix: string): string;
|
|
6
|
+
declare function resolveDirs(dir: DirInput, root: string): string[];
|
|
7
|
+
declare function normalizeIgnorePrefix(value: string | string[] | undefined, fallback?: string[]): string[];
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/index.d.ts
|
|
10
|
+
/**
|
|
11
|
+
* Directory input for mock scanning.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import type { DirInput } from '@mokup/shared'
|
|
15
|
+
*
|
|
16
|
+
* const dir: DirInput = ['mock', 'fixtures']
|
|
17
|
+
*/
|
|
18
|
+
type DirInput = string | string[] | ((root: string) => string | string[]) | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Shared entry options for mokup scanners and plugins.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* import type { MockEntryOptions } from '@mokup/shared'
|
|
24
|
+
*
|
|
25
|
+
* const entry: MockEntryOptions = {
|
|
26
|
+
* dir: 'mock',
|
|
27
|
+
* prefix: '/api',
|
|
28
|
+
* watch: true,
|
|
29
|
+
* }
|
|
30
|
+
*/
|
|
31
|
+
interface MockEntryOptions {
|
|
32
|
+
/**
|
|
33
|
+
* Directory (or directories) to scan for mock routes.
|
|
34
|
+
*
|
|
35
|
+
* @default "mock" (resolved by Vite/webpack plugins)
|
|
36
|
+
*/
|
|
37
|
+
dir?: DirInput;
|
|
38
|
+
/**
|
|
39
|
+
* Request path prefix to mount mock routes under.
|
|
40
|
+
*
|
|
41
|
+
* @default ""
|
|
42
|
+
*/
|
|
43
|
+
prefix?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Include filter for files to scan.
|
|
46
|
+
*
|
|
47
|
+
* @default undefined
|
|
48
|
+
*/
|
|
49
|
+
include?: RegExp | RegExp[];
|
|
50
|
+
/**
|
|
51
|
+
* Exclude filter for files to scan.
|
|
52
|
+
*
|
|
53
|
+
* @default undefined
|
|
54
|
+
*/
|
|
55
|
+
exclude?: RegExp | RegExp[];
|
|
56
|
+
/**
|
|
57
|
+
* Ignore file or folder prefixes when scanning.
|
|
58
|
+
*
|
|
59
|
+
* @default ["."]
|
|
60
|
+
*/
|
|
61
|
+
ignorePrefix?: string | string[];
|
|
62
|
+
/**
|
|
63
|
+
* Enable file watching for live route updates.
|
|
64
|
+
*
|
|
65
|
+
* @default true
|
|
66
|
+
*/
|
|
67
|
+
watch?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Enable mokup logging.
|
|
70
|
+
*
|
|
71
|
+
* @default true
|
|
72
|
+
*/
|
|
73
|
+
log?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Promote selected diagnostics from warnings to errors.
|
|
76
|
+
*
|
|
77
|
+
* @default undefined
|
|
78
|
+
*/
|
|
79
|
+
errorOn?: DiagnosticErrorMode;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Playground configuration input.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* import type { PlaygroundOptionsInput } from '@mokup/shared'
|
|
86
|
+
*
|
|
87
|
+
* const playground: PlaygroundOptionsInput = {
|
|
88
|
+
* path: '/__mokup',
|
|
89
|
+
* enabled: true,
|
|
90
|
+
* }
|
|
91
|
+
*/
|
|
92
|
+
type PlaygroundOptionsInput = boolean | {
|
|
93
|
+
/**
|
|
94
|
+
* Base path for the playground UI.
|
|
95
|
+
*
|
|
96
|
+
* @default "/__mokup"
|
|
97
|
+
*/
|
|
98
|
+
path?: string;
|
|
99
|
+
/**
|
|
100
|
+
* Emit playground assets during production builds.
|
|
101
|
+
*
|
|
102
|
+
* @default false
|
|
103
|
+
*/
|
|
104
|
+
build?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* Enable or disable the playground routes.
|
|
107
|
+
*
|
|
108
|
+
* @default true
|
|
109
|
+
*/
|
|
110
|
+
enabled?: boolean;
|
|
111
|
+
} | undefined;
|
|
112
|
+
//#endregion
|
|
113
|
+
export { normalizeMethod as a, normalizeIgnorePrefix as i, MockEntryOptions as n, normalizePrefix as o, PlaygroundOptionsInput as r, resolveDirs as s, DirInput as t };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { n as middlewareSymbol, t as isPromise } from "./config-core-dqVMz7on.mjs";
|
|
2
|
+
import { a as findConfigFile, c as readMiddlewareMeta, i as buildConfigChain, l as resolveDirectoryConfig, n as MiddlewareMeta, o as getConfigFileCandidates, r as MiddlewarePosition, s as normalizeMiddlewareList, t as ConfigSourceMap } from "./config-utils-DFu0_9tl.mjs";
|
|
3
|
+
import { a as createDefineConfig, i as HookHandler, n as DefineConfigFactory, r as HookErrorPolicy, t as ConfigApp } from "./define-config-CzB1-X1m.mjs";
|
|
4
|
+
import { i as isDiagnosticCategory, n as DiagnosticErrorMode, r as diagnosticCategories, t as DiagnosticCategory } from "./diagnostic-types-DqAzUbgn.mjs";
|
|
5
|
+
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";
|
|
6
|
+
import { n as readJsoncFile } from "./jsonc-utils-_Hs6a39T.mjs";
|
|
7
|
+
import { n as loadRules } from "./load-rules-D_kCpu9I.mjs";
|
|
8
|
+
import { i as isSupportedFile, n as collectFiles, r as isConfigFile } from "./mock-files-DfGigWmY.mjs";
|
|
9
|
+
import { n as ensureTsxRegister, r as loadModule, t as createTsxConfigFile } from "./module-loader-nAQlwo3D.mjs";
|
|
10
|
+
import { a as supportedExtensions, i as methodSuffixSet, n as jsonExtensions, r as methodSet, t as configExtensions } from "./route-constants-BUi36iYR.mjs";
|
|
11
|
+
import { a as createRouteUtils, i as RouteScoreComparator, n as RouteParser, r as RouteParserResult, t as DerivedRoute } from "./route-utils-BiWFUqo-.mjs";
|
|
12
|
+
import { a as normalizeMethod, i as normalizeIgnorePrefix, n as MockEntryOptions, o as normalizePrefix, r as PlaygroundOptionsInput, s as resolveDirs, t as DirInput } from "./index-5prVUGOX.mjs";
|
|
13
|
+
export { ConfigApp, ConfigSourceMap, DefineConfigFactory, DerivedRoute, DiagnosticCategory, DiagnosticErrorMode, DiagnosticSummarySection, DirInput, HookErrorPolicy, HookHandler, MiddlewareMeta, MiddlewarePosition, MockEntryOptions, PlaygroundOptionsInput, RouteParser, RouteParserResult, RouteScoreComparator, buildConfigChain, buildDiagnosticSummaryLines, collectFiles, collectRouteDiagnosticWarning, collectSwConflictDiagnosticWarning, configExtensions, createDefineConfig, createDiagnosticError, createRouteDiagnosticSections, createRouteUtils, createSwConflictDiagnosticSections, createTsxConfigFile, diagnosticCategories, ensureTsxRegister, findConfigFile, getConfigFileCandidates, isConfigFile, isDiagnosticCategory, isPromise, isSupportedFile, jsonExtensions, loadModule, loadRules, methodSet, methodSuffixSet, middlewareSymbol, normalizeIgnorePrefix, normalizeMethod, normalizeMiddlewareList, normalizePrefix, readJsoncFile, readMiddlewareMeta, reportDiagnostics, resolveDirectoryConfig, resolveDirs, routeDiagnosticCatalog, supportedExtensions, swConflictDiagnostic };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { n as middlewareSymbol, t as isPromise } from "./config-core-dqVMz7on.mjs";
|
|
2
|
+
import { a as findConfigFile, c as readMiddlewareMeta, i as buildConfigChain, l as resolveDirectoryConfig, n as MiddlewareMeta, o as getConfigFileCandidates, r as MiddlewarePosition, s as normalizeMiddlewareList, t as ConfigSourceMap } from "./config-utils-DFu0_9tl.mjs";
|
|
3
|
+
import { a as createDefineConfig, i as HookHandler, n as DefineConfigFactory, r as HookErrorPolicy, t as ConfigApp } from "./define-config-CzB1-X1m.mjs";
|
|
4
|
+
import { i as isDiagnosticCategory, n as DiagnosticErrorMode, r as diagnosticCategories, t as DiagnosticCategory } from "./diagnostic-types-DqAzUbgn.mjs";
|
|
5
|
+
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";
|
|
6
|
+
import { n as readJsoncFile } from "./jsonc-utils-_Hs6a39T.mjs";
|
|
7
|
+
import { n as loadRules } from "./load-rules-D_kCpu9I.mjs";
|
|
8
|
+
import { i as isSupportedFile, n as collectFiles, r as isConfigFile } from "./mock-files-DfGigWmY.mjs";
|
|
9
|
+
import { n as ensureTsxRegister, r as loadModule, t as createTsxConfigFile } from "./module-loader-nAQlwo3D.mjs";
|
|
10
|
+
import { a as supportedExtensions, i as methodSuffixSet, n as jsonExtensions, r as methodSet, t as configExtensions } from "./route-constants-BUi36iYR.mjs";
|
|
11
|
+
import { a as createRouteUtils, i as RouteScoreComparator, n as RouteParser, r as RouteParserResult, t as DerivedRoute } from "./route-utils-BiWFUqo-.mjs";
|
|
12
|
+
import { a as normalizeMethod, i as normalizeIgnorePrefix, n as MockEntryOptions, o as normalizePrefix, r as PlaygroundOptionsInput, s as resolveDirs, t as DirInput } from "./index-5prVUGOX.mjs";
|
|
13
|
+
export { ConfigApp, ConfigSourceMap, DefineConfigFactory, DerivedRoute, DiagnosticCategory, DiagnosticErrorMode, DiagnosticSummarySection, DirInput, HookErrorPolicy, HookHandler, MiddlewareMeta, MiddlewarePosition, MockEntryOptions, PlaygroundOptionsInput, RouteParser, RouteParserResult, RouteScoreComparator, buildConfigChain, buildDiagnosticSummaryLines, collectFiles, collectRouteDiagnosticWarning, collectSwConflictDiagnosticWarning, configExtensions, createDefineConfig, createDiagnosticError, createRouteDiagnosticSections, createRouteUtils, createSwConflictDiagnosticSections, createTsxConfigFile, diagnosticCategories, ensureTsxRegister, findConfigFile, getConfigFileCandidates, isConfigFile, isDiagnosticCategory, isPromise, isSupportedFile, jsonExtensions, loadModule, loadRules, methodSet, methodSuffixSet, middlewareSymbol, normalizeIgnorePrefix, normalizeMethod, normalizeMiddlewareList, normalizePrefix, readJsoncFile, readMiddlewareMeta, reportDiagnostics, resolveDirectoryConfig, resolveDirs, routeDiagnosticCatalog, supportedExtensions, swConflictDiagnostic };
|
package/dist/index.mjs
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
import 'node:module';
|
|
15
|
-
import 'node:os';
|
|
16
|
-
import 'node:process';
|
|
17
|
-
import 'node:url';
|
|
18
|
-
import './path-utils.mjs';
|
|
1
|
+
import { isPromise, middlewareSymbol } from "./config-core.mjs";
|
|
2
|
+
import { buildConfigChain, findConfigFile, getConfigFileCandidates, normalizeMiddlewareList, readMiddlewareMeta, resolveDirectoryConfig } from "./config-utils.mjs";
|
|
3
|
+
import { createDefineConfig } from "./define-config.mjs";
|
|
4
|
+
import { diagnosticCategories, isDiagnosticCategory } from "./diagnostic-types.mjs";
|
|
5
|
+
import { buildDiagnosticSummaryLines, collectRouteDiagnosticWarning, collectSwConflictDiagnosticWarning, createDiagnosticError, createRouteDiagnosticSections, createSwConflictDiagnosticSections, reportDiagnostics, routeDiagnosticCatalog, swConflictDiagnostic } from "./diagnostics.mjs";
|
|
6
|
+
import { readJsoncFile } from "./jsonc-utils.mjs";
|
|
7
|
+
import { loadRules } from "./load-rules.mjs";
|
|
8
|
+
import { configExtensions, jsonExtensions, methodSet, methodSuffixSet, supportedExtensions } from "./route-constants.mjs";
|
|
9
|
+
import { collectFiles, isConfigFile, isSupportedFile } from "./mock-files.mjs";
|
|
10
|
+
import { createTsxConfigFile, ensureTsxRegister, loadModule } from "./module-loader.mjs";
|
|
11
|
+
import { normalizeIgnorePrefix, normalizeMethod, normalizePrefix, resolveDirs } from "./scan-utils.mjs";
|
|
12
|
+
import { createRouteUtils } from "./route-utils.mjs";
|
|
13
|
+
export { buildConfigChain, buildDiagnosticSummaryLines, collectFiles, collectRouteDiagnosticWarning, collectSwConflictDiagnosticWarning, configExtensions, createDefineConfig, createDiagnosticError, createRouteDiagnosticSections, createRouteUtils, createSwConflictDiagnosticSections, createTsxConfigFile, diagnosticCategories, ensureTsxRegister, findConfigFile, getConfigFileCandidates, isConfigFile, isDiagnosticCategory, isPromise, isSupportedFile, jsonExtensions, loadModule, loadRules, methodSet, methodSuffixSet, middlewareSymbol, normalizeIgnorePrefix, normalizeMethod, normalizeMiddlewareList, normalizePrefix, readJsoncFile, readMiddlewareMeta, reportDiagnostics, resolveDirectoryConfig, resolveDirs, routeDiagnosticCatalog, supportedExtensions, swConflictDiagnostic };
|
package/dist/jsonc-parser.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "jsonc-parser";
|
package/dist/jsonc-parser.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "jsonc-parser";
|
package/dist/jsonc-parser.mjs
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { n as __reExport, t as __exportAll } from "./chunk-_iGcCiPk.mjs";
|
|
2
|
+
export * from "jsonc-parser";
|
|
3
|
+
//#region src/jsonc-parser.ts
|
|
4
|
+
var jsonc_parser_exports = /* @__PURE__ */ __exportAll({});
|
|
5
|
+
import * as import_jsonc_parser from "jsonc-parser";
|
|
6
|
+
__reExport(jsonc_parser_exports, import_jsonc_parser);
|
|
7
|
+
//#endregion
|
|
8
|
+
export { jsonc_parser_exports as t };
|
package/dist/jsonc-utils.d.mts
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
declare function readJsoncFile(file: string, logger?: JsoncLogger): Promise<any>;
|
|
5
|
-
|
|
6
|
-
export { readJsoncFile };
|
|
7
|
-
export type { JsoncLogger };
|
|
1
|
+
import { n as readJsoncFile, t as JsoncLogger } from "./jsonc-utils-_Hs6a39T.mjs";
|
|
2
|
+
export { JsoncLogger, readJsoncFile };
|
package/dist/jsonc-utils.d.ts
CHANGED
|
@@ -1,7 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
declare function readJsoncFile(file: string, logger?: JsoncLogger): Promise<any>;
|
|
5
|
-
|
|
6
|
-
export { readJsoncFile };
|
|
7
|
-
export type { JsoncLogger };
|
|
1
|
+
import { n as readJsoncFile, t as JsoncLogger } from "./jsonc-utils-_Hs6a39T.mjs";
|
|
2
|
+
export { JsoncLogger, readJsoncFile };
|
package/dist/jsonc-utils.mjs
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { t as jsonc_parser_exports } from "./jsonc-parser.mjs";
|
|
2
|
+
import { promises } from "node:fs";
|
|
3
|
+
//#region src/jsonc-utils.ts
|
|
4
4
|
async function readJsoncFile(file, logger) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
5
|
+
try {
|
|
6
|
+
const content = await promises.readFile(file, "utf8");
|
|
7
|
+
const errors = [];
|
|
8
|
+
const data = (0, jsonc_parser_exports.parse)(content, errors, {
|
|
9
|
+
allowTrailingComma: true,
|
|
10
|
+
disallowComments: false
|
|
11
|
+
});
|
|
12
|
+
if (errors.length > 0) {
|
|
13
|
+
logger?.warn?.(`Invalid JSONC in ${file}`);
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
return data;
|
|
17
|
+
} catch (error) {
|
|
18
|
+
logger?.warn?.(`Failed to read ${file}: ${String(error)}`);
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
//#endregion
|
|
23
23
|
export { readJsoncFile };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/load-rules.d.ts
|
|
2
|
+
interface LoadRulesOptions {
|
|
3
|
+
loadModule: (file: string) => Promise<unknown | null>;
|
|
4
|
+
logger?: {
|
|
5
|
+
warn?: (message: string) => void;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
declare function loadRules<T extends {
|
|
9
|
+
handler: unknown;
|
|
10
|
+
} = {
|
|
11
|
+
handler: unknown;
|
|
12
|
+
}>(file: string, options: LoadRulesOptions): Promise<T[]>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { loadRules as n, LoadRulesOptions as t };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/load-rules.d.ts
|
|
2
|
+
interface LoadRulesOptions {
|
|
3
|
+
loadModule: (file: string) => Promise<unknown | null>;
|
|
4
|
+
logger?: {
|
|
5
|
+
warn?: (message: string) => void;
|
|
6
|
+
};
|
|
7
|
+
}
|
|
8
|
+
declare function loadRules<T extends {
|
|
9
|
+
handler: unknown;
|
|
10
|
+
} = {
|
|
11
|
+
handler: unknown;
|
|
12
|
+
}>(file: string, options: LoadRulesOptions): Promise<T[]>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { loadRules as n, LoadRulesOptions as t };
|
package/dist/load-rules.d.mts
CHANGED
|
@@ -1,14 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
logger?: {
|
|
4
|
-
warn?: (message: string) => void;
|
|
5
|
-
};
|
|
6
|
-
}
|
|
7
|
-
declare function loadRules<T extends {
|
|
8
|
-
handler: unknown;
|
|
9
|
-
} = {
|
|
10
|
-
handler: unknown;
|
|
11
|
-
}>(file: string, options: LoadRulesOptions): Promise<T[]>;
|
|
12
|
-
|
|
13
|
-
export { loadRules };
|
|
14
|
-
export type { LoadRulesOptions };
|
|
1
|
+
import { n as loadRules, t as LoadRulesOptions } from "./load-rules-D_kCpu9I.mjs";
|
|
2
|
+
export { LoadRulesOptions, loadRules };
|
package/dist/load-rules.d.ts
CHANGED
|
@@ -1,14 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
logger?: {
|
|
4
|
-
warn?: (message: string) => void;
|
|
5
|
-
};
|
|
6
|
-
}
|
|
7
|
-
declare function loadRules<T extends {
|
|
8
|
-
handler: unknown;
|
|
9
|
-
} = {
|
|
10
|
-
handler: unknown;
|
|
11
|
-
}>(file: string, options: LoadRulesOptions): Promise<T[]>;
|
|
12
|
-
|
|
13
|
-
export { loadRules };
|
|
14
|
-
export type { LoadRulesOptions };
|
|
1
|
+
import { n as loadRules, t as LoadRulesOptions } from "./load-rules-D_kCpu9I.mjs";
|
|
2
|
+
export { LoadRulesOptions, loadRules };
|