@danielx/civet 0.6.25 → 0.6.27
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 +7 -0
- package/dist/babel-plugin.mjs +15 -0
- package/dist/browser.js +5834 -17282
- package/dist/bun-civet.mjs +2 -8
- package/dist/civet +143 -124
- package/dist/config.js +37 -31
- package/dist/esbuild-plugin.js +88 -105
- package/dist/esbuild.d.mts +7 -0
- package/dist/esbuild.d.ts +7 -0
- package/dist/esbuild.js +176 -0
- package/dist/esbuild.mjs +9 -0
- package/dist/esm.mjs +56 -103
- package/dist/main.js +5834 -17282
- package/dist/main.mjs +5834 -17282
- package/dist/rollup.d.mts +7 -0
- package/dist/rollup.d.ts +7 -0
- package/dist/rollup.js +176 -0
- package/dist/rollup.mjs +9 -0
- package/dist/unplugin-shared.mjs +141 -0
- package/dist/unplugin.d.mts +16 -0
- package/dist/unplugin.d.ts +16 -0
- package/dist/unplugin.js +171 -0
- package/dist/unplugin.mjs +6 -0
- package/dist/vite.d.mts +7 -0
- package/dist/vite.d.ts +7 -0
- package/dist/vite.js +176 -0
- package/dist/vite.mjs +9 -0
- package/dist/webpack.d.mts +6 -0
- package/dist/webpack.d.ts +6 -0
- package/dist/webpack.js +176 -0
- package/dist/webpack.mjs +9 -0
- package/package.json +37 -9
- package/dist/browser.js.gzip +0 -0
package/dist/bun-civet.mjs
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
plugin
|
|
3
|
-
} from "bun";
|
|
1
|
+
import { plugin } from "bun";
|
|
4
2
|
await plugin({
|
|
5
3
|
name: "Civet loader",
|
|
6
4
|
setup: async function(builder) {
|
|
7
|
-
var compile, readFileSync;
|
|
8
5
|
({ compile } = await import("./main.mjs"));
|
|
9
6
|
({ readFileSync } = await import("fs"));
|
|
10
|
-
return builder.onLoad({
|
|
11
|
-
filter: /\.civet$/
|
|
12
|
-
}, function({ path }) {
|
|
13
|
-
var contents, source;
|
|
7
|
+
return builder.onLoad({ filter: /\.civet$/ }, function({ path }) {
|
|
14
8
|
source = readFileSync(path, "utf8");
|
|
15
9
|
contents = compile(source);
|
|
16
10
|
return {
|
package/dist/civet
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var
|
|
3
|
+
|
|
4
|
+
// source/cli.civet
|
|
5
|
+
var import_main = require("./main.js");
|
|
6
|
+
var import_config = require("./config.js");
|
|
7
|
+
var prune;
|
|
8
|
+
var version;
|
|
9
|
+
var encoding;
|
|
10
|
+
var fs;
|
|
11
|
+
var path;
|
|
12
|
+
var parseArgs;
|
|
13
|
+
var readFiles;
|
|
14
|
+
var repl;
|
|
15
|
+
var cli;
|
|
16
|
+
var indexOf = [].indexOf;
|
|
6
17
|
({ prune } = import_main.generate);
|
|
7
18
|
version = function() {
|
|
8
19
|
return require("../package.json").version;
|
|
@@ -12,39 +23,39 @@ if (process.argv.includes("--version")) {
|
|
|
12
23
|
process.exit(0);
|
|
13
24
|
}
|
|
14
25
|
if (process.argv.includes("--help")) {
|
|
15
|
-
process.stderr.write(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
26
|
+
process.stderr.write(`\u2584\u2584\xB7 \u25AA \u258C \u2590\xB7\u2584\u2584\u2584 .\u2584\u2584\u2584\u2584\u2584
|
|
27
|
+
\u2590\u2588 \u258C\u25AA\u2588\u2588 \u25AA\u2588\xB7\u2588\u258C\u2580\u2584.\u2580\xB7\u2022\u2588\u2588 _._ _,-'""\`-._
|
|
28
|
+
\u2588\u2588 \u2584\u2584\u2590\u2588\xB7\u2590\u2588\u2590\u2588\u2022\u2590\u2580\u2580\u25AA\u2584 \u2590\u2588.\u25AA (,-.\`._,'( |\\\`-/|
|
|
29
|
+
\u2590\u2588\u2588\u2588\u258C\u2590\u2588\u258C \u2588\u2588\u2588 \u2590\u2588\u2584\u2584\u258C \u2590\u2588\u258C\xB7 \`-.-' \\ )-\`( , o o)
|
|
30
|
+
\xB7\u2580\u2580\u2580 \u2580\u2580\u2580. \u2580 \u2580\u2580\u2580 \u2580\u2580\u2580 \`- \\\`_\`"'-
|
|
20
31
|
|
|
21
32
|
|
|
22
|
-
Usage:
|
|
33
|
+
Usage:
|
|
23
34
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
35
|
+
civet # REPL for executing code
|
|
36
|
+
civet -c # REPL for transpiling code
|
|
37
|
+
civet --ast # REPL for parsing code
|
|
38
|
+
civet [options] input.civet # run input.civet
|
|
39
|
+
civet [options] -c input.civet # -> input.civet.tsx
|
|
40
|
+
civet [options] -c input.civet -o .ts # -> input.ts
|
|
41
|
+
civet [options] -c input.civet -o dir # -> dir/input.civet.tsx
|
|
42
|
+
civet [options] -c input.civet -o dir/.ts # -> dir/input.ts
|
|
43
|
+
civet [options] -c input.civet -o output.ts # -> output.ts
|
|
44
|
+
civet [options] < input.civet > output.ts # pipe form
|
|
34
45
|
|
|
35
|
-
Options:
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
+
Options:
|
|
47
|
+
--help Show this help message
|
|
48
|
+
--version Show the version number
|
|
49
|
+
-o / --output XX Specify output directory and/or extension, or filename
|
|
50
|
+
-c / --compile Compile input files to TypeScript (or JavaScript)
|
|
51
|
+
--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 .)
|
|
52
|
+
--no-config Don't scan for a config file
|
|
53
|
+
--js Strip out all type annotations; default to .jsx extension
|
|
54
|
+
--ast Print the AST instead of the compiled code
|
|
55
|
+
--inline-map Generate a sourcemap
|
|
56
|
+
--no-cache Disable compiler caching (slow, for debugging)
|
|
46
57
|
|
|
47
|
-
You can use - to read from stdin or (prefixed by -o) write to stdout.
|
|
58
|
+
You can use - to read from stdin or (prefixed by -o) write to stdout.
|
|
48
59
|
|
|
49
60
|
`);
|
|
50
61
|
process.exit(0);
|
|
@@ -53,7 +64,7 @@ encoding = "utf8";
|
|
|
53
64
|
fs = require("fs/promises");
|
|
54
65
|
path = require("path");
|
|
55
66
|
parseArgs = function(args) {
|
|
56
|
-
var
|
|
67
|
+
var options, filenames, scriptArgs, i, endOfArgs, arg, char;
|
|
57
68
|
options = {};
|
|
58
69
|
Object.defineProperty(options, "run", {
|
|
59
70
|
get: function() {
|
|
@@ -78,49 +89,57 @@ parseArgs = function(args) {
|
|
|
78
89
|
while (i < args.length) {
|
|
79
90
|
arg = args[i];
|
|
80
91
|
if (/^-\w{2,}$/.test(arg)) {
|
|
81
|
-
splice
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
for (k = 0, len = ref1.length; k < len; k++) {
|
|
86
|
-
char = ref1[k];
|
|
92
|
+
args.splice(i, 1 + i - i, ...(() => {
|
|
93
|
+
const results = [];
|
|
94
|
+
for (let ref = arg.slice(1), i1 = 0, len = ref.length; i1 < len; i1++) {
|
|
95
|
+
char = ref[i1];
|
|
87
96
|
results.push(`-${char}`);
|
|
88
97
|
}
|
|
98
|
+
;
|
|
89
99
|
return results;
|
|
90
|
-
}())
|
|
100
|
+
})());
|
|
91
101
|
continue;
|
|
92
102
|
}
|
|
93
103
|
switch (arg) {
|
|
94
104
|
case "-c":
|
|
95
|
-
case "--compile":
|
|
105
|
+
case "--compile": {
|
|
96
106
|
options.compile = true;
|
|
97
107
|
break;
|
|
108
|
+
}
|
|
98
109
|
case "-o":
|
|
99
|
-
case "--output":
|
|
110
|
+
case "--output": {
|
|
100
111
|
options.output = args[++i];
|
|
101
112
|
break;
|
|
102
|
-
|
|
113
|
+
}
|
|
114
|
+
case "--config": {
|
|
103
115
|
options.config = args[++i];
|
|
104
116
|
break;
|
|
105
|
-
|
|
117
|
+
}
|
|
118
|
+
case "--no-config": {
|
|
106
119
|
options.config = false;
|
|
107
120
|
break;
|
|
108
|
-
|
|
121
|
+
}
|
|
122
|
+
case "--ast": {
|
|
109
123
|
options.ast = true;
|
|
110
124
|
break;
|
|
111
|
-
|
|
125
|
+
}
|
|
126
|
+
case "--no-cache": {
|
|
112
127
|
options.noCache = true;
|
|
113
128
|
break;
|
|
114
|
-
|
|
129
|
+
}
|
|
130
|
+
case "--inline-map": {
|
|
115
131
|
options.inlineMap = true;
|
|
116
132
|
break;
|
|
117
|
-
|
|
133
|
+
}
|
|
134
|
+
case "--js": {
|
|
118
135
|
options.js = true;
|
|
119
136
|
break;
|
|
120
|
-
|
|
137
|
+
}
|
|
138
|
+
case "--": {
|
|
121
139
|
endOfArgs(++i);
|
|
122
140
|
break;
|
|
123
|
-
|
|
141
|
+
}
|
|
142
|
+
default: {
|
|
124
143
|
if (arg.startsWith("-") && arg !== "-") {
|
|
125
144
|
throw new Error(`Invalid command-line argument ${arg}`);
|
|
126
145
|
}
|
|
@@ -129,16 +148,18 @@ parseArgs = function(args) {
|
|
|
129
148
|
} else {
|
|
130
149
|
filenames.push(arg);
|
|
131
150
|
}
|
|
151
|
+
}
|
|
132
152
|
}
|
|
133
153
|
i++;
|
|
134
154
|
}
|
|
155
|
+
;
|
|
135
156
|
return { filenames, scriptArgs, options };
|
|
136
157
|
};
|
|
137
158
|
readFiles = async function* (filenames, options) {
|
|
138
|
-
var
|
|
139
|
-
|
|
140
|
-
for (
|
|
141
|
-
filename = filenames[
|
|
159
|
+
var filename, stdin, lines, rl, content, chunk;
|
|
160
|
+
const results1 = [];
|
|
161
|
+
for (let i2 = 0, len1 = filenames.length; i2 < len1; i2++) {
|
|
162
|
+
filename = filenames[i2];
|
|
142
163
|
stdin = filename === "-";
|
|
143
164
|
try {
|
|
144
165
|
if (stdin) {
|
|
@@ -146,7 +167,7 @@ readFiles = async function* (filenames, options) {
|
|
|
146
167
|
filename = "<stdin>";
|
|
147
168
|
try {
|
|
148
169
|
filename = await fs.realpath("/dev/stdin");
|
|
149
|
-
} catch (
|
|
170
|
+
} catch (e) {
|
|
150
171
|
}
|
|
151
172
|
if (process.stdin.isTTY) {
|
|
152
173
|
lines = [];
|
|
@@ -163,82 +184,84 @@ readFiles = async function* (filenames, options) {
|
|
|
163
184
|
});
|
|
164
185
|
});
|
|
165
186
|
} else {
|
|
166
|
-
content = (await async
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
for await (chunk of ref) {
|
|
171
|
-
results1.push(chunk);
|
|
187
|
+
content = (await (async () => {
|
|
188
|
+
const results2 = [];
|
|
189
|
+
for await (chunk of process.stdin) {
|
|
190
|
+
results2.push(chunk);
|
|
172
191
|
}
|
|
173
|
-
|
|
174
|
-
|
|
192
|
+
;
|
|
193
|
+
return results2;
|
|
194
|
+
})()).join("");
|
|
175
195
|
}
|
|
176
196
|
} else {
|
|
177
197
|
content = await fs.readFile(filename, { encoding });
|
|
178
198
|
}
|
|
179
|
-
|
|
180
|
-
} catch (
|
|
181
|
-
error
|
|
182
|
-
results.push(yield { filename, error, stdin });
|
|
199
|
+
results1.push(yield { filename, content, stdin });
|
|
200
|
+
} catch (error) {
|
|
201
|
+
results1.push(yield { filename, error, stdin });
|
|
183
202
|
}
|
|
184
203
|
}
|
|
185
|
-
|
|
204
|
+
;
|
|
205
|
+
return results1;
|
|
186
206
|
};
|
|
187
207
|
repl = function(options) {
|
|
188
|
-
var nodeRepl,
|
|
189
|
-
console.log(`Civet ${version()} REPL. Enter a blank line to ${
|
|
208
|
+
var nodeRepl, vm, r;
|
|
209
|
+
console.log(`Civet ${version()} REPL. Enter a blank line to ${(() => {
|
|
190
210
|
switch (false) {
|
|
191
|
-
case !options.ast:
|
|
211
|
+
case !options.ast: {
|
|
192
212
|
return "parse";
|
|
193
|
-
|
|
213
|
+
}
|
|
214
|
+
case !options.compile: {
|
|
194
215
|
return "transpile";
|
|
195
|
-
|
|
216
|
+
}
|
|
217
|
+
default: {
|
|
196
218
|
return "execute";
|
|
219
|
+
}
|
|
197
220
|
}
|
|
198
|
-
}()} code.`);
|
|
221
|
+
})()} code.`);
|
|
199
222
|
global.quit = global.exit = function() {
|
|
200
223
|
return process.exit(0);
|
|
201
224
|
};
|
|
202
225
|
nodeRepl = require("repl");
|
|
203
226
|
vm = require("vm");
|
|
204
227
|
return r = nodeRepl.start({
|
|
205
|
-
prompt:
|
|
228
|
+
prompt: (() => {
|
|
206
229
|
switch (false) {
|
|
207
|
-
case !options.ast:
|
|
230
|
+
case !options.ast: {
|
|
208
231
|
return "\u{1F332}> ";
|
|
209
|
-
|
|
232
|
+
}
|
|
233
|
+
case !options.compile: {
|
|
210
234
|
return "\u{1F408}> ";
|
|
211
|
-
|
|
235
|
+
}
|
|
236
|
+
default: {
|
|
212
237
|
return "\u{1F431}> ";
|
|
238
|
+
}
|
|
213
239
|
}
|
|
214
|
-
}(),
|
|
240
|
+
})(),
|
|
215
241
|
writer: options.ast ? function(obj) {
|
|
216
|
-
var e;
|
|
217
242
|
try {
|
|
218
243
|
return JSON.stringify(obj, null, 2);
|
|
219
|
-
} catch (
|
|
220
|
-
e = error1;
|
|
244
|
+
} catch (e) {
|
|
221
245
|
console.log(`Failed to stringify: ${e}`);
|
|
222
246
|
return obj;
|
|
223
247
|
}
|
|
224
248
|
} : options.compile ? function(obj) {
|
|
225
249
|
if (typeof obj === "string") {
|
|
226
|
-
return obj
|
|
250
|
+
return obj?.replace(/\n*$/, "");
|
|
227
251
|
} else {
|
|
228
252
|
return obj;
|
|
229
253
|
}
|
|
230
254
|
} : void 0,
|
|
231
255
|
eval: function(input, context, filename, callback) {
|
|
232
|
-
var
|
|
256
|
+
var output, result;
|
|
233
257
|
if (input === "\n") {
|
|
234
258
|
return callback(null);
|
|
235
|
-
} else if (
|
|
259
|
+
} else if (indexOf.call(["quit\n", "exit\n", "quit()\n", "exit()\n"], input) >= 0) {
|
|
236
260
|
return process.exit(0);
|
|
237
261
|
} else if (input.endsWith("\n\n")) {
|
|
238
262
|
try {
|
|
239
263
|
output = (0, import_main.compile)(input, { ...options, filename });
|
|
240
|
-
} catch (
|
|
241
|
-
error = error1;
|
|
264
|
+
} catch (error) {
|
|
242
265
|
console.error(error);
|
|
243
266
|
return callback("");
|
|
244
267
|
}
|
|
@@ -247,8 +270,7 @@ repl = function(options) {
|
|
|
247
270
|
} else {
|
|
248
271
|
try {
|
|
249
272
|
result = vm.runInContext(output, context, { filename });
|
|
250
|
-
} catch (
|
|
251
|
-
error = error1;
|
|
273
|
+
} catch (error) {
|
|
252
274
|
return callback(error);
|
|
253
275
|
}
|
|
254
276
|
return callback(null, result);
|
|
@@ -260,16 +282,17 @@ repl = function(options) {
|
|
|
260
282
|
});
|
|
261
283
|
};
|
|
262
284
|
cli = async function() {
|
|
263
|
-
var argv,
|
|
285
|
+
var argv, filenames, scriptArgs, options, filename, error, content, stdin, output, outputPath, outputFilename, optionsPath, stat, esm, child;
|
|
264
286
|
argv = process.argv;
|
|
265
287
|
({ filenames, scriptArgs, options } = parseArgs(argv.slice(2)));
|
|
266
288
|
if (options.config !== false) {
|
|
267
|
-
|
|
268
|
-
options.config = await (0, import_config.findConfig)(process.cwd());
|
|
269
|
-
}
|
|
289
|
+
options.config ?? (options.config = await (0, import_config.findConfig)(process.cwd()));
|
|
270
290
|
}
|
|
271
291
|
if (options.config) {
|
|
272
|
-
options = {
|
|
292
|
+
options = {
|
|
293
|
+
...await (0, import_config.loadConfig)(options.config),
|
|
294
|
+
...options
|
|
295
|
+
};
|
|
273
296
|
}
|
|
274
297
|
if (!filenames.length) {
|
|
275
298
|
if (process.stdin.isTTY) {
|
|
@@ -286,10 +309,8 @@ cli = async function() {
|
|
|
286
309
|
if (options.repl) {
|
|
287
310
|
return repl(options);
|
|
288
311
|
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
for await (x of ref) {
|
|
292
|
-
({ filename, error, content, stdin } = x);
|
|
312
|
+
const results3 = [];
|
|
313
|
+
for await ({ filename, error, content, stdin } of readFiles(filenames, options)) {
|
|
293
314
|
if (error) {
|
|
294
315
|
console.error(`${filename} failed to load:`);
|
|
295
316
|
console.error(error);
|
|
@@ -297,16 +318,15 @@ cli = async function() {
|
|
|
297
318
|
}
|
|
298
319
|
try {
|
|
299
320
|
output = (0, import_main.compile)(content, { ...options, filename });
|
|
300
|
-
} catch (
|
|
301
|
-
error
|
|
302
|
-
console.error(error);
|
|
321
|
+
} catch (error2) {
|
|
322
|
+
console.error(error2);
|
|
303
323
|
continue;
|
|
304
324
|
}
|
|
305
325
|
if (options.ast) {
|
|
306
|
-
|
|
326
|
+
results3.push(process.stdout.write(JSON.stringify(output, null, 2)));
|
|
307
327
|
} else if (options.compile) {
|
|
308
328
|
if (stdin && !options.output || options.output === "-") {
|
|
309
|
-
|
|
329
|
+
results3.push(process.stdout.write(output));
|
|
310
330
|
} else {
|
|
311
331
|
outputPath = path.parse(filename);
|
|
312
332
|
delete outputPath.base;
|
|
@@ -319,10 +339,10 @@ cli = async function() {
|
|
|
319
339
|
optionsPath = path.parse(options.output);
|
|
320
340
|
try {
|
|
321
341
|
stat = await fs.stat(options.output);
|
|
322
|
-
} catch
|
|
342
|
+
} catch {
|
|
323
343
|
stat = null;
|
|
324
344
|
}
|
|
325
|
-
if (
|
|
345
|
+
if (stat?.isDirectory() || options.output.endsWith(path.sep) || options.output.endsWith("/")) {
|
|
326
346
|
outputPath.dir = options.output;
|
|
327
347
|
} else if (/^(\.[^.]+)+$/.test(optionsPath.base)) {
|
|
328
348
|
outputPath.ext = optionsPath.base;
|
|
@@ -334,17 +354,14 @@ cli = async function() {
|
|
|
334
354
|
}
|
|
335
355
|
}
|
|
336
356
|
if (outputPath.dir) {
|
|
337
|
-
fs.mkdir(outputPath.dir, {
|
|
338
|
-
recursive: true
|
|
339
|
-
});
|
|
357
|
+
fs.mkdir(outputPath.dir, { recursive: true });
|
|
340
358
|
}
|
|
341
359
|
outputFilename = path.format(outputPath);
|
|
342
360
|
try {
|
|
343
|
-
|
|
344
|
-
} catch (
|
|
345
|
-
error = error1;
|
|
361
|
+
results3.push(await fs.writeFile(outputFilename, output));
|
|
362
|
+
} catch (error2) {
|
|
346
363
|
console.error(`${outputFilename} failed to write:`);
|
|
347
|
-
|
|
364
|
+
results3.push(console.error(error2));
|
|
348
365
|
}
|
|
349
366
|
}
|
|
350
367
|
} else {
|
|
@@ -354,41 +371,43 @@ cli = async function() {
|
|
|
354
371
|
filename = `.stdin-${process.pid}.civet`;
|
|
355
372
|
try {
|
|
356
373
|
await fs.writeFile(filename, content, { encoding });
|
|
357
|
-
} catch (
|
|
358
|
-
e = error1;
|
|
374
|
+
} catch (e) {
|
|
359
375
|
console.error(`Could not write ${filename} for Civet ESM mode:`);
|
|
360
376
|
console.error(e);
|
|
361
377
|
process.exit(1);
|
|
362
378
|
}
|
|
363
379
|
}
|
|
364
|
-
child = require("child_process").spawnSync(argv[0], [
|
|
365
|
-
|
|
366
|
-
|
|
380
|
+
child = require("child_process").spawnSync(argv[0], [
|
|
381
|
+
"--loader",
|
|
382
|
+
"@danielx/civet/esm",
|
|
383
|
+
filename,
|
|
384
|
+
...scriptArgs
|
|
385
|
+
], { stdio: "inherit" });
|
|
367
386
|
if (stdin) {
|
|
368
387
|
await fs.unlink(filename);
|
|
369
388
|
}
|
|
370
|
-
|
|
389
|
+
results3.push(process.exit(child.status));
|
|
371
390
|
} else {
|
|
372
391
|
require("../register.js");
|
|
373
392
|
try {
|
|
374
393
|
module.filename = await fs.realpath(filename);
|
|
375
|
-
} catch
|
|
394
|
+
} catch {
|
|
376
395
|
module.filename = filename;
|
|
377
396
|
}
|
|
378
397
|
process.argv = ["civet", module.filename, ...scriptArgs];
|
|
379
398
|
module.paths = require("module")._nodeModulePaths(path.dirname(module.filename));
|
|
380
399
|
try {
|
|
381
|
-
|
|
382
|
-
} catch (
|
|
383
|
-
error = error1;
|
|
400
|
+
results3.push(module._compile(output, module.filename));
|
|
401
|
+
} catch (error2) {
|
|
384
402
|
console.error(`${filename} crashed while running in CJS mode:`);
|
|
385
|
-
console.error(
|
|
386
|
-
|
|
403
|
+
console.error(error2);
|
|
404
|
+
results3.push(process.exit(1));
|
|
387
405
|
}
|
|
388
406
|
}
|
|
389
407
|
}
|
|
390
408
|
}
|
|
391
|
-
|
|
409
|
+
;
|
|
410
|
+
return results3;
|
|
392
411
|
};
|
|
393
412
|
if (require.main === module) {
|
|
394
413
|
cli();
|
package/dist/config.js
CHANGED
|
@@ -22,6 +22,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
22
|
mod
|
|
23
23
|
));
|
|
24
24
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
|
|
26
|
+
// source/config.civet
|
|
25
27
|
var config_exports = {};
|
|
26
28
|
__export(config_exports, {
|
|
27
29
|
findConfig: () => findConfig,
|
|
@@ -30,60 +32,64 @@ __export(config_exports, {
|
|
|
30
32
|
module.exports = __toCommonJS(config_exports);
|
|
31
33
|
var import_path = __toESM(require("path"));
|
|
32
34
|
var import_promises = __toESM(require("fs/promises"));
|
|
33
|
-
var import_main = require("./main");
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
35
|
+
var import_main = require("./main.js");
|
|
36
|
+
var configFileNames = /* @__PURE__ */ new Set([
|
|
37
|
+
"\u{1F408}.json",
|
|
38
|
+
"\u{1F408}.civet",
|
|
39
|
+
"civetconfig.json",
|
|
40
|
+
"civetconfig.civet"
|
|
41
|
+
]);
|
|
42
|
+
async function findInDir(dirPath) {
|
|
43
|
+
const dir = await import_promises.default.opendir(dirPath);
|
|
44
|
+
for await (const entry of dir) {
|
|
40
45
|
if (entry.isDirectory() && entry.name === ".config") {
|
|
41
|
-
|
|
46
|
+
const found = await findInDir(
|
|
47
|
+
import_path.default.join(dirPath, entry.name)
|
|
48
|
+
);
|
|
49
|
+
if (found) {
|
|
50
|
+
return found;
|
|
51
|
+
}
|
|
42
52
|
}
|
|
43
53
|
if (entry.isFile()) {
|
|
44
|
-
name = entry.name.replace(/^\./, "");
|
|
45
|
-
if (
|
|
54
|
+
const name = entry.name.replace(/^\./, "");
|
|
55
|
+
if (configFileNames.has(name)) {
|
|
46
56
|
return import_path.default.join(dirPath, entry.name);
|
|
47
57
|
}
|
|
48
58
|
}
|
|
49
59
|
}
|
|
50
|
-
return
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
parent = import_path.default.dirname(curr);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
async function findConfig(startDir) {
|
|
63
|
+
let curr = startDir;
|
|
64
|
+
let parent = import_path.default.dirname(curr);
|
|
56
65
|
while (curr !== parent) {
|
|
57
|
-
|
|
66
|
+
const configPath = await findInDir(curr);
|
|
67
|
+
if (configPath) {
|
|
58
68
|
return configPath;
|
|
59
69
|
}
|
|
60
70
|
curr = parent;
|
|
61
71
|
parent = import_path.default.dirname(curr);
|
|
62
72
|
}
|
|
63
|
-
return
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
config = await import_promises.default.readFile(path2, "utf8");
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
async function loadConfig(path2) {
|
|
76
|
+
const config = await import_promises.default.readFile(path2, "utf8");
|
|
68
77
|
if (path2.endsWith(".json")) {
|
|
69
78
|
return JSON.parse(config);
|
|
70
79
|
} else {
|
|
71
|
-
js = (0, import_main.compile)(config, {
|
|
72
|
-
|
|
73
|
-
});
|
|
74
|
-
tmpPath = path2 + `.civet-tmp-${Date.now()}.mjs`;
|
|
75
|
-
await import_promises.default.writeFile(tmpPath, js);
|
|
80
|
+
const js = (0, import_main.compile)(config, { js: true });
|
|
81
|
+
let exports;
|
|
76
82
|
try {
|
|
77
|
-
exports = await import(
|
|
78
|
-
}
|
|
79
|
-
|
|
83
|
+
exports = await import(`data:text/javascript,${js}`);
|
|
84
|
+
} catch (e) {
|
|
85
|
+
console.error("Error loading config file", path2, e);
|
|
80
86
|
}
|
|
81
87
|
if (typeof exports.default !== "object" || exports.default === null) {
|
|
82
88
|
throw new Error("civet config file must export an object");
|
|
83
89
|
}
|
|
84
90
|
return exports.default;
|
|
85
91
|
}
|
|
86
|
-
}
|
|
92
|
+
}
|
|
87
93
|
// Annotate the CommonJS export names for ESM import in node:
|
|
88
94
|
0 && (module.exports = {
|
|
89
95
|
findConfig,
|