@danielx/civet 0.7.19 → 0.7.21

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/civet CHANGED
@@ -114,6 +114,11 @@ async function parseArgs(args, isTTY = process.stdin.isTTY) {
114
114
  options.output = args[++i];
115
115
  break;
116
116
  }
117
+ case "-e":
118
+ case "--eval": {
119
+ options.eval = args[++i];
120
+ break;
121
+ }
117
122
  case "--config": {
118
123
  options.config = args[++i];
119
124
  break;
@@ -198,7 +203,7 @@ async function parseArgs(args, isTTY = process.stdin.isTTY) {
198
203
  if (options.typecheck || options.emitDeclaration) {
199
204
  options.typescript = true;
200
205
  }
201
- if (!(filenames.length || options.typescript)) {
206
+ if (!(filenames.length || options.typescript || options.eval)) {
202
207
  if (isTTY) {
203
208
  options.repl = true;
204
209
  } else {
@@ -235,7 +240,14 @@ async function parseArgs(args, isTTY = process.stdin.isTTY) {
235
240
  options.run = isRun();
236
241
  return { filenames, scriptArgs, options };
237
242
  }
238
- async function* readFiles(filenames) {
243
+ async function* readFiles(filenames, evalString) {
244
+ if (evalString != null) {
245
+ yield {
246
+ filename: "<eval>",
247
+ content: evalString + "\n",
248
+ stdin: true
249
+ };
250
+ }
239
251
  const results1 = [];
240
252
  for (let i2 = 0, len1 = filenames.length; i2 < len1; i2++) {
241
253
  let filename = filenames[i2];
@@ -289,7 +301,7 @@ async function repl(args, options) {
289
301
  const { pathToFileURL } = await import("node:url");
290
302
  importModuleDynamically = (specifier) => {
291
303
  if (/^\.\.?[/\\]/.test(specifier)) {
292
- return import(pathToFileURL(import_node_path.default.join(process.cwd(), specifier)));
304
+ return import(pathToFileURL(import_node_path.default.join(process.cwd(), specifier)).href);
293
305
  } else {
294
306
  return import(specifier);
295
307
  }
@@ -493,6 +505,7 @@ Options:
493
505
  --version Show the version number
494
506
  -o / --output XX Specify output directory and/or extension, or filename
495
507
  -c / --compile Compile input files to TypeScript (or JavaScript)
508
+ -e / --eval XX Evaluate specified code (or compile it with -c)
496
509
  --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
510
  --civet XX Specify civet compiler flag, as in "civet XX" prologue
498
511
  --comptime Enable execution of code during compilation via comptime
@@ -546,7 +559,7 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
546
559
  return repl(args, options);
547
560
  }
548
561
  let errors = 0;
549
- for await (const { filename, error, content, stdin } of readFiles(filenames)) {
562
+ for await (const { filename, error, content, stdin } of readFiles(filenames, options.eval)) {
550
563
  if (error) {
551
564
  console.error(`${filename} failed to load:`);
552
565
  console.error(error);
@@ -628,7 +641,12 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
628
641
  const { register } = await import("node:module");
629
642
  let execArgv;
630
643
  if (register) {
631
- execArgv = ["--import", "@danielx/civet/register"];
644
+ const { join } = await import("path");
645
+ const { pathToFileURL } = await import("node:url");
646
+ execArgv = [
647
+ "--import",
648
+ pathToFileURL(join(__dirname, "../register.js")).href
649
+ ];
632
650
  } else {
633
651
  execArgv = [
634
652
  "--loader",