nomen-lang 0.0.3 → 0.0.5

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.mjs CHANGED
@@ -21430,6 +21430,7 @@ function render_errors(source, errors) {
21430
21430
  //#endregion
21431
21431
  //#region src/index.ts
21432
21432
  const SUPPORTED_EXTENSION = ".nm";
21433
+ let build_root;
21433
21434
  console.log("\n~ NOMEN ~\n");
21434
21435
  const options = yargs(hideBin(process.argv)).usage("Usage: nomen --in [file/folder]").option("in", {
21435
21436
  alias: "i",
@@ -21466,12 +21467,11 @@ const options = yargs(hideBin(process.argv)).usage("Usage: nomen --in [file/fold
21466
21467
  }).option("audit-runtime", {
21467
21468
  describe: "Path to audit_runtime.c, linked in when --audit is set",
21468
21469
  type: "string"
21469
- }).help(true).check((argv) => {
21470
- if (!argv._.length && !argv.in) throw new Error("Missing required argument: in");
21471
- return true;
21472
- }).parseSync();
21470
+ }).help(true).parseSync();
21473
21471
  try {
21472
+ options.in = options.in ?? resolve_input();
21474
21473
  if (!options.in) process.exit(0);
21474
+ if (!build_root) build_root = fs.lstatSync(options.in).isDirectory() ? options.in : path.dirname(options.in);
21475
21475
  if (fs.existsSync(options.in)) {
21476
21476
  let config = {
21477
21477
  arch: "aarch64",
@@ -21495,6 +21495,31 @@ try {
21495
21495
  } catch (err) {
21496
21496
  console.log("UH", err);
21497
21497
  }
21498
+ function resolve_input() {
21499
+ const cwd = process.cwd();
21500
+ const config_path = path.join(cwd, "package.jsonc");
21501
+ if (fs.existsSync(config_path)) try {
21502
+ const json = fs.readFileSync(config_path, "utf8").replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
21503
+ const parsed = JSON.parse(json);
21504
+ if (parsed.entry) {
21505
+ build_root = cwd;
21506
+ return path.resolve(cwd, parsed.entry);
21507
+ }
21508
+ } catch {}
21509
+ let nm_files = [];
21510
+ try {
21511
+ nm_files = fs.readdirSync(cwd).filter((f) => f.endsWith(".nm"));
21512
+ } catch {}
21513
+ if (nm_files.length === 1) {
21514
+ build_root = cwd;
21515
+ return path.resolve(cwd, nm_files[0]);
21516
+ }
21517
+ if (nm_files.length > 1) {
21518
+ console.log(`Found ${nm_files.length} .nm files in ${cwd}. Specify which to run with --in:\n ` + nm_files.join("\n "));
21519
+ return;
21520
+ }
21521
+ console.log("Nothing to compile. Pass --in <file/folder>, or run inside a folder with a package.jsonc or a .nm file.");
21522
+ }
21498
21523
  function resolve_lib(file_path) {
21499
21524
  let dir = path.dirname(path.resolve(file_path));
21500
21525
  for (let i = 0; i < 20; i++) {
@@ -21572,9 +21597,8 @@ function processFile(filename, config) {
21572
21597
  console.log(render_errors(input, result.errors));
21573
21598
  return;
21574
21599
  }
21575
- const dir = path.dirname(filename);
21576
21600
  const basename = path.basename(filename, ".nm");
21577
- const buildDir = path.join(dir, "build");
21601
+ const buildDir = path.join(build_root ?? path.dirname(filename), "build");
21578
21602
  if (!fs.existsSync(buildDir)) fs.mkdirSync(buildDir, { recursive: true });
21579
21603
  const ext = arch === "aarch64" ? ".s" : platform === "macos" || platform === "ios" ? ".m" : ".c";
21580
21604
  const headerfile = path.join(buildDir, "main.h");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nomen-lang",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "The CLI for the Nomen programming language.",
5
5
  "keywords": [],
6
6
  "license": "ISC",
package/src/index.ts CHANGED
@@ -16,6 +16,11 @@ import type Config from "./types/Config.ts";
16
16
 
17
17
  const SUPPORTED_EXTENSION = ".nm";
18
18
 
19
+ // The folder whose `build/` subdirectory receives compiler output. Set during
20
+ // input resolution: the --in folder, the .nm file's folder, or — for
21
+ // package.jsonc discovery — the package folder (cwd), not the entry's folder.
22
+ let build_root: string | undefined;
23
+
19
24
  console.log("\n~ NOMEN ~\n");
20
25
 
21
26
  const options = yargs(hideBin(process.argv))
@@ -74,6 +79,11 @@ try {
74
79
  if (!options.in) {
75
80
  process.exit(0);
76
81
  }
82
+ // For an explicit --in, build next to whatever was passed (the folder
83
+ // itself, or the file's folder). Discovery cases set build_root themselves.
84
+ if (!build_root) {
85
+ build_root = fs.lstatSync(options.in).isDirectory() ? options.in : path.dirname(options.in);
86
+ }
77
87
 
78
88
  if (fs.existsSync(options.in)) {
79
89
  let config: Config = { arch: "aarch64", platform: default_platform() };
@@ -131,6 +141,7 @@ function resolve_input(): string | undefined {
131
141
  const json = raw.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
132
142
  const parsed = JSON.parse(json);
133
143
  if (parsed.entry) {
144
+ build_root = cwd;
134
145
  return path.resolve(cwd, parsed.entry);
135
146
  }
136
147
  } catch {
@@ -146,6 +157,7 @@ function resolve_input(): string | undefined {
146
157
  // unreadable working folder
147
158
  }
148
159
  if (nm_files.length === 1) {
160
+ build_root = cwd;
149
161
  return path.resolve(cwd, nm_files[0]);
150
162
  }
151
163
  if (nm_files.length > 1) {
@@ -276,9 +288,8 @@ function processFile(filename: string, config: Config) {
276
288
  return;
277
289
  }
278
290
 
279
- const dir = path.dirname(filename);
280
291
  const basename = path.basename(filename, ".nm");
281
- const buildDir = path.join(dir, "build");
292
+ const buildDir = path.join(build_root ?? path.dirname(filename), "build");
282
293
  if (!fs.existsSync(buildDir)) {
283
294
  fs.mkdirSync(buildDir, { recursive: true });
284
295
  }