@danielx/civet 0.6.36 → 0.6.38
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 +218 -94
- package/dist/bun-civet.mjs +4 -4
- package/dist/civet +60 -30
- package/dist/esbuild.js +74 -23
- package/dist/main.js +219 -94
- package/dist/main.mjs +218 -94
- package/dist/rollup.js +74 -23
- package/dist/ts-diagnostic.js +149 -0
- package/dist/ts-diagnostic.mjs +111 -0
- package/dist/unplugin-shared.mjs +80 -24
- package/dist/unplugin.d.mts +2 -0
- package/dist/unplugin.d.ts +2 -0
- package/dist/unplugin.js +74 -23
- package/dist/vite.js +74 -23
- package/dist/webpack.js +74 -23
- package/package.json +7 -1
package/dist/bun-civet.mjs
CHANGED
|
@@ -2,11 +2,11 @@ import { plugin } from "bun";
|
|
|
2
2
|
await plugin({
|
|
3
3
|
name: "Civet loader",
|
|
4
4
|
setup: async function(builder) {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
const { compile } = await import("./main.mjs");
|
|
6
|
+
const { readFileSync } = await import("fs");
|
|
7
7
|
return builder.onLoad({ filter: /\.civet$/ }, function({ path }) {
|
|
8
|
-
source = readFileSync(path, "utf8");
|
|
9
|
-
contents = compile(source);
|
|
8
|
+
const source = readFileSync(path, "utf8");
|
|
9
|
+
const contents = compile(source);
|
|
10
10
|
return {
|
|
11
11
|
contents,
|
|
12
12
|
loader: "tsx"
|
package/dist/civet
CHANGED
|
@@ -1,20 +1,39 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
3
25
|
|
|
4
26
|
// source/cli.civet
|
|
5
27
|
var import_main = require("./main.js");
|
|
6
28
|
var import_config = require("./config.js");
|
|
7
|
-
var
|
|
29
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
30
|
+
var import_path = __toESM(require("path"));
|
|
8
31
|
var version;
|
|
9
|
-
var encoding;
|
|
10
|
-
var fs;
|
|
11
|
-
var path;
|
|
12
32
|
var parseArgs;
|
|
13
33
|
var readFiles;
|
|
14
34
|
var repl;
|
|
15
35
|
var cli;
|
|
16
36
|
var indexOf = [].indexOf;
|
|
17
|
-
({ prune } = import_main.generate);
|
|
18
37
|
version = function() {
|
|
19
38
|
return require("../package.json").version;
|
|
20
39
|
};
|
|
@@ -60,9 +79,7 @@ if (process.argv.includes("--help")) {
|
|
|
60
79
|
`);
|
|
61
80
|
process.exit(0);
|
|
62
81
|
}
|
|
63
|
-
encoding = "utf8";
|
|
64
|
-
fs = require("fs/promises");
|
|
65
|
-
path = require("path");
|
|
82
|
+
var encoding = "utf8";
|
|
66
83
|
parseArgs = function(args) {
|
|
67
84
|
var options, filenames, scriptArgs, i, endOfArgs, arg;
|
|
68
85
|
options = {};
|
|
@@ -167,7 +184,7 @@ readFiles = async function* (filenames, options) {
|
|
|
167
184
|
process.stdin.setEncoding(encoding);
|
|
168
185
|
filename = "<stdin>";
|
|
169
186
|
try {
|
|
170
|
-
filename = await
|
|
187
|
+
filename = await import_promises.default.realpath("/dev/stdin");
|
|
171
188
|
} catch (e) {
|
|
172
189
|
}
|
|
173
190
|
if (process.stdin.isTTY) {
|
|
@@ -196,7 +213,7 @@ readFiles = async function* (filenames, options) {
|
|
|
196
213
|
})()).join("");
|
|
197
214
|
}
|
|
198
215
|
} else {
|
|
199
|
-
content = await
|
|
216
|
+
content = await import_promises.default.readFile(filename, { encoding });
|
|
200
217
|
}
|
|
201
218
|
results1.push(yield { filename, content, stdin });
|
|
202
219
|
} catch (error) {
|
|
@@ -284,7 +301,7 @@ repl = function(options) {
|
|
|
284
301
|
});
|
|
285
302
|
};
|
|
286
303
|
cli = async function() {
|
|
287
|
-
var argv, filenames, scriptArgs, options, filename, error, content, stdin, output, outputPath, outputFilename, optionsPath, stat, esm, child;
|
|
304
|
+
var argv, filenames, scriptArgs, options, filename, error, content, stdin, output, outputPath, outputFilename, optionsPath, stat, esm, execArgv, debugRe, isDebug, child;
|
|
288
305
|
argv = process.argv;
|
|
289
306
|
({ filenames, scriptArgs, options } = parseArgs(argv.slice(2)));
|
|
290
307
|
if (options.config !== false) {
|
|
@@ -330,7 +347,7 @@ cli = async function() {
|
|
|
330
347
|
if (stdin && !options.output || options.output === "-") {
|
|
331
348
|
results3.push(process.stdout.write(output));
|
|
332
349
|
} else {
|
|
333
|
-
outputPath =
|
|
350
|
+
outputPath = import_path.default.parse(filename);
|
|
334
351
|
delete outputPath.base;
|
|
335
352
|
if (options.js) {
|
|
336
353
|
outputPath.ext += ".jsx";
|
|
@@ -338,13 +355,13 @@ cli = async function() {
|
|
|
338
355
|
outputPath.ext += ".tsx";
|
|
339
356
|
}
|
|
340
357
|
if (options.output) {
|
|
341
|
-
optionsPath =
|
|
358
|
+
optionsPath = import_path.default.parse(options.output);
|
|
342
359
|
try {
|
|
343
|
-
stat = await
|
|
360
|
+
stat = await import_promises.default.stat(options.output);
|
|
344
361
|
} catch {
|
|
345
362
|
stat = null;
|
|
346
363
|
}
|
|
347
|
-
if (stat?.isDirectory() || options.output.endsWith(
|
|
364
|
+
if (stat?.isDirectory() || options.output.endsWith(import_path.default.sep) || options.output.endsWith("/")) {
|
|
348
365
|
outputPath.dir = options.output;
|
|
349
366
|
} else if (/^(\.[^.]+)+$/.test(optionsPath.base)) {
|
|
350
367
|
outputPath.ext = optionsPath.base;
|
|
@@ -356,11 +373,11 @@ cli = async function() {
|
|
|
356
373
|
}
|
|
357
374
|
}
|
|
358
375
|
if (outputPath.dir) {
|
|
359
|
-
|
|
376
|
+
import_promises.default.mkdir(outputPath.dir, { recursive: true });
|
|
360
377
|
}
|
|
361
|
-
outputFilename =
|
|
378
|
+
outputFilename = import_path.default.format(outputPath);
|
|
362
379
|
try {
|
|
363
|
-
results3.push(await
|
|
380
|
+
results3.push(await import_promises.default.writeFile(outputFilename, output));
|
|
364
381
|
} catch (error2) {
|
|
365
382
|
console.error(`${outputFilename} failed to write:`);
|
|
366
383
|
results3.push(console.error(error2));
|
|
@@ -372,32 +389,45 @@ cli = async function() {
|
|
|
372
389
|
if (stdin) {
|
|
373
390
|
filename = `.stdin-${process.pid}.civet`;
|
|
374
391
|
try {
|
|
375
|
-
await
|
|
392
|
+
await import_promises.default.writeFile(filename, content, { encoding });
|
|
376
393
|
} catch (e) {
|
|
377
394
|
console.error(`Could not write ${filename} for Civet ESM mode:`);
|
|
378
395
|
console.error(e);
|
|
379
396
|
process.exit(1);
|
|
380
397
|
}
|
|
381
398
|
}
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
399
|
+
;
|
|
400
|
+
const { fork } = await import("child_process");
|
|
401
|
+
execArgv = ["--loader", "@danielx/civet/esm"];
|
|
402
|
+
debugRe = /--debug|--inspect/;
|
|
403
|
+
isDebug = typeof v8debug === "object" || debugRe.test(process.execArgv.join(" ")) || debugRe.test(process.env.NODE_OPTIONS);
|
|
404
|
+
if (process.env.NODE_OPTIONS) {
|
|
405
|
+
execArgv.push(process.env.NODE_OPTIONS);
|
|
406
|
+
}
|
|
407
|
+
if (isDebug) {
|
|
408
|
+
execArgv.push("--inspect=" + (process.debugPort + 1));
|
|
390
409
|
}
|
|
391
|
-
|
|
410
|
+
child = fork(filename, [
|
|
411
|
+
...scriptArgs
|
|
412
|
+
], {
|
|
413
|
+
execArgv,
|
|
414
|
+
stdio: "inherit"
|
|
415
|
+
});
|
|
416
|
+
results3.push(child.on("exit", async function(code) {
|
|
417
|
+
if (stdin) {
|
|
418
|
+
await import_promises.default.unlink(filename);
|
|
419
|
+
}
|
|
420
|
+
return process.exit(code ?? 1);
|
|
421
|
+
}));
|
|
392
422
|
} else {
|
|
393
423
|
require("../register.js");
|
|
394
424
|
try {
|
|
395
|
-
module.filename = await
|
|
425
|
+
module.filename = await import_promises.default.realpath(filename);
|
|
396
426
|
} catch {
|
|
397
427
|
module.filename = filename;
|
|
398
428
|
}
|
|
399
429
|
process.argv = ["civet", module.filename, ...scriptArgs];
|
|
400
|
-
module.paths = require("module")._nodeModulePaths(
|
|
430
|
+
module.paths = require("module")._nodeModulePaths(import_path.default.dirname(module.filename));
|
|
401
431
|
try {
|
|
402
432
|
results3.push(module._compile(output, module.filename));
|
|
403
433
|
} catch (error2) {
|
package/dist/esbuild.js
CHANGED
|
@@ -37,6 +37,7 @@ module.exports = __toCommonJS(esbuild_exports);
|
|
|
37
37
|
// src/index.ts
|
|
38
38
|
var import_unplugin = require("unplugin");
|
|
39
39
|
var import_civet = __toESM(require("@danielx/civet"));
|
|
40
|
+
var import_ts_diagnostic = require("@danielx/civet/ts-diagnostic");
|
|
40
41
|
var fs = __toESM(require("fs"));
|
|
41
42
|
var import_path = __toESM(require("path"));
|
|
42
43
|
var import_typescript = __toESM(require("typescript"));
|
|
@@ -52,15 +53,19 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
52
53
|
if (options.dts && options.js) {
|
|
53
54
|
throw new Error("Can't have both `dts` and `js` be set to `true`.");
|
|
54
55
|
}
|
|
55
|
-
|
|
56
|
+
if (options.typecheck && options.js) {
|
|
57
|
+
throw new Error("Can't have both `typecheck` and `js` be set to `true`.");
|
|
58
|
+
}
|
|
59
|
+
const transpileToJS = options.js ?? !(options.dts || options.typecheck);
|
|
56
60
|
const outExt = options.outputExtension ?? (transpileToJS ? ".jsx" : ".tsx");
|
|
57
61
|
let fsMap = /* @__PURE__ */ new Map();
|
|
62
|
+
const sourceMaps = /* @__PURE__ */ new Map();
|
|
58
63
|
let compilerOptions;
|
|
59
64
|
return {
|
|
60
65
|
name: "unplugin-civet",
|
|
61
66
|
enforce: "pre",
|
|
62
67
|
async buildStart() {
|
|
63
|
-
if (options.dts) {
|
|
68
|
+
if (options.dts || options.typecheck) {
|
|
64
69
|
const configPath = import_typescript.default.findConfigFile(process.cwd(), import_typescript.default.sys.fileExists);
|
|
65
70
|
if (!configPath) {
|
|
66
71
|
throw new Error("Could not find 'tsconfig.json'");
|
|
@@ -86,7 +91,7 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
86
91
|
}
|
|
87
92
|
},
|
|
88
93
|
buildEnd() {
|
|
89
|
-
if (options.dts) {
|
|
94
|
+
if (options.dts || options.typecheck) {
|
|
90
95
|
const system = tsvfs.createFSBackedSystem(fsMap, process.cwd(), import_typescript.default);
|
|
91
96
|
const host = tsvfs.createVirtualCompilerHost(
|
|
92
97
|
system,
|
|
@@ -98,20 +103,55 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
98
103
|
options: compilerOptions,
|
|
99
104
|
host: host.compilerHost
|
|
100
105
|
});
|
|
101
|
-
|
|
102
|
-
const
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
const diagnostics = import_typescript.default.getPreEmitDiagnostics(program).map((diagnostic) => {
|
|
107
|
+
const file = diagnostic.file;
|
|
108
|
+
if (!file)
|
|
109
|
+
return diagnostic;
|
|
110
|
+
const sourceMap = sourceMaps.get(file.fileName);
|
|
111
|
+
if (!sourceMap)
|
|
112
|
+
return diagnostic;
|
|
113
|
+
const sourcemapLines = sourceMap.data.lines;
|
|
114
|
+
const range = (0, import_ts_diagnostic.remapRange)(
|
|
115
|
+
{
|
|
116
|
+
start: diagnostic.start || 0,
|
|
117
|
+
end: (diagnostic.start || 0) + (diagnostic.length || 1)
|
|
111
118
|
},
|
|
112
|
-
|
|
113
|
-
true
|
|
119
|
+
sourcemapLines
|
|
114
120
|
);
|
|
121
|
+
return {
|
|
122
|
+
...diagnostic,
|
|
123
|
+
messageText: (0, import_ts_diagnostic.flattenDiagnosticMessageText)(diagnostic.messageText),
|
|
124
|
+
length: diagnostic.length,
|
|
125
|
+
start: range.start
|
|
126
|
+
};
|
|
127
|
+
});
|
|
128
|
+
if (diagnostics.length > 0) {
|
|
129
|
+
console.error(
|
|
130
|
+
import_typescript.default.formatDiagnosticsWithColorAndContext(diagnostics, formatHost)
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
if (options.dts) {
|
|
134
|
+
for (const file of fsMap.keys()) {
|
|
135
|
+
const sourceFile = program.getSourceFile(file);
|
|
136
|
+
program.emit(
|
|
137
|
+
sourceFile,
|
|
138
|
+
async (filePath, content) => {
|
|
139
|
+
const dir = import_path.default.dirname(filePath);
|
|
140
|
+
await fs.promises.mkdir(dir, { recursive: true });
|
|
141
|
+
const pathFromDistDir = import_path.default.relative(
|
|
142
|
+
compilerOptions.outDir ?? process.cwd(),
|
|
143
|
+
filePath
|
|
144
|
+
);
|
|
145
|
+
this.emitFile({
|
|
146
|
+
source: content,
|
|
147
|
+
fileName: pathFromDistDir,
|
|
148
|
+
type: "asset"
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
void 0,
|
|
152
|
+
true
|
|
153
|
+
);
|
|
154
|
+
}
|
|
115
155
|
}
|
|
116
156
|
}
|
|
117
157
|
},
|
|
@@ -135,13 +175,20 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
135
175
|
return null;
|
|
136
176
|
const filename = import_path.default.resolve(process.cwd(), id.slice(0, -outExt.length));
|
|
137
177
|
const code = await fs.promises.readFile(filename, "utf-8");
|
|
178
|
+
const compiled = import_civet.default.compile(code, {
|
|
179
|
+
// inlineMap: true,
|
|
180
|
+
filename: id,
|
|
181
|
+
js: transpileToJS,
|
|
182
|
+
sourceMap: true
|
|
183
|
+
});
|
|
184
|
+
sourceMaps.set(import_path.default.resolve(process.cwd(), id), compiled.sourceMap);
|
|
185
|
+
const jsonSourceMap = compiled.sourceMap.json(
|
|
186
|
+
import_path.default.basename(id.replace(/\.[jt]sx$/, "")),
|
|
187
|
+
import_path.default.basename(id)
|
|
188
|
+
);
|
|
138
189
|
let transformed = {
|
|
139
|
-
code:
|
|
140
|
-
|
|
141
|
-
filename: id,
|
|
142
|
-
js: transpileToJS
|
|
143
|
-
}),
|
|
144
|
-
map: null
|
|
190
|
+
code: compiled.code,
|
|
191
|
+
map: jsonSourceMap
|
|
145
192
|
};
|
|
146
193
|
if (options.transformOutput)
|
|
147
194
|
transformed = await options.transformOutput(transformed.code, id);
|
|
@@ -150,8 +197,12 @@ var civetUnplugin = (0, import_unplugin.createUnplugin)((options = {}) => {
|
|
|
150
197
|
transform(code, id) {
|
|
151
198
|
if (!/\.civet\.tsx?$/.test(id))
|
|
152
199
|
return null;
|
|
153
|
-
if (options.dts) {
|
|
154
|
-
|
|
200
|
+
if (options.dts || options.typecheck) {
|
|
201
|
+
const resolved = import_path.default.resolve(process.cwd(), id);
|
|
202
|
+
fsMap.set(resolved, code);
|
|
203
|
+
const slash = resolved.replace(/\\/g, "/");
|
|
204
|
+
if (resolved !== slash)
|
|
205
|
+
fsMap.set(slash, code);
|
|
155
206
|
}
|
|
156
207
|
return null;
|
|
157
208
|
},
|