@torpor/check 1.0.17 → 1.0.18
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/bin/index.js +2 -18
- package/dist/bin/index.js.map +1 -1
- package/dist/index.d.mts +4 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/{checkFile-BvvjrnaS.mjs → printErrors-il1swuxO.mjs} +73 -13
- package/dist/printErrors-il1swuxO.mjs.map +1 -0
- package/package.json +6 -5
- package/dist/checkFile-BvvjrnaS.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -21,3 +21,8 @@ torp-check [path]
|
|
|
21
21
|
|
|
22
22
|
Checks all Torpor files in the given folder (or a single file), and prints any
|
|
23
23
|
errors found. If no path is given, the current folder is checked.
|
|
24
|
+
|
|
25
|
+
The project's own TypeScript is used when it provides the compiler API;
|
|
26
|
+
otherwise (e.g. the TypeScript 7 native package, which doesn't expose the
|
|
27
|
+
compiler enums) the TypeScript bundled with this package is used. In a Build
|
|
28
|
+
project, `tb --check` runs the same check without invoking `torp-check` directly.
|
package/dist/bin/index.js
CHANGED
|
@@ -1,26 +1,9 @@
|
|
|
1
1
|
#! /usr/bin/env node
|
|
2
|
-
import { n as check,
|
|
2
|
+
import { n as check$1, r as check, t as printErrors } from "../printErrors-il1swuxO.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import chalk from "chalk";
|
|
5
5
|
import fs, { existsSync, readdirSync, statSync } from "node:fs";
|
|
6
6
|
import path from "node:path";
|
|
7
|
-
//#region src/printErrors.ts
|
|
8
|
-
function printErrors(folder, errors) {
|
|
9
|
-
errors.sort((a, b) => a.path.localeCompare(b.path));
|
|
10
|
-
for (let error of errors) {
|
|
11
|
-
console.log(`${chalk.green(path.relative(folder, error.path))}:${chalk.yellow(error.range.start.line)}:${chalk.yellow(error.range.start.character)} - ${chalk.red("error")}${error.code ? chalk.gray(` TS${error.code}`) : ""}: ${error.message}`);
|
|
12
|
-
if (error.lineText) {
|
|
13
|
-
error.lineText = error.lineText.replaceAll(" ", " ");
|
|
14
|
-
console.log(`${chalk.black.bgWhite(error.range.start.line)} ${error.lineText}`);
|
|
15
|
-
let numberLength = error.range.start.line.toString().length;
|
|
16
|
-
let spacerLength = error.range.start.character;
|
|
17
|
-
let squiggleLength = error.range.start.line === error.range.end.line ? error.range.end.character - error.range.start.character : error.lineText.length - error.range.start.character;
|
|
18
|
-
console.log(`${chalk.black.bgWhite(" ".repeat(numberLength))} ${" ".repeat(spacerLength)}${chalk.red("~").repeat(squiggleLength)}`);
|
|
19
|
-
}
|
|
20
|
-
console.log();
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
//#endregion
|
|
24
7
|
//#region src/warnStaleView.ts
|
|
25
8
|
/**
|
|
26
9
|
* Warns when the `@torpor/view` dist that the compiler resolves to is older
|
|
@@ -78,6 +61,7 @@ if (errors.length > 0) {
|
|
|
78
61
|
console.log();
|
|
79
62
|
printErrors(path.dirname(pathArg), errors);
|
|
80
63
|
console.log(`Found ${chalk.red(errors.length)} error${errors.length === 1 ? "" : "s"}`);
|
|
64
|
+
process.exitCode = 1;
|
|
81
65
|
} else console.log("No errors found");
|
|
82
66
|
//#endregion
|
|
83
67
|
export {};
|
package/dist/bin/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["checkFile"],"sources":["../../src/
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["checkFile"],"sources":["../../src/warnStaleView.ts","../../src/bin/index.ts"],"sourcesContent":["import { existsSync, readdirSync, statSync } from \"node:fs\";\nimport path from \"node:path\";\nimport { createRequire } from \"node:module\";\n\n/**\n * Warns when the `@torpor/view` dist that the compiler resolves to is older\n * than its src tree. The check pipeline compiles `.torp` files through\n * `@torpor/view/compile`, which resolves to the packed `dist` — so after\n * changing `packages/view/src` without rebuilding, reported errors describe\n * stale compiler output that no longer matches the current compiler (this has\n * produced batches of phantom errors before). Only fires inside the monorepo,\n * where a `src` sibling exists to compare against; a one-line warning is\n * cheaper than the rebuild it saves.\n */\nexport default function warnStaleView(): void {\n\tconst require = createRequire(import.meta.url);\n\tlet viewDir: string;\n\ttry {\n\t\tviewDir = path.dirname(require.resolve(\"@torpor/view/package.json\"));\n\t} catch {\n\t\treturn;\n\t}\n\tconst srcDir = path.join(viewDir, \"src\");\n\tconst distDir = path.join(viewDir, \"dist\");\n\tif (!existsSync(srcDir) || !existsSync(distDir)) {\n\t\t// An installed copy in a user project — nothing to compare\n\t\treturn;\n\t}\n\n\tconst newestMtime = (folder: string): number => {\n\t\tlet newest = 0;\n\t\tconst walk = (dir: string): void => {\n\t\t\tfor (const entry of readdirSync(dir, { withFileTypes: true })) {\n\t\t\t\tconst full = path.join(dir, entry.name);\n\t\t\t\tif (entry.isDirectory()) {\n\t\t\t\t\twalk(full);\n\t\t\t\t} else {\n\t\t\t\t\tconst mtime = statSync(full).mtimeMs;\n\t\t\t\t\tif (mtime > newest) newest = mtime;\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\twalk(folder);\n\t\treturn newest;\n\t};\n\n\tif (newestMtime(srcDir) > newestMtime(distDir)) {\n\t\tconsole.warn(\n\t\t\t\"NOTE: @torpor/view/dist is older than its src — check results may not match the current compiler. Run `pnpm build` in packages/view to refresh.\",\n\t\t);\n\t}\n}\n","#! /usr/bin/env node\nimport chalk from \"chalk\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport check from \"../check\";\nimport checkFile from \"../checkFile\";\nimport printErrors from \"../printErrors\";\nimport type Diagnostic from \"../types/Diagnostic\";\nimport warnStaleView from \"../warnStaleView\";\n\n// Warn before checking when the compiler dist is older than its src (results\n// would describe stale compiler output)\nwarnStaleView();\n\nlet errors: Diagnostic[] = [];\n\nlet pathArg = process.argv[2];\nif (!pathArg) {\n\tpathArg = process.cwd();\n\terrors = check(pathArg);\n} else {\n\tif (!fs.existsSync(pathArg)) {\n\t\tpathArg = path.join(process.cwd(), pathArg);\n\t}\n\tif (!fs.existsSync(pathArg)) {\n\t\tconsole.log(\"Path not found\", process.argv[2]);\n\t} else if (fs.lstatSync(pathArg).isDirectory()) {\n\t\terrors = check(pathArg);\n\t} else {\n\t\terrors = checkFile(pathArg);\n\t}\n}\n\nif (errors.length > 0) {\n\tconsole.log();\n\tprintErrors(path.dirname(pathArg), errors);\n\tconsole.log(`Found ${chalk.red(errors.length)} error${errors.length === 1 ? \"\" : \"s\"}`);\n\t// A failing check should fail the command (and any CI step running it)\n\tprocess.exitCode = 1;\n} else {\n\tconsole.log(\"No errors found\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAcA,SAAwB,gBAAsB;CAC7C,MAAM,UAAU,cAAc,YAAY,GAAG;CAC7C,IAAI;CACJ,IAAI;EACH,UAAU,KAAK,QAAQ,QAAQ,QAAQ,2BAA2B,CAAC;CACpE,QAAQ;EACP;CACD;CACA,MAAM,SAAS,KAAK,KAAK,SAAS,KAAK;CACvC,MAAM,UAAU,KAAK,KAAK,SAAS,MAAM;CACzC,IAAI,CAAC,WAAW,MAAM,KAAK,CAAC,WAAW,OAAO,GAE7C;CAGD,MAAM,eAAe,WAA2B;EAC/C,IAAI,SAAS;EACb,MAAM,QAAQ,QAAsB;GACnC,KAAK,MAAM,SAAS,YAAY,KAAK,EAAE,eAAe,KAAK,CAAC,GAAG;IAC9D,MAAM,OAAO,KAAK,KAAK,KAAK,MAAM,IAAI;IACtC,IAAI,MAAM,YAAY,GACrB,KAAK,IAAI;SACH;KACN,MAAM,QAAQ,SAAS,IAAI,CAAC,CAAC;KAC7B,IAAI,QAAQ,QAAQ,SAAS;IAC9B;GACD;EACD;EACA,KAAK,MAAM;EACX,OAAO;CACR;CAEA,IAAI,YAAY,MAAM,IAAI,YAAY,OAAO,GAC5C,QAAQ,KACP,iJACD;AAEF;;;ACvCA,cAAc;AAEd,IAAI,SAAuB,CAAC;AAE5B,IAAI,UAAU,QAAQ,KAAK;AAC3B,IAAI,CAAC,SAAS;CACb,UAAU,QAAQ,IAAI;CACtB,SAAS,MAAM,OAAO;AACvB,OAAO;CACN,IAAI,CAAC,GAAG,WAAW,OAAO,GACzB,UAAU,KAAK,KAAK,QAAQ,IAAI,GAAG,OAAO;CAE3C,IAAI,CAAC,GAAG,WAAW,OAAO,GACzB,QAAQ,IAAI,kBAAkB,QAAQ,KAAK,EAAE;MACvC,IAAI,GAAG,UAAU,OAAO,CAAC,CAAC,YAAY,GAC5C,SAAS,MAAM,OAAO;MAEtB,SAASA,QAAU,OAAO;AAE5B;AAEA,IAAI,OAAO,SAAS,GAAG;CACtB,QAAQ,IAAI;CACZ,YAAY,KAAK,QAAQ,OAAO,GAAG,MAAM;CACzC,QAAQ,IAAI,SAAS,MAAM,IAAI,OAAO,MAAM,EAAE,QAAQ,OAAO,WAAW,IAAI,KAAK,KAAK;CAEtF,QAAQ,WAAW;AACpB,OACC,QAAQ,IAAI,iBAAiB"}
|
package/dist/index.d.mts
CHANGED
|
@@ -22,5 +22,8 @@ declare function check(folder: string): Diagnostic[];
|
|
|
22
22
|
//#region src/checkFile.d.ts
|
|
23
23
|
declare function check$1(file: string): Diagnostic[];
|
|
24
24
|
//#endregion
|
|
25
|
-
|
|
25
|
+
//#region src/printErrors.d.ts
|
|
26
|
+
declare function printErrors(folder: string, errors: Diagnostic[]): void;
|
|
27
|
+
//#endregion
|
|
28
|
+
export { check, check$1 as checkFile, printErrors };
|
|
26
29
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":["check"],"sources":["../src/types/Diagnostic.ts","../src/check.ts","../src/checkFile.ts"],"mappings":";UAAyB;EACxB;EACA;EACA;EACA;IACC;MAAS;MAAc;;IACvB;MAAO;MAAc;;;EAEtB;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["check"],"sources":["../src/types/Diagnostic.ts","../src/check.ts","../src/checkFile.ts","../src/printErrors.ts"],"mappings":";UAAyB;EACxB;EACA;EACA;EACA;IACC;MAAS;MAAc;;IACvB;MAAO;MAAc;;;EAEtB;;;;iBCEuB,MAAM,iBAAiB;;;iBCLvBA,QAAM,eAAe;;;iBCDrB,YAAY,gBAAgB,QAAQ"}
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { r as check, n as checkFile, t as printErrors } from "./printErrors-il1swuxO.mjs";
|
|
@@ -1,24 +1,54 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
1
2
|
import tsvfs from "@typescript/vfs";
|
|
2
3
|
import chalk from "chalk";
|
|
3
4
|
import fg from "fast-glob";
|
|
4
5
|
import fs from "node:fs";
|
|
5
6
|
import path from "node:path";
|
|
6
|
-
import ts from "typescript";
|
|
7
7
|
import path$1 from "path";
|
|
8
8
|
import { build, parse } from "@torpor/view/compile";
|
|
9
|
+
//#region src/typescriptLoader.ts
|
|
10
|
+
/**
|
|
11
|
+
* Checks that a TypeScript module provides the API surface that the check
|
|
12
|
+
* pipeline uses. Newer versions of TypeScript may drop or change the compiler
|
|
13
|
+
* API (e.g. the TypeScript 7 native package does not expose the compiler
|
|
14
|
+
* enums), in which case the version bundled with this package is used instead.
|
|
15
|
+
*/
|
|
16
|
+
function isCompatible(ts) {
|
|
17
|
+
const api = ts;
|
|
18
|
+
return !!api && typeof api.version === "string" && typeof api.createProgram === "function" && typeof api.createLanguageService === "function" && !!api.sys && typeof api.sys.getExecutingFilePath === "function" && !!api.ScriptTarget && !!api.ModuleKind && !!api.ModuleResolutionKind;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Loads the TypeScript module to check a project with.
|
|
22
|
+
*
|
|
23
|
+
* Prefers the project's own installed version (resolved from the project
|
|
24
|
+
* root, like Node would), so that diagnostics match the user's build.
|
|
25
|
+
* TypeScript 7 (the native package) doesn't expose the compiler API that the
|
|
26
|
+
* check needs, and a project may not have TypeScript installed at all, so it
|
|
27
|
+
* falls back to the version bundled with this package.
|
|
28
|
+
*/
|
|
29
|
+
function loadTypeScriptModule(projectRoot) {
|
|
30
|
+
try {
|
|
31
|
+
const ts = createRequire(path.join(projectRoot, "package.json"))("typescript");
|
|
32
|
+
if (isCompatible(ts)) {
|
|
33
|
+
console.log(`Using TypeScript ${ts.version} from the project`);
|
|
34
|
+
return ts;
|
|
35
|
+
}
|
|
36
|
+
console.log(`Project TypeScript ${ts.version} does not provide the compiler API, falling back to the bundled version`);
|
|
37
|
+
} catch {}
|
|
38
|
+
const ts = createRequire(import.meta.url)("typescript");
|
|
39
|
+
console.log(`Using bundled TypeScript ${ts.version}`);
|
|
40
|
+
return ts;
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
9
43
|
//#region src/loadVts.ts
|
|
10
44
|
let vts = {
|
|
45
|
+
ts: void 0,
|
|
11
46
|
env: void 0,
|
|
12
47
|
lang: void 0,
|
|
13
48
|
projectRoot: "",
|
|
14
49
|
configPath: void 0,
|
|
15
50
|
config: {
|
|
16
|
-
options: {
|
|
17
|
-
target: ts.ScriptTarget.ES2022,
|
|
18
|
-
module: ts.ModuleKind.ESNext,
|
|
19
|
-
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
20
|
-
esModuleInterop: true
|
|
21
|
-
},
|
|
51
|
+
options: {},
|
|
22
52
|
include: [],
|
|
23
53
|
exclude: []
|
|
24
54
|
},
|
|
@@ -33,8 +63,20 @@ function loadVts(vtsPath) {
|
|
|
33
63
|
console.log("No project root found");
|
|
34
64
|
return;
|
|
35
65
|
}
|
|
66
|
+
const ts = loadTypeScriptModule(vts.projectRoot);
|
|
67
|
+
vts.ts = ts;
|
|
68
|
+
vts.config = {
|
|
69
|
+
options: {
|
|
70
|
+
target: ts.ScriptTarget.ES2022,
|
|
71
|
+
module: ts.ModuleKind.ESNext,
|
|
72
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
73
|
+
esModuleInterop: true
|
|
74
|
+
},
|
|
75
|
+
include: [],
|
|
76
|
+
exclude: []
|
|
77
|
+
};
|
|
36
78
|
try {
|
|
37
|
-
let fileConfig = loadTypeScriptConfig();
|
|
79
|
+
let fileConfig = loadTypeScriptConfig(ts);
|
|
38
80
|
if (fileConfig?.options) vts.config = {
|
|
39
81
|
options: fileConfig.options,
|
|
40
82
|
include: fileConfig.raw.include ?? [],
|
|
@@ -50,11 +92,11 @@ function loadVts(vtsPath) {
|
|
|
50
92
|
}
|
|
51
93
|
return vts;
|
|
52
94
|
}
|
|
53
|
-
function loadTypeScriptConfig() {
|
|
54
|
-
const configFileName = ts.findConfigFile(vts.projectRoot, ts.sys.fileExists);
|
|
95
|
+
function loadTypeScriptConfig(ts) {
|
|
96
|
+
const configFileName = ts.findConfigFile(vts.projectRoot, (fileName) => ts.sys.fileExists(fileName));
|
|
55
97
|
if (configFileName) {
|
|
56
98
|
vts.configPath = path$1.dirname(configFileName);
|
|
57
|
-
const configFile = ts.readConfigFile(configFileName, ts.sys.readFile);
|
|
99
|
+
const configFile = ts.readConfigFile(configFileName, (fileName) => ts.sys.readFile(fileName));
|
|
58
100
|
return ts.parseJsonConfigFileContent(configFile.config, ts.sys, vts.projectRoot);
|
|
59
101
|
}
|
|
60
102
|
}
|
|
@@ -385,6 +427,7 @@ function check$1(folder) {
|
|
|
385
427
|
console.log("Checking files in", folder);
|
|
386
428
|
const vts = loadVts(folder);
|
|
387
429
|
if (vts === void 0) return [];
|
|
430
|
+
const ts = vts.ts;
|
|
388
431
|
let pathToGlob = (f) => {
|
|
389
432
|
f = fg.convertPathToPattern(f).replaceAll("\\*", "*");
|
|
390
433
|
if (!f.includes("*")) {
|
|
@@ -441,6 +484,23 @@ function check(file) {
|
|
|
441
484
|
return validateScript(file);
|
|
442
485
|
}
|
|
443
486
|
//#endregion
|
|
444
|
-
|
|
487
|
+
//#region src/printErrors.ts
|
|
488
|
+
function printErrors(folder, errors) {
|
|
489
|
+
errors.sort((a, b) => a.path.localeCompare(b.path));
|
|
490
|
+
for (let error of errors) {
|
|
491
|
+
console.log(`${chalk.green(path.relative(folder, error.path))}:${chalk.yellow(error.range.start.line)}:${chalk.yellow(error.range.start.character)} - ${chalk.red("error")}${error.code ? chalk.gray(` TS${error.code}`) : ""}: ${error.message}`);
|
|
492
|
+
if (error.lineText) {
|
|
493
|
+
error.lineText = error.lineText.replaceAll(" ", " ");
|
|
494
|
+
console.log(`${chalk.black.bgWhite(error.range.start.line)} ${error.lineText}`);
|
|
495
|
+
let numberLength = error.range.start.line.toString().length;
|
|
496
|
+
let spacerLength = error.range.start.character;
|
|
497
|
+
let squiggleLength = error.range.start.line === error.range.end.line ? error.range.end.character - error.range.start.character : error.lineText.length - error.range.start.character;
|
|
498
|
+
console.log(`${chalk.black.bgWhite(" ".repeat(numberLength))} ${" ".repeat(spacerLength)}${chalk.red("~").repeat(squiggleLength)}`);
|
|
499
|
+
}
|
|
500
|
+
console.log();
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
//#endregion
|
|
504
|
+
export { check as n, check$1 as r, printErrors as t };
|
|
445
505
|
|
|
446
|
-
//# sourceMappingURL=
|
|
506
|
+
//# sourceMappingURL=printErrors-il1swuxO.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"printErrors-il1swuxO.mjs","names":["path","check"],"sources":["../src/typescriptLoader.ts","../src/loadVts.ts","../src/pathReplace.ts","../src/transformDocument.ts","../src/loadDocument.ts","../src/processErrors.ts","../src/check.ts","../src/validateScript.ts","../src/checkFile.ts","../src/printErrors.ts"],"sourcesContent":["import { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport type TS from \"typescript\";\n\nexport type TypeScriptModule = typeof TS;\n\n/**\n * Checks that a TypeScript module provides the API surface that the check\n * pipeline uses. Newer versions of TypeScript may drop or change the compiler\n * API (e.g. the TypeScript 7 native package does not expose the compiler\n * enums), in which case the version bundled with this package is used instead.\n */\nfunction isCompatible(ts: TypeScriptModule): boolean {\n\tconst api = ts as unknown as Record<string, any> | undefined;\n\treturn (\n\t\t!!api &&\n\t\ttypeof api.version === \"string\" &&\n\t\ttypeof api.createProgram === \"function\" &&\n\t\ttypeof api.createLanguageService === \"function\" &&\n\t\t!!api.sys &&\n\t\ttypeof api.sys.getExecutingFilePath === \"function\" &&\n\t\t!!api.ScriptTarget &&\n\t\t!!api.ModuleKind &&\n\t\t!!api.ModuleResolutionKind\n\t);\n}\n\n/**\n * Loads the TypeScript module to check a project with.\n *\n * Prefers the project's own installed version (resolved from the project\n * root, like Node would), so that diagnostics match the user's build.\n * TypeScript 7 (the native package) doesn't expose the compiler API that the\n * check needs, and a project may not have TypeScript installed at all, so it\n * falls back to the version bundled with this package.\n */\nexport default function loadTypeScriptModule(projectRoot: string): TypeScriptModule {\n\ttry {\n\t\tconst require = createRequire(path.join(projectRoot, \"package.json\"));\n\t\tconst ts = require(\"typescript\") as TypeScriptModule;\n\t\tif (isCompatible(ts)) {\n\t\t\tconsole.log(`Using TypeScript ${ts.version} from the project`);\n\t\t\treturn ts;\n\t\t}\n\t\tconsole.log(\n\t\t\t`Project TypeScript ${ts.version} does not provide the compiler API, ` +\n\t\t\t\t`falling back to the bundled version`,\n\t\t);\n\t} catch {\n\t\t// The project does not have TypeScript installed\n\t}\n\n\tconst require = createRequire(import.meta.url);\n\tconst ts = require(\"typescript\") as TypeScriptModule;\n\tconsole.log(`Using bundled TypeScript ${ts.version}`);\n\treturn ts;\n}\n","import tsvfs from \"@typescript/vfs\";\nimport fs from \"node:fs\";\nimport path from \"path\";\nimport type { LanguageService } from \"typescript\";\nimport loadTypeScriptModule, { type TypeScriptModule } from \"./typescriptLoader\";\nimport type SourceMap from \"./types/SourceMap\";\nimport type VirtualTypeScript from \"./types/VirtualTypeScript\";\n\nlet vts: VirtualTypeScript = {\n\t// @ts-ignore This will definitely be set\n\tts: undefined,\n\t// @ts-ignore This will definitely be set\n\tenv: undefined,\n\t// @ts-ignore This will definitely be set\n\tlang: undefined,\n\tprojectRoot: \"\",\n\tconfigPath: undefined,\n\t// This is just the default config, it should be overwritten by the one from\n\t// the user's tsconfig.json (it's built in loadVts, once the TypeScript\n\t// module -- which owns the compiler enums -- has been loaded)\n\tconfig: {\n\t\toptions: {},\n\t\tinclude: [],\n\t\texclude: [],\n\t},\n\tvirtualFiles: new Map<string, string>(),\n\tvirtualFileMaps: new Map<string, { sourceFile: string; map: SourceMap[] }>(),\n};\n\nexport default function loadVts(vtsPath: string): VirtualTypeScript | undefined {\n\tif (vts.env === undefined) {\n\t\t// If using imports where the types don't directly match up to\n\t\t// their FS representation (like the imports for node) then use\n\t\t// triple-slash directives to make sure globals are set up\n\t\t// first.\n\t\t//const content = `\n\t\t//\t/// <reference types=\"node\" />\n\t\t//\timport * as path from 'path';\n\t\t//\tpath.`.replaceAll(/\\s+/, \" \").trim();\n\n\t\t// By providing a project root, the system knows how to resolve\n\t\t// node_modules correctly\n\t\tvts.projectRoot = path.join(vtsPath, \".\");\n\t\twhile (vts.projectRoot && !fs.existsSync(path.join(vts.projectRoot, \"node_modules\"))) {\n\t\t\tvts.projectRoot = path.join(vts.projectRoot, \"..\");\n\t\t}\n\t\tif (!vts.projectRoot) {\n\t\t\tconsole.log(\"No project root found\");\n\t\t\treturn;\n\t\t}\n\n\t\t// The TypeScript module to check with: the project's own version when\n\t\t// it provides the compiler API, otherwise the one bundled with this\n\t\t// package (TypeScript 7's native package does not)\n\t\tconst ts = loadTypeScriptModule(vts.projectRoot);\n\t\tvts.ts = ts;\n\n\t\t// The default config, used when the user's tsconfig.json can't be read\n\t\tvts.config = {\n\t\t\toptions: {\n\t\t\t\ttarget: ts.ScriptTarget.ES2022,\n\t\t\t\tmodule: ts.ModuleKind.ESNext,\n\t\t\t\tmoduleResolution: ts.ModuleResolutionKind.Bundler,\n\t\t\t\tesModuleInterop: true,\n\t\t\t},\n\t\t\tinclude: [],\n\t\t\texclude: [],\n\t\t};\n\n\t\t// Maybe load tsconfig from a file\n\t\t// TODO: reload if the file is changed\n\t\ttry {\n\t\t\tlet fileConfig = loadTypeScriptConfig(ts);\n\t\t\tif (fileConfig?.options) {\n\t\t\t\tvts.config = {\n\t\t\t\t\toptions: fileConfig.options,\n\t\t\t\t\tinclude: fileConfig.raw.include ?? [],\n\t\t\t\t\texclude: fileConfig.raw.exclude ?? [],\n\t\t\t\t};\n\t\t\t}\n\t\t} catch {\n\t\t\tconsole.log(\"No tsconfig.json file found, using default\");\n\t\t}\n\n\t\tconst system = tsvfs.createFSBackedSystem(vts.virtualFiles, vts.projectRoot, ts);\n\t\tvts.env = tsvfs.createVirtualTypeScriptEnvironment(system, [], ts, vts.config.options);\n\t\tvts.lang = vts.env.languageService as LanguageService;\n\n\t\tconsole.log(\"Torpor type checking loaded\");\n\t}\n\treturn vts;\n}\n\nfunction loadTypeScriptConfig(ts: TypeScriptModule): Record<string, any> | undefined {\n\tconst configFileName = ts.findConfigFile(vts.projectRoot, (fileName) =>\n\t\tts.sys.fileExists(fileName),\n\t);\n\tif (configFileName) {\n\t\tvts.configPath = path.dirname(configFileName);\n\t\tconst configFile = ts.readConfigFile(configFileName, (fileName) => ts.sys.readFile(fileName));\n\t\treturn ts.parseJsonConfigFileContent(configFile.config, ts.sys, vts.projectRoot);\n\t}\n}\n","// TODO: Implement more logic from https://www.typescriptlang.org/docs/handbook/modules/reference.html#paths\nexport default function pathReplace(pattern: string, replacement: string, value: string): string {\n\tpattern = \"^\" + pattern.replaceAll(\"*\", \"(.+?)\");\n\treplacement = replacement.replaceAll(\"*\", \"$1\");\n\n\tconst regex1 = new RegExp(pattern);\n\treturn value.replace(regex1, replacement);\n}\n","import { build, parse } from \"@torpor/view/compile\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport pathReplace from \"./pathReplace\";\nimport type Diagnostic from \"./types/Diagnostic\";\nimport type SourceMap from \"./types/SourceMap\";\nimport type VirtualTypeScript from \"./types/VirtualTypeScript\";\n\ninterface TransformResult {\n\tok: boolean;\n\terrors: Diagnostic[];\n\tcontent: string;\n\tmap: SourceMap[];\n}\n\nexport default function transformDocument(\n\tvts: VirtualTypeScript,\n\tfilename: string,\n\tsource: string,\n\tdebug = false,\n): TransformResult {\n\ttry {\n\t\t// Build the main file as a component\n\t\tconst parsed = parse(source);\n\n\t\t// If not ok, don't validate\n\t\tif (!parsed.ok) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\terrors: parsed.errors.map((e) => {\n\t\t\t\t\tlet lineTextStart = e.startIndex;\n\t\t\t\t\twhile (lineTextStart >= 0) {\n\t\t\t\t\t\tif (source[lineTextStart] === \"\\n\") {\n\t\t\t\t\t\t\tlineTextStart++;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlineTextStart--;\n\t\t\t\t\t}\n\t\t\t\t\tlet lineTextEnd: number | undefined = source.indexOf(\"\\n\", e.startIndex);\n\t\t\t\t\tif (lineTextEnd === -1) lineTextEnd = undefined;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tpath: filename,\n\t\t\t\t\t\tmessage: e.message,\n\t\t\t\t\t\trange: {\n\t\t\t\t\t\t\tstart: { line: e.startLine, character: e.startChar },\n\t\t\t\t\t\t\tend: { line: e.endLine, character: e.endChar },\n\t\t\t\t\t\t},\n\t\t\t\t\t\tlineText: source.substring(lineTextStart, lineTextEnd),\n\t\t\t\t\t} satisfies Diagnostic;\n\t\t\t\t}),\n\t\t\t\tcontent: \"\",\n\t\t\t\tmap: [],\n\t\t\t};\n\t\t}\n\n\t\tlet { code, map } = build(parsed.template!, { mapped: true });\n\n\t\tcode = importComponentFiles(vts, filename, code, map, debug);\n\n\t\t//console.log(code);\n\t\t//console.log(map);\n\n\t\treturn {\n\t\t\tok: true,\n\t\t\terrors: [],\n\t\t\tcontent: code,\n\t\t\tmap,\n\t\t};\n\t} catch (ex) {\n\t\tconst message = ex instanceof Error ? ex.stack : String(ex);\n\t\tconsole.log(\"Failed to compile\", filename);\n\t\tconsole.log(message);\n\t\treturn {\n\t\t\tok: false,\n\t\t\terrors: [],\n\t\t\tcontent: \"\",\n\t\t\tmap: [],\n\t\t};\n\t}\n}\n\nfunction importComponentFiles(\n\tvts: VirtualTypeScript,\n\tfilename: string,\n\tcontent: string,\n\tmap: SourceMap[],\n\t_debug = false,\n): string {\n\tif (!/^\\s*import\\s+(.+?)\\s+from\\s+(.+?);*\\s*$/ms.test(content)) {\n\t\treturn content;\n\t}\n\n\t// Build imported component files and add them to the virtual file map\n\t// TODO: Handle files from node_modules? Might get done automatically by typescript-vfs\n\n\t// HACK: We're assuming that all imports are at the top of the file, and\n\t// that there are not multiple imports on the one line\n\tconst first = map.shift()!;\n\tconst filepath = path.dirname(filename);\n\n\tlet moved = 0;\n\tlet newMaps: SourceMap[] = [];\n\n\tfor (let i = 0; i < first.script.length; i++) {\n\t\tif (first.script[i] === \"/\") {\n\t\t\t// Skip comments\n\t\t\tif (first.script[i + 1] === \"/\") {\n\t\t\t\ti = first.script.indexOf(\"\\n\", i);\n\t\t\t} else if (first.script[i + 1] === \"*\") {\n\t\t\t\ti = first.script.indexOf(\"*/\", i);\n\t\t\t}\n\t\t\tif (i === -1) {\n\t\t\t\treturn content;\n\t\t\t}\n\t\t} else if (first.script[i] === \"i\") {\n\t\t\tconst match = first.script.substring(i).match(/import\\s+(.+?)\\s+from\\s+(.+?);*\\s*$/ms);\n\t\t\tif (match === null) continue;\n\n\t\t\tconst oldImport = match[0];\n\t\t\t//const names = match[1];\n\t\t\tconst importedFile = match[2];\n\n\t\t\t// Strip quotes\n\t\t\tlet importFile = importedFile;\n\t\t\tif (\n\t\t\t\t(importFile.startsWith(\"'\") && importFile.endsWith(\"'\")) ||\n\t\t\t\t(importFile.startsWith('\"') && importFile.endsWith('\"'))\n\t\t\t) {\n\t\t\t\timportFile = importFile.substring(1, importFile.length - 1);\n\t\t\t}\n\n\t\t\t// Just map import files that aren't components\n\t\t\tif (!importFile.endsWith(\".torp\")) {\n\t\t\t\tnewMaps.push({\n\t\t\t\t\tscript: oldImport,\n\t\t\t\t\tsource: {\n\t\t\t\t\t\tstart: i,\n\t\t\t\t\t\tend: i + oldImport.length,\n\t\t\t\t\t},\n\t\t\t\t\tcompiled: {\n\t\t\t\t\t\tstart: first.compiled.start + i + moved,\n\t\t\t\t\t\tend: first.compiled.start + i + moved + oldImport.length,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Get the absolute path of the import file\n\t\t\tlet typeFile = importFile.startsWith(\".\") ? path.join(filepath, importFile) : importFile;\n\n\t\t\t// Replace aliased paths from tsconfig.json\n\t\t\tif (vts.configPath && vts.config.options.paths) {\n\t\t\t\t// HACK: Get the longest match etc\n\t\t\t\tconst oldTypeFile = typeFile;\n\t\t\t\tfor (let [srcGlob, paths] of Object.entries(vts.config.options.paths)) {\n\t\t\t\t\tfor (let destGlob of paths) {\n\t\t\t\t\t\ttypeFile = pathReplace(srcGlob, destGlob, typeFile);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// The import may now be relative to the tsconfig file, so make it absolute\n\t\t\t\tif (typeFile !== oldTypeFile && typeFile.startsWith(\".\")) {\n\t\t\t\t\ttypeFile = path.join(vts.configPath, typeFile);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Create the virtual file for the component\n\t\t\tconst key = typeFile.replace(/\\.torp$/, \".ts\");\n\t\t\tif (!vts.virtualFiles.has(key) && fs.existsSync(typeFile)) {\n\t\t\t\t// Mark as in progress before transforming, so that circular\n\t\t\t\t// component imports don't recurse forever\n\t\t\t\tvts.virtualFiles.set(key, \"\");\n\t\t\t\tconst typeSource = fs.readFileSync(typeFile, \"utf8\");\n\t\t\t\tconst { content } = transformDocument(vts, typeFile, typeSource);\n\t\t\t\tvts.virtualFiles.set(key, content);\n\t\t\t\tvts.env.createFile(key, content);\n\t\t\t}\n\n\t\t\t// Replace the import file with the virtual file\n\t\t\tlet oldLength = content.length;\n\t\t\tlet newValue = typeFile.replace(\".torp\", \".ts\");\n\t\t\t// HACK: We could concat this if we could be bothered\n\t\t\tlet newImport = oldImport.replace(importFile, newValue);\n\t\t\tcontent = content.replace(oldImport, newImport);\n\n\t\t\t// Move subsequent ranges around\n\t\t\tlet diff = content.length - oldLength;\n\t\t\tfor (let mapped of map) {\n\t\t\t\tmapped.compiled.start += diff;\n\t\t\t\tmapped.compiled.end += diff;\n\t\t\t}\n\n\t\t\t// Add a range for the changed import\n\t\t\tnewMaps.push({\n\t\t\t\tscript: oldImport,\n\t\t\t\tsource: {\n\t\t\t\t\tstart: i,\n\t\t\t\t\tend: i + oldImport.length,\n\t\t\t\t},\n\t\t\t\tcompiled: {\n\t\t\t\t\tstart: first.compiled.start + i + moved,\n\t\t\t\t\tend: first.compiled.start + i + moved + newImport.length,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tmoved += diff;\n\t\t\ti += oldImport.length;\n\t\t}\n\t}\n\n\tmap.unshift(...newMaps);\n\n\treturn content;\n}\n","import fs from \"node:fs\";\nimport loadVts from \"./loadVts\";\nimport transformDocument from \"./transformDocument\";\nimport type Diagnostic from \"./types/Diagnostic\";\nimport type SourceMap from \"./types/SourceMap\";\nimport type VirtualTypeScript from \"./types/VirtualTypeScript\";\n\ntype LoadResult =\n\t| { ok: false; errors: Diagnostic[] }\n\t| {\n\t\t\tok: true;\n\t\t\tfilename: string;\n\t\t\tkey: string;\n\t\t\ttext: string;\n\t\t\tcontent: string;\n\t\t\tmap: SourceMap[];\n\t\t\tvts: VirtualTypeScript;\n\t };\n\nexport function loadDocument(filename: string): LoadResult {\n\tconst key = filename.replace(/\\.torp$/, \".ts\");\n\n\tconst vts = loadVts(filename);\n\tif (vts === undefined) {\n\t\treturn { ok: false, errors: [] };\n\t}\n\n\tconst text = fs.readFileSync(filename, \"utf-8\");\n\tif (filename.endsWith(\".torp\")) {\n\t\tconst transformed = transformDocument(vts, filename, text);\n\t\tif (!transformed.ok) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\terrors: transformed.errors,\n\t\t\t};\n\t\t}\n\t\tconst { content, map } = transformed;\n\t\tupdateVirtualFile(vts, key, content, filename, map);\n\t\treturn { ok: true, filename, key, text, content, map, vts: vts };\n\t} else {\n\t\tupdateVirtualFile(vts, key, text, filename, []);\n\t\treturn { ok: true, filename, key, text, content: text, map: [], vts: vts };\n\t}\n}\n\nfunction updateVirtualFile(\n\tvts: VirtualTypeScript,\n\tkey: string,\n\tcontent: string,\n\tsourceFile: string,\n\tmap: SourceMap[],\n) {\n\tif (!vts.virtualFiles.has(key)) {\n\t\tvts.env.createFile(key, content);\n\t} else {\n\t\tvts.env.updateFile(key, content);\n\t}\n\tvts.virtualFiles.set(key, content);\n\tvts.virtualFileMaps.set(key, { sourceFile, map });\n}\n","import fs from \"node:fs\";\nimport type ts from \"typescript\";\nimport type { DiagnosticMessageChain } from \"typescript\";\nimport type Diagnostic from \"./types/Diagnostic\";\nimport type SourceMap from \"./types/SourceMap\";\nimport type VirtualTypeScript from \"./types/VirtualTypeScript\";\n\nexport default function processErrors(\n\tvts: VirtualTypeScript,\n\terrors: ts.Diagnostic[],\n): Diagnostic[] {\n\treturn errors\n\t\t.map((d: ts.Diagnostic) => {\n\t\t\tlet message = getMessageText(d);\n\n\t\t\tif (d.file === undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tpath: \"\",\n\t\t\t\t\tmessage,\n\t\t\t\t\trange: {\n\t\t\t\t\t\tstart: { line: 0, character: 0 },\n\t\t\t\t\t\tend: { line: 0, character: 0 },\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tlet filename = d.file.fileName;\n\t\t\tlet map: SourceMap[] = [];\n\t\t\tif (vts.virtualFileMaps.has(filename)) {\n\t\t\t\tlet transformed = vts.virtualFileMaps.get(filename)!;\n\t\t\t\tfilename = transformed.sourceFile;\n\t\t\t\tmap = transformed.map;\n\t\t\t}\n\t\t\tconst source = fs.readFileSync(filename, \"utf-8\");\n\t\t\tlet lineText: string | undefined;\n\t\t\tif (!filename.endsWith(\".torp\")) {\n\t\t\t\tlet start = { line: 0, character: 0 };\n\t\t\t\tlet end = { line: 0, character: 0 };\n\t\t\t\tif (d.start !== undefined) {\n\t\t\t\t\t// @ts-ignore we know this exists\n\t\t\t\t\tlet lineMap: number[] = d.file.lineMap;\n\t\t\t\t\tif (lineMap === undefined) {\n\t\t\t\t\t\tlineMap = [0];\n\t\t\t\t\t\tfor (let i = 0; i < source.length; i++) {\n\t\t\t\t\t\t\tif (source[i] === \"\\n\") lineMap.push(i);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// TODO: These need to be indexes\n\t\t\t\t\tstart.line = (lineMap.findIndex((l: number) => l > d.start!) ?? 1) - 1;\n\t\t\t\t\tstart.character = d.start - lineMap[start.line] - 1;\n\t\t\t\t\tlet endx = d.start! + (d.length ?? 0);\n\t\t\t\t\tend.line = (lineMap.findIndex((l: number) => l >= endx) ?? 1) - 1;\n\t\t\t\t\tend.character = endx - lineMap[end.line] - 1;\n\t\t\t\t\tlet lineStart = lineMap[start.line] + 1;\n\t\t\t\t\tlet lineEnd = lineMap[start.line + 1];\n\t\t\t\t\tlineText = source.substring(lineStart, lineEnd);\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tpath: filename,\n\t\t\t\t\tmessage,\n\t\t\t\t\trange: { start, end },\n\t\t\t\t\tlineText,\n\t\t\t\t} satisfies Diagnostic;\n\t\t\t}\n\n\t\t\t// Find the mapping between source and compiled, if it exists. If it\n\t\t\t// doesn't exist, the error must be in non-user code. Not great, but\n\t\t\t// the user doesn't need to know about it\n\t\t\tlet start = d.start ?? 0;\n\t\t\tlet end = (d.start ?? 0) + (d.length ?? 0);\n\t\t\tlet mapped = map.find((m: any) => start >= m.compiled.start && end <= m.compiled.end);\n\n\t\t\t// HACK: We don't care about these? Maybe there's a better way to\n\t\t\t// ignore/fix them\n\t\t\tif (\n\t\t\t\tmessage.startsWith(\"This import uses a '.ts' extension to resolve\") ||\n\t\t\t\t/Cannot find module '(.+?)\\?raw'/.test(message)\n\t\t\t) {\n\t\t\t\tmapped = undefined;\n\t\t\t\t// This special message will be filtered out\n\t\t\t\tmessage = \"!\";\n\t\t\t}\n\n\t\t\t//if (!mapped && message !== \"!\") {\n\t\t\t//\t// Log it for diagnostics\n\t\t\t//\tconsole.log(`Error${!mapped ? \" (unmapped)\" : \"\"}:`, message);\n\t\t\t//\t// @ts-ignore we know this exists\n\t\t\t//\tconst lineMap: number[] = d.file?.lineMap;\n\t\t\t//\tif (lineMap) {\n\t\t\t//\t\tconst line = (lineMap.findIndex((l: number) => l > start) ?? 1) - 1;\n\t\t\t//\t\tconst char = start - lineMap[line];\n\t\t\t//\t\tconsole.log(`(${line + 1}, ${char + 1}):`, content.split(\"\\n\")[line]);\n\t\t\t//\t}\n\t\t\t//}\n\n\t\t\t// HACK: Couldn't map back to the source, so just display it at the\n\t\t\t// first character\n\t\t\tif (!mapped) {\n\t\t\t\treturn {\n\t\t\t\t\tpath: filename,\n\t\t\t\t\tmessage,\n\t\t\t\t\trange: {\n\t\t\t\t\t\tstart: { line: 0, character: 0 },\n\t\t\t\t\t\tend: { line: 0, character: 0 },\n\t\t\t\t\t},\n\t\t\t\t} satisfies Diagnostic;\n\t\t\t}\n\n\t\t\t// We have the mapping, so we know roughly where in the\n\t\t\t// source the error occurs, but now we need to narrow it\n\t\t\t// down to the exact location\n\t\t\tlet sourceStart = mapped.source.start + start - mapped.compiled.start;\n\t\t\tlet sourceEnd = mapped.source.start + end - mapped.compiled.start;\n\t\t\t// HACK: If the translated mapping is outside of the source mapping,\n\t\t\t// just highlight the source mapping. It won't be 100% accurate, but\n\t\t\t// better than showing it way off in the middle of nowhere. This\n\t\t\t// happens e.g. when the $props are bad (as `<Component>` maps to\n\t\t\t// something like `Component($parent, $anchor, $props)`\n\t\t\tif (sourceStart > mapped.source.end) {\n\t\t\t\tsourceStart = mapped.source.start;\n\t\t\t\tsourceEnd = mapped.source.end;\n\t\t\t}\n\t\t\t// Same thing for if the error extends too far\n\t\t\tif (sourceEnd > mapped.source.end) {\n\t\t\t\tsourceEnd = mapped.source.end;\n\t\t\t}\n\n\t\t\t// TODO: Store this, so we don't need to start from 0 every time\n\t\t\tlet lastLineStart = 0;\n\t\t\tlet startLine = 0;\n\t\t\tfor (let i = 0; i < sourceStart; i++) {\n\t\t\t\tif (source[i] === \"\\n\") {\n\t\t\t\t\tlastLineStart = i + 1;\n\t\t\t\t\tstartLine++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlet startChar = sourceStart - lastLineStart; /*- 1*/\n\n\t\t\tlet lastLineEnd: number | undefined = source.indexOf(\"\\n\", lastLineStart + 1);\n\t\t\tif (lastLineEnd === -1) lastLineEnd = undefined;\n\t\t\tlineText = source.substring(lastLineStart, lastLineEnd);\n\n\t\t\tlet endLine = startLine;\n\t\t\tfor (let i = sourceStart; i < sourceEnd; i++) {\n\t\t\t\tif (source[i] === \"\\n\") {\n\t\t\t\t\tlastLineStart = i;\n\t\t\t\t\tendLine++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlet endChar = sourceEnd - lastLineStart; // - 1;\n\n\t\t\treturn {\n\t\t\t\tpath: filename,\n\t\t\t\tmessage,\n\t\t\t\tcode: d.code,\n\t\t\t\trange: {\n\t\t\t\t\tstart: {\n\t\t\t\t\t\tline: startLine,\n\t\t\t\t\t\tcharacter: startChar,\n\t\t\t\t\t},\n\t\t\t\t\tend: {\n\t\t\t\t\t\tline: endLine,\n\t\t\t\t\t\tcharacter: endChar,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tlineText,\n\t\t\t} satisfies Diagnostic;\n\t\t})\n\t\t.filter((d) => d.message !== \"!\");\n}\n\nfunction getMessageText(d: ts.Diagnostic): string {\n\tif (typeof d.messageText === \"string\") {\n\t\treturn d.messageText;\n\t} else {\n\t\tlet messages: string[] = [];\n\t\tgetMessages(d.messageText, messages);\n\t\treturn messages.map((m, i) => \" \".repeat(i * 2) + m).join(\"\\n\");\n\t}\n}\n\nfunction getMessages(chain: DiagnosticMessageChain, messages: string[]) {\n\tmessages.push(chain.messageText);\n\tif (chain.next !== undefined) {\n\t\tfor (let next of chain.next) {\n\t\t\tgetMessages(next, messages);\n\t\t}\n\t}\n}\n","import tsvfs from \"@typescript/vfs\";\nimport chalk from \"chalk\";\nimport fg from \"fast-glob\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { loadDocument } from \"./loadDocument\";\nimport loadVts from \"./loadVts\";\nimport processErrors from \"./processErrors\";\nimport type Diagnostic from \"./types/Diagnostic\";\n\nexport default function check(folder: string): Diagnostic[] {\n\tif (!fs.existsSync(folder)) {\n\t\tfolder = path.join(process.cwd(), folder);\n\t}\n\tconsole.log(\"Checking files in\", folder);\n\n\tconst vts = loadVts(folder);\n\tif (vts === undefined) {\n\t\treturn [];\n\t}\n\n\t// The compiler module the project is checked with (already loaded by\n\t// loadVts)\n\tconst ts = vts.ts;\n\n\t// Convert tsconfig includes and excludes to globs\n\tlet pathToGlob = (f: string) => {\n\t\tf = fg.convertPathToPattern(f).replaceAll(\"\\\\*\", \"*\");\n\t\tif (!f.includes(\"*\")) {\n\t\t\tif (!f.endsWith(\"/\")) f += \"/\";\n\t\t\tf += \"**\";\n\t\t}\n\t\treturn f;\n\t};\n\tlet include = vts.config.include.map(pathToGlob);\n\tif (include.length === 0) {\n\t\tinclude.push(\"**\");\n\t}\n\tconst ignore = vts.config.exclude.map(pathToGlob);\n\n\t// Get the included files with supported extensions\n\tlet files: string[] = fg\n\t\t.globSync(include, { cwd: folder, ignore })\n\t\t.filter((f) => f.endsWith(\".js\") || f.endsWith(\".ts\") || f.endsWith(\".torp\"));\n\tconsole.log(`Found ${chalk.green(files.length)} file${files.length === 1 ? \"\" : \"s\"} to check`);\n\n\tlet errors: Diagnostic[] = [];\n\n\t// Transform files and gather transform errors\n\tfor (let file of files) {\n\t\tfile = path.join(folder, file);\n\t\tconst loaded = loadDocument(file);\n\t\tif (!loaded.ok) {\n\t\t\terrors.push(...loaded.errors);\n\t\t}\n\t}\n\n\t// Build the typescript program with all compiling files\n\tconst host = tsvfs.createVirtualCompilerHost(vts.env.sys, vts.config.options, ts);\n\tconst program = ts.createProgram({\n\t\trootNames: [...vts.virtualFiles.keys()],\n\t\toptions: vts.config.options,\n\t\thost: host.compilerHost,\n\t});\n\n\t// Get typescript to check the compiled files\n\tconst compileErrors = program\n\t\t.getSemanticDiagnostics()\n\t\t.concat(program.getDeclarationDiagnostics())\n\t\t.concat(program.getConfigFileParsingDiagnostics())\n\t\t.concat(program.getGlobalDiagnostics())\n\t\t.concat(program.getOptionsDiagnostics())\n\t\t.concat(program.getSyntacticDiagnostics());\n\terrors.push(...processErrors(vts, compileErrors));\n\n\treturn errors;\n}\n","import { loadDocument } from \"./loadDocument\";\nimport processErrors from \"./processErrors\";\nimport type Diagnostic from \"./types/Diagnostic\";\n\nexport default function validateScript(filename: string): Diagnostic[] {\n\ttry {\n\t\tconst transformed = loadDocument(filename);\n\t\tif (!transformed.ok) {\n\t\t\t// If there were parse or build errors, return them immediately\n\t\t\t// TODO: Do we want to clear the virtual file??\n\t\t\tif (!transformed.ok) {\n\t\t\t\treturn transformed.errors;\n\t\t\t}\n\t\t}\n\n\t\tconst { key, vts } = transformed;\n\n\t\t// HACK: Is this ok to do every check? We're doing it because otherwise\n\t\t// changes to linked files (e.g. adding or removing a field in an interface)\n\t\t// don't get picked up. But doing it here also means that it only happens\n\t\t// when the file is edited...\n\t\tvts.lang.cleanupSemanticCache();\n\n\t\tconst diagnostics = processErrors(vts, [\n\t\t\t...vts.lang.getSyntacticDiagnostics(key),\n\t\t\t...vts.lang.getSemanticDiagnostics(key),\n\t\t]);\n\n\t\treturn diagnostics;\n\t} catch (ex) {\n\t\tconsole.log(\"VALIDATE ERROR:\", ex);\n\t\treturn [];\n\t}\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type Diagnostic from \"./types/Diagnostic\";\nimport validateScript from \"./validateScript\";\n\nexport default function check(file: string): Diagnostic[] {\n\tif (!fs.existsSync(file)) {\n\t\tfile = path.join(process.cwd(), file);\n\t}\n\tconsole.log(\"Checking file\", file);\n\n\treturn validateScript(file);\n}\n","import chalk from \"chalk\";\nimport path from \"node:path\";\nimport type Diagnostic from \"./types/Diagnostic\";\n\nexport default function printErrors(folder: string, errors: Diagnostic[]): void {\n\terrors.sort((a, b) => a.path.localeCompare(b.path));\n\n\tfor (let error of errors) {\n\t\tconsole.log(\n\t\t\t`${chalk.green(path.relative(folder, error.path))}:${chalk.yellow(error.range.start.line)}:${chalk.yellow(error.range.start.character)} - ${chalk.red(\"error\")}${error.code ? chalk.gray(` TS${error.code}`) : \"\"}: ${error.message}`,\n\t\t);\n\t\tif (error.lineText) {\n\t\t\t// HACK: If I were less lazy I'd replace tabs with 4 spaces and adjust positions\n\t\t\terror.lineText = error.lineText.replaceAll(\"\\t\", \" \");\n\t\t\tconsole.log(`${chalk.black.bgWhite(error.range.start.line)} ${error.lineText}`);\n\t\t\tlet numberLength = error.range.start.line.toString().length;\n\t\t\tlet spacerLength = error.range.start.character;\n\t\t\tlet squiggleLength =\n\t\t\t\terror.range.start.line === error.range.end.line\n\t\t\t\t\t? error.range.end.character - error.range.start.character\n\t\t\t\t\t: error.lineText.length - error.range.start.character;\n\t\t\tconsole.log(\n\t\t\t\t`${chalk.black.bgWhite(\" \".repeat(numberLength))} ${\" \".repeat(spacerLength)}${chalk.red(\"~\").repeat(squiggleLength)}`,\n\t\t\t);\n\t\t}\n\t\tconsole.log();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;AAYA,SAAS,aAAa,IAA+B;CACpD,MAAM,MAAM;CACZ,OACC,CAAC,CAAC,OACF,OAAO,IAAI,YAAY,YACvB,OAAO,IAAI,kBAAkB,cAC7B,OAAO,IAAI,0BAA0B,cACrC,CAAC,CAAC,IAAI,OACN,OAAO,IAAI,IAAI,yBAAyB,cACxC,CAAC,CAAC,IAAI,gBACN,CAAC,CAAC,IAAI,cACN,CAAC,CAAC,IAAI;AAER;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I,eAAe,MAAM,MAAM,MAAM;GACrC,IAAI,iBACH,MAAM,MAAM,MAAM,SAAS,MAAM,MAAM,IAAI,OACxC,MAAM,MAAM,IAAI,YAAY,MAAM,MAAM,MAAM,YAC9C,MAAM,SAAS,SAAS,MAAM,MAAM,MAAM;GAC9C,QAAQ,IACP,GAAG,MAAM,MAAM,QAAQ,IAAI,OAAO,YAAY,CAAC,EAAE,GAAG,IAAI,OAAO,YAAY,IAAI,MAAM,IAAI,GAAG,CAAC,CAAC,OAAO,cAAc,GACpH;EACD;EACA,QAAQ,IAAI;CACb;AACD"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@torpor/check",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.18",
|
|
4
4
|
"description": "Checks Torpor files for errors",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
7
7
|
".": {
|
|
8
8
|
"types": "./dist/index.d.mts",
|
|
9
|
-
"import": "./dist/index.mjs"
|
|
9
|
+
"import": "./dist/index.mjs",
|
|
10
|
+
"default": "./dist/index.mjs"
|
|
10
11
|
}
|
|
11
12
|
},
|
|
12
13
|
"files": [
|
|
@@ -22,15 +23,15 @@
|
|
|
22
23
|
"author": "",
|
|
23
24
|
"license": "ISC",
|
|
24
25
|
"dependencies": {
|
|
25
|
-
"@torpor/view": "^1.3.
|
|
26
|
+
"@torpor/view": "^1.3.3",
|
|
26
27
|
"@typescript/vfs": "^1.6.5",
|
|
27
28
|
"chalk": "^6.0.1",
|
|
28
|
-
"fast-glob": "^3.3.3"
|
|
29
|
+
"fast-glob": "^3.3.3",
|
|
30
|
+
"typescript": "6.0.3"
|
|
29
31
|
},
|
|
30
32
|
"devDependencies": {
|
|
31
33
|
"@typescript/native-preview": "7.0.0-dev.20260707.2",
|
|
32
34
|
"tsx": "^4.23.15",
|
|
33
|
-
"typescript": "6.0.3",
|
|
34
35
|
"vite": "npm:@voidzero-dev/vite-plus-core@1.2.0",
|
|
35
36
|
"vite-plus": "1.2.0"
|
|
36
37
|
},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"checkFile-BvvjrnaS.mjs","names":["path","check"],"sources":["../src/loadVts.ts","../src/pathReplace.ts","../src/transformDocument.ts","../src/loadDocument.ts","../src/processErrors.ts","../src/check.ts","../src/validateScript.ts","../src/checkFile.ts"],"sourcesContent":["import tsvfs from \"@typescript/vfs\";\nimport fs from \"node:fs\";\nimport path from \"path\";\nimport ts, { type LanguageService } from \"typescript\";\nimport type SourceMap from \"./types/SourceMap\";\nimport type VirtualTypeScript from \"./types/VirtualTypeScript\";\n\nlet vts: VirtualTypeScript = {\n\t// @ts-ignore This will definitely be set\n\tenv: undefined,\n\t// @ts-ignore This will definitely be set\n\tlang: undefined,\n\tprojectRoot: \"\",\n\tconfigPath: undefined,\n\t// This is just the default config, it should be overwritten by the one from\n\t// the user's tsconfig.json\n\tconfig: {\n\t\toptions: {\n\t\t\ttarget: ts.ScriptTarget.ES2022,\n\t\t\tmodule: ts.ModuleKind.ESNext,\n\t\t\tmoduleResolution: ts.ModuleResolutionKind.Bundler,\n\t\t\tesModuleInterop: true,\n\t\t},\n\t\tinclude: [],\n\t\texclude: [],\n\t},\n\tvirtualFiles: new Map<string, string>(),\n\tvirtualFileMaps: new Map<string, { sourceFile: string; map: SourceMap[] }>(),\n};\n\nexport default function loadVts(vtsPath: string): VirtualTypeScript | undefined {\n\tif (vts.env === undefined) {\n\t\t// If using imports where the types don't directly match up to\n\t\t// their FS representation (like the imports for node) then use\n\t\t// triple-slash directives to make sure globals are set up\n\t\t// first.\n\t\t//const content = `\n\t\t//\t/// <reference types=\"node\" />\n\t\t//\timport * as path from 'path';\n\t\t//\tpath.`.replaceAll(/\\s+/, \" \").trim();\n\n\t\t// By providing a project root, the system knows how to resolve\n\t\t// node_modules correctly\n\t\tvts.projectRoot = path.join(vtsPath, \".\");\n\t\twhile (vts.projectRoot && !fs.existsSync(path.join(vts.projectRoot, \"node_modules\"))) {\n\t\t\tvts.projectRoot = path.join(vts.projectRoot, \"..\");\n\t\t}\n\t\tif (!vts.projectRoot) {\n\t\t\tconsole.log(\"No project root found\");\n\t\t\treturn;\n\t\t}\n\n\t\t// Maybe load tsconfig from a file\n\t\t// TODO: reload if the file is changed\n\t\ttry {\n\t\t\tlet fileConfig = loadTypeScriptConfig();\n\t\t\tif (fileConfig?.options) {\n\t\t\t\tvts.config = {\n\t\t\t\t\toptions: fileConfig.options,\n\t\t\t\t\tinclude: fileConfig.raw.include ?? [],\n\t\t\t\t\texclude: fileConfig.raw.exclude ?? [],\n\t\t\t\t};\n\t\t\t}\n\t\t} catch {\n\t\t\tconsole.log(\"No tsconfig.json file found, using default\");\n\t\t}\n\n\t\tconst system = tsvfs.createFSBackedSystem(vts.virtualFiles, vts.projectRoot, ts);\n\t\tvts.env = tsvfs.createVirtualTypeScriptEnvironment(system, [], ts, vts.config.options);\n\t\tvts.lang = vts.env.languageService as LanguageService;\n\n\t\tconsole.log(\"Torpor type checking loaded\");\n\t}\n\treturn vts;\n}\n\nfunction loadTypeScriptConfig(): Record<string, any> | undefined {\n\tconst configFileName = ts.findConfigFile(vts.projectRoot, ts.sys.fileExists);\n\tif (configFileName) {\n\t\tvts.configPath = path.dirname(configFileName);\n\t\tconst configFile = ts.readConfigFile(configFileName, ts.sys.readFile);\n\t\treturn ts.parseJsonConfigFileContent(configFile.config, ts.sys, vts.projectRoot);\n\t}\n}\n","// TODO: Implement more logic from https://www.typescriptlang.org/docs/handbook/modules/reference.html#paths\nexport default function pathReplace(pattern: string, replacement: string, value: string): string {\n\tpattern = \"^\" + pattern.replaceAll(\"*\", \"(.+?)\");\n\treplacement = replacement.replaceAll(\"*\", \"$1\");\n\n\tconst regex1 = new RegExp(pattern);\n\treturn value.replace(regex1, replacement);\n}\n","import { build, parse } from \"@torpor/view/compile\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport pathReplace from \"./pathReplace\";\nimport type Diagnostic from \"./types/Diagnostic\";\nimport type SourceMap from \"./types/SourceMap\";\nimport type VirtualTypeScript from \"./types/VirtualTypeScript\";\n\ninterface TransformResult {\n\tok: boolean;\n\terrors: Diagnostic[];\n\tcontent: string;\n\tmap: SourceMap[];\n}\n\nexport default function transformDocument(\n\tvts: VirtualTypeScript,\n\tfilename: string,\n\tsource: string,\n\tdebug = false,\n): TransformResult {\n\ttry {\n\t\t// Build the main file as a component\n\t\tconst parsed = parse(source);\n\n\t\t// If not ok, don't validate\n\t\tif (!parsed.ok) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\terrors: parsed.errors.map((e) => {\n\t\t\t\t\tlet lineTextStart = e.startIndex;\n\t\t\t\t\twhile (lineTextStart >= 0) {\n\t\t\t\t\t\tif (source[lineTextStart] === \"\\n\") {\n\t\t\t\t\t\t\tlineTextStart++;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tlineTextStart--;\n\t\t\t\t\t}\n\t\t\t\t\tlet lineTextEnd: number | undefined = source.indexOf(\"\\n\", e.startIndex);\n\t\t\t\t\tif (lineTextEnd === -1) lineTextEnd = undefined;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tpath: filename,\n\t\t\t\t\t\tmessage: e.message,\n\t\t\t\t\t\trange: {\n\t\t\t\t\t\t\tstart: { line: e.startLine, character: e.startChar },\n\t\t\t\t\t\t\tend: { line: e.endLine, character: e.endChar },\n\t\t\t\t\t\t},\n\t\t\t\t\t\tlineText: source.substring(lineTextStart, lineTextEnd),\n\t\t\t\t\t} satisfies Diagnostic;\n\t\t\t\t}),\n\t\t\t\tcontent: \"\",\n\t\t\t\tmap: [],\n\t\t\t};\n\t\t}\n\n\t\tlet { code, map } = build(parsed.template!, { mapped: true });\n\n\t\tcode = importComponentFiles(vts, filename, code, map, debug);\n\n\t\t//console.log(code);\n\t\t//console.log(map);\n\n\t\treturn {\n\t\t\tok: true,\n\t\t\terrors: [],\n\t\t\tcontent: code,\n\t\t\tmap,\n\t\t};\n\t} catch (ex) {\n\t\tconst message = ex instanceof Error ? ex.stack : String(ex);\n\t\tconsole.log(\"Failed to compile\", filename);\n\t\tconsole.log(message);\n\t\treturn {\n\t\t\tok: false,\n\t\t\terrors: [],\n\t\t\tcontent: \"\",\n\t\t\tmap: [],\n\t\t};\n\t}\n}\n\nfunction importComponentFiles(\n\tvts: VirtualTypeScript,\n\tfilename: string,\n\tcontent: string,\n\tmap: SourceMap[],\n\t_debug = false,\n): string {\n\tif (!/^\\s*import\\s+(.+?)\\s+from\\s+(.+?);*\\s*$/ms.test(content)) {\n\t\treturn content;\n\t}\n\n\t// Build imported component files and add them to the virtual file map\n\t// TODO: Handle files from node_modules? Might get done automatically by typescript-vfs\n\n\t// HACK: We're assuming that all imports are at the top of the file, and\n\t// that there are not multiple imports on the one line\n\tconst first = map.shift()!;\n\tconst filepath = path.dirname(filename);\n\n\tlet moved = 0;\n\tlet newMaps: SourceMap[] = [];\n\n\tfor (let i = 0; i < first.script.length; i++) {\n\t\tif (first.script[i] === \"/\") {\n\t\t\t// Skip comments\n\t\t\tif (first.script[i + 1] === \"/\") {\n\t\t\t\ti = first.script.indexOf(\"\\n\", i);\n\t\t\t} else if (first.script[i + 1] === \"*\") {\n\t\t\t\ti = first.script.indexOf(\"*/\", i);\n\t\t\t}\n\t\t\tif (i === -1) {\n\t\t\t\treturn content;\n\t\t\t}\n\t\t} else if (first.script[i] === \"i\") {\n\t\t\tconst match = first.script.substring(i).match(/import\\s+(.+?)\\s+from\\s+(.+?);*\\s*$/ms);\n\t\t\tif (match === null) continue;\n\n\t\t\tconst oldImport = match[0];\n\t\t\t//const names = match[1];\n\t\t\tconst importedFile = match[2];\n\n\t\t\t// Strip quotes\n\t\t\tlet importFile = importedFile;\n\t\t\tif (\n\t\t\t\t(importFile.startsWith(\"'\") && importFile.endsWith(\"'\")) ||\n\t\t\t\t(importFile.startsWith('\"') && importFile.endsWith('\"'))\n\t\t\t) {\n\t\t\t\timportFile = importFile.substring(1, importFile.length - 1);\n\t\t\t}\n\n\t\t\t// Just map import files that aren't components\n\t\t\tif (!importFile.endsWith(\".torp\")) {\n\t\t\t\tnewMaps.push({\n\t\t\t\t\tscript: oldImport,\n\t\t\t\t\tsource: {\n\t\t\t\t\t\tstart: i,\n\t\t\t\t\t\tend: i + oldImport.length,\n\t\t\t\t\t},\n\t\t\t\t\tcompiled: {\n\t\t\t\t\t\tstart: first.compiled.start + i + moved,\n\t\t\t\t\t\tend: first.compiled.start + i + moved + oldImport.length,\n\t\t\t\t\t},\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// Get the absolute path of the import file\n\t\t\tlet typeFile = importFile.startsWith(\".\") ? path.join(filepath, importFile) : importFile;\n\n\t\t\t// Replace aliased paths from tsconfig.json\n\t\t\tif (vts.configPath && vts.config.options.paths) {\n\t\t\t\t// HACK: Get the longest match etc\n\t\t\t\tconst oldTypeFile = typeFile;\n\t\t\t\tfor (let [srcGlob, paths] of Object.entries(vts.config.options.paths)) {\n\t\t\t\t\tfor (let destGlob of paths) {\n\t\t\t\t\t\ttypeFile = pathReplace(srcGlob, destGlob, typeFile);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// The import may now be relative to the tsconfig file, so make it absolute\n\t\t\t\tif (typeFile !== oldTypeFile && typeFile.startsWith(\".\")) {\n\t\t\t\t\ttypeFile = path.join(vts.configPath, typeFile);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Create the virtual file for the component\n\t\t\tconst key = typeFile.replace(/\\.torp$/, \".ts\");\n\t\t\tif (!vts.virtualFiles.has(key) && fs.existsSync(typeFile)) {\n\t\t\t\t// Mark as in progress before transforming, so that circular\n\t\t\t\t// component imports don't recurse forever\n\t\t\t\tvts.virtualFiles.set(key, \"\");\n\t\t\t\tconst typeSource = fs.readFileSync(typeFile, \"utf8\");\n\t\t\t\tconst { content } = transformDocument(vts, typeFile, typeSource);\n\t\t\t\tvts.virtualFiles.set(key, content);\n\t\t\t\tvts.env.createFile(key, content);\n\t\t\t}\n\n\t\t\t// Replace the import file with the virtual file\n\t\t\tlet oldLength = content.length;\n\t\t\tlet newValue = typeFile.replace(\".torp\", \".ts\");\n\t\t\t// HACK: We could concat this if we could be bothered\n\t\t\tlet newImport = oldImport.replace(importFile, newValue);\n\t\t\tcontent = content.replace(oldImport, newImport);\n\n\t\t\t// Move subsequent ranges around\n\t\t\tlet diff = content.length - oldLength;\n\t\t\tfor (let mapped of map) {\n\t\t\t\tmapped.compiled.start += diff;\n\t\t\t\tmapped.compiled.end += diff;\n\t\t\t}\n\n\t\t\t// Add a range for the changed import\n\t\t\tnewMaps.push({\n\t\t\t\tscript: oldImport,\n\t\t\t\tsource: {\n\t\t\t\t\tstart: i,\n\t\t\t\t\tend: i + oldImport.length,\n\t\t\t\t},\n\t\t\t\tcompiled: {\n\t\t\t\t\tstart: first.compiled.start + i + moved,\n\t\t\t\t\tend: first.compiled.start + i + moved + newImport.length,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tmoved += diff;\n\t\t\ti += oldImport.length;\n\t\t}\n\t}\n\n\tmap.unshift(...newMaps);\n\n\treturn content;\n}\n","import fs from \"node:fs\";\nimport loadVts from \"./loadVts\";\nimport transformDocument from \"./transformDocument\";\nimport type Diagnostic from \"./types/Diagnostic\";\nimport type SourceMap from \"./types/SourceMap\";\nimport type VirtualTypeScript from \"./types/VirtualTypeScript\";\n\ntype LoadResult =\n\t| { ok: false; errors: Diagnostic[] }\n\t| {\n\t\t\tok: true;\n\t\t\tfilename: string;\n\t\t\tkey: string;\n\t\t\ttext: string;\n\t\t\tcontent: string;\n\t\t\tmap: SourceMap[];\n\t\t\tvts: VirtualTypeScript;\n\t };\n\nexport function loadDocument(filename: string): LoadResult {\n\tconst key = filename.replace(/\\.torp$/, \".ts\");\n\n\tconst vts = loadVts(filename);\n\tif (vts === undefined) {\n\t\treturn { ok: false, errors: [] };\n\t}\n\n\tconst text = fs.readFileSync(filename, \"utf-8\");\n\tif (filename.endsWith(\".torp\")) {\n\t\tconst transformed = transformDocument(vts, filename, text);\n\t\tif (!transformed.ok) {\n\t\t\treturn {\n\t\t\t\tok: false,\n\t\t\t\terrors: transformed.errors,\n\t\t\t};\n\t\t}\n\t\tconst { content, map } = transformed;\n\t\tupdateVirtualFile(vts, key, content, filename, map);\n\t\treturn { ok: true, filename, key, text, content, map, vts: vts };\n\t} else {\n\t\tupdateVirtualFile(vts, key, text, filename, []);\n\t\treturn { ok: true, filename, key, text, content: text, map: [], vts: vts };\n\t}\n}\n\nfunction updateVirtualFile(\n\tvts: VirtualTypeScript,\n\tkey: string,\n\tcontent: string,\n\tsourceFile: string,\n\tmap: SourceMap[],\n) {\n\tif (!vts.virtualFiles.has(key)) {\n\t\tvts.env.createFile(key, content);\n\t} else {\n\t\tvts.env.updateFile(key, content);\n\t}\n\tvts.virtualFiles.set(key, content);\n\tvts.virtualFileMaps.set(key, { sourceFile, map });\n}\n","import fs from \"node:fs\";\nimport ts, { type DiagnosticMessageChain } from \"typescript\";\nimport type Diagnostic from \"./types/Diagnostic\";\nimport type SourceMap from \"./types/SourceMap\";\nimport type VirtualTypeScript from \"./types/VirtualTypeScript\";\n\nexport default function processErrors(\n\tvts: VirtualTypeScript,\n\terrors: ts.Diagnostic[],\n): Diagnostic[] {\n\treturn errors\n\t\t.map((d: ts.Diagnostic) => {\n\t\t\tlet message = getMessageText(d);\n\n\t\t\tif (d.file === undefined) {\n\t\t\t\treturn {\n\t\t\t\t\tpath: \"\",\n\t\t\t\t\tmessage,\n\t\t\t\t\trange: {\n\t\t\t\t\t\tstart: { line: 0, character: 0 },\n\t\t\t\t\t\tend: { line: 0, character: 0 },\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tlet filename = d.file.fileName;\n\t\t\tlet map: SourceMap[] = [];\n\t\t\tif (vts.virtualFileMaps.has(filename)) {\n\t\t\t\tlet transformed = vts.virtualFileMaps.get(filename)!;\n\t\t\t\tfilename = transformed.sourceFile;\n\t\t\t\tmap = transformed.map;\n\t\t\t}\n\t\t\tconst source = fs.readFileSync(filename, \"utf-8\");\n\t\t\tlet lineText: string | undefined;\n\t\t\tif (!filename.endsWith(\".torp\")) {\n\t\t\t\tlet start = { line: 0, character: 0 };\n\t\t\t\tlet end = { line: 0, character: 0 };\n\t\t\t\tif (d.start !== undefined) {\n\t\t\t\t\t// @ts-ignore we know this exists\n\t\t\t\t\tlet lineMap: number[] = d.file.lineMap;\n\t\t\t\t\tif (lineMap === undefined) {\n\t\t\t\t\t\tlineMap = [0];\n\t\t\t\t\t\tfor (let i = 0; i < source.length; i++) {\n\t\t\t\t\t\t\tif (source[i] === \"\\n\") lineMap.push(i);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// TODO: These need to be indexes\n\t\t\t\t\tstart.line = (lineMap.findIndex((l: number) => l > d.start!) ?? 1) - 1;\n\t\t\t\t\tstart.character = d.start - lineMap[start.line] - 1;\n\t\t\t\t\tlet endx = d.start! + (d.length ?? 0);\n\t\t\t\t\tend.line = (lineMap.findIndex((l: number) => l >= endx) ?? 1) - 1;\n\t\t\t\t\tend.character = endx - lineMap[end.line] - 1;\n\t\t\t\t\tlet lineStart = lineMap[start.line] + 1;\n\t\t\t\t\tlet lineEnd = lineMap[start.line + 1];\n\t\t\t\t\tlineText = source.substring(lineStart, lineEnd);\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tpath: filename,\n\t\t\t\t\tmessage,\n\t\t\t\t\trange: { start, end },\n\t\t\t\t\tlineText,\n\t\t\t\t} satisfies Diagnostic;\n\t\t\t}\n\n\t\t\t// Find the mapping between source and compiled, if it exists. If it\n\t\t\t// doesn't exist, the error must be in non-user code. Not great, but\n\t\t\t// the user doesn't need to know about it\n\t\t\tlet start = d.start ?? 0;\n\t\t\tlet end = (d.start ?? 0) + (d.length ?? 0);\n\t\t\tlet mapped = map.find((m: any) => start >= m.compiled.start && end <= m.compiled.end);\n\n\t\t\t// HACK: We don't care about these? Maybe there's a better way to\n\t\t\t// ignore/fix them\n\t\t\tif (\n\t\t\t\tmessage.startsWith(\"This import uses a '.ts' extension to resolve\") ||\n\t\t\t\t/Cannot find module '(.+?)\\?raw'/.test(message)\n\t\t\t) {\n\t\t\t\tmapped = undefined;\n\t\t\t\t// This special message will be filtered out\n\t\t\t\tmessage = \"!\";\n\t\t\t}\n\n\t\t\t//if (!mapped && message !== \"!\") {\n\t\t\t//\t// Log it for diagnostics\n\t\t\t//\tconsole.log(`Error${!mapped ? \" (unmapped)\" : \"\"}:`, message);\n\t\t\t//\t// @ts-ignore we know this exists\n\t\t\t//\tconst lineMap: number[] = d.file?.lineMap;\n\t\t\t//\tif (lineMap) {\n\t\t\t//\t\tconst line = (lineMap.findIndex((l: number) => l > start) ?? 1) - 1;\n\t\t\t//\t\tconst char = start - lineMap[line];\n\t\t\t//\t\tconsole.log(`(${line + 1}, ${char + 1}):`, content.split(\"\\n\")[line]);\n\t\t\t//\t}\n\t\t\t//}\n\n\t\t\t// HACK: Couldn't map back to the source, so just display it at the\n\t\t\t// first character\n\t\t\tif (!mapped) {\n\t\t\t\treturn {\n\t\t\t\t\tpath: filename,\n\t\t\t\t\tmessage,\n\t\t\t\t\trange: {\n\t\t\t\t\t\tstart: { line: 0, character: 0 },\n\t\t\t\t\t\tend: { line: 0, character: 0 },\n\t\t\t\t\t},\n\t\t\t\t} satisfies Diagnostic;\n\t\t\t}\n\n\t\t\t// We have the mapping, so we know roughly where in the\n\t\t\t// source the error occurs, but now we need to narrow it\n\t\t\t// down to the exact location\n\t\t\tlet sourceStart = mapped.source.start + start - mapped.compiled.start;\n\t\t\tlet sourceEnd = mapped.source.start + end - mapped.compiled.start;\n\t\t\t// HACK: If the translated mapping is outside of the source mapping,\n\t\t\t// just highlight the source mapping. It won't be 100% accurate, but\n\t\t\t// better than showing it way off in the middle of nowhere. This\n\t\t\t// happens e.g. when the $props are bad (as `<Component>` maps to\n\t\t\t// something like `Component($parent, $anchor, $props)`\n\t\t\tif (sourceStart > mapped.source.end) {\n\t\t\t\tsourceStart = mapped.source.start;\n\t\t\t\tsourceEnd = mapped.source.end;\n\t\t\t}\n\t\t\t// Same thing for if the error extends too far\n\t\t\tif (sourceEnd > mapped.source.end) {\n\t\t\t\tsourceEnd = mapped.source.end;\n\t\t\t}\n\n\t\t\t// TODO: Store this, so we don't need to start from 0 every time\n\t\t\tlet lastLineStart = 0;\n\t\t\tlet startLine = 0;\n\t\t\tfor (let i = 0; i < sourceStart; i++) {\n\t\t\t\tif (source[i] === \"\\n\") {\n\t\t\t\t\tlastLineStart = i + 1;\n\t\t\t\t\tstartLine++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlet startChar = sourceStart - lastLineStart; /*- 1*/\n\n\t\t\tlet lastLineEnd: number | undefined = source.indexOf(\"\\n\", lastLineStart + 1);\n\t\t\tif (lastLineEnd === -1) lastLineEnd = undefined;\n\t\t\tlineText = source.substring(lastLineStart, lastLineEnd);\n\n\t\t\tlet endLine = startLine;\n\t\t\tfor (let i = sourceStart; i < sourceEnd; i++) {\n\t\t\t\tif (source[i] === \"\\n\") {\n\t\t\t\t\tlastLineStart = i;\n\t\t\t\t\tendLine++;\n\t\t\t\t}\n\t\t\t}\n\t\t\tlet endChar = sourceEnd - lastLineStart; // - 1;\n\n\t\t\treturn {\n\t\t\t\tpath: filename,\n\t\t\t\tmessage,\n\t\t\t\tcode: d.code,\n\t\t\t\trange: {\n\t\t\t\t\tstart: {\n\t\t\t\t\t\tline: startLine,\n\t\t\t\t\t\tcharacter: startChar,\n\t\t\t\t\t},\n\t\t\t\t\tend: {\n\t\t\t\t\t\tline: endLine,\n\t\t\t\t\t\tcharacter: endChar,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\tlineText,\n\t\t\t} satisfies Diagnostic;\n\t\t})\n\t\t.filter((d) => d.message !== \"!\");\n}\n\nfunction getMessageText(d: ts.Diagnostic): string {\n\tif (typeof d.messageText === \"string\") {\n\t\treturn d.messageText;\n\t} else {\n\t\tlet messages: string[] = [];\n\t\tgetMessages(d.messageText, messages);\n\t\treturn messages.map((m, i) => \" \".repeat(i * 2) + m).join(\"\\n\");\n\t}\n}\n\nfunction getMessages(chain: DiagnosticMessageChain, messages: string[]) {\n\tmessages.push(chain.messageText);\n\tif (chain.next !== undefined) {\n\t\tfor (let next of chain.next) {\n\t\t\tgetMessages(next, messages);\n\t\t}\n\t}\n}\n","import tsvfs from \"@typescript/vfs\";\nimport chalk from \"chalk\";\nimport fg from \"fast-glob\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport ts from \"typescript\";\nimport { loadDocument } from \"./loadDocument\";\nimport loadVts from \"./loadVts\";\nimport processErrors from \"./processErrors\";\nimport type Diagnostic from \"./types/Diagnostic\";\n\nexport default function check(folder: string): Diagnostic[] {\n\tif (!fs.existsSync(folder)) {\n\t\tfolder = path.join(process.cwd(), folder);\n\t}\n\tconsole.log(\"Checking files in\", folder);\n\n\tconst vts = loadVts(folder);\n\tif (vts === undefined) {\n\t\treturn [];\n\t}\n\n\t// Convert tsconfig includes and excludes to globs\n\tlet pathToGlob = (f: string) => {\n\t\tf = fg.convertPathToPattern(f).replaceAll(\"\\\\*\", \"*\");\n\t\tif (!f.includes(\"*\")) {\n\t\t\tif (!f.endsWith(\"/\")) f += \"/\";\n\t\t\tf += \"**\";\n\t\t}\n\t\treturn f;\n\t};\n\tlet include = vts.config.include.map(pathToGlob);\n\tif (include.length === 0) {\n\t\tinclude.push(\"**\");\n\t}\n\tconst ignore = vts.config.exclude.map(pathToGlob);\n\n\t// Get the included files with supported extensions\n\tlet files: string[] = fg\n\t\t.globSync(include, { cwd: folder, ignore })\n\t\t.filter((f) => f.endsWith(\".js\") || f.endsWith(\".ts\") || f.endsWith(\".torp\"));\n\tconsole.log(`Found ${chalk.green(files.length)} file${files.length === 1 ? \"\" : \"s\"} to check`);\n\n\tlet errors: Diagnostic[] = [];\n\n\t// Transform files and gather transform errors\n\tfor (let file of files) {\n\t\tfile = path.join(folder, file);\n\t\tconst loaded = loadDocument(file);\n\t\tif (!loaded.ok) {\n\t\t\terrors.push(...loaded.errors);\n\t\t}\n\t}\n\n\t// Build the typescript program with all compiling files\n\tconst host = tsvfs.createVirtualCompilerHost(vts.env.sys, vts.config.options, ts);\n\tconst program = ts.createProgram({\n\t\trootNames: [...vts.virtualFiles.keys()],\n\t\toptions: vts.config.options,\n\t\thost: host.compilerHost,\n\t});\n\n\t// Get typescript to check the compiled files\n\tconst compileErrors = program\n\t\t.getSemanticDiagnostics()\n\t\t.concat(program.getDeclarationDiagnostics())\n\t\t.concat(program.getConfigFileParsingDiagnostics())\n\t\t.concat(program.getGlobalDiagnostics())\n\t\t.concat(program.getOptionsDiagnostics())\n\t\t.concat(program.getSyntacticDiagnostics());\n\terrors.push(...processErrors(vts, compileErrors));\n\n\treturn errors;\n}\n","import { loadDocument } from \"./loadDocument\";\nimport processErrors from \"./processErrors\";\nimport type Diagnostic from \"./types/Diagnostic\";\n\nexport default function validateScript(filename: string): Diagnostic[] {\n\ttry {\n\t\tconst transformed = loadDocument(filename);\n\t\tif (!transformed.ok) {\n\t\t\t// If there were parse or build errors, return them immediately\n\t\t\t// TODO: Do we want to clear the virtual file??\n\t\t\tif (!transformed.ok) {\n\t\t\t\treturn transformed.errors;\n\t\t\t}\n\t\t}\n\n\t\tconst { key, vts } = transformed;\n\n\t\t// HACK: Is this ok to do every check? We're doing it because otherwise\n\t\t// changes to linked files (e.g. adding or removing a field in an interface)\n\t\t// don't get picked up. But doing it here also means that it only happens\n\t\t// when the file is edited...\n\t\tvts.lang.cleanupSemanticCache();\n\n\t\tconst diagnostics = processErrors(vts, [\n\t\t\t...vts.lang.getSyntacticDiagnostics(key),\n\t\t\t...vts.lang.getSemanticDiagnostics(key),\n\t\t]);\n\n\t\treturn diagnostics;\n\t} catch (ex) {\n\t\tconsole.log(\"VALIDATE ERROR:\", ex);\n\t\treturn [];\n\t}\n}\n","import fs from \"node:fs\";\nimport path from \"node:path\";\nimport type Diagnostic from \"./types/Diagnostic\";\nimport validateScript from \"./validateScript\";\n\nexport default function check(file: string): Diagnostic[] {\n\tif (!fs.existsSync(file)) {\n\t\tfile = path.join(process.cwd(), file);\n\t}\n\tconsole.log(\"Checking file\", file);\n\n\treturn validateScript(file);\n}\n"],"mappings":";;;;;;;;;AAOA,IAAI,MAAyB;CAE5B,KAAK,KAAA;CAEL,MAAM,KAAA;CACN,aAAa;CACb,YAAY,KAAA;CAGZ,QAAQ;EACP,SAAS;GACR,QAAQ,GAAG,aAAa;GACxB,QAAQ,GAAG,WAAW;GACtB,kBAAkB,GAAG,qBAAqB;GAC1C,iBAAiB;EAClB;EACA,SAAS,CAAC;EACV,SAAS,CAAC;CACX;CACA,8BAAc,IAAI,IAAoB;CACtC,iCAAiB,IAAI,IAAsD;AAC5E;AAEA,SAAwB,QAAQ,SAAgD;CAC/E,IAAI,IAAI,QAAQ,KAAA,GAAW;EAY1B,IAAI,cAAcA,OAAK,KAAK,SAAS,GAAG;EACxC,OAAO,IAAI,eAAe,CAAC,GAAG,WAAWA,OAAK,KAAK,IAAI,aAAa,cAAc,CAAC,GAClF,IAAI,cAAcA,OAAK,KAAK,IAAI,aAAa,IAAI;EAElD,IAAI,CAAC,IAAI,aAAa;GACrB,QAAQ,IAAI,uBAAuB;GACnC;EACD;EAIA,IAAI;GACH,IAAI,aAAa,qBAAqB;GACtC,IAAI,YAAY,SACf,IAAI,SAAS;IACZ,SAAS,WAAW;IACpB,SAAS,WAAW,IAAI,WAAW,CAAC;IACpC,SAAS,WAAW,IAAI,WAAW,CAAC;GACrC;EAEF,QAAQ;GACP,QAAQ,IAAI,4CAA4C;EACzD;EAEA,MAAM,SAAS,MAAM,qBAAqB,IAAI,cAAc,IAAI,aAAa,EAAE;EAC/E,IAAI,MAAM,MAAM,mCAAmC,QAAQ,CAAC,GAAG,IAAI,IAAI,OAAO,OAAO;EACrF,IAAI,OAAO,IAAI,IAAI;EAEnB,QAAQ,IA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