@thigasdevelopment/luam 0.11.1 → 0.12.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/luam.mjs CHANGED
@@ -4942,8 +4942,8 @@ function createObjectType(members) {
4942
4942
  return createRecord(keys.length === 0 ? "{}" : `{ ${keys.join(", ")} }`, members);
4943
4943
  }
4944
4944
  function createLiteralRecord(members) {
4945
- const literal = createObjectType(members);
4946
- return literal.kind === "record" ? { ...literal, isLiteral: true } : literal;
4945
+ const literal2 = createObjectType(members);
4946
+ return literal2.kind === "record" ? { ...literal2, isLiteral: true } : literal2;
4947
4947
  }
4948
4948
  function isEmptyLiteral(type) {
4949
4949
  return type.kind === "record" && type.isLiteral === true && type.members.size === 0;
@@ -5279,15 +5279,6 @@ var RUNTIME_HELPERS = {
5279
5279
  injection: "automatic",
5280
5280
  features: ["class-declaration", "class-inheritance", "class-instantiation", "super-call", "enum-declaration"]
5281
5281
  },
5282
- dotenv: {
5283
- name: "dotenv",
5284
- file: "dotenv.lua",
5285
- injection: "reference",
5286
- features: [],
5287
- globals: ["Dotenv"],
5288
- environment: "server"
5289
- },
5290
- env: { name: "env", file: "env.lua", injection: "manual", features: [], requires: ["dotenv"], environment: "server" },
5291
5282
  math: { name: "math", file: "math.lua", injection: "automatic", features: ["number-extension"] },
5292
5283
  string: { name: "string", file: "string.lua", injection: "automatic", features: ["string-extension", "template-string"] },
5293
5284
  table: { name: "table", file: "table.lua", injection: "automatic", features: ["table-extension"] },
@@ -6499,7 +6490,7 @@ import { tmpdir } from "node:os";
6499
6490
  import { join as join2 } from "node:path";
6500
6491
 
6501
6492
  // src/cli/version.ts
6502
- var VERSION = true ? "0.11.1" : "0.0.0-dev";
6493
+ var VERSION = true ? "0.12.0" : "0.0.0-dev";
6503
6494
  var PROGRAM_NAME = "luam";
6504
6495
  var PROGRAM_DESCRIPTION = "luam \u2014 the Luam compiler for Multi Theft Auto resources.";
6505
6496
 
@@ -7085,85 +7076,6 @@ function addProjectOptions(command) {
7085
7076
  return command.addOption(cwdOption()).addOption(manifestOption()).addOption(colorOption());
7086
7077
  }
7087
7078
 
7088
- // ../compiler/src/project/env-file.ts
7089
- var ENTRY = /^([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/;
7090
- var SENSITIVE = /(password|secret|token|key|credential|dsn|private)/i;
7091
- var EMPTY_ENV_FILE = { entries: [], errors: [] };
7092
- function unquote(raw) {
7093
- const quote2 = raw.slice(0, 1);
7094
- if (quote2 !== '"' && quote2 !== "'") {
7095
- return null;
7096
- }
7097
- const closing = raw.lastIndexOf(quote2);
7098
- return closing > 0 ? raw.slice(1, closing) : null;
7099
- }
7100
- function stripComment(raw) {
7101
- return raw.replace(/\s+#.*$/, "").trim();
7102
- }
7103
- function classify(raw) {
7104
- const quoted = unquote(raw);
7105
- if (quoted !== null) {
7106
- return { value: quoted, kind: "string" };
7107
- }
7108
- const value = stripComment(raw);
7109
- if (value === "true" || value === "false") {
7110
- return { value, kind: "boolean" };
7111
- }
7112
- return { value, kind: value.length > 0 && Number.isFinite(Number(value)) ? "number" : "string" };
7113
- }
7114
- function parseEnvFile(source) {
7115
- const entries2 = [];
7116
- const errors = [];
7117
- source.split(/\r?\n/).forEach((raw, index) => {
7118
- const trimmed = raw.trim();
7119
- const line2 = index + 1;
7120
- if (trimmed.length === 0 || trimmed.startsWith("#")) {
7121
- return;
7122
- }
7123
- const match = ENTRY.exec(trimmed);
7124
- if (match === null || match[1] === void 0 || match[2] === void 0) {
7125
- errors.push({ line: line2, message: `Malformed entry on line ${line2}. Expected "KEY=value".` });
7126
- return;
7127
- }
7128
- const { value, kind } = classify(match[2]);
7129
- entries2.push({ key: match[1], value, kind, line: line2 });
7130
- });
7131
- return { entries: entries2, errors };
7132
- }
7133
- function isSensitiveKey(key) {
7134
- return SENSITIVE.test(key);
7135
- }
7136
- function mergeEnvFiles(base, overrides) {
7137
- const merged = new Map(base.entries.map((entry) => [entry.key, entry]));
7138
- for (const entry of overrides.entries) {
7139
- const declared = merged.get(entry.key);
7140
- if (declared !== void 0) {
7141
- merged.set(entry.key, { ...declared, value: entry.value });
7142
- }
7143
- }
7144
- return { entries: [...merged.values()], errors: [...base.errors, ...overrides.errors] };
7145
- }
7146
-
7147
- // src/build/env-template.ts
7148
- var HEADER = [
7149
- "# Deployment values for this resource.",
7150
- '# Generated once by "luam build" and owned by the server administrator.',
7151
- "# The compiler never overwrites this file, and it is never sent to clients.",
7152
- ""
7153
- ];
7154
- function quote(entry) {
7155
- if (entry.kind !== "string" || /^[A-Za-z0-9._:/@-]*$/.test(entry.value)) {
7156
- return entry.value;
7157
- }
7158
- return `"${entry.value.replace(/\\/g, "\\\\").replace(/"/g, '\\"')}"`;
7159
- }
7160
- function line(entry) {
7161
- return `${entry.key}=${isSensitiveKey(entry.key) ? "" : quote(entry)}`;
7162
- }
7163
- function renderEnvironmentTemplate(file) {
7164
- return [...HEADER, ...file.entries.map(line), ""].join("\n");
7165
- }
7166
-
7167
7079
  // src/build/helper-files.ts
7168
7080
  import { existsSync as existsSync3, readFileSync as readFileSync3 } from "node:fs";
7169
7081
  import { fileURLToPath } from "node:url";
@@ -7549,8 +7461,8 @@ var ENVIRONMENT_ORDER = { shared: 0, server: 1, client: 2 };
7549
7461
  function outputPath(sourcePath) {
7550
7462
  return normalizePath(sourcePath).replace(/^\.\//, "").replace(/\.luam$/, ".lua");
7551
7463
  }
7552
- function libraryPath(environment, file) {
7553
- return `${LIBRARY_DIRECTORY}/${environment}/${file}`;
7464
+ function libraryPath(file) {
7465
+ return `${LIBRARY_DIRECTORY}/${file}`;
7554
7466
  }
7555
7467
  function mergeEnvironment(current, environment) {
7556
7468
  if (current === void 0) {
@@ -7573,7 +7485,7 @@ function collectHelpers(modules, manual) {
7573
7485
  }
7574
7486
  return [...environments.entries()].map(([helper, environment]) => {
7575
7487
  const file = RUNTIME_HELPERS[helper].file;
7576
- return { helper, file, path: libraryPath(environment, file), environment };
7488
+ return { helper, file, path: libraryPath(file), environment };
7577
7489
  }).sort((left, right) => helperDepth(left.helper) - helperDepth(right.helper) || left.path.localeCompare(right.path));
7578
7490
  }
7579
7491
  function collectDevelopmentLogHelpers(options) {
@@ -7588,7 +7500,7 @@ function collectDevelopmentLogHelpers(options) {
7588
7500
  return Object.values(DEVELOPMENT_RUNTIME_HELPERS).map((helper) => ({
7589
7501
  helper: helper.name,
7590
7502
  file: helper.file,
7591
- path: libraryPath(helper.environment, helper.file),
7503
+ path: libraryPath(helper.file),
7592
7504
  environment: helper.environment,
7593
7505
  replacements
7594
7506
  }));
@@ -7676,20 +7588,139 @@ function findDuplicateOutputs(scripts, assets) {
7676
7588
  return diagnostics;
7677
7589
  }
7678
7590
 
7591
+ // ../compiler/src/project/env-file.ts
7592
+ var ENTRY = /^([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)$/;
7593
+ var SENSITIVE = /(password|secret|token|key|credential|dsn|private)/i;
7594
+ var EMPTY_ENV_FILE = { entries: [], errors: [] };
7595
+ function unquote(raw) {
7596
+ const quote2 = raw.slice(0, 1);
7597
+ if (quote2 !== '"' && quote2 !== "'") {
7598
+ return null;
7599
+ }
7600
+ const closing = raw.lastIndexOf(quote2);
7601
+ return closing > 0 ? raw.slice(1, closing) : null;
7602
+ }
7603
+ function stripComment(raw) {
7604
+ return raw.replace(/\s+#.*$/, "").trim();
7605
+ }
7606
+ function classify(raw) {
7607
+ const quoted = unquote(raw);
7608
+ if (quoted !== null) {
7609
+ return { value: quoted, kind: "string" };
7610
+ }
7611
+ const value = stripComment(raw);
7612
+ if (value === "true" || value === "false") {
7613
+ return { value, kind: "boolean" };
7614
+ }
7615
+ return { value, kind: value.length > 0 && Number.isFinite(Number(value)) ? "number" : "string" };
7616
+ }
7617
+ function parseEnvFile(source) {
7618
+ const entries2 = [];
7619
+ const errors = [];
7620
+ source.split(/\r?\n/).forEach((raw, index) => {
7621
+ const trimmed = raw.trim();
7622
+ const line2 = index + 1;
7623
+ if (trimmed.length === 0 || trimmed.startsWith("#")) {
7624
+ return;
7625
+ }
7626
+ const match = ENTRY.exec(trimmed);
7627
+ if (match === null || match[1] === void 0 || match[2] === void 0) {
7628
+ errors.push({ line: line2, message: `Malformed entry on line ${line2}. Expected "KEY=value".` });
7629
+ return;
7630
+ }
7631
+ const { value, kind } = classify(match[2]);
7632
+ entries2.push({ key: match[1], value, kind, line: line2 });
7633
+ });
7634
+ return { entries: entries2, errors };
7635
+ }
7636
+ function isSensitiveKey(key) {
7637
+ return SENSITIVE.test(key);
7638
+ }
7639
+ function mergeEnvFiles(base, overrides) {
7640
+ const merged = new Map(base.entries.map((entry) => [entry.key, entry]));
7641
+ for (const entry of overrides.entries) {
7642
+ const declared = merged.get(entry.key);
7643
+ if (declared !== void 0) {
7644
+ merged.set(entry.key, { ...declared, value: entry.value });
7645
+ }
7646
+ }
7647
+ return { entries: [...merged.values()], errors: [...base.errors, ...overrides.errors] };
7648
+ }
7649
+
7650
+ // ../compiler/src/project/env-script.ts
7651
+ var HEADER = [
7652
+ "-- Deployment values for this resource.",
7653
+ '-- Generated once by "luam build" and owned by the server administrator.',
7654
+ "-- The compiler never overwrites this file, and it is never sent to clients.",
7655
+ "--",
7656
+ "-- Edit the values below. Text values must stay quoted; numbers and booleans must not.",
7657
+ ""
7658
+ ];
7659
+ var FOOTER = [
7660
+ "",
7661
+ "env = setmetatable({}, {",
7662
+ " __index = function(_, key)",
7663
+ " local value = values[key]",
7664
+ "",
7665
+ " if value == nil then",
7666
+ ` error('"' .. tostring(key) .. '" is not declared in "env.lua".', 2)`,
7667
+ " end",
7668
+ "",
7669
+ " return value",
7670
+ " end,",
7671
+ " __newindex = function(_, key)",
7672
+ ` error('The environment is read-only and "' .. tostring(key) .. '" cannot be assigned.', 2)`,
7673
+ " end,",
7674
+ " __metatable = false,",
7675
+ "})",
7676
+ "",
7677
+ "if type(process) ~= 'table' then",
7678
+ " process = {}",
7679
+ "end",
7680
+ "",
7681
+ "process.env = env",
7682
+ ""
7683
+ ];
7684
+ var BLANK = { boolean: "false", number: "0", string: "''" };
7685
+ function quote(value) {
7686
+ return `'${value.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n").replace(/\r/g, "\\r")}'`;
7687
+ }
7688
+ function literal(entry) {
7689
+ if (isSensitiveKey(entry.key)) {
7690
+ return BLANK[entry.kind];
7691
+ }
7692
+ return entry.kind === "string" ? quote(entry.value) : entry.value;
7693
+ }
7694
+ function line(entry) {
7695
+ return ` ${entry.key} = ${literal(entry)},`;
7696
+ }
7697
+ function renderEnvironmentScript(file) {
7698
+ const entries2 = [...file.entries].sort((left, right) => left.key.localeCompare(right.key));
7699
+ return [...HEADER, "local values = {", ...entries2.map(line), "}", ...FOOTER].join("\n");
7700
+ }
7701
+
7679
7702
  // ../compiler/src/project/resource.ts
7680
7703
  var ENVIRONMENT_FILE = ".env";
7704
+ var ENVIRONMENT_SCRIPT = "env.lua";
7681
7705
  function configurationScript(configuration) {
7682
7706
  if (configuration === null || configuration === void 0) {
7683
7707
  return null;
7684
7708
  }
7685
7709
  return { path: configuration.path, source: configuration.source, environment: "shared", content: configuration.content, lines: [] };
7686
7710
  }
7711
+ function environmentScript(content) {
7712
+ if (content === null || content === void 0) {
7713
+ return null;
7714
+ }
7715
+ return { path: ENVIRONMENT_SCRIPT, source: ENVIRONMENT_FILE, environment: "server", content, lines: [] };
7716
+ }
7687
7717
  function helperEntry(helper) {
7688
7718
  return { src: helper.path, environment: helper.environment, group: "library" };
7689
7719
  }
7690
- function manifestScripts(helpers, configuration, sources) {
7720
+ function manifestScripts(helpers, environment, configuration, sources) {
7721
+ const deployment = environment === null ? [] : [{ src: environment.path, environment: "server", group: "configuration" }];
7691
7722
  const settings = configuration === null ? [] : [{ src: configuration.path, environment: "shared", group: "configuration" }];
7692
- return [...helpers.map(helperEntry), ...settings, ...sources];
7723
+ return [...helpers.map(helperEntry), ...deployment, ...settings, ...sources];
7693
7724
  }
7694
7725
  function collectContributions(project) {
7695
7726
  return project.modules.flatMap((module) => module.contributions);
@@ -7762,15 +7793,13 @@ function assembleResource(project, options, onStep) {
7762
7793
  const helpers = [...collectHelpers(project.modules, options.helpers ?? []), ...collectDevelopmentLogHelpers(options.developmentLogs)];
7763
7794
  const scripts = collectScripts(project.modules);
7764
7795
  const configuration = configurationScript(options.configuration);
7796
+ const environment = environmentScript(options.environmentScript);
7797
+ const deployment = [configuration, environment].filter((script) => script !== null);
7765
7798
  const sorted = [...options.assets ?? []].sort((left, right) => left.path.localeCompare(right.path));
7766
7799
  const order = resolveLoadOrder(options.loadOrder ?? [], scripts, sorted);
7767
7800
  const layout = options.layout ?? "tree";
7768
7801
  const bundles = layout === "bundle" ? collectBundles(helpers, scripts, order.scripts) : [];
7769
- const outputs = configuration === null ? scripts : [...scripts, configuration];
7770
- const duplicates = layout === "tree" ? findDuplicateOutputs(outputs, sorted) : [
7771
- ...findDuplicateOutputs(scripts, []),
7772
- ...findDuplicateOutputs(configuration === null ? [] : [configuration], sorted)
7773
- ];
7802
+ const duplicates = layout === "tree" ? findDuplicateOutputs([...scripts, ...deployment], sorted) : [...findDuplicateOutputs(scripts, []), ...findDuplicateOutputs(deployment, sorted)];
7774
7803
  const collisions = layout === "bundle" ? bundleDiagnostics(project, bundles, scripts, sorted) : [];
7775
7804
  const diagnostics = sortFileDiagnostics([...project.diagnostics, ...duplicates, ...collisions, ...order.diagnostics]);
7776
7805
  if (duplicates.length > 0 || collisions.length > 0 || order.diagnostics.length > 0) {
@@ -7782,14 +7811,17 @@ function assembleResource(project, options, onStep) {
7782
7811
  const manifestHelpers = layout === "tree" ? helpers : [];
7783
7812
  const manifest = generateManifest(
7784
7813
  manifestInfo(options),
7785
- manifestScripts(manifestHelpers, configuration, sources),
7814
+ manifestScripts(manifestHelpers, environment, configuration, sources),
7786
7815
  manifestFiles(assets),
7787
7816
  collectContributions(project),
7788
7817
  { oop: options.oop === true, minMtaVersion: options.minMtaVersion ?? null, dependencies: options.dependencies ?? [] }
7789
7818
  );
7790
7819
  onStep?.("manifest");
7791
7820
  const map = layout === "tree" ? treeResourceMap(options.resourceName ?? "", scripts) : null;
7792
- return { build: { manifest, scripts: layout === "tree" ? scripts : [], helpers, configuration, assets, bundles, layout, map }, diagnostics };
7821
+ return {
7822
+ build: { manifest, scripts: layout === "tree" ? scripts : [], helpers, configuration, environmentScript: environment, assets, bundles, layout, map },
7823
+ diagnostics
7824
+ };
7793
7825
  }
7794
7826
 
7795
7827
  // src/build/asset-resolution.ts
@@ -8313,16 +8345,7 @@ var ASYNC = record("Async", [
8313
8345
  { name: "getInterval", type: fn([], NUMBER, 0) },
8314
8346
  { name: "setInterval", type: fn([NUMBER], BOOLEAN, 1) }
8315
8347
  ]);
8316
- var DOTENV = record("Dotenv", [
8317
- { name: "path", type: STRING },
8318
- { name: "get", type: fn([STRING, ANY], ANY, 1) },
8319
- { name: "has", type: fn([STRING], BOOLEAN, 1) },
8320
- { name: "all", type: fn([], TABLE, 0) },
8321
- { name: "apply", type: fn([], TABLE, 0) }
8322
- ]);
8323
- var LUAM_RUNTIME_SERVER_GLOBALS = {
8324
- Dotenv: record("DotenvLibrary", [{ name: "new", type: fn([STRING], DOTENV, 0) }])
8325
- };
8348
+ var LUAM_RUNTIME_SERVER_GLOBALS = {};
8326
8349
  var LUAM_RUNTIME_GLOBALS = {
8327
8350
  bind: fn([ANY, ANY], ANY, 2),
8328
8351
  getClass: fn([STRING], optionalOf(TABLE), 1),
@@ -13568,8 +13591,8 @@ var EXTENSION_RESULTS = {
13568
13591
  table: TABLE_TYPE
13569
13592
  };
13570
13593
  function extensionType(receiver, property) {
13571
- const literal = receiver.kind === "string-literal" ? "string" : receiver.kind === "number-literal" ? "number" : null;
13572
- const kind = literal ?? (receiver.kind === "string" || receiver.kind === "number" ? receiver.kind : null);
13594
+ const literal2 = receiver.kind === "string-literal" ? "string" : receiver.kind === "number-literal" ? "number" : null;
13595
+ const kind = literal2 ?? (receiver.kind === "string" || receiver.kind === "number" ? receiver.kind : null);
13573
13596
  const target = kind ?? (isTableLike(receiver) ? "table" : null);
13574
13597
  if (target === null) {
13575
13598
  return null;
@@ -15353,20 +15376,14 @@ function createProjectCache() {
15353
15376
  }
15354
15377
 
15355
15378
  // src/build/build-runner.ts
15356
- function helperList(config, inputs) {
15357
- if (inputs.declared === null || config.helpers.includes("env")) {
15358
- return config.helpers;
15359
- }
15360
- const helpers = [...config.helpers, "env"];
15361
- return helpers.sort();
15362
- }
15363
15379
  function resourceOptions(config, inputs, minMtaVersion, developmentLogs, layout) {
15364
15380
  const options = {
15365
15381
  oop: config.compilerOptions.oop,
15366
15382
  dependencies: config.dependencies,
15367
- helpers: helperList(config, inputs),
15383
+ helpers: config.helpers,
15368
15384
  assets: inputs.assets,
15369
15385
  configuration: inputs.configuration,
15386
+ environmentScript: inputs.deployed === null ? null : renderEnvironmentScript(inputs.deployed),
15370
15387
  loadOrder: config.loadOrder,
15371
15388
  minMtaVersion,
15372
15389
  developmentLogs,
@@ -15420,7 +15437,6 @@ function runCompile(root, config, options = {}) {
15420
15437
  fileCount: 0,
15421
15438
  durationMs: performance.now() - started,
15422
15439
  stats: null,
15423
- environmentTemplate: null,
15424
15440
  phases: tracker.durations(),
15425
15441
  sources: /* @__PURE__ */ new Map(),
15426
15442
  map: null
@@ -15452,7 +15468,6 @@ function runCompile(root, config, options = {}) {
15452
15468
  fileCount: sources.files.length,
15453
15469
  durationMs: performance.now() - started,
15454
15470
  stats: project.stats,
15455
- environmentTemplate: inputs.deployed === null ? null : renderEnvironmentTemplate(inputs.deployed),
15456
15471
  phases: tracker.durations(),
15457
15472
  sources: diagnosticSources(sources.files, assembly.diagnostics),
15458
15473
  map: build?.map ?? null
@@ -15799,7 +15814,7 @@ import { existsSync as existsSync6, readdirSync as readdirSync3, rmdirSync, unli
15799
15814
  import { join as join5, relative as relative3, resolve as resolve9 } from "node:path";
15800
15815
  var GENERATED_MANIFEST = "meta.xml";
15801
15816
  var GENERATED_EXTENSION = ".lua";
15802
- var PROTECTED = /* @__PURE__ */ new Set([ENVIRONMENT_FILE, ".env.local"]);
15817
+ var PROTECTED = /* @__PURE__ */ new Set([ENVIRONMENT_FILE, ENVIRONMENT_SCRIPT, ".env.local"]);
15803
15818
  function normalize(path) {
15804
15819
  return path.replace(/\\/g, "/");
15805
15820
  }
@@ -15888,23 +15903,23 @@ function writeIfChanged(absolute, content) {
15888
15903
  writeFileSync4(absolute, content);
15889
15904
  return true;
15890
15905
  }
15891
- function writeEnvironmentFile(targetDir, template) {
15892
- if (template === null) {
15906
+ function writeEnvironmentScript(targetDir, script) {
15907
+ if (script === null) {
15893
15908
  return false;
15894
15909
  }
15895
- const absolute = resolveInside(targetDir, ENVIRONMENT_FILE);
15910
+ const absolute = resolveInside(targetDir, script.path);
15896
15911
  if (existsSync7(absolute)) {
15897
15912
  return false;
15898
15913
  }
15899
15914
  mkdirSync3(dirname3(absolute), { recursive: true });
15900
- writeFileSync4(absolute, template, "utf8");
15915
+ writeFileSync4(absolute, script.content, "utf8");
15901
15916
  return true;
15902
15917
  }
15903
15918
  function writeResource(targetDir, build, options) {
15904
15919
  const assembled = resourceFiles(build);
15905
15920
  const files = options.minify === true ? minifyLuaFiles(assembled) : assembled;
15906
15921
  const written = [];
15907
- const total = files.size + build.assets.length + (options.environmentTemplate === null ? 0 : 1);
15922
+ const total = files.size + build.assets.length + (build.environmentScript === null ? 0 : 1);
15908
15923
  let index = 0;
15909
15924
  let unchanged = 0;
15910
15925
  const advance = (path) => {
@@ -15929,13 +15944,13 @@ function writeResource(targetDir, build, options) {
15929
15944
  unchanged += 1;
15930
15945
  advance(asset.path);
15931
15946
  }
15932
- if (options.environmentTemplate !== null) {
15933
- if (writeEnvironmentFile(targetDir, options.environmentTemplate)) {
15934
- written.push(ENVIRONMENT_FILE);
15947
+ if (build.environmentScript !== null) {
15948
+ if (writeEnvironmentScript(targetDir, build.environmentScript)) {
15949
+ written.push(build.environmentScript.path);
15935
15950
  }
15936
- advance(ENVIRONMENT_FILE);
15951
+ advance(build.environmentScript.path);
15937
15952
  }
15938
- const keep = /* @__PURE__ */ new Set([...files.keys(), ...build.assets.map((asset) => asset.path), ENVIRONMENT_FILE]);
15953
+ const keep = /* @__PURE__ */ new Set([...files.keys(), ...build.assets.map((asset) => asset.path), ENVIRONMENT_FILE, ENVIRONMENT_SCRIPT]);
15939
15954
  const removed = pruneResource(targetDir, keep, { generatedFiles: options.generatedFiles, generatedRoots: options.generatedRoots });
15940
15955
  return { written: written.sort((left, right) => left.localeCompare(right)), removed, unchanged };
15941
15956
  }
@@ -15953,19 +15968,18 @@ function generatedRoots(config) {
15953
15968
  const roots = config.assets.map(destinationRoot).filter((root) => root.length > 0);
15954
15969
  return [.../* @__PURE__ */ new Set([...roots, LIBRARY_DIRECTORY])];
15955
15970
  }
15956
- function trackedWriteOptions(root, config, environmentTemplate, tracker) {
15971
+ function trackedWriteOptions(root, config, tracker) {
15957
15972
  return {
15958
15973
  root,
15959
15974
  generatedFiles: generatedFiles(),
15960
15975
  generatedRoots: generatedRoots(config),
15961
- environmentTemplate,
15962
15976
  onProgress: (event) => {
15963
15977
  tracker.advance(event.item, event.index, event.total);
15964
15978
  }
15965
15979
  };
15966
15980
  }
15967
- function productionWriteOptions(root, config, environmentTemplate, tracker, minify) {
15968
- return { ...trackedWriteOptions(root, config, environmentTemplate, tracker), minify: minify ?? config.output.minify };
15981
+ function productionWriteOptions(root, config, tracker, minify) {
15982
+ return { ...trackedWriteOptions(root, config, tracker), minify: minify ?? config.output.minify };
15969
15983
  }
15970
15984
 
15971
15985
  // src/commands/command-context.ts
@@ -16158,7 +16172,7 @@ async function runBuildCommand(context, options = {}) {
16158
16172
  const target = resolveBuildTarget(context.root, context.config);
16159
16173
  tracker.begin("write");
16160
16174
  const minify = options.minify ?? context.config.output.minify;
16161
- const writeOptions = productionWriteOptions(context.root, context.config, outcome.environmentTemplate, tracker, minify);
16175
+ const writeOptions = productionWriteOptions(context.root, context.config, tracker, minify);
16162
16176
  let result;
16163
16177
  try {
16164
16178
  result = writeResource(target, outcome.build, writeOptions);
@@ -16267,7 +16281,7 @@ async function runOnce(scope, transport, target, cache3, options) {
16267
16281
  reporter.warn("Skipping sync and restart because the build reported errors.");
16268
16282
  return failed(outcome);
16269
16283
  }
16270
- const writeOptions = trackedWriteOptions(context.root, context.config, outcome.environmentTemplate, tracker);
16284
+ const writeOptions = trackedWriteOptions(context.root, context.config, tracker);
16271
16285
  reportBuildOutcome(context, outcome, "Build");
16272
16286
  tracker.begin("sync");
16273
16287
  const sync = writeResource(target, outcome.build, writeOptions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thigasdevelopment/luam",
3
- "version": "0.11.1",
3
+ "version": "0.12.0",
4
4
  "description": "The Luam compiler for Multi Theft Auto resources.",
5
5
  "keywords": [
6
6
  "mta",
package/lua/dotenv.lua DELETED
@@ -1,160 +0,0 @@
1
- local DEFAULT_FILE = '.env'
2
-
3
- local KEYWORDS = {
4
- ['true'] = true,
5
- ['false'] = false,
6
- }
7
-
8
- local ESCAPES = {
9
- ['n'] = '\n',
10
- ['r'] = '\r',
11
- ['t'] = '\t',
12
- ['"'] = '"',
13
- ["'"] = "'",
14
- ['\\'] = '\\',
15
- }
16
-
17
- local function trim(value)
18
- return value:match('^%s*(.-)%s*$') or ''
19
- end
20
-
21
- local function unescape(character)
22
- return ESCAPES[character] or ('\\' .. character)
23
- end
24
-
25
- local function cast(raw)
26
- local quote = raw:sub(1, 1)
27
-
28
- if quote == '"' or quote == "'" then
29
- local quoted = raw:match('^' .. quote .. '(.*)' .. quote)
30
-
31
- if quoted then
32
- return (quoted:gsub('\\(.)', unescape))
33
- end
34
- end
35
-
36
- local value = trim((raw:gsub('%s+#.*$', '')))
37
- local keyword = KEYWORDS[value]
38
-
39
- if keyword ~= nil then
40
- return keyword
41
- end
42
-
43
- return tonumber(value) or value
44
- end
45
-
46
- local function read(path)
47
- local file = fileOpen(path, true)
48
-
49
- if not file then
50
- return nil
51
- end
52
-
53
- local content = fileRead(file, fileGetSize(file))
54
-
55
- fileClose(file)
56
-
57
- return content
58
- end
59
-
60
- local function parse(path, content)
61
- local values = {}
62
- local number = 0
63
-
64
- for line in (content .. '\n'):gmatch('(.-)\r?\n') do
65
- number = number + 1
66
-
67
- local trimmed = trim(line)
68
-
69
- if trimmed ~= '' and trimmed:sub(1, 1) ~= '#' then
70
- local key, raw = trimmed:match('^([%a_][%w_]*)%s*=%s*(.*)$')
71
-
72
- if not key then
73
- error('Malformed entry in "' .. path .. '" on line ' .. number .. '. Expected "KEY=value".')
74
- end
75
-
76
- values[key] = cast(raw)
77
- end
78
- end
79
-
80
- return values
81
- end
82
-
83
- local function seal(path, values)
84
- return setmetatable({}, {
85
- __index = function(_, key)
86
- local value = values[key]
87
-
88
- if value == nil then
89
- error('"' .. tostring(key) .. '" is not declared in "' .. path .. '".', 2)
90
- end
91
-
92
- return value
93
- end,
94
-
95
- __newindex = function(_, key)
96
- error('The environment is read-only and "' .. tostring(key) .. '" cannot be assigned.', 2)
97
- end,
98
-
99
- __metatable = false,
100
- })
101
- end
102
-
103
- if localPlayer ~= nil then
104
- return
105
- end
106
-
107
- Dotenv = {}
108
- Dotenv.__index = Dotenv
109
-
110
- function Dotenv.new(path)
111
- path = path or DEFAULT_FILE
112
-
113
- local content = read(path)
114
-
115
- if not content then
116
- error('Failed to read the environment file "' .. tostring(path) .. '".', 2)
117
- end
118
-
119
- local self = setmetatable({}, Dotenv)
120
-
121
- self.path = path
122
- self.values = parse(path, content)
123
-
124
- return self
125
- end
126
-
127
- function Dotenv:get(key, default)
128
- local value = self.values[key]
129
-
130
- if value == nil then
131
- return default
132
- end
133
-
134
- return value
135
- end
136
-
137
- function Dotenv:has(key)
138
- return self.values[key] ~= nil
139
- end
140
-
141
- function Dotenv:all()
142
- local copy = {}
143
-
144
- for key, value in pairs(self.values) do
145
- copy[key] = value
146
- end
147
-
148
- return copy
149
- end
150
-
151
- function Dotenv:apply()
152
- if type(process) ~= 'table' then
153
- process = {}
154
- end
155
-
156
- process.env = seal(self.path, self.values)
157
- env = process.env
158
-
159
- return process.env
160
- end
package/lua/env.lua DELETED
@@ -1,18 +0,0 @@
1
- local ENVIRONMENT_FILE = '.env'
2
-
3
- if localPlayer ~= nil then
4
- return
5
- end
6
-
7
- if not fileExists(ENVIRONMENT_FILE) then
8
- if type(process) ~= 'table' then
9
- process = {}
10
- end
11
-
12
- process.env = {}
13
- env = process.env
14
-
15
- return
16
- end
17
-
18
- Dotenv.new(ENVIRONMENT_FILE):apply()