@danielx/civet 0.11.7 → 0.11.9
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/CHANGELOG.md +63 -0
- package/README.md +3 -7
- package/dist/browser.js +23987 -9251
- package/dist/browser.min.js +1 -0
- package/dist/cache.js +128 -0
- package/dist/cache.mjs +89 -0
- package/dist/civet +56 -8
- package/dist/main.js +37701 -12214
- package/dist/main.mjs +37701 -12214
- package/dist/ts-diagnostic.js +41 -0
- package/dist/ts-diagnostic.mjs +40 -0
- package/dist/ts-service/index.js +1239 -0
- package/dist/ts-service/index.js.map +7 -0
- package/dist/ts-service/index.mjs +1188 -0
- package/dist/ts-service/index.mjs.map +7 -0
- package/dist/types.d.ts +0 -14
- package/dist/unplugin/unplugin.d.ts +28 -1
- package/dist/unplugin/unplugin.js +269 -276
- package/dist/unplugin/unplugin.mjs +270 -282
- package/package.json +43 -26
- package/dist/esbuild-plugin.js +0 -131
package/dist/cache.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// source/cache.civet
|
|
31
|
+
var cache_exports = {};
|
|
32
|
+
__export(cache_exports, {
|
|
33
|
+
createDiskCache: () => createDiskCache,
|
|
34
|
+
createMemoryCache: () => createMemoryCache,
|
|
35
|
+
hashParts: () => hashParts,
|
|
36
|
+
makeCacheKey: () => makeCacheKey,
|
|
37
|
+
stableStringify: () => stableStringify
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(cache_exports);
|
|
40
|
+
var crypto = __toESM(require("node:crypto"));
|
|
41
|
+
var fs = __toESM(require("node:fs"));
|
|
42
|
+
var path = __toESM(require("node:path"));
|
|
43
|
+
function hashParts(parts) {
|
|
44
|
+
const hash = crypto.createHash("sha1");
|
|
45
|
+
for (const part of parts) {
|
|
46
|
+
hash.update(part).update("\0");
|
|
47
|
+
}
|
|
48
|
+
return hash.digest("hex");
|
|
49
|
+
}
|
|
50
|
+
function stableStringify(value) {
|
|
51
|
+
return JSON.stringify(value, (_key, val) => {
|
|
52
|
+
if (typeof val === "function") {
|
|
53
|
+
return void 0;
|
|
54
|
+
}
|
|
55
|
+
if (val && typeof val === "object" && !Array.isArray(val)) {
|
|
56
|
+
const sorted = {};
|
|
57
|
+
for (const key of Object.keys(val).sort()) {
|
|
58
|
+
sorted[key] = val[key];
|
|
59
|
+
}
|
|
60
|
+
return sorted;
|
|
61
|
+
}
|
|
62
|
+
return val;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
function makeCacheKey(input) {
|
|
66
|
+
const resolved = path.resolve(input.sourcePath).replace(/\\/g, "/");
|
|
67
|
+
return hashParts([
|
|
68
|
+
input.source,
|
|
69
|
+
input.compilerName,
|
|
70
|
+
input.compilerVersion,
|
|
71
|
+
input.civetVersion ?? "",
|
|
72
|
+
input.civetMtime ?? "",
|
|
73
|
+
resolved,
|
|
74
|
+
stableStringify(input.options ?? {})
|
|
75
|
+
]);
|
|
76
|
+
}
|
|
77
|
+
function createMemoryCache() {
|
|
78
|
+
const store = /* @__PURE__ */ new Map();
|
|
79
|
+
return {
|
|
80
|
+
get(key) {
|
|
81
|
+
return store.get(key);
|
|
82
|
+
},
|
|
83
|
+
set(key, value) {
|
|
84
|
+
store.set(key, value);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function createDiskCache(dir) {
|
|
90
|
+
try {
|
|
91
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
92
|
+
} catch {
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
get(key) {
|
|
96
|
+
const target = path.join(dir, key);
|
|
97
|
+
try {
|
|
98
|
+
const content = fs.readFileSync(target, "utf8");
|
|
99
|
+
try {
|
|
100
|
+
const now = /* @__PURE__ */ new Date();
|
|
101
|
+
fs.utimesSync(target, now, now);
|
|
102
|
+
} catch {
|
|
103
|
+
}
|
|
104
|
+
return content;
|
|
105
|
+
} catch {
|
|
106
|
+
return void 0;
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
set(key, value) {
|
|
110
|
+
const target = path.join(dir, key);
|
|
111
|
+
try {
|
|
112
|
+
const tmp = `${target}.tmp.${process.pid}`;
|
|
113
|
+
fs.writeFileSync(tmp, value);
|
|
114
|
+
return fs.renameSync(tmp, target);
|
|
115
|
+
} catch {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
+
0 && (module.exports = {
|
|
123
|
+
createDiskCache,
|
|
124
|
+
createMemoryCache,
|
|
125
|
+
hashParts,
|
|
126
|
+
makeCacheKey,
|
|
127
|
+
stableStringify
|
|
128
|
+
});
|
package/dist/cache.mjs
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// source/cache.civet
|
|
2
|
+
import * as crypto from "node:crypto";
|
|
3
|
+
import * as fs from "node:fs";
|
|
4
|
+
import * as path from "node:path";
|
|
5
|
+
function hashParts(parts) {
|
|
6
|
+
const hash = crypto.createHash("sha1");
|
|
7
|
+
for (const part of parts) {
|
|
8
|
+
hash.update(part).update("\0");
|
|
9
|
+
}
|
|
10
|
+
return hash.digest("hex");
|
|
11
|
+
}
|
|
12
|
+
function stableStringify(value) {
|
|
13
|
+
return JSON.stringify(value, (_key, val) => {
|
|
14
|
+
if (typeof val === "function") {
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
if (val && typeof val === "object" && !Array.isArray(val)) {
|
|
18
|
+
const sorted = {};
|
|
19
|
+
for (const key of Object.keys(val).sort()) {
|
|
20
|
+
sorted[key] = val[key];
|
|
21
|
+
}
|
|
22
|
+
return sorted;
|
|
23
|
+
}
|
|
24
|
+
return val;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function makeCacheKey(input) {
|
|
28
|
+
const resolved = path.resolve(input.sourcePath).replace(/\\/g, "/");
|
|
29
|
+
return hashParts([
|
|
30
|
+
input.source,
|
|
31
|
+
input.compilerName,
|
|
32
|
+
input.compilerVersion,
|
|
33
|
+
input.civetVersion ?? "",
|
|
34
|
+
input.civetMtime ?? "",
|
|
35
|
+
resolved,
|
|
36
|
+
stableStringify(input.options ?? {})
|
|
37
|
+
]);
|
|
38
|
+
}
|
|
39
|
+
function createMemoryCache() {
|
|
40
|
+
const store = /* @__PURE__ */ new Map();
|
|
41
|
+
return {
|
|
42
|
+
get(key) {
|
|
43
|
+
return store.get(key);
|
|
44
|
+
},
|
|
45
|
+
set(key, value) {
|
|
46
|
+
store.set(key, value);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function createDiskCache(dir) {
|
|
52
|
+
try {
|
|
53
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
get(key) {
|
|
58
|
+
const target = path.join(dir, key);
|
|
59
|
+
try {
|
|
60
|
+
const content = fs.readFileSync(target, "utf8");
|
|
61
|
+
try {
|
|
62
|
+
const now = /* @__PURE__ */ new Date();
|
|
63
|
+
fs.utimesSync(target, now, now);
|
|
64
|
+
} catch {
|
|
65
|
+
}
|
|
66
|
+
return content;
|
|
67
|
+
} catch {
|
|
68
|
+
return void 0;
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
set(key, value) {
|
|
72
|
+
const target = path.join(dir, key);
|
|
73
|
+
try {
|
|
74
|
+
const tmp = `${target}.tmp.${process.pid}`;
|
|
75
|
+
fs.writeFileSync(tmp, value);
|
|
76
|
+
return fs.renameSync(tmp, target);
|
|
77
|
+
} catch {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
export {
|
|
84
|
+
createDiskCache,
|
|
85
|
+
createMemoryCache,
|
|
86
|
+
hashParts,
|
|
87
|
+
makeCacheKey,
|
|
88
|
+
stableStringify
|
|
89
|
+
};
|
package/dist/civet
CHANGED
|
@@ -42,11 +42,9 @@ __export(cli_exports, {
|
|
|
42
42
|
module.exports = __toCommonJS(cli_exports);
|
|
43
43
|
var import_main = require("./main.js");
|
|
44
44
|
var import_config = require("./config.js");
|
|
45
|
-
var import_unplugin = require("./unplugin/unplugin.js");
|
|
46
45
|
var import_promises = __toESM(require("node:fs/promises"));
|
|
47
46
|
var import_node_path = __toESM(require("node:path"));
|
|
48
47
|
var import_meta = {};
|
|
49
|
-
var unplugin;
|
|
50
48
|
async function version() {
|
|
51
49
|
if (import_meta.url) {
|
|
52
50
|
const { createRequire } = await import("node:module");
|
|
@@ -177,6 +175,28 @@ async function parseArgs(args, isTTY = process.stdin.isTTY) {
|
|
|
177
175
|
options.typecheck = true;
|
|
178
176
|
break;
|
|
179
177
|
}
|
|
178
|
+
case "--max-errors": {
|
|
179
|
+
const n = parseInt(args[++i] ?? "", 10);
|
|
180
|
+
if (isNaN(n) || n < 0) {
|
|
181
|
+
console.error(`Invalid value for --max-errors: ${args[i]}`);
|
|
182
|
+
errors++;
|
|
183
|
+
} else {
|
|
184
|
+
options.maxErrors = n;
|
|
185
|
+
}
|
|
186
|
+
;
|
|
187
|
+
break;
|
|
188
|
+
}
|
|
189
|
+
case "--tsbuildinfo": {
|
|
190
|
+
const v = args[++i];
|
|
191
|
+
if (!v || v.startsWith("-")) {
|
|
192
|
+
console.error(`Missing PATH after --tsbuildinfo`);
|
|
193
|
+
errors++;
|
|
194
|
+
} else {
|
|
195
|
+
options.tsBuildInfoFile = v;
|
|
196
|
+
}
|
|
197
|
+
;
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
180
200
|
case "--emit-declaration":
|
|
181
201
|
case "--emitDeclaration": {
|
|
182
202
|
options.emitDeclaration = true;
|
|
@@ -203,6 +223,12 @@ async function parseArgs(args, isTTY = process.stdin.isTTY) {
|
|
|
203
223
|
if (options.typecheck || options.emitDeclaration) {
|
|
204
224
|
options.typescript = true;
|
|
205
225
|
}
|
|
226
|
+
if (options.maxErrors == null && process.env.CIVET_TYPECHECK_MAX_ERRORS) {
|
|
227
|
+
const parsed = parseInt(process.env.CIVET_TYPECHECK_MAX_ERRORS, 10);
|
|
228
|
+
if (!isNaN(parsed)) {
|
|
229
|
+
options.maxErrors = parsed;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
206
232
|
if (!(filenames.length || options.typescript || options.eval)) {
|
|
207
233
|
if (isTTY) {
|
|
208
234
|
options.repl = true;
|
|
@@ -232,6 +258,9 @@ async function parseArgs(args, isTTY = process.stdin.isTTY) {
|
|
|
232
258
|
options.outputExt = optionsPath.ext;
|
|
233
259
|
}
|
|
234
260
|
}
|
|
261
|
+
if (options.outputExt && /\.[cm]?jsx?$/i.test(options.outputExt)) {
|
|
262
|
+
options.js ??= true;
|
|
263
|
+
}
|
|
235
264
|
;
|
|
236
265
|
(options.parseOptions ??= {}).rewriteCivetImports ??= options.outputExt ?? ".civet.jsx";
|
|
237
266
|
if (errors) {
|
|
@@ -389,7 +418,7 @@ async function repl(args, options) {
|
|
|
389
418
|
input = input.replace(/\r/g, "\n");
|
|
390
419
|
if (input === "\n") {
|
|
391
420
|
return callback(null, void 0);
|
|
392
|
-
} else if (
|
|
421
|
+
} else if (["quit\n", "exit\n", "quit()\n", "exit()\n"].includes(input)) {
|
|
393
422
|
return process.exit(0);
|
|
394
423
|
} else if (input.endsWith("\n\n")) {
|
|
395
424
|
let showError2 = function(error) {
|
|
@@ -496,6 +525,7 @@ ${" ".repeat(error.column - 1)}^ ${error.header}`);
|
|
|
496
525
|
return;
|
|
497
526
|
}
|
|
498
527
|
async function cli(args = process.argv.slice(2)) {
|
|
528
|
+
let unplugin;
|
|
499
529
|
let { filenames, scriptArgs, options } = await parseArgs(args);
|
|
500
530
|
if (options.version) {
|
|
501
531
|
console.log(await version());
|
|
@@ -537,6 +567,10 @@ Options:
|
|
|
537
567
|
--inline-map Generate a sourcemap
|
|
538
568
|
--no-cache Disable compiler caching (slow, for debugging)
|
|
539
569
|
--typecheck Run TypeScript and output diagnostics
|
|
570
|
+
--max-errors N Allow up to N TS diagnostics before exiting non-zero
|
|
571
|
+
(also: CIVET_TYPECHECK_MAX_ERRORS env)
|
|
572
|
+
--tsbuildinfo PATH Persist incremental TS analysis state to PATH for
|
|
573
|
+
faster repeat typechecks
|
|
540
574
|
--emit-declaration Run TypeScript and emit .d.ts files (if no errors)
|
|
541
575
|
--trace XX Log detailed parsing notes to a file, for parser debugging
|
|
542
576
|
|
|
@@ -565,6 +599,7 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
|
|
|
565
599
|
}
|
|
566
600
|
}
|
|
567
601
|
if (options.typescript) {
|
|
602
|
+
const { rawPlugin } = await import("./unplugin/unplugin.js");
|
|
568
603
|
if (!import_meta.url) {
|
|
569
604
|
try {
|
|
570
605
|
require("typescript");
|
|
@@ -591,10 +626,13 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
|
|
|
591
626
|
...options,
|
|
592
627
|
ts: options.js ? "civet" : "preserve",
|
|
593
628
|
outputExtension: ".tsx",
|
|
594
|
-
declarationExtension: options.outputExt?.replace(/\.[jt]sx?$/i, ".d.ts")
|
|
629
|
+
declarationExtension: options.outputExt?.replace(/\.[jt]sx?$/i, ".d.ts"),
|
|
630
|
+
// No filenames + --typecheck: lint the project. Filenames given:
|
|
631
|
+
// scope to those (matches the bundler-driven default).
|
|
632
|
+
discoverProjectFiles: filenames.length === 0
|
|
595
633
|
};
|
|
596
|
-
(unpluginOptions.parseOptions ??= {}).rewriteCivetImports =
|
|
597
|
-
unplugin =
|
|
634
|
+
(unpluginOptions.parseOptions ??= {}).rewriteCivetImports = false;
|
|
635
|
+
unplugin = rawPlugin(unpluginOptions, { framework: "civet-cli" });
|
|
598
636
|
await unplugin.buildStart();
|
|
599
637
|
}
|
|
600
638
|
if (options.run) {
|
|
@@ -743,11 +781,21 @@ You can override this behavior via: --civet rewriteCivetImports=.ext
|
|
|
743
781
|
process.exitCode = Math.min(255, errors);
|
|
744
782
|
if (unplugin != null) {
|
|
745
783
|
try {
|
|
746
|
-
|
|
784
|
+
const pending = [];
|
|
785
|
+
await unplugin.buildEnd.call({
|
|
747
786
|
emitFile({ source, fileName }) {
|
|
748
|
-
|
|
787
|
+
pending.push((async () => {
|
|
788
|
+
{
|
|
789
|
+
const outputDir = import_node_path.default.dirname(fileName);
|
|
790
|
+
if (!(outputDir === ".")) {
|
|
791
|
+
await import_promises.default.mkdir(outputDir, { recursive: true });
|
|
792
|
+
}
|
|
793
|
+
return await import_promises.default.writeFile(fileName, source);
|
|
794
|
+
}
|
|
795
|
+
})());
|
|
749
796
|
}
|
|
750
797
|
}, !filenames.length);
|
|
798
|
+
return await Promise.all(pending);
|
|
751
799
|
} catch (error) {
|
|
752
800
|
let ref5;
|
|
753
801
|
if (ref5 = error.message.match(/Aborting build because of (\d+) TypeScript diagnostic/)) {
|