@mokup/shared 1.1.0 → 1.1.2
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/dist/config-core.cjs +9 -0
- package/dist/config-core.d.cts +4 -0
- package/dist/config-core.d.mts +4 -0
- package/dist/config-core.d.ts +4 -0
- package/dist/config-core.mjs +6 -0
- package/dist/config-utils.cjs +179 -0
- package/dist/config-utils.d.cts +62 -0
- package/dist/config-utils.d.mts +62 -0
- package/dist/config-utils.d.ts +62 -0
- package/dist/config-utils.mjs +171 -0
- package/dist/define-config.cjs +168 -0
- package/dist/define-config.d.cts +20 -0
- package/dist/define-config.d.mts +20 -0
- package/dist/define-config.d.ts +20 -0
- package/dist/define-config.mjs +166 -0
- package/dist/index.cjs +48 -0
- package/dist/index.d.cts +10 -98
- package/dist/index.d.mts +10 -98
- package/dist/index.d.ts +10 -98
- package/dist/index.mjs +18 -1
- package/dist/jsonc-utils.cjs +25 -0
- package/dist/jsonc-utils.d.cts +7 -0
- package/dist/jsonc-utils.d.mts +7 -0
- package/dist/jsonc-utils.d.ts +7 -0
- package/dist/jsonc-utils.mjs +23 -0
- package/dist/load-rules.cjs +39 -0
- package/dist/load-rules.d.cts +14 -0
- package/dist/load-rules.d.mts +14 -0
- package/dist/load-rules.d.ts +14 -0
- package/dist/load-rules.mjs +37 -0
- package/dist/mock-files.cjs +65 -0
- package/dist/mock-files.d.cts +10 -0
- package/dist/mock-files.d.mts +10 -0
- package/dist/mock-files.d.ts +10 -0
- package/dist/mock-files.mjs +61 -0
- package/dist/module-loader.cjs +93 -0
- package/dist/module-loader.d.cts +13 -0
- package/dist/module-loader.d.mts +13 -0
- package/dist/module-loader.d.ts +13 -0
- package/dist/module-loader.mjs +83 -0
- package/dist/path-utils.cjs +57 -0
- package/dist/path-utils.d.cts +7 -0
- package/dist/path-utils.d.mts +7 -0
- package/dist/path-utils.d.ts +7 -0
- package/dist/path-utils.mjs +51 -0
- package/dist/playground-grouping.cjs +95 -0
- package/dist/playground-grouping.d.cts +12 -0
- package/dist/playground-grouping.d.mts +12 -0
- package/dist/playground-grouping.d.ts +12 -0
- package/dist/playground-grouping.mjs +90 -0
- package/dist/route-constants.cjs +30 -0
- package/dist/route-constants.d.cts +7 -0
- package/dist/route-constants.d.mts +7 -0
- package/dist/route-constants.d.ts +7 -0
- package/dist/route-constants.mjs +24 -0
- package/dist/route-utils.cjs +126 -0
- package/dist/route-utils.d.cts +42 -0
- package/dist/route-utils.d.mts +42 -0
- package/dist/route-utils.d.ts +42 -0
- package/dist/route-utils.mjs +124 -0
- package/dist/scan-utils.cjs +39 -0
- package/dist/scan-utils.d.cts +114 -0
- package/dist/scan-utils.d.mts +114 -0
- package/dist/scan-utils.d.ts +114 -0
- package/dist/scan-utils.mjs +34 -0
- package/dist/timing.cjs +20 -0
- package/dist/timing.d.cts +4 -0
- package/dist/timing.d.mts +4 -0
- package/dist/timing.d.ts +4 -0
- package/dist/timing.mjs +17 -0
- package/package.json +81 -18
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const configCore = require('./config-core.cjs');
|
|
4
|
+
|
|
5
|
+
function normalizeHookError(policy) {
|
|
6
|
+
if (policy === "throw" || policy === "silent") {
|
|
7
|
+
return policy;
|
|
8
|
+
}
|
|
9
|
+
return "warn";
|
|
10
|
+
}
|
|
11
|
+
function createDefineConfig(options) {
|
|
12
|
+
const contextStack = [];
|
|
13
|
+
function getActiveContext() {
|
|
14
|
+
const context = contextStack[contextStack.length - 1];
|
|
15
|
+
if (!context) {
|
|
16
|
+
throw new Error("onBeforeAll/onAfterAll must be called inside defineConfig()");
|
|
17
|
+
}
|
|
18
|
+
return context;
|
|
19
|
+
}
|
|
20
|
+
function runWithContext(context, fn) {
|
|
21
|
+
contextStack.push(context);
|
|
22
|
+
try {
|
|
23
|
+
const result = fn();
|
|
24
|
+
if (configCore.isPromise(result)) {
|
|
25
|
+
return result.finally(() => {
|
|
26
|
+
contextStack.pop();
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
contextStack.pop();
|
|
30
|
+
return result;
|
|
31
|
+
} catch (error) {
|
|
32
|
+
contextStack.pop();
|
|
33
|
+
throw error;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
function reportHookError(error, policy) {
|
|
37
|
+
if (policy === "silent") {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if (policy === "warn") {
|
|
41
|
+
console.warn(`${options.logPrefix} defineConfig hook failed:`, error);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function runHookSequence(stage, hooks, policy, setStage) {
|
|
45
|
+
if (hooks.length === 0) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
setStage(stage);
|
|
49
|
+
let chain = null;
|
|
50
|
+
const runHook = (hook) => {
|
|
51
|
+
try {
|
|
52
|
+
const result = hook();
|
|
53
|
+
if (configCore.isPromise(result)) {
|
|
54
|
+
return result.catch((error) => {
|
|
55
|
+
if (policy === "throw") {
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
reportHookError(error, policy);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
return void 0;
|
|
62
|
+
} catch (error) {
|
|
63
|
+
if (policy === "throw") {
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
reportHookError(error, policy);
|
|
67
|
+
return void 0;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
for (const hook of hooks) {
|
|
71
|
+
if (chain) {
|
|
72
|
+
chain = chain.then(() => runHook(hook));
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const result = runHook(hook);
|
|
76
|
+
if (configCore.isPromise(result)) {
|
|
77
|
+
chain = result;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (!chain) {
|
|
81
|
+
setStage("normal");
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
return chain.finally(() => {
|
|
85
|
+
setStage("normal");
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function attachMetadata(config, meta) {
|
|
89
|
+
Object.defineProperty(config, configCore.middlewareSymbol, {
|
|
90
|
+
value: meta,
|
|
91
|
+
enumerable: false
|
|
92
|
+
});
|
|
93
|
+
return config;
|
|
94
|
+
}
|
|
95
|
+
function normalizeConfig(value) {
|
|
96
|
+
return value && typeof value === "object" ? value : {};
|
|
97
|
+
}
|
|
98
|
+
function onBeforeAll(handler) {
|
|
99
|
+
if (typeof handler !== "function") {
|
|
100
|
+
throw new TypeError("onBeforeAll expects a function");
|
|
101
|
+
}
|
|
102
|
+
const context = getActiveContext();
|
|
103
|
+
context.hooks.pre.push(handler);
|
|
104
|
+
}
|
|
105
|
+
function onAfterAll(handler) {
|
|
106
|
+
if (typeof handler !== "function") {
|
|
107
|
+
throw new TypeError("onAfterAll expects a function");
|
|
108
|
+
}
|
|
109
|
+
const context = getActiveContext();
|
|
110
|
+
context.hooks.post.push(handler);
|
|
111
|
+
}
|
|
112
|
+
function defineConfig(input) {
|
|
113
|
+
if (typeof input === "function") {
|
|
114
|
+
const pre = [];
|
|
115
|
+
const normal = [];
|
|
116
|
+
const post = [];
|
|
117
|
+
let stage = "normal";
|
|
118
|
+
const app = {
|
|
119
|
+
use: (...handlers) => {
|
|
120
|
+
if (stage === "pre") {
|
|
121
|
+
pre.push(...handlers);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
if (stage === "post") {
|
|
125
|
+
post.push(...handlers);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
normal.push(...handlers);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
const context = {
|
|
132
|
+
app,
|
|
133
|
+
hooks: { pre: [], post: [] },
|
|
134
|
+
setStage: (next) => {
|
|
135
|
+
stage = next;
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
const result = runWithContext(context, () => input({ app }));
|
|
139
|
+
const finalize = (value) => {
|
|
140
|
+
const config2 = normalizeConfig(value);
|
|
141
|
+
const policy = normalizeHookError(config2.hookError);
|
|
142
|
+
const preResult = runHookSequence("pre", context.hooks.pre, policy, context.setStage);
|
|
143
|
+
const runPost = () => runHookSequence("post", context.hooks.post, policy, context.setStage);
|
|
144
|
+
if (configCore.isPromise(preResult)) {
|
|
145
|
+
return preResult.then(runPost).then(() => attachMetadata(config2, { pre, normal, post }));
|
|
146
|
+
}
|
|
147
|
+
const postResult = runPost();
|
|
148
|
+
if (configCore.isPromise(postResult)) {
|
|
149
|
+
return postResult.then(() => attachMetadata(config2, { pre, normal, post }));
|
|
150
|
+
}
|
|
151
|
+
return attachMetadata(config2, { pre, normal, post });
|
|
152
|
+
};
|
|
153
|
+
if (configCore.isPromise(result)) {
|
|
154
|
+
return result.then(finalize);
|
|
155
|
+
}
|
|
156
|
+
return finalize(result);
|
|
157
|
+
}
|
|
158
|
+
const config = normalizeConfig(input);
|
|
159
|
+
return attachMetadata(config, { pre: [], normal: [], post: [] });
|
|
160
|
+
}
|
|
161
|
+
return {
|
|
162
|
+
defineConfig,
|
|
163
|
+
onBeforeAll,
|
|
164
|
+
onAfterAll
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
exports.createDefineConfig = createDefineConfig;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type HookErrorPolicy = 'warn' | 'silent' | 'throw';
|
|
2
|
+
type HookHandler = () => void | Promise<void>;
|
|
3
|
+
interface ConfigApp<TMiddleware> {
|
|
4
|
+
use: (...handlers: TMiddleware[]) => void;
|
|
5
|
+
}
|
|
6
|
+
type DefineConfigFactory<TConfig, TMiddleware> = (context: {
|
|
7
|
+
app: ConfigApp<TMiddleware>;
|
|
8
|
+
}) => TConfig | void | Promise<TConfig | void>;
|
|
9
|
+
declare function createDefineConfig<TConfig extends {
|
|
10
|
+
hookError?: HookErrorPolicy;
|
|
11
|
+
}, TMiddleware>(options: {
|
|
12
|
+
logPrefix: string;
|
|
13
|
+
}): {
|
|
14
|
+
defineConfig: (input: TConfig | DefineConfigFactory<TConfig, TMiddleware>) => TConfig | Promise<TConfig>;
|
|
15
|
+
onBeforeAll: (handler: HookHandler) => void;
|
|
16
|
+
onAfterAll: (handler: HookHandler) => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { createDefineConfig };
|
|
20
|
+
export type { ConfigApp, DefineConfigFactory, HookErrorPolicy, HookHandler };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type HookErrorPolicy = 'warn' | 'silent' | 'throw';
|
|
2
|
+
type HookHandler = () => void | Promise<void>;
|
|
3
|
+
interface ConfigApp<TMiddleware> {
|
|
4
|
+
use: (...handlers: TMiddleware[]) => void;
|
|
5
|
+
}
|
|
6
|
+
type DefineConfigFactory<TConfig, TMiddleware> = (context: {
|
|
7
|
+
app: ConfigApp<TMiddleware>;
|
|
8
|
+
}) => TConfig | void | Promise<TConfig | void>;
|
|
9
|
+
declare function createDefineConfig<TConfig extends {
|
|
10
|
+
hookError?: HookErrorPolicy;
|
|
11
|
+
}, TMiddleware>(options: {
|
|
12
|
+
logPrefix: string;
|
|
13
|
+
}): {
|
|
14
|
+
defineConfig: (input: TConfig | DefineConfigFactory<TConfig, TMiddleware>) => TConfig | Promise<TConfig>;
|
|
15
|
+
onBeforeAll: (handler: HookHandler) => void;
|
|
16
|
+
onAfterAll: (handler: HookHandler) => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { createDefineConfig };
|
|
20
|
+
export type { ConfigApp, DefineConfigFactory, HookErrorPolicy, HookHandler };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
type HookErrorPolicy = 'warn' | 'silent' | 'throw';
|
|
2
|
+
type HookHandler = () => void | Promise<void>;
|
|
3
|
+
interface ConfigApp<TMiddleware> {
|
|
4
|
+
use: (...handlers: TMiddleware[]) => void;
|
|
5
|
+
}
|
|
6
|
+
type DefineConfigFactory<TConfig, TMiddleware> = (context: {
|
|
7
|
+
app: ConfigApp<TMiddleware>;
|
|
8
|
+
}) => TConfig | void | Promise<TConfig | void>;
|
|
9
|
+
declare function createDefineConfig<TConfig extends {
|
|
10
|
+
hookError?: HookErrorPolicy;
|
|
11
|
+
}, TMiddleware>(options: {
|
|
12
|
+
logPrefix: string;
|
|
13
|
+
}): {
|
|
14
|
+
defineConfig: (input: TConfig | DefineConfigFactory<TConfig, TMiddleware>) => TConfig | Promise<TConfig>;
|
|
15
|
+
onBeforeAll: (handler: HookHandler) => void;
|
|
16
|
+
onAfterAll: (handler: HookHandler) => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export { createDefineConfig };
|
|
20
|
+
export type { ConfigApp, DefineConfigFactory, HookErrorPolicy, HookHandler };
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { isPromise, middlewareSymbol } from './config-core.mjs';
|
|
2
|
+
|
|
3
|
+
function normalizeHookError(policy) {
|
|
4
|
+
if (policy === "throw" || policy === "silent") {
|
|
5
|
+
return policy;
|
|
6
|
+
}
|
|
7
|
+
return "warn";
|
|
8
|
+
}
|
|
9
|
+
function createDefineConfig(options) {
|
|
10
|
+
const contextStack = [];
|
|
11
|
+
function getActiveContext() {
|
|
12
|
+
const context = contextStack[contextStack.length - 1];
|
|
13
|
+
if (!context) {
|
|
14
|
+
throw new Error("onBeforeAll/onAfterAll must be called inside defineConfig()");
|
|
15
|
+
}
|
|
16
|
+
return context;
|
|
17
|
+
}
|
|
18
|
+
function runWithContext(context, fn) {
|
|
19
|
+
contextStack.push(context);
|
|
20
|
+
try {
|
|
21
|
+
const result = fn();
|
|
22
|
+
if (isPromise(result)) {
|
|
23
|
+
return result.finally(() => {
|
|
24
|
+
contextStack.pop();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
contextStack.pop();
|
|
28
|
+
return result;
|
|
29
|
+
} catch (error) {
|
|
30
|
+
contextStack.pop();
|
|
31
|
+
throw error;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function reportHookError(error, policy) {
|
|
35
|
+
if (policy === "silent") {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (policy === "warn") {
|
|
39
|
+
console.warn(`${options.logPrefix} defineConfig hook failed:`, error);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
function runHookSequence(stage, hooks, policy, setStage) {
|
|
43
|
+
if (hooks.length === 0) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
setStage(stage);
|
|
47
|
+
let chain = null;
|
|
48
|
+
const runHook = (hook) => {
|
|
49
|
+
try {
|
|
50
|
+
const result = hook();
|
|
51
|
+
if (isPromise(result)) {
|
|
52
|
+
return result.catch((error) => {
|
|
53
|
+
if (policy === "throw") {
|
|
54
|
+
throw error;
|
|
55
|
+
}
|
|
56
|
+
reportHookError(error, policy);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
return void 0;
|
|
60
|
+
} catch (error) {
|
|
61
|
+
if (policy === "throw") {
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
reportHookError(error, policy);
|
|
65
|
+
return void 0;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
for (const hook of hooks) {
|
|
69
|
+
if (chain) {
|
|
70
|
+
chain = chain.then(() => runHook(hook));
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const result = runHook(hook);
|
|
74
|
+
if (isPromise(result)) {
|
|
75
|
+
chain = result;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (!chain) {
|
|
79
|
+
setStage("normal");
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
return chain.finally(() => {
|
|
83
|
+
setStage("normal");
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function attachMetadata(config, meta) {
|
|
87
|
+
Object.defineProperty(config, middlewareSymbol, {
|
|
88
|
+
value: meta,
|
|
89
|
+
enumerable: false
|
|
90
|
+
});
|
|
91
|
+
return config;
|
|
92
|
+
}
|
|
93
|
+
function normalizeConfig(value) {
|
|
94
|
+
return value && typeof value === "object" ? value : {};
|
|
95
|
+
}
|
|
96
|
+
function onBeforeAll(handler) {
|
|
97
|
+
if (typeof handler !== "function") {
|
|
98
|
+
throw new TypeError("onBeforeAll expects a function");
|
|
99
|
+
}
|
|
100
|
+
const context = getActiveContext();
|
|
101
|
+
context.hooks.pre.push(handler);
|
|
102
|
+
}
|
|
103
|
+
function onAfterAll(handler) {
|
|
104
|
+
if (typeof handler !== "function") {
|
|
105
|
+
throw new TypeError("onAfterAll expects a function");
|
|
106
|
+
}
|
|
107
|
+
const context = getActiveContext();
|
|
108
|
+
context.hooks.post.push(handler);
|
|
109
|
+
}
|
|
110
|
+
function defineConfig(input) {
|
|
111
|
+
if (typeof input === "function") {
|
|
112
|
+
const pre = [];
|
|
113
|
+
const normal = [];
|
|
114
|
+
const post = [];
|
|
115
|
+
let stage = "normal";
|
|
116
|
+
const app = {
|
|
117
|
+
use: (...handlers) => {
|
|
118
|
+
if (stage === "pre") {
|
|
119
|
+
pre.push(...handlers);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
if (stage === "post") {
|
|
123
|
+
post.push(...handlers);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
normal.push(...handlers);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
const context = {
|
|
130
|
+
app,
|
|
131
|
+
hooks: { pre: [], post: [] },
|
|
132
|
+
setStage: (next) => {
|
|
133
|
+
stage = next;
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
const result = runWithContext(context, () => input({ app }));
|
|
137
|
+
const finalize = (value) => {
|
|
138
|
+
const config2 = normalizeConfig(value);
|
|
139
|
+
const policy = normalizeHookError(config2.hookError);
|
|
140
|
+
const preResult = runHookSequence("pre", context.hooks.pre, policy, context.setStage);
|
|
141
|
+
const runPost = () => runHookSequence("post", context.hooks.post, policy, context.setStage);
|
|
142
|
+
if (isPromise(preResult)) {
|
|
143
|
+
return preResult.then(runPost).then(() => attachMetadata(config2, { pre, normal, post }));
|
|
144
|
+
}
|
|
145
|
+
const postResult = runPost();
|
|
146
|
+
if (isPromise(postResult)) {
|
|
147
|
+
return postResult.then(() => attachMetadata(config2, { pre, normal, post }));
|
|
148
|
+
}
|
|
149
|
+
return attachMetadata(config2, { pre, normal, post });
|
|
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
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export { createDefineConfig };
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,50 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const configCore = require('./config-core.cjs');
|
|
4
|
+
const configUtils = require('./config-utils.cjs');
|
|
5
|
+
const defineConfig = require('./define-config.cjs');
|
|
6
|
+
const jsoncUtils = require('./jsonc-utils.cjs');
|
|
7
|
+
const loadRules = require('./load-rules.cjs');
|
|
8
|
+
const mockFiles = require('./mock-files.cjs');
|
|
9
|
+
const moduleLoader = require('./module-loader.cjs');
|
|
10
|
+
const routeConstants = require('./route-constants.cjs');
|
|
11
|
+
const routeUtils = require('./route-utils.cjs');
|
|
12
|
+
const scanUtils = require('./scan-utils.cjs');
|
|
13
|
+
require('node:fs');
|
|
14
|
+
require('pathe');
|
|
15
|
+
require('jsonc-parser');
|
|
16
|
+
require('node:module');
|
|
17
|
+
require('node:os');
|
|
18
|
+
require('node:process');
|
|
19
|
+
require('node:url');
|
|
20
|
+
require('./path-utils.cjs');
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
exports.isPromise = configCore.isPromise;
|
|
25
|
+
exports.middlewareSymbol = configCore.middlewareSymbol;
|
|
26
|
+
exports.buildConfigChain = configUtils.buildConfigChain;
|
|
27
|
+
exports.findConfigFile = configUtils.findConfigFile;
|
|
28
|
+
exports.getConfigFileCandidates = configUtils.getConfigFileCandidates;
|
|
29
|
+
exports.normalizeMiddlewareList = configUtils.normalizeMiddlewareList;
|
|
30
|
+
exports.readMiddlewareMeta = configUtils.readMiddlewareMeta;
|
|
31
|
+
exports.resolveDirectoryConfig = configUtils.resolveDirectoryConfig;
|
|
32
|
+
exports.createDefineConfig = defineConfig.createDefineConfig;
|
|
33
|
+
exports.readJsoncFile = jsoncUtils.readJsoncFile;
|
|
34
|
+
exports.loadRules = loadRules.loadRules;
|
|
35
|
+
exports.collectFiles = mockFiles.collectFiles;
|
|
36
|
+
exports.isConfigFile = mockFiles.isConfigFile;
|
|
37
|
+
exports.isSupportedFile = mockFiles.isSupportedFile;
|
|
38
|
+
exports.createTsxConfigFile = moduleLoader.createTsxConfigFile;
|
|
39
|
+
exports.ensureTsxRegister = moduleLoader.ensureTsxRegister;
|
|
40
|
+
exports.loadModule = moduleLoader.loadModule;
|
|
41
|
+
exports.configExtensions = routeConstants.configExtensions;
|
|
42
|
+
exports.jsonExtensions = routeConstants.jsonExtensions;
|
|
43
|
+
exports.methodSet = routeConstants.methodSet;
|
|
44
|
+
exports.methodSuffixSet = routeConstants.methodSuffixSet;
|
|
45
|
+
exports.supportedExtensions = routeConstants.supportedExtensions;
|
|
46
|
+
exports.createRouteUtils = routeUtils.createRouteUtils;
|
|
47
|
+
exports.normalizeIgnorePrefix = scanUtils.normalizeIgnorePrefix;
|
|
48
|
+
exports.normalizeMethod = scanUtils.normalizeMethod;
|
|
49
|
+
exports.normalizePrefix = scanUtils.normalizePrefix;
|
|
50
|
+
exports.resolveDirs = scanUtils.resolveDirs;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,98 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* Shared entry options for mokup scanners and plugins.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* import type { MockEntryOptions } from '@mokup/shared'
|
|
15
|
-
*
|
|
16
|
-
* const entry: MockEntryOptions = {
|
|
17
|
-
* dir: 'mock',
|
|
18
|
-
* prefix: '/api',
|
|
19
|
-
* watch: true,
|
|
20
|
-
* }
|
|
21
|
-
*/
|
|
22
|
-
interface MockEntryOptions {
|
|
23
|
-
/**
|
|
24
|
-
* Directory (or directories) to scan for mock routes.
|
|
25
|
-
*
|
|
26
|
-
* @default "mock" (resolved by Vite/webpack plugins)
|
|
27
|
-
*/
|
|
28
|
-
dir?: DirInput;
|
|
29
|
-
/**
|
|
30
|
-
* Request path prefix to mount mock routes under.
|
|
31
|
-
*
|
|
32
|
-
* @default ""
|
|
33
|
-
*/
|
|
34
|
-
prefix?: string;
|
|
35
|
-
/**
|
|
36
|
-
* Include filter for files to scan.
|
|
37
|
-
*
|
|
38
|
-
* @default undefined
|
|
39
|
-
*/
|
|
40
|
-
include?: RegExp | RegExp[];
|
|
41
|
-
/**
|
|
42
|
-
* Exclude filter for files to scan.
|
|
43
|
-
*
|
|
44
|
-
* @default undefined
|
|
45
|
-
*/
|
|
46
|
-
exclude?: RegExp | RegExp[];
|
|
47
|
-
/**
|
|
48
|
-
* Ignore file or folder prefixes when scanning.
|
|
49
|
-
*
|
|
50
|
-
* @default ["."]
|
|
51
|
-
*/
|
|
52
|
-
ignorePrefix?: string | string[];
|
|
53
|
-
/**
|
|
54
|
-
* Enable file watching for live route updates.
|
|
55
|
-
*
|
|
56
|
-
* @default true
|
|
57
|
-
*/
|
|
58
|
-
watch?: boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Enable mokup logging.
|
|
61
|
-
*
|
|
62
|
-
* @default true
|
|
63
|
-
*/
|
|
64
|
-
log?: boolean;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Playground configuration input.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* import type { PlaygroundOptionsInput } from '@mokup/shared'
|
|
71
|
-
*
|
|
72
|
-
* const playground: PlaygroundOptionsInput = {
|
|
73
|
-
* path: '/__mokup',
|
|
74
|
-
* enabled: true,
|
|
75
|
-
* }
|
|
76
|
-
*/
|
|
77
|
-
type PlaygroundOptionsInput = boolean | {
|
|
78
|
-
/**
|
|
79
|
-
* Base path for the playground UI.
|
|
80
|
-
*
|
|
81
|
-
* @default "/__mokup"
|
|
82
|
-
*/
|
|
83
|
-
path?: string;
|
|
84
|
-
/**
|
|
85
|
-
* Emit playground assets during production builds.
|
|
86
|
-
*
|
|
87
|
-
* @default false
|
|
88
|
-
*/
|
|
89
|
-
build?: boolean;
|
|
90
|
-
/**
|
|
91
|
-
* Enable or disable the playground routes.
|
|
92
|
-
*
|
|
93
|
-
* @default true
|
|
94
|
-
*/
|
|
95
|
-
enabled?: boolean;
|
|
96
|
-
} | undefined;
|
|
97
|
-
|
|
98
|
-
export type { DirInput, MockEntryOptions, PlaygroundOptionsInput };
|
|
1
|
+
export { isPromise, middlewareSymbol } from './config-core.cjs';
|
|
2
|
+
export { ConfigSourceMap, MiddlewareMeta, MiddlewarePosition, buildConfigChain, findConfigFile, getConfigFileCandidates, normalizeMiddlewareList, readMiddlewareMeta, resolveDirectoryConfig } from './config-utils.cjs';
|
|
3
|
+
export { ConfigApp, DefineConfigFactory, HookErrorPolicy, HookHandler, createDefineConfig } from './define-config.cjs';
|
|
4
|
+
export { readJsoncFile } from './jsonc-utils.cjs';
|
|
5
|
+
export { loadRules } from './load-rules.cjs';
|
|
6
|
+
export { collectFiles, isConfigFile, isSupportedFile } from './mock-files.cjs';
|
|
7
|
+
export { createTsxConfigFile, ensureTsxRegister, loadModule } from './module-loader.cjs';
|
|
8
|
+
export { configExtensions, jsonExtensions, methodSet, methodSuffixSet, supportedExtensions } from './route-constants.cjs';
|
|
9
|
+
export { DerivedRoute, RouteParser, RouteParserResult, RouteScoreComparator, createRouteUtils } from './route-utils.cjs';
|
|
10
|
+
export { D as DirInput, M as MockEntryOptions, P as PlaygroundOptionsInput, normalizeIgnorePrefix, normalizeMethod, normalizePrefix, resolveDirs } from './scan-utils.cjs';
|
package/dist/index.d.mts
CHANGED
|
@@ -1,98 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
* Shared entry options for mokup scanners and plugins.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* import type { MockEntryOptions } from '@mokup/shared'
|
|
15
|
-
*
|
|
16
|
-
* const entry: MockEntryOptions = {
|
|
17
|
-
* dir: 'mock',
|
|
18
|
-
* prefix: '/api',
|
|
19
|
-
* watch: true,
|
|
20
|
-
* }
|
|
21
|
-
*/
|
|
22
|
-
interface MockEntryOptions {
|
|
23
|
-
/**
|
|
24
|
-
* Directory (or directories) to scan for mock routes.
|
|
25
|
-
*
|
|
26
|
-
* @default "mock" (resolved by Vite/webpack plugins)
|
|
27
|
-
*/
|
|
28
|
-
dir?: DirInput;
|
|
29
|
-
/**
|
|
30
|
-
* Request path prefix to mount mock routes under.
|
|
31
|
-
*
|
|
32
|
-
* @default ""
|
|
33
|
-
*/
|
|
34
|
-
prefix?: string;
|
|
35
|
-
/**
|
|
36
|
-
* Include filter for files to scan.
|
|
37
|
-
*
|
|
38
|
-
* @default undefined
|
|
39
|
-
*/
|
|
40
|
-
include?: RegExp | RegExp[];
|
|
41
|
-
/**
|
|
42
|
-
* Exclude filter for files to scan.
|
|
43
|
-
*
|
|
44
|
-
* @default undefined
|
|
45
|
-
*/
|
|
46
|
-
exclude?: RegExp | RegExp[];
|
|
47
|
-
/**
|
|
48
|
-
* Ignore file or folder prefixes when scanning.
|
|
49
|
-
*
|
|
50
|
-
* @default ["."]
|
|
51
|
-
*/
|
|
52
|
-
ignorePrefix?: string | string[];
|
|
53
|
-
/**
|
|
54
|
-
* Enable file watching for live route updates.
|
|
55
|
-
*
|
|
56
|
-
* @default true
|
|
57
|
-
*/
|
|
58
|
-
watch?: boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Enable mokup logging.
|
|
61
|
-
*
|
|
62
|
-
* @default true
|
|
63
|
-
*/
|
|
64
|
-
log?: boolean;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* Playground configuration input.
|
|
68
|
-
*
|
|
69
|
-
* @example
|
|
70
|
-
* import type { PlaygroundOptionsInput } from '@mokup/shared'
|
|
71
|
-
*
|
|
72
|
-
* const playground: PlaygroundOptionsInput = {
|
|
73
|
-
* path: '/__mokup',
|
|
74
|
-
* enabled: true,
|
|
75
|
-
* }
|
|
76
|
-
*/
|
|
77
|
-
type PlaygroundOptionsInput = boolean | {
|
|
78
|
-
/**
|
|
79
|
-
* Base path for the playground UI.
|
|
80
|
-
*
|
|
81
|
-
* @default "/__mokup"
|
|
82
|
-
*/
|
|
83
|
-
path?: string;
|
|
84
|
-
/**
|
|
85
|
-
* Emit playground assets during production builds.
|
|
86
|
-
*
|
|
87
|
-
* @default false
|
|
88
|
-
*/
|
|
89
|
-
build?: boolean;
|
|
90
|
-
/**
|
|
91
|
-
* Enable or disable the playground routes.
|
|
92
|
-
*
|
|
93
|
-
* @default true
|
|
94
|
-
*/
|
|
95
|
-
enabled?: boolean;
|
|
96
|
-
} | undefined;
|
|
97
|
-
|
|
98
|
-
export type { DirInput, MockEntryOptions, PlaygroundOptionsInput };
|
|
1
|
+
export { isPromise, middlewareSymbol } from './config-core.mjs';
|
|
2
|
+
export { ConfigSourceMap, MiddlewareMeta, MiddlewarePosition, buildConfigChain, findConfigFile, getConfigFileCandidates, normalizeMiddlewareList, readMiddlewareMeta, resolveDirectoryConfig } from './config-utils.mjs';
|
|
3
|
+
export { ConfigApp, DefineConfigFactory, HookErrorPolicy, HookHandler, createDefineConfig } from './define-config.mjs';
|
|
4
|
+
export { readJsoncFile } from './jsonc-utils.mjs';
|
|
5
|
+
export { loadRules } from './load-rules.mjs';
|
|
6
|
+
export { collectFiles, isConfigFile, isSupportedFile } from './mock-files.mjs';
|
|
7
|
+
export { createTsxConfigFile, ensureTsxRegister, loadModule } from './module-loader.mjs';
|
|
8
|
+
export { configExtensions, jsonExtensions, methodSet, methodSuffixSet, supportedExtensions } from './route-constants.mjs';
|
|
9
|
+
export { DerivedRoute, RouteParser, RouteParserResult, RouteScoreComparator, createRouteUtils } from './route-utils.mjs';
|
|
10
|
+
export { D as DirInput, M as MockEntryOptions, P as PlaygroundOptionsInput, normalizeIgnorePrefix, normalizeMethod, normalizePrefix, resolveDirs } from './scan-utils.mjs';
|