@danielx/civet 0.9.1 → 0.9.3
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 +11 -0
- package/dist/babel-plugin.js +6 -7
- package/dist/babel-plugin.mjs +3 -3
- package/dist/browser.js +4719 -9822
- 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 +1175 -995
- package/dist/main.mjs +1179 -992
- 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 +135 -142
- package/dist/unplugin/unplugin.mjs +135 -142
- package/package.json +4 -4
|
@@ -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
|
}
|
|
@@ -346,16 +337,6 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
346
337
|
compilerOptions.outDir ?? process.cwd(),
|
|
347
338
|
filePath
|
|
348
339
|
);
|
|
349
|
-
if (meta.framework === "esbuild") {
|
|
350
|
-
fs.mkdirSync(
|
|
351
|
-
path.dirname(
|
|
352
|
-
path.resolve(esbuildOptions.outdir, pathFromDistDir)
|
|
353
|
-
),
|
|
354
|
-
{
|
|
355
|
-
recursive: true
|
|
356
|
-
}
|
|
357
|
-
);
|
|
358
|
-
}
|
|
359
340
|
return this.emitFile({
|
|
360
341
|
source: content,
|
|
361
342
|
fileName: pathFromDistDir,
|
|
@@ -378,11 +359,7 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
378
359
|
if (aliasResolver != null) {
|
|
379
360
|
id = aliasResolver(id);
|
|
380
361
|
}
|
|
381
|
-
if (/\0/.test(id))
|
|
382
|
-
return null;
|
|
383
|
-
if (plugin.__virtualModulePrefix && importer?.startsWith(plugin.__virtualModulePrefix)) {
|
|
384
|
-
importer = decodeURIComponent(importer.slice(plugin.__virtualModulePrefix.length));
|
|
385
|
-
}
|
|
362
|
+
if (/\0/.test(id)) return null;
|
|
386
363
|
let postfix;
|
|
387
364
|
({ id, postfix } = cleanCivetId(id));
|
|
388
365
|
let ref2;
|
|
@@ -393,14 +370,11 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
393
370
|
}
|
|
394
371
|
;
|
|
395
372
|
let resolvedId = ref2;
|
|
396
|
-
if (!resolvedId)
|
|
397
|
-
return null;
|
|
373
|
+
if (!resolvedId) return null;
|
|
398
374
|
if (!resolvedId.endsWith(".civet")) {
|
|
399
|
-
if (!implicitExtension)
|
|
400
|
-
return null;
|
|
375
|
+
if (!implicitExtension) return null;
|
|
401
376
|
const implicitId = implicitCivet(resolvedId);
|
|
402
|
-
if (!implicitId)
|
|
403
|
-
return null;
|
|
377
|
+
if (!implicitId) return null;
|
|
404
378
|
resolvedId = implicitId;
|
|
405
379
|
}
|
|
406
380
|
if (options2.scan && meta.framework === "vite") {
|
|
@@ -418,114 +392,130 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
418
392
|
}
|
|
419
393
|
const basename = id.slice(0, match.index + match[1].length);
|
|
420
394
|
const filename = path.resolve(rootDir, basename);
|
|
421
|
-
let mtime;
|
|
422
|
-
if (cache) {
|
|
395
|
+
let mtime, cached, resolve;
|
|
396
|
+
if (cache != null) {
|
|
423
397
|
mtime = (await fs.promises.stat(filename)).mtimeMs;
|
|
424
|
-
|
|
398
|
+
cached = cache?.get(filename);
|
|
425
399
|
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);
|
|
400
|
+
if (cached.promise) {
|
|
401
|
+
await cached.promise;
|
|
402
|
+
}
|
|
403
|
+
if (cached.result) {
|
|
404
|
+
return cached.result;
|
|
405
|
+
}
|
|
441
406
|
}
|
|
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
|
|
407
|
+
const promise = new Promise((r) => {
|
|
408
|
+
resolve = r;
|
|
455
409
|
});
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
410
|
+
cache.set(filename, cached = { mtime, promise });
|
|
411
|
+
}
|
|
412
|
+
try {
|
|
413
|
+
let checkErrors = function() {
|
|
414
|
+
if (civetOptions.errors.length) {
|
|
415
|
+
throw new civet.ParseErrors(civetOptions.errors);
|
|
416
|
+
}
|
|
417
|
+
;
|
|
418
|
+
return;
|
|
419
|
+
};
|
|
420
|
+
this.addWatchFile(filename);
|
|
421
|
+
let compiled;
|
|
422
|
+
let sourceMap;
|
|
423
|
+
const civetOptions = {
|
|
424
|
+
...compileOptions,
|
|
425
|
+
filename: id,
|
|
426
|
+
errors: []
|
|
427
|
+
};
|
|
428
|
+
const rawCivetSource = await fs.promises.readFile(filename, "utf-8");
|
|
429
|
+
const ast = await civet.compile(rawCivetSource, {
|
|
460
430
|
...civetOptions,
|
|
461
|
-
|
|
462
|
-
sourceMap: civetSourceMap
|
|
431
|
+
ast: true
|
|
463
432
|
});
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
433
|
+
const civetSourceMap = SourceMap(rawCivetSource);
|
|
434
|
+
if (ts === "civet") {
|
|
435
|
+
compiled = await civet.generate(ast, {
|
|
436
|
+
...civetOptions,
|
|
437
|
+
js: true,
|
|
438
|
+
sourceMap: civetSourceMap
|
|
439
|
+
});
|
|
440
|
+
sourceMap = civetSourceMap;
|
|
441
|
+
checkErrors();
|
|
442
|
+
} else {
|
|
443
|
+
const compiledTS = await civet.generate(ast, {
|
|
444
|
+
...civetOptions,
|
|
445
|
+
js: false,
|
|
446
|
+
sourceMap: civetSourceMap
|
|
447
|
+
});
|
|
448
|
+
checkErrors();
|
|
449
|
+
switch (ts) {
|
|
450
|
+
case "esbuild": {
|
|
451
|
+
const esbuildTransform = (await import("esbuild")).transform;
|
|
452
|
+
const result = await esbuildTransform(compiledTS, {
|
|
453
|
+
jsx: "preserve",
|
|
454
|
+
loader: "tsx",
|
|
455
|
+
sourcefile: id,
|
|
456
|
+
sourcemap: "external"
|
|
457
|
+
});
|
|
458
|
+
compiled = result.code;
|
|
459
|
+
sourceMap = result.map;
|
|
460
|
+
break;
|
|
461
|
+
}
|
|
462
|
+
case "tsc": {
|
|
463
|
+
const tsTranspile = (await tsPromise).transpileModule;
|
|
464
|
+
const result = tsTranspile(compiledTS, {
|
|
465
|
+
compilerOptions: compilerOptionsWithSourceMap
|
|
466
|
+
});
|
|
467
|
+
compiled = result.outputText;
|
|
468
|
+
sourceMap = result.sourceMapText;
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
471
|
+
case "preserve": {
|
|
472
|
+
compiled = compiledTS;
|
|
473
|
+
break;
|
|
474
|
+
}
|
|
477
475
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
476
|
+
}
|
|
477
|
+
if (transformTS) {
|
|
478
|
+
for (let ref3 = lib.gatherRecursive(ast, ($) => $.type === "ModuleSpecifier"), i = 0, len = ref3.length; i < len; i++) {
|
|
479
|
+
const _spec = ref3[i];
|
|
480
|
+
const spec = _spec;
|
|
481
|
+
if (spec.module?.input) {
|
|
482
|
+
spec.module.token = spec.module.input.replace(/\.([mc])?ts(['"])$/, ".$1js$2");
|
|
483
|
+
}
|
|
486
484
|
}
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
485
|
+
const compiledTS = await civet.generate(ast, {
|
|
486
|
+
...civetOptions,
|
|
487
|
+
js: false,
|
|
488
|
+
sourceMap: civetSourceMap
|
|
489
|
+
});
|
|
490
|
+
checkErrors();
|
|
491
|
+
const tsx = filename + ".tsx";
|
|
492
|
+
fsMap.set(tsx, compiledTS);
|
|
493
|
+
sourceMaps.set(tsx, civetSourceMap);
|
|
494
|
+
const slashed = slash(tsx);
|
|
495
|
+
if (!(tsx === slashed)) {
|
|
496
|
+
fsMap.set(slashed, compiledTS);
|
|
497
|
+
sourceMaps.set(slashed, civetSourceMap);
|
|
490
498
|
}
|
|
491
499
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
+
const jsonSourceMap = sourceMap && (typeof sourceMap === "string" ? JSON.parse(sourceMap) : sourceMap.json(
|
|
501
|
+
path.basename(id.replace(/\.[jt]sx$/, "")),
|
|
502
|
+
path.basename(id)
|
|
503
|
+
));
|
|
504
|
+
let transformed = {
|
|
505
|
+
code: compiled,
|
|
506
|
+
map: jsonSourceMap
|
|
507
|
+
};
|
|
508
|
+
if (options.transformOutput) {
|
|
509
|
+
transformed = await options.transformOutput(transformed.code, id);
|
|
500
510
|
}
|
|
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);
|
|
511
|
+
if (cached != null) {
|
|
512
|
+
cached.result = transformed;
|
|
513
|
+
delete cached.promise;
|
|
514
514
|
}
|
|
515
|
+
return transformed;
|
|
516
|
+
} finally {
|
|
517
|
+
resolve?.();
|
|
515
518
|
}
|
|
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
519
|
},
|
|
530
520
|
esbuild: {
|
|
531
521
|
config(options2) {
|
|
@@ -573,6 +563,9 @@ var rawPlugin = (options = {}, meta) => {
|
|
|
573
563
|
},
|
|
574
564
|
webpack(compiler) {
|
|
575
565
|
if (implicitExtension) {
|
|
566
|
+
compiler.options ??= {};
|
|
567
|
+
compiler.options.resolve ??= {};
|
|
568
|
+
compiler.options.resolve.extensions ??= ["", ".js", ".json", ".wasm"];
|
|
576
569
|
compiler.options.resolve.extensions.unshift(".civet");
|
|
577
570
|
}
|
|
578
571
|
return aliasResolver = (id) => {
|
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.3",
|
|
5
5
|
"description": "CoffeeScript style syntax for TypeScript",
|
|
6
6
|
"main": "dist/main.js",
|
|
7
7
|
"module": "dist/main.mjs",
|
|
@@ -95,14 +95,14 @@
|
|
|
95
95
|
"unplugin": "^2.1.0"
|
|
96
96
|
},
|
|
97
97
|
"devDependencies": {
|
|
98
|
-
"@danielx/civet": "0.9.
|
|
98
|
+
"@danielx/civet": "0.9.2",
|
|
99
99
|
"@danielx/hera": "^0.8.16",
|
|
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",
|