@enactprotocol/shared 1.2.13 → 2.0.1
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 +44 -0
- package/dist/config.d.ts +164 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +386 -0
- package/dist/config.js.map +1 -0
- package/dist/constants.d.ts +15 -5
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +24 -8
- package/dist/constants.js.map +1 -0
- package/dist/execution/command.d.ts +102 -0
- package/dist/execution/command.d.ts.map +1 -0
- package/dist/execution/command.js +262 -0
- package/dist/execution/command.js.map +1 -0
- package/dist/execution/index.d.ts +12 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +17 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/runtime.d.ts +82 -0
- package/dist/execution/runtime.d.ts.map +1 -0
- package/dist/execution/runtime.js +273 -0
- package/dist/execution/runtime.js.map +1 -0
- package/dist/execution/types.d.ts +306 -0
- package/dist/execution/types.d.ts.map +1 -0
- package/dist/execution/types.js +14 -0
- package/dist/execution/types.js.map +1 -0
- package/dist/execution/validation.d.ts +43 -0
- package/dist/execution/validation.d.ts.map +1 -0
- package/dist/execution/validation.js +430 -0
- package/dist/execution/validation.js.map +1 -0
- package/dist/index.d.ts +21 -21
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -25
- package/dist/index.js.map +1 -0
- package/dist/manifest/index.d.ts +7 -0
- package/dist/manifest/index.d.ts.map +1 -0
- package/dist/manifest/index.js +10 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/manifest/loader.d.ts +76 -0
- package/dist/manifest/loader.d.ts.map +1 -0
- package/dist/manifest/loader.js +146 -0
- package/dist/manifest/loader.js.map +1 -0
- package/dist/manifest/parser.d.ts +64 -0
- package/dist/manifest/parser.d.ts.map +1 -0
- package/dist/manifest/parser.js +135 -0
- package/dist/manifest/parser.js.map +1 -0
- package/dist/manifest/validator.d.ts +95 -0
- package/dist/manifest/validator.d.ts.map +1 -0
- package/dist/manifest/validator.js +258 -0
- package/dist/manifest/validator.js.map +1 -0
- package/dist/paths.d.ts +57 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +93 -0
- package/dist/paths.js.map +1 -0
- package/dist/registry.d.ts +73 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +147 -0
- package/dist/registry.js.map +1 -0
- package/dist/resolver.d.ts +89 -0
- package/dist/resolver.d.ts.map +1 -0
- package/dist/resolver.js +282 -0
- package/dist/resolver.js.map +1 -0
- package/dist/types/index.d.ts +6 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/manifest.d.ts +201 -0
- package/dist/types/manifest.d.ts.map +1 -0
- package/dist/types/manifest.js +13 -0
- package/dist/types/manifest.js.map +1 -0
- package/dist/types.d.ts +5 -132
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -3
- package/dist/types.js.map +1 -0
- package/dist/utils/fs.d.ts +105 -0
- package/dist/utils/fs.d.ts.map +1 -0
- package/dist/utils/fs.js +233 -0
- package/dist/utils/fs.js.map +1 -0
- package/dist/utils/logger.d.ts +102 -25
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +214 -57
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/version.d.ts +60 -2
- package/dist/utils/version.d.ts.map +1 -0
- package/dist/utils/version.js +255 -31
- package/dist/utils/version.js.map +1 -0
- package/package.json +16 -58
- package/src/config.ts +510 -0
- package/src/constants.ts +36 -0
- package/src/execution/command.ts +314 -0
- package/src/execution/index.ts +73 -0
- package/src/execution/runtime.ts +308 -0
- package/src/execution/types.ts +379 -0
- package/src/execution/validation.ts +508 -0
- package/src/index.ts +238 -30
- package/src/manifest/index.ts +36 -0
- package/src/manifest/loader.ts +187 -0
- package/src/manifest/parser.ts +173 -0
- package/src/manifest/validator.ts +309 -0
- package/src/paths.ts +108 -0
- package/src/registry.ts +219 -0
- package/src/resolver.ts +345 -0
- package/src/types/index.ts +30 -0
- package/src/types/manifest.ts +255 -0
- package/src/types.ts +5 -188
- package/src/utils/fs.ts +281 -0
- package/src/utils/logger.ts +270 -59
- package/src/utils/version.ts +304 -36
- package/tests/config.test.ts +515 -0
- package/tests/execution/command.test.ts +317 -0
- package/tests/execution/validation.test.ts +384 -0
- package/tests/fixtures/invalid-tool.yaml +4 -0
- package/tests/fixtures/valid-tool.md +62 -0
- package/tests/fixtures/valid-tool.yaml +40 -0
- package/tests/index.test.ts +8 -0
- package/tests/manifest/loader.test.ts +291 -0
- package/tests/manifest/parser.test.ts +345 -0
- package/tests/manifest/validator.test.ts +394 -0
- package/tests/manifest-types.test.ts +358 -0
- package/tests/paths.test.ts +153 -0
- package/tests/registry.test.ts +231 -0
- package/tests/resolver.test.ts +272 -0
- package/tests/utils/fs.test.ts +388 -0
- package/tests/utils/logger.test.ts +480 -0
- package/tests/utils/version.test.ts +390 -0
- package/tsconfig.json +12 -0
- package/dist/LocalToolResolver.d.ts +0 -84
- package/dist/LocalToolResolver.js +0 -353
- package/dist/api/enact-api.d.ts +0 -130
- package/dist/api/enact-api.js +0 -428
- package/dist/api/index.d.ts +0 -2
- package/dist/api/index.js +0 -2
- package/dist/api/types.d.ts +0 -103
- package/dist/api/types.js +0 -1
- package/dist/core/DaggerExecutionProvider.d.ts +0 -169
- package/dist/core/DaggerExecutionProvider.js +0 -1029
- package/dist/core/DirectExecutionProvider.d.ts +0 -23
- package/dist/core/DirectExecutionProvider.js +0 -406
- package/dist/core/EnactCore.d.ts +0 -162
- package/dist/core/EnactCore.js +0 -597
- package/dist/core/NativeExecutionProvider.d.ts +0 -9
- package/dist/core/NativeExecutionProvider.js +0 -16
- package/dist/core/index.d.ts +0 -3
- package/dist/core/index.js +0 -3
- package/dist/exec/index.d.ts +0 -3
- package/dist/exec/index.js +0 -3
- package/dist/exec/logger.d.ts +0 -11
- package/dist/exec/logger.js +0 -57
- package/dist/exec/validate.d.ts +0 -5
- package/dist/exec/validate.js +0 -167
- package/dist/lib/enact-direct.d.ts +0 -150
- package/dist/lib/enact-direct.js +0 -159
- package/dist/lib/index.d.ts +0 -1
- package/dist/lib/index.js +0 -1
- package/dist/security/index.d.ts +0 -3
- package/dist/security/index.js +0 -3
- package/dist/security/security.d.ts +0 -23
- package/dist/security/security.js +0 -137
- package/dist/security/sign.d.ts +0 -103
- package/dist/security/sign.js +0 -666
- package/dist/security/verification-enforcer.d.ts +0 -53
- package/dist/security/verification-enforcer.js +0 -204
- package/dist/services/McpCoreService.d.ts +0 -98
- package/dist/services/McpCoreService.js +0 -124
- package/dist/services/index.d.ts +0 -1
- package/dist/services/index.js +0 -1
- package/dist/utils/config.d.ts +0 -111
- package/dist/utils/config.js +0 -342
- package/dist/utils/env-loader.d.ts +0 -54
- package/dist/utils/env-loader.js +0 -270
- package/dist/utils/help.d.ts +0 -36
- package/dist/utils/help.js +0 -248
- package/dist/utils/index.d.ts +0 -7
- package/dist/utils/index.js +0 -7
- package/dist/utils/silent-monitor.d.ts +0 -67
- package/dist/utils/silent-monitor.js +0 -242
- package/dist/utils/timeout.d.ts +0 -5
- package/dist/utils/timeout.js +0 -23
- package/dist/web/env-manager-server.d.ts +0 -29
- package/dist/web/env-manager-server.js +0 -367
- package/dist/web/index.d.ts +0 -1
- package/dist/web/index.js +0 -1
- package/src/LocalToolResolver.ts +0 -424
- package/src/api/enact-api.ts +0 -604
- package/src/api/index.ts +0 -2
- package/src/api/types.ts +0 -114
- package/src/core/DaggerExecutionProvider.ts +0 -1357
- package/src/core/DirectExecutionProvider.ts +0 -484
- package/src/core/EnactCore.ts +0 -847
- package/src/core/index.ts +0 -3
- package/src/exec/index.ts +0 -3
- package/src/exec/logger.ts +0 -63
- package/src/exec/validate.ts +0 -238
- package/src/lib/enact-direct.ts +0 -254
- package/src/lib/index.ts +0 -1
- package/src/services/McpCoreService.ts +0 -201
- package/src/services/index.ts +0 -1
- package/src/utils/config.ts +0 -438
- package/src/utils/env-loader.ts +0 -370
- package/src/utils/help.ts +0 -257
- package/src/utils/index.ts +0 -7
- package/src/utils/silent-monitor.ts +0 -328
- package/src/utils/timeout.ts +0 -26
- package/src/web/env-manager-server.ts +0 -465
- package/src/web/index.ts +0 -1
- package/src/web/static/app.js +0 -663
- package/src/web/static/index.html +0 -117
- package/src/web/static/style.css +0 -291
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
coerceVersion,
|
|
4
|
+
compareVersions,
|
|
5
|
+
formatVersion,
|
|
6
|
+
getHighestVersion,
|
|
7
|
+
incrementVersion,
|
|
8
|
+
isValidVersion,
|
|
9
|
+
parseRange,
|
|
10
|
+
parseVersion,
|
|
11
|
+
satisfiesRange,
|
|
12
|
+
sortVersions,
|
|
13
|
+
} from "../../src/utils/version";
|
|
14
|
+
|
|
15
|
+
describe("Version utilities", () => {
|
|
16
|
+
describe("parseVersion", () => {
|
|
17
|
+
test("parses simple version", () => {
|
|
18
|
+
const result = parseVersion("1.2.3");
|
|
19
|
+
expect(result).not.toBeNull();
|
|
20
|
+
expect(result?.major).toBe(1);
|
|
21
|
+
expect(result?.minor).toBe(2);
|
|
22
|
+
expect(result?.patch).toBe(3);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("parses version with v prefix", () => {
|
|
26
|
+
const result = parseVersion("v1.2.3");
|
|
27
|
+
expect(result).not.toBeNull();
|
|
28
|
+
expect(result?.major).toBe(1);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("parses major only", () => {
|
|
32
|
+
const result = parseVersion("1");
|
|
33
|
+
expect(result).not.toBeNull();
|
|
34
|
+
expect(result?.major).toBe(1);
|
|
35
|
+
expect(result?.minor).toBe(0);
|
|
36
|
+
expect(result?.patch).toBe(0);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("parses major.minor", () => {
|
|
40
|
+
const result = parseVersion("1.2");
|
|
41
|
+
expect(result).not.toBeNull();
|
|
42
|
+
expect(result?.major).toBe(1);
|
|
43
|
+
expect(result?.minor).toBe(2);
|
|
44
|
+
expect(result?.patch).toBe(0);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test("parses version with prerelease", () => {
|
|
48
|
+
const result = parseVersion("1.2.3-alpha.1");
|
|
49
|
+
expect(result).not.toBeNull();
|
|
50
|
+
expect(result?.prerelease).toBe("alpha.1");
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("parses version with build metadata", () => {
|
|
54
|
+
const result = parseVersion("1.2.3+build.123");
|
|
55
|
+
expect(result).not.toBeNull();
|
|
56
|
+
expect(result?.build).toBe("build.123");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("parses version with prerelease and build", () => {
|
|
60
|
+
const result = parseVersion("1.2.3-beta.2+build.456");
|
|
61
|
+
expect(result).not.toBeNull();
|
|
62
|
+
expect(result?.prerelease).toBe("beta.2");
|
|
63
|
+
expect(result?.build).toBe("build.456");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
test("trims whitespace", () => {
|
|
67
|
+
const result = parseVersion(" 1.2.3 ");
|
|
68
|
+
expect(result).not.toBeNull();
|
|
69
|
+
expect(result?.major).toBe(1);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
test("stores raw version", () => {
|
|
73
|
+
const result = parseVersion("v1.2.3");
|
|
74
|
+
expect(result?.raw).toBe("v1.2.3");
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("returns null for invalid version", () => {
|
|
78
|
+
expect(parseVersion("invalid")).toBeNull();
|
|
79
|
+
expect(parseVersion("")).toBeNull();
|
|
80
|
+
expect(parseVersion("a.b.c")).toBeNull();
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
describe("isValidVersion", () => {
|
|
85
|
+
test("returns true for valid versions", () => {
|
|
86
|
+
expect(isValidVersion("1.0.0")).toBe(true);
|
|
87
|
+
expect(isValidVersion("0.0.1")).toBe(true);
|
|
88
|
+
expect(isValidVersion("1.2.3-alpha")).toBe(true);
|
|
89
|
+
expect(isValidVersion("v2.0.0")).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("returns false for invalid versions", () => {
|
|
93
|
+
expect(isValidVersion("invalid")).toBe(false);
|
|
94
|
+
expect(isValidVersion("")).toBe(false);
|
|
95
|
+
expect(isValidVersion("1.2.x")).toBe(false);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe("compareVersions", () => {
|
|
100
|
+
test("compares major versions", () => {
|
|
101
|
+
expect(compareVersions("1.0.0", "2.0.0")).toBe(-1);
|
|
102
|
+
expect(compareVersions("2.0.0", "1.0.0")).toBe(1);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("compares minor versions", () => {
|
|
106
|
+
expect(compareVersions("1.0.0", "1.1.0")).toBe(-1);
|
|
107
|
+
expect(compareVersions("1.1.0", "1.0.0")).toBe(1);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
test("compares patch versions", () => {
|
|
111
|
+
expect(compareVersions("1.0.0", "1.0.1")).toBe(-1);
|
|
112
|
+
expect(compareVersions("1.0.1", "1.0.0")).toBe(1);
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test("returns 0 for equal versions", () => {
|
|
116
|
+
expect(compareVersions("1.0.0", "1.0.0")).toBe(0);
|
|
117
|
+
expect(compareVersions("v1.0.0", "1.0.0")).toBe(0);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
test("prerelease is less than release", () => {
|
|
121
|
+
expect(compareVersions("1.0.0-alpha", "1.0.0")).toBe(-1);
|
|
122
|
+
expect(compareVersions("1.0.0", "1.0.0-alpha")).toBe(1);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test("compares prereleases", () => {
|
|
126
|
+
expect(compareVersions("1.0.0-alpha", "1.0.0-beta")).toBe(-1);
|
|
127
|
+
expect(compareVersions("1.0.0-alpha.1", "1.0.0-alpha.2")).toBe(-1);
|
|
128
|
+
expect(compareVersions("1.0.0-1", "1.0.0-2")).toBe(-1);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("handles invalid versions", () => {
|
|
132
|
+
expect(compareVersions("invalid", "1.0.0")).toBe(1);
|
|
133
|
+
expect(compareVersions("1.0.0", "invalid")).toBe(-1);
|
|
134
|
+
expect(compareVersions("invalid", "invalid")).toBe(0);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("parseRange", () => {
|
|
139
|
+
test("parses exact range", () => {
|
|
140
|
+
const result = parseRange("=1.0.0");
|
|
141
|
+
expect(result).not.toBeNull();
|
|
142
|
+
expect(result?.operator).toBe("=");
|
|
143
|
+
expect(result?.version.major).toBe(1);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test("parses greater than range", () => {
|
|
147
|
+
const result = parseRange(">1.0.0");
|
|
148
|
+
expect(result).not.toBeNull();
|
|
149
|
+
expect(result?.operator).toBe(">");
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
test("parses greater or equal range", () => {
|
|
153
|
+
const result = parseRange(">=1.0.0");
|
|
154
|
+
expect(result).not.toBeNull();
|
|
155
|
+
expect(result?.operator).toBe(">=");
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
test("parses less than range", () => {
|
|
159
|
+
const result = parseRange("<2.0.0");
|
|
160
|
+
expect(result).not.toBeNull();
|
|
161
|
+
expect(result?.operator).toBe("<");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
test("parses less or equal range", () => {
|
|
165
|
+
const result = parseRange("<=2.0.0");
|
|
166
|
+
expect(result).not.toBeNull();
|
|
167
|
+
expect(result?.operator).toBe("<=");
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
test("parses caret range", () => {
|
|
171
|
+
const result = parseRange("^1.0.0");
|
|
172
|
+
expect(result).not.toBeNull();
|
|
173
|
+
expect(result?.operator).toBe("^");
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
test("parses tilde range", () => {
|
|
177
|
+
const result = parseRange("~1.0.0");
|
|
178
|
+
expect(result).not.toBeNull();
|
|
179
|
+
expect(result?.operator).toBe("~");
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
test("defaults to exact match without operator", () => {
|
|
183
|
+
const result = parseRange("1.0.0");
|
|
184
|
+
expect(result).not.toBeNull();
|
|
185
|
+
expect(result?.operator).toBe("=");
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test("returns null for invalid range", () => {
|
|
189
|
+
expect(parseRange("")).toBeNull();
|
|
190
|
+
expect(parseRange("invalid")).toBeNull();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe("satisfiesRange", () => {
|
|
195
|
+
test("exact match", () => {
|
|
196
|
+
expect(satisfiesRange("1.0.0", "=1.0.0")).toBe(true);
|
|
197
|
+
expect(satisfiesRange("1.0.0", "1.0.0")).toBe(true);
|
|
198
|
+
expect(satisfiesRange("1.0.1", "=1.0.0")).toBe(false);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test("greater than", () => {
|
|
202
|
+
expect(satisfiesRange("1.0.1", ">1.0.0")).toBe(true);
|
|
203
|
+
expect(satisfiesRange("1.0.0", ">1.0.0")).toBe(false);
|
|
204
|
+
expect(satisfiesRange("0.9.0", ">1.0.0")).toBe(false);
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
test("greater or equal", () => {
|
|
208
|
+
expect(satisfiesRange("1.0.1", ">=1.0.0")).toBe(true);
|
|
209
|
+
expect(satisfiesRange("1.0.0", ">=1.0.0")).toBe(true);
|
|
210
|
+
expect(satisfiesRange("0.9.0", ">=1.0.0")).toBe(false);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test("less than", () => {
|
|
214
|
+
expect(satisfiesRange("0.9.0", "<1.0.0")).toBe(true);
|
|
215
|
+
expect(satisfiesRange("1.0.0", "<1.0.0")).toBe(false);
|
|
216
|
+
expect(satisfiesRange("1.0.1", "<1.0.0")).toBe(false);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
test("less or equal", () => {
|
|
220
|
+
expect(satisfiesRange("0.9.0", "<=1.0.0")).toBe(true);
|
|
221
|
+
expect(satisfiesRange("1.0.0", "<=1.0.0")).toBe(true);
|
|
222
|
+
expect(satisfiesRange("1.0.1", "<=1.0.0")).toBe(false);
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
test("caret range with major version", () => {
|
|
226
|
+
// ^1.2.3 := >=1.2.3 <2.0.0
|
|
227
|
+
expect(satisfiesRange("1.2.3", "^1.2.3")).toBe(true);
|
|
228
|
+
expect(satisfiesRange("1.3.0", "^1.2.3")).toBe(true);
|
|
229
|
+
expect(satisfiesRange("1.9.9", "^1.2.3")).toBe(true);
|
|
230
|
+
expect(satisfiesRange("2.0.0", "^1.2.3")).toBe(false);
|
|
231
|
+
expect(satisfiesRange("1.2.2", "^1.2.3")).toBe(false);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
test("caret range with 0.x", () => {
|
|
235
|
+
// ^0.2.3 := >=0.2.3 <0.3.0
|
|
236
|
+
expect(satisfiesRange("0.2.3", "^0.2.3")).toBe(true);
|
|
237
|
+
expect(satisfiesRange("0.2.9", "^0.2.3")).toBe(true);
|
|
238
|
+
expect(satisfiesRange("0.3.0", "^0.2.3")).toBe(false);
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
test("caret range with 0.0.x", () => {
|
|
242
|
+
// ^0.0.3 := >=0.0.3 <0.0.4
|
|
243
|
+
expect(satisfiesRange("0.0.3", "^0.0.3")).toBe(true);
|
|
244
|
+
expect(satisfiesRange("0.0.4", "^0.0.3")).toBe(false);
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
test("tilde range", () => {
|
|
248
|
+
// ~1.2.3 := >=1.2.3 <1.3.0
|
|
249
|
+
expect(satisfiesRange("1.2.3", "~1.2.3")).toBe(true);
|
|
250
|
+
expect(satisfiesRange("1.2.9", "~1.2.3")).toBe(true);
|
|
251
|
+
expect(satisfiesRange("1.3.0", "~1.2.3")).toBe(false);
|
|
252
|
+
expect(satisfiesRange("1.2.2", "~1.2.3")).toBe(false);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test("returns false for invalid input", () => {
|
|
256
|
+
expect(satisfiesRange("invalid", "1.0.0")).toBe(false);
|
|
257
|
+
expect(satisfiesRange("1.0.0", "invalid")).toBe(false);
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
describe("sortVersions", () => {
|
|
262
|
+
test("sorts versions ascending", () => {
|
|
263
|
+
const result = sortVersions(["2.0.0", "1.0.0", "1.1.0"]);
|
|
264
|
+
expect(result).toEqual(["1.0.0", "1.1.0", "2.0.0"]);
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
test("handles prerelease versions", () => {
|
|
268
|
+
const result = sortVersions(["1.0.0", "1.0.0-alpha", "1.0.0-beta"]);
|
|
269
|
+
expect(result).toEqual(["1.0.0-alpha", "1.0.0-beta", "1.0.0"]);
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
test("does not modify original array", () => {
|
|
273
|
+
const original = ["2.0.0", "1.0.0"];
|
|
274
|
+
sortVersions(original);
|
|
275
|
+
expect(original).toEqual(["2.0.0", "1.0.0"]);
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
describe("getHighestVersion", () => {
|
|
280
|
+
test("returns highest version", () => {
|
|
281
|
+
expect(getHighestVersion(["1.0.0", "2.0.0", "1.5.0"])).toBe("2.0.0");
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
test("returns null for empty array", () => {
|
|
285
|
+
expect(getHighestVersion([])).toBeNull();
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
test("filters invalid versions", () => {
|
|
289
|
+
expect(getHighestVersion(["invalid", "1.0.0", "also-invalid"])).toBe("1.0.0");
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
test("returns null if all invalid", () => {
|
|
293
|
+
expect(getHighestVersion(["invalid", "also-invalid"])).toBeNull();
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
describe("incrementVersion", () => {
|
|
298
|
+
test("increments major", () => {
|
|
299
|
+
expect(incrementVersion("1.2.3", "major")).toBe("2.0.0");
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
test("increments minor", () => {
|
|
303
|
+
expect(incrementVersion("1.2.3", "minor")).toBe("1.3.0");
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
test("increments patch", () => {
|
|
307
|
+
expect(incrementVersion("1.2.3", "patch")).toBe("1.2.4");
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
test("returns null for invalid version", () => {
|
|
311
|
+
expect(incrementVersion("invalid", "patch")).toBeNull();
|
|
312
|
+
});
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
describe("coerceVersion", () => {
|
|
316
|
+
test("coerces complete version", () => {
|
|
317
|
+
expect(coerceVersion("1.2.3")).toBe("1.2.3");
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
test("fills in missing minor and patch", () => {
|
|
321
|
+
expect(coerceVersion("1")).toBe("1.0.0");
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
test("fills in missing patch", () => {
|
|
325
|
+
expect(coerceVersion("1.2")).toBe("1.2.0");
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
test("strips prerelease and build", () => {
|
|
329
|
+
expect(coerceVersion("1.2.3-alpha")).toBe("1.2.3");
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
test("handles v prefix", () => {
|
|
333
|
+
expect(coerceVersion("v1.2.3")).toBe("1.2.3");
|
|
334
|
+
});
|
|
335
|
+
|
|
336
|
+
test("returns null for non-version", () => {
|
|
337
|
+
expect(coerceVersion("invalid")).toBeNull();
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
describe("formatVersion", () => {
|
|
342
|
+
test("formats simple version", () => {
|
|
343
|
+
expect(
|
|
344
|
+
formatVersion({
|
|
345
|
+
major: 1,
|
|
346
|
+
minor: 2,
|
|
347
|
+
patch: 3,
|
|
348
|
+
raw: "1.2.3",
|
|
349
|
+
})
|
|
350
|
+
).toBe("1.2.3");
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
test("formats version with prerelease", () => {
|
|
354
|
+
expect(
|
|
355
|
+
formatVersion({
|
|
356
|
+
major: 1,
|
|
357
|
+
minor: 0,
|
|
358
|
+
patch: 0,
|
|
359
|
+
prerelease: "alpha.1",
|
|
360
|
+
raw: "1.0.0-alpha.1",
|
|
361
|
+
})
|
|
362
|
+
).toBe("1.0.0-alpha.1");
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
test("formats version with build", () => {
|
|
366
|
+
expect(
|
|
367
|
+
formatVersion({
|
|
368
|
+
major: 1,
|
|
369
|
+
minor: 0,
|
|
370
|
+
patch: 0,
|
|
371
|
+
build: "build.123",
|
|
372
|
+
raw: "1.0.0+build.123",
|
|
373
|
+
})
|
|
374
|
+
).toBe("1.0.0+build.123");
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
test("formats version with prerelease and build", () => {
|
|
378
|
+
expect(
|
|
379
|
+
formatVersion({
|
|
380
|
+
major: 1,
|
|
381
|
+
minor: 0,
|
|
382
|
+
patch: 0,
|
|
383
|
+
prerelease: "beta.2",
|
|
384
|
+
build: "build.456",
|
|
385
|
+
raw: "1.0.0-beta.2+build.456",
|
|
386
|
+
})
|
|
387
|
+
).toBe("1.0.0-beta.2+build.456");
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "./dist",
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"composite": true,
|
|
7
|
+
"noEmit": false
|
|
8
|
+
},
|
|
9
|
+
"include": ["src/**/*"],
|
|
10
|
+
"exclude": ["node_modules", "dist", "tests"],
|
|
11
|
+
"references": [{ "path": "../trust" }]
|
|
12
|
+
}
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { EnactCore } from "./core/EnactCore";
|
|
2
|
-
export interface LocalTool {
|
|
3
|
-
name: string;
|
|
4
|
-
path: string;
|
|
5
|
-
definition: any;
|
|
6
|
-
lastModified: Date;
|
|
7
|
-
cached: boolean;
|
|
8
|
-
}
|
|
9
|
-
export interface ToolResolutionResult {
|
|
10
|
-
tool: LocalTool | any;
|
|
11
|
-
source: "local" | "registry" | "cache";
|
|
12
|
-
metadata?: any;
|
|
13
|
-
}
|
|
14
|
-
export declare class LocalToolResolver {
|
|
15
|
-
private enactCore;
|
|
16
|
-
private localToolsDir;
|
|
17
|
-
private cacheDir;
|
|
18
|
-
private toolCache;
|
|
19
|
-
private aliases;
|
|
20
|
-
private favorites;
|
|
21
|
-
constructor(enactCore: EnactCore, localToolsDir?: string, cacheDir?: string);
|
|
22
|
-
/**
|
|
23
|
-
* Main resolution method - checks local first, then registry
|
|
24
|
-
*/
|
|
25
|
-
resolveTool(toolName: string): Promise<ToolResolutionResult | null>;
|
|
26
|
-
/**
|
|
27
|
-
* Get tool from local directory
|
|
28
|
-
*/
|
|
29
|
-
private getLocalTool;
|
|
30
|
-
/**
|
|
31
|
-
* Cache a registry tool locally for faster access
|
|
32
|
-
*/
|
|
33
|
-
private cacheRegistryTool;
|
|
34
|
-
/**
|
|
35
|
-
* Check if cached tool is expired (24 hours by default)
|
|
36
|
-
*/
|
|
37
|
-
private isCacheExpired;
|
|
38
|
-
/**
|
|
39
|
-
* List all available tools from all sources
|
|
40
|
-
*/
|
|
41
|
-
listAllTools(): Promise<{
|
|
42
|
-
local: LocalTool[];
|
|
43
|
-
cached: LocalTool[];
|
|
44
|
-
favorites: string[];
|
|
45
|
-
aliases: Record<string, string>;
|
|
46
|
-
}>;
|
|
47
|
-
/**
|
|
48
|
-
* Scan local tools directory
|
|
49
|
-
*/
|
|
50
|
-
private scanLocalTools;
|
|
51
|
-
/**
|
|
52
|
-
* Recursively scan directory for tool files
|
|
53
|
-
*/
|
|
54
|
-
private scanDirectory;
|
|
55
|
-
/**
|
|
56
|
-
* Add a tool to favorites for priority resolution
|
|
57
|
-
*/
|
|
58
|
-
addToFavorites(toolName: string): void;
|
|
59
|
-
/**
|
|
60
|
-
* Add an alias for a tool
|
|
61
|
-
*/
|
|
62
|
-
addAlias(alias: string, toolName: string): void;
|
|
63
|
-
/**
|
|
64
|
-
* Get suggestions based on partial tool name
|
|
65
|
-
*/
|
|
66
|
-
getSuggestions(partial: string): Promise<string[]>;
|
|
67
|
-
/**
|
|
68
|
-
* Clear expired cache entries
|
|
69
|
-
*/
|
|
70
|
-
cleanupCache(): Promise<number>;
|
|
71
|
-
/**
|
|
72
|
-
* Load configuration from file
|
|
73
|
-
*/
|
|
74
|
-
private loadConfiguration;
|
|
75
|
-
/**
|
|
76
|
-
* Save configuration to file
|
|
77
|
-
*/
|
|
78
|
-
private saveConfiguration;
|
|
79
|
-
/**
|
|
80
|
-
* Initialize local tools directory with examples
|
|
81
|
-
*/
|
|
82
|
-
initialize(): Promise<void>;
|
|
83
|
-
}
|
|
84
|
-
export default LocalToolResolver;
|