polybundle 0.1.1 → 0.1.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.
package/README.md CHANGED
@@ -48,6 +48,8 @@ An array of entry script paths (order matters):
48
48
  ```
49
49
 
50
50
  ## Example Output:
51
+ [Instance2Lua](https://github.com/geringverdien/Polytoria-Instance2Lua) is built using polybundle! Below is the bundled output from the boilerplate init scripts
52
+
51
53
  ```lua
52
54
  local __module_env = {}
53
55
 
@@ -63,18 +65,18 @@ return returnedLib
63
65
  end)()
64
66
 
65
67
  -- polybundle: begin scripts\init1.lua
66
- coroutine.wrap(function()
68
+ spawn(function()
67
69
  local lib = __module_env["scripts/lib/library1.module.lua"]
68
70
 
69
71
  local addResult = lib.Add(2, 50)
70
72
 
71
73
  print(addResult)
72
74
  print("added successfully in init1")
73
- end)()
75
+ end)
74
76
  -- polybundle: end scripts\init1.lua
75
77
 
76
78
  -- polybundle: begin scripts\init2.lua
77
- coroutine.wrap(function()
79
+ spawn(function()
78
80
  local addLib = __module_env["scripts/lib/library1.module.lua"]
79
81
 
80
82
  local addResult = addLib.Add(9, 10)
@@ -84,6 +86,6 @@ local res = "add result is "
84
86
  local final = res .. tostring(addResult)
85
87
 
86
88
  print(final)
87
- end)()
89
+ end)
88
90
  -- polybundle: end scripts\init2.lua
89
91
  ```
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "polybundle",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Lua script bundler for Polytoria.",
5
5
  "license": "MIT",
6
6
  "bin": {
7
- "polybundle": "./bin/polybundle.js"
7
+ "polybundle": "bin/polybundle.js"
8
8
  },
9
9
  "files": [
10
10
  "bin/",
package/src/bundler.js CHANGED
@@ -121,14 +121,14 @@ function bundleEntries(entries, rootDir) {
121
121
  const moduleCache = new Map();
122
122
  const chunks = [];
123
123
 
124
- chunks.push("local __module_env = {}\n");
124
+ chunks.push("local __module_env = {};\n");
125
125
 
126
126
  for (const modulePath of moduleList) {
127
127
  const moduleSource = fs.readFileSync(modulePath, "utf8");
128
128
  const bundledModule = bundleModuleSource(moduleSource, modulePath, rootDir, moduleKeyMap, moduleCache, []);
129
129
  const moduleKey = moduleKeyMap.get(modulePath);
130
130
  const header = `-- polybundle: module ${moduleKey}\n`;
131
- const assignment = `__module_env[\"${moduleKey}\"] = (function()\n${normalizeLuaSource(bundledModule)}end)()\n`;
131
+ const assignment = `__module_env[\"${moduleKey}\"] = (function()\n${normalizeLuaSource(bundledModule)}end)();\n`;
132
132
  chunks.push(header + assignment);
133
133
  }
134
134
 
@@ -140,7 +140,7 @@ function bundleEntries(entries, rootDir) {
140
140
 
141
141
  const entrySource = fs.readFileSync(entryPath, "utf8");
142
142
  const replaced = replaceRequiresWithModuleRefs(entrySource, entryPath, rootDir, moduleKeyMap);
143
- const wrapped = `spawn(function()\n${normalizeLuaSource(replaced)}end)`;
143
+ const wrapped = `spawn(function()\n${normalizeLuaSource(replaced)}end);`;
144
144
  const header = `-- polybundle: begin ${path.relative(rootDir, entryPath)}\n`;
145
145
  const footer = `-- polybundle: end ${path.relative(rootDir, entryPath)}\n`;
146
146
  chunks.push(header + normalizeLuaSource(wrapped) + footer);
package/src/cli.js CHANGED
@@ -123,7 +123,14 @@ function run(args) {
123
123
  : path.resolve(cwd, "dist", "bundle.lua");
124
124
 
125
125
  try {
126
+ // save output file, warn user about localscript string lenght limit if output exceeds 65,535 characters
126
127
  const bundled = bundleEntries(entries, cwd);
128
+ if (bundled.length > 65535) {
129
+ console.warn(
130
+ "Warning: Output exceeds 65,535 characters, which is the limit for LocalScripts in Polytoria.\n" +
131
+ "Consider splitting your code into multiple bundles or optimizing your code to reduce size."
132
+ );
133
+ }
127
134
  fs.mkdirSync(path.dirname(outFile), { recursive: true });
128
135
  fs.writeFileSync(outFile, bundled, "utf8");
129
136
  console.log(`Bundled ${entries.length} entries into ${outFile}`);