@mokup/shared 1.1.1 → 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.
Files changed (58) hide show
  1. package/dist/config-core.cjs +9 -0
  2. package/dist/config-core.d.cts +4 -0
  3. package/dist/config-core.d.mts +4 -0
  4. package/dist/config-core.d.ts +4 -0
  5. package/dist/config-core.mjs +6 -0
  6. package/dist/config-utils.cjs +179 -0
  7. package/dist/config-utils.d.cts +62 -0
  8. package/dist/config-utils.d.mts +62 -0
  9. package/dist/config-utils.d.ts +62 -0
  10. package/dist/config-utils.mjs +171 -0
  11. package/dist/define-config.cjs +168 -0
  12. package/dist/define-config.d.cts +20 -0
  13. package/dist/define-config.d.mts +20 -0
  14. package/dist/define-config.d.ts +20 -0
  15. package/dist/define-config.mjs +166 -0
  16. package/dist/index.cjs +48 -0
  17. package/dist/index.d.cts +10 -98
  18. package/dist/index.d.mts +10 -98
  19. package/dist/index.d.ts +10 -98
  20. package/dist/index.mjs +18 -1
  21. package/dist/jsonc-utils.cjs +25 -0
  22. package/dist/jsonc-utils.d.cts +7 -0
  23. package/dist/jsonc-utils.d.mts +7 -0
  24. package/dist/jsonc-utils.d.ts +7 -0
  25. package/dist/jsonc-utils.mjs +23 -0
  26. package/dist/load-rules.cjs +39 -0
  27. package/dist/load-rules.d.cts +14 -0
  28. package/dist/load-rules.d.mts +14 -0
  29. package/dist/load-rules.d.ts +14 -0
  30. package/dist/load-rules.mjs +37 -0
  31. package/dist/mock-files.cjs +65 -0
  32. package/dist/mock-files.d.cts +10 -0
  33. package/dist/mock-files.d.mts +10 -0
  34. package/dist/mock-files.d.ts +10 -0
  35. package/dist/mock-files.mjs +61 -0
  36. package/dist/module-loader.cjs +93 -0
  37. package/dist/module-loader.d.cts +13 -0
  38. package/dist/module-loader.d.mts +13 -0
  39. package/dist/module-loader.d.ts +13 -0
  40. package/dist/module-loader.mjs +83 -0
  41. package/dist/path-utils.cjs +2 -2
  42. package/dist/playground-grouping.cjs +3 -3
  43. package/dist/route-constants.cjs +30 -0
  44. package/dist/route-constants.d.cts +7 -0
  45. package/dist/route-constants.d.mts +7 -0
  46. package/dist/route-constants.d.ts +7 -0
  47. package/dist/route-constants.mjs +24 -0
  48. package/dist/route-utils.cjs +126 -0
  49. package/dist/route-utils.d.cts +42 -0
  50. package/dist/route-utils.d.mts +42 -0
  51. package/dist/route-utils.d.ts +42 -0
  52. package/dist/route-utils.mjs +124 -0
  53. package/dist/scan-utils.cjs +39 -0
  54. package/dist/scan-utils.d.cts +114 -0
  55. package/dist/scan-utils.d.mts +114 -0
  56. package/dist/scan-utils.d.ts +114 -0
  57. package/dist/scan-utils.mjs +34 -0
  58. package/package.json +67 -19
@@ -0,0 +1,114 @@
1
+ import './config-core.cjs';
2
+ import './config-utils.cjs';
3
+ import './define-config.cjs';
4
+ import './jsonc-utils.cjs';
5
+ import './load-rules.cjs';
6
+ import './mock-files.cjs';
7
+ import './module-loader.cjs';
8
+ import './route-constants.cjs';
9
+ import './route-utils.cjs';
10
+
11
+ declare function normalizeMethod(method?: string | null): string | undefined;
12
+ declare function normalizePrefix(prefix: string): string;
13
+ declare function resolveDirs(dir: DirInput, root: string): string[];
14
+ declare function normalizeIgnorePrefix(value: string | string[] | undefined, fallback?: string[]): string[];
15
+
16
+ /**
17
+ * Directory input for mock scanning.
18
+ *
19
+ * @example
20
+ * import type { DirInput } from '@mokup/shared'
21
+ *
22
+ * const dir: DirInput = ['mock', 'fixtures']
23
+ */
24
+ type DirInput = string | string[] | ((root: string) => string | string[]) | undefined;
25
+ /**
26
+ * Shared entry options for mokup scanners and plugins.
27
+ *
28
+ * @example
29
+ * import type { MockEntryOptions } from '@mokup/shared'
30
+ *
31
+ * const entry: MockEntryOptions = {
32
+ * dir: 'mock',
33
+ * prefix: '/api',
34
+ * watch: true,
35
+ * }
36
+ */
37
+ interface MockEntryOptions {
38
+ /**
39
+ * Directory (or directories) to scan for mock routes.
40
+ *
41
+ * @default "mock" (resolved by Vite/webpack plugins)
42
+ */
43
+ dir?: DirInput;
44
+ /**
45
+ * Request path prefix to mount mock routes under.
46
+ *
47
+ * @default ""
48
+ */
49
+ prefix?: string;
50
+ /**
51
+ * Include filter for files to scan.
52
+ *
53
+ * @default undefined
54
+ */
55
+ include?: RegExp | RegExp[];
56
+ /**
57
+ * Exclude filter for files to scan.
58
+ *
59
+ * @default undefined
60
+ */
61
+ exclude?: RegExp | RegExp[];
62
+ /**
63
+ * Ignore file or folder prefixes when scanning.
64
+ *
65
+ * @default ["."]
66
+ */
67
+ ignorePrefix?: string | string[];
68
+ /**
69
+ * Enable file watching for live route updates.
70
+ *
71
+ * @default true
72
+ */
73
+ watch?: boolean;
74
+ /**
75
+ * Enable mokup logging.
76
+ *
77
+ * @default true
78
+ */
79
+ log?: boolean;
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
+
113
+ export { normalizeIgnorePrefix, normalizeMethod, normalizePrefix, resolveDirs };
114
+ export type { DirInput as D, MockEntryOptions as M, PlaygroundOptionsInput as P };
@@ -0,0 +1,114 @@
1
+ import './config-core.mjs';
2
+ import './config-utils.mjs';
3
+ import './define-config.mjs';
4
+ import './jsonc-utils.mjs';
5
+ import './load-rules.mjs';
6
+ import './mock-files.mjs';
7
+ import './module-loader.mjs';
8
+ import './route-constants.mjs';
9
+ import './route-utils.mjs';
10
+
11
+ declare function normalizeMethod(method?: string | null): string | undefined;
12
+ declare function normalizePrefix(prefix: string): string;
13
+ declare function resolveDirs(dir: DirInput, root: string): string[];
14
+ declare function normalizeIgnorePrefix(value: string | string[] | undefined, fallback?: string[]): string[];
15
+
16
+ /**
17
+ * Directory input for mock scanning.
18
+ *
19
+ * @example
20
+ * import type { DirInput } from '@mokup/shared'
21
+ *
22
+ * const dir: DirInput = ['mock', 'fixtures']
23
+ */
24
+ type DirInput = string | string[] | ((root: string) => string | string[]) | undefined;
25
+ /**
26
+ * Shared entry options for mokup scanners and plugins.
27
+ *
28
+ * @example
29
+ * import type { MockEntryOptions } from '@mokup/shared'
30
+ *
31
+ * const entry: MockEntryOptions = {
32
+ * dir: 'mock',
33
+ * prefix: '/api',
34
+ * watch: true,
35
+ * }
36
+ */
37
+ interface MockEntryOptions {
38
+ /**
39
+ * Directory (or directories) to scan for mock routes.
40
+ *
41
+ * @default "mock" (resolved by Vite/webpack plugins)
42
+ */
43
+ dir?: DirInput;
44
+ /**
45
+ * Request path prefix to mount mock routes under.
46
+ *
47
+ * @default ""
48
+ */
49
+ prefix?: string;
50
+ /**
51
+ * Include filter for files to scan.
52
+ *
53
+ * @default undefined
54
+ */
55
+ include?: RegExp | RegExp[];
56
+ /**
57
+ * Exclude filter for files to scan.
58
+ *
59
+ * @default undefined
60
+ */
61
+ exclude?: RegExp | RegExp[];
62
+ /**
63
+ * Ignore file or folder prefixes when scanning.
64
+ *
65
+ * @default ["."]
66
+ */
67
+ ignorePrefix?: string | string[];
68
+ /**
69
+ * Enable file watching for live route updates.
70
+ *
71
+ * @default true
72
+ */
73
+ watch?: boolean;
74
+ /**
75
+ * Enable mokup logging.
76
+ *
77
+ * @default true
78
+ */
79
+ log?: boolean;
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
+
113
+ export { normalizeIgnorePrefix, normalizeMethod, normalizePrefix, resolveDirs };
114
+ export type { DirInput as D, MockEntryOptions as M, PlaygroundOptionsInput as P };
@@ -0,0 +1,114 @@
1
+ import './config-core.js';
2
+ import './config-utils.js';
3
+ import './define-config.js';
4
+ import './jsonc-utils.js';
5
+ import './load-rules.js';
6
+ import './mock-files.js';
7
+ import './module-loader.js';
8
+ import './route-constants.js';
9
+ import './route-utils.js';
10
+
11
+ declare function normalizeMethod(method?: string | null): string | undefined;
12
+ declare function normalizePrefix(prefix: string): string;
13
+ declare function resolveDirs(dir: DirInput, root: string): string[];
14
+ declare function normalizeIgnorePrefix(value: string | string[] | undefined, fallback?: string[]): string[];
15
+
16
+ /**
17
+ * Directory input for mock scanning.
18
+ *
19
+ * @example
20
+ * import type { DirInput } from '@mokup/shared'
21
+ *
22
+ * const dir: DirInput = ['mock', 'fixtures']
23
+ */
24
+ type DirInput = string | string[] | ((root: string) => string | string[]) | undefined;
25
+ /**
26
+ * Shared entry options for mokup scanners and plugins.
27
+ *
28
+ * @example
29
+ * import type { MockEntryOptions } from '@mokup/shared'
30
+ *
31
+ * const entry: MockEntryOptions = {
32
+ * dir: 'mock',
33
+ * prefix: '/api',
34
+ * watch: true,
35
+ * }
36
+ */
37
+ interface MockEntryOptions {
38
+ /**
39
+ * Directory (or directories) to scan for mock routes.
40
+ *
41
+ * @default "mock" (resolved by Vite/webpack plugins)
42
+ */
43
+ dir?: DirInput;
44
+ /**
45
+ * Request path prefix to mount mock routes under.
46
+ *
47
+ * @default ""
48
+ */
49
+ prefix?: string;
50
+ /**
51
+ * Include filter for files to scan.
52
+ *
53
+ * @default undefined
54
+ */
55
+ include?: RegExp | RegExp[];
56
+ /**
57
+ * Exclude filter for files to scan.
58
+ *
59
+ * @default undefined
60
+ */
61
+ exclude?: RegExp | RegExp[];
62
+ /**
63
+ * Ignore file or folder prefixes when scanning.
64
+ *
65
+ * @default ["."]
66
+ */
67
+ ignorePrefix?: string | string[];
68
+ /**
69
+ * Enable file watching for live route updates.
70
+ *
71
+ * @default true
72
+ */
73
+ watch?: boolean;
74
+ /**
75
+ * Enable mokup logging.
76
+ *
77
+ * @default true
78
+ */
79
+ log?: boolean;
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
+
113
+ export { normalizeIgnorePrefix, normalizeMethod, normalizePrefix, resolveDirs };
114
+ export type { DirInput as D, MockEntryOptions as M, PlaygroundOptionsInput as P };
@@ -0,0 +1,34 @@
1
+ import { resolve, isAbsolute } from 'pathe';
2
+ import { methodSet } from './route-constants.mjs';
3
+
4
+ function normalizeMethod(method) {
5
+ if (!method) {
6
+ return void 0;
7
+ }
8
+ const normalized = method.toUpperCase();
9
+ if (methodSet.has(normalized)) {
10
+ return normalized;
11
+ }
12
+ return void 0;
13
+ }
14
+ function normalizePrefix(prefix) {
15
+ if (!prefix) {
16
+ return "";
17
+ }
18
+ const normalized = prefix.startsWith("/") ? prefix : `/${prefix}`;
19
+ return normalized.endsWith("/") ? normalized.slice(0, -1) : normalized;
20
+ }
21
+ function resolveDirs(dir, root) {
22
+ const raw = typeof dir === "function" ? dir(root) : dir;
23
+ const resolved = Array.isArray(raw) ? raw : raw ? [raw] : ["mock"];
24
+ const normalized = resolved.map(
25
+ (entry) => isAbsolute(entry) ? entry : resolve(root, entry)
26
+ );
27
+ return Array.from(new Set(normalized));
28
+ }
29
+ function normalizeIgnorePrefix(value, fallback = ["."]) {
30
+ const list = typeof value === "undefined" ? fallback : Array.isArray(value) ? value : [value];
31
+ return list.filter((entry) => typeof entry === "string" && entry.length > 0);
32
+ }
33
+
34
+ export { normalizeIgnorePrefix, normalizeMethod, normalizePrefix, resolveDirs };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mokup/shared",
3
3
  "type": "module",
4
- "version": "1.1.1",
4
+ "version": "1.1.2",
5
5
  "description": "Shared dependency exports for mokup.",
6
6
  "license": "MIT",
7
7
  "homepage": "https://mokup.icebreaker.top",
@@ -16,21 +16,51 @@
16
16
  "import": "./dist/index.mjs",
17
17
  "require": "./dist/index.cjs"
18
18
  },
19
- "./esbuild": {
20
- "types": "./dist/esbuild.d.ts",
21
- "import": "./dist/esbuild.mjs",
22
- "require": "./dist/esbuild.cjs"
23
- },
24
19
  "./chokidar": {
25
20
  "types": "./dist/chokidar.d.ts",
26
21
  "import": "./dist/chokidar.mjs",
27
22
  "require": "./dist/chokidar.cjs"
28
23
  },
24
+ "./config-utils": {
25
+ "types": "./dist/config-utils.d.ts",
26
+ "import": "./dist/config-utils.mjs",
27
+ "require": "./dist/config-utils.cjs"
28
+ },
29
+ "./config-core": {
30
+ "types": "./dist/config-core.d.ts",
31
+ "import": "./dist/config-core.mjs",
32
+ "require": "./dist/config-core.cjs"
33
+ },
34
+ "./define-config": {
35
+ "types": "./dist/define-config.d.ts",
36
+ "import": "./dist/define-config.mjs",
37
+ "require": "./dist/define-config.cjs"
38
+ },
39
+ "./esbuild": {
40
+ "types": "./dist/esbuild.d.ts",
41
+ "import": "./dist/esbuild.mjs",
42
+ "require": "./dist/esbuild.cjs"
43
+ },
29
44
  "./hono": {
30
45
  "types": "./dist/hono.d.ts",
31
46
  "import": "./dist/hono.mjs",
32
47
  "require": "./dist/hono.cjs"
33
48
  },
49
+ "./jsonc-parser": {
50
+ "types": "./dist/jsonc-parser.d.ts",
51
+ "import": "./dist/jsonc-parser.mjs",
52
+ "require": "./dist/jsonc-parser.cjs"
53
+ },
54
+ "./jsonc-utils": {
55
+ "types": "./dist/jsonc-utils.d.ts",
56
+ "import": "./dist/jsonc-utils.mjs",
57
+ "require": "./dist/jsonc-utils.cjs"
58
+ },
59
+ "./load-rules": {
60
+ "types": "./dist/load-rules.d.ts",
61
+ "import": "./dist/load-rules.mjs",
62
+ "require": "./dist/load-rules.cjs"
63
+ },
34
64
  "./logger": {
35
65
  "types": "./dist/logger.d.ts",
36
66
  "browser": "./dist/logger.browser.mjs",
@@ -38,6 +68,16 @@
38
68
  "import": "./dist/logger.mjs",
39
69
  "require": "./dist/logger.cjs"
40
70
  },
71
+ "./mock-files": {
72
+ "types": "./dist/mock-files.d.ts",
73
+ "import": "./dist/mock-files.mjs",
74
+ "require": "./dist/mock-files.cjs"
75
+ },
76
+ "./module-loader": {
77
+ "types": "./dist/module-loader.d.ts",
78
+ "import": "./dist/module-loader.mjs",
79
+ "require": "./dist/module-loader.cjs"
80
+ },
41
81
  "./pathe": {
42
82
  "types": "./dist/pathe.d.ts",
43
83
  "import": "./dist/pathe.mjs",
@@ -53,15 +93,25 @@
53
93
  "import": "./dist/playground-grouping.mjs",
54
94
  "require": "./dist/playground-grouping.cjs"
55
95
  },
96
+ "./route-constants": {
97
+ "types": "./dist/route-constants.d.ts",
98
+ "import": "./dist/route-constants.mjs",
99
+ "require": "./dist/route-constants.cjs"
100
+ },
101
+ "./route-utils": {
102
+ "types": "./dist/route-utils.d.ts",
103
+ "import": "./dist/route-utils.mjs",
104
+ "require": "./dist/route-utils.cjs"
105
+ },
106
+ "./scan-utils": {
107
+ "types": "./dist/scan-utils.d.ts",
108
+ "import": "./dist/scan-utils.mjs",
109
+ "require": "./dist/scan-utils.cjs"
110
+ },
56
111
  "./timing": {
57
112
  "types": "./dist/timing.d.ts",
58
113
  "import": "./dist/timing.mjs",
59
114
  "require": "./dist/timing.cjs"
60
- },
61
- "./jsonc-parser": {
62
- "types": "./dist/jsonc-parser.d.ts",
63
- "import": "./dist/jsonc-parser.mjs",
64
- "require": "./dist/jsonc-parser.cjs"
65
115
  }
66
116
  },
67
117
  "publishConfig": {
@@ -77,18 +127,16 @@
77
127
  "chokidar": "^5.0.0",
78
128
  "consola": "^3.4.2",
79
129
  "esbuild": "^0.27.2",
80
- "hono": "^4.11.5",
130
+ "hono": "^4.11.7",
81
131
  "jsonc-parser": "^3.3.1",
82
- "pathe": "^2.0.3"
83
- },
84
- "devDependencies": {
85
- "typescript": "^5.9.3",
86
- "unbuild": "^3.6.1"
132
+ "pathe": "^2.0.3",
133
+ "tsx": "^4.21.0"
87
134
  },
88
135
  "scripts": {
89
- "build": "unbuild",
136
+ "build": "cross-env NODE_OPTIONS=--max-old-space-size=4096 unbuild",
90
137
  "dev": "unbuild --stub",
91
138
  "lint": "eslint .",
92
- "typecheck": "tsc -p tsconfig.json --noEmit"
139
+ "typecheck": "tsc -p tsconfig.json --noEmit",
140
+ "test:types": "tsd"
93
141
  }
94
142
  }