nomen-lang 0.0.11 → 0.0.13

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/package.json CHANGED
@@ -1,34 +1,35 @@
1
1
  {
2
- "name": "nomen-lang",
3
- "version": "0.0.11",
4
- "description": "The CLI for the Nomen programming language.",
5
- "keywords": [],
6
- "license": "ISC",
7
- "author": "",
8
- "bin": {
9
- "nomen": "dist/index.mjs"
10
- },
11
- "files": [
12
- "dist",
13
- "src",
14
- "core",
15
- "NOMEN_AGENTS.md"
16
- ],
17
- "type": "module",
18
- "devDependencies": {
19
- "@types/node": "^26.1.2",
20
- "chokidar": "^5.0.0",
21
- "tsx": "^4.23.1",
22
- "typescript": "^7.0.2",
23
- "vite-plus": "0.2.7"
24
- },
25
- "scripts": {
26
- "build": "node scripts/bundle-assets.mjs && vp pack",
27
- "dev": "node scripts/bundle-assets.mjs && vp pack --watch",
28
- "test": "vp test",
29
- "check": "vp check",
30
- "format": "vp check --fix",
31
- "go": "tsx src/index.ts",
32
- "register": "pnpm build && pnpm add -g ."
33
- }
34
- }
2
+ "name": "nomen-lang",
3
+ "version": "0.0.13",
4
+ "description": "The CLI for the Nomen programming language.",
5
+ "keywords": [],
6
+ "license": "ISC",
7
+ "author": "",
8
+ "bin": {
9
+ "nomen": "dist/index.mjs"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "src",
14
+ "core",
15
+ "NOMEN_AGENTS.md"
16
+ ],
17
+ "type": "module",
18
+ "scripts": {
19
+ "build": "node scripts/bundle-assets.mjs && vp pack",
20
+ "dev": "node scripts/bundle-assets.mjs && vp pack --watch",
21
+ "test": "vp test",
22
+ "check": "vp check",
23
+ "format": "vp check --fix",
24
+ "prepare": "vp config",
25
+ "go": "tsx src/index.ts",
26
+ "register": "pnpm build && pnpm add -g ."
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^26.2.0",
30
+ "chokidar": "^5.0.0",
31
+ "tsx": "^4.23.12",
32
+ "typescript": "^7.0.2",
33
+ "vite-plus": "catalog:"
34
+ }
35
+ }
package/src/args.ts CHANGED
@@ -12,6 +12,10 @@ export interface Args {
12
12
  audit: boolean;
13
13
  audit_runtime?: string;
14
14
  check: boolean;
15
+ // Everything after a bare `--` on the command line — forwarded verbatim to
16
+ // the compiled program by `nomen run`. Lets a program receive its own argv
17
+ // (`nomen run --in app/main.nm -- arg1 arg2`).
18
+ program_args: string[];
15
19
  }
16
20
 
17
21
  // Canonical option name for each accepted long/short spelling.
@@ -53,9 +57,8 @@ function set(args: Args, key: string, value: string | boolean): void {
53
57
 
54
58
  /** Parse `argv` (excluding the node binary and script path) into an `Args` object. */
55
59
  export function parse_args(argv: string[] = process.argv.slice(2)): Args {
56
- const args: Args = { command: undefined, ...DEFAULTS } as Args;
60
+ const args: Args = { command: undefined, ...DEFAULTS, program_args: [] } as Args;
57
61
  const positional: string[] = [];
58
- let only_positional = false;
59
62
 
60
63
  const next_value = (i: number, spelling: string): string => {
61
64
  if (i + 1 >= argv.length) throw new Error(`Option ${spelling} requires a value`);
@@ -65,14 +68,12 @@ export function parse_args(argv: string[] = process.argv.slice(2)): Args {
65
68
  for (let i = 0; i < argv.length; i++) {
66
69
  const arg = argv[i];
67
70
 
68
- if (only_positional) {
69
- positional.push(arg);
70
- continue;
71
- }
72
-
71
+ // A bare `--` ends nomen's own option parsing; everything that follows
72
+ // is captured verbatim as the compiled program's argv (forwarded by
73
+ // `nomen run`). This matches the conventional `--` passthrough.
73
74
  if (arg === "--") {
74
- only_positional = true;
75
- continue;
75
+ args.program_args = argv.slice(i + 1);
76
+ break;
76
77
  }
77
78
 
78
79
  if (arg === "-h" || arg === "--help") {
@@ -145,6 +146,7 @@ export function print_help(): void {
145
146
  [
146
147
  "Usage:",
147
148
  " nomen run --in [file/folder] Parse, check, build and run a program",
149
+ " (args after a bare -- are forwarded to the program)",
148
150
  " nomen build --in [file/folder] Parse, check and build (no run)",
149
151
  " nomen check --in [file/folder] Parse and check only",
150
152
  " nomen format [--in folder] Reformat every .nm file",
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  #! /usr/bin/env node
2
- import { execSync } from "node:child_process";
2
+ import { execFileSync, execSync } from "node:child_process";
3
3
  import fs from "node:fs";
4
4
  import path from "node:path";
5
5
 
@@ -167,9 +167,9 @@ try {
167
167
  // Is the --in path a folder
168
168
  if (fs.lstatSync(args.in).isDirectory()) {
169
169
  if (args.watch) {
170
- watchPath(args.in, config, mode);
170
+ watchPath(args.in, config, mode, args.program_args);
171
171
  } else {
172
- processFolder(args.in, config, mode);
172
+ processFolder(args.in, config, mode, args.program_args);
173
173
  }
174
174
  } else {
175
175
  // Process the supplied file
@@ -178,9 +178,9 @@ try {
178
178
  // NOTE: We get add notifications for all watched files immediately
179
179
  // TODO: Is this the case on Windows etc too?
180
180
  if (args.watch) {
181
- watchPath(args.in, config, mode);
181
+ watchPath(args.in, config, mode, args.program_args);
182
182
  } else {
183
- processFile(args.in, config, mode);
183
+ processFile(args.in, config, mode, args.program_args);
184
184
  }
185
185
  } else {
186
186
  console.log("Unsupported file type: " + extname);
@@ -289,20 +289,20 @@ function compile_audit_runtime(config: Config, input_path: string, buildDir: str
289
289
  return audit_obj;
290
290
  }
291
291
 
292
- function watchPath(p: string, config: Config, mode: Mode) {
292
+ function watchPath(p: string, config: Config, mode: Mode, program_args: string[]) {
293
293
  chokidar.watch(p).on("all", (event, filePath) => {
294
294
  if (shouldProcessFile(filePath)) {
295
- processFile(filePath, config, mode);
295
+ processFile(filePath, config, mode, program_args);
296
296
  }
297
297
  });
298
298
  }
299
299
 
300
- function processFolder(folder: string, config: Config, mode: Mode) {
300
+ function processFolder(folder: string, config: Config, mode: Mode, program_args: string[]) {
301
301
  const dir = fs.opendirSync(folder);
302
302
  let dirent;
303
303
  while ((dirent = dir.readSync()) !== null) {
304
304
  if (shouldProcessFile(dirent.name)) {
305
- processFile(path.join(folder, dirent.name), config, mode);
305
+ processFile(path.join(folder, dirent.name), config, mode, program_args);
306
306
  // @ts-ignore
307
307
  let _ = fs.watch;
308
308
  }
@@ -314,7 +314,7 @@ function shouldProcessFile(filename: string) {
314
314
  return path.extname(filename) === SUPPORTED_EXTENSION;
315
315
  }
316
316
 
317
- function processFile(filename: string, config: Config, mode: Mode) {
317
+ function processFile(filename: string, config: Config, mode: Mode, program_args: string[]) {
318
318
  console.log("Processing", filename);
319
319
 
320
320
  const arch = config.arch || "aarch64";
@@ -399,10 +399,16 @@ function processFile(filename: string, config: Config, mode: Mode) {
399
399
  return;
400
400
  }
401
401
 
402
- execSync(outfile, { stdio: "inherit" });
403
-
404
- const runTime = performance.now();
405
- console.log("");
406
- console.log("");
407
- console.log(`Completed in ${(runTime - startTime).toFixed(2)}ms`);
402
+ // `run` executes the linked binary, forwarding any program args that
403
+ // followed a bare `--` on the nomen command line. execFileSync runs the
404
+ // binary directly (no shell), so the args are passed as real argv without
405
+ // shell-escaping concerns.
406
+ if (mode === "run") {
407
+ execFileSync(outfile, program_args, { stdio: "inherit" });
408
+
409
+ const runTime = performance.now();
410
+ console.log("");
411
+ console.log("");
412
+ console.log(`Completed in ${(runTime - startTime).toFixed(2)}ms`);
413
+ }
408
414
  }