@tobos/cli 0.4.17 → 0.4.19
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/chunk-4CLH25WE.js +55 -0
- package/dist/chunk-LMYDB4CF.js +55740 -0
- package/dist/chunk-O52ON2LV.js +141 -0
- package/dist/chunk-XJ7FDNTP.js +26 -0
- package/dist/cli.js +1371 -0
- package/dist/render-CRDYQFP2.js +189 -0
- package/dist/src-6IFWTNIY.js +42 -0
- package/dist/tobos.js +3 -59364
- package/dist/types-QVZY4DVU.js +223 -0
- package/package.json +1 -1
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire as __tobosRequire } from 'node:module';
|
|
3
|
+
const require = __tobosRequire(import.meta.url);
|
|
4
|
+
import {
|
|
5
|
+
parseDeckJson
|
|
6
|
+
} from "./chunk-LMYDB4CF.js";
|
|
7
|
+
import "./chunk-XJ7FDNTP.js";
|
|
8
|
+
import {
|
|
9
|
+
CliError
|
|
10
|
+
} from "./chunk-4CLH25WE.js";
|
|
11
|
+
import {
|
|
12
|
+
define_TOBOS_PRESENT_TYPES_default,
|
|
13
|
+
define_TOBOS_TOOLCHAIN_default,
|
|
14
|
+
init_define_TOBOS_PRESENT_TYPES,
|
|
15
|
+
init_define_TOBOS_SKILL,
|
|
16
|
+
init_define_TOBOS_TOOLCHAIN
|
|
17
|
+
} from "./chunk-O52ON2LV.js";
|
|
18
|
+
|
|
19
|
+
// src/types.ts
|
|
20
|
+
init_define_TOBOS_PRESENT_TYPES();
|
|
21
|
+
init_define_TOBOS_SKILL();
|
|
22
|
+
init_define_TOBOS_TOOLCHAIN();
|
|
23
|
+
import { spawn } from "node:child_process";
|
|
24
|
+
import { createHash } from "node:crypto";
|
|
25
|
+
import {
|
|
26
|
+
existsSync,
|
|
27
|
+
lstatSync,
|
|
28
|
+
mkdirSync,
|
|
29
|
+
mkdtempSync,
|
|
30
|
+
readFileSync,
|
|
31
|
+
renameSync,
|
|
32
|
+
rmSync,
|
|
33
|
+
symlinkSync,
|
|
34
|
+
writeFileSync
|
|
35
|
+
} from "node:fs";
|
|
36
|
+
import { homedir } from "node:os";
|
|
37
|
+
import { dirname, join, relative } from "node:path";
|
|
38
|
+
function run(command, args, cwd) {
|
|
39
|
+
return new Promise((resolve, reject) => {
|
|
40
|
+
const child = spawn(command, args, { cwd, env: process.env });
|
|
41
|
+
let out = "";
|
|
42
|
+
child.stdout.on("data", (d) => out += d);
|
|
43
|
+
child.stderr.on("data", (d) => out += d);
|
|
44
|
+
child.on("error", reject);
|
|
45
|
+
child.on("close", (code) => resolve({ code: code ?? 1, out }));
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
async function toolchain(dependencies, note) {
|
|
49
|
+
const wanted = { ...define_TOBOS_TOOLCHAIN_default, ...dependencies };
|
|
50
|
+
const id = createHash("sha256").update(JSON.stringify(wanted)).digest("hex").slice(0, 16);
|
|
51
|
+
const dir = join(process.env.XDG_CACHE_HOME || join(homedir(), ".cache"), "tobos", "types", id);
|
|
52
|
+
const complete = () => existsSync(join(dir, "node_modules", "svelte-check"));
|
|
53
|
+
if (complete()) return dir;
|
|
54
|
+
note("installing the type checker (once for these versions)\u2026");
|
|
55
|
+
mkdirSync(dirname(dir), { recursive: true });
|
|
56
|
+
const partial = mkdtempSync(`${dir}.`);
|
|
57
|
+
writeFileSync(join(partial, "package.json"), JSON.stringify({ private: true }) + "\n");
|
|
58
|
+
const install = await run(
|
|
59
|
+
"npm",
|
|
60
|
+
[
|
|
61
|
+
"install",
|
|
62
|
+
"--ignore-scripts",
|
|
63
|
+
"--no-audit",
|
|
64
|
+
"--no-fund",
|
|
65
|
+
"--loglevel=error",
|
|
66
|
+
...Object.entries(wanted).map(([name, version]) => `${name}@${version}`)
|
|
67
|
+
],
|
|
68
|
+
partial
|
|
69
|
+
).catch((error) => ({ code: 1, out: error.message }));
|
|
70
|
+
if (install.code !== 0) {
|
|
71
|
+
rmSync(partial, { recursive: true, force: true });
|
|
72
|
+
throw new CliError(`Couldn't install the type checker with npm:
|
|
73
|
+
${install.out.trim()}`);
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
renameSync(partial, dir);
|
|
77
|
+
} catch {
|
|
78
|
+
if (complete()) {
|
|
79
|
+
rmSync(partial, { recursive: true, force: true });
|
|
80
|
+
} else {
|
|
81
|
+
rmSync(dir, { recursive: true, force: true });
|
|
82
|
+
renameSync(partial, dir);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return dir;
|
|
86
|
+
}
|
|
87
|
+
function linkModules(root, dir) {
|
|
88
|
+
const link = join(root, "node_modules");
|
|
89
|
+
if (existsSync(link) && !lstatSync(link).isSymbolicLink())
|
|
90
|
+
throw new CliError(
|
|
91
|
+
"This deck has its own node_modules/; remove it (a deck has no build step)."
|
|
92
|
+
);
|
|
93
|
+
rmSync(link, { force: true });
|
|
94
|
+
symlinkSync(join(dir, "node_modules"), link, "dir");
|
|
95
|
+
const exclude = join(root, ".git", "info", "exclude");
|
|
96
|
+
if (existsSync(join(root, ".git"))) {
|
|
97
|
+
mkdirSync(dirname(exclude), { recursive: true });
|
|
98
|
+
const current = existsSync(exclude) ? readFileSync(exclude, "utf8") : "";
|
|
99
|
+
if (!/^\/?node_modules$/m.test(current))
|
|
100
|
+
writeFileSync(
|
|
101
|
+
exclude,
|
|
102
|
+
`${current}${current && !current.endsWith("\n") ? "\n" : ""}/node_modules
|
|
103
|
+
`
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function writeConfig(root) {
|
|
108
|
+
const dir = join(root, ".tobos", "types");
|
|
109
|
+
rmSync(dir, { recursive: true, force: true });
|
|
110
|
+
for (const [file, text] of Object.entries(define_TOBOS_PRESENT_TYPES_default)) {
|
|
111
|
+
const path = join(dir, "present", file);
|
|
112
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
113
|
+
writeFileSync(path, text);
|
|
114
|
+
}
|
|
115
|
+
const rel = (path) => relative(dir, path).split("\\").join("/");
|
|
116
|
+
const paths = {
|
|
117
|
+
"@tobos/present": [rel(join(dir, "present", "index.d.ts"))],
|
|
118
|
+
"@tobos/deck/types": [rel(join(dir, "present", "deck", "types.d.ts"))]
|
|
119
|
+
};
|
|
120
|
+
const config = join(dir, "tsconfig.json");
|
|
121
|
+
writeFileSync(
|
|
122
|
+
config,
|
|
123
|
+
JSON.stringify(
|
|
124
|
+
{
|
|
125
|
+
compilerOptions: {
|
|
126
|
+
target: "ES2023",
|
|
127
|
+
module: "ESNext",
|
|
128
|
+
moduleResolution: "Bundler",
|
|
129
|
+
lib: ["ES2023", "DOM", "DOM.Iterable"],
|
|
130
|
+
strict: true,
|
|
131
|
+
noEmit: true,
|
|
132
|
+
allowImportingTsExtensions: true,
|
|
133
|
+
resolveJsonModule: true,
|
|
134
|
+
skipLibCheck: true,
|
|
135
|
+
verbatimModuleSyntax: true,
|
|
136
|
+
types: [],
|
|
137
|
+
paths
|
|
138
|
+
},
|
|
139
|
+
include: [
|
|
140
|
+
"../../scenes/**/*",
|
|
141
|
+
"../../master/**/*",
|
|
142
|
+
"../../lib/**/*",
|
|
143
|
+
"../../data/**/*.json"
|
|
144
|
+
]
|
|
145
|
+
},
|
|
146
|
+
null,
|
|
147
|
+
2
|
|
148
|
+
) + "\n"
|
|
149
|
+
);
|
|
150
|
+
return config;
|
|
151
|
+
}
|
|
152
|
+
function parseMachineOutput(output, root) {
|
|
153
|
+
const problems = [];
|
|
154
|
+
for (const line of output.split("\n")) {
|
|
155
|
+
const match = /^\d+ (ERROR|WARNING) "(.+?)" (\d+):(\d+) "(.*)"$/.exec(line.trim());
|
|
156
|
+
if (!match) continue;
|
|
157
|
+
const file = match[2].startsWith("/") ? relative(root, match[2]) : match[2];
|
|
158
|
+
if (file.startsWith(".tobos/")) continue;
|
|
159
|
+
let message = match[5];
|
|
160
|
+
try {
|
|
161
|
+
message = JSON.parse(`"${message}"`);
|
|
162
|
+
} catch {
|
|
163
|
+
}
|
|
164
|
+
problems.push({
|
|
165
|
+
file,
|
|
166
|
+
line: Number(match[3]),
|
|
167
|
+
column: Number(match[4]),
|
|
168
|
+
rule: "types",
|
|
169
|
+
message: message.split("\n")[0],
|
|
170
|
+
severity: match[1] === "ERROR" ? "error" : "warning"
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return problems;
|
|
174
|
+
}
|
|
175
|
+
async function checkTypes(root, note) {
|
|
176
|
+
if (typeof define_TOBOS_PRESENT_TYPES_default === "undefined" || typeof define_TOBOS_TOOLCHAIN_default === "undefined")
|
|
177
|
+
throw new CliError(
|
|
178
|
+
"--types needs the built CLI (dist/tobos.js), which carries the engine's types and toolchain."
|
|
179
|
+
);
|
|
180
|
+
const { deck } = parseDeckJson(readFileSync(join(root, "deck.json"), "utf8"));
|
|
181
|
+
if (!deck) return [];
|
|
182
|
+
const dir = await toolchain(deck.dependencies ?? {}, note);
|
|
183
|
+
linkModules(root, dir);
|
|
184
|
+
const config = writeConfig(root);
|
|
185
|
+
const result = await run(
|
|
186
|
+
process.execPath,
|
|
187
|
+
[
|
|
188
|
+
join(dir, "node_modules", "svelte-check", "bin", "svelte-check"),
|
|
189
|
+
"--tsconfig",
|
|
190
|
+
config,
|
|
191
|
+
"--workspace",
|
|
192
|
+
root,
|
|
193
|
+
"--output",
|
|
194
|
+
"machine",
|
|
195
|
+
"--threshold",
|
|
196
|
+
"warning"
|
|
197
|
+
],
|
|
198
|
+
root
|
|
199
|
+
);
|
|
200
|
+
return typeProblems(result, root);
|
|
201
|
+
}
|
|
202
|
+
function typeProblems(result, root) {
|
|
203
|
+
const problems = parseMachineOutput(result.out, root);
|
|
204
|
+
const completed = /^\d+ COMPLETED /m.test(result.out);
|
|
205
|
+
if (completed && (result.code === 0 || problems.some((p) => p.severity === "error")))
|
|
206
|
+
return problems;
|
|
207
|
+
const said = result.out.trim().split("\n").slice(-5).join("\n");
|
|
208
|
+
return [
|
|
209
|
+
...problems,
|
|
210
|
+
{
|
|
211
|
+
file: "deck.json",
|
|
212
|
+
rule: "types",
|
|
213
|
+
message: `The type checker didn't finish (exit code ${result.code})${said ? `:
|
|
214
|
+
${said}` : "."}`,
|
|
215
|
+
severity: "error"
|
|
216
|
+
}
|
|
217
|
+
];
|
|
218
|
+
}
|
|
219
|
+
export {
|
|
220
|
+
checkTypes,
|
|
221
|
+
parseMachineOutput,
|
|
222
|
+
typeProblems
|
|
223
|
+
};
|