@danielx/civet 0.9.1 → 0.9.2
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 +4 -0
- package/dist/babel-plugin.js +6 -7
- package/dist/babel-plugin.mjs +3 -3
- package/dist/browser.js +4471 -9759
- package/dist/civet +11 -10
- package/dist/config.js +6 -7
- package/dist/config.mjs +3 -3
- package/dist/esbuild-plugin.js +6 -7
- package/dist/esm.mjs +1 -1
- package/dist/main.js +854 -919
- package/dist/main.mjs +856 -914
- package/dist/node-worker.mjs +29 -0
- package/dist/ts-diagnostic.js +5 -8
- package/dist/ts-diagnostic.mjs +2 -4
- package/dist/types.d.ts +4 -0
- package/dist/unplugin/unplugin.d.ts +2 -0
- package/dist/unplugin/unplugin.js +132 -129
- package/dist/unplugin/unplugin.mjs +132 -129
- package/package.json +3 -3
|
@@ -21,7 +21,7 @@ DiagnosticCategory[DiagnosticCategory["Error"] = 1] = "Error";
|
|
|
21
21
|
DiagnosticCategory[DiagnosticCategory["Suggestion"] = 2] = "Suggestion";
|
|
22
22
|
DiagnosticCategory[DiagnosticCategory["Message"] = 3] = "Message";
|
|
23
23
|
var civetExtension = /\.civet$/;
|
|
24
|
-
var isCivetTranspiled = /(\.civet)(\.[jt]sx)([?#].*)?$/;
|
|
24
|
+
var isCivetTranspiled = /(\.civet)(\.[jt]sx)?([?#].*)?$/;
|
|
25
25
|
var postfixRE = /[?#].*$/s;
|
|
26
26
|
var isWindows = os.platform() === "win32";
|
|
27
27
|
var windowsSlashRE = /\\/g;
|
|
@@ -70,12 +70,10 @@ function implicitCivet(file) {
|
|
|
70
70
|
return;
|
|
71
71
|
}
|
|
72
72
|
var rawPlugin = (options = {}, meta) => {
|
|
73
|
-
if (options.dts)
|
|
74
|
-
options.emitDeclaration = options.dts;
|
|
73
|
+
if (options.dts) options.emitDeclaration = options.dts;
|
|
75
74
|
let compileOptions = {};
|
|
76
75
|
let ts = options.ts;
|
|
77
|
-
if (options.js)
|
|
78
|
-
ts = "civet";
|
|
76
|
+
if (options.js) ts = "civet";
|
|
79
77
|
if (!(ts != null)) {
|
|
80
78
|
console.log('WARNING: You are using the default mode for `options.ts` which is `"civet"`. This mode does not support all TS features. If this is intentional, you should explicitly set `options.ts` to `"civet"`, or choose a different mode.');
|
|
81
79
|
ts = "civet";
|
|
@@ -110,7 +108,7 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
110
108
|
getCanonicalFileName: sys.useCaseSensitiveFileNames ? (f) => f : (f) => f.toLowerCase()
|
|
111
109
|
};
|
|
112
110
|
};
|
|
113
|
-
const cache = options.cache ? /* @__PURE__ */ new Map() : void 0;
|
|
111
|
+
const cache = !(options.cache === false) ? /* @__PURE__ */ new Map() : void 0;
|
|
114
112
|
const plugin = {
|
|
115
113
|
name: "unplugin-civet",
|
|
116
114
|
enforce: "pre",
|
|
@@ -123,6 +121,9 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
123
121
|
...compileOptions.parseOptions,
|
|
124
122
|
...options.parseOptions
|
|
125
123
|
};
|
|
124
|
+
if (options.threads != null) {
|
|
125
|
+
compileOptions.threads = options.threads;
|
|
126
|
+
}
|
|
126
127
|
if (transformTS || ts === "tsc") {
|
|
127
128
|
let mogrify = function(key) {
|
|
128
129
|
if (key in config && Array.isArray(config[key])) {
|
|
@@ -186,10 +187,8 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
186
187
|
readDirectory: systemReadDirectory
|
|
187
188
|
} = system;
|
|
188
189
|
system.fileExists = (filename) => {
|
|
189
|
-
if (!filename.endsWith(".civet.tsx"))
|
|
190
|
-
|
|
191
|
-
if (fsMap.has(filename))
|
|
192
|
-
return true;
|
|
190
|
+
if (!filename.endsWith(".civet.tsx")) return systemFileExists(filename);
|
|
191
|
+
if (fsMap.has(filename)) return true;
|
|
193
192
|
return systemFileExists(filename.slice(0, -4));
|
|
194
193
|
};
|
|
195
194
|
system.readDirectory = (path2) => {
|
|
@@ -226,10 +225,8 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
226
225
|
recurse(parsed.imports);
|
|
227
226
|
return modified ? JSON.stringify(parsed) : json;
|
|
228
227
|
}
|
|
229
|
-
if (!filename.endsWith(".civet.tsx"))
|
|
230
|
-
|
|
231
|
-
if (fsMap.has(filename))
|
|
232
|
-
return fsMap.get(filename);
|
|
228
|
+
if (!filename.endsWith(".civet.tsx")) return systemReadFile(filename, encoding);
|
|
229
|
+
if (fsMap.has(filename)) return fsMap.get(filename);
|
|
233
230
|
const civetFilename = filename.slice(0, -4);
|
|
234
231
|
const rawCivetSource = fs.readFileSync(civetFilename, {
|
|
235
232
|
encoding
|
|
@@ -258,11 +255,9 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
258
255
|
});
|
|
259
256
|
const diagnostics = ts2.getPreEmitDiagnostics(program).map((diagnostic) => {
|
|
260
257
|
const file = diagnostic.file;
|
|
261
|
-
if (!file)
|
|
262
|
-
return diagnostic;
|
|
258
|
+
if (!file) return diagnostic;
|
|
263
259
|
const sourceMap = sourceMaps.get(file.fileName);
|
|
264
|
-
if (!sourceMap)
|
|
265
|
-
return diagnostic;
|
|
260
|
+
if (!sourceMap) return diagnostic;
|
|
266
261
|
const sourcemapLines = sourceMap.data.lines;
|
|
267
262
|
const range = remapRange(
|
|
268
263
|
{
|
|
@@ -291,14 +286,10 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
291
286
|
if (options.typecheck) {
|
|
292
287
|
let failures = [];
|
|
293
288
|
if (typeof options.typecheck === "string") {
|
|
294
|
-
if (options.typecheck.includes("error"))
|
|
295
|
-
|
|
296
|
-
if (options.typecheck.includes("
|
|
297
|
-
|
|
298
|
-
if (options.typecheck.includes("suggestion"))
|
|
299
|
-
failures.push(DiagnosticCategory.Suggestion);
|
|
300
|
-
if (options.typecheck.includes("message"))
|
|
301
|
-
failures.push(DiagnosticCategory.Message);
|
|
289
|
+
if (options.typecheck.includes("error")) failures.push(DiagnosticCategory.Error);
|
|
290
|
+
if (options.typecheck.includes("warning")) failures.push(DiagnosticCategory.Warning);
|
|
291
|
+
if (options.typecheck.includes("suggestion")) failures.push(DiagnosticCategory.Suggestion);
|
|
292
|
+
if (options.typecheck.includes("message")) failures.push(DiagnosticCategory.Message);
|
|
302
293
|
if (options.typecheck.includes("all")) {
|
|
303
294
|
failures = { includes: () => true };
|
|
304
295
|
}
|
|
@@ -378,8 +369,7 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
378
369
|
if (aliasResolver != null) {
|
|
379
370
|
id = aliasResolver(id);
|
|
380
371
|
}
|
|
381
|
-
if (/\0/.test(id))
|
|
382
|
-
return null;
|
|
372
|
+
if (/\0/.test(id)) return null;
|
|
383
373
|
if (plugin.__virtualModulePrefix && importer?.startsWith(plugin.__virtualModulePrefix)) {
|
|
384
374
|
importer = decodeURIComponent(importer.slice(plugin.__virtualModulePrefix.length));
|
|
385
375
|
}
|
|
@@ -393,14 +383,11 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
393
383
|
}
|
|
394
384
|
;
|
|
395
385
|
let resolvedId = ref2;
|
|
396
|
-
if (!resolvedId)
|
|
397
|
-
return null;
|
|
386
|
+
if (!resolvedId) return null;
|
|
398
387
|
if (!resolvedId.endsWith(".civet")) {
|
|
399
|
-
if (!implicitExtension)
|
|
400
|
-
return null;
|
|
388
|
+
if (!implicitExtension) return null;
|
|
401
389
|
const implicitId = implicitCivet(resolvedId);
|
|
402
|
-
if (!implicitId)
|
|
403
|
-
return null;
|
|
390
|
+
if (!implicitId) return null;
|
|
404
391
|
resolvedId = implicitId;
|
|
405
392
|
}
|
|
406
393
|
if (options2.scan && meta.framework === "vite") {
|
|
@@ -418,114 +405,130 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
418
405
|
}
|
|
419
406
|
const basename = id.slice(0, match.index + match[1].length);
|
|
420
407
|
const filename = path.resolve(rootDir, basename);
|
|
421
|
-
let mtime;
|
|
422
|
-
if (cache) {
|
|
408
|
+
let mtime, cached, resolve;
|
|
409
|
+
if (cache != null) {
|
|
423
410
|
mtime = (await fs.promises.stat(filename)).mtimeMs;
|
|
424
|
-
|
|
411
|
+
cached = cache?.get(filename);
|
|
425
412
|
if (cached && cached.mtime === mtime) {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
let sourceMap;
|
|
433
|
-
const civetOptions = {
|
|
434
|
-
...compileOptions,
|
|
435
|
-
filename: id,
|
|
436
|
-
errors: []
|
|
437
|
-
};
|
|
438
|
-
function checkErrors() {
|
|
439
|
-
if (civetOptions.errors.length) {
|
|
440
|
-
throw new civet.ParseErrors(civetOptions.errors);
|
|
413
|
+
if (cached.promise) {
|
|
414
|
+
await cached.promise;
|
|
415
|
+
}
|
|
416
|
+
if (cached.result) {
|
|
417
|
+
return cached.result;
|
|
418
|
+
}
|
|
441
419
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
}
|
|
445
|
-
const ast = await civet.compile(rawCivetSource, {
|
|
446
|
-
...civetOptions,
|
|
447
|
-
ast: true
|
|
448
|
-
});
|
|
449
|
-
const civetSourceMap = SourceMap(rawCivetSource);
|
|
450
|
-
if (ts === "civet") {
|
|
451
|
-
compiled = await civet.generate(ast, {
|
|
452
|
-
...civetOptions,
|
|
453
|
-
js: true,
|
|
454
|
-
sourceMap: civetSourceMap
|
|
420
|
+
const promise = new Promise((r) => {
|
|
421
|
+
resolve = r;
|
|
455
422
|
});
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
423
|
+
cache.set(filename, cached = { mtime, promise });
|
|
424
|
+
}
|
|
425
|
+
try {
|
|
426
|
+
let checkErrors = function() {
|
|
427
|
+
if (civetOptions.errors.length) {
|
|
428
|
+
throw new civet.ParseErrors(civetOptions.errors);
|
|
429
|
+
}
|
|
430
|
+
;
|
|
431
|
+
return;
|
|
432
|
+
};
|
|
433
|
+
this.addWatchFile(filename);
|
|
434
|
+
let compiled;
|
|
435
|
+
let sourceMap;
|
|
436
|
+
const civetOptions = {
|
|
437
|
+
...compileOptions,
|
|
438
|
+
filename: id,
|
|
439
|
+
errors: []
|
|
440
|
+
};
|
|
441
|
+
const rawCivetSource = await fs.promises.readFile(filename, "utf-8");
|
|
442
|
+
const ast = await civet.compile(rawCivetSource, {
|
|
460
443
|
...civetOptions,
|
|
461
|
-
|
|
462
|
-
sourceMap: civetSourceMap
|
|
444
|
+
ast: true
|
|
463
445
|
});
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
446
|
+
const civetSourceMap = SourceMap(rawCivetSource);
|
|
447
|
+
if (ts === "civet") {
|
|
448
|
+
compiled = await civet.generate(ast, {
|
|
449
|
+
...civetOptions,
|
|
450
|
+
js: true,
|
|
451
|
+
sourceMap: civetSourceMap
|
|
452
|
+
});
|
|
453
|
+
sourceMap = civetSourceMap;
|
|
454
|
+
checkErrors();
|
|
455
|
+
} else {
|
|
456
|
+
const compiledTS = await civet.generate(ast, {
|
|
457
|
+
...civetOptions,
|
|
458
|
+
js: false,
|
|
459
|
+
sourceMap: civetSourceMap
|
|
460
|
+
});
|
|
461
|
+
checkErrors();
|
|
462
|
+
switch (ts) {
|
|
463
|
+
case "esbuild": {
|
|
464
|
+
const esbuildTransform = (await import("esbuild")).transform;
|
|
465
|
+
const result = await esbuildTransform(compiledTS, {
|
|
466
|
+
jsx: "preserve",
|
|
467
|
+
loader: "tsx",
|
|
468
|
+
sourcefile: id,
|
|
469
|
+
sourcemap: "external"
|
|
470
|
+
});
|
|
471
|
+
compiled = result.code;
|
|
472
|
+
sourceMap = result.map;
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
475
|
+
case "tsc": {
|
|
476
|
+
const tsTranspile = (await tsPromise).transpileModule;
|
|
477
|
+
const result = tsTranspile(compiledTS, {
|
|
478
|
+
compilerOptions: compilerOptionsWithSourceMap
|
|
479
|
+
});
|
|
480
|
+
compiled = result.outputText;
|
|
481
|
+
sourceMap = result.sourceMapText;
|
|
482
|
+
break;
|
|
483
|
+
}
|
|
484
|
+
case "preserve": {
|
|
485
|
+
compiled = compiledTS;
|
|
486
|
+
break;
|
|
487
|
+
}
|
|
477
488
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
489
|
+
}
|
|
490
|
+
if (transformTS) {
|
|
491
|
+
for (let ref3 = lib.gatherRecursive(ast, ($) => $.type === "ModuleSpecifier"), i = 0, len = ref3.length; i < len; i++) {
|
|
492
|
+
const _spec = ref3[i];
|
|
493
|
+
const spec = _spec;
|
|
494
|
+
if (spec.module?.input) {
|
|
495
|
+
spec.module.token = spec.module.input.replace(/\.([mc])?ts(['"])$/, ".$1js$2");
|
|
496
|
+
}
|
|
486
497
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
498
|
+
const compiledTS = await civet.generate(ast, {
|
|
499
|
+
...civetOptions,
|
|
500
|
+
js: false,
|
|
501
|
+
sourceMap: civetSourceMap
|
|
502
|
+
});
|
|
503
|
+
checkErrors();
|
|
504
|
+
const tsx = filename + ".tsx";
|
|
505
|
+
fsMap.set(tsx, compiledTS);
|
|
506
|
+
sourceMaps.set(tsx, civetSourceMap);
|
|
507
|
+
const slashed = slash(tsx);
|
|
508
|
+
if (!(tsx === slashed)) {
|
|
509
|
+
fsMap.set(slashed, compiledTS);
|
|
510
|
+
sourceMaps.set(slashed, civetSourceMap);
|
|
490
511
|
}
|
|
491
512
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
513
|
+
const jsonSourceMap = sourceMap && (typeof sourceMap === "string" ? JSON.parse(sourceMap) : sourceMap.json(
|
|
514
|
+
path.basename(id.replace(/\.[jt]sx$/, "")),
|
|
515
|
+
path.basename(id)
|
|
516
|
+
));
|
|
517
|
+
let transformed = {
|
|
518
|
+
code: compiled,
|
|
519
|
+
map: jsonSourceMap
|
|
520
|
+
};
|
|
521
|
+
if (options.transformOutput) {
|
|
522
|
+
transformed = await options.transformOutput(transformed.code, id);
|
|
500
523
|
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
sourceMap: civetSourceMap
|
|
505
|
-
});
|
|
506
|
-
checkErrors();
|
|
507
|
-
const tsx = filename + ".tsx";
|
|
508
|
-
fsMap.set(tsx, compiledTS);
|
|
509
|
-
sourceMaps.set(tsx, civetSourceMap);
|
|
510
|
-
const slashed = slash(tsx);
|
|
511
|
-
if (!(tsx === slashed)) {
|
|
512
|
-
fsMap.set(slashed, compiledTS);
|
|
513
|
-
sourceMaps.set(slashed, civetSourceMap);
|
|
524
|
+
if (cached != null) {
|
|
525
|
+
cached.result = transformed;
|
|
526
|
+
delete cached.promise;
|
|
514
527
|
}
|
|
528
|
+
return transformed;
|
|
529
|
+
} finally {
|
|
530
|
+
resolve?.();
|
|
515
531
|
}
|
|
516
|
-
const jsonSourceMap = sourceMap && (typeof sourceMap === "string" ? JSON.parse(sourceMap) : sourceMap.json(
|
|
517
|
-
path.basename(id.replace(/\.[jt]sx$/, "")),
|
|
518
|
-
path.basename(id)
|
|
519
|
-
));
|
|
520
|
-
let transformed = {
|
|
521
|
-
code: compiled,
|
|
522
|
-
map: jsonSourceMap
|
|
523
|
-
};
|
|
524
|
-
if (options.transformOutput) {
|
|
525
|
-
transformed = await options.transformOutput(transformed.code, id);
|
|
526
|
-
}
|
|
527
|
-
cache?.set(filename, { mtime, result: transformed });
|
|
528
|
-
return transformed;
|
|
529
532
|
},
|
|
530
533
|
esbuild: {
|
|
531
534
|
config(options2) {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielx/civet",
|
|
3
3
|
"type": "commonjs",
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.2",
|
|
5
5
|
"description": "CoffeeScript style syntax for TypeScript",
|
|
6
6
|
"main": "dist/main.js",
|
|
7
7
|
"module": "dist/main.mjs",
|
|
@@ -100,9 +100,9 @@
|
|
|
100
100
|
"@prettier/sync": "^0.5.2",
|
|
101
101
|
"@types/assert": "^1.5.6",
|
|
102
102
|
"@types/mocha": "^10.0.8",
|
|
103
|
-
"@types/node": "^
|
|
103
|
+
"@types/node": "^22.10.2",
|
|
104
104
|
"c8": "^7.12.0",
|
|
105
|
-
"esbuild": "0.
|
|
105
|
+
"esbuild": "0.24.0",
|
|
106
106
|
"marked": "^4.2.4",
|
|
107
107
|
"mocha": "^10.7.3",
|
|
108
108
|
"prettier": "^3.2.5",
|