@danielx/civet 0.7.16 → 0.7.17

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.
Files changed (49) hide show
  1. package/dist/browser.js +12 -9
  2. package/dist/civet +131 -99
  3. package/dist/config.d.mts +1 -0
  4. package/dist/config.d.ts +1 -0
  5. package/dist/config.mjs +122 -0
  6. package/dist/esm.mjs +1 -1
  7. package/dist/main.js +12 -9
  8. package/dist/main.mjs +12 -9
  9. package/dist/unplugin/astro.d.ts +11 -0
  10. package/dist/unplugin/astro.js +49 -0
  11. package/dist/unplugin/astro.mjs +19 -0
  12. package/dist/unplugin/esbuild.d.ts +2 -0
  13. package/dist/unplugin/esbuild.js +36 -0
  14. package/dist/unplugin/esbuild.mjs +6 -0
  15. package/dist/unplugin/rollup.d.ts +2 -0
  16. package/dist/unplugin/rollup.js +36 -0
  17. package/dist/unplugin/rollup.mjs +6 -0
  18. package/dist/{unplugin.d.ts → unplugin/unplugin.d.ts} +7 -10
  19. package/dist/{unplugin.js → unplugin/unplugin.js} +81 -66
  20. package/dist/{unplugin-shared.mjs → unplugin/unplugin.mjs} +80 -65
  21. package/dist/unplugin/vite.d.ts +2 -0
  22. package/dist/unplugin/vite.js +36 -0
  23. package/dist/unplugin/vite.mjs +6 -0
  24. package/dist/unplugin/webpack.d.ts +2 -0
  25. package/dist/unplugin/webpack.js +36 -0
  26. package/dist/unplugin/webpack.mjs +6 -0
  27. package/package.json +27 -17
  28. package/dist/astro.d.mts +0 -16
  29. package/dist/astro.d.ts +0 -16
  30. package/dist/astro.js +0 -537
  31. package/dist/astro.mjs +0 -22
  32. package/dist/esbuild.d.mts +0 -8
  33. package/dist/esbuild.d.ts +0 -8
  34. package/dist/esbuild.js +0 -524
  35. package/dist/esbuild.mjs +0 -9
  36. package/dist/rollup.d.mts +0 -8
  37. package/dist/rollup.d.ts +0 -8
  38. package/dist/rollup.js +0 -524
  39. package/dist/rollup.mjs +0 -9
  40. package/dist/unplugin.d.mts +0 -26
  41. package/dist/unplugin.mjs +0 -10
  42. package/dist/vite.d.mts +0 -8
  43. package/dist/vite.d.ts +0 -8
  44. package/dist/vite.js +0 -524
  45. package/dist/vite.mjs +0 -9
  46. package/dist/webpack.d.mts +0 -7
  47. package/dist/webpack.d.ts +0 -7
  48. package/dist/webpack.js +0 -524
  49. package/dist/webpack.mjs +0 -9
package/dist/browser.js CHANGED
@@ -7108,8 +7108,8 @@ ${js}`
7108
7108
  var $L61 = (0, import_lib3.$L)("?=");
7109
7109
  var $L62 = (0, import_lib3.$L)("and=");
7110
7110
  var $L63 = (0, import_lib3.$L)("or=");
7111
- var $L64 = (0, import_lib3.$L)("**");
7112
- var $L65 = (0, import_lib3.$L)("*");
7111
+ var $L64 = (0, import_lib3.$L)("*");
7112
+ var $L65 = (0, import_lib3.$L)("**");
7113
7113
  var $L66 = (0, import_lib3.$L)("/");
7114
7114
  var $L67 = (0, import_lib3.$L)("%%");
7115
7115
  var $L68 = (0, import_lib3.$L)("%");
@@ -8147,13 +8147,15 @@ ${js}`
8147
8147
  function TernaryRest(ctx, state2) {
8148
8148
  return (0, import_lib3.$EVENT_C)(ctx, state2, "TernaryRest", TernaryRest$$);
8149
8149
  }
8150
- var NestedTernaryRest$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(PushIndent, (0, import_lib3.$E)((0, import_lib3.$S)(Nested, QuestionMark, MaybeNestedExtendedExpression, Nested, Colon, MaybeNestedExtendedExpression)), PopIndent), function($skip, $loc, $0, $1, $2, $3) {
8150
+ var NestedTernaryRest$0 = (0, import_lib3.$S)(Nested, QuestionMark, MaybeNestedExtendedExpression, Nested, Colon, MaybeNestedExtendedExpression);
8151
+ var NestedTernaryRest$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(PushIndent, (0, import_lib3.$E)((0, import_lib3.$S)(Nested, QuestionMark, MaybeNestedExtendedExpression, Nested, Colon, MaybeNestedExtendedExpression)), PopIndent), function($skip, $loc, $0, $1, $2, $3) {
8151
8152
  if ($2)
8152
8153
  return $2;
8153
8154
  return $skip;
8154
8155
  });
8156
+ var NestedTernaryRest$$ = [NestedTernaryRest$0, NestedTernaryRest$1];
8155
8157
  function NestedTernaryRest(ctx, state2) {
8156
- return (0, import_lib3.$EVENT)(ctx, state2, "NestedTernaryRest", NestedTernaryRest$0);
8158
+ return (0, import_lib3.$EVENT_C)(ctx, state2, "NestedTernaryRest", NestedTernaryRest$$);
8157
8159
  }
8158
8160
  var ShortCircuitExpression$0 = BinaryOpExpression;
8159
8161
  function ShortCircuitExpression(ctx, state2) {
@@ -11501,11 +11503,12 @@ ${js}`
11501
11503
  ws.push(...$2);
11502
11504
  return [ws, $3];
11503
11505
  });
11504
- var NotDedentedBinaryOp$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(Nested, (0, import_lib3.$E)(_), (0, import_lib3.$N)(Identifier), BinaryOp), function($skip, $loc, $0, $1, $2, $3, $4) {
11506
+ var NotDedentedBinaryOp$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(Nested, (0, import_lib3.$E)(_), (0, import_lib3.$N)(Identifier), (0, import_lib3.$C)((0, import_lib3.$N)((0, import_lib3.$EXPECT)($L64, 'NotDedentedBinaryOp "*"')), (0, import_lib3.$N)(ImportDeclaration)), BinaryOp), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
11507
+ var op = $5;
11505
11508
  const ws = [...$1];
11506
11509
  if ($2)
11507
11510
  ws.push(...$2);
11508
- return [ws, $4];
11511
+ return [ws, op];
11509
11512
  });
11510
11513
  var NotDedentedBinaryOp$$ = [NotDedentedBinaryOp$0, NotDedentedBinaryOp$1];
11511
11514
  function NotDedentedBinaryOp(ctx, state2) {
@@ -11559,8 +11562,8 @@ ${js}`
11559
11562
  function _BinaryOp(ctx, state2) {
11560
11563
  return (0, import_lib3.$EVENT_C)(ctx, state2, "_BinaryOp", _BinaryOp$$);
11561
11564
  }
11562
- var BinaryOpSymbol$0 = (0, import_lib3.$EXPECT)($L64, 'BinaryOpSymbol "**"');
11563
- var BinaryOpSymbol$1 = (0, import_lib3.$EXPECT)($L65, 'BinaryOpSymbol "*"');
11565
+ var BinaryOpSymbol$0 = (0, import_lib3.$EXPECT)($L65, 'BinaryOpSymbol "**"');
11566
+ var BinaryOpSymbol$1 = (0, import_lib3.$EXPECT)($L64, 'BinaryOpSymbol "*"');
11564
11567
  var BinaryOpSymbol$2 = (0, import_lib3.$EXPECT)($L66, 'BinaryOpSymbol "/"');
11565
11568
  var BinaryOpSymbol$3 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L67, 'BinaryOpSymbol "%%"'), function($skip, $loc, $0, $1) {
11566
11569
  return {
@@ -14495,7 +14498,7 @@ ${js}`
14495
14498
  function SingleQuote(ctx, state2) {
14496
14499
  return (0, import_lib3.$EVENT)(ctx, state2, "SingleQuote", SingleQuote$0);
14497
14500
  }
14498
- var Star$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L65, 'Star "*"'), function($skip, $loc, $0, $1) {
14501
+ var Star$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L64, 'Star "*"'), function($skip, $loc, $0, $1) {
14499
14502
  return { $loc, token: $1 };
14500
14503
  });
14501
14504
  function Star(ctx, state2) {
package/dist/civet CHANGED
@@ -39,68 +39,34 @@ __export(cli_exports, {
39
39
  module.exports = __toCommonJS(cli_exports);
40
40
  var import_main = require("./main.js");
41
41
  var import_config = require("./config.js");
42
- var import_unplugin = require("./unplugin");
42
+ var import_unplugin = require("./unplugin/unplugin.js");
43
43
  var import_promises = __toESM(require("node:fs/promises"));
44
44
  var import_node_path = __toESM(require("node:path"));
45
+ var import_meta = {};
45
46
  var unplugin;
46
- function version() {
47
- return require("../package.json").version;
48
- }
49
- if (process.argv.some((a) => a === "--version" || a === "-version" || a === "-v")) {
50
- console.log(version());
51
- process.exit(0);
52
- }
53
- if (process.argv.some((a1) => a1 === "--help" || a1 === "-help" || a1 === "-h")) {
54
- process.stderr.write(` \u2584\u2584\xB7 \u25AA \u258C \u2590\xB7\u2584\u2584\u2584 .\u2584\u2584\u2584\u2584\u2584
55
- \u2590\u2588 \u258C\u25AA\u2588\u2588 \u25AA\u2588\xB7\u2588\u258C\u2580\u2584.\u2580\xB7\u2022\u2588\u2588 _._ _,-'""\`-._
56
- \u2588\u2588 \u2584\u2584\u2590\u2588\xB7\u2590\u2588\u2590\u2588\u2022\u2590\u2580\u2580\u25AA\u2584 \u2590\u2588.\u25AA (,-.\`._,'( |\\\`-/|
57
- \u2590\u2588\u2588\u2588\u258C\u2590\u2588\u258C \u2588\u2588\u2588 \u2590\u2588\u2584\u2584\u258C \u2590\u2588\u258C\xB7 \`-.-' \\ )-\`( , o o)
58
- \xB7\u2580\u2580\u2580 \u2580\u2580\u2580. \u2580 \u2580\u2580\u2580 \u2580\u2580\u2580 \`- \\\`_\`"'-
59
-
60
-
61
- Usage:
62
-
63
- civet # REPL for executing code
64
- civet -c # REPL for transpiling code
65
- civet --ast # REPL for parsing code
66
- civet [options] input.civet # run input.civet
67
- civet [options] -c input.civet # -> input.civet.tsx
68
- civet [options] -c input.civet -o .ts # -> input.ts
69
- civet [options] -c input.civet -o dir # -> dir/input.civet.tsx
70
- civet [options] -c input.civet -o dir/.ts # -> dir/input.ts
71
- civet [options] -c input.civet -o output.ts # -> output.ts
72
- civet [options] < input.civet > output.ts # pipe form
73
-
74
- Options:
75
- --help Show this help message
76
- --version Show the version number
77
- -o / --output XX Specify output directory and/or extension, or filename
78
- -c / --compile Compile input files to TypeScript (or JavaScript)
79
- --config XX Specify a config file (default scans for a config.civet, civet.json, civetconfig.civet or civetconfig.json file, optionally in a .config directory, or starting with a .)
80
- --civet XX Specify civet compiler flag, as in "civet XX" prologue
81
- --comptime Enable execution of code during compilation via comptime
82
- --no-config Don't scan for a config file
83
- --js Strip out all type annotations; default to .jsx extension
84
- --ast Print the AST instead of the compiled code
85
- --inline-map Generate a sourcemap
86
- --no-cache Disable compiler caching (slow, for debugging)
87
- --typecheck Run TypeScript and output diagnostics
88
- --emit-declaration Run TypeScript and emit .d.ts files (if no errors)
89
-
90
- You can use - to read from stdin or (prefixed by -o) write to stdout.
91
-
92
- By default, .civet imports get rewritten to use the output extension.
93
- You can override this behavior via: --civet rewriteCivetImports=.ext
94
-
95
- `);
96
- process.exit(0);
47
+ async function version() {
48
+ if (import_meta.url) {
49
+ const { createRequire } = await import("node:module");
50
+ return createRequire(import_meta.url)("../package.json").version;
51
+ } else {
52
+ return require("../package.json").version;
53
+ }
97
54
  }
98
55
  var encoding = "utf8";
99
- function parseArgs(args) {
56
+ async function parseArgs(args, isTTY = process.stdin.isTTY) {
100
57
  const options = {};
101
58
  const isRun = () => !(options.ast || options.compile || options.typecheck || options.emitDeclaration);
102
59
  let filenames = [];
103
60
  let scriptArgs = [];
61
+ if (args.includes("-version")) {
62
+ options.version = true;
63
+ }
64
+ if (args.includes("-help")) {
65
+ options.help = true;
66
+ }
67
+ if (options.version || options.help) {
68
+ return { filenames, scriptArgs, options };
69
+ }
104
70
  let i = 0;
105
71
  let errors = 0;
106
72
  function endOfArgs(j) {
@@ -128,6 +94,16 @@ function parseArgs(args) {
128
94
  continue;
129
95
  }
130
96
  switch (arg) {
97
+ case "-v":
98
+ case "--version": {
99
+ options.version = true;
100
+ break;
101
+ }
102
+ case "-h":
103
+ case "--help": {
104
+ options.help = true;
105
+ break;
106
+ }
131
107
  case "-c":
132
108
  case "--compile": {
133
109
  options.compile = true;
@@ -150,7 +126,13 @@ function parseArgs(args) {
150
126
  Object.assign(
151
127
  options.parseOptions ??= {},
152
128
  (0, import_main.parse)(`civet ${args[++i]}`, {
153
- startRule: "CivetPrologueContent"
129
+ startRule: "CivetPrologueContent",
130
+ filename: "--civet argument",
131
+ events: {
132
+ // remove cache in case we've compiled Civet before
133
+ enter: void 0,
134
+ exit: void 0
135
+ }
154
136
  }).config
155
137
  );
156
138
  break;
@@ -213,9 +195,11 @@ function parseArgs(args) {
213
195
  }
214
196
  i++;
215
197
  }
216
- options.typescript = Boolean(options.typecheck || options.emitDeclaration);
198
+ if (options.typecheck || options.emitDeclaration) {
199
+ options.typescript = true;
200
+ }
217
201
  if (!(filenames.length || options.typescript)) {
218
- if (process.stdin.isTTY) {
202
+ if (isTTY) {
219
203
  options.repl = true;
220
204
  } else {
221
205
  options.compile = true;
@@ -223,6 +207,28 @@ function parseArgs(args) {
223
207
  filenames = ["-"];
224
208
  }
225
209
  }
210
+ if (options.output && options.output !== "-") {
211
+ const optionsPath = import_node_path.default.parse(options.output);
212
+ let stat;
213
+ try {
214
+ stat = await import_promises.default.stat(options.output);
215
+ } catch {
216
+ stat = null;
217
+ }
218
+ if (stat?.isDirectory() || options.output.endsWith(import_node_path.default.sep) || options.output.endsWith("/")) {
219
+ options.outputDir = options.output;
220
+ } else if (/^(\.[^]+)+$/.test(optionsPath.base)) {
221
+ options.outputExt = optionsPath.base;
222
+ if (optionsPath.dir) {
223
+ options.outputDir = optionsPath.dir;
224
+ }
225
+ } else {
226
+ options.outputPath = optionsPath;
227
+ options.outputExt = optionsPath.ext;
228
+ }
229
+ }
230
+ ;
231
+ (options.parseOptions ??= {}).rewriteCivetImports ??= options.outputExt ?? ".civet.jsx";
226
232
  if (errors) {
227
233
  process.exit(Math.min(255, errors));
228
234
  }
@@ -275,7 +281,7 @@ async function* readFiles(filenames) {
275
281
  ;
276
282
  return results1;
277
283
  }
278
- async function repl(options) {
284
+ async function repl(args, options) {
279
285
  const vm = await import("node:vm");
280
286
  let importModuleDynamically = vm.constants?.USE_MAIN_CONTEXT_DEFAULT_LOADER;
281
287
  if (!importModuleDynamically) {
@@ -294,15 +300,15 @@ async function repl(options) {
294
300
  execArgv.push(process.env.NODE_OPTIONS);
295
301
  }
296
302
  const { fork } = await import("node:child_process");
297
- fork(__filename, process.argv.slice(2), {
303
+ fork(__filename, args, {
298
304
  execArgv,
299
305
  stdio: "inherit"
300
306
  });
301
307
  return;
302
308
  }
303
309
  }
304
- require("../register.js");
305
- console.log(`Civet ${version()} REPL. Enter a blank line to ${(() => {
310
+ await import("../register.js");
311
+ console.log(`Civet ${await version()} REPL. Enter a blank line to ${(() => {
306
312
  switch (false) {
307
313
  case !options.ast: {
308
314
  return "parse";
@@ -391,7 +397,10 @@ ${" ".repeat(error.column - 1)}^ ${error.header}`);
391
397
  }
392
398
  const topLevelAwait = import_main.lib.hasAwait(ast) || import_main.lib.hasImportDeclaration(ast);
393
399
  if (topLevelAwait) {
394
- const [prologue, rest] = (0, import_main.parse)(input, { startRule: "ProloguePrefix" });
400
+ const [prologue, rest] = (0, import_main.parse)(input, {
401
+ startRule: "ProloguePrefix",
402
+ filename: "--civet argument"
403
+ });
395
404
  const prefix = input.slice(0, -rest.length);
396
405
  const coffee = prologue.some((p) => p.type === "CivetPrologue" && (p.config.coffeeCompat || p.config.coffeeDo));
397
406
  ast = await (0, import_main.compile)(
@@ -452,9 +461,57 @@ ${" ".repeat(error.column - 1)}^ ${error.header}`);
452
461
  });
453
462
  return r;
454
463
  }
455
- async function cli() {
456
- const argv = process.argv;
457
- let { filenames, scriptArgs, options } = parseArgs(argv.slice(2));
464
+ async function cli(args = process.argv.slice(2)) {
465
+ let { filenames, scriptArgs, options } = await parseArgs(args);
466
+ if (options.version) {
467
+ console.log(await version());
468
+ process.exit(0);
469
+ }
470
+ if (options.help) {
471
+ process.stderr.write(` \u2584\u2584\xB7 \u25AA \u258C \u2590\xB7\u2584\u2584\u2584 .\u2584\u2584\u2584\u2584\u2584
472
+ \u2590\u2588 \u258C\u25AA\u2588\u2588 \u25AA\u2588\xB7\u2588\u258C\u2580\u2584.\u2580\xB7\u2022\u2588\u2588 _._ _,-'""\`-._
473
+ \u2588\u2588 \u2584\u2584\u2590\u2588\xB7\u2590\u2588\u2590\u2588\u2022\u2590\u2580\u2580\u25AA\u2584 \u2590\u2588.\u25AA (,-.\`._,'( |\\\`-/|
474
+ \u2590\u2588\u2588\u2588\u258C\u2590\u2588\u258C \u2588\u2588\u2588 \u2590\u2588\u2584\u2584\u258C \u2590\u2588\u258C\xB7 \`-.-' \\ )-\`( , o o)
475
+ \xB7\u2580\u2580\u2580 \u2580\u2580\u2580. \u2580 \u2580\u2580\u2580 \u2580\u2580\u2580 \`- \\\`_\`"'-
476
+
477
+
478
+ Usage:
479
+
480
+ civet # REPL for executing code
481
+ civet -c # REPL for transpiling code
482
+ civet --ast # REPL for parsing code
483
+ civet [options] input.civet # run input.civet
484
+ civet [options] -c input.civet # -> input.civet.tsx
485
+ civet [options] -c input.civet -o .ts # -> input.ts
486
+ civet [options] -c input.civet -o dir # -> dir/input.civet.tsx
487
+ civet [options] -c input.civet -o dir/.ts # -> dir/input.ts
488
+ civet [options] -c input.civet -o output.ts # -> output.ts
489
+ civet [options] < input.civet > output.ts # pipe form
490
+
491
+ Options:
492
+ --help Show this help message
493
+ --version Show the version number
494
+ -o / --output XX Specify output directory and/or extension, or filename
495
+ -c / --compile Compile input files to TypeScript (or JavaScript)
496
+ --config XX Specify a config file (default scans for a config.civet, civet.json, civetconfig.civet or civetconfig.json file, optionally in a .config directory, or starting with a .)
497
+ --civet XX Specify civet compiler flag, as in "civet XX" prologue
498
+ --comptime Enable execution of code during compilation via comptime
499
+ --no-config Don't scan for a config file
500
+ --js Strip out all type annotations; default to .jsx extension
501
+ --ast Print the AST instead of the compiled code
502
+ --inline-map Generate a sourcemap
503
+ --no-cache Disable compiler caching (slow, for debugging)
504
+ --typecheck Run TypeScript and output diagnostics
505
+ --emit-declaration Run TypeScript and emit .d.ts files (if no errors)
506
+
507
+ You can use - to read from stdin or (prefixed by -o) write to stdout.
508
+
509
+ By default, .civet imports get rewritten to use the output extension.
510
+ You can override this behavior via: --civet rewriteCivetImports=.ext
511
+
512
+ `);
513
+ process.exit(0);
514
+ }
458
515
  if (options.config !== false) {
459
516
  options.config ??= await (0, import_config.findConfig)(process.cwd());
460
517
  }
@@ -479,30 +536,7 @@ async function cli() {
479
536
  options.inlineMap = true;
480
537
  }
481
538
  if (options.repl) {
482
- return repl(options);
483
- }
484
- let outputDir, outputExt, outputPath;
485
- if (options.output) {
486
- const optionsPath = import_node_path.default.parse(options.output);
487
- let stat;
488
- try {
489
- stat = await import_promises.default.stat(options.output);
490
- } catch {
491
- stat = null;
492
- }
493
- if (stat?.isDirectory() || options.output.endsWith(import_node_path.default.sep) || options.output.endsWith("/")) {
494
- outputDir = options.output;
495
- } else if (/^(\.[^.]+)+$/.test(optionsPath.base)) {
496
- outputExt = optionsPath.base;
497
- if (optionsPath.dir) {
498
- outputDir = optionsPath.dir;
499
- }
500
- } else {
501
- outputPath = optionsPath;
502
- }
503
- if (options.output !== "-") {
504
- (options.parseOptions ??= {}).rewriteCivetImports ??= outputExt ?? ".civet" + (options.js ? ".jsx" : ".tsx");
505
- }
539
+ return repl(args, options);
506
540
  }
507
541
  let errors = 0;
508
542
  for await (const { filename, error, content, stdin } of readFiles(filenames)) {
@@ -549,14 +583,14 @@ async function cli() {
549
583
  } else {
550
584
  targetPath.ext += ".tsx";
551
585
  }
552
- if (outputDir != null) {
553
- targetPath.dir = outputDir;
586
+ if (options.outputDir != null) {
587
+ targetPath.dir = options.outputDir;
554
588
  }
555
- if (outputExt != null) {
556
- targetPath.ext = outputExt;
589
+ if (options.outputExt != null) {
590
+ targetPath.ext = options.outputExt;
557
591
  }
558
- if (outputPath != null) {
559
- targetPath = outputPath;
592
+ if (options.outputPath != null) {
593
+ targetPath = options.outputPath;
560
594
  }
561
595
  if (targetPath.dir) {
562
596
  await import_promises.default.mkdir(targetPath.dir, { recursive: true });
@@ -619,14 +653,14 @@ async function cli() {
619
653
  return process.exit(code ?? 1);
620
654
  });
621
655
  } else {
622
- require("../register.js");
656
+ await import("../register.js");
623
657
  try {
624
658
  module.filename = await import_promises.default.realpath(filename);
625
659
  } catch {
626
660
  module.filename = filename;
627
661
  }
628
662
  process.argv = ["civet", module.filename, ...scriptArgs];
629
- module.paths = require("module")._nodeModulePaths(import_node_path.default.dirname(module.filename));
663
+ module.paths = (await import("node:module"))._nodeModulePaths(import_node_path.default.dirname(module.filename));
630
664
  try {
631
665
  module._compile(output, module.filename);
632
666
  } catch (error2) {
@@ -659,9 +693,6 @@ async function cli() {
659
693
  ;
660
694
  return;
661
695
  }
662
- if (require.main === module) {
663
- cli();
664
- }
665
696
  // Annotate the CommonJS export names for ESM import in node:
666
697
  0 && (module.exports = {
667
698
  cli,
@@ -669,3 +700,4 @@ if (require.main === module) {
669
700
  repl,
670
701
  version
671
702
  });
703
+ cli()
@@ -0,0 +1 @@
1
+ /// <reference path="./types.d.ts" />
@@ -0,0 +1 @@
1
+ /// <reference path="./types.d.ts" />
@@ -0,0 +1,122 @@
1
+ // source/config.civet
2
+ import path from "path";
3
+ import fs from "fs/promises";
4
+ import { compile } from "./main.mjs";
5
+ var configNames = [
6
+ "\u{1F408}",
7
+ "civetconfig",
8
+ "civet.config",
9
+ "package"
10
+ ];
11
+ var configExtensions = [
12
+ ".civet",
13
+ ".js",
14
+ ".yaml",
15
+ ".yml",
16
+ ".json"
17
+ ];
18
+ var configDir = ".config";
19
+ async function findInDir(dirPath) {
20
+ const entries = new Set(await fs.readdir(dirPath));
21
+ const pathFor = (name) => path.join(dirPath, name);
22
+ if (entries.has(configDir) && await (async () => {
23
+ try {
24
+ return (await fs.stat(pathFor(configDir))).isDirectory();
25
+ } catch (e) {
26
+ return;
27
+ }
28
+ })()) {
29
+ const found = await findInDir(pathFor(configDir));
30
+ if (found) {
31
+ return found;
32
+ }
33
+ }
34
+ for (let i = 0, len = configNames.length; i < len; i++) {
35
+ const configName = configNames[i];
36
+ for (let i1 = 0, len1 = configExtensions.length; i1 < len1; i1++) {
37
+ const extension = configExtensions[i1];
38
+ for (let ref = ["." + configName + extension, configName + extension], i2 = 0, len2 = ref.length; i2 < len2; i2++) {
39
+ const entry = ref[i2];
40
+ if (entries.has(entry) && await (async () => {
41
+ try {
42
+ return (await fs.stat(pathFor(entry))).isFile();
43
+ } catch (e) {
44
+ return;
45
+ }
46
+ })()) {
47
+ return pathFor(entry);
48
+ }
49
+ }
50
+ }
51
+ }
52
+ return;
53
+ }
54
+ async function findConfig(startDir) {
55
+ let curr = startDir;
56
+ let parent = path.dirname(curr);
57
+ while (curr !== parent) {
58
+ const configPath = await findInDir(curr);
59
+ if (configPath) {
60
+ return configPath;
61
+ }
62
+ curr = parent;
63
+ parent = path.dirname(curr);
64
+ }
65
+ return;
66
+ }
67
+ async function loadConfig(pathname) {
68
+ const config = await fs.readFile(pathname, "utf8");
69
+ let data = {};
70
+ if (pathname.endsWith(".json")) {
71
+ let json;
72
+ try {
73
+ json = JSON.parse(config);
74
+ } catch (e) {
75
+ throw new Error(`Error parsing JSON config file ${pathname}: ${e}`);
76
+ }
77
+ if ("civetConfig" in json) {
78
+ data = json.civetConfig;
79
+ } else if (path.basename(pathname).startsWith("package")) {
80
+ return {};
81
+ } else {
82
+ data = json;
83
+ }
84
+ } else if (/\.ya?ml$/.test(pathname)) {
85
+ try {
86
+ const { default: YAML } = await import("yaml");
87
+ const yaml = YAML.parse(config);
88
+ data = yaml.civetConfig ?? yaml;
89
+ } catch (e) {
90
+ throw new Error(`Error parsing YAML config file ${pathname}: ${e}`);
91
+ }
92
+ } else {
93
+ let js;
94
+ if (pathname.endsWith(".civet")) {
95
+ try {
96
+ js = await compile(config, {
97
+ js: true
98
+ });
99
+ } catch (e) {
100
+ throw new Error(`Error compiling Civet config file ${pathname}: ${e}`);
101
+ }
102
+ } else {
103
+ js = config;
104
+ }
105
+ try {
106
+ const exports = await import(`data:text/javascript,${encodeURIComponent(js)}`);
107
+ data = exports?.default;
108
+ } catch (e) {
109
+ throw new Error(`Error running Civet config file ${pathname}: ${e}`);
110
+ }
111
+ }
112
+ if (!(data != null && typeof data === "object" && !Array.isArray(data))) {
113
+ throw new Error(`Civet config file must export an object, not ${Array.isArray(data) ? "array" : data != null ? typeof data : "null"}`);
114
+ }
115
+ delete data?.parseOptions?.comptime;
116
+ return data;
117
+ }
118
+ export {
119
+ findConfig,
120
+ findInDir,
121
+ loadConfig
122
+ };
package/dist/esm.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  // source/esm.civet
2
2
  import { readFileSync } from "fs";
3
3
  import { pathToFileURL, fileURLToPath } from "url";
4
- import Civet from "./main.js";
4
+ import Civet from "./main.mjs";
5
5
  var { compile, SourceMap } = Civet;
6
6
  var baseURL = pathToFileURL(process.cwd() + "/").href;
7
7
  var extensionsRegex = /\.civet$/;
package/dist/main.js CHANGED
@@ -7086,8 +7086,8 @@ var $L60 = (0, import_lib3.$L)("??=");
7086
7086
  var $L61 = (0, import_lib3.$L)("?=");
7087
7087
  var $L62 = (0, import_lib3.$L)("and=");
7088
7088
  var $L63 = (0, import_lib3.$L)("or=");
7089
- var $L64 = (0, import_lib3.$L)("**");
7090
- var $L65 = (0, import_lib3.$L)("*");
7089
+ var $L64 = (0, import_lib3.$L)("*");
7090
+ var $L65 = (0, import_lib3.$L)("**");
7091
7091
  var $L66 = (0, import_lib3.$L)("/");
7092
7092
  var $L67 = (0, import_lib3.$L)("%%");
7093
7093
  var $L68 = (0, import_lib3.$L)("%");
@@ -8125,13 +8125,15 @@ var TernaryRest$$ = [TernaryRest$0, TernaryRest$1];
8125
8125
  function TernaryRest(ctx, state2) {
8126
8126
  return (0, import_lib3.$EVENT_C)(ctx, state2, "TernaryRest", TernaryRest$$);
8127
8127
  }
8128
- var NestedTernaryRest$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(PushIndent, (0, import_lib3.$E)((0, import_lib3.$S)(Nested, QuestionMark, MaybeNestedExtendedExpression, Nested, Colon, MaybeNestedExtendedExpression)), PopIndent), function($skip, $loc, $0, $1, $2, $3) {
8128
+ var NestedTernaryRest$0 = (0, import_lib3.$S)(Nested, QuestionMark, MaybeNestedExtendedExpression, Nested, Colon, MaybeNestedExtendedExpression);
8129
+ var NestedTernaryRest$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(PushIndent, (0, import_lib3.$E)((0, import_lib3.$S)(Nested, QuestionMark, MaybeNestedExtendedExpression, Nested, Colon, MaybeNestedExtendedExpression)), PopIndent), function($skip, $loc, $0, $1, $2, $3) {
8129
8130
  if ($2)
8130
8131
  return $2;
8131
8132
  return $skip;
8132
8133
  });
8134
+ var NestedTernaryRest$$ = [NestedTernaryRest$0, NestedTernaryRest$1];
8133
8135
  function NestedTernaryRest(ctx, state2) {
8134
- return (0, import_lib3.$EVENT)(ctx, state2, "NestedTernaryRest", NestedTernaryRest$0);
8136
+ return (0, import_lib3.$EVENT_C)(ctx, state2, "NestedTernaryRest", NestedTernaryRest$$);
8135
8137
  }
8136
8138
  var ShortCircuitExpression$0 = BinaryOpExpression;
8137
8139
  function ShortCircuitExpression(ctx, state2) {
@@ -11479,11 +11481,12 @@ var NotDedentedBinaryOp$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_
11479
11481
  ws.push(...$2);
11480
11482
  return [ws, $3];
11481
11483
  });
11482
- var NotDedentedBinaryOp$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(Nested, (0, import_lib3.$E)(_), (0, import_lib3.$N)(Identifier), BinaryOp), function($skip, $loc, $0, $1, $2, $3, $4) {
11484
+ var NotDedentedBinaryOp$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(Nested, (0, import_lib3.$E)(_), (0, import_lib3.$N)(Identifier), (0, import_lib3.$C)((0, import_lib3.$N)((0, import_lib3.$EXPECT)($L64, 'NotDedentedBinaryOp "*"')), (0, import_lib3.$N)(ImportDeclaration)), BinaryOp), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
11485
+ var op = $5;
11483
11486
  const ws = [...$1];
11484
11487
  if ($2)
11485
11488
  ws.push(...$2);
11486
- return [ws, $4];
11489
+ return [ws, op];
11487
11490
  });
11488
11491
  var NotDedentedBinaryOp$$ = [NotDedentedBinaryOp$0, NotDedentedBinaryOp$1];
11489
11492
  function NotDedentedBinaryOp(ctx, state2) {
@@ -11537,8 +11540,8 @@ var _BinaryOp$$ = [_BinaryOp$0, _BinaryOp$1, _BinaryOp$2];
11537
11540
  function _BinaryOp(ctx, state2) {
11538
11541
  return (0, import_lib3.$EVENT_C)(ctx, state2, "_BinaryOp", _BinaryOp$$);
11539
11542
  }
11540
- var BinaryOpSymbol$0 = (0, import_lib3.$EXPECT)($L64, 'BinaryOpSymbol "**"');
11541
- var BinaryOpSymbol$1 = (0, import_lib3.$EXPECT)($L65, 'BinaryOpSymbol "*"');
11543
+ var BinaryOpSymbol$0 = (0, import_lib3.$EXPECT)($L65, 'BinaryOpSymbol "**"');
11544
+ var BinaryOpSymbol$1 = (0, import_lib3.$EXPECT)($L64, 'BinaryOpSymbol "*"');
11542
11545
  var BinaryOpSymbol$2 = (0, import_lib3.$EXPECT)($L66, 'BinaryOpSymbol "/"');
11543
11546
  var BinaryOpSymbol$3 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L67, 'BinaryOpSymbol "%%"'), function($skip, $loc, $0, $1) {
11544
11547
  return {
@@ -14473,7 +14476,7 @@ var SingleQuote$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L188, `Single
14473
14476
  function SingleQuote(ctx, state2) {
14474
14477
  return (0, import_lib3.$EVENT)(ctx, state2, "SingleQuote", SingleQuote$0);
14475
14478
  }
14476
- var Star$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L65, 'Star "*"'), function($skip, $loc, $0, $1) {
14479
+ var Star$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L64, 'Star "*"'), function($skip, $loc, $0, $1) {
14477
14480
  return { $loc, token: $1 };
14478
14481
  });
14479
14482
  function Star(ctx, state2) {
package/dist/main.mjs CHANGED
@@ -7066,8 +7066,8 @@ var $L60 = (0, import_lib3.$L)("??=");
7066
7066
  var $L61 = (0, import_lib3.$L)("?=");
7067
7067
  var $L62 = (0, import_lib3.$L)("and=");
7068
7068
  var $L63 = (0, import_lib3.$L)("or=");
7069
- var $L64 = (0, import_lib3.$L)("**");
7070
- var $L65 = (0, import_lib3.$L)("*");
7069
+ var $L64 = (0, import_lib3.$L)("*");
7070
+ var $L65 = (0, import_lib3.$L)("**");
7071
7071
  var $L66 = (0, import_lib3.$L)("/");
7072
7072
  var $L67 = (0, import_lib3.$L)("%%");
7073
7073
  var $L68 = (0, import_lib3.$L)("%");
@@ -8105,13 +8105,15 @@ var TernaryRest$$ = [TernaryRest$0, TernaryRest$1];
8105
8105
  function TernaryRest(ctx, state2) {
8106
8106
  return (0, import_lib3.$EVENT_C)(ctx, state2, "TernaryRest", TernaryRest$$);
8107
8107
  }
8108
- var NestedTernaryRest$0 = (0, import_lib3.$TS)((0, import_lib3.$S)(PushIndent, (0, import_lib3.$E)((0, import_lib3.$S)(Nested, QuestionMark, MaybeNestedExtendedExpression, Nested, Colon, MaybeNestedExtendedExpression)), PopIndent), function($skip, $loc, $0, $1, $2, $3) {
8108
+ var NestedTernaryRest$0 = (0, import_lib3.$S)(Nested, QuestionMark, MaybeNestedExtendedExpression, Nested, Colon, MaybeNestedExtendedExpression);
8109
+ var NestedTernaryRest$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(PushIndent, (0, import_lib3.$E)((0, import_lib3.$S)(Nested, QuestionMark, MaybeNestedExtendedExpression, Nested, Colon, MaybeNestedExtendedExpression)), PopIndent), function($skip, $loc, $0, $1, $2, $3) {
8109
8110
  if ($2)
8110
8111
  return $2;
8111
8112
  return $skip;
8112
8113
  });
8114
+ var NestedTernaryRest$$ = [NestedTernaryRest$0, NestedTernaryRest$1];
8113
8115
  function NestedTernaryRest(ctx, state2) {
8114
- return (0, import_lib3.$EVENT)(ctx, state2, "NestedTernaryRest", NestedTernaryRest$0);
8116
+ return (0, import_lib3.$EVENT_C)(ctx, state2, "NestedTernaryRest", NestedTernaryRest$$);
8115
8117
  }
8116
8118
  var ShortCircuitExpression$0 = BinaryOpExpression;
8117
8119
  function ShortCircuitExpression(ctx, state2) {
@@ -11459,11 +11461,12 @@ var NotDedentedBinaryOp$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_
11459
11461
  ws.push(...$2);
11460
11462
  return [ws, $3];
11461
11463
  });
11462
- var NotDedentedBinaryOp$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(Nested, (0, import_lib3.$E)(_), (0, import_lib3.$N)(Identifier), BinaryOp), function($skip, $loc, $0, $1, $2, $3, $4) {
11464
+ var NotDedentedBinaryOp$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(Nested, (0, import_lib3.$E)(_), (0, import_lib3.$N)(Identifier), (0, import_lib3.$C)((0, import_lib3.$N)((0, import_lib3.$EXPECT)($L64, 'NotDedentedBinaryOp "*"')), (0, import_lib3.$N)(ImportDeclaration)), BinaryOp), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
11465
+ var op = $5;
11463
11466
  const ws = [...$1];
11464
11467
  if ($2)
11465
11468
  ws.push(...$2);
11466
- return [ws, $4];
11469
+ return [ws, op];
11467
11470
  });
11468
11471
  var NotDedentedBinaryOp$$ = [NotDedentedBinaryOp$0, NotDedentedBinaryOp$1];
11469
11472
  function NotDedentedBinaryOp(ctx, state2) {
@@ -11517,8 +11520,8 @@ var _BinaryOp$$ = [_BinaryOp$0, _BinaryOp$1, _BinaryOp$2];
11517
11520
  function _BinaryOp(ctx, state2) {
11518
11521
  return (0, import_lib3.$EVENT_C)(ctx, state2, "_BinaryOp", _BinaryOp$$);
11519
11522
  }
11520
- var BinaryOpSymbol$0 = (0, import_lib3.$EXPECT)($L64, 'BinaryOpSymbol "**"');
11521
- var BinaryOpSymbol$1 = (0, import_lib3.$EXPECT)($L65, 'BinaryOpSymbol "*"');
11523
+ var BinaryOpSymbol$0 = (0, import_lib3.$EXPECT)($L65, 'BinaryOpSymbol "**"');
11524
+ var BinaryOpSymbol$1 = (0, import_lib3.$EXPECT)($L64, 'BinaryOpSymbol "*"');
11522
11525
  var BinaryOpSymbol$2 = (0, import_lib3.$EXPECT)($L66, 'BinaryOpSymbol "/"');
11523
11526
  var BinaryOpSymbol$3 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L67, 'BinaryOpSymbol "%%"'), function($skip, $loc, $0, $1) {
11524
11527
  return {
@@ -14453,7 +14456,7 @@ var SingleQuote$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L188, `Single
14453
14456
  function SingleQuote(ctx, state2) {
14454
14457
  return (0, import_lib3.$EVENT)(ctx, state2, "SingleQuote", SingleQuote$0);
14455
14458
  }
14456
- var Star$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L65, 'Star "*"'), function($skip, $loc, $0, $1) {
14459
+ var Star$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L64, 'Star "*"'), function($skip, $loc, $0, $1) {
14457
14460
  return { $loc, token: $1 };
14458
14461
  });
14459
14462
  function Star(ctx, state2) {