@pronto-tools-and-more/type-checker 7.5.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 ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@pronto-tools-and-more/type-checker",
3
+ "version": "7.5.0",
4
+ "description": "",
5
+ "main": "src/typeCheckerMain.js",
6
+ "type": "module",
7
+ "scripts": {
8
+ "test": "node --unhandled-rejections=warn --experimental-vm-modules ./node_modules/jest/bin/jest.js --detectOpenHandles --forceExit",
9
+ "test:watch": "node --unhandled-rejections=warn --experimental-vm-modules ./node_modules/jest/bin/jest.js --watch",
10
+ "type-check": "tsc"
11
+ },
12
+ "keywords": [],
13
+ "author": "",
14
+ "license": "MIT",
15
+ "dependencies": {
16
+ "@lvce-editor/assert": "^1.3.0",
17
+ "@lvce-editor/ipc": "^11.0.1",
18
+ "@lvce-editor/json-rpc": "^4.2.0",
19
+ "@lvce-editor/verror": "^1.4.0",
20
+ "@ts-morph/bootstrap": "^0.25.0",
21
+ "typescript": "^5.6.3"
22
+ },
23
+ "devDependencies": {
24
+ "@types/node": "^22.7.4",
25
+ "jest": "^29.7.0"
26
+ }
27
+ }
@@ -0,0 +1 @@
1
+ export * from "@lvce-editor/assert";
@@ -0,0 +1 @@
1
+ export { resolve } from "@lvce-editor/json-rpc";
@@ -0,0 +1,13 @@
1
+ import { createProject, ts } from "@ts-morph/bootstrap";
2
+ import * as Assert from "../Assert/Assert.js";
3
+ import * as FormatError from "../FormatError/FormatError.js";
4
+
5
+ export const checkTypes = async (code) => {
6
+ Assert.string(code);
7
+ const project = await createProject({ useInMemoryFileSystem: true });
8
+ project.createSourceFile("MyClass.ts", code);
9
+ const program = project.createProgram();
10
+ const diag = ts.getPreEmitDiagnostics(program); // check these
11
+ const formatted = diag.map(FormatError.formatError);
12
+ return formatted;
13
+ };
@@ -0,0 +1,9 @@
1
+ import * as CommandState from "../CommandState/CommandState.js";
2
+
3
+ export const execute = (command, ...args) => {
4
+ const fn = CommandState.getCommand(command);
5
+ if (!fn) {
6
+ throw new Error(`Command not found ${command}`);
7
+ }
8
+ return fn(...args);
9
+ };
@@ -0,0 +1 @@
1
+ export const commandMap = {};
@@ -0,0 +1,17 @@
1
+ export const state = {
2
+ commands: Object.create(null),
3
+ };
4
+
5
+ export const registerCommand = (key, fn) => {
6
+ state.commands[key] = fn;
7
+ };
8
+
9
+ export const registerCommands = (commandMap) => {
10
+ for (const [key, value] of Object.entries(commandMap)) {
11
+ registerCommand(key, value);
12
+ }
13
+ };
14
+
15
+ export const getCommand = (key) => {
16
+ return state.commands[key];
17
+ };
@@ -0,0 +1,9 @@
1
+ export const formatError = (error) => {
2
+ const { file, start, length, messageText } = error;
3
+ return {
4
+ message: messageText,
5
+ start,
6
+ length,
7
+ fileName: file?.fileName || "",
8
+ };
9
+ };
@@ -0,0 +1,10 @@
1
+ import * as HandleMessage from "../HandleMessage/HandleMessage.js";
2
+
3
+ export const handleIpc = (ipc) => {
4
+ if ("addEventListener" in ipc) {
5
+ ipc.addEventListener("message", HandleMessage.handleMessage);
6
+ } else if ("on" in ipc) {
7
+ // deprecated
8
+ ipc.on("message", HandleMessage.handleMessage);
9
+ }
10
+ };
@@ -0,0 +1,27 @@
1
+ import * as Callback from "../Callback/Callback.js";
2
+ import * as Command from "../Command/Command.js";
3
+ import * as JsonRpc from "../JsonRpc/JsonRpc.js";
4
+
5
+ const prepare = (error) => {
6
+ return error;
7
+ };
8
+
9
+ const requiresSocket = (method) => {
10
+ return false;
11
+ };
12
+
13
+ const logError = (error, prettyError) => {
14
+ console.error(error);
15
+ };
16
+
17
+ export const handleMessage = (event) => {
18
+ return JsonRpc.handleJsonRpcMessage(
19
+ event.target,
20
+ event.data,
21
+ Command.execute,
22
+ Callback.resolve,
23
+ prepare,
24
+ logError,
25
+ requiresSocket,
26
+ );
27
+ };
@@ -0,0 +1,15 @@
1
+ import * as IpcChildModule from "../IpcChildModule/IpcChildModule.js";
2
+
3
+ export const listen = async ({ method, ...params }) => {
4
+ const module = await IpcChildModule.getModule(method);
5
+ // @ts-ignore
6
+ const rawIpc = await module.listen(params);
7
+ // @ts-ignore
8
+ if (module.signal) {
9
+ // @ts-ignore
10
+ module.signal(rawIpc);
11
+ }
12
+ // @ts-ignore
13
+ const ipc = module.wrap(rawIpc);
14
+ return ipc;
15
+ };
@@ -0,0 +1,25 @@
1
+ import {
2
+ IpcChildWithElectronMessagePort,
3
+ IpcChildWithElectronUtilityProcess,
4
+ IpcChildWithNodeForkedProcess,
5
+ IpcChildWithNodeWorker,
6
+ IpcChildWithWebSocket,
7
+ } from "@lvce-editor/ipc";
8
+ import * as IpcChildType from "../IpcChildType/IpcChildType.js";
9
+
10
+ export const getModule = (method) => {
11
+ switch (method) {
12
+ case IpcChildType.NodeForkedProcess:
13
+ return IpcChildWithNodeForkedProcess;
14
+ case IpcChildType.NodeWorker:
15
+ return IpcChildWithNodeWorker;
16
+ case IpcChildType.ElectronUtilityProcess:
17
+ return IpcChildWithElectronUtilityProcess;
18
+ case IpcChildType.ElectronMessagePort:
19
+ return IpcChildWithElectronMessagePort;
20
+ case IpcChildType.WebSocket:
21
+ return IpcChildWithWebSocket;
22
+ default:
23
+ throw new Error("unexpected ipc type");
24
+ }
25
+ };
@@ -0,0 +1,20 @@
1
+ export const NodeWorker = 1;
2
+ export const NodeForkedProcess = 2;
3
+ export const ElectronUtilityProcess = 3;
4
+ export const ElectronMessagePort = 4;
5
+ export const NodeMessagePort = 5;
6
+ export const WebSocket = 6;
7
+
8
+ export const Auto = () => {
9
+ const { argv } = process;
10
+ if (argv.includes("--ipc-type=node-worker")) {
11
+ return NodeWorker;
12
+ }
13
+ if (argv.includes("--ipc-type=node-forked-process")) {
14
+ return NodeForkedProcess;
15
+ }
16
+ if (argv.includes("--ipc-type=electron-utility-process")) {
17
+ return ElectronUtilityProcess;
18
+ }
19
+ throw new Error(`[shared-process] unknown ipc type`);
20
+ };
@@ -0,0 +1,9 @@
1
+ export const EmbedsProcess = 2;
2
+ export const EmbedsWorker = 77;
3
+ export const ExtensionHostHelperProcess = 3;
4
+ export const MainProcess = -5;
5
+ export const ProcessExplorer = 11;
6
+ export const SearchProcess = 13;
7
+ export const SharedProcess = 1;
8
+ export const TerminalProcess = 7;
9
+ export const Unknown = 0;
@@ -0,0 +1 @@
1
+ export * from "@lvce-editor/json-rpc";
@@ -0,0 +1,8 @@
1
+ import * as HandleIpc from "../HandleIpc/HandleIpc.js";
2
+ import * as IpcChild from "../IpcChild/IpcChild.js";
3
+ import * as IpcChildType from "../IpcChildType/IpcChildType.js";
4
+
5
+ export const listen = async () => {
6
+ const ipc = await IpcChild.listen({ method: IpcChildType.Auto() });
7
+ HandleIpc.handleIpc(ipc);
8
+ };
@@ -0,0 +1,8 @@
1
+ import * as CommandMap from "../CommandMap/CommandMap.js";
2
+ import * as CommandState from "../CommandState/CommandState.js";
3
+ import * as Listen from "../Listen/Listen.js";
4
+
5
+ export const main = async () => {
6
+ CommandState.registerCommands(CommandMap.commandMap);
7
+ await Listen.listen();
8
+ };
@@ -0,0 +1,3 @@
1
+ import * as Main from "./parts/Main/Main.js";
2
+
3
+ Main.main();