@pronto-tools-and-more/type-checker 8.13.0 → 8.15.0
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pronto-tools-and-more/type-checker",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.15.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "src/typeCheckerMain.js",
|
|
6
6
|
"type": "module",
|
|
@@ -14,14 +14,14 @@
|
|
|
14
14
|
"license": "MIT",
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@lvce-editor/assert": "^1.3.0",
|
|
17
|
-
"@lvce-editor/ipc": "^11.0
|
|
18
|
-
"@lvce-editor/json-rpc": "^
|
|
17
|
+
"@lvce-editor/ipc": "^11.1.0",
|
|
18
|
+
"@lvce-editor/json-rpc": "^5.0.0",
|
|
19
19
|
"@lvce-editor/verror": "^1.4.0",
|
|
20
20
|
"@ts-morph/bootstrap": "^0.25.0",
|
|
21
21
|
"typescript": "^5.6.3"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@types/node": "^22.7
|
|
24
|
+
"@types/node": "^22.8.7",
|
|
25
25
|
"jest": "^29.7.0"
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -1,16 +1,106 @@
|
|
|
1
1
|
import { createProject, ts } from "@ts-morph/bootstrap";
|
|
2
|
+
import { readFileSync } from "fs";
|
|
3
|
+
import { createRequire } from "module";
|
|
4
|
+
import { basename, dirname, join } from "path";
|
|
2
5
|
import * as Assert from "../Assert/Assert.js";
|
|
3
6
|
import * as FormatError from "../FormatError/FormatError.js";
|
|
4
7
|
|
|
8
|
+
const getLibName = (fileName) => {
|
|
9
|
+
let libName = fileName;
|
|
10
|
+
if (libName.startsWith("lib.")) {
|
|
11
|
+
libName = libName.slice(4);
|
|
12
|
+
}
|
|
13
|
+
if (libName.endsWith(".d.ts")) {
|
|
14
|
+
libName = libName.slice(0, -5);
|
|
15
|
+
} else if (libName.endsWith(".ts")) {
|
|
16
|
+
libName = libName.slice(0, -3);
|
|
17
|
+
}
|
|
18
|
+
libName = libName.toLowerCase();
|
|
19
|
+
libName = `lib.${libName}.d.ts`;
|
|
20
|
+
return libName;
|
|
21
|
+
};
|
|
22
|
+
|
|
5
23
|
export const checkTypes = async (code, path = "index.js") => {
|
|
6
24
|
Assert.string(code);
|
|
25
|
+
const require = createRequire(import.meta.url);
|
|
26
|
+
const typescriptPath = require.resolve("typescript");
|
|
27
|
+
const libFolderPath = dirname(typescriptPath);
|
|
28
|
+
const codeFileDirname = dirname(path);
|
|
7
29
|
const project = await createProject({
|
|
8
|
-
|
|
30
|
+
fileSystem: {
|
|
31
|
+
async readFile(filePath) {
|
|
32
|
+
console.log("read", filePath);
|
|
33
|
+
return "";
|
|
34
|
+
},
|
|
35
|
+
async writeFile(filePath, fileText) {
|
|
36
|
+
return;
|
|
37
|
+
},
|
|
38
|
+
isCaseSensitive() {
|
|
39
|
+
return false;
|
|
40
|
+
},
|
|
41
|
+
async copy(srcPath, destPath) {},
|
|
42
|
+
copySync(srcPath, destPath) {},
|
|
43
|
+
async delete(path) {},
|
|
44
|
+
deleteSync(path) {},
|
|
45
|
+
async directoryExists(dirPath) {
|
|
46
|
+
return false;
|
|
47
|
+
},
|
|
48
|
+
directoryExistsSync(dirPath) {
|
|
49
|
+
if (dirPath.startsWith("/test/node_modules")) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
if (dirPath === codeFileDirname) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return false;
|
|
56
|
+
},
|
|
57
|
+
async fileExists(filePath) {
|
|
58
|
+
return false;
|
|
59
|
+
},
|
|
60
|
+
fileExistsSync(filePath) {
|
|
61
|
+
return false;
|
|
62
|
+
},
|
|
63
|
+
getCurrentDirectory() {
|
|
64
|
+
return "/test";
|
|
65
|
+
},
|
|
66
|
+
readDirSync(dirPath) {
|
|
67
|
+
return [];
|
|
68
|
+
},
|
|
69
|
+
readFileSync(filePath) {
|
|
70
|
+
if (filePath.startsWith(libFolderPath)) {
|
|
71
|
+
const name = basename(filePath);
|
|
72
|
+
const libName = getLibName(name);
|
|
73
|
+
const libPath = join(libFolderPath, libName);
|
|
74
|
+
const content = readFileSync(libPath, "utf8");
|
|
75
|
+
return content;
|
|
76
|
+
}
|
|
77
|
+
return "";
|
|
78
|
+
},
|
|
79
|
+
writeFileSync(filePath, fileText) {},
|
|
80
|
+
async glob(patterns) {
|
|
81
|
+
return [];
|
|
82
|
+
},
|
|
83
|
+
globSync(patterns) {
|
|
84
|
+
return [];
|
|
85
|
+
},
|
|
86
|
+
async mkdir(dirPath) {},
|
|
87
|
+
mkdirSync(dirPath) {},
|
|
88
|
+
async move(srcPath, destPath) {},
|
|
89
|
+
moveSync(srcPath, destPath) {},
|
|
90
|
+
realpathSync(path) {
|
|
91
|
+
return path;
|
|
92
|
+
},
|
|
93
|
+
},
|
|
9
94
|
compilerOptions: {
|
|
10
95
|
allowJs: true,
|
|
11
96
|
checkJs: true,
|
|
12
97
|
noEmit: true,
|
|
98
|
+
lib: ["lib.dom.d.ts", "lib.esnext.d.ts"],
|
|
99
|
+
traceResolution: true,
|
|
13
100
|
},
|
|
101
|
+
// skipLoadingLibFiles: true,
|
|
102
|
+
libFolderPath,
|
|
103
|
+
skipFileDependencyResolution: true,
|
|
14
104
|
});
|
|
15
105
|
project.createSourceFile(path, code);
|
|
16
106
|
const program = project.createProgram();
|