@kevisual/router 0.0.68 → 0.0.69
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/router.d.ts +1 -7
- package/dist/router.js +1 -115
- package/package.json +1 -1
- package/src/auto/load-ts.ts +6 -4
- package/src/index.ts +1 -1
package/dist/router.d.ts
CHANGED
|
@@ -958,11 +958,5 @@ declare class App<U = {}> extends QueryRouter {
|
|
|
958
958
|
onServerRequest(fn: (req: IncomingMessage$1, res: ServerResponse$1) => void): void;
|
|
959
959
|
}
|
|
960
960
|
|
|
961
|
-
|
|
962
|
-
cwd?: string;
|
|
963
|
-
load?: (args?: any) => Promise<any>;
|
|
964
|
-
};
|
|
965
|
-
declare const loadTS: (match?: string, { cwd, load }?: GlobOptions) => Promise<any[]>;
|
|
966
|
-
|
|
967
|
-
export { App, CustomError, Mini, MockProcess, QueryRouter, QueryRouterServer, QueryUtil, Route, ServerNode, createSchema, createSkill, define, fromJSONSchema, handleServer, loadTS, toJSONSchema, tool, util };
|
|
961
|
+
export { App, CustomError, Mini, MockProcess, QueryRouter, QueryRouterServer, QueryUtil, Route, ServerNode, createSchema, createSkill, define, fromJSONSchema, handleServer, toJSONSchema, tool, util };
|
|
968
962
|
export type { HttpListenerFun, Listener, OnListener, OnWebSocketFn, RouteArray, RouteContext, RouteMiddleware, RouteObject, RouteOpts, RouterReq, RouterRes, Rule, Run, Schema, Skill, WS, WebSocketListenerFun, WebSocketReq, WebSocketRes };
|
package/dist/router.js
CHANGED
|
@@ -21818,118 +21818,4 @@ class App extends QueryRouter {
|
|
|
21818
21818
|
}
|
|
21819
21819
|
}
|
|
21820
21820
|
|
|
21821
|
-
|
|
21822
|
-
// @ts-ignore
|
|
21823
|
-
if (typeof Deno !== 'undefined') {
|
|
21824
|
-
return { isDeno: true, engine: 'deno' };
|
|
21825
|
-
}
|
|
21826
|
-
// @ts-ignore
|
|
21827
|
-
if (typeof Bun !== 'undefined') {
|
|
21828
|
-
return { isBun: true, engine: 'bun' };
|
|
21829
|
-
}
|
|
21830
|
-
return { isNode: true, engine: 'node' };
|
|
21831
|
-
};
|
|
21832
|
-
|
|
21833
|
-
const glob = async (match = './*.ts', { cwd = process.cwd() } = {}) => {
|
|
21834
|
-
const fs = await import('node:fs');
|
|
21835
|
-
const path = await import('node:path');
|
|
21836
|
-
// 将 glob 模式转换为正则表达式
|
|
21837
|
-
const globToRegex = (pattern) => {
|
|
21838
|
-
const escaped = pattern
|
|
21839
|
-
.replace(/\./g, '\\.')
|
|
21840
|
-
.replace(/\*\*/g, '__DOUBLE_STAR__') // 临时替换 **
|
|
21841
|
-
.replace(/\*/g, '[^/]*') // * 匹配除 / 外的任意字符
|
|
21842
|
-
.replace(/__DOUBLE_STAR__/g, '.*') // ** 匹配任意字符包括 /
|
|
21843
|
-
.replace(/\?/g, '[^/]'); // ? 匹配除 / 外的单个字符
|
|
21844
|
-
return new RegExp(`^${escaped}$`);
|
|
21845
|
-
};
|
|
21846
|
-
// 递归读取目录
|
|
21847
|
-
const readDirRecursive = async (dir) => {
|
|
21848
|
-
const files = [];
|
|
21849
|
-
try {
|
|
21850
|
-
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
21851
|
-
for (const entry of entries) {
|
|
21852
|
-
const fullPath = path.join(dir, entry.name);
|
|
21853
|
-
if (entry.isFile()) {
|
|
21854
|
-
files.push(fullPath);
|
|
21855
|
-
}
|
|
21856
|
-
else if (entry.isDirectory()) {
|
|
21857
|
-
// 递归搜索子目录
|
|
21858
|
-
const subFiles = await readDirRecursive(fullPath);
|
|
21859
|
-
files.push(...subFiles);
|
|
21860
|
-
}
|
|
21861
|
-
}
|
|
21862
|
-
}
|
|
21863
|
-
catch (error) {
|
|
21864
|
-
// 忽略无法访问的目录
|
|
21865
|
-
}
|
|
21866
|
-
return files;
|
|
21867
|
-
};
|
|
21868
|
-
// 解析模式是否包含递归搜索
|
|
21869
|
-
const hasRecursive = match.includes('**');
|
|
21870
|
-
try {
|
|
21871
|
-
let allFiles = [];
|
|
21872
|
-
if (hasRecursive) {
|
|
21873
|
-
// 处理递归模式
|
|
21874
|
-
const basePath = match.split('**')[0];
|
|
21875
|
-
const startDir = path.resolve(cwd, basePath || '.');
|
|
21876
|
-
allFiles = await readDirRecursive(startDir);
|
|
21877
|
-
}
|
|
21878
|
-
else {
|
|
21879
|
-
// 处理非递归模式
|
|
21880
|
-
const dir = path.resolve(cwd, path.dirname(match));
|
|
21881
|
-
const entries = await fs.promises.readdir(dir, { withFileTypes: true });
|
|
21882
|
-
for (const entry of entries) {
|
|
21883
|
-
if (entry.isFile()) {
|
|
21884
|
-
allFiles.push(path.join(dir, entry.name));
|
|
21885
|
-
}
|
|
21886
|
-
}
|
|
21887
|
-
}
|
|
21888
|
-
// 创建相对于 cwd 的匹配模式
|
|
21889
|
-
const normalizedMatch = path.resolve(cwd, match);
|
|
21890
|
-
const regex = globToRegex(normalizedMatch);
|
|
21891
|
-
// 过滤匹配的文件
|
|
21892
|
-
const matchedFiles = allFiles.filter(file => {
|
|
21893
|
-
const normalizedFile = path.resolve(file);
|
|
21894
|
-
return regex.test(normalizedFile);
|
|
21895
|
-
});
|
|
21896
|
-
return matchedFiles;
|
|
21897
|
-
}
|
|
21898
|
-
catch (error) {
|
|
21899
|
-
console.error(`Error in glob pattern "${match}":`, error);
|
|
21900
|
-
return [];
|
|
21901
|
-
}
|
|
21902
|
-
};
|
|
21903
|
-
|
|
21904
|
-
const getMatchFiles = async (match = './*.ts', { cwd = process.cwd() } = {}) => {
|
|
21905
|
-
const runtime = getRuntime();
|
|
21906
|
-
if (runtime.isNode) {
|
|
21907
|
-
console.error(`Node.js is not supported`);
|
|
21908
|
-
return [];
|
|
21909
|
-
}
|
|
21910
|
-
if (runtime.isDeno) {
|
|
21911
|
-
// Deno 环境下
|
|
21912
|
-
return await glob(match);
|
|
21913
|
-
}
|
|
21914
|
-
if (runtime.isBun) {
|
|
21915
|
-
// Bun 环境下
|
|
21916
|
-
// @ts-ignore
|
|
21917
|
-
const { Glob } = await import('bun');
|
|
21918
|
-
const path = await import('node:path');
|
|
21919
|
-
// @ts-ignore
|
|
21920
|
-
const glob = new Glob(match, { cwd, absolute: true, onlyFiles: true });
|
|
21921
|
-
const files = [];
|
|
21922
|
-
for await (const file of glob.scan('.')) {
|
|
21923
|
-
files.push(path.join(cwd, file));
|
|
21924
|
-
}
|
|
21925
|
-
// @ts-ignore
|
|
21926
|
-
return Array.from(files);
|
|
21927
|
-
}
|
|
21928
|
-
return [];
|
|
21929
|
-
};
|
|
21930
|
-
const loadTS = async (match = './*.ts', { cwd = process.cwd(), load } = {}) => {
|
|
21931
|
-
const files = await getMatchFiles(match, { cwd });
|
|
21932
|
-
return Promise.all(files.map((file) => (load ? load(file) : import(file))));
|
|
21933
|
-
};
|
|
21934
|
-
|
|
21935
|
-
export { App, CustomError, Mini, MockProcess, QueryRouter, QueryRouterServer, QueryUtil, Route, ServerNode, createSchema, createSkill, define, fromJSONSchema, handleServer, loadTS, toJSONSchema, tool, util };
|
|
21821
|
+
export { App, CustomError, Mini, MockProcess, QueryRouter, QueryRouterServer, QueryUtil, Route, ServerNode, createSchema, createSkill, define, fromJSONSchema, handleServer, toJSONSchema, tool, util };
|
package/package.json
CHANGED
package/src/auto/load-ts.ts
CHANGED
|
@@ -17,9 +17,11 @@ export const getMatchFiles = async (match: string = './*.ts', { cwd = process.cw
|
|
|
17
17
|
}
|
|
18
18
|
if (runtime.isBun) {
|
|
19
19
|
// Bun 环境下
|
|
20
|
+
const bunPkgs = 'bun';
|
|
21
|
+
const pathPkgs = 'node:path';
|
|
20
22
|
// @ts-ignore
|
|
21
|
-
const { Glob } = await import(
|
|
22
|
-
const path = await import(
|
|
23
|
+
const { Glob } = await import(/*---*/bunPkgs);
|
|
24
|
+
const path = await import(/*---*/pathPkgs);
|
|
23
25
|
// @ts-ignore
|
|
24
26
|
const glob = new Glob(match, { cwd, absolute: true, onlyFiles: true });
|
|
25
27
|
const files: string[] = [];
|
|
@@ -32,7 +34,7 @@ export const getMatchFiles = async (match: string = './*.ts', { cwd = process.cw
|
|
|
32
34
|
return [];
|
|
33
35
|
};
|
|
34
36
|
|
|
35
|
-
export const loadTS = async (match: string = './*.ts', { cwd = process
|
|
37
|
+
export const loadTS = async (match: string = './*.ts', { cwd = process?.cwd?.(), load }: GlobOptions = {}): Promise<any[]> => {
|
|
36
38
|
const files = await getMatchFiles(match, { cwd });
|
|
37
|
-
return Promise.all(files.map((file) => (load ? load(file) : import(file))));
|
|
39
|
+
return Promise.all(files.map((file) => (load ? load(file) : import(/*---*/file))));
|
|
38
40
|
};
|
package/src/index.ts
CHANGED