@aomex/internal-file-import 3.30.6 → 3.30.8-alpha.131cf1c.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/CHANGELOG.md +8 -0
- package/dist/index.d.ts +8 -12
- package/dist/index.js +55 -69
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [3.30.7](https://github.com/aomex/aomex/compare/v3.30.6...v3.30.7) (2026-11-01)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @aomex/internal-file-import
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
## [3.30.6](https://github.com/aomex/aomex/compare/v3.30.5...v3.30.6) (2026-10-19)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @aomex/internal-file-import
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
interface GlobPathFullOptions {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export interface GlobPathFullOptions {
|
|
2
|
+
pattern: string[];
|
|
3
|
+
ignore?: string[];
|
|
4
|
+
dot?: boolean;
|
|
5
5
|
}
|
|
6
|
-
type GlobPathOptions = string | string[] | GlobPathFullOptions | GlobPathFullOptions[];
|
|
7
|
-
declare const normalizeGlobPath: (paths: GlobPathOptions) => GlobPathFullOptions[];
|
|
8
|
-
|
|
9
|
-
declare const
|
|
10
|
-
|
|
11
|
-
declare const getFileValues: <T extends unknown>(files: string[], filterValues?: (item?: unknown) => boolean) => Promise<T[]>;
|
|
12
|
-
|
|
13
|
-
export { type GlobPathFullOptions, type GlobPathOptions, getFileValues, normalizeGlobPath, pathToFiles };
|
|
6
|
+
export type GlobPathOptions = string | string[] | GlobPathFullOptions | GlobPathFullOptions[];
|
|
7
|
+
export declare const normalizeGlobPath: (paths: GlobPathOptions) => GlobPathFullOptions[];
|
|
8
|
+
export declare const pathToFiles: (paths: GlobPathOptions) => Promise<string[]>;
|
|
9
|
+
export declare const getFileValues: <T extends unknown>(files: string[], filterValues?: (item?: unknown) => boolean) => Promise<T[]>;
|
package/dist/index.js
CHANGED
|
@@ -1,78 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
import { stat } from "fs/promises";
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { stat } from "node:fs/promises";
|
|
4
3
|
import { glob, hasMagic } from "glob";
|
|
5
|
-
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
6
5
|
// src/normalize-glob-path.ts
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
return [paths];
|
|
6
|
+
const normalizeGlobPath = (paths) => {
|
|
7
|
+
if (typeof paths === "string") return [{ pattern: [paths] }];
|
|
8
|
+
if (Array.isArray(paths)) {
|
|
9
|
+
if (!paths.length) return [];
|
|
10
|
+
return isStringArray(paths) ? [{ pattern: paths }] : paths;
|
|
11
|
+
}
|
|
12
|
+
return [paths];
|
|
16
13
|
};
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
const isStringArray = (data) => {
|
|
15
|
+
return typeof data[0] === "string";
|
|
19
16
|
};
|
|
20
|
-
|
|
21
17
|
// src/path-to-file.ts
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return [...new Set(files.flat(2))].sort();
|
|
18
|
+
const pathToFiles = async (paths) => {
|
|
19
|
+
const opts = normalizeGlobPath(paths);
|
|
20
|
+
const files = await Promise.all(opts.map((opt) => {
|
|
21
|
+
const { dot, pattern: patterns } = opt;
|
|
22
|
+
const ignore = (opt.ignore || []).slice();
|
|
23
|
+
ignore.push("**/node_modules/**/**", "**/*.d.{ts,mts}");
|
|
24
|
+
const options = {
|
|
25
|
+
nodir: true,
|
|
26
|
+
dot,
|
|
27
|
+
ignore,
|
|
28
|
+
absolute: true,
|
|
29
|
+
withFileTypes: false,
|
|
30
|
+
maxDepth: Infinity
|
|
31
|
+
};
|
|
32
|
+
return Promise.all(patterns.map(async (pattern) => {
|
|
33
|
+
if (!path.isAbsolute(pattern)) pattern = path.resolve(pattern);
|
|
34
|
+
/**
|
|
35
|
+
* 在windows系统默认使用反斜杠`\`拼接路径,但是glob只支持正斜杠`/`.
|
|
36
|
+
* @link https://github.com/isaacs/node-glob#windows
|
|
37
|
+
*/
|
|
38
|
+
pattern = pattern.replace(/\\/g, path.posix.sep);
|
|
39
|
+
/**
|
|
40
|
+
* glob.hasMagic 不支持带反斜杠(\)的路径。从glob@9.0.0起,花括号不再是魔术路径
|
|
41
|
+
* @see https://github.com/isaacs/node-glob/issues/496
|
|
42
|
+
*/
|
|
43
|
+
if (!hasMagic(pattern, { magicalBraces: true })) {
|
|
44
|
+
if (!(await stat(pattern)).isFile()) pattern = path.posix.join(pattern, "**", "*.{ts,js,mts,mjs}");
|
|
45
|
+
}
|
|
46
|
+
return glob(pattern, options);
|
|
47
|
+
}));
|
|
48
|
+
}));
|
|
49
|
+
return [...new Set(files.flat(2))].sort();
|
|
55
50
|
};
|
|
56
|
-
|
|
57
51
|
// src/get-file-values.ts
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
})
|
|
70
|
-
);
|
|
71
|
-
return filterValues ? [...totalFiles].filter(filterValues) : [...totalFiles];
|
|
72
|
-
};
|
|
73
|
-
export {
|
|
74
|
-
getFileValues,
|
|
75
|
-
normalizeGlobPath,
|
|
76
|
-
pathToFiles
|
|
52
|
+
const getFileValues = async (files, filterValues) => {
|
|
53
|
+
const totalFiles = /* @__PURE__ */ new Set();
|
|
54
|
+
await Promise.all(files.map(async (file) => {
|
|
55
|
+
const modules = await import(pathToFileURL(file).toString());
|
|
56
|
+
if (typeof modules === "object") Object.values(modules).forEach((item) => {
|
|
57
|
+
totalFiles.add(item);
|
|
58
|
+
});
|
|
59
|
+
}));
|
|
60
|
+
return filterValues ? [...totalFiles].filter(filterValues) : [...totalFiles];
|
|
77
61
|
};
|
|
62
|
+
export { getFileValues, normalizeGlobPath, pathToFiles };
|
|
63
|
+
|
|
78
64
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/normalize-glob-path.ts","../src/path-to-file.ts","../src/get-file-values.ts"],"sourcesContent":["export interface GlobPathFullOptions {\n pattern: string[];\n ignore?: string[];\n dot?: boolean;\n}\n\nexport type GlobPathOptions =\n string | string[] | GlobPathFullOptions | GlobPathFullOptions[];\n\nexport const normalizeGlobPath = (paths: GlobPathOptions): GlobPathFullOptions[] => {\n if (typeof paths === 'string') {\n return [{ pattern: [paths] }];\n }\n\n if (Array.isArray(paths)) {\n if (!paths.length) return [];\n return isStringArray(paths) ? [{ pattern: paths }] : paths;\n }\n\n return [paths];\n};\n\nconst isStringArray = (data: string[] | GlobPathFullOptions[]): data is string[] => {\n return typeof data[0] === 'string';\n};\n","import path from 'node:path';\nimport { stat } from 'node:fs/promises';\nimport { glob, type GlobOptionsWithFileTypesFalse, hasMagic } from 'glob';\nimport { normalizeGlobPath, type GlobPathOptions } from './normalize-glob-path';\n\nexport const pathToFiles = async (paths: GlobPathOptions): Promise<string[]> => {\n const opts = normalizeGlobPath(paths);\n\n const files = await Promise.all(\n opts.map((opt) => {\n const { dot, pattern: patterns } = opt;\n const ignore = (opt.ignore || []).slice();\n ignore.push('**/node_modules/**/**', '**/*.d.{ts,mts}');\n\n const options: GlobOptionsWithFileTypesFalse = {\n nodir: true,\n dot,\n ignore,\n absolute: true,\n withFileTypes: false,\n maxDepth: Infinity,\n };\n\n return Promise.all(\n patterns.map(async (pattern) => {\n if (!path.isAbsolute(pattern)) {\n pattern = path.resolve(pattern);\n }\n\n /**\n * 在windows系统默认使用反斜杠`\\`拼接路径,但是glob只支持正斜杠`/`.\n * @link https://github.com/isaacs/node-glob#windows\n */\n pattern = pattern.replace(/\\\\/g, path.posix.sep);\n\n /**\n * glob.hasMagic 不支持带反斜杠(\\)的路径。从glob@9.0.0起,花括号不再是魔术路径\n * @see https://github.com/isaacs/node-glob/issues/496\n */\n if (!hasMagic(pattern, { magicalBraces: true })) {\n const stats = await stat(pattern);\n if (!stats.isFile()) {\n pattern = path.posix.join(pattern, '**', '*.{ts,js,mts,mjs}');\n }\n }\n\n return glob(pattern, options);\n }),\n );\n }),\n );\n\n return [...new Set(files.flat(2))].sort();\n};\n","import { pathToFileURL } from 'node:url';\n\nexport const getFileValues = async <T extends unknown>(\n files: string[],\n filterValues?: (item?: unknown) => boolean,\n): Promise<T[]> => {\n const totalFiles = new Set<T>();\n await Promise.all(\n files.map(async (file) => {\n // Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only URLs with a scheme in: file, data, and node are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'\n const modules = await import(pathToFileURL(file).toString());\n if (typeof modules === 'object') {\n Object.values(modules).forEach((item) => {\n totalFiles.add(item as any);\n });\n }\n }),\n );\n return filterValues ? [...totalFiles].filter(filterValues) : [...totalFiles];\n};\n"],"mappings":";;;;;AASA,MAAa,qBAAqB,UAAkD;CAClF,IAAI,OAAO,UAAU,UACnB,OAAO,CAAC,EAAE,SAAS,CAAC,KAAK,EAAE,CAAC;CAG9B,IAAI,MAAM,QAAQ,KAAK,GAAG;EACxB,IAAI,CAAC,MAAM,QAAQ,OAAO,CAAC;EAC3B,OAAO,cAAc,KAAK,IAAI,CAAC,EAAE,SAAS,MAAM,CAAC,IAAI;CACvD;CAEA,OAAO,CAAC,KAAK;AACf;AAEA,MAAM,iBAAiB,SAA6D;CAClF,OAAO,OAAO,KAAK,OAAO;AAC5B;;ACnBA,MAAa,cAAc,OAAO,UAA8C;CAC9E,MAAM,OAAO,kBAAkB,KAAK;CAEpC,MAAM,QAAQ,MAAM,QAAQ,IAC1B,KAAK,KAAK,QAAQ;EAChB,MAAM,EAAE,KAAK,SAAS,aAAa;EACnC,MAAM,UAAU,IAAI,UAAU,CAAC,EAAA,CAAG,MAAM;EACxC,OAAO,KAAK,yBAAyB,iBAAiB;EAEtD,MAAM,UAAyC;GAC7C,OAAO;GACP;GACA;GACA,UAAU;GACV,eAAe;GACf,UAAU;EACZ;EAEA,OAAO,QAAQ,IACb,SAAS,IAAI,OAAO,YAAY;GAC9B,IAAI,CAAC,KAAK,WAAW,OAAO,GAC1B,UAAU,KAAK,QAAQ,OAAO;;;;;GAOhC,UAAU,QAAQ,QAAQ,OAAO,KAAK,MAAM,GAAG;;;;;GAM/C,IAAI,CAAC,SAAS,SAAS,EAAE,eAAe,KAAK,CAAC,GAExC;QAAA,EAAC,MADe,KAAK,OAAO,EAAA,CACrB,OAAO,GAChB,UAAU,KAAK,MAAM,KAAK,SAAS,MAAM,mBAAmB;GAAA;GAIhE,OAAO,KAAK,SAAS,OAAO;EAC9B,CAAC,CACH;CACF,CAAC,CACH;CAEA,OAAO,CAAC,GAAG,IAAI,IAAI,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK;AAC1C;;ACnDA,MAAa,gBAAgB,OAC3B,OACA,iBACiB;CACjB,MAAM,6BAAa,IAAI,IAAO;CAC9B,MAAM,QAAQ,IACZ,MAAM,IAAI,OAAO,SAAS;EAExB,MAAM,UAAU,MAAM,OAAO,cAAc,IAAI,CAAC,CAAC,SAAS;EAC1D,IAAI,OAAO,YAAY,UACrB,OAAO,OAAO,OAAO,CAAC,CAAC,SAAS,SAAS;GACvC,WAAW,IAAI,IAAW;EAC5B,CAAC;CAEL,CAAC,CACH;CACA,OAAO,eAAe,CAAC,GAAG,UAAU,CAAC,CAAC,OAAO,YAAY,IAAI,CAAC,GAAG,UAAU;AAC7E"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aomex/internal-file-import",
|
|
3
|
-
"version": "3.30.
|
|
3
|
+
"version": "3.30.8-alpha.131cf1c.0",
|
|
4
4
|
"description": "aomex根据文件路径导入模块",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"homepage": "https://aomex.js.org",
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"glob": "^
|
|
32
|
+
"glob": "^14.0.6"
|
|
33
33
|
},
|
|
34
34
|
"scripts": {}
|
|
35
35
|
}
|