@danielx/civet 0.6.87 → 0.6.89
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 +3 -4
- package/dist/browser.js +251 -48
- package/dist/civet +117 -10
- package/dist/esm.mjs +0 -11
- package/dist/main.js +251 -48
- package/dist/main.mjs +251 -48
- package/dist/types.d.ts +6 -1
- package/package.json +2 -2
- package/register.js +20 -4
package/dist/civet
CHANGED
|
@@ -6,6 +6,10 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
6
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
9
13
|
var __copyProps = (to, from, except, desc) => {
|
|
10
14
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
15
|
for (let key of __getOwnPropNames(from))
|
|
@@ -22,8 +26,17 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
26
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
27
|
mod
|
|
24
28
|
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
30
|
|
|
26
31
|
// source/cli.civet
|
|
32
|
+
var cli_exports = {};
|
|
33
|
+
__export(cli_exports, {
|
|
34
|
+
cli: () => cli,
|
|
35
|
+
parseArgs: () => parseArgs,
|
|
36
|
+
repl: () => repl,
|
|
37
|
+
version: () => version
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(cli_exports);
|
|
27
40
|
var import_main = require("./main.js");
|
|
28
41
|
var import_config = require("./config.js");
|
|
29
42
|
var import_unplugin = require("./unplugin");
|
|
@@ -244,6 +257,33 @@ async function* readFiles(filenames) {
|
|
|
244
257
|
return results1;
|
|
245
258
|
}
|
|
246
259
|
async function repl(options) {
|
|
260
|
+
const vm = await import("vm");
|
|
261
|
+
let importModuleDynamically = vm.constants?.USE_MAIN_CONTEXT_DEFAULT_LOADER;
|
|
262
|
+
if (!importModuleDynamically) {
|
|
263
|
+
if (vm.SourceTextModule != null) {
|
|
264
|
+
const { pathToFileURL } = await import("url");
|
|
265
|
+
importModuleDynamically = (specifier) => {
|
|
266
|
+
if (/^\.\.?[/\\]/.test(specifier)) {
|
|
267
|
+
return import(pathToFileURL(import_path.default.join(process.cwd(), specifier)));
|
|
268
|
+
} else {
|
|
269
|
+
return import(specifier);
|
|
270
|
+
}
|
|
271
|
+
};
|
|
272
|
+
} else {
|
|
273
|
+
const execArgv = ["--experimental-vm-modules"];
|
|
274
|
+
const { register } = await import("module");
|
|
275
|
+
if (process.env.NODE_OPTIONS) {
|
|
276
|
+
execArgv.push(process.env.NODE_OPTIONS);
|
|
277
|
+
}
|
|
278
|
+
const { fork } = await import("child_process");
|
|
279
|
+
fork(__filename, process.argv.slice(2), {
|
|
280
|
+
execArgv,
|
|
281
|
+
stdio: "inherit"
|
|
282
|
+
});
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
require("../register.js");
|
|
247
287
|
console.log(`Civet ${version()} REPL. Enter a blank line to ${(() => {
|
|
248
288
|
switch (false) {
|
|
249
289
|
case !options.ast: {
|
|
@@ -259,7 +299,6 @@ async function repl(options) {
|
|
|
259
299
|
})()} code.`);
|
|
260
300
|
global.quit = global.exit = () => process.exit(0);
|
|
261
301
|
const nodeRepl = await import("repl");
|
|
262
|
-
const vm = await import("vm");
|
|
263
302
|
const r = nodeRepl.start({
|
|
264
303
|
prompt: (() => {
|
|
265
304
|
switch (false) {
|
|
@@ -288,28 +327,76 @@ async function repl(options) {
|
|
|
288
327
|
return "";
|
|
289
328
|
}
|
|
290
329
|
} : void 0,
|
|
291
|
-
eval: function(input, context, filename, callback) {
|
|
330
|
+
eval: async function(input, context, filename, callback) {
|
|
292
331
|
if (input === "\n") {
|
|
293
332
|
return callback(null, void 0);
|
|
294
333
|
} else if (input in ["quit\n", "exit\n", "quit()\n", "exit()\n"]) {
|
|
295
334
|
return process.exit(0);
|
|
296
335
|
} else if (input.endsWith("\n\n")) {
|
|
297
336
|
let output;
|
|
337
|
+
if (options.compile || options.ast) {
|
|
338
|
+
try {
|
|
339
|
+
output = (0, import_main.compile)(input, { ...options, filename });
|
|
340
|
+
} catch (error) {
|
|
341
|
+
console.error(error);
|
|
342
|
+
return callback(null, void 0);
|
|
343
|
+
}
|
|
344
|
+
return callback(null, output);
|
|
345
|
+
}
|
|
346
|
+
let ast = (0, import_main.compile)(input, { ...options, filename, ast: true });
|
|
347
|
+
const topLevelAwait = import_main.lib.hasAwait(ast) || import_main.lib.hasImportDeclaration(ast);
|
|
348
|
+
if (topLevelAwait) {
|
|
349
|
+
const [prologue, rest] = (0, import_main.parse)(input, { startRule: "ProloguePrefix" });
|
|
350
|
+
const prefix = input.slice(0, -rest.length);
|
|
351
|
+
const coffee = prologue.some((p) => p.type === "CivetPrologue" && (p.config.coffeeCompat || p.config.coffeeDo));
|
|
352
|
+
ast = (0, import_main.compile)(
|
|
353
|
+
prefix + (coffee ? "(do ->\n" : "async do\n") + rest.replace(/^/gm, " ") + (coffee ? ")" : ""),
|
|
354
|
+
{ ...options, filename, ast: true }
|
|
355
|
+
);
|
|
356
|
+
import_main.lib.gatherRecursive(ast, ($) => $.type === "BlockStatement").forEach((topBlock) => {
|
|
357
|
+
return import_main.lib.gatherRecursiveWithinFunction(topBlock, ($1) => $1.type === "Declaration").forEach((decl) => {
|
|
358
|
+
const type = decl.children.shift();
|
|
359
|
+
if (!Array.isArray(ast)) {
|
|
360
|
+
ast = [ast];
|
|
361
|
+
}
|
|
362
|
+
return ast.unshift(`var ${decl.names.join(",")};`);
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
const errors = [];
|
|
298
367
|
try {
|
|
299
|
-
output = (0, import_main.
|
|
368
|
+
output = (0, import_main.generate)(ast, { errors });
|
|
300
369
|
} catch (error) {
|
|
301
370
|
console.error(error);
|
|
302
371
|
return callback(null, void 0);
|
|
303
372
|
}
|
|
304
|
-
if (
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
373
|
+
if (errors.length) {
|
|
374
|
+
console.error(`Parse errors: ${errors.map(($2) => $2.message).join("\n")}`);
|
|
375
|
+
return callback(null, void 0);
|
|
376
|
+
}
|
|
377
|
+
let result;
|
|
378
|
+
try {
|
|
379
|
+
result = vm.runInContext(output, context, {
|
|
380
|
+
filename,
|
|
381
|
+
importModuleDynamically
|
|
382
|
+
});
|
|
383
|
+
} catch (error) {
|
|
384
|
+
return callback(error, void 0);
|
|
385
|
+
}
|
|
386
|
+
if (topLevelAwait) {
|
|
387
|
+
let threw = false;
|
|
308
388
|
try {
|
|
309
|
-
result =
|
|
389
|
+
result = await result;
|
|
310
390
|
} catch (error) {
|
|
311
|
-
|
|
391
|
+
threw = true;
|
|
392
|
+
callback(error, void 0);
|
|
312
393
|
}
|
|
394
|
+
if (!threw) {
|
|
395
|
+
return callback(null, result);
|
|
396
|
+
}
|
|
397
|
+
;
|
|
398
|
+
return;
|
|
399
|
+
} else {
|
|
313
400
|
return callback(null, result);
|
|
314
401
|
}
|
|
315
402
|
} else {
|
|
@@ -451,7 +538,20 @@ async function cli() {
|
|
|
451
538
|
}
|
|
452
539
|
}
|
|
453
540
|
const { fork } = await import("child_process");
|
|
454
|
-
const
|
|
541
|
+
const { register } = await import("module");
|
|
542
|
+
let execArgv;
|
|
543
|
+
if (register) {
|
|
544
|
+
execArgv = ["--import", "@danielx/civet/register"];
|
|
545
|
+
} else {
|
|
546
|
+
execArgv = [
|
|
547
|
+
"--loader",
|
|
548
|
+
"@danielx/civet/esm",
|
|
549
|
+
// ESM
|
|
550
|
+
"--require",
|
|
551
|
+
"@danielx/civet/register"
|
|
552
|
+
// CJS
|
|
553
|
+
];
|
|
554
|
+
}
|
|
455
555
|
const debugRe = /--debug|--inspect/;
|
|
456
556
|
const isDebug = typeof v8debug === "object" || debugRe.test(process.execArgv.join(" ")) || debugRe.test(process.env.NODE_OPTIONS ?? "");
|
|
457
557
|
if (process.env.NODE_OPTIONS) {
|
|
@@ -516,3 +616,10 @@ async function cli() {
|
|
|
516
616
|
if (require.main === module) {
|
|
517
617
|
cli();
|
|
518
618
|
}
|
|
619
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
620
|
+
0 && (module.exports = {
|
|
621
|
+
cli,
|
|
622
|
+
parseArgs,
|
|
623
|
+
repl,
|
|
624
|
+
version
|
|
625
|
+
});
|
package/dist/esm.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
// source/esm.civet
|
|
2
2
|
import { readFileSync } from "fs";
|
|
3
|
-
import { createRequire } from "module";
|
|
4
3
|
import { pathToFileURL, fileURLToPath } from "url";
|
|
5
4
|
import sourceMapSupport from "@cspotcode/source-map-support";
|
|
6
5
|
import Civet from "./main.js";
|
|
@@ -72,16 +71,6 @@ async function load(url, context, next) {
|
|
|
72
71
|
}
|
|
73
72
|
return next(url, context);
|
|
74
73
|
}
|
|
75
|
-
var require2 = createRequire(import.meta.url);
|
|
76
|
-
require2.extensions[".civet"] = function(m, filename) {
|
|
77
|
-
const source = readFileSync(filename, "utf8");
|
|
78
|
-
const code = compile(source, {
|
|
79
|
-
filename,
|
|
80
|
-
inlineMap: true,
|
|
81
|
-
js: true
|
|
82
|
-
});
|
|
83
|
-
return m._compile(code, filename);
|
|
84
|
-
};
|
|
85
74
|
export {
|
|
86
75
|
load,
|
|
87
76
|
resolve
|