@danielx/civet 0.5.21 → 0.5.23
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 +5 -0
- package/dist/civet +39 -15
- package/dist/esm.mjs +1 -1
- package/package.json +2 -1
- package/register.js +14 -1
- package/register.mjs +0 -56
package/README.md
CHANGED
|
@@ -8,6 +8,7 @@ Civet
|
|
|
8
8
|
|
|
9
9
|
The CoffeeScript of TypeScript. Much closer to ES2015+ (for better or worse).
|
|
10
10
|
|
|
11
|
+
- [Documentation](https://civet.dev/)
|
|
11
12
|
- [Online Civet Playground](https://civet-web.vercel.app/)
|
|
12
13
|
- [Civet VSCode Extension](https://marketplace.visualstudio.com/items?itemName=DanielX.civet)
|
|
13
14
|
- [Discord Server](https://discord.gg/xkrW9GebBc)
|
|
@@ -23,8 +24,12 @@ Quickstart Guide
|
|
|
23
24
|
```bash
|
|
24
25
|
# Install
|
|
25
26
|
npm install -g @danielx/civet
|
|
27
|
+
# Run civet code directly in a REPL
|
|
28
|
+
civet
|
|
26
29
|
# Compile civet source file to typescript
|
|
27
30
|
civet < source.civet > output.ts
|
|
31
|
+
# Execute a simple civet script (no imports)
|
|
32
|
+
civet source.civet ...args...
|
|
28
33
|
# Execute a civet source file in node using ts-node
|
|
29
34
|
node --loader ts-node/esm --loader @danielx/civet/esm source.civet
|
|
30
35
|
```
|
package/dist/civet
CHANGED
|
@@ -46,19 +46,37 @@ encoding = "utf8";
|
|
|
46
46
|
fs = require("fs/promises");
|
|
47
47
|
path = require("path");
|
|
48
48
|
parseArgs = function(args = process.argv.slice(2)) {
|
|
49
|
-
var arg, char, filenames, i, options, ref;
|
|
49
|
+
var arg, char, endOfArgs, filenames, i, options, ref, scriptArgs;
|
|
50
50
|
options = {};
|
|
51
|
+
Object.defineProperty(options, "run", {
|
|
52
|
+
get: function() {
|
|
53
|
+
return !(this.ast || this.compile);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
51
56
|
filenames = [];
|
|
57
|
+
scriptArgs = null;
|
|
52
58
|
i = 0;
|
|
59
|
+
endOfArgs = function(j) {
|
|
60
|
+
i = args.length;
|
|
61
|
+
if (j >= args.length) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
if (options.run) {
|
|
65
|
+
filenames.push(args[j]);
|
|
66
|
+
return scriptArgs = args.slice(j);
|
|
67
|
+
} else {
|
|
68
|
+
return filenames.push(...args.slice(j));
|
|
69
|
+
}
|
|
70
|
+
};
|
|
53
71
|
while (i < args.length) {
|
|
54
72
|
arg = args[i];
|
|
55
73
|
if (/^-\w{2,}$/.test(arg)) {
|
|
56
74
|
splice.apply(args, [i, i - i + 1].concat(ref = function() {
|
|
57
|
-
var
|
|
75
|
+
var k, len, ref1, results;
|
|
58
76
|
ref1 = arg.slice(1);
|
|
59
77
|
results = [];
|
|
60
|
-
for (
|
|
61
|
-
char = ref1[
|
|
78
|
+
for (k = 0, len = ref1.length; k < len; k++) {
|
|
79
|
+
char = ref1[k];
|
|
62
80
|
results.push(`-${char}`);
|
|
63
81
|
}
|
|
64
82
|
return results;
|
|
@@ -87,21 +105,24 @@ parseArgs = function(args = process.argv.slice(2)) {
|
|
|
87
105
|
options.js = true;
|
|
88
106
|
break;
|
|
89
107
|
case "--":
|
|
90
|
-
|
|
91
|
-
i = args.length;
|
|
108
|
+
endOfArgs(++i);
|
|
92
109
|
break;
|
|
93
110
|
default:
|
|
94
|
-
|
|
111
|
+
if (options.run) {
|
|
112
|
+
endOfArgs(i);
|
|
113
|
+
} else {
|
|
114
|
+
filenames.push(arg);
|
|
115
|
+
}
|
|
95
116
|
}
|
|
96
117
|
i++;
|
|
97
118
|
}
|
|
98
|
-
return { filenames, options };
|
|
119
|
+
return { filenames, scriptArgs, options };
|
|
99
120
|
};
|
|
100
121
|
readFiles = async function* (filenames, options) {
|
|
101
|
-
var content, error, filename,
|
|
122
|
+
var content, error, filename, k, len, lines, results, rl, stdin;
|
|
102
123
|
results = [];
|
|
103
|
-
for (
|
|
104
|
-
filename = filenames[
|
|
124
|
+
for (k = 0, len = filenames.length; k < len; k++) {
|
|
125
|
+
filename = filenames[k];
|
|
105
126
|
stdin = filename === "-";
|
|
106
127
|
try {
|
|
107
128
|
if (stdin) {
|
|
@@ -172,8 +193,8 @@ repl = function(options) {
|
|
|
172
193
|
});
|
|
173
194
|
};
|
|
174
195
|
cli = async function() {
|
|
175
|
-
var content, error, filename, filenames, options, optionsPath, output, outputFilename, outputPath, ref, results, stat, stdin, x;
|
|
176
|
-
({ filenames, options } = parseArgs());
|
|
196
|
+
var content, error, filename, filenames, options, optionsPath, output, outputFilename, outputPath, ref, results, scriptArgs, stat, stdin, x;
|
|
197
|
+
({ filenames, scriptArgs, options } = parseArgs());
|
|
177
198
|
if (!filenames.length) {
|
|
178
199
|
options.compile = true;
|
|
179
200
|
if (process.stdin.isTTY) {
|
|
@@ -182,10 +203,10 @@ cli = async function() {
|
|
|
182
203
|
filenames = ["-"];
|
|
183
204
|
}
|
|
184
205
|
}
|
|
185
|
-
options.run = !(options.ast || options.compile);
|
|
186
206
|
if (options.run) {
|
|
187
207
|
options.js = true;
|
|
188
208
|
options.inlineMap = true;
|
|
209
|
+
require("../register.js");
|
|
189
210
|
}
|
|
190
211
|
if (options.repl) {
|
|
191
212
|
return repl(options);
|
|
@@ -247,8 +268,11 @@ cli = async function() {
|
|
|
247
268
|
}
|
|
248
269
|
}
|
|
249
270
|
} else {
|
|
271
|
+
module.filename = await fs.realpath(filename);
|
|
272
|
+
process.argv = ["civet", module.filename, ...scriptArgs];
|
|
273
|
+
module.paths = require("module")._nodeModulePaths(path.dirname(module.filename));
|
|
250
274
|
try {
|
|
251
|
-
results.push(
|
|
275
|
+
results.push(module._compile(output, module.filename));
|
|
252
276
|
} catch (error1) {
|
|
253
277
|
error = error1;
|
|
254
278
|
console.error(`${filename} crashed while running:`);
|
package/dist/esm.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielx/civet",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.23",
|
|
4
4
|
"description": "CoffeeScript style syntax for TypeScript",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"exports": {
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"@types/coffeescript": "^2.5.2",
|
|
37
37
|
"@types/mocha": "^9.1.1",
|
|
38
38
|
"@types/node": "^18.7.8",
|
|
39
|
+
"axios": "^1.2.2",
|
|
39
40
|
"c8": "^7.12.0",
|
|
40
41
|
"esbuild": "^0.14.49",
|
|
41
42
|
"esbuild-coffeescript": "^2.1.0",
|
package/register.js
CHANGED
|
@@ -1,10 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file Civet CJS registration
|
|
3
|
+
|
|
4
|
+
`require`ing this file will register the `.civet` extension with
|
|
5
|
+
Node.js's `require`.
|
|
6
|
+
|
|
7
|
+
@example
|
|
8
|
+
```bash
|
|
9
|
+
node -r @danielx/civet/register.js source.civet
|
|
10
|
+
```
|
|
11
|
+
*/
|
|
12
|
+
|
|
1
13
|
if (require.extensions) {
|
|
2
14
|
const fs = require("fs");
|
|
3
15
|
const { compile } = require("./");
|
|
4
16
|
|
|
5
17
|
require.extensions[".civet"] = function (module, filename) {
|
|
6
18
|
const js = compile(fs.readFileSync(filename, 'utf8'), {
|
|
7
|
-
js: true
|
|
19
|
+
js: true,
|
|
20
|
+
inlineMap: true,
|
|
8
21
|
});
|
|
9
22
|
module._compile(js, filename);
|
|
10
23
|
return;
|
package/register.mjs
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'fs';
|
|
2
|
-
import { readFile } from 'fs/promises';
|
|
3
|
-
import { createRequire } from 'module';
|
|
4
|
-
import { pathToFileURL, fileURLToPath } from 'url';
|
|
5
|
-
|
|
6
|
-
import { compile } from "./dist/main.js";
|
|
7
|
-
|
|
8
|
-
const baseURL = pathToFileURL(process.cwd() + '/').href;
|
|
9
|
-
const extensionsRegex = /\.civet$/;
|
|
10
|
-
|
|
11
|
-
export async function resolve(specifier, context, next) {
|
|
12
|
-
const { parentURL = baseURL } = context;
|
|
13
|
-
|
|
14
|
-
if (extensionsRegex.test(specifier)) {
|
|
15
|
-
return {
|
|
16
|
-
shortCircuit: true,
|
|
17
|
-
format: "civet",
|
|
18
|
-
url: new URL(specifier, parentURL).href,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Let Node.js handle all other specifiers.
|
|
23
|
-
return next(specifier, context);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export async function load(url, context, next) {
|
|
27
|
-
if (context.format === "civet") {
|
|
28
|
-
const path = fileURLToPath(url)
|
|
29
|
-
const source = await readFile(path, "utf8")
|
|
30
|
-
const tsSource = compile(source, { filename: path })
|
|
31
|
-
|
|
32
|
-
// NOTE: Assuming ts-node hook follows load hook
|
|
33
|
-
// NOTE: This causes .civet files to show up as .ts in ts-node error reporting (TODO: May be able to add a sourcemapping)
|
|
34
|
-
const result = await next(url.replace(extensionsRegex, ".tsx"), {
|
|
35
|
-
// ts-node won't transpile unless this is module
|
|
36
|
-
// can't use commonjs since we don't rewrite imports
|
|
37
|
-
format: "module",
|
|
38
|
-
// NOTE: Setting the source in the context makes it available when ts-node uses defaultLoad
|
|
39
|
-
source: tsSource
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
return result
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Let Node.js handle all other URLs.
|
|
46
|
-
return next(url, context);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const require = createRequire(import.meta.url);
|
|
50
|
-
require.extensions[".civet"] = function (m, filename) {
|
|
51
|
-
// We end up here when being required from cjs
|
|
52
|
-
const source = readFileSync(filename, "utf8")
|
|
53
|
-
const code = compile(source, { filename, js: true })
|
|
54
|
-
|
|
55
|
-
m._compile(code, filename)
|
|
56
|
-
}
|