@quenty/loader 3.1.1 → 3.2.0-canary.241.a4e8214.0

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/CHANGELOG.md CHANGED
@@ -3,6 +3,25 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.2.0-canary.241.a4e8214.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/loader@3.1.2...@quenty/loader@3.2.0-canary.241.a4e8214.0) (2022-01-03)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * Better error messages ([4a49909](https://github.com/Quenty/NevermoreEngine/commit/4a49909e607ca21d751da510f57ee0629808f11d))
12
+
13
+
14
+
15
+
16
+
17
+ ## [3.1.2](https://github.com/Quenty/NevermoreEngine/compare/@quenty/loader@3.1.1...@quenty/loader@3.1.2) (2021-12-30)
18
+
19
+ **Note:** Version bump only for package @quenty/loader
20
+
21
+
22
+
23
+
24
+
6
25
  ## [3.1.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/loader@3.1.0...@quenty/loader@3.1.1) (2021-10-30)
7
26
 
8
27
 
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2014 Quenty
3
+ Copyright (c) 2014-2021 Quenty
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Nevermore Loader
2
2
  <div align="center">
3
- <a href="http://quenty.github.io/api/">
4
- <img src="https://img.shields.io/badge/docs-website-green.svg" alt="Documentation" />
3
+ <a href="http://quenty.github.io/NevermoreEngine/">
4
+ <img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/docs.yml/badge.svg" alt="Documentation status" />
5
5
  </a>
6
6
  <a href="https://discord.gg/mhtGUS8">
7
- <img src="https://img.shields.io/badge/discord-nevermore-blue.svg" alt="Discord" />
7
+ <img src="https://img.shields.io/discord/385151591524597761?color=5865F2&label=discord&logo=discord&logoColor=white" alt="Discord" />
8
8
  </a>
9
9
  <a href="https://github.com/Quenty/NevermoreEngine/actions">
10
10
  <img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/build.yml/badge.svg" alt="Build and release status" />
@@ -18,6 +18,8 @@ A simple module loader for Roblox
18
18
  npm install @quenty/loader --save
19
19
  ```
20
20
 
21
+ <div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/loader">View docs →</a></div>
22
+
21
23
  ## Installation with NPM
22
24
 
23
25
  Install via NPM like this:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/loader",
3
- "version": "3.1.1",
3
+ "version": "3.2.0-canary.241.a4e8214.0",
4
4
  "description": "A simple module loader for Roblox",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -26,5 +26,5 @@
26
26
  "publishConfig": {
27
27
  "access": "public"
28
28
  },
29
- "gitHead": "e9cd4223c7fda7c852db9743ef844baa19cacb13"
29
+ "gitHead": "a4e821471f35998d63f38a4f4a578e07b4e79035"
30
30
  }
@@ -1,6 +1,9 @@
1
- --- Bounces the current named script to the expected version of this module
2
- -- @module BounceTemplate
3
- -- @author Quenty
1
+ --[=[
2
+ Bounces the current named script to the expected version of this module
3
+
4
+ @private
5
+ @class BounceTemplate
6
+ ]=]
4
7
 
5
8
  local function waitForValue(objectValue)
6
9
  local value = objectValue.Value
@@ -1,6 +1,7 @@
1
- ---
2
- -- @module BounceTemplateUtils
3
- -- @author Quenty
1
+ --[=[
2
+ @class BounceTemplateUtils
3
+ @private
4
+ ]=]
4
5
 
5
6
  local BounceTemplate = script.Parent.BounceTemplate
6
7
 
@@ -9,57 +10,57 @@ local CREATE_ONLY_LINK = false
9
10
  local BounceTemplateUtils = {}
10
11
 
11
12
  function BounceTemplateUtils.isBounceTemplate(instance)
12
- return instance:GetAttribute("IsBounceTemplate", true) == true
13
+ return instance:GetAttribute("IsBounceTemplate", true) == true
13
14
  end
14
15
 
15
16
  function BounceTemplateUtils.getTarget(instance)
16
- if not BounceTemplateUtils.isBounceTemplate(instance) then
17
- return nil
18
- end
17
+ if not BounceTemplateUtils.isBounceTemplate(instance) then
18
+ return nil
19
+ end
19
20
 
20
- if instance:IsA("ObjectValue") then
21
- return instance.Value
22
- else
23
- local found = instance:FindFirstChild("BounceTarget")
24
- if found then
25
- return found.Value
26
- else
27
- warn("[BounceTemplateUtils.getTarget] - Bounce template without BounceTarget")
28
- return nil
29
- end
30
- end
21
+ if instance:IsA("ObjectValue") then
22
+ return instance.Value
23
+ else
24
+ local found = instance:FindFirstChild("BounceTarget")
25
+ if found then
26
+ return found.Value
27
+ else
28
+ warn("[BounceTemplateUtils.getTarget] - Bounce template without BounceTarget")
29
+ return nil
30
+ end
31
+ end
31
32
  end
32
33
 
33
34
  function BounceTemplateUtils.create(target, linkName)
34
- assert(typeof(target) == "Instance", "Bad target")
35
- assert(type(linkName) == "string", "Bad linkName")
35
+ assert(typeof(target) == "Instance", "Bad target")
36
+ assert(type(linkName) == "string", "Bad linkName")
36
37
 
37
- if CREATE_ONLY_LINK then
38
- return BounceTemplateUtils.createLink(target, linkName)
39
- end
38
+ if CREATE_ONLY_LINK then
39
+ return BounceTemplateUtils.createLink(target, linkName)
40
+ end
40
41
 
41
- local copy = BounceTemplate:Clone()
42
- copy:SetAttribute("IsBounceTemplate", true)
43
- copy.Name = linkName
42
+ local copy = BounceTemplate:Clone()
43
+ copy:SetAttribute("IsBounceTemplate", true)
44
+ copy.Name = linkName
44
45
 
45
- local objectValue = Instance.new("ObjectValue")
46
- objectValue.Name = "BounceTarget"
47
- objectValue.Value = target
48
- objectValue.Parent = copy
46
+ local objectValue = Instance.new("ObjectValue")
47
+ objectValue.Name = "BounceTarget"
48
+ objectValue.Value = target
49
+ objectValue.Parent = copy
49
50
 
50
- return copy
51
+ return copy
51
52
  end
52
53
 
53
54
  function BounceTemplateUtils.createLink(target, linkName)
54
- assert(typeof(target) == "Instance", "Bad target")
55
- assert(type(linkName) == "string", "Bad linkName")
55
+ assert(typeof(target) == "Instance", "Bad target")
56
+ assert(type(linkName) == "string", "Bad linkName")
56
57
 
57
- local objectValue = Instance.new("ObjectValue")
58
- objectValue.Name = linkName
59
- objectValue.Value = target
60
- objectValue:SetAttribute("IsBounceTemplate", true)
58
+ local objectValue = Instance.new("ObjectValue")
59
+ objectValue.Name = linkName
60
+ objectValue.Value = target
61
+ objectValue:SetAttribute("IsBounceTemplate", true)
61
62
 
62
- return objectValue
63
+ return objectValue
63
64
  end
64
65
 
65
66
  return BounceTemplateUtils
@@ -1,6 +1,8 @@
1
- ---
2
- -- @module GroupInfoUtils
3
- -- @author Quenty
1
+ --[=[
2
+ Nevermore loader utility library
3
+ @private
4
+ @class GroupInfoUtils
5
+ ]=]
4
6
 
5
7
  local Utils = require(script.Parent.Utils)
6
8
  local Queue = require(script.Parent.Queue)
@@ -1,5 +1,9 @@
1
- --- Legacy loading logic
2
- -- @module loader
1
+ --[=[
2
+ Legacy loading logic
3
+
4
+ @private
5
+ @class LegacyLoader
6
+ ]=]
3
7
 
4
8
  local RunService = game:GetService("RunService")
5
9
  local ReplicatedStorage = game:GetService("ReplicatedStorage")
package/src/Loader.lua CHANGED
@@ -1,5 +1,9 @@
1
- --- Loading logic
2
- -- @module loader
1
+ --[=[
2
+ Loading logic for Nevermore
3
+
4
+ @private
5
+ @class LoaderClass
6
+ ]=]
3
7
 
4
8
  local Loader = {}
5
9
  Loader.ClassName = "Loader"
@@ -1,6 +1,7 @@
1
- ---
2
- -- @module LoaderUtils
3
- -- @author Quenty
1
+ --[=[
2
+ @private
3
+ @class LoaderUtils
4
+ ]=]
4
5
 
5
6
  local loader = script.Parent
6
7
  local BounceTemplateUtils = require(script.Parent.BounceTemplateUtils)
@@ -1,6 +1,8 @@
1
- --- Utility methods to build a virtual graph of the existing package information set
2
- -- @module PackageInfoUtils
3
- -- @author Quenty
1
+ --[=[
2
+ Utility methods to build a virtual graph of the existing package information set
3
+ @private
4
+ @class PackageInfoUtils
5
+ ]=]
4
6
 
5
7
  local Utils = require(script.Parent.Utils)
6
8
  local ScriptInfoUtils = require(script.Parent.ScriptInfoUtils)
@@ -183,7 +185,7 @@ function PackageInfoUtils.tryLoadPackageFromInstance(packageInfoList, packageInf
183
185
  if value and (value:IsA("Folder") or value:IsA("ModuleScript")) then
184
186
  table.insert(packageInfoList, PackageInfoUtils.getOrCreatePackageInfo(value, packageInfoMap, scope))
185
187
  else
186
- warn(("Invalid %q ObjectValue in package linking to nothing cannot be resolved into package dependency\n\t-> %s")
188
+ error(("Invalid %q ObjectValue in package linking to nothing cannot be resolved into package dependency\n\t-> %s")
187
189
  :format(instance.Name, instance:GetFullName()))
188
190
  end
189
191
  end
package/src/Queue.lua CHANGED
@@ -1,11 +1,18 @@
1
- ---
2
- -- @module Queue
3
- -- @author Quenty
1
+ --[=[
2
+ Private queue class for loading system.
3
+
4
+ @private
5
+ @class Queue
6
+ ]=]
4
7
 
5
8
  local Queue = {}
6
9
  Queue.ClassName = "Queue"
7
10
  Queue.__index = Queue
8
11
 
12
+ --[=[
13
+ Constructs a new queue
14
+ @return Queue<T>
15
+ ]=]
9
16
  function Queue.new()
10
17
  return setmetatable({
11
18
  _first = 0;
@@ -13,16 +20,28 @@ function Queue.new()
13
20
  }, Queue)
14
21
  end
15
22
 
23
+ --[=[
24
+ Pushes an entry to the left of the queue
25
+ @param value T
26
+ ]=]
16
27
  function Queue:PushLeft(value)
17
28
  self._first = self._first - 1
18
29
  self[self._first] = value
19
30
  end
20
31
 
32
+ --[=[
33
+ Pushes an entry to the right of the queue
34
+ @param value T
35
+ ]=]
21
36
  function Queue:PushRight(value)
22
37
  self._last = self._last + 1
23
38
  self[self._last] = value
24
39
  end
25
40
 
41
+ --[=[
42
+ Pops an entry from the left of the queue
43
+ @return T
44
+ ]=]
26
45
  function Queue:PopLeft()
27
46
  if self._first > self._last then
28
47
  error("Queue is empty")
@@ -35,6 +54,10 @@ function Queue:PopLeft()
35
54
  return value
36
55
  end
37
56
 
57
+ --[=[
58
+ Pops an entry from the right of the queue
59
+ @return T
60
+ ]=]
38
61
  function Queue:PopRight()
39
62
  if self._first > self._last then
40
63
  error("Queue is empty")
@@ -47,6 +70,10 @@ function Queue:PopRight()
47
70
  return value
48
71
  end
49
72
 
73
+ --[=[
74
+ Returns true if the queue is empty
75
+ @return boolean
76
+ ]=]
50
77
  function Queue:IsEmpty()
51
78
  return self._first > self._last
52
79
  end
@@ -1,6 +1,7 @@
1
- ---
2
- -- @module ScriptInfoUtils
3
- -- @author Quenty
1
+ --[=[
2
+ @private
3
+ @class ScriptInfoUtils
4
+ ]=]
4
5
 
5
6
  local CollectionService = game:GetService("CollectionService")
6
7
 
@@ -1,6 +1,7 @@
1
- ---
2
- -- @classmod StaticLegacyLoader
3
- -- @author Quenty
1
+ --[=[
2
+ @private
3
+ @class StaticLegacyLoader
4
+ ]=]
4
5
 
5
6
  local loader = script.Parent
6
7
  local ScriptInfoUtils = require(script.Parent.ScriptInfoUtils)
package/src/Utils.lua CHANGED
@@ -1,112 +1,113 @@
1
- ---
2
- -- @module Utils
3
- -- @author Quenty
1
+ --[=[
2
+ @private
3
+ @class Utils
4
+ ]=]
4
5
 
5
6
  local Utils = {}
6
7
 
7
8
  local function errorOnIndex(_, index)
8
- error(("Bad index %q"):format(tostring(index)), 2)
9
+ error(("Bad index %q"):format(tostring(index)), 2)
9
10
  end
10
11
 
11
12
  local READ_ONLY_METATABLE = {
12
- __index = errorOnIndex;
13
- __newindex = errorOnIndex;
13
+ __index = errorOnIndex;
14
+ __newindex = errorOnIndex;
14
15
  }
15
16
 
16
17
  function Utils.readonly(_table)
17
- return setmetatable(_table, READ_ONLY_METATABLE)
18
+ return setmetatable(_table, READ_ONLY_METATABLE)
18
19
  end
19
20
 
20
21
  function Utils.copyTable(target)
21
- local new = {}
22
- for key, value in pairs(target) do
23
- new[key] = value
24
- end
25
- return new
22
+ local new = {}
23
+ for key, value in pairs(target) do
24
+ new[key] = value
25
+ end
26
+ return new
26
27
  end
27
28
 
28
29
  function Utils.count(_table)
29
- local count = 0
30
- for _, _ in pairs(_table) do
31
- count = count + 1
32
- end
33
- return count
30
+ local count = 0
31
+ for _, _ in pairs(_table) do
32
+ count = count + 1
33
+ end
34
+ return count
34
35
  end
35
36
 
36
37
  function Utils.getOrCreateValue(parent, instanceType, name, defaultValue)
37
- assert(typeof(parent) == "Instance", "Bad argument 'parent'")
38
- assert(type(instanceType) == "string", "Bad argument 'instanceType'")
39
- assert(type(name) == "string", "Bad argument 'name'")
40
-
41
- local foundChild = parent:FindFirstChild(name)
42
- if foundChild then
43
- if not foundChild:IsA(instanceType) then
44
- warn(("[Utils.getOrCreateValue] - Value of type %q of name %q is of type %q in %s instead")
45
- :format(instanceType, name, foundChild.ClassName, foundChild:GetFullName()))
46
- end
47
-
48
- return foundChild
49
- else
50
- local newChild = Instance.new(instanceType)
51
- newChild.Name = name
52
- newChild.Value = defaultValue
53
- newChild.Parent = parent
54
-
55
- return newChild
56
- end
38
+ assert(typeof(parent) == "Instance", "Bad argument 'parent'")
39
+ assert(type(instanceType) == "string", "Bad argument 'instanceType'")
40
+ assert(type(name) == "string", "Bad argument 'name'")
41
+
42
+ local foundChild = parent:FindFirstChild(name)
43
+ if foundChild then
44
+ if not foundChild:IsA(instanceType) then
45
+ warn(("[Utils.getOrCreateValue] - Value of type %q of name %q is of type %q in %s instead")
46
+ :format(instanceType, name, foundChild.ClassName, foundChild:GetFullName()))
47
+ end
48
+
49
+ return foundChild
50
+ else
51
+ local newChild = Instance.new(instanceType)
52
+ newChild.Name = name
53
+ newChild.Value = defaultValue
54
+ newChild.Parent = parent
55
+
56
+ return newChild
57
+ end
57
58
  end
58
59
 
59
60
  function Utils.getValue(parent, instanceType, name, default)
60
- assert(typeof(parent) == "Instance", "Bad argument 'parent'")
61
- assert(type(instanceType) == "string", "Bad argument 'instanceType'")
62
- assert(type(name) == "string", "Bad argument 'name'")
63
-
64
- local foundChild = parent:FindFirstChild(name)
65
- if foundChild then
66
- if foundChild:IsA(instanceType) then
67
- return foundChild.Value
68
- else
69
- warn(("[Utils.getValue] - Value of type %q of name %q is of type %q in %s instead")
70
- :format(instanceType, name, foundChild.ClassName, foundChild:GetFullName()))
71
- return nil
72
- end
73
- else
74
- return default
75
- end
61
+ assert(typeof(parent) == "Instance", "Bad argument 'parent'")
62
+ assert(type(instanceType) == "string", "Bad argument 'instanceType'")
63
+ assert(type(name) == "string", "Bad argument 'name'")
64
+
65
+ local foundChild = parent:FindFirstChild(name)
66
+ if foundChild then
67
+ if foundChild:IsA(instanceType) then
68
+ return foundChild.Value
69
+ else
70
+ warn(("[Utils.getValue] - Value of type %q of name %q is of type %q in %s instead")
71
+ :format(instanceType, name, foundChild.ClassName, foundChild:GetFullName()))
72
+ return nil
73
+ end
74
+ else
75
+ return default
76
+ end
76
77
  end
77
78
 
78
79
  function Utils.setValue(parent, instanceType, name, value)
79
- assert(typeof(parent) == "Instance", "Bad argument 'parent'")
80
- assert(type(instanceType) == "string", "Bad argument 'instanceType'")
81
- assert(type(name) == "string", "Bad argument 'name'")
82
-
83
- local foundChild = parent:FindFirstChild(name)
84
- if foundChild then
85
- if not foundChild:IsA(instanceType) then
86
- warn(("[Utils.setValue] - Value of type %q of name %q is of type %q in %s instead")
87
- :format(instanceType, name, foundChild.ClassName, foundChild:GetFullName()))
88
- end
89
-
90
- foundChild.Value = value
91
- else
92
- local newChild = Instance.new(instanceType)
93
- newChild.Name = name
94
- newChild.Value = value
95
- newChild.Parent = parent
96
- end
80
+ assert(typeof(parent) == "Instance", "Bad argument 'parent'")
81
+ assert(type(instanceType) == "string", "Bad argument 'instanceType'")
82
+ assert(type(name) == "string", "Bad argument 'name'")
83
+
84
+ local foundChild = parent:FindFirstChild(name)
85
+ if foundChild then
86
+ if not foundChild:IsA(instanceType) then
87
+ warn(("[Utils.setValue] - Value of type %q of name %q is of type %q in %s instead")
88
+ :format(instanceType, name, foundChild.ClassName, foundChild:GetFullName()))
89
+ end
90
+
91
+ foundChild.Value = value
92
+ else
93
+ local newChild = Instance.new(instanceType)
94
+ newChild.Name = name
95
+ newChild.Value = value
96
+ newChild.Parent = parent
97
+ end
97
98
  end
98
99
 
99
100
 
100
101
  function Utils.getOrCreateFolder(parent, folderName)
101
- local found = parent:FindFirstChild(folderName)
102
- if found then
103
- return found
104
- else
105
- local folder = Instance.new("Folder")
106
- folder.Name = folderName
107
- folder.Parent = parent
108
- return folder
109
- end
102
+ local found = parent:FindFirstChild(folderName)
103
+ if found then
104
+ return found
105
+ else
106
+ local folder = Instance.new("Folder")
107
+ folder.Name = folderName
108
+ folder.Parent = parent
109
+ return folder
110
+ end
110
111
  end
111
112
 
112
113
 
package/src/init.lua CHANGED
@@ -1,5 +1,17 @@
1
- --- Loads things
2
- -- @module loader
1
+ --[=[
2
+ Loads Nevermore and handles loading!
3
+
4
+ This is a centralized loader that handles the following scenarios:
5
+
6
+ * Specific layouts for npm node_modules
7
+ * Layouts for node_modules being symlinked
8
+ * Multiple versions of modules being used in conjunction with each other
9
+ * Relative path requires
10
+ * Require by name
11
+ * Replication to client and server
12
+
13
+ @class Loader
14
+ ]=]
3
15
 
4
16
  local ReplicatedStorage = game:GetService("ReplicatedStorage")
5
17
  local ServerScriptService = game:GetService("ServerScriptService")
@@ -34,6 +46,27 @@ else
34
46
  }
35
47
  end
36
48
 
49
+ --[=[
50
+ Bootstraps the game by replicating packages to server, client, and
51
+ shared.
52
+
53
+ ```lua
54
+ local ServerScriptService = game:GetService("ServerScriptService")
55
+
56
+ local loader = ServerScriptService:FindFirstChild("LoaderUtils", true).Parent
57
+ local packages = require(loader).bootstrapGame(ServerScriptService.ik)
58
+ ```
59
+
60
+ :::info
61
+ The game must be running to do this bootstrapping operation.
62
+ :::
63
+
64
+ @server
65
+ @function bootstrapGame
66
+ @param packageFolder Instance
67
+ @return Folder -- serverFolder
68
+ @within Loader
69
+ ]=]
37
70
  local function bootstrapGame(packageFolder)
38
71
  assert(RunService:IsRunning(), "Game must be running")
39
72
 
@@ -48,6 +81,27 @@ local function bootstrapGame(packageFolder)
48
81
  return serverFolder
49
82
  end
50
83
 
84
+ --[=[
85
+ A type that can be loaded into a module
86
+ @type ModuleReference ModuleScript | number | string
87
+ @within Loader
88
+ ]=]
89
+
90
+ --[=[
91
+ Returns a function that can be used to load modules relative
92
+ to the script specified.
93
+
94
+ ```lua
95
+ local require = require(script.Parent.loader).load(script)
96
+
97
+ local maid = require("Maid")
98
+ ```
99
+
100
+ @function load
101
+ @param script Script -- The script to load dependencies for.
102
+ @return (moduleReference: ModuleReference) -> any
103
+ @within Loader
104
+ ]=]
51
105
  local function handleLoad(moduleScript)
52
106
  assert(typeof(moduleScript) == "Instance", "Bad moduleScript")
53
107