@ainc/fs 0.1.22 → 0.1.24

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 (64) hide show
  1. package/dist/cache.d.ts +16 -0
  2. package/dist/cache.js +24 -0
  3. package/dist/dict.d.ts +21 -0
  4. package/dist/dict.js +66 -0
  5. package/dist/download.js +4 -16
  6. package/dist/downloadFile.js +19 -13
  7. package/dist/gzip.d.ts +13 -0
  8. package/dist/gzip.js +50 -0
  9. package/dist/index.d.ts +37 -1
  10. package/dist/index.exports.json +34 -0
  11. package/dist/index.js +60 -3
  12. package/dist/isEsmModule.d.ts +18 -0
  13. package/dist/isEsmModule.js +63 -0
  14. package/dist/loadPackageDescription.d.ts +61 -0
  15. package/dist/loadPackageDescription.js +71 -0
  16. package/dist/loadTsConfig.d.ts +87 -0
  17. package/dist/loadTsConfig.js +219 -0
  18. package/dist/match.d.ts +30 -0
  19. package/dist/match.js +59 -0
  20. package/dist/promises.d.ts +69 -0
  21. package/dist/promises.js +103 -0
  22. package/dist/resolveAlias.d.ts +25 -0
  23. package/dist/resolveAlias.js +82 -0
  24. package/dist/resolveDirect.d.ts +15 -0
  25. package/dist/resolveDirect.js +144 -0
  26. package/dist/resolveExports.d.ts +19 -0
  27. package/dist/resolveExports.js +54 -0
  28. package/dist/resolveImports.d.ts +21 -0
  29. package/dist/resolveImports.js +114 -0
  30. package/dist/resolveModuleDir.d.ts +12 -0
  31. package/dist/resolveModuleDir.js +67 -0
  32. package/dist/resolveModuleId.d.ts +6 -0
  33. package/dist/resolveModuleId.js +32 -0
  34. package/dist/resolvePath.d.ts +23 -0
  35. package/dist/resolvePath.js +86 -0
  36. package/dist/resolvePaths.d.ts +13 -0
  37. package/dist/resolvePaths.js +42 -0
  38. package/dist/split.d.ts +6 -0
  39. package/dist/split.js +24 -0
  40. package/dist/sys.d.ts +60 -0
  41. package/dist/sys.js +260 -0
  42. package/esm/cache.mjs +22 -0
  43. package/esm/dict.mjs +63 -0
  44. package/esm/download.mjs +4 -16
  45. package/esm/downloadFile.mjs +19 -13
  46. package/esm/gzip.mjs +47 -0
  47. package/esm/index.exports.json +34 -0
  48. package/esm/index.mjs +29 -1
  49. package/esm/isEsmModule.mjs +59 -0
  50. package/esm/loadPackageDescription.mjs +67 -0
  51. package/esm/loadTsConfig.mjs +215 -0
  52. package/esm/match.mjs +53 -0
  53. package/esm/promises.mjs +96 -0
  54. package/esm/resolveAlias.mjs +79 -0
  55. package/esm/resolveDirect.mjs +142 -0
  56. package/esm/resolveExports.mjs +51 -0
  57. package/esm/resolveImports.mjs +112 -0
  58. package/esm/resolveModuleDir.mjs +64 -0
  59. package/esm/resolveModuleId.mjs +30 -0
  60. package/esm/resolvePath.mjs +84 -0
  61. package/esm/resolvePaths.mjs +40 -0
  62. package/esm/split.mjs +22 -0
  63. package/esm/sys.mjs +258 -0
  64. package/package.json +5 -6
@@ -0,0 +1,82 @@
1
+ /**
2
+ *****************************************
3
+ * Created by edonet@163.com
4
+ * Created on 2025-05-26 22:30:23
5
+ *****************************************
6
+ */
7
+ 'use strict';
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.resolveAlias = resolveAlias;
10
+ exports.resolveDict = resolveDict;
11
+ /**
12
+ *****************************************
13
+ * 加载依赖
14
+ *****************************************
15
+ */
16
+ const dict_1 = require("./dict");
17
+ const cache_1 = require("./cache");
18
+ const resolveDirect_1 = require("./resolveDirect");
19
+ /**
20
+ *****************************************
21
+ * 缓存
22
+ *****************************************
23
+ */
24
+ const cached = (0, cache_1.cache)(new WeakMap());
25
+ /**
26
+ *****************************************
27
+ * 解析别名
28
+ *****************************************
29
+ */
30
+ function resolveAlias(alias) {
31
+ return cached.get(alias, resolveTarget);
32
+ }
33
+ /**
34
+ *****************************************
35
+ * 解析别名
36
+ *****************************************
37
+ */
38
+ function resolveTarget(alias) {
39
+ return resolveDict(alias, resolvePath);
40
+ }
41
+ /**
42
+ *****************************************
43
+ * 解析匹配路径
44
+ *****************************************
45
+ */
46
+ function resolvePath(key, value) {
47
+ const { test, resolve } = (0, resolveDirect_1.resolveDirect)(key);
48
+ const rule = resolve(value);
49
+ // 返回匹配函数
50
+ return function match(id, handler) {
51
+ if (test(id)) {
52
+ return handler(rule(id));
53
+ }
54
+ };
55
+ }
56
+ /**
57
+ *****************************************
58
+ * 解析字典
59
+ *****************************************
60
+ */
61
+ function resolveDict(data, handler) {
62
+ const result = new dict_1.Dict();
63
+ // 生成元素
64
+ Object.keys(data)
65
+ .forEach(key => result.set(key, handler(key, data[key])));
66
+ // 排序列表
67
+ result.sort((a, b) => {
68
+ const idxA = a.indexOf('*');
69
+ const idxB = b.indexOf('*');
70
+ const baseA = idxA === -1 ? a.length : idxA;
71
+ const baseB = idxB === -1 ? b.length : idxB;
72
+ // 比较基准长度
73
+ if (baseA !== baseB) {
74
+ return baseB - baseA;
75
+ }
76
+ else {
77
+ return idxA === -1 ? -1 : idxB === -1 ? 1 : b.length - a.length;
78
+ }
79
+ });
80
+ // 返回结果
81
+ return result;
82
+ }
@@ -0,0 +1,15 @@
1
+ /**
2
+ *****************************************
3
+ * 解析指令
4
+ *****************************************
5
+ */
6
+ export interface Direct {
7
+ test(id: string): boolean;
8
+ resolve(path: string): (id: string) => string;
9
+ }
10
+ /**
11
+ *****************************************
12
+ * 解析指令
13
+ *****************************************
14
+ */
15
+ export declare function resolveDirect(direct: string): Direct;
@@ -0,0 +1,144 @@
1
+ /**
2
+ *****************************************
3
+ * Created by edonet@163.com
4
+ * Created on 2026-03-18 13:32:09
5
+ *****************************************
6
+ */
7
+ 'use strict';
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.resolveDirect = resolveDirect;
10
+ /**
11
+ *****************************************
12
+ * 加载依赖
13
+ *****************************************
14
+ */
15
+ const node_path_1 = require("node:path");
16
+ const match_1 = require("./match");
17
+ const split_1 = require("./split");
18
+ /**
19
+ *****************************************
20
+ * 格式化路径
21
+ *****************************************
22
+ */
23
+ const sepReg = /\//g;
24
+ const normalizePath = (path) => path.replace(sepReg, node_path_1.sep);
25
+ /**
26
+ *****************************************
27
+ * 格式化路径
28
+ *****************************************
29
+ */
30
+ function normalizeFn(path) {
31
+ return node_path_1.sep === '\\' && (0, node_path_1.isAbsolute)(path) ? normalizePath : match_1.unary;
32
+ }
33
+ /**
34
+ *****************************************
35
+ * 解析指令
36
+ *****************************************
37
+ */
38
+ function resolveDirect(direct) {
39
+ const idx = direct.indexOf('*');
40
+ if (idx === -1) {
41
+ return {
42
+ test: id => id === direct,
43
+ resolve: path => () => path,
44
+ };
45
+ }
46
+ // 分割路径
47
+ const [prefix, suffix] = [direct.slice(0, idx), direct.slice(idx + 1)];
48
+ // 生成匹配规则
49
+ if (prefix) {
50
+ return suffix ? resolvePrefixSuffix(prefix, suffix) : resolvePrefix(prefix);
51
+ }
52
+ else {
53
+ return suffix ? resolveSuffix(suffix) : resolveWildcard();
54
+ }
55
+ }
56
+ /**
57
+ *****************************************
58
+ * 解析前/后缀
59
+ *****************************************
60
+ */
61
+ function resolvePrefixSuffix(prefix, suffix) {
62
+ const size = prefix.length + suffix.length;
63
+ return {
64
+ test(id) {
65
+ return id.length >= size && id.startsWith(prefix) && id.endsWith(suffix);
66
+ },
67
+ resolve(path) {
68
+ const [start, end] = (0, split_1.split)(path, '*');
69
+ const normalize = normalizeFn(start);
70
+ if (end === undefined) {
71
+ return () => start;
72
+ }
73
+ else {
74
+ return (id) => start + normalize(id.slice(prefix.length, -suffix.length)) + end;
75
+ }
76
+ },
77
+ };
78
+ }
79
+ /**
80
+ *****************************************
81
+ * 解析前缀
82
+ *****************************************
83
+ */
84
+ function resolvePrefix(prefix) {
85
+ return {
86
+ test(id) {
87
+ return id.startsWith(prefix);
88
+ },
89
+ resolve(path) {
90
+ const [start, end] = (0, split_1.split)(path, '*');
91
+ const normalize = normalizeFn(start);
92
+ if (end === undefined) {
93
+ return () => start;
94
+ }
95
+ else {
96
+ return (id) => start + normalize(id.slice(prefix.length)) + end;
97
+ }
98
+ },
99
+ };
100
+ }
101
+ /**
102
+ *****************************************
103
+ * 解析后缀
104
+ *****************************************
105
+ */
106
+ function resolveSuffix(suffix) {
107
+ return {
108
+ test(id) {
109
+ return id.endsWith(suffix);
110
+ },
111
+ resolve(val) {
112
+ const [start, end] = (0, split_1.split)(val, '*');
113
+ const normalize = normalizeFn(start);
114
+ if (end === undefined) {
115
+ return () => start;
116
+ }
117
+ else {
118
+ return (id) => start + normalize(id.slice(0, -suffix.length)) + end;
119
+ }
120
+ },
121
+ };
122
+ }
123
+ /**
124
+ *****************************************
125
+ * 解析通配符
126
+ *****************************************
127
+ */
128
+ function resolveWildcard() {
129
+ return {
130
+ test() {
131
+ return true;
132
+ },
133
+ resolve(val) {
134
+ const [start, end] = (0, split_1.split)(val, '*');
135
+ const normalize = normalizeFn(start);
136
+ if (end === undefined) {
137
+ return () => start;
138
+ }
139
+ else {
140
+ return (id) => start + normalize(id) + end;
141
+ }
142
+ },
143
+ };
144
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ *****************************************
3
+ * 加载依赖
4
+ *****************************************
5
+ */
6
+ import { TargetDescription } from './loadPackageDescription';
7
+ import { Handler } from './resolveAlias';
8
+ /**
9
+ *****************************************
10
+ * 解析导出描述
11
+ *****************************************
12
+ */
13
+ export declare function resolveTargetDescription(exports: (null | string | TargetDescription)[] | TargetDescription): TargetDescription;
14
+ /**
15
+ *****************************************
16
+ * 解析导出配置
17
+ *****************************************
18
+ */
19
+ export declare function resolveExports(id: string, conditions: string[], exports: TargetDescription[string], handler?: Handler): string | null | undefined;
@@ -0,0 +1,54 @@
1
+ /**
2
+ *****************************************
3
+ * Created by edonet@163.com
4
+ * Created on 2025-05-27 21:02:36
5
+ *****************************************
6
+ */
7
+ 'use strict';
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.resolveTargetDescription = resolveTargetDescription;
10
+ exports.resolveExports = resolveExports;
11
+ const resolveImports_1 = require("./resolveImports");
12
+ /**
13
+ *****************************************
14
+ * 缓存
15
+ *****************************************
16
+ */
17
+ const cache = new WeakMap();
18
+ /**
19
+ *****************************************
20
+ * 解析导出描述
21
+ *****************************************
22
+ */
23
+ function resolveTargetDescription(exports) {
24
+ const cached = cache.get(exports);
25
+ if (cached) {
26
+ return cached;
27
+ }
28
+ // 生成目标配置
29
+ const target = Array.isArray(exports) || !Object.keys(exports).some(key => key.charAt(0) === '.')
30
+ ? { '.': exports }
31
+ : exports;
32
+ // 添加缓存
33
+ cache.set(exports, target);
34
+ // 返回目标
35
+ return target;
36
+ }
37
+ /**
38
+ *****************************************
39
+ * 解析导出配置
40
+ *****************************************
41
+ */
42
+ function resolveExports(id, conditions, exports, handler) {
43
+ if (!exports) {
44
+ return;
45
+ }
46
+ // 处理导出路径
47
+ if (typeof exports === 'string') {
48
+ return id === '.' ? exports : undefined;
49
+ }
50
+ // 解析导出描述
51
+ const target = resolveTargetDescription(exports);
52
+ // 获取匹配函数
53
+ return (0, resolveImports_1.resolveImports)(id, conditions, target, handler);
54
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ *****************************************
3
+ * 加载依赖
4
+ *****************************************
5
+ */
6
+ import { TargetDescription } from './loadPackageDescription';
7
+ import { Handler } from './resolveAlias';
8
+ /**
9
+ *****************************************
10
+ * 映射函数
11
+ *****************************************
12
+ */
13
+ export interface Direct {
14
+ [key: string]: Handler | Direct | (Handler | Direct)[];
15
+ }
16
+ /**
17
+ *****************************************
18
+ * 解析目标
19
+ *****************************************
20
+ */
21
+ export declare function resolveImports(id: string, conditions: string[], target: TargetDescription, handler?: Handler): string | null | undefined;
@@ -0,0 +1,114 @@
1
+ /**
2
+ *****************************************
3
+ * Created by edonet@163.com
4
+ * Created on 2025-06-22 11:21:37
5
+ *****************************************
6
+ */
7
+ 'use strict';
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.resolveImports = resolveImports;
10
+ const match_1 = require("./match");
11
+ const cache_1 = require("./cache");
12
+ const resolveAlias_1 = require("./resolveAlias");
13
+ const resolveDirect_1 = require("./resolveDirect");
14
+ /**
15
+ *****************************************
16
+ * 缓存
17
+ *****************************************
18
+ */
19
+ const cached = (0, cache_1.cache)(new WeakMap());
20
+ /**
21
+ *****************************************
22
+ * 解析目标
23
+ *****************************************
24
+ */
25
+ function resolveImports(id, conditions, target, handler) {
26
+ const rules = cached.get(target, () => (0, resolveAlias_1.resolveDict)(target, resolveTargetDescription));
27
+ const resolve = handler || match_1.unary;
28
+ // 返回匹配函数
29
+ return rules.match(rule => {
30
+ if (rule.test(id)) {
31
+ return resolvePath(id, conditions, rule.direct, resolve);
32
+ }
33
+ });
34
+ }
35
+ /**
36
+ *****************************************
37
+ * 解析规则
38
+ *****************************************
39
+ */
40
+ function resolveTargetDescription(key, value) {
41
+ const { test, resolve } = (0, resolveDirect_1.resolveDirect)(key);
42
+ // 返回配置规则
43
+ return {
44
+ test,
45
+ direct: walk(value, resolve),
46
+ };
47
+ }
48
+ /**
49
+ *****************************************
50
+ * 解析重定向
51
+ *****************************************
52
+ */
53
+ function walk(value, handler) {
54
+ switch (typeof value) {
55
+ case 'string':
56
+ return handler(value);
57
+ case 'object':
58
+ break;
59
+ default:
60
+ return match_1.nil;
61
+ }
62
+ // 处理空目标
63
+ if (!value) {
64
+ return match_1.nil;
65
+ }
66
+ // 处理数组目标
67
+ if (Array.isArray(value)) {
68
+ return value.map(id => walk(id, handler));
69
+ }
70
+ // 定义结果
71
+ const direct = {};
72
+ // 遍历目标描述
73
+ Object.keys(value)
74
+ .forEach(key => {
75
+ direct[key] = walk(value[key], handler);
76
+ });
77
+ // 返回结果
78
+ return direct;
79
+ }
80
+ /**
81
+ *****************************************
82
+ * 解析规则
83
+ *****************************************
84
+ */
85
+ function resolvePath(id, conditions, rule, handler) {
86
+ switch (typeof rule) {
87
+ case 'function':
88
+ return resolvePath(id, conditions, rule(id), handler);
89
+ case 'string':
90
+ return handler(rule);
91
+ case 'object':
92
+ break;
93
+ default:
94
+ return;
95
+ }
96
+ // 处理空规则
97
+ if (!rule) {
98
+ return null;
99
+ }
100
+ // 处理数组
101
+ if (Array.isArray(rule)) {
102
+ return (0, match_1.match)(rule, value => resolvePath(id, conditions, value, handler));
103
+ }
104
+ // 处理条件映射
105
+ const condition = conditions.find(key => rule[key]);
106
+ const value = condition ? rule[condition] : rule.default;
107
+ // 存在解析时,继续解析
108
+ if (value) {
109
+ return resolvePath(id, conditions, value, handler);
110
+ }
111
+ else {
112
+ return value;
113
+ }
114
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ *****************************************
3
+ * 解析模块目录
4
+ *****************************************
5
+ */
6
+ export declare function resolveModuleDir(id: string, from: string): string | undefined;
7
+ /**
8
+ *****************************************
9
+ * 解析模块目录列表
10
+ *****************************************
11
+ */
12
+ export declare function resolveModuleDirs(from: string | undefined): string[];
@@ -0,0 +1,67 @@
1
+ /**
2
+ *****************************************
3
+ * Created by edonet@163.com
4
+ * Created on 2025-05-29 20:26:27
5
+ *****************************************
6
+ */
7
+ 'use strict';
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.resolveModuleDir = resolveModuleDir;
10
+ exports.resolveModuleDirs = resolveModuleDirs;
11
+ /**
12
+ *****************************************
13
+ * 加载依赖
14
+ *****************************************
15
+ */
16
+ const node_path_1 = require("node:path");
17
+ const dirname_1 = require("./dirname");
18
+ const stat_1 = require("./stat");
19
+ const match_1 = require("./match");
20
+ /**
21
+ *****************************************
22
+ * 模块路径缓存
23
+ *****************************************
24
+ */
25
+ const cacheModuleDirs = new Map();
26
+ const cacheModuleDir = new Map();
27
+ /**
28
+ *****************************************
29
+ * 解析模块目录
30
+ *****************************************
31
+ */
32
+ function resolveModuleDir(id, from) {
33
+ const cacheId = `${from}:${id}`;
34
+ if (cacheModuleDir.has(cacheId)) {
35
+ return cacheModuleDir.get(cacheId);
36
+ }
37
+ // 解析目录
38
+ const dirs = resolveModuleDirs(from);
39
+ const result = (0, match_1.match)(dirs, dir => (0, stat_1.isDir)((0, node_path_1.resolve)(dir, id)));
40
+ // 缓存结果
41
+ cacheModuleDir.set(cacheId, result);
42
+ // 返回结果
43
+ return result;
44
+ }
45
+ /**
46
+ *****************************************
47
+ * 解析模块目录列表
48
+ *****************************************
49
+ */
50
+ function resolveModuleDirs(from) {
51
+ if (!from) {
52
+ return [];
53
+ }
54
+ // 存在缓存时,直接返回
55
+ const cached = cacheModuleDirs.get(from);
56
+ if (cached) {
57
+ return cached;
58
+ }
59
+ // 解析目录
60
+ const dirs = resolveModuleDirs((0, dirname_1.dirname)(from));
61
+ const dir = (0, node_path_1.join)(from, 'node_modules');
62
+ const result = (0, stat_1.isDir)(dir) ? [dir, ...dirs] : dirs;
63
+ // 缓存结果
64
+ cacheModuleDirs.set(from, result);
65
+ // 返回结果
66
+ return result;
67
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ *****************************************
3
+ * 解析模块路径
4
+ *****************************************
5
+ */
6
+ export declare function resolveModuleId(id: string): [string, string];
@@ -0,0 +1,32 @@
1
+ /**
2
+ *****************************************
3
+ * Created by edonet@163.com
4
+ * Created on 2025-05-29 20:26:27
5
+ *****************************************
6
+ */
7
+ 'use strict';
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.resolveModuleId = resolveModuleId;
10
+ /**
11
+ *****************************************
12
+ * 解析模块路径
13
+ *****************************************
14
+ */
15
+ function resolveModuleId(id) {
16
+ const idx1 = id.indexOf('/');
17
+ // 处理不带域的模块路径
18
+ if (idx1 === -1) {
19
+ return [id, '.'];
20
+ }
21
+ else if (id.charAt(0) !== '@') {
22
+ return [id.slice(0, idx1), '.' + id.slice(idx1)];
23
+ }
24
+ // 分割模块路径
25
+ const idx2 = id.indexOf('/', idx1 + 1);
26
+ if (idx2 === -1) {
27
+ return [id, '.'];
28
+ }
29
+ else {
30
+ return [id.slice(0, idx2), '.' + id.slice(idx2)];
31
+ }
32
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ *****************************************
3
+ * 文件系统
4
+ *****************************************
5
+ */
6
+ export interface Options {
7
+ baseUrl?: string;
8
+ alias?: Record<string, string>;
9
+ paths?: Record<string, string[]>;
10
+ cache?: Map<string, string | null | undefined>;
11
+ cwd?: string;
12
+ module?: boolean;
13
+ moduleExports?: boolean;
14
+ mainFields?: string[];
15
+ conditions?: string[];
16
+ extensions?: string[];
17
+ }
18
+ /**
19
+ *****************************************
20
+ * 解析路径
21
+ *****************************************
22
+ */
23
+ export declare function resolvePath(id: string, issuer?: string, options?: Options): string | null | undefined;
@@ -0,0 +1,86 @@
1
+ /**
2
+ *****************************************
3
+ * Created by edonet@163.com
4
+ * Created on 2026-03-18 20:06:20
5
+ *****************************************
6
+ */
7
+ 'use strict';
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.resolvePath = resolvePath;
10
+ /**
11
+ *****************************************
12
+ * 加载依赖
13
+ *****************************************
14
+ */
15
+ const node_path_1 = require("node:path");
16
+ const loadTsConfig_1 = require("./loadTsConfig");
17
+ const sys_1 = require("./sys");
18
+ const isEsmModule_1 = require("./isEsmModule");
19
+ /**
20
+ *****************************************
21
+ * 创建文件系统
22
+ *****************************************
23
+ */
24
+ function createFileSystem(options) {
25
+ return {
26
+ ...sys_1.sys,
27
+ ...options,
28
+ cache: options.cache || sys_1.sys.cache,
29
+ cwd: options.cwd || sys_1.sys.cwd,
30
+ mainFields: options.mainFields || sys_1.sys.mainFields,
31
+ conditions: options.conditions || sys_1.sys.conditions,
32
+ extensions: options.extensions || sys_1.sys.extensions,
33
+ };
34
+ }
35
+ /**
36
+ *****************************************
37
+ * 判断是否为 ESM 模块
38
+ *****************************************
39
+ */
40
+ function isEsmModule(dir, filename) {
41
+ if (filename) {
42
+ const result = (0, isEsmModule_1.isEsmFile)(filename);
43
+ if (result !== undefined) {
44
+ return result;
45
+ }
46
+ }
47
+ // 判断为 ESM 模块
48
+ if ((0, isEsmModule_1.isEsmPackage)(dir)) {
49
+ return true;
50
+ }
51
+ // 判断 TS 配置
52
+ const { module } = (0, loadTsConfig_1.loadCompilerOptions)(dir) || {};
53
+ if (module && module.toLowerCase().startsWith('es')) {
54
+ return true;
55
+ }
56
+ else {
57
+ return false;
58
+ }
59
+ }
60
+ /**
61
+ *****************************************
62
+ * 解析路径
63
+ *****************************************
64
+ */
65
+ function resolvePath(id, issuer, options) {
66
+ const from = issuer ? (0, node_path_1.dirname)((0, node_path_1.resolve)(issuer)) : process.cwd();
67
+ const opts = options || {};
68
+ const sys = createFileSystem(opts);
69
+ // 设置模块路径映射
70
+ if (!opts.paths && !opts.baseUrl) {
71
+ const { baseUrl, paths } = (0, loadTsConfig_1.loadCompilerOptions)(from) || {};
72
+ sys.baseUrl = baseUrl;
73
+ sys.paths = paths;
74
+ }
75
+ else {
76
+ sys.baseUrl = opts.baseUrl && (0, node_path_1.resolve)(opts.baseUrl);
77
+ }
78
+ // 设置加载条件
79
+ if (!opts.conditions) {
80
+ sys.conditions = isEsmModule(from, issuer) ? ['import', 'node'] : ['require', 'node'];
81
+ }
82
+ // 生成缓存 ID
83
+ sys.cacheSalt = sys.conditions.join(',');
84
+ // 执行解析
85
+ return sys.resolve(id, from);
86
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ *****************************************
3
+ * 加载依赖
4
+ *****************************************
5
+ */
6
+ import { Dict } from './dict';
7
+ import { Match } from './resolveAlias';
8
+ /**
9
+ *****************************************
10
+ * 解析别名
11
+ *****************************************
12
+ */
13
+ export declare function resolvePaths(paths: Record<string, string[]>): Dict<Match>;