@danielx/civet 0.7.15 → 0.7.17
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/browser.js +14 -11
- package/dist/civet +141 -108
- package/dist/config.d.mts +1 -0
- package/dist/config.d.ts +1 -0
- package/dist/config.mjs +122 -0
- package/dist/esm.mjs +1 -1
- package/dist/main.js +14 -11
- package/dist/main.mjs +14 -11
- package/dist/unplugin/astro.d.ts +11 -0
- package/dist/unplugin/astro.js +49 -0
- package/dist/unplugin/astro.mjs +19 -0
- package/dist/unplugin/esbuild.d.ts +2 -0
- package/dist/unplugin/esbuild.js +36 -0
- package/dist/unplugin/esbuild.mjs +6 -0
- package/dist/unplugin/rollup.d.ts +2 -0
- package/dist/unplugin/rollup.js +36 -0
- package/dist/unplugin/rollup.mjs +6 -0
- package/dist/{unplugin.d.ts → unplugin/unplugin.d.ts} +7 -10
- package/dist/{unplugin.js → unplugin/unplugin.js} +81 -66
- package/dist/{unplugin-shared.mjs → unplugin/unplugin.mjs} +80 -65
- package/dist/unplugin/vite.d.ts +2 -0
- package/dist/unplugin/vite.js +36 -0
- package/dist/unplugin/vite.mjs +6 -0
- package/dist/unplugin/webpack.d.ts +2 -0
- package/dist/unplugin/webpack.js +36 -0
- package/dist/unplugin/webpack.mjs +6 -0
- package/package.json +27 -17
- package/dist/astro.d.mts +0 -16
- package/dist/astro.d.ts +0 -16
- package/dist/astro.js +0 -537
- package/dist/astro.mjs +0 -22
- package/dist/esbuild.d.mts +0 -8
- package/dist/esbuild.d.ts +0 -8
- package/dist/esbuild.js +0 -524
- package/dist/esbuild.mjs +0 -9
- package/dist/rollup.d.mts +0 -8
- package/dist/rollup.d.ts +0 -8
- package/dist/rollup.js +0 -524
- package/dist/rollup.mjs +0 -9
- package/dist/unplugin.d.mts +0 -26
- package/dist/unplugin.mjs +0 -10
- package/dist/vite.d.mts +0 -8
- package/dist/vite.d.ts +0 -8
- package/dist/vite.js +0 -524
- package/dist/vite.mjs +0 -9
- package/dist/webpack.d.mts +0 -7
- package/dist/webpack.d.ts +0 -7
- package/dist/webpack.js +0 -524
- package/dist/webpack.mjs +0 -9
package/dist/browser.js
CHANGED
|
@@ -38,9 +38,9 @@ var Civet = (() => {
|
|
|
38
38
|
));
|
|
39
39
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
40
40
|
|
|
41
|
-
//
|
|
41
|
+
// ../Hera/dist/machine.js
|
|
42
42
|
var require_machine = __commonJS({
|
|
43
|
-
"
|
|
43
|
+
"../Hera/dist/machine.js"(exports, module) {
|
|
44
44
|
"use strict";
|
|
45
45
|
var __defProp2 = Object.defineProperty;
|
|
46
46
|
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
@@ -7108,8 +7108,8 @@ ${js}`
|
|
|
7108
7108
|
var $L61 = (0, import_lib3.$L)("?=");
|
|
7109
7109
|
var $L62 = (0, import_lib3.$L)("and=");
|
|
7110
7110
|
var $L63 = (0, import_lib3.$L)("or=");
|
|
7111
|
-
var $L64 = (0, import_lib3.$L)("
|
|
7112
|
-
var $L65 = (0, import_lib3.$L)("
|
|
7111
|
+
var $L64 = (0, import_lib3.$L)("*");
|
|
7112
|
+
var $L65 = (0, import_lib3.$L)("**");
|
|
7113
7113
|
var $L66 = (0, import_lib3.$L)("/");
|
|
7114
7114
|
var $L67 = (0, import_lib3.$L)("%%");
|
|
7115
7115
|
var $L68 = (0, import_lib3.$L)("%");
|
|
@@ -8147,13 +8147,15 @@ ${js}`
|
|
|
8147
8147
|
function TernaryRest(ctx, state2) {
|
|
8148
8148
|
return (0, import_lib3.$EVENT_C)(ctx, state2, "TernaryRest", TernaryRest$$);
|
|
8149
8149
|
}
|
|
8150
|
-
var NestedTernaryRest$0 = (0, import_lib3.$
|
|
8150
|
+
var NestedTernaryRest$0 = (0, import_lib3.$S)(Nested, QuestionMark, MaybeNestedExtendedExpression, Nested, Colon, MaybeNestedExtendedExpression);
|
|
8151
|
+
var NestedTernaryRest$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(PushIndent, (0, import_lib3.$E)((0, import_lib3.$S)(Nested, QuestionMark, MaybeNestedExtendedExpression, Nested, Colon, MaybeNestedExtendedExpression)), PopIndent), function($skip, $loc, $0, $1, $2, $3) {
|
|
8151
8152
|
if ($2)
|
|
8152
8153
|
return $2;
|
|
8153
8154
|
return $skip;
|
|
8154
8155
|
});
|
|
8156
|
+
var NestedTernaryRest$$ = [NestedTernaryRest$0, NestedTernaryRest$1];
|
|
8155
8157
|
function NestedTernaryRest(ctx, state2) {
|
|
8156
|
-
return (0, import_lib3.$
|
|
8158
|
+
return (0, import_lib3.$EVENT_C)(ctx, state2, "NestedTernaryRest", NestedTernaryRest$$);
|
|
8157
8159
|
}
|
|
8158
8160
|
var ShortCircuitExpression$0 = BinaryOpExpression;
|
|
8159
8161
|
function ShortCircuitExpression(ctx, state2) {
|
|
@@ -11501,11 +11503,12 @@ ${js}`
|
|
|
11501
11503
|
ws.push(...$2);
|
|
11502
11504
|
return [ws, $3];
|
|
11503
11505
|
});
|
|
11504
|
-
var NotDedentedBinaryOp$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(Nested, (0, import_lib3.$E)(_), (0, import_lib3.$N)(Identifier), BinaryOp), function($skip, $loc, $0, $1, $2, $3, $4) {
|
|
11506
|
+
var NotDedentedBinaryOp$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(Nested, (0, import_lib3.$E)(_), (0, import_lib3.$N)(Identifier), (0, import_lib3.$C)((0, import_lib3.$N)((0, import_lib3.$EXPECT)($L64, 'NotDedentedBinaryOp "*"')), (0, import_lib3.$N)(ImportDeclaration)), BinaryOp), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
|
|
11507
|
+
var op = $5;
|
|
11505
11508
|
const ws = [...$1];
|
|
11506
11509
|
if ($2)
|
|
11507
11510
|
ws.push(...$2);
|
|
11508
|
-
return [ws,
|
|
11511
|
+
return [ws, op];
|
|
11509
11512
|
});
|
|
11510
11513
|
var NotDedentedBinaryOp$$ = [NotDedentedBinaryOp$0, NotDedentedBinaryOp$1];
|
|
11511
11514
|
function NotDedentedBinaryOp(ctx, state2) {
|
|
@@ -11559,8 +11562,8 @@ ${js}`
|
|
|
11559
11562
|
function _BinaryOp(ctx, state2) {
|
|
11560
11563
|
return (0, import_lib3.$EVENT_C)(ctx, state2, "_BinaryOp", _BinaryOp$$);
|
|
11561
11564
|
}
|
|
11562
|
-
var BinaryOpSymbol$0 = (0, import_lib3.$EXPECT)($
|
|
11563
|
-
var BinaryOpSymbol$1 = (0, import_lib3.$EXPECT)($
|
|
11565
|
+
var BinaryOpSymbol$0 = (0, import_lib3.$EXPECT)($L65, 'BinaryOpSymbol "**"');
|
|
11566
|
+
var BinaryOpSymbol$1 = (0, import_lib3.$EXPECT)($L64, 'BinaryOpSymbol "*"');
|
|
11564
11567
|
var BinaryOpSymbol$2 = (0, import_lib3.$EXPECT)($L66, 'BinaryOpSymbol "/"');
|
|
11565
11568
|
var BinaryOpSymbol$3 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L67, 'BinaryOpSymbol "%%"'), function($skip, $loc, $0, $1) {
|
|
11566
11569
|
return {
|
|
@@ -14495,7 +14498,7 @@ ${js}`
|
|
|
14495
14498
|
function SingleQuote(ctx, state2) {
|
|
14496
14499
|
return (0, import_lib3.$EVENT)(ctx, state2, "SingleQuote", SingleQuote$0);
|
|
14497
14500
|
}
|
|
14498
|
-
var Star$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($
|
|
14501
|
+
var Star$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L64, 'Star "*"'), function($skip, $loc, $0, $1) {
|
|
14499
14502
|
return { $loc, token: $1 };
|
|
14500
14503
|
});
|
|
14501
14504
|
function Star(ctx, state2) {
|
package/dist/civet
CHANGED
|
@@ -39,68 +39,34 @@ __export(cli_exports, {
|
|
|
39
39
|
module.exports = __toCommonJS(cli_exports);
|
|
40
40
|
var import_main = require("./main.js");
|
|
41
41
|
var import_config = require("./config.js");
|
|
42
|
-
var import_unplugin = require("./unplugin");
|
|
42
|
+
var import_unplugin = require("./unplugin/unplugin.js");
|
|
43
43
|
var import_promises = __toESM(require("node:fs/promises"));
|
|
44
44
|
var import_node_path = __toESM(require("node:path"));
|
|
45
|
+
var import_meta = {};
|
|
45
46
|
var unplugin;
|
|
46
|
-
function version() {
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
if (process.argv.some((a1) => a1 === "--help" || a1 === "-help" || a1 === "-h")) {
|
|
54
|
-
process.stderr.write(` \u2584\u2584\xB7 \u25AA \u258C \u2590\xB7\u2584\u2584\u2584 .\u2584\u2584\u2584\u2584\u2584
|
|
55
|
-
\u2590\u2588 \u258C\u25AA\u2588\u2588 \u25AA\u2588\xB7\u2588\u258C\u2580\u2584.\u2580\xB7\u2022\u2588\u2588 _._ _,-'""\`-._
|
|
56
|
-
\u2588\u2588 \u2584\u2584\u2590\u2588\xB7\u2590\u2588\u2590\u2588\u2022\u2590\u2580\u2580\u25AA\u2584 \u2590\u2588.\u25AA (,-.\`._,'( |\\\`-/|
|
|
57
|
-
\u2590\u2588\u2588\u2588\u258C\u2590\u2588\u258C \u2588\u2588\u2588 \u2590\u2588\u2584\u2584\u258C \u2590\u2588\u258C\xB7 \`-.-' \\ )-\`( , o o)
|
|
58
|
-
\xB7\u2580\u2580\u2580 \u2580\u2580\u2580. \u2580 \u2580\u2580\u2580 \u2580\u2580\u2580 \`- \\\`_\`"'-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
Usage:
|
|
62
|
-
|
|
63
|
-
civet # REPL for executing code
|
|
64
|
-
civet -c # REPL for transpiling code
|
|
65
|
-
civet --ast # REPL for parsing code
|
|
66
|
-
civet [options] input.civet # run input.civet
|
|
67
|
-
civet [options] -c input.civet # -> input.civet.tsx
|
|
68
|
-
civet [options] -c input.civet -o .ts # -> input.ts
|
|
69
|
-
civet [options] -c input.civet -o dir # -> dir/input.civet.tsx
|
|
70
|
-
civet [options] -c input.civet -o dir/.ts # -> dir/input.ts
|
|
71
|
-
civet [options] -c input.civet -o output.ts # -> output.ts
|
|
72
|
-
civet [options] < input.civet > output.ts # pipe form
|
|
73
|
-
|
|
74
|
-
Options:
|
|
75
|
-
--help Show this help message
|
|
76
|
-
--version Show the version number
|
|
77
|
-
-o / --output XX Specify output directory and/or extension, or filename
|
|
78
|
-
-c / --compile Compile input files to TypeScript (or JavaScript)
|
|
79
|
-
--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 .)
|
|
80
|
-
--civet XX Specify civet compiler flag, as in "civet XX" prologue
|
|
81
|
-
--comptime Enable execution of code during compilation via comptime
|
|
82
|
-
--no-config Don't scan for a config file
|
|
83
|
-
--js Strip out all type annotations; default to .jsx extension
|
|
84
|
-
--ast Print the AST instead of the compiled code
|
|
85
|
-
--inline-map Generate a sourcemap
|
|
86
|
-
--no-cache Disable compiler caching (slow, for debugging)
|
|
87
|
-
--typecheck Run TypeScript and output diagnostics
|
|
88
|
-
--emit-declaration Run TypeScript and emit .d.ts files (if no errors)
|
|
89
|
-
|
|
90
|
-
You can use - to read from stdin or (prefixed by -o) write to stdout.
|
|
91
|
-
|
|
92
|
-
By default, .civet imports get rewritten to use the output extension.
|
|
93
|
-
You can override this behavior via: --civet rewriteCivetImports=.ext
|
|
94
|
-
|
|
95
|
-
`);
|
|
96
|
-
process.exit(0);
|
|
47
|
+
async function version() {
|
|
48
|
+
if (import_meta.url) {
|
|
49
|
+
const { createRequire } = await import("node:module");
|
|
50
|
+
return createRequire(import_meta.url)("../package.json").version;
|
|
51
|
+
} else {
|
|
52
|
+
return require("../package.json").version;
|
|
53
|
+
}
|
|
97
54
|
}
|
|
98
55
|
var encoding = "utf8";
|
|
99
|
-
function parseArgs(args) {
|
|
56
|
+
async function parseArgs(args, isTTY = process.stdin.isTTY) {
|
|
100
57
|
const options = {};
|
|
101
58
|
const isRun = () => !(options.ast || options.compile || options.typecheck || options.emitDeclaration);
|
|
102
|
-
|
|
59
|
+
let filenames = [];
|
|
103
60
|
let scriptArgs = [];
|
|
61
|
+
if (args.includes("-version")) {
|
|
62
|
+
options.version = true;
|
|
63
|
+
}
|
|
64
|
+
if (args.includes("-help")) {
|
|
65
|
+
options.help = true;
|
|
66
|
+
}
|
|
67
|
+
if (options.version || options.help) {
|
|
68
|
+
return { filenames, scriptArgs, options };
|
|
69
|
+
}
|
|
104
70
|
let i = 0;
|
|
105
71
|
let errors = 0;
|
|
106
72
|
function endOfArgs(j) {
|
|
@@ -128,6 +94,16 @@ function parseArgs(args) {
|
|
|
128
94
|
continue;
|
|
129
95
|
}
|
|
130
96
|
switch (arg) {
|
|
97
|
+
case "-v":
|
|
98
|
+
case "--version": {
|
|
99
|
+
options.version = true;
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
case "-h":
|
|
103
|
+
case "--help": {
|
|
104
|
+
options.help = true;
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
131
107
|
case "-c":
|
|
132
108
|
case "--compile": {
|
|
133
109
|
options.compile = true;
|
|
@@ -150,7 +126,13 @@ function parseArgs(args) {
|
|
|
150
126
|
Object.assign(
|
|
151
127
|
options.parseOptions ??= {},
|
|
152
128
|
(0, import_main.parse)(`civet ${args[++i]}`, {
|
|
153
|
-
startRule: "CivetPrologueContent"
|
|
129
|
+
startRule: "CivetPrologueContent",
|
|
130
|
+
filename: "--civet argument",
|
|
131
|
+
events: {
|
|
132
|
+
// remove cache in case we've compiled Civet before
|
|
133
|
+
enter: void 0,
|
|
134
|
+
exit: void 0
|
|
135
|
+
}
|
|
154
136
|
}).config
|
|
155
137
|
);
|
|
156
138
|
break;
|
|
@@ -213,6 +195,40 @@ function parseArgs(args) {
|
|
|
213
195
|
}
|
|
214
196
|
i++;
|
|
215
197
|
}
|
|
198
|
+
if (options.typecheck || options.emitDeclaration) {
|
|
199
|
+
options.typescript = true;
|
|
200
|
+
}
|
|
201
|
+
if (!(filenames.length || options.typescript)) {
|
|
202
|
+
if (isTTY) {
|
|
203
|
+
options.repl = true;
|
|
204
|
+
} else {
|
|
205
|
+
options.compile = true;
|
|
206
|
+
options.run = false;
|
|
207
|
+
filenames = ["-"];
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
if (options.output && options.output !== "-") {
|
|
211
|
+
const optionsPath = import_node_path.default.parse(options.output);
|
|
212
|
+
let stat;
|
|
213
|
+
try {
|
|
214
|
+
stat = await import_promises.default.stat(options.output);
|
|
215
|
+
} catch {
|
|
216
|
+
stat = null;
|
|
217
|
+
}
|
|
218
|
+
if (stat?.isDirectory() || options.output.endsWith(import_node_path.default.sep) || options.output.endsWith("/")) {
|
|
219
|
+
options.outputDir = options.output;
|
|
220
|
+
} else if (/^(\.[^]+)+$/.test(optionsPath.base)) {
|
|
221
|
+
options.outputExt = optionsPath.base;
|
|
222
|
+
if (optionsPath.dir) {
|
|
223
|
+
options.outputDir = optionsPath.dir;
|
|
224
|
+
}
|
|
225
|
+
} else {
|
|
226
|
+
options.outputPath = optionsPath;
|
|
227
|
+
options.outputExt = optionsPath.ext;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
;
|
|
231
|
+
(options.parseOptions ??= {}).rewriteCivetImports ??= options.outputExt ?? ".civet.jsx";
|
|
216
232
|
if (errors) {
|
|
217
233
|
process.exit(Math.min(255, errors));
|
|
218
234
|
}
|
|
@@ -265,7 +281,7 @@ async function* readFiles(filenames) {
|
|
|
265
281
|
;
|
|
266
282
|
return results1;
|
|
267
283
|
}
|
|
268
|
-
async function repl(options) {
|
|
284
|
+
async function repl(args, options) {
|
|
269
285
|
const vm = await import("node:vm");
|
|
270
286
|
let importModuleDynamically = vm.constants?.USE_MAIN_CONTEXT_DEFAULT_LOADER;
|
|
271
287
|
if (!importModuleDynamically) {
|
|
@@ -284,15 +300,15 @@ async function repl(options) {
|
|
|
284
300
|
execArgv.push(process.env.NODE_OPTIONS);
|
|
285
301
|
}
|
|
286
302
|
const { fork } = await import("node:child_process");
|
|
287
|
-
fork(__filename,
|
|
303
|
+
fork(__filename, args, {
|
|
288
304
|
execArgv,
|
|
289
305
|
stdio: "inherit"
|
|
290
306
|
});
|
|
291
307
|
return;
|
|
292
308
|
}
|
|
293
309
|
}
|
|
294
|
-
|
|
295
|
-
console.log(`Civet ${version()} REPL. Enter a blank line to ${(() => {
|
|
310
|
+
await import("../register.js");
|
|
311
|
+
console.log(`Civet ${await version()} REPL. Enter a blank line to ${(() => {
|
|
296
312
|
switch (false) {
|
|
297
313
|
case !options.ast: {
|
|
298
314
|
return "parse";
|
|
@@ -381,7 +397,10 @@ ${" ".repeat(error.column - 1)}^ ${error.header}`);
|
|
|
381
397
|
}
|
|
382
398
|
const topLevelAwait = import_main.lib.hasAwait(ast) || import_main.lib.hasImportDeclaration(ast);
|
|
383
399
|
if (topLevelAwait) {
|
|
384
|
-
const [prologue, rest] = (0, import_main.parse)(input, {
|
|
400
|
+
const [prologue, rest] = (0, import_main.parse)(input, {
|
|
401
|
+
startRule: "ProloguePrefix",
|
|
402
|
+
filename: "--civet argument"
|
|
403
|
+
});
|
|
385
404
|
const prefix = input.slice(0, -rest.length);
|
|
386
405
|
const coffee = prologue.some((p) => p.type === "CivetPrologue" && (p.config.coffeeCompat || p.config.coffeeDo));
|
|
387
406
|
ast = await (0, import_main.compile)(
|
|
@@ -442,9 +461,57 @@ ${" ".repeat(error.column - 1)}^ ${error.header}`);
|
|
|
442
461
|
});
|
|
443
462
|
return r;
|
|
444
463
|
}
|
|
445
|
-
async function cli() {
|
|
446
|
-
|
|
447
|
-
|
|
464
|
+
async function cli(args = process.argv.slice(2)) {
|
|
465
|
+
let { filenames, scriptArgs, options } = await parseArgs(args);
|
|
466
|
+
if (options.version) {
|
|
467
|
+
console.log(await version());
|
|
468
|
+
process.exit(0);
|
|
469
|
+
}
|
|
470
|
+
if (options.help) {
|
|
471
|
+
process.stderr.write(` \u2584\u2584\xB7 \u25AA \u258C \u2590\xB7\u2584\u2584\u2584 .\u2584\u2584\u2584\u2584\u2584
|
|
472
|
+
\u2590\u2588 \u258C\u25AA\u2588\u2588 \u25AA\u2588\xB7\u2588\u258C\u2580\u2584.\u2580\xB7\u2022\u2588\u2588 _._ _,-'""\`-._
|
|
473
|
+
\u2588\u2588 \u2584\u2584\u2590\u2588\xB7\u2590\u2588\u2590\u2588\u2022\u2590\u2580\u2580\u25AA\u2584 \u2590\u2588.\u25AA (,-.\`._,'( |\\\`-/|
|
|
474
|
+
\u2590\u2588\u2588\u2588\u258C\u2590\u2588\u258C \u2588\u2588\u2588 \u2590\u2588\u2584\u2584\u258C \u2590\u2588\u258C\xB7 \`-.-' \\ )-\`( , o o)
|
|
475
|
+
\xB7\u2580\u2580\u2580 \u2580\u2580\u2580. \u2580 \u2580\u2580\u2580 \u2580\u2580\u2580 \`- \\\`_\`"'-
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
Usage:
|
|
479
|
+
|
|
480
|
+
civet # REPL for executing code
|
|
481
|
+
civet -c # REPL for transpiling code
|
|
482
|
+
civet --ast # REPL for parsing code
|
|
483
|
+
civet [options] input.civet # run input.civet
|
|
484
|
+
civet [options] -c input.civet # -> input.civet.tsx
|
|
485
|
+
civet [options] -c input.civet -o .ts # -> input.ts
|
|
486
|
+
civet [options] -c input.civet -o dir # -> dir/input.civet.tsx
|
|
487
|
+
civet [options] -c input.civet -o dir/.ts # -> dir/input.ts
|
|
488
|
+
civet [options] -c input.civet -o output.ts # -> output.ts
|
|
489
|
+
civet [options] < input.civet > output.ts # pipe form
|
|
490
|
+
|
|
491
|
+
Options:
|
|
492
|
+
--help Show this help message
|
|
493
|
+
--version Show the version number
|
|
494
|
+
-o / --output XX Specify output directory and/or extension, or filename
|
|
495
|
+
-c / --compile Compile input files to TypeScript (or JavaScript)
|
|
496
|
+
--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
|
+
--civet XX Specify civet compiler flag, as in "civet XX" prologue
|
|
498
|
+
--comptime Enable execution of code during compilation via comptime
|
|
499
|
+
--no-config Don't scan for a config file
|
|
500
|
+
--js Strip out all type annotations; default to .jsx extension
|
|
501
|
+
--ast Print the AST instead of the compiled code
|
|
502
|
+
--inline-map Generate a sourcemap
|
|
503
|
+
--no-cache Disable compiler caching (slow, for debugging)
|
|
504
|
+
--typecheck Run TypeScript and output diagnostics
|
|
505
|
+
--emit-declaration Run TypeScript and emit .d.ts files (if no errors)
|
|
506
|
+
|
|
507
|
+
You can use - to read from stdin or (prefixed by -o) write to stdout.
|
|
508
|
+
|
|
509
|
+
By default, .civet imports get rewritten to use the output extension.
|
|
510
|
+
You can override this behavior via: --civet rewriteCivetImports=.ext
|
|
511
|
+
|
|
512
|
+
`);
|
|
513
|
+
process.exit(0);
|
|
514
|
+
}
|
|
448
515
|
if (options.config !== false) {
|
|
449
516
|
options.config ??= await (0, import_config.findConfig)(process.cwd());
|
|
450
517
|
}
|
|
@@ -454,16 +521,7 @@ async function cli() {
|
|
|
454
521
|
...options
|
|
455
522
|
};
|
|
456
523
|
}
|
|
457
|
-
|
|
458
|
-
if (!(filenames.length || typescript)) {
|
|
459
|
-
if (process.stdin.isTTY) {
|
|
460
|
-
options.repl = true;
|
|
461
|
-
} else {
|
|
462
|
-
options.compile = true;
|
|
463
|
-
filenames = ["-"];
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
if (typescript) {
|
|
524
|
+
if (options.typescript) {
|
|
467
525
|
const unpluginOptions = {
|
|
468
526
|
...options,
|
|
469
527
|
ts: options.js ? "civet" : "preserve",
|
|
@@ -478,30 +536,7 @@ async function cli() {
|
|
|
478
536
|
options.inlineMap = true;
|
|
479
537
|
}
|
|
480
538
|
if (options.repl) {
|
|
481
|
-
return repl(options);
|
|
482
|
-
}
|
|
483
|
-
let outputDir, outputExt, outputPath;
|
|
484
|
-
if (options.output) {
|
|
485
|
-
const optionsPath = import_node_path.default.parse(options.output);
|
|
486
|
-
let stat;
|
|
487
|
-
try {
|
|
488
|
-
stat = await import_promises.default.stat(options.output);
|
|
489
|
-
} catch {
|
|
490
|
-
stat = null;
|
|
491
|
-
}
|
|
492
|
-
if (stat?.isDirectory() || options.output.endsWith(import_node_path.default.sep) || options.output.endsWith("/")) {
|
|
493
|
-
outputDir = options.output;
|
|
494
|
-
} else if (/^(\.[^.]+)+$/.test(optionsPath.base)) {
|
|
495
|
-
outputExt = optionsPath.base;
|
|
496
|
-
if (optionsPath.dir) {
|
|
497
|
-
outputDir = optionsPath.dir;
|
|
498
|
-
}
|
|
499
|
-
} else {
|
|
500
|
-
outputPath = optionsPath;
|
|
501
|
-
}
|
|
502
|
-
if (options.output !== "-") {
|
|
503
|
-
(options.parseOptions ??= {}).rewriteCivetImports ??= outputExt ?? ".civet" + (options.js ? ".jsx" : ".tsx");
|
|
504
|
-
}
|
|
539
|
+
return repl(args, options);
|
|
505
540
|
}
|
|
506
541
|
let errors = 0;
|
|
507
542
|
for await (const { filename, error, content, stdin } of readFiles(filenames)) {
|
|
@@ -548,14 +583,14 @@ async function cli() {
|
|
|
548
583
|
} else {
|
|
549
584
|
targetPath.ext += ".tsx";
|
|
550
585
|
}
|
|
551
|
-
if (outputDir != null) {
|
|
552
|
-
targetPath.dir = outputDir;
|
|
586
|
+
if (options.outputDir != null) {
|
|
587
|
+
targetPath.dir = options.outputDir;
|
|
553
588
|
}
|
|
554
|
-
if (outputExt != null) {
|
|
555
|
-
targetPath.ext = outputExt;
|
|
589
|
+
if (options.outputExt != null) {
|
|
590
|
+
targetPath.ext = options.outputExt;
|
|
556
591
|
}
|
|
557
|
-
if (outputPath != null) {
|
|
558
|
-
targetPath = outputPath;
|
|
592
|
+
if (options.outputPath != null) {
|
|
593
|
+
targetPath = options.outputPath;
|
|
559
594
|
}
|
|
560
595
|
if (targetPath.dir) {
|
|
561
596
|
await import_promises.default.mkdir(targetPath.dir, { recursive: true });
|
|
@@ -618,14 +653,14 @@ async function cli() {
|
|
|
618
653
|
return process.exit(code ?? 1);
|
|
619
654
|
});
|
|
620
655
|
} else {
|
|
621
|
-
|
|
656
|
+
await import("../register.js");
|
|
622
657
|
try {
|
|
623
658
|
module.filename = await import_promises.default.realpath(filename);
|
|
624
659
|
} catch {
|
|
625
660
|
module.filename = filename;
|
|
626
661
|
}
|
|
627
662
|
process.argv = ["civet", module.filename, ...scriptArgs];
|
|
628
|
-
module.paths =
|
|
663
|
+
module.paths = (await import("node:module"))._nodeModulePaths(import_node_path.default.dirname(module.filename));
|
|
629
664
|
try {
|
|
630
665
|
module._compile(output, module.filename);
|
|
631
666
|
} catch (error2) {
|
|
@@ -658,9 +693,6 @@ async function cli() {
|
|
|
658
693
|
;
|
|
659
694
|
return;
|
|
660
695
|
}
|
|
661
|
-
if (require.main === module) {
|
|
662
|
-
cli();
|
|
663
|
-
}
|
|
664
696
|
// Annotate the CommonJS export names for ESM import in node:
|
|
665
697
|
0 && (module.exports = {
|
|
666
698
|
cli,
|
|
@@ -668,3 +700,4 @@ if (require.main === module) {
|
|
|
668
700
|
repl,
|
|
669
701
|
version
|
|
670
702
|
});
|
|
703
|
+
cli()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference path="./types.d.ts" />
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference path="./types.d.ts" />
|
package/dist/config.mjs
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// source/config.civet
|
|
2
|
+
import path from "path";
|
|
3
|
+
import fs from "fs/promises";
|
|
4
|
+
import { compile } from "./main.mjs";
|
|
5
|
+
var configNames = [
|
|
6
|
+
"\u{1F408}",
|
|
7
|
+
"civetconfig",
|
|
8
|
+
"civet.config",
|
|
9
|
+
"package"
|
|
10
|
+
];
|
|
11
|
+
var configExtensions = [
|
|
12
|
+
".civet",
|
|
13
|
+
".js",
|
|
14
|
+
".yaml",
|
|
15
|
+
".yml",
|
|
16
|
+
".json"
|
|
17
|
+
];
|
|
18
|
+
var configDir = ".config";
|
|
19
|
+
async function findInDir(dirPath) {
|
|
20
|
+
const entries = new Set(await fs.readdir(dirPath));
|
|
21
|
+
const pathFor = (name) => path.join(dirPath, name);
|
|
22
|
+
if (entries.has(configDir) && await (async () => {
|
|
23
|
+
try {
|
|
24
|
+
return (await fs.stat(pathFor(configDir))).isDirectory();
|
|
25
|
+
} catch (e) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
})()) {
|
|
29
|
+
const found = await findInDir(pathFor(configDir));
|
|
30
|
+
if (found) {
|
|
31
|
+
return found;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
for (let i = 0, len = configNames.length; i < len; i++) {
|
|
35
|
+
const configName = configNames[i];
|
|
36
|
+
for (let i1 = 0, len1 = configExtensions.length; i1 < len1; i1++) {
|
|
37
|
+
const extension = configExtensions[i1];
|
|
38
|
+
for (let ref = ["." + configName + extension, configName + extension], i2 = 0, len2 = ref.length; i2 < len2; i2++) {
|
|
39
|
+
const entry = ref[i2];
|
|
40
|
+
if (entries.has(entry) && await (async () => {
|
|
41
|
+
try {
|
|
42
|
+
return (await fs.stat(pathFor(entry))).isFile();
|
|
43
|
+
} catch (e) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
})()) {
|
|
47
|
+
return pathFor(entry);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
async function findConfig(startDir) {
|
|
55
|
+
let curr = startDir;
|
|
56
|
+
let parent = path.dirname(curr);
|
|
57
|
+
while (curr !== parent) {
|
|
58
|
+
const configPath = await findInDir(curr);
|
|
59
|
+
if (configPath) {
|
|
60
|
+
return configPath;
|
|
61
|
+
}
|
|
62
|
+
curr = parent;
|
|
63
|
+
parent = path.dirname(curr);
|
|
64
|
+
}
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
async function loadConfig(pathname) {
|
|
68
|
+
const config = await fs.readFile(pathname, "utf8");
|
|
69
|
+
let data = {};
|
|
70
|
+
if (pathname.endsWith(".json")) {
|
|
71
|
+
let json;
|
|
72
|
+
try {
|
|
73
|
+
json = JSON.parse(config);
|
|
74
|
+
} catch (e) {
|
|
75
|
+
throw new Error(`Error parsing JSON config file ${pathname}: ${e}`);
|
|
76
|
+
}
|
|
77
|
+
if ("civetConfig" in json) {
|
|
78
|
+
data = json.civetConfig;
|
|
79
|
+
} else if (path.basename(pathname).startsWith("package")) {
|
|
80
|
+
return {};
|
|
81
|
+
} else {
|
|
82
|
+
data = json;
|
|
83
|
+
}
|
|
84
|
+
} else if (/\.ya?ml$/.test(pathname)) {
|
|
85
|
+
try {
|
|
86
|
+
const { default: YAML } = await import("yaml");
|
|
87
|
+
const yaml = YAML.parse(config);
|
|
88
|
+
data = yaml.civetConfig ?? yaml;
|
|
89
|
+
} catch (e) {
|
|
90
|
+
throw new Error(`Error parsing YAML config file ${pathname}: ${e}`);
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
let js;
|
|
94
|
+
if (pathname.endsWith(".civet")) {
|
|
95
|
+
try {
|
|
96
|
+
js = await compile(config, {
|
|
97
|
+
js: true
|
|
98
|
+
});
|
|
99
|
+
} catch (e) {
|
|
100
|
+
throw new Error(`Error compiling Civet config file ${pathname}: ${e}`);
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
js = config;
|
|
104
|
+
}
|
|
105
|
+
try {
|
|
106
|
+
const exports = await import(`data:text/javascript,${encodeURIComponent(js)}`);
|
|
107
|
+
data = exports?.default;
|
|
108
|
+
} catch (e) {
|
|
109
|
+
throw new Error(`Error running Civet config file ${pathname}: ${e}`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
if (!(data != null && typeof data === "object" && !Array.isArray(data))) {
|
|
113
|
+
throw new Error(`Civet config file must export an object, not ${Array.isArray(data) ? "array" : data != null ? typeof data : "null"}`);
|
|
114
|
+
}
|
|
115
|
+
delete data?.parseOptions?.comptime;
|
|
116
|
+
return data;
|
|
117
|
+
}
|
|
118
|
+
export {
|
|
119
|
+
findConfig,
|
|
120
|
+
findInDir,
|
|
121
|
+
loadConfig
|
|
122
|
+
};
|
package/dist/esm.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// source/esm.civet
|
|
2
2
|
import { readFileSync } from "fs";
|
|
3
3
|
import { pathToFileURL, fileURLToPath } from "url";
|
|
4
|
-
import Civet from "./main.
|
|
4
|
+
import Civet from "./main.mjs";
|
|
5
5
|
var { compile, SourceMap } = Civet;
|
|
6
6
|
var baseURL = pathToFileURL(process.cwd() + "/").href;
|
|
7
7
|
var extensionsRegex = /\.civet$/;
|
package/dist/main.js
CHANGED
|
@@ -30,9 +30,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
));
|
|
31
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
32
|
|
|
33
|
-
//
|
|
33
|
+
// ../Hera/dist/machine.js
|
|
34
34
|
var require_machine = __commonJS({
|
|
35
|
-
"
|
|
35
|
+
"../Hera/dist/machine.js"(exports2, module2) {
|
|
36
36
|
"use strict";
|
|
37
37
|
var __defProp2 = Object.defineProperty;
|
|
38
38
|
var __getOwnPropDesc2 = Object.getOwnPropertyDescriptor;
|
|
@@ -7086,8 +7086,8 @@ var $L60 = (0, import_lib3.$L)("??=");
|
|
|
7086
7086
|
var $L61 = (0, import_lib3.$L)("?=");
|
|
7087
7087
|
var $L62 = (0, import_lib3.$L)("and=");
|
|
7088
7088
|
var $L63 = (0, import_lib3.$L)("or=");
|
|
7089
|
-
var $L64 = (0, import_lib3.$L)("
|
|
7090
|
-
var $L65 = (0, import_lib3.$L)("
|
|
7089
|
+
var $L64 = (0, import_lib3.$L)("*");
|
|
7090
|
+
var $L65 = (0, import_lib3.$L)("**");
|
|
7091
7091
|
var $L66 = (0, import_lib3.$L)("/");
|
|
7092
7092
|
var $L67 = (0, import_lib3.$L)("%%");
|
|
7093
7093
|
var $L68 = (0, import_lib3.$L)("%");
|
|
@@ -8125,13 +8125,15 @@ var TernaryRest$$ = [TernaryRest$0, TernaryRest$1];
|
|
|
8125
8125
|
function TernaryRest(ctx, state2) {
|
|
8126
8126
|
return (0, import_lib3.$EVENT_C)(ctx, state2, "TernaryRest", TernaryRest$$);
|
|
8127
8127
|
}
|
|
8128
|
-
var NestedTernaryRest$0 = (0, import_lib3.$
|
|
8128
|
+
var NestedTernaryRest$0 = (0, import_lib3.$S)(Nested, QuestionMark, MaybeNestedExtendedExpression, Nested, Colon, MaybeNestedExtendedExpression);
|
|
8129
|
+
var NestedTernaryRest$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(PushIndent, (0, import_lib3.$E)((0, import_lib3.$S)(Nested, QuestionMark, MaybeNestedExtendedExpression, Nested, Colon, MaybeNestedExtendedExpression)), PopIndent), function($skip, $loc, $0, $1, $2, $3) {
|
|
8129
8130
|
if ($2)
|
|
8130
8131
|
return $2;
|
|
8131
8132
|
return $skip;
|
|
8132
8133
|
});
|
|
8134
|
+
var NestedTernaryRest$$ = [NestedTernaryRest$0, NestedTernaryRest$1];
|
|
8133
8135
|
function NestedTernaryRest(ctx, state2) {
|
|
8134
|
-
return (0, import_lib3.$
|
|
8136
|
+
return (0, import_lib3.$EVENT_C)(ctx, state2, "NestedTernaryRest", NestedTernaryRest$$);
|
|
8135
8137
|
}
|
|
8136
8138
|
var ShortCircuitExpression$0 = BinaryOpExpression;
|
|
8137
8139
|
function ShortCircuitExpression(ctx, state2) {
|
|
@@ -11479,11 +11481,12 @@ var NotDedentedBinaryOp$0 = (0, import_lib3.$TS)((0, import_lib3.$S)((0, import_
|
|
|
11479
11481
|
ws.push(...$2);
|
|
11480
11482
|
return [ws, $3];
|
|
11481
11483
|
});
|
|
11482
|
-
var NotDedentedBinaryOp$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(Nested, (0, import_lib3.$E)(_), (0, import_lib3.$N)(Identifier), BinaryOp), function($skip, $loc, $0, $1, $2, $3, $4) {
|
|
11484
|
+
var NotDedentedBinaryOp$1 = (0, import_lib3.$TS)((0, import_lib3.$S)(Nested, (0, import_lib3.$E)(_), (0, import_lib3.$N)(Identifier), (0, import_lib3.$C)((0, import_lib3.$N)((0, import_lib3.$EXPECT)($L64, 'NotDedentedBinaryOp "*"')), (0, import_lib3.$N)(ImportDeclaration)), BinaryOp), function($skip, $loc, $0, $1, $2, $3, $4, $5) {
|
|
11485
|
+
var op = $5;
|
|
11483
11486
|
const ws = [...$1];
|
|
11484
11487
|
if ($2)
|
|
11485
11488
|
ws.push(...$2);
|
|
11486
|
-
return [ws,
|
|
11489
|
+
return [ws, op];
|
|
11487
11490
|
});
|
|
11488
11491
|
var NotDedentedBinaryOp$$ = [NotDedentedBinaryOp$0, NotDedentedBinaryOp$1];
|
|
11489
11492
|
function NotDedentedBinaryOp(ctx, state2) {
|
|
@@ -11537,8 +11540,8 @@ var _BinaryOp$$ = [_BinaryOp$0, _BinaryOp$1, _BinaryOp$2];
|
|
|
11537
11540
|
function _BinaryOp(ctx, state2) {
|
|
11538
11541
|
return (0, import_lib3.$EVENT_C)(ctx, state2, "_BinaryOp", _BinaryOp$$);
|
|
11539
11542
|
}
|
|
11540
|
-
var BinaryOpSymbol$0 = (0, import_lib3.$EXPECT)($
|
|
11541
|
-
var BinaryOpSymbol$1 = (0, import_lib3.$EXPECT)($
|
|
11543
|
+
var BinaryOpSymbol$0 = (0, import_lib3.$EXPECT)($L65, 'BinaryOpSymbol "**"');
|
|
11544
|
+
var BinaryOpSymbol$1 = (0, import_lib3.$EXPECT)($L64, 'BinaryOpSymbol "*"');
|
|
11542
11545
|
var BinaryOpSymbol$2 = (0, import_lib3.$EXPECT)($L66, 'BinaryOpSymbol "/"');
|
|
11543
11546
|
var BinaryOpSymbol$3 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L67, 'BinaryOpSymbol "%%"'), function($skip, $loc, $0, $1) {
|
|
11544
11547
|
return {
|
|
@@ -14473,7 +14476,7 @@ var SingleQuote$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L188, `Single
|
|
|
14473
14476
|
function SingleQuote(ctx, state2) {
|
|
14474
14477
|
return (0, import_lib3.$EVENT)(ctx, state2, "SingleQuote", SingleQuote$0);
|
|
14475
14478
|
}
|
|
14476
|
-
var Star$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($
|
|
14479
|
+
var Star$0 = (0, import_lib3.$TV)((0, import_lib3.$EXPECT)($L64, 'Star "*"'), function($skip, $loc, $0, $1) {
|
|
14477
14480
|
return { $loc, token: $1 };
|
|
14478
14481
|
});
|
|
14479
14482
|
function Star(ctx, state2) {
|