@danielx/civet 0.6.73 → 0.6.75

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
@@ -26,8 +26,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  // source/cli.civet
27
27
  var import_main = require("./main.js");
28
28
  var import_config = require("./config.js");
29
+ var import_unplugin = require("./unplugin");
29
30
  var import_promises = __toESM(require("fs/promises"));
30
31
  var import_path = __toESM(require("path"));
32
+ var unplugin;
31
33
  function version() {
32
34
  return require("../package.json").version;
33
35
  }
@@ -68,6 +70,8 @@ Options:
68
70
  --ast Print the AST instead of the compiled code
69
71
  --inline-map Generate a sourcemap
70
72
  --no-cache Disable compiler caching (slow, for debugging)
73
+ --typecheck Run TypeScript and output diagnostics
74
+ --emit-declaration Run TypeScript and emit .d.ts files (if no errors)
71
75
 
72
76
  You can use - to read from stdin or (prefixed by -o) write to stdout.
73
77
 
@@ -82,7 +86,7 @@ function parseArgs(args) {
82
86
  const options = {};
83
87
  Object.defineProperty(options, "run", {
84
88
  get: function() {
85
- return !(this.ast || this.compile);
89
+ return !(this.ast || this.compile || this.typecheck || this.emitDeclaration);
86
90
  }
87
91
  });
88
92
  const filenames = [];
@@ -165,6 +169,15 @@ function parseArgs(args) {
165
169
  options.trace = args[++i];
166
170
  break;
167
171
  }
172
+ case "--typecheck": {
173
+ options.typecheck = true;
174
+ break;
175
+ }
176
+ case "--emit-declaration":
177
+ case "--emitDeclaration": {
178
+ options.emitDeclaration = true;
179
+ break;
180
+ }
168
181
  case "--": {
169
182
  endOfArgs(++i);
170
183
  break;
@@ -326,6 +339,14 @@ async function cli() {
326
339
  filenames = ["-"];
327
340
  }
328
341
  }
342
+ if (options.typecheck || options.emitDeclaration) {
343
+ unplugin = (0, import_unplugin.rawPlugin)({
344
+ ...options,
345
+ ts: options.js ? "civet" : "preserve",
346
+ outputExtension: ".tsx"
347
+ }, { framework: "civet-cli" });
348
+ unplugin.buildStart();
349
+ }
329
350
  if (options.run) {
330
351
  options.js = true;
331
352
  options.inlineMap = true;
@@ -356,25 +377,35 @@ async function cli() {
356
377
  (options.parseOptions ??= {}).rewriteCivetImports ??= outputExt ?? ".civet" + (options.js ? ".jsx" : ".tsx");
357
378
  }
358
379
  }
359
- const results3 = [];
380
+ let errors = 0;
360
381
  for await (const { filename, error, content, stdin } of readFiles(filenames)) {
361
382
  if (error) {
362
383
  console.error(`${filename} failed to load:`);
363
384
  console.error(error);
385
+ errors++;
364
386
  continue;
365
387
  }
366
388
  let output;
367
389
  try {
368
- output = (0, import_main.compile)(content, { ...options, filename });
390
+ if (unplugin != null) {
391
+ output = (await unplugin.load.call({
392
+ addWatchFile() {
393
+ ;
394
+ }
395
+ }, `${filename}.tsx`)).code;
396
+ } else {
397
+ output = (0, import_main.compile)(content, { ...options, filename });
398
+ }
369
399
  } catch (error2) {
370
400
  console.error(error2);
401
+ errors++;
371
402
  continue;
372
403
  }
373
404
  if (options.ast) {
374
- results3.push(process.stdout.write(JSON.stringify(output, null, 2)));
405
+ process.stdout.write(JSON.stringify(output, null, 2));
375
406
  } else if (options.compile) {
376
407
  if (stdin && !options.output || options.output === "-") {
377
- results3.push(process.stdout.write(output));
408
+ process.stdout.write(output);
378
409
  } else {
379
410
  let targetPath = import_path.default.parse(filename);
380
411
  delete targetPath.base;
@@ -397,13 +428,14 @@ async function cli() {
397
428
  }
398
429
  const targetFilename = import_path.default.format(targetPath);
399
430
  try {
400
- results3.push(await import_promises.default.writeFile(targetFilename, output));
431
+ await import_promises.default.writeFile(targetFilename, output);
401
432
  } catch (error2) {
402
433
  console.error(`${targetFilename} failed to write:`);
403
- results3.push(console.error(error2));
434
+ console.error(error2);
435
+ errors++;
404
436
  }
405
437
  }
406
- } else {
438
+ } else if (options.run) {
407
439
  const esm = /^\s*(import|export)\b/m.test(output);
408
440
  if (esm) {
409
441
  if (stdin) {
@@ -432,12 +464,12 @@ async function cli() {
432
464
  execArgv,
433
465
  stdio: "inherit"
434
466
  });
435
- results3.push(child.on("exit", async (code) => {
467
+ child.on("exit", async (code) => {
436
468
  if (stdin) {
437
469
  await import_promises.default.unlink(filename);
438
470
  }
439
471
  return process.exit(code ?? 1);
440
- }));
472
+ });
441
473
  } else {
442
474
  require("../register.js");
443
475
  try {
@@ -448,17 +480,36 @@ async function cli() {
448
480
  process.argv = ["civet", module.filename, ...scriptArgs];
449
481
  module.paths = require("module")._nodeModulePaths(import_path.default.dirname(module.filename));
450
482
  try {
451
- results3.push(module._compile(output, module.filename));
483
+ module._compile(output, module.filename);
452
484
  } catch (error2) {
453
485
  console.error(`${filename} crashed while running in CJS mode:`);
454
486
  console.error(error2);
455
- results3.push(process.exit(1));
487
+ process.exit(1);
456
488
  }
457
489
  }
458
490
  }
459
491
  }
492
+ process.exitCode = Math.min(255, errors);
493
+ if (unplugin != null) {
494
+ try {
495
+ return await unplugin.buildEnd.call({
496
+ emitFile({ source, fileName }) {
497
+ return import_promises.default.writeFile(fileName, source);
498
+ }
499
+ });
500
+ } catch (error) {
501
+ let ref1;
502
+ if (ref1 = error.message.match(/Aborting build because of (\d+) TypeScript diagnostic/)) {
503
+ const match = ref1;
504
+ return process.exitCode = Math.min(255, errors + +match[1]);
505
+ } else {
506
+ process.exitCode = 1;
507
+ throw error;
508
+ }
509
+ }
510
+ }
460
511
  ;
461
- return results3;
512
+ return;
462
513
  }
463
514
  if (require.main === module) {
464
515
  cli();
package/dist/esbuild.js CHANGED
@@ -80,7 +80,7 @@ function implicitCivet(file) {
80
80
  return civet2;
81
81
  return;
82
82
  }
83
- var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}, meta) => {
83
+ var rawPlugin = (options = {}, meta) => {
84
84
  if (options.dts)
85
85
  options.emitDeclaration = options.dts;
86
86
  if (options.js)
@@ -389,8 +389,8 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}, meta) =>
389
389
  }
390
390
  }
391
391
  };
392
- });
393
- var src_default = civetUnplugin;
392
+ };
393
+ var src_default = (0, import_unplugin.createUnplugin)(rawPlugin);
394
394
 
395
395
  // src/esbuild.ts
396
396
  var esbuild_default = src_default.esbuild;