@danielx/civet 0.11.1 → 0.11.3
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 +29 -0
- package/README.md +3 -0
- package/dist/browser.js +402 -234
- package/dist/civet +97 -43
- package/dist/config.js +3 -0
- package/dist/config.mjs +3 -0
- package/dist/main.js +511 -265
- package/dist/main.mjs +511 -265
- package/dist/types.d.ts +4 -0
- package/dist/unplugin/unplugin.js +193 -13
- package/dist/unplugin/unplugin.mjs +200 -13
- package/package.json +6 -2
package/dist/civet
CHANGED
|
@@ -33,6 +33,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
33
33
|
var cli_civet_exports = {};
|
|
34
34
|
__export(cli_civet_exports, {
|
|
35
35
|
cli: () => cli,
|
|
36
|
+
makeOutputFilename: () => makeOutputFilename,
|
|
36
37
|
parseArgs: () => parseArgs,
|
|
37
38
|
repl: () => repl,
|
|
38
39
|
version: () => version
|
|
@@ -287,6 +288,22 @@ async function* readFiles(filenames, evalString) {
|
|
|
287
288
|
}
|
|
288
289
|
}
|
|
289
290
|
}
|
|
291
|
+
function makeOutputFilename(filename, options) {
|
|
292
|
+
let ref1;
|
|
293
|
+
const outputPath = (delete (ref1 = options.outputPath ?? import_node_path.default.parse(filename)).base, // use name and ext
|
|
294
|
+
ref1.ext += // default extension
|
|
295
|
+
options.js ? ".jsx" : ".tsx", (($) => {
|
|
296
|
+
if (options.outputDir != null) {
|
|
297
|
+
$.dir = options.outputDir;
|
|
298
|
+
}
|
|
299
|
+
if (options.outputExt != null) {
|
|
300
|
+
return $.ext = options.outputExt;
|
|
301
|
+
}
|
|
302
|
+
;
|
|
303
|
+
return;
|
|
304
|
+
})(ref1), ref1);
|
|
305
|
+
return import_node_path.default.format(outputPath);
|
|
306
|
+
}
|
|
290
307
|
async function repl(args, options) {
|
|
291
308
|
const vm = await import("node:vm");
|
|
292
309
|
let importModuleDynamically = vm.constants?.USE_MAIN_CONTEXT_DEFAULT_LOADER;
|
|
@@ -326,20 +343,24 @@ async function repl(args, options) {
|
|
|
326
343
|
})()} code.`);
|
|
327
344
|
global.quit = global.exit = () => process.exit(0);
|
|
328
345
|
const nodeRepl = await import("node:repl");
|
|
346
|
+
let ref2;
|
|
347
|
+
switch (false) {
|
|
348
|
+
case !options.ast: {
|
|
349
|
+
ref2 = "\u{1F332}> ";
|
|
350
|
+
break;
|
|
351
|
+
}
|
|
352
|
+
case !options.compile: {
|
|
353
|
+
ref2 = "\u{1F408}> ";
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
default: {
|
|
357
|
+
ref2 = "\u{1F431}> ";
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
;
|
|
361
|
+
const prompt = ref2;
|
|
329
362
|
const r = nodeRepl.start({
|
|
330
|
-
prompt
|
|
331
|
-
switch (false) {
|
|
332
|
-
case !options.ast: {
|
|
333
|
-
return "\u{1F332}> ";
|
|
334
|
-
}
|
|
335
|
-
case !options.compile: {
|
|
336
|
-
return "\u{1F408}> ";
|
|
337
|
-
}
|
|
338
|
-
default: {
|
|
339
|
-
return "\u{1F431}> ";
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
})(),
|
|
363
|
+
prompt,
|
|
343
364
|
writer: (() => {
|
|
344
365
|
if (options.ast) {
|
|
345
366
|
return (obj) => {
|
|
@@ -444,7 +465,32 @@ ${" ".repeat(error.column - 1)}^ ${error.header}`);
|
|
|
444
465
|
}
|
|
445
466
|
}
|
|
446
467
|
});
|
|
447
|
-
|
|
468
|
+
const bufferedCommandSymbol = Object.getOwnPropertySymbols(r).find((symbol) => {
|
|
469
|
+
return symbol.description === "bufferedCommand";
|
|
470
|
+
});
|
|
471
|
+
const interfaceSetPrompt = Object.getPrototypeOf(Object.getPrototypeOf(r))?.setPrompt;
|
|
472
|
+
const writeToOutputSymbol = Object.getOwnPropertySymbols(Object.getPrototypeOf(Object.getPrototypeOf(r))).find((symbol) => {
|
|
473
|
+
return symbol.description === "_writeToOutput";
|
|
474
|
+
});
|
|
475
|
+
if (bufferedCommandSymbol && interfaceSetPrompt && writeToOutputSymbol) {
|
|
476
|
+
const originalWriteToOutput = r[writeToOutputSymbol];
|
|
477
|
+
Object.defineProperty(r, writeToOutputSymbol, {
|
|
478
|
+
value: (text) => {
|
|
479
|
+
return originalWriteToOutput.call(r, text.replace(/(^|\n)\| /g, "$1... "));
|
|
480
|
+
},
|
|
481
|
+
configurable: true,
|
|
482
|
+
writable: true
|
|
483
|
+
});
|
|
484
|
+
return r.displayPrompt = (preserveCursor) => {
|
|
485
|
+
interfaceSetPrompt.call(
|
|
486
|
+
r,
|
|
487
|
+
r[bufferedCommandSymbol]?.length ? "... " : prompt
|
|
488
|
+
);
|
|
489
|
+
return r.prompt(preserveCursor);
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
;
|
|
493
|
+
return;
|
|
448
494
|
}
|
|
449
495
|
async function cli(args = process.argv.slice(2)) {
|
|
450
496
|
let { filenames, scriptArgs, options } = await parseArgs(args);
|
|
@@ -516,6 +562,28 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
|
|
|
516
562
|
}
|
|
517
563
|
}
|
|
518
564
|
if (options.typescript) {
|
|
565
|
+
if (!import_meta.url) {
|
|
566
|
+
try {
|
|
567
|
+
require("typescript");
|
|
568
|
+
} catch {
|
|
569
|
+
const modulePkg = require("node:module");
|
|
570
|
+
let ref3;
|
|
571
|
+
if (ref3 = __dirname.match(/([/\\]@danielx)?[/\\][cC]ivet[/\\]dist[/\\]?$/)) {
|
|
572
|
+
const match = ref3;
|
|
573
|
+
if (match[1]) {
|
|
574
|
+
modulePkg.globalPaths?.push(import_node_path.default.join(__dirname, "..", "..", ".."));
|
|
575
|
+
} else {
|
|
576
|
+
modulePkg.globalPaths?.push(import_node_path.default.join(__dirname, "..", ".."));
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
try {
|
|
580
|
+
require("typescript");
|
|
581
|
+
} catch {
|
|
582
|
+
console.error("Civet could not find TypeScript, which is required for --typecheck or --emit-declaration. Please install typescript using the same package manager you used to install @danielx/civet. With NPM for example: `npm install typescript` if you are local to a project, or `npm install -g typescript` if you installed Civet globally.");
|
|
583
|
+
process.exit(1);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
}
|
|
519
587
|
const unpluginOptions = {
|
|
520
588
|
...options,
|
|
521
589
|
ts: options.js ? "civet" : "preserve",
|
|
@@ -549,6 +617,7 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
|
|
|
549
617
|
errors++;
|
|
550
618
|
continue;
|
|
551
619
|
}
|
|
620
|
+
const outputFilename = makeOutputFilename(filename, options);
|
|
552
621
|
let output;
|
|
553
622
|
try {
|
|
554
623
|
if (unplugin != null) {
|
|
@@ -558,7 +627,7 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
|
|
|
558
627
|
}
|
|
559
628
|
}, `${filename}.tsx`)).code;
|
|
560
629
|
} else {
|
|
561
|
-
output = await (0, import_main.compile)(content, { ...options, filename });
|
|
630
|
+
output = await (0, import_main.compile)(content, { ...options, filename, outputFilename });
|
|
562
631
|
}
|
|
563
632
|
} catch (error2) {
|
|
564
633
|
console.error(error2);
|
|
@@ -571,46 +640,30 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
|
|
|
571
640
|
if (stdin && !options.output || options.output === "-") {
|
|
572
641
|
process.stdout.write(output);
|
|
573
642
|
} else {
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
targetPath.ext += ".jsx";
|
|
578
|
-
} else {
|
|
579
|
-
targetPath.ext += ".tsx";
|
|
580
|
-
}
|
|
581
|
-
if (options.outputDir != null) {
|
|
582
|
-
targetPath.dir = options.outputDir;
|
|
583
|
-
}
|
|
584
|
-
if (options.outputExt != null) {
|
|
585
|
-
targetPath.ext = options.outputExt;
|
|
586
|
-
}
|
|
587
|
-
if (options.outputPath != null) {
|
|
588
|
-
targetPath = options.outputPath;
|
|
589
|
-
}
|
|
590
|
-
if (targetPath.dir) {
|
|
591
|
-
await import_promises.default.mkdir(targetPath.dir, { recursive: true });
|
|
643
|
+
const outputDir = import_node_path.default.dirname(outputFilename);
|
|
644
|
+
if (!(outputDir === ".")) {
|
|
645
|
+
await import_promises.default.mkdir(outputDir, { recursive: true });
|
|
592
646
|
}
|
|
593
|
-
const targetFilename = import_node_path.default.format(targetPath);
|
|
594
647
|
try {
|
|
595
|
-
await import_promises.default.writeFile(
|
|
648
|
+
await import_promises.default.writeFile(outputFilename, output);
|
|
596
649
|
} catch (error2) {
|
|
597
|
-
console.error(`${
|
|
650
|
+
console.error(`${outputFilename} failed to write:`);
|
|
598
651
|
console.error(error2);
|
|
599
652
|
errors++;
|
|
600
653
|
}
|
|
601
654
|
}
|
|
602
655
|
} else if (options.run) {
|
|
603
|
-
let
|
|
656
|
+
let ref4;
|
|
604
657
|
{
|
|
605
658
|
if (typeof output === "string" && /\b(await|import|export)\b/.test(output)) {
|
|
606
659
|
const ast = await (0, import_main.compile)(content, { ...options, ast: true, filename });
|
|
607
|
-
|
|
660
|
+
ref4 = import_main.lib.hasAwait(ast) || import_main.lib.hasImportDeclaration(ast) || import_main.lib.hasExportDeclaration(ast);
|
|
608
661
|
} else {
|
|
609
|
-
|
|
662
|
+
ref4 = void 0;
|
|
610
663
|
}
|
|
611
664
|
}
|
|
612
665
|
;
|
|
613
|
-
const esm =
|
|
666
|
+
const esm = ref4;
|
|
614
667
|
if (esm) {
|
|
615
668
|
if (stdin) {
|
|
616
669
|
filename = `.stdin-${process.pid}.civet`;
|
|
@@ -690,9 +743,9 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
|
|
|
690
743
|
}
|
|
691
744
|
}, !filenames.length);
|
|
692
745
|
} catch (error) {
|
|
693
|
-
let
|
|
694
|
-
if (
|
|
695
|
-
const match =
|
|
746
|
+
let ref5;
|
|
747
|
+
if (ref5 = error.message.match(/Aborting build because of (\d+) TypeScript diagnostic/)) {
|
|
748
|
+
const match = ref5;
|
|
696
749
|
return process.exitCode = Math.min(255, errors + +match[1]);
|
|
697
750
|
} else {
|
|
698
751
|
process.exitCode = 1;
|
|
@@ -706,6 +759,7 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
|
|
|
706
759
|
// Annotate the CommonJS export names for ESM import in node:
|
|
707
760
|
0 && (module.exports = {
|
|
708
761
|
cli,
|
|
762
|
+
makeOutputFilename,
|
|
709
763
|
parseArgs,
|
|
710
764
|
repl,
|
|
711
765
|
version
|
package/dist/config.js
CHANGED
|
@@ -71,6 +71,9 @@ async function findInDir(dirPath) {
|
|
|
71
71
|
const configName = configNames[i];
|
|
72
72
|
for (let i1 = 0, len1 = configExtensions.length; i1 < len1; i1++) {
|
|
73
73
|
const extension = configExtensions[i1];
|
|
74
|
+
if (configName === "package" && (extension === ".civet" || extension === ".js")) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
74
77
|
for (let ref = ["." + configName + extension, configName + extension], i2 = 0, len2 = ref.length; i2 < len2; i2++) {
|
|
75
78
|
const entry = ref[i2];
|
|
76
79
|
if (entries.has(entry) && await (async () => {
|
package/dist/config.mjs
CHANGED
|
@@ -35,6 +35,9 @@ async function findInDir(dirPath) {
|
|
|
35
35
|
const configName = configNames[i];
|
|
36
36
|
for (let i1 = 0, len1 = configExtensions.length; i1 < len1; i1++) {
|
|
37
37
|
const extension = configExtensions[i1];
|
|
38
|
+
if (configName === "package" && (extension === ".civet" || extension === ".js")) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
38
41
|
for (let ref = ["." + configName + extension, configName + extension], i2 = 0, len2 = ref.length; i2 < len2; i2++) {
|
|
39
42
|
const entry = ref[i2];
|
|
40
43
|
if (entries.has(entry) && await (async () => {
|