@justscale/typescript 0.1.1
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/LICENSE +21 -0
- package/README.md +128 -0
- package/dist/api.d.ts +144 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +380 -0
- package/dist/api.js.map +1 -0
- package/dist/compiler/analyzer.d.ts +247 -0
- package/dist/compiler/analyzer.d.ts.map +1 -0
- package/dist/compiler/analyzer.js +3201 -0
- package/dist/compiler/analyzer.js.map +1 -0
- package/dist/compiler/cli.d.ts +12 -0
- package/dist/compiler/cli.d.ts.map +1 -0
- package/dist/compiler/cli.js +209 -0
- package/dist/compiler/cli.js.map +1 -0
- package/dist/compiler/compile.d.ts +26 -0
- package/dist/compiler/compile.d.ts.map +1 -0
- package/dist/compiler/compile.js +121 -0
- package/dist/compiler/compile.js.map +1 -0
- package/dist/compiler/errors.d.ts +336 -0
- package/dist/compiler/errors.d.ts.map +1 -0
- package/dist/compiler/errors.js +466 -0
- package/dist/compiler/errors.js.map +1 -0
- package/dist/compiler/exports-prepass.d.ts +31 -0
- package/dist/compiler/exports-prepass.d.ts.map +1 -0
- package/dist/compiler/exports-prepass.js +249 -0
- package/dist/compiler/exports-prepass.js.map +1 -0
- package/dist/compiler/hmr-change-detector.d.ts +47 -0
- package/dist/compiler/hmr-change-detector.d.ts.map +1 -0
- package/dist/compiler/hmr-change-detector.js +395 -0
- package/dist/compiler/hmr-change-detector.js.map +1 -0
- package/dist/compiler/hmr-transformer.d.ts +54 -0
- package/dist/compiler/hmr-transformer.d.ts.map +1 -0
- package/dist/compiler/hmr-transformer.js +535 -0
- package/dist/compiler/hmr-transformer.js.map +1 -0
- package/dist/compiler/index.d.ts +19 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +16 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/primitive-detector.d.ts +70 -0
- package/dist/compiler/primitive-detector.d.ts.map +1 -0
- package/dist/compiler/primitive-detector.js +338 -0
- package/dist/compiler/primitive-detector.js.map +1 -0
- package/dist/compiler/ptsc.d.ts +40 -0
- package/dist/compiler/ptsc.d.ts.map +1 -0
- package/dist/compiler/ptsc.js +462 -0
- package/dist/compiler/ptsc.js.map +1 -0
- package/dist/compiler/rewriter.d.ts +96 -0
- package/dist/compiler/rewriter.d.ts.map +1 -0
- package/dist/compiler/rewriter.js +418 -0
- package/dist/compiler/rewriter.js.map +1 -0
- package/dist/compiler/step-hash.d.ts +43 -0
- package/dist/compiler/step-hash.d.ts.map +1 -0
- package/dist/compiler/step-hash.js +83 -0
- package/dist/compiler/step-hash.js.map +1 -0
- package/dist/compiler/switch-codegen.d.ts +84 -0
- package/dist/compiler/switch-codegen.d.ts.map +1 -0
- package/dist/compiler/switch-codegen.js +1540 -0
- package/dist/compiler/switch-codegen.js.map +1 -0
- package/dist/compiler/transformer.d.ts +29 -0
- package/dist/compiler/transformer.d.ts.map +1 -0
- package/dist/compiler/transformer.js +216 -0
- package/dist/compiler/transformer.js.map +1 -0
- package/dist/config/index.d.ts +122 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +215 -0
- package/dist/config/index.js.map +1 -0
- package/dist/di-errors/formatter.d.ts +126 -0
- package/dist/di-errors/formatter.d.ts.map +1 -0
- package/dist/di-errors/formatter.js +384 -0
- package/dist/di-errors/formatter.js.map +1 -0
- package/dist/di-errors/index.d.ts +5 -0
- package/dist/di-errors/index.d.ts.map +1 -0
- package/dist/di-errors/index.js +13 -0
- package/dist/di-errors/index.js.map +1 -0
- package/dist/editor.d.ts +11 -0
- package/dist/editor.d.ts.map +1 -0
- package/dist/editor.js +2 -0
- package/dist/editor.js.map +1 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/index.js.map +1 -0
- package/dist/language-service/index.d.ts +52 -0
- package/dist/language-service/index.d.ts.map +1 -0
- package/dist/language-service/index.js +366 -0
- package/dist/language-service/index.js.map +1 -0
- package/dist/language-service/process-quick-fixes.d.ts +20 -0
- package/dist/language-service/process-quick-fixes.d.ts.map +1 -0
- package/dist/language-service/process-quick-fixes.js +114 -0
- package/dist/language-service/process-quick-fixes.js.map +1 -0
- package/dist/language-service/quick-fix-discovery.d.ts +39 -0
- package/dist/language-service/quick-fix-discovery.d.ts.map +1 -0
- package/dist/language-service/quick-fix-discovery.js +124 -0
- package/dist/language-service/quick-fix-discovery.js.map +1 -0
- package/dist/loader/incremental.d.ts +50 -0
- package/dist/loader/incremental.d.ts.map +1 -0
- package/dist/loader/incremental.js +151 -0
- package/dist/loader/incremental.js.map +1 -0
- package/dist/loader/index.d.ts +25 -0
- package/dist/loader/index.d.ts.map +1 -0
- package/dist/loader/index.js +24 -0
- package/dist/loader/index.js.map +1 -0
- package/dist/loader/loader.d.ts +52 -0
- package/dist/loader/loader.d.ts.map +1 -0
- package/dist/loader/loader.js +248 -0
- package/dist/loader/loader.js.map +1 -0
- package/dist/loader/register.d.ts +14 -0
- package/dist/loader/register.d.ts.map +1 -0
- package/dist/loader/register.js +20 -0
- package/dist/loader/register.js.map +1 -0
- package/dist/plugins/index.d.ts +13 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +13 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/plugins/index.public.d.ts +13 -0
- package/dist/plugins/index.public.d.ts.map +1 -0
- package/dist/plugins/index.public.js +13 -0
- package/dist/plugins/index.public.js.map +1 -0
- package/dist/plugins/types.d.ts +83 -0
- package/dist/plugins/types.d.ts.map +1 -0
- package/dist/plugins/types.js +24 -0
- package/dist/plugins/types.js.map +1 -0
- package/dist/server/index.d.ts +33 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +42 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/tsserver.d.ts +28 -0
- package/dist/server/tsserver.d.ts.map +1 -0
- package/dist/server/tsserver.js +126 -0
- package/dist/server/tsserver.js.map +1 -0
- package/lib/lib.d.ts +20 -0
- package/lib/lib.decorators.d.ts +382 -0
- package/lib/lib.decorators.legacy.d.ts +20 -0
- package/lib/lib.dom.asynciterable.d.ts +18 -0
- package/lib/lib.dom.d.ts +45125 -0
- package/lib/lib.dom.iterable.d.ts +18 -0
- package/lib/lib.es2015.collection.d.ts +150 -0
- package/lib/lib.es2015.core.d.ts +595 -0
- package/lib/lib.es2015.d.ts +26 -0
- package/lib/lib.es2015.generator.d.ts +75 -0
- package/lib/lib.es2015.iterable.d.ts +603 -0
- package/lib/lib.es2015.promise.d.ts +79 -0
- package/lib/lib.es2015.proxy.d.ts +126 -0
- package/lib/lib.es2015.reflect.d.ts +142 -0
- package/lib/lib.es2015.symbol.d.ts +44 -0
- package/lib/lib.es2015.symbol.wellknown.d.ts +324 -0
- package/lib/lib.es2016.array.include.d.ts +114 -0
- package/lib/lib.es2016.d.ts +19 -0
- package/lib/lib.es2016.full.d.ts +21 -0
- package/lib/lib.es2016.intl.d.ts +29 -0
- package/lib/lib.es2017.arraybuffer.d.ts +19 -0
- package/lib/lib.es2017.d.ts +24 -0
- package/lib/lib.es2017.date.d.ts +29 -0
- package/lib/lib.es2017.full.d.ts +21 -0
- package/lib/lib.es2017.intl.d.ts +42 -0
- package/lib/lib.es2017.object.d.ts +47 -0
- package/lib/lib.es2017.sharedmemory.d.ts +133 -0
- package/lib/lib.es2017.string.d.ts +43 -0
- package/lib/lib.es2017.typedarrays.d.ts +51 -0
- package/lib/lib.es2018.asyncgenerator.d.ts +75 -0
- package/lib/lib.es2018.asynciterable.d.ts +51 -0
- package/lib/lib.es2018.d.ts +22 -0
- package/lib/lib.es2018.full.d.ts +22 -0
- package/lib/lib.es2018.intl.d.ts +81 -0
- package/lib/lib.es2018.promise.d.ts +28 -0
- package/lib/lib.es2018.regexp.d.ts +35 -0
- package/lib/lib.es2019.array.d.ts +77 -0
- package/lib/lib.es2019.d.ts +22 -0
- package/lib/lib.es2019.full.d.ts +22 -0
- package/lib/lib.es2019.intl.d.ts +21 -0
- package/lib/lib.es2019.object.d.ts +31 -0
- package/lib/lib.es2019.string.d.ts +35 -0
- package/lib/lib.es2019.symbol.d.ts +22 -0
- package/lib/lib.es2020.bigint.d.ts +763 -0
- package/lib/lib.es2020.d.ts +25 -0
- package/lib/lib.es2020.date.d.ts +40 -0
- package/lib/lib.es2020.full.d.ts +22 -0
- package/lib/lib.es2020.intl.d.ts +472 -0
- package/lib/lib.es2020.number.d.ts +26 -0
- package/lib/lib.es2020.promise.d.ts +45 -0
- package/lib/lib.es2020.sharedmemory.d.ts +97 -0
- package/lib/lib.es2020.string.d.ts +42 -0
- package/lib/lib.es2020.symbol.wellknown.d.ts +39 -0
- package/lib/lib.es2021.d.ts +21 -0
- package/lib/lib.es2021.full.d.ts +22 -0
- package/lib/lib.es2021.intl.d.ts +164 -0
- package/lib/lib.es2021.promise.d.ts +46 -0
- package/lib/lib.es2021.string.d.ts +31 -0
- package/lib/lib.es2021.weakref.d.ts +76 -0
- package/lib/lib.es2022.array.d.ts +119 -0
- package/lib/lib.es2022.d.ts +23 -0
- package/lib/lib.es2022.error.d.ts +73 -0
- package/lib/lib.es2022.full.d.ts +22 -0
- package/lib/lib.es2022.intl.d.ts +143 -0
- package/lib/lib.es2022.object.d.ts +24 -0
- package/lib/lib.es2022.regexp.d.ts +37 -0
- package/lib/lib.es2022.string.d.ts +23 -0
- package/lib/lib.es2023.array.d.ts +922 -0
- package/lib/lib.es2023.collection.d.ts +19 -0
- package/lib/lib.es2023.d.ts +20 -0
- package/lib/lib.es2023.full.d.ts +22 -0
- package/lib/lib.es2023.intl.d.ts +62 -0
- package/lib/lib.es2024.arraybuffer.d.ts +63 -0
- package/lib/lib.es2024.collection.d.ts +27 -0
- package/lib/lib.es2024.d.ts +24 -0
- package/lib/lib.es2024.full.d.ts +22 -0
- package/lib/lib.es2024.object.d.ts +27 -0
- package/lib/lib.es2024.promise.d.ts +33 -0
- package/lib/lib.es2024.regexp.d.ts +23 -0
- package/lib/lib.es2024.sharedmemory.d.ts +66 -0
- package/lib/lib.es2024.string.d.ts +27 -0
- package/lib/lib.es2025.collection.d.ts +94 -0
- package/lib/lib.es2025.d.ts +23 -0
- package/lib/lib.es2025.float16.d.ts +443 -0
- package/lib/lib.es2025.full.d.ts +22 -0
- package/lib/lib.es2025.intl.d.ts +200 -0
- package/lib/lib.es2025.iterator.d.ts +146 -0
- package/lib/lib.es2025.promise.d.ts +32 -0
- package/lib/lib.es2025.regexp.d.ts +30 -0
- package/lib/lib.es5.d.ts +4599 -0
- package/lib/lib.es6.d.ts +21 -0
- package/lib/lib.esnext.array.d.ts +33 -0
- package/lib/lib.esnext.collection.d.ts +47 -0
- package/lib/lib.esnext.d.ts +27 -0
- package/lib/lib.esnext.date.d.ts +21 -0
- package/lib/lib.esnext.decorators.d.ts +26 -0
- package/lib/lib.esnext.disposable.d.ts +191 -0
- package/lib/lib.esnext.error.d.ts +22 -0
- package/lib/lib.esnext.full.d.ts +22 -0
- package/lib/lib.esnext.intl.d.ts +107 -0
- package/lib/lib.esnext.sharedmemory.d.ts +23 -0
- package/lib/lib.esnext.temporal.d.ts +485 -0
- package/lib/lib.esnext.typedarrays.d.ts +90 -0
- package/lib/lib.scripthost.d.ts +320 -0
- package/lib/lib.webworker.asynciterable.d.ts +18 -0
- package/lib/lib.webworker.d.ts +15606 -0
- package/lib/lib.webworker.importscripts.d.ts +21 -0
- package/lib/lib.webworker.iterable.d.ts +18 -0
- package/lib/logger.js +144 -0
- package/lib/package.json +7 -0
- package/lib/tsserver.js +57 -0
- package/lib/tsserverlibrary.js +171 -0
- package/lib/typesMap.json +497 -0
- package/lib/typescript.js +373 -0
- package/package.json +115 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/*! *****************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
4
|
+
this file except in compliance with the License. You may obtain a copy of the
|
|
5
|
+
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
8
|
+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
9
|
+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
10
|
+
MERCHANTABILITY OR NON-INFRINGEMENT.
|
|
11
|
+
|
|
12
|
+
See the Apache Version 2.0 License for specific language governing permissions
|
|
13
|
+
and limitations under the License.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
/////////////////////////////
|
|
18
|
+
/// WorkerGlobalScope APIs
|
|
19
|
+
/////////////////////////////
|
|
20
|
+
// These are only available in a Web Worker
|
|
21
|
+
declare function importScripts(...urls: string[]): void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*! *****************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
4
|
+
this file except in compliance with the License. You may obtain a copy of the
|
|
5
|
+
License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
|
|
7
|
+
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
8
|
+
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
|
|
9
|
+
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
|
|
10
|
+
MERCHANTABILITY OR NON-INFRINGEMENT.
|
|
11
|
+
|
|
12
|
+
See the Apache Version 2.0 License for specific language governing permissions
|
|
13
|
+
and limitations under the License.
|
|
14
|
+
***************************************************************************** */
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
// This file's contents are now included in the main types file.
|
|
18
|
+
// The file has been left for backward compatibility.
|
package/lib/logger.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Logger for JustScale TypeScript
|
|
4
|
+
*
|
|
5
|
+
* Provides structured logging with timestamps for debugging
|
|
6
|
+
* TypeScript/proto integration issues.
|
|
7
|
+
*
|
|
8
|
+
* Integrates with TypeScript's TSS_LOG environment variable:
|
|
9
|
+
* TSS_LOG="-logToFile true -file /path/to/log.txt -level verbose"
|
|
10
|
+
*
|
|
11
|
+
* Or use our own:
|
|
12
|
+
* JUSTSCALE_LOG=1 JUSTSCALE_LOG_LEVEL=debug
|
|
13
|
+
*/
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.logger = void 0;
|
|
16
|
+
exports.createLogger = createLogger;
|
|
17
|
+
exports.logCall = logCall;
|
|
18
|
+
const node_fs_1 = require("node:fs");
|
|
19
|
+
const node_path_1 = require("node:path");
|
|
20
|
+
const node_os_1 = require("node:os");
|
|
21
|
+
const LOG_LEVELS = {
|
|
22
|
+
debug: 0,
|
|
23
|
+
info: 1,
|
|
24
|
+
warn: 2,
|
|
25
|
+
error: 3,
|
|
26
|
+
};
|
|
27
|
+
// Parse TSS_LOG environment variable (TypeScript's native logging)
|
|
28
|
+
function parseTssLog() {
|
|
29
|
+
const tssLog = process.env.TSS_LOG || '';
|
|
30
|
+
let file;
|
|
31
|
+
let level = 'info';
|
|
32
|
+
// Parse -file flag
|
|
33
|
+
const fileMatch = tssLog.match(/-file\s+(\S+)/);
|
|
34
|
+
if (fileMatch) {
|
|
35
|
+
file = fileMatch[1];
|
|
36
|
+
}
|
|
37
|
+
// Parse -level flag (verbose = debug, normal = info)
|
|
38
|
+
if (tssLog.includes('-level verbose')) {
|
|
39
|
+
level = 'debug';
|
|
40
|
+
}
|
|
41
|
+
return { file, level };
|
|
42
|
+
}
|
|
43
|
+
const tssConfig = parseTssLog();
|
|
44
|
+
// Log file location - prefer TSS_LOG, fallback to our default
|
|
45
|
+
const LOG_DIR = (0, node_path_1.join)((0, node_os_1.homedir)(), '.justscale', 'logs');
|
|
46
|
+
const LOG_FILE = tssConfig.file || (0, node_path_1.join)(LOG_DIR, 'typescript.log');
|
|
47
|
+
// Minimum log level from environment (our var takes precedence)
|
|
48
|
+
const MIN_LEVEL = process.env.JUSTSCALE_LOG_LEVEL || tssConfig.level;
|
|
49
|
+
// Off by default — opt in with JUSTSCALE_LOG=1 or any TSS_LOG flag.
|
|
50
|
+
// Header docstring describes the env-var contract; this gate enforces it.
|
|
51
|
+
// Without this, every TS compile in any user's IDE writes to ~/.justscale/logs.
|
|
52
|
+
const LOGGING_ENABLED = process.env.JUSTSCALE_LOG === '1' || Boolean(process.env.TSS_LOG);
|
|
53
|
+
let initialized = false;
|
|
54
|
+
function ensureLogDir() {
|
|
55
|
+
if (initialized)
|
|
56
|
+
return;
|
|
57
|
+
// Only create dir if using our default location (not TSS_LOG file)
|
|
58
|
+
if (!tssConfig.file) {
|
|
59
|
+
try {
|
|
60
|
+
(0, node_fs_1.mkdirSync)(LOG_DIR, { recursive: true });
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
// Ignore - logging is best-effort
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
initialized = true;
|
|
67
|
+
}
|
|
68
|
+
function formatTimestamp() {
|
|
69
|
+
const now = new Date();
|
|
70
|
+
return now.toISOString();
|
|
71
|
+
}
|
|
72
|
+
function formatData(data) {
|
|
73
|
+
if (data === undefined)
|
|
74
|
+
return '';
|
|
75
|
+
// Handle objects with stack traces specially
|
|
76
|
+
if (typeof data === 'object' && data !== null) {
|
|
77
|
+
const obj = data;
|
|
78
|
+
const parts = [];
|
|
79
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
80
|
+
if (key === 'stack' && typeof value === 'string') {
|
|
81
|
+
// Format stack traces with actual newlines and indentation
|
|
82
|
+
parts.push(`${key}:\n\t${value}`);
|
|
83
|
+
}
|
|
84
|
+
else if (typeof value === 'string') {
|
|
85
|
+
parts.push(`${key}=${value}`);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
parts.push(`${key}=${JSON.stringify(value)}`);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return ' ' + parts.join(' ');
|
|
92
|
+
}
|
|
93
|
+
return ` ${JSON.stringify(data)}`;
|
|
94
|
+
}
|
|
95
|
+
function formatMessage(level, component, message, data) {
|
|
96
|
+
const timestamp = formatTimestamp();
|
|
97
|
+
const dataStr = formatData(data);
|
|
98
|
+
return `[${timestamp}] [${level.toUpperCase().padEnd(5)}] [${component}] ${message}${dataStr}\n`;
|
|
99
|
+
}
|
|
100
|
+
function createLogger(component) {
|
|
101
|
+
const log = (level, message, data) => {
|
|
102
|
+
if (!LOGGING_ENABLED)
|
|
103
|
+
return;
|
|
104
|
+
if (LOG_LEVELS[level] < LOG_LEVELS[MIN_LEVEL])
|
|
105
|
+
return;
|
|
106
|
+
ensureLogDir();
|
|
107
|
+
const formatted = formatMessage(level, component, message, data);
|
|
108
|
+
// Write to file
|
|
109
|
+
try {
|
|
110
|
+
(0, node_fs_1.appendFileSync)(LOG_FILE, formatted);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
// Ignore write errors - logging is best-effort
|
|
114
|
+
}
|
|
115
|
+
// Also write to stderr for errors
|
|
116
|
+
if (level === 'error') {
|
|
117
|
+
process.stderr.write(`[justscale] ${formatted}`);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
return {
|
|
121
|
+
debug: (message, data) => log('debug', message, data),
|
|
122
|
+
info: (message, data) => log('info', message, data),
|
|
123
|
+
warn: (message, data) => log('warn', message, data),
|
|
124
|
+
error: (message, data) => log('error', message, data),
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
// Main logger for the typescript.js module
|
|
128
|
+
exports.logger = createLogger('typescript');
|
|
129
|
+
// Helper to log function calls with timing
|
|
130
|
+
function logCall(log, fnName, fn, args) {
|
|
131
|
+
const start = performance.now();
|
|
132
|
+
log.debug(`${fnName} called`, args);
|
|
133
|
+
try {
|
|
134
|
+
const result = fn();
|
|
135
|
+
const duration = (performance.now() - start).toFixed(2);
|
|
136
|
+
log.debug(`${fnName} completed in ${duration}ms`);
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
139
|
+
catch (err) {
|
|
140
|
+
const duration = (performance.now() - start).toFixed(2);
|
|
141
|
+
log.error(`${fnName} failed after ${duration}ms`, { error: String(err) });
|
|
142
|
+
throw err;
|
|
143
|
+
}
|
|
144
|
+
}
|
package/lib/package.json
ADDED
package/lib/tsserver.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* JustScale TypeScript Server
|
|
5
|
+
*
|
|
6
|
+
* Drop-in replacement for tsserver that uses our patched TypeScript.
|
|
7
|
+
* This ensures proto support works in any IDE that loads this server.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
const logger_1 = require("./logger");
|
|
11
|
+
const node_path_1 = require("node:path");
|
|
12
|
+
const log = (0, logger_1.createLogger)('tsserver');
|
|
13
|
+
log.info('JustScale TSServer starting...');
|
|
14
|
+
log.info('Process args', { argv: process.argv });
|
|
15
|
+
// Import our patched TypeScript to ensure patches are applied
|
|
16
|
+
// before the real tsserver loads
|
|
17
|
+
log.info('Loading patched TypeScript...');
|
|
18
|
+
require('./typescript');
|
|
19
|
+
log.info('Patched TypeScript loaded');
|
|
20
|
+
function findTsServer() {
|
|
21
|
+
const __dirname = (0, node_path_1.dirname)(__filename);
|
|
22
|
+
const possiblePaths = [
|
|
23
|
+
// From lib/ directory, go up to find node_modules
|
|
24
|
+
(0, node_path_1.resolve)(__dirname, '../node_modules/typescript/lib/tsserver.js'),
|
|
25
|
+
(0, node_path_1.resolve)(__dirname, '../../node_modules/typescript/lib/tsserver.js'),
|
|
26
|
+
(0, node_path_1.resolve)(__dirname, '../../../node_modules/typescript/lib/tsserver.js'),
|
|
27
|
+
(0, node_path_1.resolve)(__dirname, '../../../../node_modules/typescript/lib/tsserver.js'),
|
|
28
|
+
(0, node_path_1.resolve)(__dirname, '../../../../../node_modules/typescript/lib/tsserver.js'),
|
|
29
|
+
];
|
|
30
|
+
for (const p of possiblePaths) {
|
|
31
|
+
try {
|
|
32
|
+
require.resolve(p);
|
|
33
|
+
log.info('Found tsserver', { path: p });
|
|
34
|
+
return p;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
log.debug('TSServer not at', { path: p });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
// Last resort: try to resolve from node_modules
|
|
41
|
+
try {
|
|
42
|
+
const resolved = require.resolve('typescript/lib/tsserver.js');
|
|
43
|
+
log.info('Found tsserver via require.resolve', { path: resolved });
|
|
44
|
+
return resolved;
|
|
45
|
+
}
|
|
46
|
+
catch (err) {
|
|
47
|
+
log.error('Could not find tsserver', { error: String(err) });
|
|
48
|
+
const error = new Error('Could not find TypeScript tsserver. Make sure typescript is installed.');
|
|
49
|
+
error.cause = err;
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// Run tsserver
|
|
54
|
+
const tsserverPath = findTsServer();
|
|
55
|
+
log.info('Starting real tsserver', { path: tsserverPath });
|
|
56
|
+
// The real tsserver.js will start the server when required
|
|
57
|
+
require(tsserverPath);
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* JustScale TypeScript Server Library
|
|
4
|
+
*
|
|
5
|
+
* This module re-exports our patched TypeScript for IDE integration.
|
|
6
|
+
* JetBrains loads this when using our lib/ as the TypeScript SDK.
|
|
7
|
+
*/
|
|
8
|
+
const logger_1 = require("./logger");
|
|
9
|
+
let filterUsingExportsDiagnostics = null;
|
|
10
|
+
try {
|
|
11
|
+
const errors = require('../dist/compiler/errors.js');
|
|
12
|
+
filterUsingExportsDiagnostics = errors.filterUsingExportsDiagnostics;
|
|
13
|
+
}
|
|
14
|
+
catch { /* errors.js not available in all environments */ }
|
|
15
|
+
const log = (0, logger_1.createLogger)('tsserverlibrary');
|
|
16
|
+
log.info('JustScale TSServerLibrary loading...');
|
|
17
|
+
// Re-export our patched TypeScript
|
|
18
|
+
// This ensures JetBrains gets the proto-aware version
|
|
19
|
+
const ts = require('./typescript');
|
|
20
|
+
// Load the real tsserverlibrary to get ts.server
|
|
21
|
+
const realTsServerLib = require('typescript/lib/tsserverlibrary');
|
|
22
|
+
log.info('JustScale TSServerLibrary ready', { version: ts.version });
|
|
23
|
+
// Import process analyzer dynamically
|
|
24
|
+
let analyzeHandler = null;
|
|
25
|
+
let formatErrorCode = null;
|
|
26
|
+
try {
|
|
27
|
+
const analyzer = require('@justscale/typescript/api');
|
|
28
|
+
analyzeHandler = analyzer.analyzeHandler;
|
|
29
|
+
formatErrorCode = analyzer.formatErrorCode;
|
|
30
|
+
log.info('Process analyzer loaded');
|
|
31
|
+
}
|
|
32
|
+
catch (err) {
|
|
33
|
+
log.info('Process analyzer not available', { error: String(err) });
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Check if a source file is a process file
|
|
37
|
+
*/
|
|
38
|
+
function isProcessFile(sourceFile) {
|
|
39
|
+
if (sourceFile.fileName.includes('.process.')) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
for (const statement of sourceFile.statements) {
|
|
43
|
+
if (ts.isImportDeclaration(statement)) {
|
|
44
|
+
const moduleSpecifier = statement.moduleSpecifier;
|
|
45
|
+
if (ts.isStringLiteral(moduleSpecifier)) {
|
|
46
|
+
if (moduleSpecifier.text === '@justscale/core/process') {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Get process-specific diagnostics for a source file.
|
|
56
|
+
*/
|
|
57
|
+
function getProcessDiagnostics(sourceFile, program) {
|
|
58
|
+
if (!analyzeHandler) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
const diagnostics = [];
|
|
62
|
+
const typeChecker = program.getTypeChecker();
|
|
63
|
+
const visit = (node) => {
|
|
64
|
+
if (ts.isCallExpression(node)) {
|
|
65
|
+
const expr = node.expression;
|
|
66
|
+
if (ts.isIdentifier(expr) && expr.text === 'createProcess') {
|
|
67
|
+
const configArg = node.arguments[0];
|
|
68
|
+
if (configArg && ts.isObjectLiteralExpression(configArg)) {
|
|
69
|
+
// Find handler
|
|
70
|
+
for (const prop of configArg.properties) {
|
|
71
|
+
if (ts.isMethodDeclaration(prop)) {
|
|
72
|
+
if (ts.isIdentifier(prop.name) && prop.name.text === 'handler') {
|
|
73
|
+
const analysis = analyzeHandler(prop, typeChecker);
|
|
74
|
+
diagnostics.push(...analysis.diagnostics.map(d => ({
|
|
75
|
+
...d,
|
|
76
|
+
messageText: formatDiagnosticMessage(d),
|
|
77
|
+
})));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
else if (ts.isPropertyAssignment(prop)) {
|
|
81
|
+
if (ts.isIdentifier(prop.name) && prop.name.text === 'handler') {
|
|
82
|
+
if (ts.isFunctionExpression(prop.initializer) || ts.isArrowFunction(prop.initializer)) {
|
|
83
|
+
const analysis = analyzeHandler(prop.initializer, typeChecker);
|
|
84
|
+
diagnostics.push(...analysis.diagnostics.map(d => ({
|
|
85
|
+
...d,
|
|
86
|
+
messageText: formatDiagnosticMessage(d),
|
|
87
|
+
})));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
ts.forEachChild(node, visit);
|
|
96
|
+
};
|
|
97
|
+
visit(sourceFile);
|
|
98
|
+
return diagnostics;
|
|
99
|
+
}
|
|
100
|
+
function formatDiagnosticMessage(diagnostic) {
|
|
101
|
+
const code = diagnostic.code - 100000;
|
|
102
|
+
const tspCode = formatErrorCode ? formatErrorCode(code) : `TSP${code}`;
|
|
103
|
+
const message = typeof diagnostic.messageText === 'string'
|
|
104
|
+
? diagnostic.messageText
|
|
105
|
+
: diagnostic.messageText.messageText;
|
|
106
|
+
return `${tspCode}: ${message}`;
|
|
107
|
+
}
|
|
108
|
+
// Patch the Project prototype from the real tsserverlibrary
|
|
109
|
+
if (realTsServerLib.server?.Project) {
|
|
110
|
+
const ProjectProto = realTsServerLib.server.Project.prototype;
|
|
111
|
+
if (ProjectProto.getLanguageService && !ProjectProto.__justscale_patched) {
|
|
112
|
+
const originalGetLanguageService = ProjectProto.getLanguageService;
|
|
113
|
+
ProjectProto.getLanguageService = function () {
|
|
114
|
+
const ls = originalGetLanguageService.call(this);
|
|
115
|
+
// Check if we already wrapped this language service
|
|
116
|
+
const lsAny = ls;
|
|
117
|
+
if (lsAny.__justscale_wrapped) {
|
|
118
|
+
return ls;
|
|
119
|
+
}
|
|
120
|
+
log.info('Project.getLanguageService: wrapping language service');
|
|
121
|
+
// Create wrapped version
|
|
122
|
+
const originalGetSemanticDiagnostics = ls.getSemanticDiagnostics.bind(ls);
|
|
123
|
+
ls.getSemanticDiagnostics = (fileName) => {
|
|
124
|
+
log.info('getSemanticDiagnostics: called', { fileName });
|
|
125
|
+
const original = originalGetSemanticDiagnostics(fileName);
|
|
126
|
+
const program = ls.getProgram();
|
|
127
|
+
if (!program) {
|
|
128
|
+
return original;
|
|
129
|
+
}
|
|
130
|
+
const sourceFile = program.getSourceFile(fileName);
|
|
131
|
+
if (!sourceFile) {
|
|
132
|
+
return original;
|
|
133
|
+
}
|
|
134
|
+
const isProcess = isProcessFile(sourceFile);
|
|
135
|
+
log.info('getSemanticDiagnostics: isProcessFile', { fileName, isProcess });
|
|
136
|
+
if (!isProcess) {
|
|
137
|
+
return original;
|
|
138
|
+
}
|
|
139
|
+
const filtered = filterUsingExportsDiagnostics ? filterUsingExportsDiagnostics(original) : original;
|
|
140
|
+
log.info('getSemanticDiagnostics: analyzing process file', { fileName });
|
|
141
|
+
try {
|
|
142
|
+
const processDiagnostics = getProcessDiagnostics(sourceFile, program);
|
|
143
|
+
log.info('getSemanticDiagnostics: complete', {
|
|
144
|
+
fileName,
|
|
145
|
+
originalCount: original.length,
|
|
146
|
+
filteredCount: filtered.length,
|
|
147
|
+
processCount: processDiagnostics.length,
|
|
148
|
+
});
|
|
149
|
+
return [...filtered, ...processDiagnostics];
|
|
150
|
+
}
|
|
151
|
+
catch (err) {
|
|
152
|
+
log.error('getSemanticDiagnostics: error', { fileName, error: String(err) });
|
|
153
|
+
return original;
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
lsAny.__justscale_wrapped = true;
|
|
157
|
+
return ls;
|
|
158
|
+
};
|
|
159
|
+
ProjectProto.__justscale_patched = true;
|
|
160
|
+
log.info('Patched ts.server.Project.prototype.getLanguageService');
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
log.warn('ts.server.Project not found in tsserverlibrary');
|
|
165
|
+
}
|
|
166
|
+
// Re-export the patched ts with server from real tsserverlibrary
|
|
167
|
+
const merged = {
|
|
168
|
+
...ts,
|
|
169
|
+
server: realTsServerLib.server,
|
|
170
|
+
};
|
|
171
|
+
module.exports = merged;
|