@quenty/loader 10.8.0 → 10.8.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/src/Utils.lua CHANGED
@@ -1,4 +1,7 @@
1
+ --!strict
1
2
  --[=[
3
+ Utility methods to help with loader functionality.
4
+
2
5
  @private
3
6
  @class Utils
4
7
  ]=]
@@ -10,23 +13,23 @@ local function errorOnIndex(_, index)
10
13
  end
11
14
 
12
15
  local READ_ONLY_METATABLE = {
13
- __index = errorOnIndex;
14
- __newindex = errorOnIndex;
16
+ __index = errorOnIndex,
17
+ __newindex = errorOnIndex,
15
18
  }
16
19
 
17
- function Utils.readonly(_table)
18
- return setmetatable(_table, READ_ONLY_METATABLE)
20
+ function Utils.readonly<T>(_table: T): T
21
+ return setmetatable(_table :: any, READ_ONLY_METATABLE)
19
22
  end
20
23
 
21
- function Utils.count(_table)
24
+ function Utils.count(_table): number
22
25
  local count = 0
23
- for _, _ in pairs(_table) do
26
+ for _, _ in _table do
24
27
  count = count + 1
25
28
  end
26
29
  return count
27
30
  end
28
31
 
29
- function Utils.getOrCreateValue(parent, instanceType, name, defaultValue)
32
+ function Utils.getOrCreateValue(parent: Instance, instanceType: string, name: string, defaultValue: any)
30
33
  assert(typeof(parent) == "Instance", "Bad argument 'parent'")
31
34
  assert(type(instanceType) == "string", "Bad argument 'instanceType'")
32
35
  assert(type(name) == "string", "Bad argument 'name'")
@@ -34,12 +37,20 @@ function Utils.getOrCreateValue(parent, instanceType, name, defaultValue)
34
37
  local foundChild = parent:FindFirstChild(name)
35
38
  if foundChild then
36
39
  if not foundChild:IsA(instanceType) then
37
- warn(string.format("[Utils.getOrCreateValue] - Value of type %q of name %q is of type %q in %s instead", instanceType, name, foundChild.ClassName, foundChild:GetFullName()))
40
+ warn(
41
+ string.format(
42
+ "[Utils.getOrCreateValue] - Value of type %q of name %q is of type %q in %s instead",
43
+ instanceType,
44
+ name,
45
+ foundChild.ClassName,
46
+ foundChild:GetFullName()
47
+ )
48
+ )
38
49
  end
39
50
 
40
51
  return foundChild
41
52
  else
42
- local newChild = Instance.new(instanceType)
53
+ local newChild: any = Instance.new(instanceType)
43
54
  newChild.Name = name
44
55
  newChild.Value = defaultValue
45
56
  newChild.Parent = parent
@@ -48,7 +59,7 @@ function Utils.getOrCreateValue(parent, instanceType, name, defaultValue)
48
59
  end
49
60
  end
50
61
 
51
- function Utils.getValue(parent, instanceType, name, default)
62
+ function Utils.getValue(parent: Instance, instanceType: string, name: string, default: any)
52
63
  assert(typeof(parent) == "Instance", "Bad argument 'parent'")
53
64
  assert(type(instanceType) == "string", "Bad argument 'instanceType'")
54
65
  assert(type(name) == "string", "Bad argument 'name'")
@@ -56,9 +67,17 @@ function Utils.getValue(parent, instanceType, name, default)
56
67
  local foundChild = parent:FindFirstChild(name)
57
68
  if foundChild then
58
69
  if foundChild:IsA(instanceType) then
59
- return foundChild.Value
70
+ return (foundChild :: any).Value
60
71
  else
61
- warn(string.format("[Utils.getValue] - Value of type %q of name %q is of type %q in %s instead", instanceType, name, foundChild.ClassName, foundChild:GetFullName()))
72
+ warn(
73
+ string.format(
74
+ "[Utils.getValue] - Value of type %q of name %q is of type %q in %s instead",
75
+ instanceType,
76
+ name,
77
+ foundChild.ClassName,
78
+ foundChild:GetFullName()
79
+ )
80
+ )
62
81
  return nil
63
82
  end
64
83
  else
@@ -66,7 +85,7 @@ function Utils.getValue(parent, instanceType, name, default)
66
85
  end
67
86
  end
68
87
 
69
- function Utils.setValue(parent, instanceType, name, value)
88
+ function Utils.setValue(parent: Instance, instanceType: string, name: string, value: any)
70
89
  assert(typeof(parent) == "Instance", "Bad argument 'parent'")
71
90
  assert(type(instanceType) == "string", "Bad argument 'instanceType'")
72
91
  assert(type(name) == "string", "Bad argument 'name'")
@@ -74,12 +93,20 @@ function Utils.setValue(parent, instanceType, name, value)
74
93
  local foundChild = parent:FindFirstChild(name)
75
94
  if foundChild then
76
95
  if not foundChild:IsA(instanceType) then
77
- warn(string.format("[Utils.setValue] - Value of type %q of name %q is of type %q in %s instead", instanceType, name, foundChild.ClassName, foundChild:GetFullName()))
96
+ warn(
97
+ string.format(
98
+ "[Utils.setValue] - Value of type %q of name %q is of type %q in %s instead",
99
+ instanceType,
100
+ name,
101
+ foundChild.ClassName,
102
+ foundChild:GetFullName()
103
+ )
104
+ )
78
105
  end
79
106
 
80
- foundChild.Value = value
107
+ (foundChild :: any).Value = value
81
108
  else
82
- local newChild = Instance.new(instanceType)
109
+ local newChild: any = Instance.new(instanceType)
83
110
  newChild.Name = name
84
111
  newChild.Value = value
85
112
  newChild.Parent = parent
@@ -87,7 +114,7 @@ function Utils.setValue(parent, instanceType, name, value)
87
114
  end
88
115
 
89
116
 
90
- function Utils.getOrCreateFolder(parent, folderName)
117
+ function Utils.getOrCreateFolder(parent: Instance, folderName: string): Instance
91
118
  local found = parent:FindFirstChild(folderName)
92
119
  if found then
93
120
  return found
package/src/init.lua CHANGED
@@ -119,7 +119,7 @@ function Loader:__call(request)
119
119
  end
120
120
  end
121
121
 
122
- function Loader:_findDependency(request)
122
+ function Loader:_findDependency(request: string)
123
123
  assert(type(request) == "string", "Bad request")
124
124
 
125
125
  local packageTracker = GLOBAL_PACKAGE_TRACKER:FindPackageTracker(self._packages)
@@ -1,25 +0,0 @@
1
- --[=[
2
- @class ReplicatorUtils
3
- ]=]
4
-
5
- local ReplicatorUtils = {}
6
-
7
- function ReplicatorUtils.cloneWithoutChildren(value)
8
- local original = {}
9
- for _, item in pairs(value:GetChildren()) do
10
- if item.Archivable then
11
- original[item] = true
12
- item.Archivable = false
13
- end
14
- end
15
-
16
- local copy = value:Clone()
17
-
18
- for item, _ in pairs(original) do
19
- item.Archivable = true
20
- end
21
-
22
- return copy
23
- end
24
-
25
- return ReplicatorUtils