@mokup/shared 1.1.4 → 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.d.cts → config-core-dqVMz7on.d.mts} +3 -2
- 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 -162
- 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-utils.cjs +0 -179
- package/dist/config-utils.d.cts +0 -62
- package/dist/define-config.cjs +0 -169
- package/dist/define-config.d.cts +0 -20
- package/dist/esbuild.cjs +0 -16
- package/dist/esbuild.d.cts +0 -1
- package/dist/esbuild.d.mts +0 -1
- package/dist/esbuild.d.ts +0 -1
- package/dist/esbuild.mjs +0 -1
- package/dist/hono.cjs +0 -20
- package/dist/hono.d.cts +0 -3
- package/dist/index.cjs +0 -50
- package/dist/index.d.cts +0 -10
- package/dist/jsonc-parser.cjs +0 -16
- package/dist/jsonc-parser.d.cts +0 -1
- package/dist/jsonc-utils.cjs +0 -25
- package/dist/jsonc-utils.d.cts +0 -7
- package/dist/load-rules.cjs +0 -39
- package/dist/load-rules.d.cts +0 -14
- package/dist/logger.browser.cjs +0 -55
- package/dist/logger.browser.d.cts +0 -21
- package/dist/logger.cjs +0 -55
- package/dist/logger.d.cts +0 -21
- package/dist/mock-files.cjs +0 -65
- package/dist/module-loader.cjs +0 -93
- package/dist/path-utils.cjs +0 -57
- package/dist/path-utils.d.cts +0 -7
- package/dist/pathe.cjs +0 -16
- package/dist/pathe.d.cts +0 -1
- package/dist/playground-grouping.cjs +0 -95
- package/dist/playground-grouping.d.cts +0 -12
- package/dist/route-constants.cjs +0 -30
- package/dist/route-utils.cjs +0 -126
- package/dist/route-utils.d.cts +0 -42
- package/dist/scan-utils.cjs +0 -39
- package/dist/scan-utils.d.cts +0 -114
- package/dist/shared/shared.DazgCdsk.d.cts +0 -49
- package/dist/shared/shared.DazgCdsk.d.mts +0 -49
- package/dist/shared/shared.DazgCdsk.d.ts +0 -49
- package/dist/timing.cjs +0 -20
- package/dist/timing.d.cts +0 -4
package/dist/module-loader.mjs
CHANGED
|
@@ -1,83 +1,74 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createRequire } from
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
sourceMapsEnabled = false;
|
|
22
|
+
tsxRegisterPromise = null;
|
|
23
|
+
tsxRegisteredConfig = null;
|
|
27
24
|
}
|
|
28
25
|
function ensureSourceMapsEnabled() {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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 };
|
package/dist/path-utils.d.mts
CHANGED
|
@@ -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 };
|
package/dist/path-utils.d.ts
CHANGED
|
@@ -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 };
|
package/dist/path-utils.mjs
CHANGED
|
@@ -1,51 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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
|
-
|
|
8
|
+
return platform === "win32" || WINDOWS_DRIVE_RE.test(normalized) || normalized.startsWith("//");
|
|
6
9
|
}
|
|
7
10
|
function toPosix(value) {
|
|
8
|
-
|
|
11
|
+
return value.replace(WINDOWS_SEPARATOR_RE, "/");
|
|
9
12
|
}
|
|
10
13
|
function normalizePath(value) {
|
|
11
|
-
|
|
14
|
+
return normalize(toPosix(value));
|
|
12
15
|
}
|
|
13
16
|
function normalizePathForComparison(value) {
|
|
14
|
-
|
|
15
|
-
|
|
17
|
+
const normalized = normalizePath(value);
|
|
18
|
+
return isWindowsLikePath(normalized) ? normalized.toLowerCase() : normalized;
|
|
16
19
|
}
|
|
17
20
|
function isInDirs(file, dirs) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
|
1
|
+
export * from "pathe";
|
package/dist/pathe.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from "pathe";
|
package/dist/pathe.mjs
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
-
|
|
7
|
+
return normalize(toPosix(value));
|
|
7
8
|
}
|
|
8
9
|
function isAncestor(parent, child) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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 {
|
|
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
|
-
|
|
2
|
-
|
|
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 };
|