@danielx/civet 0.8.0 → 0.8.2
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/CHANGELOG.md +19 -0
- package/dist/browser.js +5770 -5593
- package/dist/civet +36 -43
- package/dist/config.js +7182 -1
- package/dist/config.mjs +7205 -1
- package/dist/main.js +5741 -5564
- package/dist/main.mjs +5741 -5564
- package/dist/types.d.ts +2 -0
- package/dist/unplugin/rollup.d.ts +1 -1
- package/dist/unplugin/unplugin.d.ts +2 -1
- package/dist/unplugin/unplugin.js +23 -8
- package/dist/unplugin/unplugin.mjs +23 -8
- package/package.json +1 -1
package/dist/civet
CHANGED
|
@@ -400,45 +400,27 @@ ${" ".repeat(error.column - 1)}^ ${error.header}`);
|
|
|
400
400
|
}
|
|
401
401
|
return callback(null, output);
|
|
402
402
|
}
|
|
403
|
+
const parseOptions = {
|
|
404
|
+
...options.parseOptions,
|
|
405
|
+
repl: true
|
|
406
|
+
};
|
|
403
407
|
let ast;
|
|
404
408
|
try {
|
|
405
|
-
ast = await (0, import_main.compile)(input, { ...options, filename, ast: true });
|
|
409
|
+
ast = await (0, import_main.compile)(input, { ...options, parseOptions, filename, ast: true });
|
|
406
410
|
} catch (error) {
|
|
407
411
|
showError2(error);
|
|
408
412
|
return callback(null, void 0);
|
|
409
413
|
}
|
|
410
|
-
const topLevelAwait = import_main.lib.hasAwait(ast) || import_main.lib.hasImportDeclaration(ast);
|
|
411
|
-
if (topLevelAwait) {
|
|
412
|
-
const [prologue, rest] = (0, import_main.parse)(input, {
|
|
413
|
-
startRule: "ProloguePrefix",
|
|
414
|
-
filename: "--civet argument"
|
|
415
|
-
});
|
|
416
|
-
const prefix = input.slice(0, -rest.length);
|
|
417
|
-
const coffee = prologue.some((p) => p.type === "CivetPrologue" && (p.config.coffeeCompat || p.config.coffeeDo));
|
|
418
|
-
ast = await (0, import_main.compile)(
|
|
419
|
-
prefix + (coffee ? "(do ->\n" : "async do\n") + rest.replace(/^/gm, " ") + (coffee ? ")" : ""),
|
|
420
|
-
{ ...options, filename, ast: true }
|
|
421
|
-
);
|
|
422
|
-
import_main.lib.gatherRecursive(ast, ($) => $.type === "BlockStatement").forEach((topBlock) => {
|
|
423
|
-
return import_main.lib.gatherRecursiveWithinFunction(topBlock, ($1) => $1.type === "Declaration").forEach((decl) => {
|
|
424
|
-
const type = decl.children.shift();
|
|
425
|
-
if (!Array.isArray(ast)) {
|
|
426
|
-
ast = [ast];
|
|
427
|
-
}
|
|
428
|
-
return ast.unshift(`var ${decl.names.join(",")};`);
|
|
429
|
-
});
|
|
430
|
-
});
|
|
431
|
-
}
|
|
432
414
|
let errors = [];
|
|
433
415
|
try {
|
|
434
|
-
output = (0, import_main.generate)(ast, { errors });
|
|
416
|
+
output = (0, import_main.generate)(ast, { ...options, errors, sourceMap: void 0 });
|
|
435
417
|
} catch (error) {
|
|
436
418
|
console.error(error);
|
|
437
419
|
return callback(null, void 0);
|
|
438
420
|
}
|
|
439
421
|
if (errors.length) {
|
|
440
422
|
errors = [];
|
|
441
|
-
(0, import_main.generate)(ast, { errors, sourceMap: (0, import_main.SourceMap)(input) });
|
|
423
|
+
(0, import_main.generate)(ast, { ...options, errors, sourceMap: (0, import_main.SourceMap)(input) });
|
|
442
424
|
showError2(errors[0]);
|
|
443
425
|
return callback(null, void 0);
|
|
444
426
|
}
|
|
@@ -451,7 +433,7 @@ ${" ".repeat(error.column - 1)}^ ${error.header}`);
|
|
|
451
433
|
} catch (error) {
|
|
452
434
|
return callback(error, void 0);
|
|
453
435
|
}
|
|
454
|
-
if (topLevelAwait) {
|
|
436
|
+
if (ast.topLevelAwait) {
|
|
455
437
|
let ok = true;
|
|
456
438
|
try {
|
|
457
439
|
return result = await result;
|
|
@@ -546,7 +528,8 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
|
|
|
546
528
|
const unpluginOptions = {
|
|
547
529
|
...options,
|
|
548
530
|
ts: options.js ? "civet" : "preserve",
|
|
549
|
-
outputExtension: ".tsx"
|
|
531
|
+
outputExtension: ".tsx",
|
|
532
|
+
declarationExtension: options.outputExt?.replace(/\.[jt]sx?$/i, ".d.ts")
|
|
550
533
|
};
|
|
551
534
|
(unpluginOptions.parseOptions ??= {}).rewriteCivetImports = ".civet.jsx";
|
|
552
535
|
unplugin = (0, import_unplugin.rawPlugin)(unpluginOptions, { framework: "civet-cli" });
|
|
@@ -559,8 +542,16 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
|
|
|
559
542
|
if (options.repl) {
|
|
560
543
|
return repl(args, options);
|
|
561
544
|
}
|
|
545
|
+
process.stdout.on("error", (e) => {
|
|
546
|
+
if (["EPIPE", "EOF"].includes(e.code)) {
|
|
547
|
+
return process.exit(0);
|
|
548
|
+
} else {
|
|
549
|
+
console.error(e);
|
|
550
|
+
return process.exit(1);
|
|
551
|
+
}
|
|
552
|
+
});
|
|
562
553
|
let errors = 0;
|
|
563
|
-
for await (
|
|
554
|
+
for await (let { filename, error, content, stdin } of readFiles(filenames, options.eval)) {
|
|
564
555
|
if (error) {
|
|
565
556
|
console.error(`${filename} failed to load:`);
|
|
566
557
|
console.error(error);
|
|
@@ -583,14 +574,6 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
|
|
|
583
574
|
errors++;
|
|
584
575
|
continue;
|
|
585
576
|
}
|
|
586
|
-
process.stdout.on("error", (e) => {
|
|
587
|
-
if (["EPIPE", "EOF"].includes(e.code)) {
|
|
588
|
-
return process.exit(0);
|
|
589
|
-
} else {
|
|
590
|
-
console.error(e);
|
|
591
|
-
return process.exit(1);
|
|
592
|
-
}
|
|
593
|
-
});
|
|
594
577
|
if (options.ast) {
|
|
595
578
|
process.stdout.write(JSON.stringify(output, null, 2));
|
|
596
579
|
} else if (options.compile) {
|
|
@@ -626,14 +609,24 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
|
|
|
626
609
|
}
|
|
627
610
|
}
|
|
628
611
|
} else if (options.run) {
|
|
629
|
-
|
|
612
|
+
let ref1;
|
|
613
|
+
{
|
|
614
|
+
if (typeof output === "string" && /\b(await|import|export)\b/.test(output)) {
|
|
615
|
+
const ast = await (0, import_main.compile)(content, { ...options, ast: true, filename });
|
|
616
|
+
ref1 = import_main.lib.hasAwait(ast) || import_main.lib.hasImportDeclaration(ast) || import_main.lib.hasExportDeclaration(ast);
|
|
617
|
+
} else {
|
|
618
|
+
ref1 = void 0;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
;
|
|
622
|
+
const esm = ref1;
|
|
630
623
|
if (esm) {
|
|
631
624
|
if (stdin) {
|
|
632
|
-
|
|
625
|
+
filename = `.stdin-${process.pid}.civet`;
|
|
633
626
|
try {
|
|
634
|
-
await import_promises.default.writeFile(
|
|
627
|
+
await import_promises.default.writeFile(filename, content, { encoding });
|
|
635
628
|
} catch (e) {
|
|
636
|
-
console.error(`Could not write ${
|
|
629
|
+
console.error(`Could not write ${filename} for Civet ESM mode:`);
|
|
637
630
|
console.error(e);
|
|
638
631
|
process.exit(1);
|
|
639
632
|
}
|
|
@@ -706,9 +699,9 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
|
|
|
706
699
|
}
|
|
707
700
|
}, !filenames.length);
|
|
708
701
|
} catch (error) {
|
|
709
|
-
let
|
|
710
|
-
if (
|
|
711
|
-
const match =
|
|
702
|
+
let ref2;
|
|
703
|
+
if (ref2 = error.message.match(/Aborting build because of (\d+) TypeScript diagnostic/)) {
|
|
704
|
+
const match = ref2;
|
|
712
705
|
return process.exitCode = Math.min(255, errors + +match[1]);
|
|
713
706
|
} else {
|
|
714
707
|
process.exitCode = 1;
|