@thigasdevelopment/luam 1.0.2 → 1.0.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/luam.mjs CHANGED
@@ -7154,7 +7154,7 @@ import { tmpdir } from "node:os";
7154
7154
  import { join as join2 } from "node:path";
7155
7155
 
7156
7156
  // src/cli/version.ts
7157
- var VERSION = true ? "1.0.2" : "0.0.0-dev";
7157
+ var VERSION = true ? "1.0.3" : "0.0.0-dev";
7158
7158
  var PROGRAM_NAME = "luam";
7159
7159
  var PROGRAM_DESCRIPTION = "luam \u2014 the Luam compiler for Multi Theft Auto resources.";
7160
7160
 
@@ -7909,6 +7909,22 @@ function walk(root, directory, excluded, tree) {
7909
7909
  }
7910
7910
  }
7911
7911
  }
7912
+ function listRootFiles(root, excluded = []) {
7913
+ let entries3;
7914
+ try {
7915
+ entries3 = readdirSync(root, { withFileTypes: true });
7916
+ } catch {
7917
+ return [];
7918
+ }
7919
+ const files = [];
7920
+ for (const entry of entries3) {
7921
+ const path = normalizePattern(entry.name);
7922
+ if (entry.isFile() && path.length > 0 && !isExcludedPath(path, excluded)) {
7923
+ files.push(path);
7924
+ }
7925
+ }
7926
+ return files.sort();
7927
+ }
7912
7928
  function listProjectFiles(root, roots, excluded = []) {
7913
7929
  const tree = { files: [], errors: [] };
7914
7930
  const seen = /* @__PURE__ */ new Set();
@@ -8736,6 +8752,7 @@ function assembleResource(project, options, onStep) {
8736
8752
  }
8737
8753
 
8738
8754
  // src/build/asset-resolution.ts
8755
+ var EMPTY_ASSET = "config-empty-asset";
8739
8756
  var MISSING_ASSET = "config-missing-asset";
8740
8757
  var OUTPUT_COLLISION = "config-output-collision";
8741
8758
  var MANIFEST_OUTPUT = "meta.xml";
@@ -8770,6 +8787,13 @@ function reservedOutput(destination) {
8770
8787
  }
8771
8788
  return destination === LIBRARY_DIRECTORY || destination.startsWith(`${LIBRARY_DIRECTORY}/`) ? `the generated "${LIBRARY_DIRECTORY}" directory` : null;
8772
8789
  }
8790
+ function emptyAssetMessage(root, from, base) {
8791
+ if (base.length > 0 && !isDirectory2(root, base)) {
8792
+ return `"${from}" is listed in "assets" but "${base}" is not a directory in "${normalizePattern(root)}".`;
8793
+ }
8794
+ const where = base.length === 0 ? `"${normalizePattern(root)}"` : `"${base}"`;
8795
+ return `"${from}" is listed in "assets" but matched no file under ${where}.`;
8796
+ }
8773
8797
  function collect(root, mapping, excluded, diagnostics) {
8774
8798
  const from = normalizePattern(mapping.from);
8775
8799
  const to = normalizePattern(mapping.to);
@@ -8786,7 +8810,11 @@ function collect(root, mapping, excluded, diagnostics) {
8786
8810
  for (const message of tree.errors) {
8787
8811
  diagnostics.push(cliError(MISSING_ASSET, message));
8788
8812
  }
8789
- return tree.files.filter((path) => matchesPattern(pattern, path)).map((path) => ({ path: joinDestination(to, suffixBelow(base, path)), source: path, isDownloaded: true }));
8813
+ const matched = tree.files.filter((path) => matchesPattern(pattern, path));
8814
+ if (matched.length === 0 && tree.errors.length === 0) {
8815
+ diagnostics.push(cliWarning(EMPTY_ASSET, emptyAssetMessage(root, from, base)));
8816
+ }
8817
+ return matched.map((path) => ({ path: joinDestination(to, suffixBelow(base, path)), source: path, isDownloaded: true }));
8790
8818
  }
8791
8819
  function reject(assets, diagnostics) {
8792
8820
  const seen = /* @__PURE__ */ new Map();
@@ -8887,7 +8915,13 @@ var MISSING_SOURCE = "config-missing-source";
8887
8915
  var NO_SOURCES = "config-no-sources";
8888
8916
  var SIDE_CONFLICT = "config-source-side-conflict";
8889
8917
  var TEST_SOURCE = "config-test-source";
8918
+ var UNMATCHED_SOURCE = "config-unmatched-source";
8890
8919
  var UNREADABLE_SOURCE = "build-source-unreadable";
8920
+ var NAMED_LIMIT = 5;
8921
+ var REMEDIES = [
8922
+ 'Add a pattern to "sources", move the file under a directory "sources" already names,',
8923
+ 'or put it in the project root, where a file no pattern names is built with the side its "#!" directive declares.'
8924
+ ].join(" ");
8891
8925
  function checkLiterals(root, resolver, found, diagnostics) {
8892
8926
  for (const pattern of resolver.patterns.filter(isLiteralPattern)) {
8893
8927
  if (isTestPath(pattern)) {
@@ -8905,6 +8939,29 @@ function checkLiterals(root, resolver, found, diagnostics) {
8905
8939
  }
8906
8940
  }
8907
8941
  }
8942
+ function collectRootSources(root, resolver, excluded, files, diagnostics) {
8943
+ for (const path of listRootFiles(root, excluded)) {
8944
+ if (!path.endsWith(SOURCE_EXTENSION) || isTestPath(path) || resolver.resolve(path).matches.length > 0) {
8945
+ continue;
8946
+ }
8947
+ const source = readSource(root, path, diagnostics);
8948
+ if (source !== null) {
8949
+ files.push({ path, source });
8950
+ }
8951
+ }
8952
+ }
8953
+ function describePaths(paths) {
8954
+ const named2 = paths.slice(0, NAMED_LIMIT).map((path) => `"${path}"`).join(", ");
8955
+ const rest = paths.length - NAMED_LIMIT;
8956
+ return rest > 0 ? `${named2} and ${rest} more` : named2;
8957
+ }
8958
+ function reportNothingBuilt(root, excluded) {
8959
+ const paths = listProjectFiles(root, [""], excluded).files.filter((path) => path.endsWith(SOURCE_EXTENSION) && !isTestPath(path));
8960
+ if (paths.length === 0) {
8961
+ return cliError(NO_SOURCES, `No "${SOURCE_EXTENSION}" source files matched "sources" in "${normalizePattern(root)}".`);
8962
+ }
8963
+ return cliError(UNMATCHED_SOURCE, `No "sources" pattern matched ${describePaths(paths)} in "${normalizePattern(root)}". ${REMEDIES}`);
8964
+ }
8908
8965
  function readSource(root, path, diagnostics) {
8909
8966
  try {
8910
8967
  return readFileSync7(resolve9(root, path), "utf8");
@@ -8934,9 +8991,10 @@ function discoverSources(root, sources, excluded = []) {
8934
8991
  files.push({ path, source, environment: resolution.environment });
8935
8992
  }
8936
8993
  }
8994
+ collectRootSources(root, resolver, excluded, files, diagnostics);
8937
8995
  checkLiterals(root, resolver, matched, diagnostics);
8938
8996
  if (files.length === 0 && diagnostics.length === 0) {
8939
- diagnostics.push(cliError(NO_SOURCES, `No "${SOURCE_EXTENSION}" source files matched "sources" in "${normalizePattern(root)}".`));
8997
+ diagnostics.push(reportNothingBuilt(root, excluded));
8940
8998
  }
8941
8999
  return { files: files.sort((left, right) => left.path.localeCompare(right.path)), resolver, diagnostics };
8942
9000
  }
@@ -25240,20 +25298,28 @@ function watchSources(root, sources, onChange, debounceMs = DEFAULT_DEBOUNCE_MS)
25240
25298
  };
25241
25299
  const isWatched = (directory, filename) => {
25242
25300
  const path = normalizePattern(relative5(root, resolve14(directory, filename)));
25243
- return path.endsWith(SOURCE_EXTENSION) && resolver.resolve(path).matches.length > 0;
25301
+ if (!path.endsWith(SOURCE_EXTENSION) || isTestPath(path)) {
25302
+ return false;
25303
+ }
25304
+ return resolver.resolve(path).matches.length > 0 || !path.includes("/");
25244
25305
  };
25245
- for (const entry of resolver.roots) {
25246
- const absolute = resolve14(root, entry);
25306
+ const observe = (absolute, recursive) => {
25247
25307
  if (!existsSync9(absolute)) {
25248
- continue;
25308
+ return;
25249
25309
  }
25250
25310
  watchers.push(
25251
- watch(absolute, { recursive: true }, (_event, filename) => {
25311
+ watch(absolute, { recursive }, (_event, filename) => {
25252
25312
  if (filename !== null && isWatched(absolute, filename.toString())) {
25253
25313
  schedule();
25254
25314
  }
25255
25315
  })
25256
25316
  );
25317
+ };
25318
+ for (const entry of resolver.roots) {
25319
+ observe(resolve14(root, entry), true);
25320
+ }
25321
+ if (!resolver.roots.includes("")) {
25322
+ observe(root, false);
25257
25323
  }
25258
25324
  return {
25259
25325
  close: () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thigasdevelopment/luam",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "The Luam compiler for Multi Theft Auto resources.",
5
5
  "keywords": [
6
6
  "mta",
@@ -7,14 +7,15 @@ compiler = {
7
7
  oop = false,
8
8
  }
9
9
 
10
+ # The layout for a project with folders. A ".luam" file in the project root is built without it.
10
11
  sources = {
11
12
  server = { 'src/server/**/*.luam' },
12
13
  client = { 'src/client/**/*.luam' },
13
14
  shared = { 'src/shared/**/*.luam' },
14
15
  }
15
16
 
16
- assets = {
17
- { from = 'assets/**/*', to = 'assets' },
18
- }
17
+ # assets = {
18
+ # { from = 'assets/**/*', to = 'assets' },
19
+ # }
19
20
 
20
21
  outDir = 'build'