@cldmv/slothlet 3.2.3 → 3.3.2
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 +22 -9
- package/REFERENCE.md +23 -0
- package/dist/lib/builders/api-assignment.mjs +1 -589
- package/dist/lib/builders/api_builder.mjs +1 -1155
- package/dist/lib/builders/builder.mjs +1 -78
- package/dist/lib/builders/modes-processor.mjs +1 -1800
- package/dist/lib/errors.mjs +9 -211
- package/dist/lib/factories/component-base.mjs +1 -80
- package/dist/lib/factories/context.mjs +1 -22
- package/dist/lib/handlers/api-cache-manager.mjs +1 -200
- package/dist/lib/handlers/api-manager.mjs +1 -2513
- package/dist/lib/handlers/context-async.mjs +1 -168
- package/dist/lib/handlers/context-live.mjs +1 -168
- package/dist/lib/handlers/hook-manager.mjs +1 -773
- package/dist/lib/handlers/lifecycle-token.mjs +1 -28
- package/dist/lib/handlers/lifecycle.mjs +1 -115
- package/dist/lib/handlers/materialize-manager.mjs +1 -48
- package/dist/lib/handlers/metadata.mjs +1 -501
- package/dist/lib/handlers/ownership.mjs +1 -322
- package/dist/lib/handlers/permission-manager.mjs +17 -0
- package/dist/lib/handlers/unified-wrapper.mjs +1 -3042
- package/dist/lib/handlers/version-manager.mjs +1 -885
- package/dist/lib/helpers/class-instance-wrapper.mjs +1 -109
- package/dist/lib/helpers/config.mjs +1 -355
- package/dist/lib/helpers/eventemitter-context.mjs +1 -349
- package/dist/lib/helpers/hint-detector.mjs +1 -47
- package/dist/lib/helpers/modes-utils.mjs +1 -37
- package/dist/lib/helpers/pattern-matcher.mjs +17 -0
- package/dist/lib/helpers/resolve-from-caller.mjs +1 -169
- package/dist/lib/helpers/sanitize.mjs +1 -340
- package/dist/lib/helpers/utilities.mjs +1 -70
- package/dist/lib/i18n/languages/de-de.json +21 -1
- package/dist/lib/i18n/languages/en-gb.json +21 -1
- package/dist/lib/i18n/languages/en-us.json +21 -1
- package/dist/lib/i18n/languages/es-mx.json +21 -1
- package/dist/lib/i18n/languages/fr-fr.json +21 -1
- package/dist/lib/i18n/languages/hi-in.json +21 -1
- package/dist/lib/i18n/languages/ja-jp.json +21 -1
- package/dist/lib/i18n/languages/ko-kr.json +21 -1
- package/dist/lib/i18n/languages/pt-br.json +21 -1
- package/dist/lib/i18n/languages/ru-ru.json +21 -1
- package/dist/lib/i18n/languages/zh-cn.json +21 -1
- package/dist/lib/i18n/translations.mjs +1 -126
- package/dist/lib/modes/eager.mjs +1 -59
- package/dist/lib/modes/lazy.mjs +1 -81
- package/dist/lib/processors/flatten.mjs +1 -437
- package/dist/lib/processors/loader.mjs +1 -339
- package/dist/lib/processors/type-generator.mjs +1 -275
- package/dist/lib/processors/typescript.mjs +1 -172
- package/dist/lib/runtime/runtime-asynclocalstorage.mjs +1 -113
- package/dist/lib/runtime/runtime-livebindings.mjs +1 -78
- package/dist/lib/runtime/runtime.mjs +1 -102
- package/dist/slothlet.mjs +1 -808
- package/package.json +37 -31
- package/types/dist/lib/builders/api-assignment.d.mts +3 -92
- package/types/dist/lib/builders/api-assignment.d.mts.map +1 -1
- package/types/dist/lib/builders/api_builder.d.mts +102 -91
- package/types/dist/lib/builders/api_builder.d.mts.map +1 -1
- package/types/dist/lib/builders/builder.d.mts +1 -55
- package/types/dist/lib/builders/builder.d.mts.map +1 -1
- package/types/dist/lib/builders/modes-processor.d.mts +3 -27
- package/types/dist/lib/builders/modes-processor.d.mts.map +1 -1
- package/types/dist/lib/errors.d.mts +19 -109
- package/types/dist/lib/errors.d.mts.map +1 -1
- package/types/dist/lib/factories/component-base.d.mts +7 -177
- package/types/dist/lib/factories/component-base.d.mts.map +1 -1
- package/types/dist/lib/factories/context.d.mts +4 -22
- package/types/dist/lib/factories/context.d.mts.map +1 -1
- package/types/dist/lib/handlers/api-cache-manager.d.mts +20 -203
- package/types/dist/lib/handlers/api-cache-manager.d.mts.map +1 -1
- package/types/dist/lib/handlers/api-manager.d.mts +33 -408
- package/types/dist/lib/handlers/api-manager.d.mts.map +1 -1
- package/types/dist/lib/handlers/context-async.d.mts +23 -61
- package/types/dist/lib/handlers/context-async.d.mts.map +1 -1
- package/types/dist/lib/handlers/context-live.d.mts +22 -59
- package/types/dist/lib/handlers/context-live.d.mts.map +1 -1
- package/types/dist/lib/handlers/hook-manager.d.mts +46 -185
- package/types/dist/lib/handlers/hook-manager.d.mts.map +1 -1
- package/types/dist/lib/handlers/lifecycle-token.d.mts +3 -48
- package/types/dist/lib/handlers/lifecycle-token.d.mts.map +1 -1
- package/types/dist/lib/handlers/lifecycle.d.mts +5 -82
- package/types/dist/lib/handlers/lifecycle.d.mts.map +1 -1
- package/types/dist/lib/handlers/materialize-manager.d.mts +8 -70
- package/types/dist/lib/handlers/materialize-manager.d.mts.map +1 -1
- package/types/dist/lib/handlers/metadata.d.mts +17 -221
- package/types/dist/lib/handlers/metadata.d.mts.map +1 -1
- package/types/dist/lib/handlers/ownership.d.mts +44 -160
- package/types/dist/lib/handlers/ownership.d.mts.map +1 -1
- package/types/dist/lib/handlers/permission-manager.d.mts +47 -0
- package/types/dist/lib/handlers/permission-manager.d.mts.map +1 -0
- package/types/dist/lib/handlers/unified-wrapper.d.mts +26 -239
- package/types/dist/lib/handlers/unified-wrapper.d.mts.map +1 -1
- package/types/dist/lib/handlers/version-manager.d.mts +28 -225
- package/types/dist/lib/handlers/version-manager.d.mts.map +1 -1
- package/types/dist/lib/helpers/class-instance-wrapper.d.mts +2 -52
- package/types/dist/lib/helpers/class-instance-wrapper.d.mts.map +1 -1
- package/types/dist/lib/helpers/config.d.mts +125 -123
- package/types/dist/lib/helpers/config.d.mts.map +1 -1
- package/types/dist/lib/helpers/eventemitter-context.d.mts +3 -29
- package/types/dist/lib/helpers/eventemitter-context.d.mts.map +1 -1
- package/types/dist/lib/helpers/hint-detector.d.mts +2 -15
- package/types/dist/lib/helpers/hint-detector.d.mts.map +1 -1
- package/types/dist/lib/helpers/modes-utils.d.mts +3 -30
- package/types/dist/lib/helpers/modes-utils.d.mts.map +1 -1
- package/types/dist/lib/helpers/pattern-matcher.d.mts +4 -0
- package/types/dist/lib/helpers/pattern-matcher.d.mts.map +1 -0
- package/types/dist/lib/helpers/resolve-from-caller.d.mts +3 -27
- package/types/dist/lib/helpers/resolve-from-caller.d.mts.map +1 -1
- package/types/dist/lib/helpers/sanitize.d.mts +4 -92
- package/types/dist/lib/helpers/sanitize.d.mts.map +1 -1
- package/types/dist/lib/helpers/utilities.d.mts +4 -52
- package/types/dist/lib/helpers/utilities.d.mts.map +1 -1
- package/types/dist/lib/i18n/translations.d.mts +4 -37
- package/types/dist/lib/i18n/translations.d.mts.map +1 -1
- package/types/dist/lib/modes/eager.d.mts +8 -30
- package/types/dist/lib/modes/eager.d.mts.map +1 -1
- package/types/dist/lib/modes/lazy.d.mts +10 -43
- package/types/dist/lib/modes/lazy.d.mts.map +1 -1
- package/types/dist/lib/processors/flatten.d.mts +56 -107
- package/types/dist/lib/processors/flatten.d.mts.map +1 -1
- package/types/dist/lib/processors/loader.d.mts +6 -41
- package/types/dist/lib/processors/loader.d.mts.map +1 -1
- package/types/dist/lib/processors/type-generator.d.mts +2 -16
- package/types/dist/lib/processors/type-generator.d.mts.map +1 -1
- package/types/dist/lib/processors/typescript.d.mts +6 -53
- package/types/dist/lib/processors/typescript.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts +3 -71
- package/types/dist/lib/runtime/runtime-asynclocalstorage.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime-livebindings.d.mts +2 -37
- package/types/dist/lib/runtime/runtime-livebindings.d.mts.map +1 -1
- package/types/dist/lib/runtime/runtime.d.mts +3 -39
- package/types/dist/lib/runtime/runtime.d.mts.map +1 -1
- package/types/dist/slothlet.d.mts +3 -249
- package/types/dist/slothlet.d.mts.map +1 -1
- package/types/index.d.mts +36 -16
- package/types/index.d.mts.map +1 -0
- package/AGENT-USAGE.md +0 -736
- package/docs/API-RULES.md +0 -712
|
@@ -14,352 +14,4 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
import { EventEmitter } from "node:events";
|
|
21
|
-
import { AsyncResource } from "node:async_hooks";
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
let isInApiContext = null;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
export function setApiContextChecker(checker) {
|
|
28
|
-
isInApiContext = checker;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const originalMethods = new Map();
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const wrappedListeners = new Map();
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const trackedEmitters = new Set();
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
let isPatchingEnabled = false;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
function runtime_wrapEventListener(listener) {
|
|
45
|
-
|
|
46
|
-
const resource = new AsyncResource("slothlet-event-listener");
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const runtime_wrappedListener = function (...args) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return resource.runInAsyncScope(() => {
|
|
53
|
-
return listener.apply(this, args);
|
|
54
|
-
}, this);
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
runtime_wrappedListener._slothletOriginal = listener;
|
|
59
|
-
runtime_wrappedListener._slothletResource = resource;
|
|
60
|
-
|
|
61
|
-
return runtime_wrappedListener;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
function runtime_getListenerTracking(emitter) {
|
|
66
|
-
let emitterTracking = wrappedListeners.get(emitter);
|
|
67
|
-
if (!emitterTracking) {
|
|
68
|
-
emitterTracking = new Map();
|
|
69
|
-
wrappedListeners.set(emitter, emitterTracking);
|
|
70
|
-
}
|
|
71
|
-
return emitterTracking;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
function runtime_trackListener(emitter, event, originalListener, wrappedListener) {
|
|
76
|
-
const emitterTracking = runtime_getListenerTracking(emitter);
|
|
77
|
-
|
|
78
|
-
let eventTracking = emitterTracking.get(event);
|
|
79
|
-
if (!eventTracking) {
|
|
80
|
-
eventTracking = new Map();
|
|
81
|
-
emitterTracking.set(event, eventTracking);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
eventTracking.set(originalListener, wrappedListener);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
function runtime_getWrappedListener(emitter, event, originalListener) {
|
|
89
|
-
const emitterTracking = wrappedListeners.get(emitter);
|
|
90
|
-
if (!emitterTracking) return undefined;
|
|
91
|
-
|
|
92
|
-
const eventTracking = emitterTracking.get(event);
|
|
93
|
-
if (!eventTracking) return undefined;
|
|
94
|
-
|
|
95
|
-
return eventTracking.get(originalListener);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
function runtime_untrackListener(emitter, event, originalListener) {
|
|
100
|
-
const emitterTracking = wrappedListeners.get(emitter);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (!emitterTracking) return;
|
|
105
|
-
|
|
106
|
-
const eventTracking = emitterTracking.get(event);
|
|
107
|
-
if (!eventTracking) return;
|
|
108
|
-
|
|
109
|
-
const wrappedListener = eventTracking.get(originalListener);
|
|
110
|
-
if (wrappedListener) {
|
|
111
|
-
|
|
112
|
-
wrappedListener._slothletResource = null;
|
|
113
|
-
eventTracking.delete(originalListener);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (eventTracking.size === 0) {
|
|
118
|
-
emitterTracking.delete(event);
|
|
119
|
-
}
|
|
120
|
-
if (emitterTracking.size === 0) {
|
|
121
|
-
wrappedListeners.delete(emitter);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
function runtime_shouldWrapListener(listener) {
|
|
127
|
-
|
|
128
|
-
if (typeof listener !== "function") return false;
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (listener._slothletOriginal) return false;
|
|
132
|
-
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
function runtime_maybeTrackEmitter(emitter) {
|
|
138
|
-
|
|
139
|
-
if (isInApiContext && isInApiContext()) {
|
|
140
|
-
trackedEmitters.add(emitter);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
function runtime_patchOn() {
|
|
146
|
-
const original = EventEmitter.prototype.on;
|
|
147
|
-
originalMethods.set("on", original);
|
|
148
|
-
|
|
149
|
-
EventEmitter.prototype.on = function (event, listener) {
|
|
150
|
-
|
|
151
|
-
runtime_maybeTrackEmitter(this);
|
|
152
|
-
|
|
153
|
-
if (!runtime_shouldWrapListener(listener)) {
|
|
154
|
-
return original.call(this, event, listener);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const wrapped = runtime_wrapEventListener(listener);
|
|
158
|
-
runtime_trackListener(this, event, listener, wrapped);
|
|
159
|
-
return original.call(this, event, wrapped);
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
function runtime_patchOnce() {
|
|
168
|
-
const original = EventEmitter.prototype.once;
|
|
169
|
-
originalMethods.set("once", original);
|
|
170
|
-
|
|
171
|
-
EventEmitter.prototype.once = function (event, listener) {
|
|
172
|
-
|
|
173
|
-
runtime_maybeTrackEmitter(this);
|
|
174
|
-
|
|
175
|
-
if (!runtime_shouldWrapListener(listener)) {
|
|
176
|
-
return original.call(this, event, listener);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
const wrapped = runtime_wrapEventListener(listener);
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const runtime_onceWrapper = function (...args) {
|
|
183
|
-
const result = wrapped.apply(this, args);
|
|
184
|
-
|
|
185
|
-
runtime_untrackListener(this, event, listener);
|
|
186
|
-
return result;
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
runtime_onceWrapper._slothletOriginal = listener;
|
|
191
|
-
runtime_onceWrapper._slothletResource = wrapped._slothletResource;
|
|
192
|
-
|
|
193
|
-
runtime_trackListener(this, event, listener, runtime_onceWrapper);
|
|
194
|
-
return original.call(this, event, runtime_onceWrapper);
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
function runtime_patchPrependListener() {
|
|
200
|
-
const original = EventEmitter.prototype.prependListener;
|
|
201
|
-
originalMethods.set("prependListener", original);
|
|
202
|
-
|
|
203
|
-
EventEmitter.prototype.prependListener = function (event, listener) {
|
|
204
|
-
|
|
205
|
-
runtime_maybeTrackEmitter(this);
|
|
206
|
-
|
|
207
|
-
if (!runtime_shouldWrapListener(listener)) {
|
|
208
|
-
return original.call(this, event, listener);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
const wrapped = runtime_wrapEventListener(listener);
|
|
212
|
-
runtime_trackListener(this, event, listener, wrapped);
|
|
213
|
-
return original.call(this, event, wrapped);
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
function runtime_patchPrependOnceListener() {
|
|
219
|
-
const original = EventEmitter.prototype.prependOnceListener;
|
|
220
|
-
originalMethods.set("prependOnceListener", original);
|
|
221
|
-
|
|
222
|
-
EventEmitter.prototype.prependOnceListener = function (event, listener) {
|
|
223
|
-
|
|
224
|
-
runtime_maybeTrackEmitter(this);
|
|
225
|
-
|
|
226
|
-
if (!runtime_shouldWrapListener(listener)) {
|
|
227
|
-
return original.call(this, event, listener);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
const wrapped = runtime_wrapEventListener(listener);
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const runtime_onceWrapper = function (...args) {
|
|
234
|
-
const result = wrapped.apply(this, args);
|
|
235
|
-
|
|
236
|
-
runtime_untrackListener(this, event, listener);
|
|
237
|
-
return result;
|
|
238
|
-
};
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
runtime_onceWrapper._slothletOriginal = listener;
|
|
242
|
-
runtime_onceWrapper._slothletResource = wrapped._slothletResource;
|
|
243
|
-
|
|
244
|
-
runtime_trackListener(this, event, listener, runtime_onceWrapper);
|
|
245
|
-
return original.call(this, event, runtime_onceWrapper);
|
|
246
|
-
};
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
function runtime_patchRemoveListener() {
|
|
251
|
-
const original = EventEmitter.prototype.removeListener;
|
|
252
|
-
originalMethods.set("removeListener", original);
|
|
253
|
-
|
|
254
|
-
EventEmitter.prototype.removeListener = function (event, listener) {
|
|
255
|
-
|
|
256
|
-
const wrapped = runtime_getWrappedListener(this, event, listener);
|
|
257
|
-
if (wrapped) {
|
|
258
|
-
|
|
259
|
-
const result = original.call(this, event, wrapped);
|
|
260
|
-
|
|
261
|
-
runtime_untrackListener(this, event, listener);
|
|
262
|
-
return result;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
return original.call(this, event, listener);
|
|
266
|
-
};
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
function runtime_patchRemoveAllListeners() {
|
|
274
|
-
const original = EventEmitter.prototype.removeAllListeners;
|
|
275
|
-
originalMethods.set("removeAllListeners", original);
|
|
276
|
-
|
|
277
|
-
EventEmitter.prototype.removeAllListeners = function (event) {
|
|
278
|
-
|
|
279
|
-
const emitterTracking = wrappedListeners.get(this);
|
|
280
|
-
if (emitterTracking) {
|
|
281
|
-
if (event === undefined) {
|
|
282
|
-
|
|
283
|
-
for (const [____evt, eventTracking] of emitterTracking.entries()) {
|
|
284
|
-
for (const wrappedListener of eventTracking.values()) {
|
|
285
|
-
|
|
286
|
-
wrappedListener._slothletResource = null;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
wrappedListeners.delete(this);
|
|
290
|
-
} else {
|
|
291
|
-
|
|
292
|
-
const eventTracking = emitterTracking.get(event);
|
|
293
|
-
if (eventTracking) {
|
|
294
|
-
for (const wrappedListener of eventTracking.values()) {
|
|
295
|
-
|
|
296
|
-
wrappedListener._slothletResource = null;
|
|
297
|
-
}
|
|
298
|
-
emitterTracking.delete(event);
|
|
299
|
-
if (emitterTracking.size === 0) {
|
|
300
|
-
wrappedListeners.delete(this);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
return original.call(this, event);
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
export function enableEventEmitterPatching() {
|
|
312
|
-
if (isPatchingEnabled) {
|
|
313
|
-
|
|
314
|
-
return;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
runtime_patchOn();
|
|
319
|
-
runtime_patchOnce();
|
|
320
|
-
runtime_patchPrependListener();
|
|
321
|
-
runtime_patchPrependOnceListener();
|
|
322
|
-
runtime_patchRemoveListener();
|
|
323
|
-
runtime_patchRemoveAllListeners();
|
|
324
|
-
|
|
325
|
-
isPatchingEnabled = true;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
export function disableEventEmitterPatching() {
|
|
330
|
-
if (!isPatchingEnabled) {
|
|
331
|
-
return;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
for (const [methodName, originalMethod] of originalMethods.entries()) {
|
|
336
|
-
EventEmitter.prototype[methodName] = originalMethod;
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
if (methodName === "on") {
|
|
340
|
-
EventEmitter.prototype.addListener = originalMethod;
|
|
341
|
-
} else if (methodName === "removeListener") {
|
|
342
|
-
EventEmitter.prototype.off = originalMethod;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
originalMethods.clear();
|
|
347
|
-
isPatchingEnabled = false;
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
export function cleanupEventEmitterResources() {
|
|
352
|
-
|
|
353
|
-
for (const emitter of trackedEmitters) {
|
|
354
|
-
try {
|
|
355
|
-
|
|
356
|
-
emitter.removeAllListeners();
|
|
357
|
-
} catch (____error) {
|
|
358
|
-
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
trackedEmitters.clear();
|
|
364
|
-
wrappedListeners.clear();
|
|
365
|
-
}
|
|
17
|
+
import{EventEmitter}from"node:events";import{AsyncResource}from"node:async_hooks";let isInApiContext=null;function setApiContextChecker(checker){isInApiContext=checker}const originalMethods=new Map;const wrappedListeners=new Map;const trackedEmitters=new Set;let isPatchingEnabled=false;function runtime_wrapEventListener(listener){const resource=new AsyncResource("slothlet-event-listener");const runtime_wrappedListener=function(...args){return resource.runInAsyncScope(()=>{return listener.apply(this,args)},this)};runtime_wrappedListener._slothletOriginal=listener;runtime_wrappedListener._slothletResource=resource;return runtime_wrappedListener}function runtime_getListenerTracking(emitter){let emitterTracking=wrappedListeners.get(emitter);if(!emitterTracking){emitterTracking=new Map;wrappedListeners.set(emitter,emitterTracking)}return emitterTracking}function runtime_trackListener(emitter,event,originalListener,wrappedListener){const emitterTracking=runtime_getListenerTracking(emitter);let eventTracking=emitterTracking.get(event);if(!eventTracking){eventTracking=new Map;emitterTracking.set(event,eventTracking)}eventTracking.set(originalListener,wrappedListener)}function runtime_getWrappedListener(emitter,event,originalListener){const emitterTracking=wrappedListeners.get(emitter);if(!emitterTracking)return void 0;const eventTracking=emitterTracking.get(event);if(!eventTracking)return void 0;return eventTracking.get(originalListener)}function runtime_untrackListener(emitter,event,originalListener){const emitterTracking=wrappedListeners.get(emitter);if(!emitterTracking)return;const eventTracking=emitterTracking.get(event);if(!eventTracking)return;const wrappedListener=eventTracking.get(originalListener);if(wrappedListener){wrappedListener._slothletResource=null;eventTracking.delete(originalListener)}if(eventTracking.size===0){emitterTracking.delete(event)}if(emitterTracking.size===0){wrappedListeners.delete(emitter)}}function runtime_shouldWrapListener(listener){if(typeof listener!=="function")return false;if(listener._slothletOriginal)return false;return true}function runtime_maybeTrackEmitter(emitter){if(isInApiContext&&isInApiContext()){trackedEmitters.add(emitter)}}function runtime_patchOn(){const original=EventEmitter.prototype.on;originalMethods.set("on",original);EventEmitter.prototype.on=function(event,listener){runtime_maybeTrackEmitter(this);if(!runtime_shouldWrapListener(listener)){return original.call(this,event,listener)}const wrapped=runtime_wrapEventListener(listener);runtime_trackListener(this,event,listener,wrapped);return original.call(this,event,wrapped)};EventEmitter.prototype.addListener=EventEmitter.prototype.on}function runtime_patchOnce(){const original=EventEmitter.prototype.once;originalMethods.set("once",original);EventEmitter.prototype.once=function(event,listener){runtime_maybeTrackEmitter(this);if(!runtime_shouldWrapListener(listener)){return original.call(this,event,listener)}const wrapped=runtime_wrapEventListener(listener);const runtime_onceWrapper=function(...args){const result=wrapped.apply(this,args);runtime_untrackListener(this,event,listener);return result};runtime_onceWrapper._slothletOriginal=listener;runtime_onceWrapper._slothletResource=wrapped._slothletResource;runtime_trackListener(this,event,listener,runtime_onceWrapper);return original.call(this,event,runtime_onceWrapper)}}function runtime_patchPrependListener(){const original=EventEmitter.prototype.prependListener;originalMethods.set("prependListener",original);EventEmitter.prototype.prependListener=function(event,listener){runtime_maybeTrackEmitter(this);if(!runtime_shouldWrapListener(listener)){return original.call(this,event,listener)}const wrapped=runtime_wrapEventListener(listener);runtime_trackListener(this,event,listener,wrapped);return original.call(this,event,wrapped)}}function runtime_patchPrependOnceListener(){const original=EventEmitter.prototype.prependOnceListener;originalMethods.set("prependOnceListener",original);EventEmitter.prototype.prependOnceListener=function(event,listener){runtime_maybeTrackEmitter(this);if(!runtime_shouldWrapListener(listener)){return original.call(this,event,listener)}const wrapped=runtime_wrapEventListener(listener);const runtime_onceWrapper=function(...args){const result=wrapped.apply(this,args);runtime_untrackListener(this,event,listener);return result};runtime_onceWrapper._slothletOriginal=listener;runtime_onceWrapper._slothletResource=wrapped._slothletResource;runtime_trackListener(this,event,listener,runtime_onceWrapper);return original.call(this,event,runtime_onceWrapper)}}function runtime_patchRemoveListener(){const original=EventEmitter.prototype.removeListener;originalMethods.set("removeListener",original);EventEmitter.prototype.removeListener=function(event,listener){const wrapped=runtime_getWrappedListener(this,event,listener);if(wrapped){const result=original.call(this,event,wrapped);runtime_untrackListener(this,event,listener);return result}return original.call(this,event,listener)};EventEmitter.prototype.off=EventEmitter.prototype.removeListener}function runtime_patchRemoveAllListeners(){const original=EventEmitter.prototype.removeAllListeners;originalMethods.set("removeAllListeners",original);EventEmitter.prototype.removeAllListeners=function(event){const emitterTracking=wrappedListeners.get(this);if(emitterTracking){if(event===void 0){for(const[____evt,eventTracking]of emitterTracking.entries()){for(const wrappedListener of eventTracking.values()){wrappedListener._slothletResource=null}}wrappedListeners.delete(this)}else{const eventTracking=emitterTracking.get(event);if(eventTracking){for(const wrappedListener of eventTracking.values()){wrappedListener._slothletResource=null}emitterTracking.delete(event);if(emitterTracking.size===0){wrappedListeners.delete(this)}}}}return original.call(this,event)}}function enableEventEmitterPatching(){if(isPatchingEnabled){return}runtime_patchOn();runtime_patchOnce();runtime_patchPrependListener();runtime_patchPrependOnceListener();runtime_patchRemoveListener();runtime_patchRemoveAllListeners();isPatchingEnabled=true}function disableEventEmitterPatching(){if(!isPatchingEnabled){return}for(const[methodName,originalMethod]of originalMethods.entries()){EventEmitter.prototype[methodName]=originalMethod;if(methodName==="on"){EventEmitter.prototype.addListener=originalMethod}else if(methodName==="removeListener"){EventEmitter.prototype.off=originalMethod}}originalMethods.clear();isPatchingEnabled=false}function cleanupEventEmitterResources(){for(const emitter of trackedEmitters){try{emitter.removeAllListeners()}catch(____error){}}trackedEmitters.clear();wrappedListeners.clear()}export{cleanupEventEmitterResources,disableEventEmitterPatching,enableEventEmitterPatching,setApiContextChecker};
|
|
@@ -14,50 +14,4 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const HINT_RULES = [
|
|
25
|
-
{
|
|
26
|
-
pattern: /does not provide an export named 'reference'/i,
|
|
27
|
-
hintKey: "HINT_REFERENCE_REMOVED"
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
pattern: /Cannot find module/i,
|
|
31
|
-
hintKey: "HINT_MODULE_NOT_FOUND"
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
pattern: /Unexpected token/i,
|
|
35
|
-
hintKey: "HINT_SYNTAX_ERROR"
|
|
36
|
-
}
|
|
37
|
-
];
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
export class HintDetector extends ComponentBase {
|
|
41
|
-
static slothletProperty = "hintDetector";
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
detectHint(error, errorCode) {
|
|
45
|
-
|
|
46
|
-
if (error) {
|
|
47
|
-
const errorMessage = error.message || error.toString();
|
|
48
|
-
for (const rule of HINT_RULES) {
|
|
49
|
-
if (rule.pattern.test(errorMessage)) {
|
|
50
|
-
return rule.hintKey;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return `HINT_${errorCode}`;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const hintDetectorInstance_standalone = new HintDetector();
|
|
63
|
-
export const detectHint = hintDetectorInstance_standalone.detectHint.bind(hintDetectorInstance_standalone);
|
|
17
|
+
import{ComponentBase}from"@cldmv/slothlet/factories/component-base";const HINT_RULES=[{pattern:/does not provide an export named 'reference'/i,hintKey:"HINT_REFERENCE_REMOVED"},{pattern:/Cannot find module/i,hintKey:"HINT_MODULE_NOT_FOUND"},{pattern:/Unexpected token/i,hintKey:"HINT_SYNTAX_ERROR"}];class HintDetector extends ComponentBase{static slothletProperty="hintDetector";detectHint(error,errorCode){if(error){const errorMessage=error.message||error.toString();for(const rule of HINT_RULES){if(rule.pattern.test(errorMessage)){return rule.hintKey}}}return`HINT_${errorCode}`}}const hintDetectorInstance_standalone=new HintDetector;const detectHint=hintDetectorInstance_standalone.detectHint.bind(hintDetectorInstance_standalone);export{HintDetector,detectHint};
|
|
@@ -14,40 +14,4 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
export class ModesUtils extends ComponentBase {
|
|
25
|
-
static slothletProperty = "modesUtils";
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
ensureNamedExportFunction(fn, ____nameHint) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return fn;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
cloneWrapperImpl(value, mode) {
|
|
36
|
-
if (mode !== "eager") {
|
|
37
|
-
return value;
|
|
38
|
-
}
|
|
39
|
-
if (!value || typeof value !== "object") {
|
|
40
|
-
return value;
|
|
41
|
-
}
|
|
42
|
-
if (Array.isArray(value)) {
|
|
43
|
-
return value.slice();
|
|
44
|
-
}
|
|
45
|
-
const descriptors = Object.getOwnPropertyDescriptors(value);
|
|
46
|
-
return Object.create(Object.getPrototypeOf(value), descriptors);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
getOwnershipCollisionMode(config, collisionContext = "initial") {
|
|
51
|
-
return config.collision?.[collisionContext] || "merge";
|
|
52
|
-
}
|
|
53
|
-
}
|
|
17
|
+
import{ComponentBase}from"@cldmv/slothlet/factories/component-base";class ModesUtils extends ComponentBase{static slothletProperty="modesUtils";ensureNamedExportFunction(fn,____nameHint){return fn}cloneWrapperImpl(value,mode){if(mode!=="eager"){return value}if(!value||typeof value!=="object"){return value}if(Array.isArray(value)){return value.slice()}const descriptors=Object.getOwnPropertyDescriptors(value);return Object.create(Object.getPrototypeOf(value),descriptors)}getOwnershipCollisionMode(config,collisionContext="initial"){return config.collision?.[collisionContext]||"merge"}}export{ModesUtils};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2026 CLDMV/Shinrai
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import{SlothletError}from"@cldmv/slothlet/errors";function compilePattern(pattern,options={}){const isNegation=pattern.startsWith("!");if(isNegation){pattern=pattern.slice(1);const matcher=compilePattern(pattern,options);return path=>!matcher(path)}const expanded=expandBraces(pattern,0,10,options);if(expanded.length>1){const matchers=expanded.map(p=>compilePattern(p,options));return path=>matchers.some(m=>m(path))}pattern=expanded[0];let regexPattern=pattern.replace(/[.+^$()|[\]\\]/g,"\\$&").replace(/\*\*/g,"__DOUBLESTAR__").replace(/\*/g,"[^.]*").replace(/__DOUBLESTAR__/g,".*").replace(/\?/g,".");regexPattern=`^${regexPattern}$`;const regex=new RegExp(regexPattern);return path=>regex.test(path)}function expandBraces(pattern,depth=0,maxDepth=10,options={}){if(depth>=maxDepth){if(options.onMaxDepth){options.onMaxDepth(maxDepth)}throw new SlothletError("BRACE_EXPANSION_MAX_DEPTH",{maxDepth,validationError:true})}const braceStart=pattern.indexOf("{");if(braceStart===-1){return[pattern]}let braceEnd=-1;let depthCount=1;for(let i=braceStart+1;i<pattern.length;i++){if(pattern[i]==="{")depthCount++;if(pattern[i]==="}"){depthCount--;if(depthCount===0){braceEnd=i;break}}}if(braceEnd===-1){return[pattern]}const prefix=pattern.slice(0,braceStart);const braceContent=pattern.slice(braceStart+1,braceEnd);const suffix=pattern.slice(braceEnd+1);const alternatives=splitBraceAlternatives(braceContent);const expanded=[];for(const alt of alternatives){const combined=prefix+alt+suffix;const recursiveExpanded=expandBraces(combined,depth+1,maxDepth,options);expanded.push(...recursiveExpanded)}return expanded}function splitBraceAlternatives(content){const alternatives=[];let current="";let depth=0;for(let i=0;i<content.length;i++){const char=content[i];if(char==="{"){depth++;current+=char}else if(char==="}"){depth--;current+=char}else if(char===","&&depth===0){alternatives.push(current);current=""}else{current+=char}}if(current){alternatives.push(current)}return alternatives}export{compilePattern,expandBraces,splitBraceAlternatives};
|
|
@@ -14,172 +14,4 @@
|
|
|
14
14
|
limitations under the License.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
import fs from "node:fs";
|
|
22
|
-
import path from "node:path";
|
|
23
|
-
import { fileURLToPath } from "node:url";
|
|
24
|
-
import { ComponentBase } from "@cldmv/slothlet/factories/component-base";
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const __filename = fileURLToPath(import.meta.url);
|
|
28
|
-
const __dirname = path.dirname(__filename);
|
|
29
|
-
const SLOTHLET_LIB_ROOT = path.resolve(__dirname, "../..");
|
|
30
|
-
const SLOTHLET_PKG_ROOT = path.normalize(path.resolve(__dirname, "../../.."));
|
|
31
|
-
|
|
32
|
-
export class Resolver extends ComponentBase {
|
|
33
|
-
static slothletProperty = "resolver";
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
getStack(skipFn) {
|
|
37
|
-
const orig = Error.prepareStackTrace;
|
|
38
|
-
try {
|
|
39
|
-
Error.prepareStackTrace = (_, s) => s;
|
|
40
|
-
const e = new Error("Stack trace");
|
|
41
|
-
if (skipFn) Error.captureStackTrace(e, skipFn);
|
|
42
|
-
return e.stack;
|
|
43
|
-
} finally {
|
|
44
|
-
Error.prepareStackTrace = orig;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
#getStack() {
|
|
50
|
-
const originalPrepare = Error.prepareStackTrace;
|
|
51
|
-
Error.prepareStackTrace = (___, stack) => stack;
|
|
52
|
-
const stack = new Error().stack;
|
|
53
|
-
Error.prepareStackTrace = originalPrepare;
|
|
54
|
-
return stack;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
toFsPath(v) {
|
|
59
|
-
if (!v) return null;
|
|
60
|
-
const str = String(v);
|
|
61
|
-
return str.startsWith("file://") ? fileURLToPath(str) : str;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
#isSlothletInternal(filePath) {
|
|
66
|
-
|
|
67
|
-
const normalized = path.normalize(filePath);
|
|
68
|
-
const normalizedLibRoot = path.normalize(SLOTHLET_LIB_ROOT);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (normalized.startsWith(normalizedLibRoot)) {
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
const basename = path.basename(normalized);
|
|
81
|
-
if (basename === "index.mjs" || basename === "index.cjs") {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (path.dirname(normalized) === SLOTHLET_PKG_ROOT) return true;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return false;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
#findCallerBase() {
|
|
94
|
-
const stack = this.#getStack();
|
|
95
|
-
const files = stack.map((s) => this.toFsPath(s.getFileName())).filter(Boolean);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const slothletIndex = files.findIndex((f) => path.basename(f).toLowerCase() === "slothlet.mjs");
|
|
99
|
-
|
|
100
|
-
if (slothletIndex === -1) {
|
|
101
|
-
|
|
102
|
-
for (const file of files) {
|
|
103
|
-
if (!this.#isSlothletInternal(file)) {
|
|
104
|
-
return file;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
for (let i = slothletIndex + 1; i < files.length; i++) {
|
|
117
|
-
const file = files[i];
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (file.startsWith?.("node:")) continue;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (this.#isSlothletInternal(file)) continue;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
return file;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
for (const file of files) {
|
|
136
|
-
if (!this.#isSlothletInternal(file)) {
|
|
137
|
-
return file;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
return null;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
resolvePathFromCaller(rel) {
|
|
150
|
-
|
|
151
|
-
if (rel.startsWith?.("file://")) return fileURLToPath(rel);
|
|
152
|
-
if (path.isAbsolute(rel)) return rel;
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const callerFile = this.#findCallerBase();
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (!callerFile) {
|
|
162
|
-
|
|
163
|
-
return path.resolve(process.cwd(), rel);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const callerDir = path.dirname(callerFile);
|
|
168
|
-
const resolved = path.resolve(callerDir, rel);
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (fs.existsSync(resolved)) {
|
|
172
|
-
return resolved;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const cwdResolved = path.resolve(process.cwd(), rel);
|
|
177
|
-
if (fs.existsSync(cwdResolved)) {
|
|
178
|
-
return cwdResolved;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return resolved;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
17
|
+
import fs from"node:fs";import path from"node:path";import{fileURLToPath}from"node:url";import{ComponentBase}from"@cldmv/slothlet/factories/component-base";const __filename=fileURLToPath(import.meta.url);const __dirname=path.dirname(__filename);const SLOTHLET_LIB_ROOT=path.resolve(__dirname,"../..");const SLOTHLET_PKG_ROOT=path.normalize(path.resolve(__dirname,"../../.."));class Resolver extends ComponentBase{static slothletProperty="resolver";getStack(skipFn){const orig=Error.prepareStackTrace;try{Error.prepareStackTrace=(_,s)=>s;const e=new Error("Stack trace");if(skipFn)Error.captureStackTrace(e,skipFn);return e.stack}finally{Error.prepareStackTrace=orig}}#getStack(){const originalPrepare=Error.prepareStackTrace;Error.prepareStackTrace=(___,stack2)=>stack2;const stack=new Error().stack;Error.prepareStackTrace=originalPrepare;return stack}toFsPath(v){if(!v)return null;const str=String(v);return str.startsWith("file://")?fileURLToPath(str):str}#isSlothletInternal(filePath){const normalized=path.normalize(filePath);const normalizedLibRoot=path.normalize(SLOTHLET_LIB_ROOT);if(normalized.startsWith(normalizedLibRoot)){return true}const basename=path.basename(normalized);if(basename==="index.mjs"||basename==="index.cjs"){if(path.dirname(normalized)===SLOTHLET_PKG_ROOT)return true}return false}#findCallerBase(){const stack=this.#getStack();const files=stack.map(s=>this.toFsPath(s.getFileName())).filter(Boolean);const slothletIndex=files.findIndex(f=>path.basename(f).toLowerCase()==="slothlet.mjs");if(slothletIndex===-1){for(const file of files){if(!this.#isSlothletInternal(file)){return file}}return null}for(let i=slothletIndex+1;i<files.length;i++){const file=files[i];if(file.startsWith?.("node:"))continue;if(this.#isSlothletInternal(file))continue;return file}for(const file of files){if(!this.#isSlothletInternal(file)){return file}}return null}resolvePathFromCaller(rel){if(rel.startsWith?.("file://"))return fileURLToPath(rel);if(path.isAbsolute(rel))return rel;const callerFile=this.#findCallerBase();if(!callerFile){return path.resolve(process.cwd(),rel)}const callerDir=path.dirname(callerFile);const resolved=path.resolve(callerDir,rel);if(fs.existsSync(resolved)){return resolved}const cwdResolved=path.resolve(process.cwd(),rel);if(fs.existsSync(cwdResolved)){return cwdResolved}return resolved}}export{Resolver};
|