@danielx/civet 0.7.9 → 0.7.11
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/README.md +2 -3
- package/dist/browser.js +686 -526
- package/dist/civet +54 -25
- package/dist/esm.mjs +1 -33
- package/dist/main.js +689 -527
- package/dist/main.mjs +687 -526
- package/dist/types.d.ts +11 -4
- package/package.json +5 -5
- package/register.js +40 -12
package/dist/civet
CHANGED
|
@@ -46,11 +46,11 @@ var unplugin;
|
|
|
46
46
|
function version() {
|
|
47
47
|
return require("../package.json").version;
|
|
48
48
|
}
|
|
49
|
-
if (process.argv.
|
|
49
|
+
if (process.argv.some((a) => a === "--version" || a === "-version" || a === "-v")) {
|
|
50
50
|
console.log(version());
|
|
51
51
|
process.exit(0);
|
|
52
52
|
}
|
|
53
|
-
if (process.argv.
|
|
53
|
+
if (process.argv.some((a1) => a1 === "--help" || a1 === "-help" || a1 === "-h")) {
|
|
54
54
|
process.stderr.write(` \u2584\u2584\xB7 \u25AA \u258C \u2590\xB7\u2584\u2584\u2584 .\u2584\u2584\u2584\u2584\u2584
|
|
55
55
|
\u2590\u2588 \u258C\u25AA\u2588\u2588 \u25AA\u2588\xB7\u2588\u258C\u2580\u2584.\u2580\xB7\u2022\u2588\u2588 _._ _,-'""\`-._
|
|
56
56
|
\u2588\u2588 \u2584\u2584\u2590\u2588\xB7\u2590\u2588\u2590\u2588\u2022\u2590\u2580\u2580\u25AA\u2584 \u2590\u2588.\u25AA (,-.\`._,'( |\\\`-/|
|
|
@@ -106,6 +106,7 @@ function parseArgs(args) {
|
|
|
106
106
|
const filenames = [];
|
|
107
107
|
let scriptArgs = [];
|
|
108
108
|
let i = 0;
|
|
109
|
+
let errors = 0;
|
|
109
110
|
function endOfArgs(j) {
|
|
110
111
|
i = args.length;
|
|
111
112
|
if (j >= args.length) {
|
|
@@ -121,6 +122,12 @@ function parseArgs(args) {
|
|
|
121
122
|
while (i < args.length) {
|
|
122
123
|
const arg = args[i];
|
|
123
124
|
if (/^-\w{2,}$/.test(arg)) {
|
|
125
|
+
const results = [];
|
|
126
|
+
for (let ref = arg.slice(1), i1 = 0, len = ref.length; i1 < len; i1++) {
|
|
127
|
+
const char = ref[i1];
|
|
128
|
+
results.push(`-${char}`);
|
|
129
|
+
}
|
|
130
|
+
;
|
|
124
131
|
args.splice(i, 1 + i - i, ...results);
|
|
125
132
|
continue;
|
|
126
133
|
}
|
|
@@ -199,9 +206,9 @@ function parseArgs(args) {
|
|
|
199
206
|
}
|
|
200
207
|
default: {
|
|
201
208
|
if (arg.startsWith("-") && arg !== "-") {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (options.run) {
|
|
209
|
+
console.error(`Invalid command-line argument: ${arg}`);
|
|
210
|
+
errors++;
|
|
211
|
+
} else if (options.run) {
|
|
205
212
|
endOfArgs(i);
|
|
206
213
|
} else {
|
|
207
214
|
filenames.push(arg);
|
|
@@ -210,12 +217,15 @@ function parseArgs(args) {
|
|
|
210
217
|
}
|
|
211
218
|
i++;
|
|
212
219
|
}
|
|
220
|
+
if (errors) {
|
|
221
|
+
process.exit(Math.min(255, errors));
|
|
222
|
+
}
|
|
213
223
|
return { filenames, scriptArgs, options };
|
|
214
224
|
}
|
|
215
225
|
async function* readFiles(filenames) {
|
|
216
226
|
const results1 = [];
|
|
217
|
-
for (let
|
|
218
|
-
let filename = filenames[
|
|
227
|
+
for (let i2 = 0, len1 = filenames.length; i2 < len1; i2++) {
|
|
228
|
+
let filename = filenames[i2];
|
|
219
229
|
const stdin = filename === "-";
|
|
220
230
|
try {
|
|
221
231
|
let content;
|
|
@@ -273,7 +283,6 @@ async function repl(options) {
|
|
|
273
283
|
};
|
|
274
284
|
} else {
|
|
275
285
|
const execArgv = ["--experimental-vm-modules"];
|
|
276
|
-
const { register } = await import("node:module");
|
|
277
286
|
if (process.env.NODE_OPTIONS) {
|
|
278
287
|
execArgv.push(process.env.NODE_OPTIONS);
|
|
279
288
|
}
|
|
@@ -343,17 +352,36 @@ async function repl(options) {
|
|
|
343
352
|
} else if (input in ["quit\n", "exit\n", "quit()\n", "exit()\n"]) {
|
|
344
353
|
return process.exit(0);
|
|
345
354
|
} else if (input.endsWith("\n\n")) {
|
|
355
|
+
let showError2 = function(error) {
|
|
356
|
+
console.error("Error while parsing Civet code:");
|
|
357
|
+
if ((0, import_main.isCompileError)(error)) {
|
|
358
|
+
if (error.errors != null) {
|
|
359
|
+
error = error.errors[0];
|
|
360
|
+
}
|
|
361
|
+
return console.log(`${input.split("\n").slice(0, error.line).join("\n")}
|
|
362
|
+
${" ".repeat(error.column - 1)}^ ${error.header}`);
|
|
363
|
+
} else {
|
|
364
|
+
return console.error(error);
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
var showError = showError2;
|
|
346
368
|
let output;
|
|
347
369
|
if (options.compile || options.ast) {
|
|
348
370
|
try {
|
|
349
371
|
output = await (0, import_main.compile)(input, { ...options, filename });
|
|
350
372
|
} catch (error) {
|
|
351
|
-
|
|
373
|
+
showError2(error);
|
|
352
374
|
return callback(null, void 0);
|
|
353
375
|
}
|
|
354
376
|
return callback(null, output);
|
|
355
377
|
}
|
|
356
|
-
let ast
|
|
378
|
+
let ast;
|
|
379
|
+
try {
|
|
380
|
+
ast = await (0, import_main.compile)(input, { ...options, filename, ast: true });
|
|
381
|
+
} catch (error) {
|
|
382
|
+
showError2(error);
|
|
383
|
+
return callback(null, void 0);
|
|
384
|
+
}
|
|
357
385
|
const topLevelAwait = import_main.lib.hasAwait(ast) || import_main.lib.hasImportDeclaration(ast);
|
|
358
386
|
if (topLevelAwait) {
|
|
359
387
|
const [prologue, rest] = (0, import_main.parse)(input, { startRule: "ProloguePrefix" });
|
|
@@ -373,7 +401,7 @@ async function repl(options) {
|
|
|
373
401
|
});
|
|
374
402
|
});
|
|
375
403
|
}
|
|
376
|
-
|
|
404
|
+
let errors = [];
|
|
377
405
|
try {
|
|
378
406
|
output = (0, import_main.generate)(ast, { errors });
|
|
379
407
|
} catch (error) {
|
|
@@ -381,7 +409,9 @@ async function repl(options) {
|
|
|
381
409
|
return callback(null, void 0);
|
|
382
410
|
}
|
|
383
411
|
if (errors.length) {
|
|
384
|
-
|
|
412
|
+
errors = [];
|
|
413
|
+
(0, import_main.generate)(ast, { errors, sourceMap: (0, import_main.SourceMap)(input) });
|
|
414
|
+
showError2(errors[0]);
|
|
385
415
|
return callback(null, void 0);
|
|
386
416
|
}
|
|
387
417
|
let result;
|
|
@@ -394,18 +424,17 @@ async function repl(options) {
|
|
|
394
424
|
return callback(error, void 0);
|
|
395
425
|
}
|
|
396
426
|
if (topLevelAwait) {
|
|
397
|
-
let
|
|
427
|
+
let ok = true;
|
|
398
428
|
try {
|
|
399
|
-
result = await result;
|
|
429
|
+
return result = await result;
|
|
400
430
|
} catch (error) {
|
|
401
|
-
|
|
402
|
-
callback(error, void 0);
|
|
403
|
-
}
|
|
404
|
-
|
|
405
|
-
|
|
431
|
+
ok = false;
|
|
432
|
+
return callback(error, void 0);
|
|
433
|
+
} finally {
|
|
434
|
+
if (ok) {
|
|
435
|
+
callback(null, result);
|
|
436
|
+
}
|
|
406
437
|
}
|
|
407
|
-
;
|
|
408
|
-
return;
|
|
409
438
|
} else {
|
|
410
439
|
return callback(null, result);
|
|
411
440
|
}
|
|
@@ -531,7 +560,7 @@ async function cli() {
|
|
|
531
560
|
targetPath = outputPath;
|
|
532
561
|
}
|
|
533
562
|
if (targetPath.dir) {
|
|
534
|
-
import_promises.default.mkdir(targetPath.dir, { recursive: true });
|
|
563
|
+
await import_promises.default.mkdir(targetPath.dir, { recursive: true });
|
|
535
564
|
}
|
|
536
565
|
const targetFilename = import_path.default.format(targetPath);
|
|
537
566
|
try {
|
|
@@ -618,9 +647,9 @@ async function cli() {
|
|
|
618
647
|
}
|
|
619
648
|
});
|
|
620
649
|
} catch (error) {
|
|
621
|
-
let
|
|
622
|
-
if (
|
|
623
|
-
const match =
|
|
650
|
+
let ref1;
|
|
651
|
+
if (ref1 = error.message.match(/Aborting build because of (\d+) TypeScript diagnostic/)) {
|
|
652
|
+
const match = ref1;
|
|
624
653
|
return process.exitCode = Math.min(255, errors + +match[1]);
|
|
625
654
|
} else {
|
|
626
655
|
process.exitCode = 1;
|
package/dist/esm.mjs
CHANGED
|
@@ -1,40 +1,10 @@
|
|
|
1
1
|
// source/esm.civet
|
|
2
2
|
import { readFileSync } from "fs";
|
|
3
3
|
import { pathToFileURL, fileURLToPath } from "url";
|
|
4
|
-
import sourceMapSupport from "@cspotcode/source-map-support";
|
|
5
4
|
import Civet from "./main.js";
|
|
6
|
-
var { compile,
|
|
7
|
-
var { SourceMap } = util;
|
|
5
|
+
var { compile, SourceMap } = Civet;
|
|
8
6
|
var baseURL = pathToFileURL(process.cwd() + "/").href;
|
|
9
7
|
var extensionsRegex = /\.civet$/;
|
|
10
|
-
var registered = false;
|
|
11
|
-
var outputCache = /* @__PURE__ */ new Map();
|
|
12
|
-
var directorySeparator = "/";
|
|
13
|
-
var backslashRegExp = /\\/g;
|
|
14
|
-
function normalizeSlashes(value) {
|
|
15
|
-
return value.replace(backslashRegExp, directorySeparator);
|
|
16
|
-
}
|
|
17
|
-
var ensureRegister = function() {
|
|
18
|
-
if (registered) {
|
|
19
|
-
return;
|
|
20
|
-
}
|
|
21
|
-
const installation = {
|
|
22
|
-
environment: "node",
|
|
23
|
-
retrieveFile(pathOrUrl) {
|
|
24
|
-
let path = pathOrUrl;
|
|
25
|
-
if (path.startsWith("file:")) {
|
|
26
|
-
try {
|
|
27
|
-
path = fileURLToPath(path);
|
|
28
|
-
} catch (e) {
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
path = normalizeSlashes(path);
|
|
32
|
-
return outputCache.get(path);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
sourceMapSupport.install(installation);
|
|
36
|
-
return registered = true;
|
|
37
|
-
};
|
|
38
8
|
function resolve(specifier, context, next) {
|
|
39
9
|
const { parentURL = baseURL } = context;
|
|
40
10
|
if (extensionsRegex.test(specifier)) {
|
|
@@ -63,10 +33,8 @@ async function load(url, context, next) {
|
|
|
63
33
|
// NOTE: Setting the source in the context makes it available when ts-node uses defaultLoad
|
|
64
34
|
source: tsSource
|
|
65
35
|
});
|
|
66
|
-
ensureRegister();
|
|
67
36
|
result.responseURL = (result.responseURL ?? transpiledUrl).replace(/.tsx$/, "");
|
|
68
37
|
result.source = SourceMap.remap(result.source, sourceMap, url, result.responseURL);
|
|
69
|
-
outputCache.set(normalizeSlashes(path), result.source);
|
|
70
38
|
return result;
|
|
71
39
|
}
|
|
72
40
|
return next(url, context);
|