@danielx/civet 0.11.2 → 0.11.4
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 +24 -0
- package/README.md +3 -0
- package/dist/browser.js +301 -124
- package/dist/civet +91 -35
- package/dist/config.js +3 -0
- package/dist/config.mjs +3 -0
- package/dist/main.js +422 -194
- package/dist/main.mjs +422 -194
- package/dist/unplugin/unplugin.js +176 -3
- package/dist/unplugin/unplugin.mjs +183 -3
- 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,20 +617,7 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
|
|
|
549
617
|
errors++;
|
|
550
618
|
continue;
|
|
551
619
|
}
|
|
552
|
-
|
|
553
|
-
const outputPath = (delete (ref1 = options.outputPath ?? import_node_path.default.parse(filename)).base, // use name and ext
|
|
554
|
-
ref1.ext += // default extension
|
|
555
|
-
options.js ? ".jsx" : ".tsx", (($) => {
|
|
556
|
-
if (options.outputDir != null) {
|
|
557
|
-
$.dir = options.outputDir;
|
|
558
|
-
}
|
|
559
|
-
if (options.outputExt != null) {
|
|
560
|
-
return $.ext = options.outputExt;
|
|
561
|
-
}
|
|
562
|
-
;
|
|
563
|
-
return;
|
|
564
|
-
})(ref1), ref1);
|
|
565
|
-
const outputFilename = import_node_path.default.format(outputPath);
|
|
620
|
+
const outputFilename = makeOutputFilename(filename, options);
|
|
566
621
|
let output;
|
|
567
622
|
try {
|
|
568
623
|
if (unplugin != null) {
|
|
@@ -598,17 +653,17 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
|
|
|
598
653
|
}
|
|
599
654
|
}
|
|
600
655
|
} else if (options.run) {
|
|
601
|
-
let
|
|
656
|
+
let ref4;
|
|
602
657
|
{
|
|
603
658
|
if (typeof output === "string" && /\b(await|import|export)\b/.test(output)) {
|
|
604
659
|
const ast = await (0, import_main.compile)(content, { ...options, ast: true, filename });
|
|
605
|
-
|
|
660
|
+
ref4 = import_main.lib.hasAwait(ast) || import_main.lib.hasImportDeclaration(ast) || import_main.lib.hasExportDeclaration(ast);
|
|
606
661
|
} else {
|
|
607
|
-
|
|
662
|
+
ref4 = void 0;
|
|
608
663
|
}
|
|
609
664
|
}
|
|
610
665
|
;
|
|
611
|
-
const esm =
|
|
666
|
+
const esm = ref4;
|
|
612
667
|
if (esm) {
|
|
613
668
|
if (stdin) {
|
|
614
669
|
filename = `.stdin-${process.pid}.civet`;
|
|
@@ -688,9 +743,9 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
|
|
|
688
743
|
}
|
|
689
744
|
}, !filenames.length);
|
|
690
745
|
} catch (error) {
|
|
691
|
-
let
|
|
692
|
-
if (
|
|
693
|
-
const match =
|
|
746
|
+
let ref5;
|
|
747
|
+
if (ref5 = error.message.match(/Aborting build because of (\d+) TypeScript diagnostic/)) {
|
|
748
|
+
const match = ref5;
|
|
694
749
|
return process.exitCode = Math.min(255, errors + +match[1]);
|
|
695
750
|
} else {
|
|
696
751
|
process.exitCode = 1;
|
|
@@ -704,6 +759,7 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
|
|
|
704
759
|
// Annotate the CommonJS export names for ESM import in node:
|
|
705
760
|
0 && (module.exports = {
|
|
706
761
|
cli,
|
|
762
|
+
makeOutputFilename,
|
|
707
763
|
parseArgs,
|
|
708
764
|
repl,
|
|
709
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 () => {
|