aontu 0.60.0 → 0.61.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/dist/aontu.d.ts CHANGED
@@ -21,7 +21,7 @@ import { render, renderValue, renderProfile } from './render';
21
21
  import { desugarTemplate, resugarTemplate, markerFor } from './template';
22
22
  import { format, unifiedDiff } from './format';
23
23
  export type { LintFinding, FormatReport, FormatOptions } from './format';
24
- declare const VERSION = "0.60.0";
24
+ declare const VERSION = "0.61.0";
25
25
  declare class Aontu {
26
26
  opts: AontuOptions;
27
27
  lang: Lang;
package/dist/aontu.js CHANGED
@@ -65,7 +65,7 @@ Object.defineProperty(exports, "unifiedDiff", { enumerable: true, get: function
65
65
  // Kept in step with package.json by the `version` npm lifecycle script,
66
66
  // which runs on `npm version` / `npm run repo-bump`. version.test.ts
67
67
  // fails if the two ever drift.
68
- const VERSION = '0.60.0';
68
+ const VERSION = '0.61.0';
69
69
  exports.VERSION = VERSION;
70
70
  // A module file's VALUE, as far as it goes. COLLECTED, not raised: a
71
71
  // module file that does not stand up has no `mod.main` to read, and
package/dist/cli.js CHANGED
@@ -75,7 +75,7 @@ const HELP = `Usage: aontu [options] [file]
75
75
  aontu why <path> [options] <file>
76
76
  aontu set <path>=<value>... --entry <file> --overlay <file>
77
77
  aontu agentsmd [--write <AGENTS.md>] <file>
78
- aontu fmt [-w|-l|--check|-d|--lint] <file>...
78
+ aontu fmt [-w|-l|--check|-d|--lint] [--marker <token>] <file>...
79
79
  aontu lsp
80
80
  aontu mcp [--root <dir>]
81
81
 
@@ -343,10 +343,18 @@ Fmt options:
343
343
  --lint Report the style findings, key case and repeated
344
344
  shapes, on standard error, and print nothing else
345
345
  --strict With --lint, and exit 1 when there is a finding
346
+ --marker <t> The file is a generator, and this is its marker
347
+ (default //-, and #- --- /*- by extension)
346
348
 
347
349
  The fmt verb prints one document in the agreed form; with no file it
348
350
  reads standard input. Several files need one of the options above.
349
351
 
352
+ A file whose extension is not .aon is a GENERATOR, as it is for render:
353
+ the aontu its marker lines carry is formatted, the marker stands at the
354
+ left margin with the aontu indented after it, and every line of output
355
+ is held on a line of its own. A file with no marker line in it is
356
+ another language's, and is refused.
357
+
350
358
  Fmt exit codes: 0 formatted or clean, 1 a --check file would change or
351
359
  a --strict finding, 2 usage, 4 a document does not parse.
352
360
 
@@ -3419,13 +3427,15 @@ function runAgentsMd(argv) {
3419
3427
  // tradition of gofmt. The verb prints, lists, checks, diffs or rewrites;
3420
3428
  // the form itself is the library's (ts/src/format.ts), and the two
3421
3429
  // ports agree on it row by row in test/spec/fmt.tsv.
3422
- const FMT_HELP = 'aontu fmt [-w|-l|--check|-d|--lint] <file>... (try --help)';
3430
+ const FMT_HELP = 'aontu fmt [-w|-l|--check|-d|--lint] [--marker <token>] <file>... (try --help)';
3423
3431
  function runFmt(argv) {
3424
3432
  const files = [];
3433
+ let marker = undefined;
3425
3434
  const flags = {
3426
3435
  write: false, list: false, check: false, diff: false, lint: false, strict: false,
3427
3436
  };
3428
- for (const arg of argv) {
3437
+ for (let i = 0; i < argv.length; i++) {
3438
+ const arg = argv[i];
3429
3439
  if ('-h' === arg || '--help' === arg) {
3430
3440
  process.stdout.write(HELP);
3431
3441
  return 0;
@@ -3449,6 +3459,16 @@ function runFmt(argv) {
3449
3459
  flags.lint = true;
3450
3460
  flags.strict = true;
3451
3461
  }
3462
+ else if ('--marker' === arg) {
3463
+ // THE MARKER SAYS THE FILE IS A GENERATOR, whatever its
3464
+ // extension: `render` and `template` take the same option for
3465
+ // the same reason, a language the table has never seen.
3466
+ marker = argv[++i];
3467
+ if (null == marker) {
3468
+ process.stderr.write('aontu: --marker needs a token\n');
3469
+ return 2;
3470
+ }
3471
+ }
3452
3472
  else if (arg.startsWith('-')) {
3453
3473
  process.stderr.write(`aontu: unknown fmt option ${arg} (try --help)\n`);
3454
3474
  return 2;
@@ -3469,7 +3489,7 @@ function runFmt(argv) {
3469
3489
  let src = '';
3470
3490
  process.stdin.setEncoding('utf8');
3471
3491
  process.stdin.on('data', (d) => (src += d));
3472
- process.stdin.on('end', () => resolve(fmtOne('<stdin>', src, flags)));
3492
+ process.stdin.on('end', () => resolve(fmtOne('<stdin>', src, flags, marker)));
3473
3493
  });
3474
3494
  }
3475
3495
  // Several files onto standard output would be one stream nobody can
@@ -3482,22 +3502,6 @@ function runFmt(argv) {
3482
3502
  }
3483
3503
  let worst = 0;
3484
3504
  for (const file of files) {
3485
- // FMT FORMATS AONTU SOURCE, AND THE EXTENSION SAYS WHAT A FILE IS
3486
- // (ADR-012's rule, and the one `render` reads a template by).
3487
- // A TEMPLATE FILE IS NOT AONTU (docs/design/TEMPLATE.0.md; P8):
3488
- // its marker lines are fragments of a document and its other lines
3489
- // are the target's, so there is nothing here to format that would
3490
- // not also rewrite the output. Refused rather than attempted, and
3491
- // refused BY NAME rather than by a parse failure, because a `#-`
3492
- // template parses: `#` opens a comment, so every marker line
3493
- // vanishes and what is left is read as a document that was never
3494
- // written. The verb answered `0` over one, having understood none
3495
- // of it.
3496
- if (!/[.](aon|aontu)$/.test(file)) {
3497
- process.stderr.write(`aontu: ${file} is not aontu source (.aon, .aontu); a generator ` +
3498
- 'written in the target\'s own syntax is aontu template\'s\n');
3499
- return 2;
3500
- }
3501
3505
  let src;
3502
3506
  try {
3503
3507
  src = (0, node_fs_1.readFileSync)(file, 'utf8');
@@ -3506,10 +3510,42 @@ function runFmt(argv) {
3506
3510
  process.stderr.write(`aontu: cannot read ${err.path}: ${err.message}\n`);
3507
3511
  return 2;
3508
3512
  }
3509
- worst = Math.max(worst, fmtOne(file, src, flags));
3513
+ const mark = fmtMarker(file, src, marker);
3514
+ if (false === mark) {
3515
+ process.stderr.write(`aontu: ${file} is not aontu source (.aon, .aontu) and carries no ` +
3516
+ `${(0, template_1.markerFor)(file)} marker line, so there is no aontu in it to ` +
3517
+ 'format; --marker names the marker for a language the table does ' +
3518
+ 'not know\n');
3519
+ return 2;
3520
+ }
3521
+ worst = Math.max(worst, fmtOne(file, src, flags, mark));
3510
3522
  }
3511
3523
  return worst;
3512
3524
  }
3525
+ // WHAT A FILE IS, BY ITS EXTENSION (ADR-012's rule, and the one
3526
+ // `render` reads an entry by): `.aon` and `.aontu` are aontu source,
3527
+ // and anything else is a GENERATOR written in the target's own syntax
3528
+ // (docs/design/TEMPLATE.0.md), whose marker lines carry the document
3529
+ // this formats and whose other lines are output. `undefined` is aontu,
3530
+ // a string is the generator's marker, and `false` is neither.
3531
+ //
3532
+ // A FILE WITH NO MARKER LINE IN IT IS NEITHER, and that is what keeps
3533
+ // FMT.0.md §9's boundary where it stood: a `.json`, `.yaml` or `.toml`
3534
+ // include is another language's file, and reading one as a generator
3535
+ // would answer it back unchanged having understood none of it. The
3536
+ // marker is the evidence that a file was written to carry aontu at
3537
+ // all. `--marker` says so outright, and then the file is a generator
3538
+ // whatever it is called.
3539
+ function fmtMarker(file, src, marker) {
3540
+ if (undefined !== marker) {
3541
+ return marker;
3542
+ }
3543
+ if (/[.](aon|aontu)$/.test(file)) {
3544
+ return undefined;
3545
+ }
3546
+ const mark = (0, template_1.markerFor)(file);
3547
+ return (0, template_1.templateOutputs)(src, mark).some((out) => !out) ? mark : false;
3548
+ }
3513
3549
  // An option that says what to do with a file, in place of printing
3514
3550
  // it: what to do when its form would change, or the lint.
3515
3551
  function fmtQuiet(flags) {
@@ -3520,8 +3556,8 @@ function fmtQuiet(flags) {
3520
3556
  // document that does not format, with the finding that says why. The
3521
3557
  // style findings go to standard error, one line each, in the shape
3522
3558
  // every linter prints: `file:line:col: rule: message`.
3523
- function fmtOne(name, src, flags) {
3524
- const report = (0, format_1.format)(src, { path: name, lint: flags.lint });
3559
+ function fmtOne(name, src, flags, marker) {
3560
+ const report = (0, format_1.format)(src, { path: name, lint: flags.lint, template: marker });
3525
3561
  if ('error' === report.verdict) {
3526
3562
  process.stderr.write(`aontu: ${name} was not formatted\n` +
3527
3563
  report.errors.map(renderFinding).join('\n') + '\n');