@danielx/civet 0.5.89 → 0.5.91
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 +1 -1
- package/dist/browser.js +455 -295
- package/dist/browser.js.gzip +0 -0
- package/dist/civet +41 -12
- package/dist/esm.mjs +2 -1
- package/dist/main.js +455 -295
- package/dist/main.mjs +455 -295
- package/package.json +1 -1
|
Binary file
|
package/dist/civet
CHANGED
|
@@ -23,6 +23,7 @@ Usage:
|
|
|
23
23
|
civet # REPL for executing code
|
|
24
24
|
civet -c # REPL for transpiling code
|
|
25
25
|
civet --ast # REPL for parsing code
|
|
26
|
+
civet [options] input.civet # run input.civet
|
|
26
27
|
civet [options] -c input.civet # -> input.civet.tsx
|
|
27
28
|
civet [options] -c input.civet -o .ts # -> input.ts
|
|
28
29
|
civet [options] -c input.civet -o dir # -> dir/input.civet.tsx
|
|
@@ -48,7 +49,7 @@ You can use - to read from stdin or (prefixed by -o) write to stdout.
|
|
|
48
49
|
encoding = "utf8";
|
|
49
50
|
fs = require("fs/promises");
|
|
50
51
|
path = require("path");
|
|
51
|
-
parseArgs = function(args
|
|
52
|
+
parseArgs = function(args) {
|
|
52
53
|
var arg, char, endOfArgs, filenames, i, options, ref, scriptArgs;
|
|
53
54
|
options = {};
|
|
54
55
|
Object.defineProperty(options, "run", {
|
|
@@ -250,8 +251,9 @@ repl = function(options) {
|
|
|
250
251
|
});
|
|
251
252
|
};
|
|
252
253
|
cli = async function() {
|
|
253
|
-
var content, error, filename, filenames, options, optionsPath, output, outputFilename, outputPath, ref, results, scriptArgs, stat, stdin, x;
|
|
254
|
-
|
|
254
|
+
var argv, child, content, e, error, esm, filename, filenames, options, optionsPath, output, outputFilename, outputPath, ref, results, scriptArgs, stat, stdin, x;
|
|
255
|
+
argv = process.argv;
|
|
256
|
+
({ filenames, scriptArgs, options } = parseArgs(argv.slice(2)));
|
|
255
257
|
if (!filenames.length) {
|
|
256
258
|
if (process.stdin.isTTY) {
|
|
257
259
|
options.repl = true;
|
|
@@ -330,15 +332,42 @@ cli = async function() {
|
|
|
330
332
|
}
|
|
331
333
|
}
|
|
332
334
|
} else {
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
335
|
+
esm = /^\s*(import|export)\b/m.test(output);
|
|
336
|
+
if (esm) {
|
|
337
|
+
if (stdin) {
|
|
338
|
+
filename = `.stdin-${process.pid}.civet`;
|
|
339
|
+
try {
|
|
340
|
+
await fs.writeFile(filename, content, { encoding });
|
|
341
|
+
} catch (error1) {
|
|
342
|
+
e = error1;
|
|
343
|
+
console.error(`Could not write ${filename} for Civet ESM mode:`);
|
|
344
|
+
console.error(e);
|
|
345
|
+
process.exit(1);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
child = require("child_process").spawnSync(argv[0], ["--loader", "@danielx/civet/esm", filename, ...scriptArgs], {
|
|
349
|
+
stdio: "inherit"
|
|
350
|
+
});
|
|
351
|
+
if (stdin) {
|
|
352
|
+
await fs.unlink(filename);
|
|
353
|
+
}
|
|
354
|
+
results.push(process.exit(child.status));
|
|
355
|
+
} else {
|
|
356
|
+
try {
|
|
357
|
+
module.filename = await fs.realpath(filename);
|
|
358
|
+
} catch (error1) {
|
|
359
|
+
module.filename = filename;
|
|
360
|
+
}
|
|
361
|
+
process.argv = ["civet", module.filename, ...scriptArgs];
|
|
362
|
+
module.paths = require("module")._nodeModulePaths(path.dirname(module.filename));
|
|
363
|
+
try {
|
|
364
|
+
results.push(module._compile(output, module.filename));
|
|
365
|
+
} catch (error1) {
|
|
366
|
+
error = error1;
|
|
367
|
+
console.error(`${filename} crashed while running in CJS mode:`);
|
|
368
|
+
console.error(error);
|
|
369
|
+
results.push(process.exit(1));
|
|
370
|
+
}
|
|
342
371
|
}
|
|
343
372
|
}
|
|
344
373
|
}
|
package/dist/esm.mjs
CHANGED
|
@@ -23,7 +23,7 @@ const { SourceMap } = util
|
|
|
23
23
|
const baseURL = pathToFileURL(process.cwd() + '/').href
|
|
24
24
|
const extensionsRegex = /\.civet$/
|
|
25
25
|
|
|
26
|
-
let registered = false
|
|
26
|
+
let registered = false;
|
|
27
27
|
const outputCache = new Map
|
|
28
28
|
|
|
29
29
|
const directorySeparator = '/'
|
|
@@ -82,6 +82,7 @@ export async function load(url, context, next) {
|
|
|
82
82
|
const {code: tsSource, sourceMap} = compile(source, {
|
|
83
83
|
filename: path,
|
|
84
84
|
sourceMap: true,
|
|
85
|
+
js: true,
|
|
85
86
|
})
|
|
86
87
|
|
|
87
88
|
const transpiledPath = url + ".tsx"
|