@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.
Files changed (143) hide show
  1. package/README.md +58 -0
  2. package/dist/chokidar.d.mts +3 -8
  3. package/dist/chokidar.d.ts +3 -9
  4. package/dist/chokidar.mjs +2 -1
  5. package/dist/chunk-_iGcCiPk.mjs +28 -0
  6. package/dist/config-core-dqVMz7on.d.mts +5 -0
  7. package/dist/config-core-dqVMz7on.d.ts +5 -0
  8. package/dist/config-core.d.mts +2 -4
  9. package/dist/config-core.d.ts +2 -4
  10. package/dist/config-core.mjs +3 -2
  11. package/dist/config-utils-DFu0_9tl.d.mts +59 -0
  12. package/dist/config-utils-DFu0_9tl.d.ts +59 -0
  13. package/dist/config-utils.d.mts +3 -62
  14. package/dist/config-utils.d.ts +3 -62
  15. package/dist/config-utils.mjs +143 -159
  16. package/dist/define-config-CzB1-X1m.d.mts +20 -0
  17. package/dist/define-config-CzB1-X1m.d.ts +20 -0
  18. package/dist/define-config.d.mts +2 -20
  19. package/dist/define-config.d.ts +2 -20
  20. package/dist/define-config.mjs +146 -161
  21. package/dist/diagnostic-types-DqAzUbgn.d.mts +39 -0
  22. package/dist/diagnostic-types-DqAzUbgn.d.ts +39 -0
  23. package/dist/diagnostic-types.d.mts +2 -0
  24. package/dist/diagnostic-types.d.ts +2 -0
  25. package/dist/diagnostic-types.mjs +29 -0
  26. package/dist/diagnostics-C3QaEtqE.d.mts +101 -0
  27. package/dist/diagnostics-C3QaEtqE.d.ts +101 -0
  28. package/dist/diagnostics.d.mts +2 -0
  29. package/dist/diagnostics.d.ts +2 -0
  30. package/dist/diagnostics.mjs +129 -0
  31. package/dist/hono.d.mts +4 -3
  32. package/dist/hono.d.ts +4 -3
  33. package/dist/hono.mjs +4 -3
  34. package/dist/index-5prVUGOX.d.mts +113 -0
  35. package/dist/index-5prVUGOX.d.ts +113 -0
  36. package/dist/index.d.mts +13 -10
  37. package/dist/index.d.ts +13 -10
  38. package/dist/index.mjs +13 -18
  39. package/dist/jsonc-parser.d.mts +1 -1
  40. package/dist/jsonc-parser.d.ts +1 -1
  41. package/dist/jsonc-parser.mjs +8 -1
  42. package/dist/jsonc-utils-_Hs6a39T.d.mts +7 -0
  43. package/dist/jsonc-utils-_Hs6a39T.d.ts +7 -0
  44. package/dist/jsonc-utils.d.mts +2 -7
  45. package/dist/jsonc-utils.d.ts +2 -7
  46. package/dist/jsonc-utils.mjs +20 -20
  47. package/dist/load-rules-D_kCpu9I.d.mts +14 -0
  48. package/dist/load-rules-D_kCpu9I.d.ts +14 -0
  49. package/dist/load-rules.d.mts +2 -14
  50. package/dist/load-rules.d.ts +2 -14
  51. package/dist/load-rules.mjs +16 -34
  52. package/dist/logger-types-BbqYCr6j.d.mts +50 -0
  53. package/dist/logger-types-BbqYCr6j.d.ts +50 -0
  54. package/dist/logger.browser.d.mts +4 -3
  55. package/dist/logger.browser.d.ts +4 -3
  56. package/dist/logger.browser.mjs +49 -48
  57. package/dist/logger.d.mts +4 -3
  58. package/dist/logger.d.ts +4 -3
  59. package/dist/logger.mjs +49 -48
  60. package/dist/{mock-files.d.cts → mock-files-DfGigWmY.d.mts} +5 -5
  61. package/dist/mock-files-DfGigWmY.d.ts +10 -0
  62. package/dist/mock-files.d.mts +2 -10
  63. package/dist/mock-files.d.ts +2 -10
  64. package/dist/mock-files.mjs +38 -50
  65. package/dist/{module-loader.d.cts → module-loader-nAQlwo3D.d.mts} +7 -6
  66. package/dist/module-loader-nAQlwo3D.d.ts +14 -0
  67. package/dist/module-loader.d.mts +2 -13
  68. package/dist/module-loader.d.ts +2 -13
  69. package/dist/module-loader.mjs +60 -69
  70. package/dist/path-utils.d.mts +3 -2
  71. package/dist/path-utils.d.ts +3 -2
  72. package/dist/path-utils.mjs +25 -35
  73. package/dist/pathe.d.mts +1 -1
  74. package/dist/pathe.d.ts +1 -1
  75. package/dist/pathe.mjs +8 -1
  76. package/dist/playground-grouping.d.mts +6 -6
  77. package/dist/playground-grouping.d.ts +6 -6
  78. package/dist/playground-grouping.mjs +57 -77
  79. package/dist/rolldown.d.mts +37 -0
  80. package/dist/rolldown.d.ts +37 -0
  81. package/dist/rolldown.mjs +81 -0
  82. package/dist/{route-constants.d.cts → route-constants-BUi36iYR.d.mts} +3 -2
  83. package/dist/route-constants-BUi36iYR.d.ts +8 -0
  84. package/dist/route-constants.d.mts +2 -7
  85. package/dist/route-constants.d.ts +2 -7
  86. package/dist/route-constants.mjs +25 -21
  87. package/dist/route-utils-BiWFUqo-.d.mts +42 -0
  88. package/dist/route-utils-BiWFUqo-.d.ts +42 -0
  89. package/dist/route-utils.d.mts +2 -42
  90. package/dist/route-utils.d.ts +2 -42
  91. package/dist/route-utils.mjs +94 -121
  92. package/dist/scan-utils.d.mts +2 -114
  93. package/dist/scan-utils.d.ts +2 -114
  94. package/dist/scan-utils.mjs +14 -25
  95. package/dist/timing.d.mts +3 -2
  96. package/dist/timing.d.ts +3 -2
  97. package/dist/timing.mjs +11 -12
  98. package/package.json +88 -128
  99. package/dist/chokidar.cjs +0 -11
  100. package/dist/chokidar.d.cts +0 -9
  101. package/dist/config-core.cjs +0 -9
  102. package/dist/config-core.d.cts +0 -4
  103. package/dist/config-utils.cjs +0 -179
  104. package/dist/config-utils.d.cts +0 -62
  105. package/dist/define-config.cjs +0 -168
  106. package/dist/define-config.d.cts +0 -20
  107. package/dist/esbuild.cjs +0 -16
  108. package/dist/esbuild.d.cts +0 -1
  109. package/dist/esbuild.d.mts +0 -1
  110. package/dist/esbuild.d.ts +0 -1
  111. package/dist/esbuild.mjs +0 -1
  112. package/dist/hono.cjs +0 -20
  113. package/dist/hono.d.cts +0 -3
  114. package/dist/index.cjs +0 -50
  115. package/dist/index.d.cts +0 -10
  116. package/dist/jsonc-parser.cjs +0 -16
  117. package/dist/jsonc-parser.d.cts +0 -1
  118. package/dist/jsonc-utils.cjs +0 -25
  119. package/dist/jsonc-utils.d.cts +0 -7
  120. package/dist/load-rules.cjs +0 -39
  121. package/dist/load-rules.d.cts +0 -14
  122. package/dist/logger.browser.cjs +0 -55
  123. package/dist/logger.browser.d.cts +0 -21
  124. package/dist/logger.cjs +0 -55
  125. package/dist/logger.d.cts +0 -21
  126. package/dist/mock-files.cjs +0 -65
  127. package/dist/module-loader.cjs +0 -93
  128. package/dist/path-utils.cjs +0 -57
  129. package/dist/path-utils.d.cts +0 -7
  130. package/dist/pathe.cjs +0 -16
  131. package/dist/pathe.d.cts +0 -1
  132. package/dist/playground-grouping.cjs +0 -95
  133. package/dist/playground-grouping.d.cts +0 -12
  134. package/dist/route-constants.cjs +0 -30
  135. package/dist/route-utils.cjs +0 -126
  136. package/dist/route-utils.d.cts +0 -42
  137. package/dist/scan-utils.cjs +0 -39
  138. package/dist/scan-utils.d.cts +0 -114
  139. package/dist/shared/shared.DazgCdsk.d.cts +0 -49
  140. package/dist/shared/shared.DazgCdsk.d.mts +0 -49
  141. package/dist/shared/shared.DazgCdsk.d.ts +0 -49
  142. package/dist/timing.cjs +0 -20
  143. package/dist/timing.d.cts +0 -4
@@ -1,83 +1,74 @@
1
- import { writeFileSync } from 'node:fs';
2
- import { createRequire } from 'node:module';
3
- import { tmpdir } from 'node:os';
4
- import process from 'node:process';
5
- import { pathToFileURL } from 'node:url';
6
- import { resolve, extname } from 'pathe';
7
-
1
+ import { t as pathe_exports } from "./pathe.mjs";
2
+ import { createRequire } from "node:module";
3
+ import { writeFileSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import process from "node:process";
6
+ import { pathToFileURL } from "node:url";
7
+ //#region src/module-loader.ts
8
8
  function createTsxConfigFile(options) {
9
- const config = {
10
- compilerOptions: {
11
- baseUrl: options.baseUrl,
12
- paths: options.paths
13
- }
14
- };
15
- const configPath = options.fileName ?? resolve(tmpdir(), `mokup-tsx-${process.pid}.json`);
16
- writeFileSync(configPath, `${JSON.stringify(config, null, 2)}
17
- `, "utf8");
18
- return configPath;
9
+ const config = { compilerOptions: {
10
+ baseUrl: options.baseUrl,
11
+ paths: options.paths
12
+ } };
13
+ const configPath = options.fileName ?? (0, pathe_exports.resolve)(tmpdir(), `mokup-tsx-${process.pid}.json`);
14
+ writeFileSync(configPath, `${JSON.stringify(config, null, 2)}\n`, "utf8");
15
+ return configPath;
19
16
  }
20
17
  let sourceMapsEnabled = false;
21
18
  let tsxRegisterPromise = null;
22
19
  let tsxRegisteredConfig = null;
23
20
  function resetModuleLoaderForTests() {
24
- sourceMapsEnabled = false;
25
- tsxRegisterPromise = null;
26
- tsxRegisteredConfig = null;
21
+ sourceMapsEnabled = false;
22
+ tsxRegisterPromise = null;
23
+ tsxRegisteredConfig = null;
27
24
  }
28
25
  function ensureSourceMapsEnabled() {
29
- if (sourceMapsEnabled) {
30
- return;
31
- }
32
- const setSourceMapsEnabled = process.setSourceMapsEnabled;
33
- if (typeof setSourceMapsEnabled === "function") {
34
- setSourceMapsEnabled(true);
35
- }
36
- sourceMapsEnabled = true;
26
+ if (sourceMapsEnabled) return;
27
+ const setSourceMapsEnabled = process.setSourceMapsEnabled;
28
+ if (typeof setSourceMapsEnabled === "function") setSourceMapsEnabled(true);
29
+ sourceMapsEnabled = true;
37
30
  }
38
31
  async function ensureTsxRegister(tsconfigPath) {
39
- const desired = tsconfigPath ?? null;
40
- if (tsxRegisterPromise) {
41
- await tsxRegisterPromise;
42
- if (desired && tsxRegisteredConfig !== desired) {
43
- tsxRegisterPromise = (async () => {
44
- ensureSourceMapsEnabled();
45
- const { register } = await import('tsx/esm/api');
46
- register({ tsconfig: desired });
47
- tsxRegisteredConfig = desired;
48
- })();
49
- await tsxRegisterPromise;
50
- }
51
- return tsxRegisterPromise;
52
- }
53
- tsxRegisterPromise = (async () => {
54
- ensureSourceMapsEnabled();
55
- const { register } = await import('tsx/esm/api');
56
- if (desired) {
57
- register({ tsconfig: desired });
58
- tsxRegisteredConfig = desired;
59
- } else {
60
- register();
61
- tsxRegisteredConfig = null;
62
- }
63
- })();
64
- return tsxRegisterPromise;
32
+ const desired = tsconfigPath ?? null;
33
+ if (tsxRegisterPromise) {
34
+ await tsxRegisterPromise;
35
+ if (desired && tsxRegisteredConfig !== desired) {
36
+ tsxRegisterPromise = (async () => {
37
+ ensureSourceMapsEnabled();
38
+ const { register } = await import("tsx/esm/api");
39
+ register({ tsconfig: desired });
40
+ tsxRegisteredConfig = desired;
41
+ })();
42
+ await tsxRegisterPromise;
43
+ }
44
+ return tsxRegisterPromise;
45
+ }
46
+ tsxRegisterPromise = (async () => {
47
+ ensureSourceMapsEnabled();
48
+ const { register } = await import("tsx/esm/api");
49
+ if (desired) {
50
+ register({ tsconfig: desired });
51
+ tsxRegisteredConfig = desired;
52
+ } else {
53
+ register();
54
+ tsxRegisteredConfig = null;
55
+ }
56
+ })();
57
+ return tsxRegisterPromise;
65
58
  }
66
59
  async function loadModule(file, options) {
67
- const ext = extname(file).toLowerCase();
68
- if (ext === ".cjs") {
69
- const require = createRequire(import.meta.url);
70
- delete require.cache[file];
71
- return require(file);
72
- }
73
- if (ext === ".js" || ext === ".mjs") {
74
- return import(`${pathToFileURL(file).href}?t=${Date.now()}`);
75
- }
76
- if (ext === ".ts") {
77
- await ensureTsxRegister(options?.tsconfigPath ?? null);
78
- return import(`${pathToFileURL(file).href}?t=${Date.now()}`);
79
- }
80
- return null;
60
+ const ext = (0, pathe_exports.extname)(file).toLowerCase();
61
+ if (ext === ".cjs") {
62
+ const require = createRequire(import.meta.url);
63
+ delete require.cache[file];
64
+ return require(file);
65
+ }
66
+ if (ext === ".js" || ext === ".mjs") return import(`${pathToFileURL(file).href}?t=${Date.now()}`);
67
+ if (ext === ".ts") {
68
+ await ensureTsxRegister(options?.tsconfigPath ?? null);
69
+ return import(`${pathToFileURL(file).href}?t=${Date.now()}`);
70
+ }
71
+ return null;
81
72
  }
82
-
73
+ //#endregion
83
74
  export { createTsxConfigFile, ensureTsxRegister, loadModule, resetModuleLoaderForTests };
@@ -1,7 +1,8 @@
1
+ //#region src/path-utils.d.ts
1
2
  declare function toPosix(value: string): string;
2
3
  declare function normalizePathForComparison(value: string): string;
3
4
  declare function isInDirs(file: string, dirs: string[]): boolean;
4
5
  declare function matchesFilter(file: string, include?: RegExp | RegExp[], exclude?: RegExp | RegExp[]): boolean;
5
6
  declare function hasIgnoredPrefix(file: string, rootDir: string, prefixes: string[]): boolean;
6
-
7
- export { hasIgnoredPrefix, isInDirs, matchesFilter, normalizePathForComparison, toPosix };
7
+ //#endregion
8
+ export { hasIgnoredPrefix, isInDirs, matchesFilter, normalizePathForComparison, toPosix };
@@ -1,7 +1,8 @@
1
+ //#region src/path-utils.d.ts
1
2
  declare function toPosix(value: string): string;
2
3
  declare function normalizePathForComparison(value: string): string;
3
4
  declare function isInDirs(file: string, dirs: string[]): boolean;
4
5
  declare function matchesFilter(file: string, include?: RegExp | RegExp[], exclude?: RegExp | RegExp[]): boolean;
5
6
  declare function hasIgnoredPrefix(file: string, rootDir: string, prefixes: string[]): boolean;
6
-
7
- export { hasIgnoredPrefix, isInDirs, matchesFilter, normalizePathForComparison, toPosix };
7
+ //#endregion
8
+ export { hasIgnoredPrefix, isInDirs, matchesFilter, normalizePathForComparison, toPosix };
@@ -1,51 +1,41 @@
1
- import { platform } from 'node:process';
2
- import { relative, normalize } from 'pathe';
3
-
1
+ import { normalize, relative } from "pathe";
2
+ import { platform } from "node:process";
3
+ //#region src/path-utils.ts
4
+ const WINDOWS_DRIVE_RE = /^[a-z]:\//i;
5
+ const WINDOWS_SEPARATOR_RE = /\\/g;
6
+ const TRAILING_SLASH_RE = /\/$/;
4
7
  function isWindowsLikePath(normalized) {
5
- return platform === "win32" || /^[a-z]:\//i.test(normalized) || normalized.startsWith("//");
8
+ return platform === "win32" || WINDOWS_DRIVE_RE.test(normalized) || normalized.startsWith("//");
6
9
  }
7
10
  function toPosix(value) {
8
- return value.replace(/\\/g, "/");
11
+ return value.replace(WINDOWS_SEPARATOR_RE, "/");
9
12
  }
10
13
  function normalizePath(value) {
11
- return normalize(toPosix(value));
14
+ return normalize(toPosix(value));
12
15
  }
13
16
  function normalizePathForComparison(value) {
14
- const normalized = normalizePath(value);
15
- return isWindowsLikePath(normalized) ? normalized.toLowerCase() : normalized;
17
+ const normalized = normalizePath(value);
18
+ return isWindowsLikePath(normalized) ? normalized.toLowerCase() : normalized;
16
19
  }
17
20
  function isInDirs(file, dirs) {
18
- const normalized = normalizePathForComparison(file);
19
- return dirs.some((dir) => {
20
- const normalizedDir = normalizePathForComparison(dir).replace(/\/$/, "");
21
- return normalized === normalizedDir || normalized.startsWith(`${normalizedDir}/`);
22
- });
21
+ const normalized = normalizePathForComparison(file);
22
+ return dirs.some((dir) => {
23
+ const normalizedDir = normalizePathForComparison(dir).replace(TRAILING_SLASH_RE, "");
24
+ return normalized === normalizedDir || normalized.startsWith(`${normalizedDir}/`);
25
+ });
23
26
  }
24
27
  function testPatterns(patterns, value) {
25
- const list = Array.isArray(patterns) ? patterns : [patterns];
26
- return list.some((pattern) => pattern.test(value));
28
+ return (Array.isArray(patterns) ? patterns : [patterns]).some((pattern) => pattern.test(value));
27
29
  }
28
30
  function matchesFilter(file, include, exclude) {
29
- const normalized = normalizePathForComparison(file);
30
- if (exclude && testPatterns(exclude, normalized)) {
31
- return false;
32
- }
33
- if (include) {
34
- return testPatterns(include, normalized);
35
- }
36
- return true;
31
+ const normalized = normalizePathForComparison(file);
32
+ if (exclude && testPatterns(exclude, normalized)) return false;
33
+ if (include) return testPatterns(include, normalized);
34
+ return true;
37
35
  }
38
36
  function hasIgnoredPrefix(file, rootDir, prefixes) {
39
- if (prefixes.length === 0) {
40
- return false;
41
- }
42
- const normalizedRoot = normalizePathForComparison(rootDir);
43
- const normalizedFile = normalizePathForComparison(file);
44
- const relativePath = toPosix(relative(normalizedRoot, normalizedFile));
45
- const segments = relativePath.split("/");
46
- return segments.some(
47
- (segment) => prefixes.some((prefix) => segment.startsWith(prefix))
48
- );
49
- }
50
-
37
+ if (prefixes.length === 0) return false;
38
+ return toPosix(relative(normalizePathForComparison(rootDir), normalizePathForComparison(file))).split("/").some((segment) => prefixes.some((prefix) => segment.startsWith(prefix)));
39
+ }
40
+ //#endregion
51
41
  export { hasIgnoredPrefix, isInDirs, matchesFilter, normalizePathForComparison, toPosix };
package/dist/pathe.d.mts CHANGED
@@ -1 +1 @@
1
- export * from 'pathe';
1
+ export * from "pathe";
package/dist/pathe.d.ts CHANGED
@@ -1 +1 @@
1
- export * from 'pathe';
1
+ export * from "pathe";
package/dist/pathe.mjs CHANGED
@@ -1 +1,8 @@
1
- export * from 'pathe';
1
+ import { n as __reExport, t as __exportAll } from "./chunk-_iGcCiPk.mjs";
2
+ export * from "pathe";
3
+ //#region src/pathe.ts
4
+ var pathe_exports = /* @__PURE__ */ __exportAll({});
5
+ import * as import_pathe from "pathe";
6
+ __reExport(pathe_exports, import_pathe);
7
+ //#endregion
8
+ export { pathe_exports as t };
@@ -1,12 +1,12 @@
1
+ //#region src/playground-grouping.d.ts
1
2
  interface PlaygroundGroup {
2
- key: string;
3
- label: string;
4
- path: string;
3
+ key: string;
4
+ label: string;
5
+ path: string;
5
6
  }
6
7
  declare function resolveGroupRoot(dirs: string[], serverRoot?: string): string;
7
8
  declare function resolveGroups(dirs: string[], root: string): PlaygroundGroup[];
8
9
  declare function resolveRouteGroup(routeFile: string, groups: PlaygroundGroup[]): PlaygroundGroup | undefined;
9
10
  declare function formatRouteFile(file: string, root?: string): string;
10
-
11
- export { formatRouteFile, resolveGroupRoot, resolveGroups, resolveRouteGroup };
12
- export type { PlaygroundGroup };
11
+ //#endregion
12
+ export { type PlaygroundGroup, formatRouteFile, resolveGroupRoot, resolveGroups, resolveRouteGroup };
@@ -1,12 +1,12 @@
1
+ //#region src/playground-grouping.d.ts
1
2
  interface PlaygroundGroup {
2
- key: string;
3
- label: string;
4
- path: string;
3
+ key: string;
4
+ label: string;
5
+ path: string;
5
6
  }
6
7
  declare function resolveGroupRoot(dirs: string[], serverRoot?: string): string;
7
8
  declare function resolveGroups(dirs: string[], root: string): PlaygroundGroup[];
8
9
  declare function resolveRouteGroup(routeFile: string, groups: PlaygroundGroup[]): PlaygroundGroup | undefined;
9
10
  declare function formatRouteFile(file: string, root?: string): string;
10
-
11
- export { formatRouteFile, resolveGroupRoot, resolveGroups, resolveRouteGroup };
12
- export type { PlaygroundGroup };
11
+ //#endregion
12
+ export { type PlaygroundGroup, formatRouteFile, resolveGroupRoot, resolveGroups, resolveRouteGroup };
@@ -1,90 +1,70 @@
1
- import { cwd } from 'node:process';
2
- import { relative, dirname, normalize } from 'pathe';
3
- import { toPosix, normalizePathForComparison } from './path-utils.mjs';
4
-
1
+ import { normalizePathForComparison, toPosix } from "./path-utils.mjs";
2
+ import { dirname, normalize, relative } from "pathe";
3
+ import { cwd } from "node:process";
4
+ //#region src/playground-grouping.ts
5
+ const TRAILING_SLASH_RE = /\/$/;
5
6
  function normalizePath(value) {
6
- return normalize(toPosix(value));
7
+ return normalize(toPosix(value));
7
8
  }
8
9
  function isAncestor(parent, child) {
9
- const normalizedParent = normalizePathForComparison(parent).replace(/\/$/, "");
10
- const normalizedChild = normalizePathForComparison(child);
11
- return normalizedChild === normalizedParent || normalizedChild.startsWith(`${normalizedParent}/`);
10
+ const normalizedParent = normalizePathForComparison(parent).replace(TRAILING_SLASH_RE, "");
11
+ const normalizedChild = normalizePathForComparison(child);
12
+ return normalizedChild === normalizedParent || normalizedChild.startsWith(`${normalizedParent}/`);
12
13
  }
13
14
  function resolveGroupRoot(dirs, serverRoot) {
14
- if (!dirs || dirs.length === 0) {
15
- return serverRoot ?? cwd();
16
- }
17
- if (serverRoot) {
18
- const normalizedRoot = normalizePath(serverRoot);
19
- const canUseRoot = dirs.every((dir) => isAncestor(normalizedRoot, dir));
20
- if (canUseRoot) {
21
- return normalizedRoot;
22
- }
23
- }
24
- if (dirs.length === 1) {
25
- return normalizePath(dirname(dirs[0]));
26
- }
27
- let common = normalizePath(dirs[0]);
28
- for (const dir of dirs.slice(1)) {
29
- const normalizedDir = normalizePath(dir);
30
- while (common && !isAncestor(common, normalizedDir)) {
31
- const parent = normalizePath(dirname(common));
32
- if (parent === common) {
33
- break;
34
- }
35
- common = parent;
36
- }
37
- }
38
- if (!common || common === "/") {
39
- return serverRoot ?? cwd();
40
- }
41
- return common;
15
+ if (!dirs || dirs.length === 0) return serverRoot ?? cwd();
16
+ if (serverRoot) {
17
+ const normalizedRoot = normalizePath(serverRoot);
18
+ if (dirs.every((dir) => isAncestor(normalizedRoot, dir))) return normalizedRoot;
19
+ }
20
+ if (dirs.length === 1) return normalizePath(dirname(dirs[0]));
21
+ let common = normalizePath(dirs[0]);
22
+ for (const dir of dirs.slice(1)) {
23
+ const normalizedDir = normalizePath(dir);
24
+ while (common && !isAncestor(common, normalizedDir)) {
25
+ const parent = normalizePath(dirname(common));
26
+ if (parent === common) break;
27
+ common = parent;
28
+ }
29
+ }
30
+ if (!common || common === "/") return serverRoot ?? cwd();
31
+ return common;
42
32
  }
43
33
  function resolveGroups(dirs, root) {
44
- const groups = [];
45
- const seen = /* @__PURE__ */ new Set();
46
- for (const dir of dirs) {
47
- const normalized = normalizePath(dir);
48
- const compareKey = normalizePathForComparison(dir);
49
- if (seen.has(compareKey)) {
50
- continue;
51
- }
52
- seen.add(compareKey);
53
- const rel = toPosix(relative(root, normalized));
54
- const label = rel && !rel.startsWith("..") ? rel : normalized;
55
- groups.push({
56
- key: normalized,
57
- label,
58
- path: normalized
59
- });
60
- }
61
- return groups;
34
+ const groups = [];
35
+ const seen = /* @__PURE__ */ new Set();
36
+ for (const dir of dirs) {
37
+ const normalized = normalizePath(dir);
38
+ const compareKey = normalizePathForComparison(dir);
39
+ if (seen.has(compareKey)) continue;
40
+ seen.add(compareKey);
41
+ const rel = toPosix(relative(root, normalized));
42
+ const label = rel && !rel.startsWith("..") ? rel : normalized;
43
+ groups.push({
44
+ key: normalized,
45
+ label,
46
+ path: normalized
47
+ });
48
+ }
49
+ return groups;
62
50
  }
63
51
  function resolveRouteGroup(routeFile, groups) {
64
- if (groups.length === 0) {
65
- return void 0;
66
- }
67
- const normalizedFile = normalizePathForComparison(routeFile);
68
- let matched;
69
- for (const group of groups) {
70
- const normalizedGroup = normalizePathForComparison(group.path);
71
- if (normalizedFile === normalizedGroup || normalizedFile.startsWith(`${normalizedGroup}/`)) {
72
- if (!matched || group.path.length > matched.path.length) {
73
- matched = group;
74
- }
75
- }
76
- }
77
- return matched;
52
+ if (groups.length === 0) return;
53
+ const normalizedFile = normalizePathForComparison(routeFile);
54
+ let matched;
55
+ for (const group of groups) {
56
+ const normalizedGroup = normalizePathForComparison(group.path);
57
+ if (normalizedFile === normalizedGroup || normalizedFile.startsWith(`${normalizedGroup}/`)) {
58
+ if (!matched || group.path.length > matched.path.length) matched = group;
59
+ }
60
+ }
61
+ return matched;
78
62
  }
79
63
  function formatRouteFile(file, root) {
80
- if (!root) {
81
- return toPosix(file);
82
- }
83
- const rel = toPosix(relative(root, file));
84
- if (!rel || rel.startsWith("..")) {
85
- return toPosix(file);
86
- }
87
- return rel;
64
+ if (!root) return toPosix(file);
65
+ const rel = toPosix(relative(root, file));
66
+ if (!rel || rel.startsWith("..")) return toPosix(file);
67
+ return rel;
88
68
  }
89
-
69
+ //#endregion
90
70
  export { formatRouteFile, resolveGroupRoot, resolveGroups, resolveRouteGroup };
@@ -0,0 +1,37 @@
1
+ //#region src/rolldown.d.ts
2
+ interface StdinOptions {
3
+ contents: string;
4
+ loader?: 'js' | 'jsx' | 'ts' | 'tsx';
5
+ resolveDir?: string;
6
+ sourcefile?: string;
7
+ }
8
+ interface BuildOptions {
9
+ absWorkingDir?: string;
10
+ bundle?: boolean;
11
+ entryNames?: string;
12
+ entryPoints?: string[];
13
+ format?: 'cjs' | 'esm' | 'iife';
14
+ logLevel?: 'debug' | 'error' | 'info' | 'silent' | 'warn';
15
+ outbase?: string;
16
+ outdir?: string;
17
+ outExtension?: Record<string, string>;
18
+ platform?: 'browser' | 'neutral' | 'node';
19
+ stdin?: StdinOptions;
20
+ target?: string | string[];
21
+ write?: boolean;
22
+ }
23
+ interface OutputFile {
24
+ contents: Uint8Array;
25
+ path: string;
26
+ text: string;
27
+ }
28
+ interface BuildResult {
29
+ outputFiles: OutputFile[];
30
+ }
31
+ /**
32
+ * Rolldown-backed compatibility wrapper for the subset of `build()`
33
+ * API used inside this repository.
34
+ */
35
+ declare function build(options: BuildOptions): Promise<BuildResult>;
36
+ //#endregion
37
+ export { BuildOptions, BuildResult, OutputFile, StdinOptions, build };
@@ -0,0 +1,37 @@
1
+ //#region src/rolldown.d.ts
2
+ interface StdinOptions {
3
+ contents: string;
4
+ loader?: 'js' | 'jsx' | 'ts' | 'tsx';
5
+ resolveDir?: string;
6
+ sourcefile?: string;
7
+ }
8
+ interface BuildOptions {
9
+ absWorkingDir?: string;
10
+ bundle?: boolean;
11
+ entryNames?: string;
12
+ entryPoints?: string[];
13
+ format?: 'cjs' | 'esm' | 'iife';
14
+ logLevel?: 'debug' | 'error' | 'info' | 'silent' | 'warn';
15
+ outbase?: string;
16
+ outdir?: string;
17
+ outExtension?: Record<string, string>;
18
+ platform?: 'browser' | 'neutral' | 'node';
19
+ stdin?: StdinOptions;
20
+ target?: string | string[];
21
+ write?: boolean;
22
+ }
23
+ interface OutputFile {
24
+ contents: Uint8Array;
25
+ path: string;
26
+ text: string;
27
+ }
28
+ interface BuildResult {
29
+ outputFiles: OutputFile[];
30
+ }
31
+ /**
32
+ * Rolldown-backed compatibility wrapper for the subset of `build()`
33
+ * API used inside this repository.
34
+ */
35
+ declare function build(options: BuildOptions): Promise<BuildResult>;
36
+ //#endregion
37
+ export { BuildOptions, BuildResult, OutputFile, StdinOptions, build };
@@ -0,0 +1,81 @@
1
+ import process from "node:process";
2
+ import { Buffer } from "node:buffer";
3
+ import { basename, extname, relative, resolve } from "node:path";
4
+ import { build as build$1 } from "rolldown";
5
+ //#region src/rolldown.ts
6
+ const defaultEntryName = "[name]";
7
+ const defaultJsExtension = ".js";
8
+ const virtualEntryBaseName = "__mokup_stdin_entry__";
9
+ function toPosixPath(value) {
10
+ return value.replaceAll("\\", "/");
11
+ }
12
+ function stripExtension(value) {
13
+ const extension = extname(value);
14
+ return extension ? value.slice(0, -extension.length) : value;
15
+ }
16
+ function resolveEntryNamePattern(options) {
17
+ return `${(options.entryNames ?? defaultEntryName).replaceAll("[dir]/", "")}${options.outExtension?.[".js"] ?? defaultJsExtension}`;
18
+ }
19
+ function normalizeInput(entryPoints, options) {
20
+ const baseDir = options.outbase ?? options.absWorkingDir ?? process.cwd();
21
+ return Object.fromEntries(entryPoints.map((entryPoint) => {
22
+ const relPath = relative(baseDir, entryPoint);
23
+ const fallbackName = stripExtension(basename(entryPoint));
24
+ return [relPath && !relPath.startsWith("..") ? stripExtension(toPosixPath(relPath)) : fallbackName, entryPoint];
25
+ }));
26
+ }
27
+ function normalizeStdinEntry(options) {
28
+ const stdin = options.stdin;
29
+ if (!stdin) return null;
30
+ const loader = stdin.loader ?? "js";
31
+ const resolveDir = stdin.resolveDir ?? options.absWorkingDir ?? process.cwd();
32
+ const sourceFile = stdin.sourcefile ?? `${virtualEntryBaseName}.${loader}`;
33
+ const virtualId = resolve(resolveDir, extname(sourceFile) ? sourceFile : `${sourceFile}.${loader}`);
34
+ return {
35
+ plugin: {
36
+ name: "mokup-stdin-entry",
37
+ load(id) {
38
+ if (id === virtualId) return stdin.contents;
39
+ return null;
40
+ },
41
+ resolveId(id) {
42
+ if (id === virtualId) return virtualId;
43
+ return null;
44
+ }
45
+ },
46
+ virtualId
47
+ };
48
+ }
49
+ function toOutputFiles(output, outdir) {
50
+ return output.filter((item) => Boolean(item.fileName)).map((item) => {
51
+ const contents = item.type === "chunk" ? Buffer.from(item.code ?? "") : typeof item.source === "string" ? Buffer.from(item.source) : Buffer.from(item.source ?? []);
52
+ return {
53
+ contents,
54
+ path: outdir ? resolve(outdir, item.fileName) : item.fileName,
55
+ text: contents.toString("utf8")
56
+ };
57
+ });
58
+ }
59
+ /**
60
+ * Rolldown-backed compatibility wrapper for the subset of `build()`
61
+ * API used inside this repository.
62
+ */
63
+ async function build(options) {
64
+ const stdinEntry = normalizeStdinEntry(options);
65
+ const input = stdinEntry ? stdinEntry.virtualId : normalizeInput(options.entryPoints ?? [], options);
66
+ return { outputFiles: toOutputFiles((await build$1({
67
+ cwd: options.absWorkingDir,
68
+ input,
69
+ logLevel: options.logLevel,
70
+ platform: options.platform,
71
+ plugins: stdinEntry ? [stdinEntry.plugin] : [],
72
+ write: options.write,
73
+ output: {
74
+ dir: options.outdir,
75
+ entryFileNames: resolveEntryNamePattern(options),
76
+ format: options.format
77
+ }
78
+ }))?.output ?? [], options.outdir) };
79
+ }
80
+ //#endregion
81
+ export { build };
@@ -1,7 +1,8 @@
1
+ //#region src/route-constants.d.ts
1
2
  declare const methodSet: Set<string>;
2
3
  declare const methodSuffixSet: Set<string>;
3
4
  declare const supportedExtensions: Set<string>;
4
5
  declare const configExtensions: readonly [".ts", ".js", ".mjs", ".cjs"];
5
6
  declare const jsonExtensions: Set<string>;
6
-
7
- export { configExtensions, jsonExtensions, methodSet, methodSuffixSet, supportedExtensions };
7
+ //#endregion
8
+ export { supportedExtensions as a, methodSuffixSet as i, jsonExtensions as n, methodSet as r, configExtensions as t };
@@ -0,0 +1,8 @@
1
+ //#region src/route-constants.d.ts
2
+ declare const methodSet: Set<string>;
3
+ declare const methodSuffixSet: Set<string>;
4
+ declare const supportedExtensions: Set<string>;
5
+ declare const configExtensions: readonly [".ts", ".js", ".mjs", ".cjs"];
6
+ declare const jsonExtensions: Set<string>;
7
+ //#endregion
8
+ export { supportedExtensions as a, methodSuffixSet as i, jsonExtensions as n, methodSet as r, configExtensions as t };
@@ -1,7 +1,2 @@
1
- declare const methodSet: Set<string>;
2
- declare const methodSuffixSet: Set<string>;
3
- declare const supportedExtensions: Set<string>;
4
- declare const configExtensions: readonly [".ts", ".js", ".mjs", ".cjs"];
5
- declare const jsonExtensions: Set<string>;
6
-
7
- export { configExtensions, jsonExtensions, methodSet, methodSuffixSet, supportedExtensions };
1
+ import { a as supportedExtensions, i as methodSuffixSet, n as jsonExtensions, r as methodSet, t as configExtensions } from "./route-constants-BUi36iYR.mjs";
2
+ export { configExtensions, jsonExtensions, methodSet, methodSuffixSet, supportedExtensions };