lua-obfuscator 1.0.2 → 1.0.4

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/dist/index.js CHANGED
@@ -4,7 +4,12 @@ import path from 'path';
4
4
  import { fileURLToPath } from 'url';
5
5
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
6
6
  const prometheusPath = path.join(__dirname, '../dist/prometheus');
7
- const factory = new LuaFactory();
7
+ let factory = null;
8
+ function getFactory() {
9
+ if (!factory)
10
+ factory = new LuaFactory();
11
+ return factory;
12
+ }
8
13
  let mountPromise = null;
9
14
  async function mountDirectory(dir, prefix = '') {
10
15
  const entries = fs.readdirSync(dir, { withFileTypes: true });
@@ -15,7 +20,7 @@ async function mountDirectory(dir, prefix = '') {
15
20
  await mountDirectory(fullPath, luaPath);
16
21
  }
17
22
  else if (entry.name.endsWith('.lua')) {
18
- await factory.mountFile(luaPath, fs.readFileSync(fullPath));
23
+ await getFactory().mountFile(luaPath, fs.readFileSync(fullPath));
19
24
  }
20
25
  }
21
26
  }
@@ -30,7 +35,7 @@ function ensureMounted() {
30
35
  }
31
36
  export async function obfuscate(text, config = 'Strong', luaVersion) {
32
37
  await ensureMounted();
33
- const lua = await factory.createEngine();
38
+ const lua = await getFactory().createEngine();
34
39
  try {
35
40
  await lua.doString(`arg = {}`);
36
41
  lua.global.set('__input_code', text);
@@ -43,7 +48,9 @@ export async function obfuscate(text, config = 'Strong', luaVersion) {
43
48
  lua.global.set('__custom_config', config);
44
49
  configExpr = '__custom_config';
45
50
  }
46
- lua.global.set('__lua_version', luaVersion ?? null);
51
+ if (luaVersion !== undefined) {
52
+ await lua.global.set('__lua_version', luaVersion);
53
+ }
47
54
  const obfuscated = await lua.doString(`
48
55
  local Prometheus = require("src.prometheus")
49
56
  Prometheus.Logger.logLevel = Prometheus.Logger.LogLevel.Error
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lua-obfuscator",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -6,7 +6,11 @@ import { fileURLToPath } from 'url'
6
6
  const __dirname = path.dirname(fileURLToPath(import.meta.url))
7
7
  const prometheusPath = path.join(__dirname, '../dist/prometheus')
8
8
 
9
- const factory = new LuaFactory()
9
+ let factory: LuaFactory | null = null
10
+ function getFactory(): LuaFactory {
11
+ if (!factory) factory = new LuaFactory()
12
+ return factory
13
+ }
10
14
 
11
15
  let mountPromise: Promise<void> | null = null
12
16
 
@@ -18,7 +22,7 @@ async function mountDirectory(dir: string, prefix: string = ''): Promise<void> {
18
22
  if (entry.isDirectory()) {
19
23
  await mountDirectory(fullPath, luaPath)
20
24
  } else if (entry.name.endsWith('.lua')) {
21
- await factory.mountFile(luaPath, fs.readFileSync(fullPath))
25
+ await getFactory().mountFile(luaPath, fs.readFileSync(fullPath))
22
26
  }
23
27
  }
24
28
  }
@@ -51,7 +55,7 @@ export async function obfuscate(
51
55
  ): Promise<string> {
52
56
  await ensureMounted()
53
57
 
54
- const lua = await factory.createEngine()
58
+ const lua = await getFactory().createEngine()
55
59
  try {
56
60
  await lua.doString(`arg = {}`)
57
61
  lua.global.set('__input_code', text)
@@ -65,7 +69,9 @@ export async function obfuscate(
65
69
  configExpr = '__custom_config'
66
70
  }
67
71
 
68
- lua.global.set('__lua_version', luaVersion ?? null)
72
+ if (luaVersion !== undefined) {
73
+ await lua.global.set('__lua_version', luaVersion)
74
+ }
69
75
 
70
76
  const obfuscated = await lua.doString(`
71
77
  local Prometheus = require("src.prometheus")