@snailycfx/nexus 1.0.2 → 1.0.3

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.
@@ -1,260 +0,0 @@
1
- local Promise = require(script.Parent.Promise)
2
-
3
- local RunService = game:GetService("RunService")
4
-
5
- local OUTPUT_PREFIX = "roblox-ts: "
6
- local NODE_MODULES = "node_modules"
7
- local DEFAULT_SCOPE = "@rbxts"
8
-
9
- local TS = {}
10
-
11
- TS.Promise = Promise
12
-
13
- local function isPlugin(context)
14
- return RunService:IsStudio() and context:FindFirstAncestorWhichIsA("Plugin") ~= nil
15
- end
16
-
17
- function TS.getModule(context, scope, moduleName)
18
- -- legacy call signature
19
- if moduleName == nil then
20
- moduleName = scope
21
- scope = DEFAULT_SCOPE
22
- end
23
-
24
- -- ensure modules have fully replicated
25
- if RunService:IsRunning() and RunService:IsClient() and not isPlugin(context) and not game:IsLoaded() then
26
- game.Loaded:Wait()
27
- end
28
-
29
- local object = context
30
- repeat
31
- local nodeModulesFolder = object:FindFirstChild(NODE_MODULES)
32
- if nodeModulesFolder then
33
- local scopeFolder = nodeModulesFolder:FindFirstChild(scope)
34
- if scopeFolder then
35
- local module = scopeFolder:FindFirstChild(moduleName)
36
- if module then
37
- return module
38
- end
39
- end
40
- end
41
- object = object.Parent
42
- until object == nil
43
-
44
- error(OUTPUT_PREFIX .. "Could not find module: " .. moduleName, 2)
45
- end
46
-
47
- -- This is a hash which TS.import uses as a kind of linked-list-like history of [Script who Loaded] -> Library
48
- local currentlyLoading = {}
49
- local registeredLibraries = {}
50
-
51
- function TS.import(context, module, ...)
52
- for i = 1, select("#", ...) do
53
- module = module:WaitForChild((select(i, ...)))
54
- end
55
-
56
- if module.ClassName ~= "ModuleScript" then
57
- error(OUTPUT_PREFIX .. "Failed to import! Expected ModuleScript, got " .. module.ClassName, 2)
58
- end
59
-
60
- currentlyLoading[context] = module
61
-
62
- -- Check to see if a case like this occurs:
63
- -- module -> Module1 -> Module2 -> module
64
-
65
- -- WHERE currentlyLoading[module] is Module1
66
- -- and currentlyLoading[Module1] is Module2
67
- -- and currentlyLoading[Module2] is module
68
-
69
- local currentModule = module
70
- local depth = 0
71
-
72
- while currentModule do
73
- depth = depth + 1
74
- currentModule = currentlyLoading[currentModule]
75
-
76
- if currentModule == module then
77
- local str = currentModule.Name -- Get the string traceback
78
-
79
- for _ = 1, depth do
80
- currentModule = currentlyLoading[currentModule]
81
- str = str .. " ⇒ " .. currentModule.Name
82
- end
83
-
84
- error(OUTPUT_PREFIX .. "Failed to import! Detected a circular dependency chain: " .. str, 2)
85
- end
86
- end
87
-
88
- if not registeredLibraries[module] then
89
- if _G[module] then
90
- error(
91
- OUTPUT_PREFIX
92
- .. "Invalid module access! Do you have multiple TS runtimes trying to import this? "
93
- .. module:GetFullName(),
94
- 2
95
- )
96
- end
97
-
98
- _G[module] = TS
99
- registeredLibraries[module] = true -- register as already loaded for subsequent calls
100
- end
101
-
102
- local data = require(module)
103
-
104
- if currentlyLoading[context] == module then -- Thread-safe cleanup!
105
- currentlyLoading[context] = nil
106
- end
107
-
108
- return data
109
- end
110
-
111
- function TS.instanceof(obj, class)
112
- -- custom Class.instanceof() check
113
- if type(class) == "table" and type(class.instanceof) == "function" then
114
- return class.instanceof(obj)
115
- end
116
-
117
- -- metatable check
118
- if type(obj) == "table" then
119
- obj = getmetatable(obj)
120
- while obj ~= nil do
121
- if obj == class then
122
- return true
123
- end
124
- local mt = getmetatable(obj)
125
- if mt then
126
- obj = mt.__index
127
- else
128
- obj = nil
129
- end
130
- end
131
- end
132
-
133
- return false
134
- end
135
-
136
- function TS.async(callback)
137
- return function(...)
138
- local n = select("#", ...)
139
- local args = { ... }
140
- return Promise.new(function(resolve, reject)
141
- coroutine.wrap(function()
142
- local ok, result = pcall(callback, unpack(args, 1, n))
143
- if ok then
144
- resolve(result)
145
- else
146
- reject(result)
147
- end
148
- end)()
149
- end)
150
- end
151
- end
152
-
153
- function TS.await(promise)
154
- if not Promise.is(promise) then
155
- return promise
156
- end
157
-
158
- local status, value = promise:awaitStatus()
159
- if status == Promise.Status.Resolved then
160
- return value
161
- elseif status == Promise.Status.Rejected then
162
- error(value, 2)
163
- else
164
- error("The awaited Promise was cancelled", 2)
165
- end
166
- end
167
-
168
- local SIGN = 2 ^ 31
169
- local COMPLEMENT = 2 ^ 32
170
- local function bit_sign(num)
171
- -- Restores the sign after an unsigned conversion according to 2s complement.
172
- if bit32.btest(num, SIGN) then
173
- return num - COMPLEMENT
174
- else
175
- return num
176
- end
177
- end
178
-
179
- function TS.bit_lrsh(a, b)
180
- return bit_sign(bit32.arshift(a, b))
181
- end
182
-
183
- TS.TRY_RETURN = 1
184
- TS.TRY_BREAK = 2
185
- TS.TRY_CONTINUE = 3
186
-
187
- function TS.try(try, catch, finally)
188
- -- execute try
189
- local trySuccess, exitTypeOrTryError, returns = pcall(try)
190
- local exitType, tryError
191
- if trySuccess then
192
- exitType = exitTypeOrTryError
193
- else
194
- tryError = exitTypeOrTryError
195
- end
196
-
197
- local catchSuccess = true
198
- local catchError
199
-
200
- -- if try block failed, and catch block exists, execute catch
201
- if not trySuccess and catch then
202
- local newExitTypeOrCatchError, newReturns
203
- catchSuccess, newExitTypeOrCatchError, newReturns = pcall(catch, tryError)
204
- local newExitType
205
- if catchSuccess then
206
- newExitType = newExitTypeOrCatchError
207
- else
208
- catchError = newExitTypeOrCatchError
209
- end
210
-
211
- if newExitType then
212
- exitType, returns = newExitType, newReturns
213
- end
214
- end
215
-
216
- -- execute finally
217
- if finally then
218
- local newExitType, newReturns = finally()
219
- if newExitType then
220
- exitType, returns = newExitType, newReturns
221
- end
222
- end
223
-
224
- -- if exit type is a control flow, do not rethrow errors
225
- if exitType ~= TS.TRY_RETURN and exitType ~= TS.TRY_BREAK and exitType ~= TS.TRY_CONTINUE then
226
- -- if catch block threw an error, rethrow it
227
- if not catchSuccess then
228
- error(catchError, 2)
229
- end
230
-
231
- -- if try block threw an error and there was no catch block, rethrow it
232
- if not trySuccess and not catch then
233
- error(tryError, 2)
234
- end
235
- end
236
-
237
- return exitType, returns
238
- end
239
-
240
- function TS.generator(callback)
241
- local co = coroutine.create(callback)
242
- return {
243
- next = function(...)
244
- if coroutine.status(co) == "dead" then
245
- return { done = true }
246
- else
247
- local success, value = coroutine.resume(co, ...)
248
- if success == false then
249
- error(value, 2)
250
- end
251
- return {
252
- value = value,
253
- done = coroutine.status(co) == "dead",
254
- }
255
- end
256
- end,
257
- }
258
- end
259
-
260
- return TS
File without changes
File without changes