@danielx/civet 0.6.8 → 0.6.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/dist/babel-plugin.mjs +5 -6
- package/dist/browser.js +8 -2
- package/dist/civet +17 -0
- package/dist/config.js +91 -0
- package/dist/main.js +8 -2
- package/dist/main.mjs +8 -2
- package/dist/types.d.ts +39 -0
- package/package.json +2 -1
package/dist/babel-plugin.mjs
CHANGED
|
@@ -7,17 +7,16 @@ export default function (api, civetOptions) {
|
|
|
7
7
|
if (opts.sourceFileName.endsWith(".civet")) {
|
|
8
8
|
const config = Object.assign({}, civetOptions, {
|
|
9
9
|
filename: opts.sourceFileName,
|
|
10
|
-
sourceMap:
|
|
10
|
+
sourceMap: false,
|
|
11
11
|
})
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
src = compile(code, config)
|
|
17
|
-
}
|
|
13
|
+
config.inlineMap ??= true
|
|
14
|
+
config.js = true
|
|
15
|
+
src = compile(code, config)
|
|
18
16
|
} else {
|
|
19
17
|
src = code
|
|
20
18
|
}
|
|
19
|
+
|
|
21
20
|
const ast = parse(src, opts)
|
|
22
21
|
return ast
|
|
23
22
|
}
|
package/dist/browser.js
CHANGED
|
@@ -22979,7 +22979,7 @@ ${input.slice(result.pos)}
|
|
|
22979
22979
|
}
|
|
22980
22980
|
});
|
|
22981
22981
|
}
|
|
22982
|
-
module.config =
|
|
22982
|
+
module.config = {
|
|
22983
22983
|
autoVar: false,
|
|
22984
22984
|
autoLet: false,
|
|
22985
22985
|
coffeeBinaryExistential: false,
|
|
@@ -23140,6 +23140,8 @@ ${input.slice(result.pos)}
|
|
|
23140
23140
|
}
|
|
23141
23141
|
}
|
|
23142
23142
|
});
|
|
23143
|
+
Object.assign(module.config, parse2.config);
|
|
23144
|
+
parse2.config = module.config;
|
|
23143
23145
|
});
|
|
23144
23146
|
function Reset(state) {
|
|
23145
23147
|
let eventData;
|
|
@@ -23953,13 +23955,17 @@ ${input.slice(result.pos)}
|
|
|
23953
23955
|
} else {
|
|
23954
23956
|
options = { ...options };
|
|
23955
23957
|
}
|
|
23958
|
+
if (options.parseOptions == null) {
|
|
23959
|
+
options.parseOptions = {};
|
|
23960
|
+
}
|
|
23956
23961
|
filename = options.filename || "unknown";
|
|
23957
23962
|
if (filename.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
|
|
23958
|
-
|
|
23963
|
+
options.parseOptions.coffeeCompat = true;
|
|
23959
23964
|
}
|
|
23960
23965
|
if (!options.noCache) {
|
|
23961
23966
|
events = makeCache();
|
|
23962
23967
|
}
|
|
23968
|
+
parse.config = options.parseOptions || {};
|
|
23963
23969
|
ast = prune(parse(src, { filename, events }));
|
|
23964
23970
|
if (options.ast) {
|
|
23965
23971
|
return ast;
|
package/dist/civet
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
var import_main = require("./main");
|
|
4
|
+
var import_config = require("./config");
|
|
4
5
|
var cli, encoding, fs, parseArgs, path, prune, readFiles, repl, version, splice = [].splice;
|
|
5
6
|
({ prune } = import_main.generate);
|
|
6
7
|
version = function() {
|
|
@@ -36,6 +37,8 @@ Options:
|
|
|
36
37
|
--version Show the version number
|
|
37
38
|
-o / --output XX Specify output directory and/or extension, or filename
|
|
38
39
|
-c / --compile Compile input files to TypeScript (or JavaScript)
|
|
40
|
+
--config XX Specify a config file (default scans for a config.civet, civet.json, civetconfig.civet or civetconfig.json file, optionally in a .config directory, or starting with a .)
|
|
41
|
+
--no-config Don't scan for a config file
|
|
39
42
|
--js Strip out all type annotations; default to .jsx extension
|
|
40
43
|
--ast Print the AST instead of the compiled code
|
|
41
44
|
--inline-map Generate a sourcemap
|
|
@@ -96,6 +99,12 @@ parseArgs = function(args) {
|
|
|
96
99
|
case "--output":
|
|
97
100
|
options.output = args[++i];
|
|
98
101
|
break;
|
|
102
|
+
case "--config":
|
|
103
|
+
options.config = args[++i];
|
|
104
|
+
break;
|
|
105
|
+
case "--no-config":
|
|
106
|
+
options.config = false;
|
|
107
|
+
break;
|
|
99
108
|
case "--ast":
|
|
100
109
|
options.ast = true;
|
|
101
110
|
break;
|
|
@@ -254,6 +263,14 @@ cli = async function() {
|
|
|
254
263
|
var argv, child, content, e, error, esm, filename, filenames, options, optionsPath, output, outputFilename, outputPath, ref, results, scriptArgs, stat, stdin, x;
|
|
255
264
|
argv = process.argv;
|
|
256
265
|
({ filenames, scriptArgs, options } = parseArgs(argv.slice(2)));
|
|
266
|
+
if (options.config !== false) {
|
|
267
|
+
if (options.config == null) {
|
|
268
|
+
options.config = await (0, import_config.findConfig)(process.cwd());
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (options.config) {
|
|
272
|
+
options = { ...await (0, import_config.loadConfig)(options.config), ...options };
|
|
273
|
+
}
|
|
257
274
|
if (!filenames.length) {
|
|
258
275
|
if (process.stdin.isTTY) {
|
|
259
276
|
options.repl = true;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var config_exports = {};
|
|
26
|
+
__export(config_exports, {
|
|
27
|
+
findConfig: () => findConfig,
|
|
28
|
+
loadConfig: () => loadConfig
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(config_exports);
|
|
31
|
+
var import_path = __toESM(require("path"));
|
|
32
|
+
var import_promises = __toESM(require("fs/promises"));
|
|
33
|
+
var import_main = require("./main");
|
|
34
|
+
var import_url = require("url");
|
|
35
|
+
var findInDir;
|
|
36
|
+
findInDir = async function(dirPath) {
|
|
37
|
+
var dir, entry, name;
|
|
38
|
+
dir = await import_promises.default.opendir(dirPath);
|
|
39
|
+
for await (entry of dir) {
|
|
40
|
+
if (entry.isDirectory() && entry.name === ".config") {
|
|
41
|
+
return findInDir(import_path.default.join(dirPath, entry.name));
|
|
42
|
+
}
|
|
43
|
+
if (entry.isFile()) {
|
|
44
|
+
name = entry.name.replace(/^\./, "");
|
|
45
|
+
if (name === "config.civet" || name === "civet.json" || name === "civetconfig.civet" || name === "civetconfig.json") {
|
|
46
|
+
return import_path.default.join(dirPath, entry.name);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
};
|
|
52
|
+
var findConfig = async function(startDir) {
|
|
53
|
+
var configPath, curr, parent;
|
|
54
|
+
curr = startDir;
|
|
55
|
+
parent = import_path.default.dirname(curr);
|
|
56
|
+
while (curr !== parent) {
|
|
57
|
+
if (configPath = await findInDir(curr)) {
|
|
58
|
+
return configPath;
|
|
59
|
+
}
|
|
60
|
+
curr = parent;
|
|
61
|
+
parent = import_path.default.dirname(curr);
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
};
|
|
65
|
+
var loadConfig = async function(path2) {
|
|
66
|
+
var config, exports, js, tmpPath;
|
|
67
|
+
config = await import_promises.default.readFile(path2, "utf8");
|
|
68
|
+
if (path2.endsWith(".json")) {
|
|
69
|
+
return JSON.parse(config);
|
|
70
|
+
} else {
|
|
71
|
+
js = (0, import_main.compile)(config, {
|
|
72
|
+
js: true
|
|
73
|
+
});
|
|
74
|
+
tmpPath = path2 + `.civet-tmp-${Date.now()}.mjs`;
|
|
75
|
+
await import_promises.default.writeFile(tmpPath, js);
|
|
76
|
+
try {
|
|
77
|
+
exports = await import((0, import_url.pathToFileURL)(tmpPath));
|
|
78
|
+
} finally {
|
|
79
|
+
await import_promises.default.unlink(tmpPath);
|
|
80
|
+
}
|
|
81
|
+
if (typeof exports.default !== "object" || exports.default === null) {
|
|
82
|
+
throw new Error("civet config file must export an object");
|
|
83
|
+
}
|
|
84
|
+
return exports.default;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
findConfig,
|
|
90
|
+
loadConfig
|
|
91
|
+
});
|
package/dist/main.js
CHANGED
|
@@ -22978,7 +22978,7 @@ ${input.slice(result.pos)}
|
|
|
22978
22978
|
}
|
|
22979
22979
|
});
|
|
22980
22980
|
}
|
|
22981
|
-
module2.config =
|
|
22981
|
+
module2.config = {
|
|
22982
22982
|
autoVar: false,
|
|
22983
22983
|
autoLet: false,
|
|
22984
22984
|
coffeeBinaryExistential: false,
|
|
@@ -23139,6 +23139,8 @@ ${input.slice(result.pos)}
|
|
|
23139
23139
|
}
|
|
23140
23140
|
}
|
|
23141
23141
|
});
|
|
23142
|
+
Object.assign(module2.config, parse2.config);
|
|
23143
|
+
parse2.config = module2.config;
|
|
23142
23144
|
});
|
|
23143
23145
|
function Reset(state) {
|
|
23144
23146
|
let eventData;
|
|
@@ -23953,13 +23955,17 @@ var compile = function(src, options) {
|
|
|
23953
23955
|
} else {
|
|
23954
23956
|
options = { ...options };
|
|
23955
23957
|
}
|
|
23958
|
+
if (options.parseOptions == null) {
|
|
23959
|
+
options.parseOptions = {};
|
|
23960
|
+
}
|
|
23956
23961
|
filename = options.filename || "unknown";
|
|
23957
23962
|
if (filename.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
|
|
23958
|
-
|
|
23963
|
+
options.parseOptions.coffeeCompat = true;
|
|
23959
23964
|
}
|
|
23960
23965
|
if (!options.noCache) {
|
|
23961
23966
|
events = makeCache();
|
|
23962
23967
|
}
|
|
23968
|
+
parse.config = options.parseOptions || {};
|
|
23963
23969
|
ast = prune(parse(src, { filename, events }));
|
|
23964
23970
|
if (options.ast) {
|
|
23965
23971
|
return ast;
|
package/dist/main.mjs
CHANGED
|
@@ -22976,7 +22976,7 @@ ${input.slice(result.pos)}
|
|
|
22976
22976
|
}
|
|
22977
22977
|
});
|
|
22978
22978
|
}
|
|
22979
|
-
module.config =
|
|
22979
|
+
module.config = {
|
|
22980
22980
|
autoVar: false,
|
|
22981
22981
|
autoLet: false,
|
|
22982
22982
|
coffeeBinaryExistential: false,
|
|
@@ -23137,6 +23137,8 @@ ${input.slice(result.pos)}
|
|
|
23137
23137
|
}
|
|
23138
23138
|
}
|
|
23139
23139
|
});
|
|
23140
|
+
Object.assign(module.config, parse2.config);
|
|
23141
|
+
parse2.config = module.config;
|
|
23140
23142
|
});
|
|
23141
23143
|
function Reset(state) {
|
|
23142
23144
|
let eventData;
|
|
@@ -23941,13 +23943,17 @@ var compile = function(src, options) {
|
|
|
23941
23943
|
} else {
|
|
23942
23944
|
options = { ...options };
|
|
23943
23945
|
}
|
|
23946
|
+
if (options.parseOptions == null) {
|
|
23947
|
+
options.parseOptions = {};
|
|
23948
|
+
}
|
|
23944
23949
|
filename = options.filename || "unknown";
|
|
23945
23950
|
if (filename.endsWith(".coffee") && !/^(#![^\r\n]*(\r\n|\n|\r))?\s*['"]civet/.test(src)) {
|
|
23946
|
-
|
|
23951
|
+
options.parseOptions.coffeeCompat = true;
|
|
23947
23952
|
}
|
|
23948
23953
|
if (!options.noCache) {
|
|
23949
23954
|
events = makeCache();
|
|
23950
23955
|
}
|
|
23956
|
+
parse.config = options.parseOptions || {};
|
|
23951
23957
|
ast = prune(parse(src, { filename, events }));
|
|
23952
23958
|
if (options.ast) {
|
|
23953
23959
|
return ast;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,9 +1,38 @@
|
|
|
1
1
|
declare module "@danielx/civet" {
|
|
2
2
|
export type CivetAST = unknown
|
|
3
|
+
export type ParseOptions = Partial<{
|
|
4
|
+
autoVar: boolean
|
|
5
|
+
autoLet: boolean
|
|
6
|
+
coffeeBinaryExistential: boolean
|
|
7
|
+
coffeeBooleans: boolean
|
|
8
|
+
coffeeClasses: boolean
|
|
9
|
+
coffeeComment: boolean
|
|
10
|
+
coffeeDo: boolean
|
|
11
|
+
coffeeEq: boolean
|
|
12
|
+
coffeeForLoops: boolean
|
|
13
|
+
coffeeInterpolation: boolean
|
|
14
|
+
coffeeIsnt: boolean
|
|
15
|
+
coffeeJSX: boolean
|
|
16
|
+
coffeeLineContinuation: boolean
|
|
17
|
+
coffeeNot: boolean
|
|
18
|
+
coffeeOf: boolean
|
|
19
|
+
coffeePrototype: boolean
|
|
20
|
+
defaultElement: string
|
|
21
|
+
implicitReturns: boolean
|
|
22
|
+
objectIs: boolean
|
|
23
|
+
react: boolean
|
|
24
|
+
solid: boolean
|
|
25
|
+
client: boolean
|
|
26
|
+
rewriteTsImports: boolean
|
|
27
|
+
server: boolean
|
|
28
|
+
tab: number
|
|
29
|
+
verbose: boolean
|
|
30
|
+
}>
|
|
3
31
|
export type CompileOptions = {
|
|
4
32
|
filename?: string
|
|
5
33
|
js?: boolean
|
|
6
34
|
sourceMap?: boolean
|
|
35
|
+
parseOptions?: ParseOptions
|
|
7
36
|
}
|
|
8
37
|
|
|
9
38
|
export type SourceMapping = [number] | [number, number, number, number]
|
|
@@ -62,3 +91,13 @@ declare module "@danielx/civet/esbuild-plugin" {
|
|
|
62
91
|
const plugin: ((options: Options) => Plugin) & Plugin
|
|
63
92
|
export default plugin
|
|
64
93
|
}
|
|
94
|
+
|
|
95
|
+
declare module "@danielx/civet/config" {
|
|
96
|
+
const Config: {
|
|
97
|
+
findConfig: (path: string) => Promise<string | null>
|
|
98
|
+
loadConfig: (
|
|
99
|
+
path: string
|
|
100
|
+
) => Promise<import("@danielx/civet").CompileOptions>
|
|
101
|
+
}
|
|
102
|
+
export default Config
|
|
103
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danielx/civet",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.9",
|
|
4
4
|
"description": "CoffeeScript style syntax for TypeScript",
|
|
5
5
|
"main": "dist/main.js",
|
|
6
6
|
"module": "dist/main.mjs",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
"./esbuild-plugin": "./dist/esbuild-plugin.js",
|
|
14
14
|
"./bun-civet": "./dist/bun-civet.mjs",
|
|
15
15
|
"./register": "./register.js",
|
|
16
|
+
"./config": "./dist/config.js",
|
|
16
17
|
"./*": "./*",
|
|
17
18
|
"./dist/*": "./dist/*"
|
|
18
19
|
},
|