@danielx/civet 0.7.4 → 0.7.6
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/astro.js +6 -6
- package/dist/babel-plugin.mjs +4 -2
- package/dist/browser.js +335 -150
- package/dist/bun-civet.mjs +4 -4
- package/dist/civet +20 -12
- package/dist/config.js +4 -1
- package/dist/esbuild-plugin.js +1 -1
- package/dist/esbuild.js +6 -6
- package/dist/esm.mjs +1 -1
- package/dist/main.js +322 -150
- package/dist/main.mjs +320 -150
- package/dist/rollup.js +6 -6
- package/dist/types.d.ts +16 -5
- package/dist/unplugin-shared.mjs +6 -6
- package/dist/unplugin.js +6 -6
- package/dist/vite.js +6 -6
- package/dist/webpack.js +6 -6
- package/package.json +3 -3
package/dist/bun-civet.mjs
CHANGED
|
@@ -3,10 +3,10 @@ await plugin({
|
|
|
3
3
|
name: "Civet loader",
|
|
4
4
|
setup: async function(builder) {
|
|
5
5
|
const { compile } = await import("./main.mjs");
|
|
6
|
-
const {
|
|
7
|
-
return builder.onLoad({ filter: /\.civet$/ }, function({ path }) {
|
|
8
|
-
const source =
|
|
9
|
-
const contents = compile(source);
|
|
6
|
+
const { readFile } = await import("node:fs/promises");
|
|
7
|
+
return builder.onLoad({ filter: /\.civet$/ }, async function({ path }) {
|
|
8
|
+
const source = await readFile(path, "utf8");
|
|
9
|
+
const contents = await compile(source, { comptime: true });
|
|
10
10
|
return {
|
|
11
11
|
contents,
|
|
12
12
|
loader: "tsx"
|
package/dist/civet
CHANGED
|
@@ -228,7 +228,7 @@ async function* readFiles(filenames) {
|
|
|
228
228
|
}
|
|
229
229
|
if (process.stdin.isTTY) {
|
|
230
230
|
const lines = [];
|
|
231
|
-
const rl = (await import("readline")).createInterface(process.stdin, process.stdout);
|
|
231
|
+
const rl = (await import("node:readline")).createInterface(process.stdin, process.stdout);
|
|
232
232
|
rl.on("line", (buffer) => lines.push(buffer + "\n"));
|
|
233
233
|
content = await new Promise((resolve, reject) => {
|
|
234
234
|
rl.on("SIGINT", () => {
|
|
@@ -259,11 +259,11 @@ async function* readFiles(filenames) {
|
|
|
259
259
|
return results1;
|
|
260
260
|
}
|
|
261
261
|
async function repl(options) {
|
|
262
|
-
const vm = await import("vm");
|
|
262
|
+
const vm = await import("node:vm");
|
|
263
263
|
let importModuleDynamically = vm.constants?.USE_MAIN_CONTEXT_DEFAULT_LOADER;
|
|
264
264
|
if (!importModuleDynamically) {
|
|
265
265
|
if (vm.SourceTextModule != null) {
|
|
266
|
-
const { pathToFileURL } = await import("url");
|
|
266
|
+
const { pathToFileURL } = await import("node:url");
|
|
267
267
|
importModuleDynamically = (specifier) => {
|
|
268
268
|
if (/^\.\.?[/\\]/.test(specifier)) {
|
|
269
269
|
return import(pathToFileURL(import_path.default.join(process.cwd(), specifier)));
|
|
@@ -273,11 +273,11 @@ async function repl(options) {
|
|
|
273
273
|
};
|
|
274
274
|
} else {
|
|
275
275
|
const execArgv = ["--experimental-vm-modules"];
|
|
276
|
-
const { register } = await import("module");
|
|
276
|
+
const { register } = await import("node:module");
|
|
277
277
|
if (process.env.NODE_OPTIONS) {
|
|
278
278
|
execArgv.push(process.env.NODE_OPTIONS);
|
|
279
279
|
}
|
|
280
|
-
const { fork } = await import("child_process");
|
|
280
|
+
const { fork } = await import("node:child_process");
|
|
281
281
|
fork(__filename, process.argv.slice(2), {
|
|
282
282
|
execArgv,
|
|
283
283
|
stdio: "inherit"
|
|
@@ -300,7 +300,7 @@ async function repl(options) {
|
|
|
300
300
|
}
|
|
301
301
|
})()} code.`);
|
|
302
302
|
global.quit = global.exit = () => process.exit(0);
|
|
303
|
-
const nodeRepl = await import("repl");
|
|
303
|
+
const nodeRepl = await import("node:repl");
|
|
304
304
|
const r = nodeRepl.start({
|
|
305
305
|
prompt: (() => {
|
|
306
306
|
switch (false) {
|
|
@@ -346,20 +346,20 @@ async function repl(options) {
|
|
|
346
346
|
let output;
|
|
347
347
|
if (options.compile || options.ast) {
|
|
348
348
|
try {
|
|
349
|
-
output = (0, import_main.compile)(input, { ...options, filename });
|
|
349
|
+
output = await (0, import_main.compile)(input, { ...options, filename });
|
|
350
350
|
} catch (error) {
|
|
351
351
|
console.error(error);
|
|
352
352
|
return callback(null, void 0);
|
|
353
353
|
}
|
|
354
354
|
return callback(null, output);
|
|
355
355
|
}
|
|
356
|
-
let ast = (0, import_main.compile)(input, { ...options, filename, ast: true });
|
|
356
|
+
let ast = await (0, import_main.compile)(input, { ...options, filename, ast: true });
|
|
357
357
|
const topLevelAwait = import_main.lib.hasAwait(ast) || import_main.lib.hasImportDeclaration(ast);
|
|
358
358
|
if (topLevelAwait) {
|
|
359
359
|
const [prologue, rest] = (0, import_main.parse)(input, { startRule: "ProloguePrefix" });
|
|
360
360
|
const prefix = input.slice(0, -rest.length);
|
|
361
361
|
const coffee = prologue.some((p) => p.type === "CivetPrologue" && (p.config.coffeeCompat || p.config.coffeeDo));
|
|
362
|
-
ast = (0, import_main.compile)(
|
|
362
|
+
ast = await (0, import_main.compile)(
|
|
363
363
|
prefix + (coffee ? "(do ->\n" : "async do\n") + rest.replace(/^/gm, " ") + (coffee ? ")" : ""),
|
|
364
364
|
{ ...options, filename, ast: true }
|
|
365
365
|
);
|
|
@@ -493,13 +493,21 @@ async function cli() {
|
|
|
493
493
|
}
|
|
494
494
|
}, `${filename}.tsx`)).code;
|
|
495
495
|
} else {
|
|
496
|
-
output = (0, import_main.compile)(content, { ...options, filename });
|
|
496
|
+
output = await (0, import_main.compile)(content, { ...options, filename });
|
|
497
497
|
}
|
|
498
498
|
} catch (error2) {
|
|
499
499
|
console.error(error2);
|
|
500
500
|
errors++;
|
|
501
501
|
continue;
|
|
502
502
|
}
|
|
503
|
+
process.stdout.on("error", (e) => {
|
|
504
|
+
if (["EPIPE", "EOF"].includes(e.code)) {
|
|
505
|
+
return process.exit(0);
|
|
506
|
+
} else {
|
|
507
|
+
console.error(e);
|
|
508
|
+
return process.exit(1);
|
|
509
|
+
}
|
|
510
|
+
});
|
|
503
511
|
if (options.ast) {
|
|
504
512
|
process.stdout.write(JSON.stringify(output, null, 2));
|
|
505
513
|
} else if (options.compile) {
|
|
@@ -547,8 +555,8 @@ async function cli() {
|
|
|
547
555
|
process.exit(1);
|
|
548
556
|
}
|
|
549
557
|
}
|
|
550
|
-
const { fork } = await import("child_process");
|
|
551
|
-
const { register } = await import("module");
|
|
558
|
+
const { fork } = await import("node:child_process");
|
|
559
|
+
const { register } = await import("node:module");
|
|
552
560
|
let execArgv;
|
|
553
561
|
if (register) {
|
|
554
562
|
execArgv = ["--import", "@danielx/civet/register"];
|
package/dist/config.js
CHANGED
|
@@ -96,7 +96,10 @@ async function loadConfig(path2) {
|
|
|
96
96
|
} else {
|
|
97
97
|
let js;
|
|
98
98
|
try {
|
|
99
|
-
js = (0, import_main.compile)(config, {
|
|
99
|
+
js = (0, import_main.compile)(config, {
|
|
100
|
+
js: true,
|
|
101
|
+
sync: true
|
|
102
|
+
});
|
|
100
103
|
} catch (e) {
|
|
101
104
|
throw new Error(`Error compiling Civet config file ${path2}: ${e}`);
|
|
102
105
|
}
|
package/dist/esbuild-plugin.js
CHANGED
|
@@ -90,7 +90,7 @@ var civet = function(options = {}) {
|
|
|
90
90
|
try {
|
|
91
91
|
const source = await (0, import_promises.readFile)(args.path, "utf8");
|
|
92
92
|
const filename = import_path.default.relative(process.cwd(), args.path);
|
|
93
|
-
const compiled = (0, import_main.compile)(source, {
|
|
93
|
+
const compiled = await (0, import_main.compile)(source, {
|
|
94
94
|
filename,
|
|
95
95
|
inlineMap,
|
|
96
96
|
js
|
package/dist/esbuild.js
CHANGED
|
@@ -166,9 +166,9 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
166
166
|
const compiledTS = import_civet.default.compile(rawCivetSource, {
|
|
167
167
|
filename,
|
|
168
168
|
js: false,
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
169
|
+
comptime: Boolean(options.comptime),
|
|
170
|
+
sync: true
|
|
171
|
+
// TS readFile API seems to need to be synchronous
|
|
172
172
|
});
|
|
173
173
|
fsMap.set(filename, compiledTS);
|
|
174
174
|
return compiledTS;
|
|
@@ -321,12 +321,12 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
321
321
|
}
|
|
322
322
|
};
|
|
323
323
|
if (options.ts === "civet" && !transformTS) {
|
|
324
|
-
compiled = import_civet.default.compile(rawCivetSource, {
|
|
324
|
+
compiled = await import_civet.default.compile(rawCivetSource, {
|
|
325
325
|
...civetOptions,
|
|
326
326
|
js: true
|
|
327
327
|
});
|
|
328
328
|
} else {
|
|
329
|
-
const compiledTS = import_civet.default.compile(rawCivetSource, {
|
|
329
|
+
const compiledTS = await import_civet.default.compile(rawCivetSource, {
|
|
330
330
|
...civetOptions,
|
|
331
331
|
js: false
|
|
332
332
|
});
|
|
@@ -372,7 +372,7 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
372
372
|
}
|
|
373
373
|
case "civet":
|
|
374
374
|
default: {
|
|
375
|
-
compiled = import_civet.default.compile(rawCivetSource, {
|
|
375
|
+
compiled = await import_civet.default.compile(rawCivetSource, {
|
|
376
376
|
...civetOptions,
|
|
377
377
|
js: true
|
|
378
378
|
});
|
package/dist/esm.mjs
CHANGED
|
@@ -50,7 +50,7 @@ async function load(url, context, next) {
|
|
|
50
50
|
if (context.format === "civet") {
|
|
51
51
|
const path = fileURLToPath(url);
|
|
52
52
|
const source = readFileSync(path, "utf8");
|
|
53
|
-
const { code: tsSource, sourceMap } = compile(source, {
|
|
53
|
+
const { code: tsSource, sourceMap } = await compile(source, {
|
|
54
54
|
filename: path,
|
|
55
55
|
sourceMap: true,
|
|
56
56
|
js: true
|